| | |
| | | import android.provider.Settings; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | import android.widget.Toast; |
| | | |
| | | import com.auto.lyric.base.activities.BaseActivity; |
| | | import com.auto.lyric.data.LyricServer; |
| | | import com.auto.lyric.data.TextBean; |
| | | import com.auto.lyric.databinding.ActivityMainBinding; |
| | | import com.auto.lyric.service.AutoInputService; |
| | | import com.auto.lyric.service.FloatingWindowService; |
| | | import com.auto.lyric.vm.MainViewModel; |
| | | |
| | | public class MainActivity extends BaseActivity<ActivityMainBinding, MainViewModel> { |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.regex.Pattern; |
| | | |
| | | Intent service = new Intent(getApplicationContext(), AutoInputService.class); |
| | | public class MainActivity extends BaseActivity<ActivityMainBinding, MainViewModel> { |
| | | |
| | | @Override |
| | | public void initViews() { |
| | | |
| | | } |
| | | Intent inputService = new Intent(getApplicationContext(), AutoInputService.class); |
| | | |
| | | @Override |
| | | protected void onResume() { |
| | | super.onResume(); |
| | | Intent floatService = new Intent(getApplicationContext(), FloatingWindowService.class); |
| | | binding.button.setOnClickListener(v -> { |
| | | |
| | | //申请权限 |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| | | //开启悬浮窗 |
| | | if(!Settings.canDrawOverlays(getApplicationContext())) { |
| | | //启动Activity让用户授权 |
| | | Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); |
| | | intent.setData(Uri.parse("package:" + getPackageName())); |
| | | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK ); |
| | | startActivity(intent); |
| | | }else if(!isAccessibilitySettingsOn()){//辅助权限 |
| | | Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); |
| | | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK ); |
| | | startActivity(intent); |
| | | }else{//开启监听服务 |
| | | startService(service); |
| | | if(binding.edit.getText().toString().trim().length() == 0){ |
| | | Toast.makeText(this,"请输入文本", Toast.LENGTH_SHORT).show(); |
| | | return; |
| | | } |
| | | } |
| | | ArrayList<TextBean> arrayList = new ArrayList<>();//解析的文本数据 |
| | | SimpleDateFormat msFormat = new SimpleDateFormat("mm:ss.SSS"); |
| | | String[] strings = binding.edit.getText().toString().split("\n"); |
| | | for(String text : strings){ |
| | | int index = text.indexOf("]"); |
| | | if(index < 8 ){ |
| | | continue; |
| | | } |
| | | String regex = "(?<=\\])"; |
| | | Pattern compile = Pattern.compile(regex); |
| | | String[] split = compile.split(text,2); |
| | | long wait = 0; |
| | | try { |
| | | wait = 28800000 + msFormat.parse(split[0].replace("[","").replace("]","")).getTime(); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | arrayList.add(new TextBean(wait,split[1])); |
| | | } |
| | | if(arrayList.size() == 0){ |
| | | return; |
| | | } |
| | | |
| | | LyricServer.read(Arrays.asList(strings)); |
| | | //申请权限 |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| | | //开启悬浮窗 |
| | | if(!Settings.canDrawOverlays(getApplicationContext())) { |
| | | //启动Activity让用户授权 |
| | | Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); |
| | | intent.setData(Uri.parse("package:" + getPackageName())); |
| | | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK ); |
| | | startActivity(intent); |
| | | }else if(!isAccessibilitySettingsOn()){//辅助权限 |
| | | Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); |
| | | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK ); |
| | | startActivity(intent); |
| | | }else{//开启监听服务 |
| | | startService(floatService); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public boolean isAccessibilitySettingsOn() { |