Skip to content

Commit 150e092

Browse files
committed
保持唤醒设置
1 parent f351df5 commit 150e092

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable
7878
Service service = (Service) param.thisObject;
7979
AntForestToast.context = service.getApplicationContext();
8080
times = 0;
81-
PowerManager pm = (PowerManager) service.getSystemService(service.POWER_SERVICE);
82-
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, service.getClass().getName());
83-
wakeLock.acquire();
81+
if(Config.stayAwake())
82+
{
83+
PowerManager pm = (PowerManager) service.getSystemService(service.POWER_SERVICE);
84+
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, service.getClass().getName());
85+
wakeLock.acquire();
86+
}
8487
if(handler == null) handler = new Handler();
8588
if(runnable == null) runnable = new Runnable()
8689
{

app/src/main/java/pansong291/xposed/quickenergy/ui/SettingsActivity.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public class SettingsActivity extends Activity
1717
{
1818
CheckBox cb_immediateEffect, cb_recordLog, cb_showToast,
19-
cb_autoRestart,
19+
cb_stayAwake, cb_autoRestart,
2020
cb_collectEnergy, cb_helpFriendCollect, cb_receiveForestTaskAward,
2121
cb_cooperateWater,
2222
cb_enableFarm, cb_rewardFriend, cb_sendBackAnimal,
@@ -39,6 +39,7 @@ protected void onCreate(Bundle savedInstanceState)
3939
cb_immediateEffect = (CheckBox) findViewById(R.id.cb_immediateEffect);
4040
cb_recordLog = (CheckBox) findViewById(R.id.cb_recordLog);
4141
cb_showToast = (CheckBox) findViewById(R.id.cb_showToast);
42+
cb_stayAwake = (CheckBox) findViewById(R.id.cb_stayAwake);
4243
cb_autoRestart = (CheckBox) findViewById(R.id.cb_autoRestart);
4344
cb_collectEnergy = (CheckBox) findViewById(R.id.cb_collectEnergy);
4445
cb_helpFriendCollect = (CheckBox) findViewById(R.id.cb_helpFriendCollect);
@@ -69,6 +70,7 @@ protected void onResume()
6970
cb_immediateEffect.setChecked(Config.immediateEffect());
7071
cb_recordLog.setChecked(Config.recordLog());
7172
cb_showToast.setChecked(Config.showToast());
73+
cb_stayAwake.setChecked(Config.stayAwake());
7274
cb_autoRestart.setChecked(Config.autoRestart());
7375
cb_collectEnergy.setChecked(Config.collectEnergy());
7476
cb_helpFriendCollect.setChecked(Config.helpFriendCollect());
@@ -110,6 +112,10 @@ public void onClick(View v)
110112
Config.setShowToast(cb.isChecked());
111113
break;
112114

115+
case R.id.cb_stayAwake:
116+
Config.setStayAwake(cb.isChecked());
117+
break;
118+
113119
case R.id.cb_autoRestart:
114120
Config.setAutoRestart(cb.isChecked());
115121
break;

app/src/main/java/pansong291/xposed/quickenergy/util/Config.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public CharSequence nickName()
2828
public static final String
2929
/* application */
3030
jn_immediateEffect = "immediateEffect", jn_recordLog = "recordLog", jn_showToast = "showToast",
31-
jn_autoRestart = "autoRestart",
31+
jn_stayAwake = "stayAwake", jn_autoRestart = "autoRestart",
3232
/* forest */
3333
jn_collectEnergy = "collectEnergy", jn_ReturnWater30 = "returnWater30", jn_ReturnWater20 = "returnWater20",
3434
jn_ReturnWater10 = "returnWater10", jn_helpFriendCollect = "helpFriendCollect", jn_dontCollectList = "dontCollectList",
@@ -55,6 +55,7 @@ public CharSequence nickName()
5555
private boolean immediateEffect;
5656
private boolean recordLog;
5757
private boolean showToast;
58+
private boolean stayAwake;
5859
private boolean autoRestart;
5960

6061
/* forest */
@@ -143,6 +144,17 @@ public static boolean showToast()
143144
return getConfig().showToast;
144145
}
145146

147+
public static void setStayAwake(boolean b)
148+
{
149+
getConfig().stayAwake = b;
150+
hasChanged = true;
151+
}
152+
153+
public static boolean stayAwake()
154+
{
155+
return getConfig().stayAwake;
156+
}
157+
146158
public static void setAutoRestart(boolean b)
147159
{
148160
getConfig().autoRestart = b;
@@ -581,6 +593,7 @@ public static Config defInit()
581593
c.immediateEffect = true;
582594
c.recordLog = true;
583595
c.showToast = true;
596+
c.stayAwake = true;
584597
c.autoRestart = true;
585598

586599
c.collectEnergy = true;
@@ -651,6 +664,9 @@ public static Config json2Config(String json)
651664
config.showToast = jo.optBoolean(jn_showToast, true);
652665
Log.i(TAG, jn_showToast + ":" + config.showToast);
653666

667+
config.stayAwake = jo.optBoolean(jn_stayAwake, true);
668+
Log.i(TAG, jn_stayAwake + ":" + config.stayAwake);
669+
654670
config.autoRestart = jo.optBoolean(jn_autoRestart, true);
655671
Log.i(TAG, jn_autoRestart + ":" + config.autoRestart);
656672

@@ -898,6 +914,8 @@ public static String config2Json(Config config)
898914

899915
jo.put(jn_showToast, config.showToast);
900916

917+
jo.put(jn_stayAwake, config.stayAwake);
918+
901919
jo.put(jn_autoRestart, config.autoRestart);
902920

903921
/* forest */

app/src/main/res/layout/include_settings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
android:minHeight="50dp"
4444
android:id="@+id/cb_showToast"/>
4545

46+
<CheckBox
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:text="Stay awake"
50+
android:onClick="onClick"
51+
android:minHeight="50dp"
52+
android:id="@+id/cb_stayAwake"/>
53+
4654
<CheckBox
4755
android:layout_width="match_parent"
4856
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)