global key observer lazy initialize
This commit is contained in:
@@ -81,7 +81,9 @@ public class App extends MultiDexApplication {
|
|||||||
ThemeColorManager.setDefaultThemeColor(new ThemeColor(getResources().getColor(R.color.colorPrimary), getResources().getColor(R.color.colorPrimaryDark), getResources().getColor(R.color.colorAccent)));
|
ThemeColorManager.setDefaultThemeColor(new ThemeColor(getResources().getColor(R.color.colorPrimary), getResources().getColor(R.color.colorPrimaryDark), getResources().getColor(R.color.colorAccent)));
|
||||||
ThemeColorManager.init(this);
|
ThemeColorManager.init(this);
|
||||||
AutoJs.initInstance(this);
|
AutoJs.initInstance(this);
|
||||||
GlobalKeyObserver.getSingleton();
|
if (Pref.isRunningVolumeControlEnabled()) {
|
||||||
|
GlobalKeyObserver.init();
|
||||||
|
}
|
||||||
setupDrawableImageLoader();
|
setupDrawableImageLoader();
|
||||||
TimedTaskScheduler.setupRepeating(this);
|
TimedTaskScheduler.setupRepeating(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.stardust.autojs.runtime.accessibility.AccessibilityConfig;
|
import com.stardust.autojs.runtime.accessibility.AccessibilityConfig;
|
||||||
|
import com.stardust.scriptdroid.autojs.key.GlobalKeyObserver;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -24,9 +25,12 @@ public class Pref {
|
|||||||
|
|
||||||
private static SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
private static SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences p, String key) {
|
||||||
if (key.equals(getString(R.string.key_guard_mode))) {
|
if (key.equals(getString(R.string.key_guard_mode))) {
|
||||||
AccessibilityConfig.setIsUnintendedGuardEnabled(sharedPreferences.getBoolean(getString(R.string.key_guard_mode), false));
|
AccessibilityConfig.setIsUnintendedGuardEnabled(p.getBoolean(getString(R.string.key_guard_mode), false));
|
||||||
|
} else if ((key.equals(getString(R.string.key_use_volume_control_record)) || key.equals(getString(R.string.key_use_volume_control_running)))
|
||||||
|
&& p.getBoolean(key, false)) {
|
||||||
|
GlobalKeyObserver.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class GlobalKeyObserver implements OnKeyListener, ShellKeyObserver.KeyLis
|
|||||||
private static final EventDispatcher.Event<OnVolumeDownListener> VOLUME_DOWN_EVENT = OnVolumeDownListener::onVolumeDown;
|
private static final EventDispatcher.Event<OnVolumeDownListener> VOLUME_DOWN_EVENT = OnVolumeDownListener::onVolumeDown;
|
||||||
private static final String LOG_TAG = "GlobalKeyObserver";
|
private static final String LOG_TAG = "GlobalKeyObserver";
|
||||||
private static final long EVENT_TIMEOUT = 200;
|
private static final long EVENT_TIMEOUT = 200;
|
||||||
private static GlobalKeyObserver sSingleton = new GlobalKeyObserver();
|
private static GlobalKeyObserver sSingleton;
|
||||||
private EventDispatcher<OnVolumeDownListener> mVolumeDownEventDispatcher = new EventDispatcher<>();
|
private EventDispatcher<OnVolumeDownListener> mVolumeDownEventDispatcher = new EventDispatcher<>();
|
||||||
private boolean mVolumeDownFromShell, mVolumeDownFromAccessibility;
|
private boolean mVolumeDownFromShell, mVolumeDownFromAccessibility;
|
||||||
private boolean mVolumeUpFromShell, mVolumeUpFromAccessibility;
|
private boolean mVolumeUpFromShell, mVolumeUpFromAccessibility;
|
||||||
@@ -39,11 +39,14 @@ public class GlobalKeyObserver implements OnKeyListener, ShellKeyObserver.KeyLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static GlobalKeyObserver getSingleton() {
|
public static GlobalKeyObserver getSingleton() {
|
||||||
|
if (sSingleton == null) {
|
||||||
|
sSingleton = new GlobalKeyObserver();
|
||||||
|
}
|
||||||
return sSingleton;
|
return sSingleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
//do nothing
|
getSingleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onVolumeUp() {
|
public void onVolumeUp() {
|
||||||
|
|||||||
Reference in New Issue
Block a user