Skip to content

Commit

Permalink
根据 CC0126 所述,修改手电筒亮度功能,更新后需要重新选择该功能模式,默认为默认写入模式。
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Feb 29, 2024
1 parent e4aef89 commit b53e24f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void handleLoadPackage() {
initHook(new TaplusTile(), mPrefsMap.getBoolean("security_center_taplus"));
initHook(new ReduceBrightColorsTile(), mPrefsMap.getBoolean("security_center_reduce_bright_colors_tile"));
initHook(new FiveGTile(), mPrefsMap.getStringAsInt("system_control_center_5g_new_tile", 0) != 0);
initHook(new FlashLight(), mPrefsMap.getBoolean("security_flash_light"));
initHook(new FlashLight(), mPrefsMap.getStringAsInt("security_flash_light_switch", 0) != 0);
initHook(new SunlightMode(), mPrefsMap.getStringAsInt("system_control_center_sunshine_new_mode", 0) != 0);
initHook(new QSGridLabels(), mPrefsMap.getInt("system_control_center_old_qs_row", 1) > 1 ||
mPrefsMap.getBoolean("system_control_center_qs_tile_label"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ public class FlashLight extends TileUtils {
public final String other = "/sys/class/leds/flashlight/brightness";
public final String flashSwitch = "/sys/class/leds/led:switch_0/brightness";
public final String maxBrightness = "/sys/class/leds/led:torch_0/max_brightness";
public int mode = 0;
public int lastFlash = -1;
public boolean isListening = false;
public boolean isHook = false;

@Override
public void init() {
super.init();
mode = mPrefsMap.getStringAsInt("security_flash_light_switch", 0);
setPermission(mtk);
setPermission(torch);
setPermission(other);
Expand Down Expand Up @@ -353,9 +355,47 @@ private int maxBrightness() {
}

private void writeFile(int flash) {
if (exists(mtk)) write(mtk, flash);
if (exists(torch)) write(torch, flash);
if (exists(other)) write(other, flash);
boolean bmtk = exists(mtk);
boolean btorch = exists(torch);
boolean bother = exists(other);
switch (mode) {
case 0, 1 -> {
if (bmtk) write(mtk, flash);
if (btorch) write(torch, flash);
if (bother) write(other, flash);
}
case 2 -> {
if (bmtk)
zero(mtk, flash);
if (btorch) {
zero(torch, flash);
break; // 根据 CC0126 所述,不同时操作。
}
if (bother)
zero(other, flash);
}
case 3 -> {
if (bmtk)
flashSwitch(mtk, flash);
if (btorch) {
flashSwitch(torch, flash);
break; // 根据 CC0126 所述,不同时操作。
}
if (bother)
flashSwitch(other, flash);
}
}
}

private void zero(String path, int flash) {
write(path, 0);
write(path, flash);
}

private void flashSwitch(String path, int flash) {
write(path, flash);
write(flashSwitch, 1);
write(flashSwitch, 0);
}

private boolean exists(String path) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@
<string name="control_center_sunshine_mode_one">系统默认模式</string>
<string name="control_center_sunshine_mode_two">强制最高亮度</string>

<string name="security_center_flash_light_default">关闭</string>
<string name="security_center_flash_light_1">默认写入模式</string>
<string name="security_center_flash_light_2">写入模式一</string>
<string name="security_center_flash_light_3">写入模式二</string>

<string name="control_center_5g_off">关闭</string>
<string name="control_center_5g_v1">样式一</string>
<string name="control_center_5g_v2">样式二</string>
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@
<item>@string/control_center_sunshine_mode_two</item>
</string-array>

<string-array name="security_center_flash_light">
<item>@string/security_center_flash_light_default</item>
<item>@string/security_center_flash_light_1</item>
<item>@string/security_center_flash_light_2</item>
<item>@string/security_center_flash_light_3</item>
</string-array>

<string-array name="control_center_5g_mode">
<item>@string/control_center_5g_off</item>
<item>@string/control_center_5g_v1</item>
Expand Down Expand Up @@ -260,6 +267,13 @@
<item>2</item>
</string-array>

<string-array name="security_center_flash_light_value">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>

<string-array name="status_bar_icon_mode_new_value">
<item>0</item>
<item>1</item>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@
<string name="control_center_sunshine_mode_default">Close</string>
<string name="control_center_sunshine_mode_one">System default mode</string>
<string name="control_center_sunshine_mode_two">Force maximum brightness</string>
<string name="security_center_flash_light_default">Close</string>
<string name="security_center_flash_light_1">Default write mode</string>
<string name="security_center_flash_light_2">Write mode one</string>
<string name="security_center_flash_light_3">Write Mode two</string>
<string name="control_center_5g_off">Off</string>
<string name="control_center_5g_v1">5G Style One</string>
<string name="control_center_5g_v2">5G Style Two</string>
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/res/xml/system_ui_control_center.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,19 @@
app:entries="@array/control_center_sunshine_mode"
app:entryValues="@array/status_bar_icon_mode_value" />

<SwitchPreference
<DropDownPreference
android:defaultValue="0"
android:key="prefs_key_security_flash_light_switch"
android:title="@string/security_center_flash_light"
android:summary="@string/security_center_flash_light_more"
app:entries="@array/security_center_flash_light"
app:entryValues="@array/security_center_flash_light_value" />

<!--<SwitchPreference
android:defaultValue="false"
android:key="prefs_key_security_flash_light"
android:summary="@string/security_center_flash_light_more"
android:title="@string/security_center_flash_light" />
android:title="@string/security_center_flash_light" />-->

<SwitchPreference
android:defaultValue="false"
Expand Down

0 comments on commit b53e24f

Please sign in to comment.