api: device.keepScreenOn(), device.keepScreenDim(), device.wakeUp(), device.vibrate();
fix: crash when rotating editor
This commit is contained in:
@@ -97,7 +97,10 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.stardust.autojs.core.image.ScreenCaptureRequestActivity"
|
||||
android:excludeFromRecents="true"
|
||||
android:taskAffinity="com.stardust.autojs.runtime.api.image.ScreenCaptureRequestActivity"
|
||||
android:theme="@style/AppTheme.Transparent"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.error.IssueReporterActivity"
|
||||
android:theme="@style/IssueReporterTheme"/>
|
||||
|
||||
@@ -84,7 +84,7 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
|
||||
@ViewById(R.id.symbol_bar)
|
||||
CodeCompletionBar mSymbolBar;
|
||||
|
||||
@ViewById(R.id.properties)
|
||||
@ViewById(R.id.functions)
|
||||
ImageView mShowFunctionsButton;
|
||||
|
||||
@ViewById(R.id.functions_keyboard)
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/properties"
|
||||
android:id="@+id/functions"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
@@ -156,7 +156,7 @@
|
||||
android:layout_above="@+id/symbol_bar"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toRightOf="@+id/properties"/>
|
||||
android:layout_toRightOf="@+id/functions"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
|
||||
|
||||
<application
|
||||
|
||||
@@ -10,6 +10,8 @@ import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -84,6 +86,8 @@ public class Device {
|
||||
public static final String serial = Build.SERIAL;
|
||||
|
||||
private Context mContext;
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
private int mWakeLockFlag;
|
||||
|
||||
public Device(Context context) {
|
||||
mContext = context;
|
||||
@@ -195,7 +199,6 @@ public class Device {
|
||||
return info.availMem;
|
||||
}
|
||||
|
||||
|
||||
public boolean isCharging() {
|
||||
Intent intent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
if (intent == null) {
|
||||
@@ -205,6 +208,58 @@ public class Device {
|
||||
return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
|
||||
}
|
||||
|
||||
public void keepAwake(int flags, long timeout) {
|
||||
checkWakeLock(flags);
|
||||
mWakeLock.acquire(timeout);
|
||||
}
|
||||
|
||||
@SuppressLint("WakelockTimeout")
|
||||
public void keepAwake(int flags) {
|
||||
checkWakeLock(flags);
|
||||
mWakeLock.acquire();
|
||||
}
|
||||
|
||||
public void wakeUp() {
|
||||
keepScreenOn(200);
|
||||
}
|
||||
|
||||
public void keepScreenOn() {
|
||||
keepAwake(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP);
|
||||
}
|
||||
|
||||
public void keepScreenOn(long timeout) {
|
||||
keepAwake(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, timeout);
|
||||
}
|
||||
|
||||
public void keepScreenDim() {
|
||||
keepAwake(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP);
|
||||
}
|
||||
|
||||
public void keepScreenDim(long timeout) {
|
||||
keepAwake(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, timeout);
|
||||
}
|
||||
|
||||
private void checkWakeLock(int flags) {
|
||||
if (mWakeLock == null || flags != mWakeLockFlag) {
|
||||
cancelKeepingAwake();
|
||||
mWakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(flags, Device.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelKeepingAwake() {
|
||||
if (mWakeLock != null && mWakeLock.isHeld())
|
||||
mWakeLock.release();
|
||||
}
|
||||
|
||||
public void vibrate(long millis) {
|
||||
((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(millis);
|
||||
}
|
||||
|
||||
public void cancelVibration() {
|
||||
((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).cancel();
|
||||
}
|
||||
|
||||
|
||||
private void checkWriteSettingsPermission() {
|
||||
if (SettingsCompat.canWriteSettings(mContext)) {
|
||||
return;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Timers {
|
||||
return mMainTimer;
|
||||
}
|
||||
|
||||
public VolatileBox<Long> getMaxCallbackUptimeMillisForAllThreads() {
|
||||
VolatileBox<Long> getMaxCallbackUptimeMillisForAllThreads() {
|
||||
return mMaxCallbackUptimeMillisForAllThreads;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,6 @@ public class Timers {
|
||||
public boolean hasPendingCallbacks() {
|
||||
//如果是脚本主线程,则检查所有子线程中的定时回调。mFutureCallbackUptimeMillis用来记录所有子线程中定时最久的一个。
|
||||
if (mThreads.getMainThread() == Thread.currentThread()) {
|
||||
Log.d(LOG_TAG, "[main thread]hasPendingCallbacks:" + (mMaxCallbackUptimeMillisForAllThreads.get() > SystemClock.uptimeMillis()));
|
||||
Log.d(LOG_TAG, "mMaxCallbackUptimeMillisForAllThreads:" + mMaxCallbackUptimeMillisForAllThreads.get());
|
||||
return mMaxCallbackUptimeMillisForAllThreads.get() > SystemClock.uptimeMillis();
|
||||
}
|
||||
//否则检查当前线程的定时回调
|
||||
|
||||
Reference in New Issue
Block a user