Add: Volume Changing to stop scripts, Fix: Automator ANR
This commit is contained in:
@@ -9,6 +9,7 @@ import android.view.View;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.layout_inspector.view.LayoutInspectView;
|
||||
import com.stardust.scriptdroid.tool.IntentTool;
|
||||
import com.stardust.view.Floaty;
|
||||
import com.stardust.view.ResizableFloaty;
|
||||
|
||||
@@ -30,16 +31,17 @@ public class FloatingWindowManger {
|
||||
|
||||
public static void goToFloatingWindowPermissionSetting() {
|
||||
String packageName = App.getApp().getPackageName();
|
||||
Intent intent;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
Uri.parse("package:" + packageName))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
try {
|
||||
App.getApp().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
Uri.parse("package:" + packageName))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
} catch (Exception e) {
|
||||
IntentTool.goToAppSetting(App.getApp());
|
||||
}
|
||||
} else {
|
||||
intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + packageName))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
IntentTool.goToAppSetting(App.getApp());
|
||||
}
|
||||
App.getApp().startActivity(intent);
|
||||
}
|
||||
|
||||
private static boolean hasFloatingWindowPermission() {
|
||||
@@ -56,6 +58,6 @@ public class FloatingWindowManger {
|
||||
|
||||
public static void hideFloatingWindow() {
|
||||
if (HoverMenuService.isServiceRunning())
|
||||
HoverMenuService.stopService();
|
||||
App.getApp().stopService(new Intent(App.getApp(), HoverMenuService.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ public class HoverMenuService extends Service {
|
||||
public static final String MESSAGE_MENU_EXPANDING = "MESSAGE_MENU_EXPANDING";
|
||||
public static final String MESSAGE_MENU_EXIT = "MESSAGE_MENU_EXIT";
|
||||
|
||||
private static HoverMenuService service = null;
|
||||
private static boolean sIsRunning;
|
||||
|
||||
public static void startService(Context context) {
|
||||
@@ -66,13 +65,6 @@ public class HoverMenuService extends Service {
|
||||
return sIsRunning;
|
||||
}
|
||||
|
||||
public static void stopService() {
|
||||
if (isServiceRunning() && service != null) {
|
||||
service.stopSelf();
|
||||
setIsRunning(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setIsRunning(boolean isRunning) {
|
||||
sIsRunning = isRunning;
|
||||
EventBus.getDefault().post(new ServiceStateChangedEvent(sIsRunning));
|
||||
@@ -105,20 +97,18 @@ public class HoverMenuService extends Service {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
if (service != null) {
|
||||
stopSelf();
|
||||
return;
|
||||
}
|
||||
service = this;
|
||||
EventBus.getDefault().register(this);
|
||||
mPrefs = getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE);
|
||||
tryInitViews();
|
||||
}
|
||||
|
||||
private void tryInitViews() {
|
||||
try {
|
||||
initViews();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
FloatingWindowManger.goToFloatingWindowPermissionSetting();
|
||||
stopService();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +161,8 @@ public class HoverMenuService extends Service {
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (mWindowHoverMenu == null)
|
||||
tryInitViews();
|
||||
if (mWindowHoverMenu != null)
|
||||
mWindowHoverMenu.show();
|
||||
return START_STICKY;
|
||||
@@ -183,8 +175,6 @@ public class HoverMenuService extends Service {
|
||||
if (EventBus.getDefault().isRegistered(this))
|
||||
EventBus.getDefault().unregister(this);
|
||||
setIsRunning(false);
|
||||
if (service == this)
|
||||
service = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,11 +78,7 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
|
||||
@ViewBinding.Click(R.id.stop_all_running_scripts)
|
||||
private void stopAllRunningScripts() {
|
||||
int n = Droid.getInstance().stopAll();
|
||||
if (n > 0)
|
||||
Toast.makeText(mView.getContext(), String.format(mView.getContext().getString(R.string.text_already_stop_n_scripts), n), Toast.LENGTH_SHORT).show();
|
||||
else
|
||||
Toast.makeText(mView.getContext(), R.string.text_no_running_script, Toast.LENGTH_SHORT).show();
|
||||
Droid.getInstance().stopAllAndToast();
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.open_launcher)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.stardust.scriptdroid.external.floating_window.content;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.view.View;
|
||||
@@ -8,6 +9,8 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.accessibility.AccessibilityEventHelper;
|
||||
import com.stardust.scriptdroid.external.floating_window.HoverMenuService;
|
||||
@@ -15,6 +18,7 @@ import com.stardust.scriptdroid.record.Recorder;
|
||||
import com.stardust.scriptdroid.record.accessibility.AccessibilityActionRecorder;
|
||||
import com.stardust.scriptdroid.record.inputevent.InputEventConverter;
|
||||
import com.stardust.scriptdroid.record.inputevent.TouchRecorder;
|
||||
import com.stardust.scriptdroid.service.VolumeChangeObverseService;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity;
|
||||
import com.stardust.util.MessageEvent;
|
||||
import com.stardust.view.ViewBinder;
|
||||
@@ -53,10 +57,26 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
private Recorder mRecorder;
|
||||
private Context mContext;
|
||||
|
||||
private VolumeChangeObverseService.OnVolumeChangeListener mOnVolumeChangeListener = new VolumeChangeObverseService.OnVolumeChangeListener() {
|
||||
@Override
|
||||
public void onVolumeChange() {
|
||||
if (Pref.isRecordVolumeControlEnable()) {
|
||||
if (mRecorder == null) {
|
||||
startRecord();
|
||||
} else if (mRecorder.getState() == Recorder.STATE_RECORDING) {
|
||||
stopRecord();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public RecordNavigatorContent(Context context) {
|
||||
mContext = context;
|
||||
mView = View.inflate(context, R.layout.floating_window_record, null);
|
||||
ViewBinder.bind(this);
|
||||
EventBus.getDefault().register(this);
|
||||
App.getApp().startService(new Intent(App.getApp(), VolumeChangeObverseService.class));
|
||||
VolumeChangeObverseService.addOnVolumeChangeListener(mOnVolumeChangeListener);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -67,16 +87,12 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
|
||||
@Override
|
||||
public void onShown(@NonNull Navigator navigator) {
|
||||
if (!EventBus.getDefault().isRegistered(this)) {
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHidden() {
|
||||
if (EventBus.getDefault().isRegistered(this)) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.sw_root_container)
|
||||
@@ -145,6 +161,9 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
||||
public void onMessageEvent(MessageEvent event) {
|
||||
if (event.message.equals(HoverMenuService.MESSAGE_MENU_EXPANDING)) {
|
||||
pauseRecord();
|
||||
} else if (event.message.equals(HoverMenuService.MESSAGE_MENU_EXIT)) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
VolumeChangeObverseService.removeOnVolumeChangeListener(mOnVolumeChangeListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ public class AccessibilityActionRecordNotification {
|
||||
case ACTION_DELETE:
|
||||
AccessibilityActionRecordNotification.cancelNotification();
|
||||
stopRecordIfNeeded(context);
|
||||
VolumeChangeObverseService.stopServiceIfNeeded();
|
||||
break;
|
||||
case ACTION_REDO:
|
||||
redoRecord(context);
|
||||
@@ -93,7 +92,7 @@ public class AccessibilityActionRecordNotification {
|
||||
.setCustomContentView(AccessibilityActionRecordSwitchView.getInstance());
|
||||
}
|
||||
showNotification(builder.build());
|
||||
VolumeChangeObverseService.startServiceIfNeeded(App.getApp());
|
||||
App.getApp().startService(new Intent(App.getApp(), VolumeChangeObverseService.class));
|
||||
}
|
||||
|
||||
private static void showNotification(Notification notification) {
|
||||
|
||||
Reference in New Issue
Block a user