Skip to content

Commit 9d011e1

Browse files
committed
Settings: Split battery light toggle into charging & low battery [2/2]
* also cleanup preference controller code
1 parent 9786634 commit 9d011e1

6 files changed

Lines changed: 124 additions & 129 deletions

File tree

res/values-ru/wave_strings.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@
7575
<string name="ambient_notification_light_color_automatic_title">Цвет уведомления</string>
7676
<string name="pulse_ambient_light_color">Цвет подсветки</string>
7777

78-
<!-- Battery light -->
79-
<string name="battery_light_title">Индикация батареи</string>
80-
<string name="battery_light_summary">Настроить цвет индикатора на основе уровня заряда батареи и статуса</string>
81-
8278
<!-- Lockscreen battery info indicator -->
8379
<string name="lockscreen_battery_info_title">Информация о батарее на экране блокировки</string>
8480
<string name="lockscreen_battery_info_summary">Показывать ток зарядки, напряжение и температуру аккумулятора на экране блокировки во время зарядки</string>

res/values/wave_strings.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@
7878
<string name="pulse_ambient_light_color">When pulsing, use</string>
7979

8080
<!-- Battery light -->
81-
<string name="battery_light_title">Battery light</string>
82-
<string name="battery_light_summary">Turn on the light while charging and blink when battery is low</string>
81+
<string name="charging_battery_light_title">Charging battery light</string>
82+
<string name="charging_battery_light_summary">Turn on light while charging battery</string>
83+
<string name="low_battery_light_title">Low battery light</string>
84+
<string name="low_battery_light_summary">Blink light when battery is low</string>
8385

8486
<!-- Lockscreen battery info indicator -->
8587
<string name="lockscreen_battery_info_title">Lockscreen charging info</string>

res/xml/configure_notification_settings.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,16 @@
134134

135135
<!-- Battery light -->
136136
<SwitchPreference
137-
android:key="battery_light_enabled"
138-
android:title="@string/battery_light_title"
139-
android:summary="@string/battery_light_summary"
140-
settings:controller="com.android.settings.notification.BatteryLightPreferenceController"/>
137+
android:key="charging_battery_light_enabled"
138+
android:title="@string/charging_battery_light_title"
139+
android:summary="@string/charging_battery_light_summary"
140+
settings:controller="com.android.settings.notification.ChargingBatteryLightPreferenceController"/>
141+
142+
<SwitchPreference
143+
android:key="low_battery_light_enabled"
144+
android:title="@string/low_battery_light_title"
145+
android:summary="@string/low_battery_light_summary"
146+
settings:controller="com.android.settings.notification.LowBatteryLightPreferenceController"/>
141147

142148
<!-- Default notification ringtone -->
143149
<com.android.settings.DefaultRingtonePreference

src/com/android/settings/notification/BatteryLightPreferenceController.java

Lines changed: 0 additions & 119 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.settings.notification;
18+
19+
import android.content.ContentResolver;
20+
import android.content.Context;
21+
import android.provider.Settings;
22+
23+
import androidx.preference.Preference;
24+
import androidx.preference.PreferenceScreen;
25+
26+
import static android.provider.Settings.Global.CHARGING_BATTERY_LIGHT_ENABLED;
27+
28+
public class ChargingBatteryLightPreferenceController extends TogglePreferenceController {
29+
30+
public ChargingBatteryLightPreferenceController(Context context, String key) {
31+
super(context, key);
32+
}
33+
34+
@Override
35+
public int getAvailabilityStatus() {
36+
return mContext.getResources().getBoolean(
37+
com.android.internal.R.bool.config_intrusiveNotificationLed) ? AVAILABLE
38+
: UNSUPPORTED_ON_DEVICE;
39+
}
40+
41+
@Override
42+
public boolean isChecked() {
43+
boolean enabledByDefault = mContext.getResources().getBoolean(
44+
com.android.internal.R.bool.config_intrusiveBatteryLed);
45+
return Settings.Global.getInt(mContext.getContentResolver(), CHARGING_BATTERY_LIGHT_ENABLED,
46+
enabledByDefault ? 1 : 0) == 1;
47+
}
48+
49+
@Override
50+
public boolean setChecked(boolean isChecked) {
51+
return Settings.Global.putInt(mContext.getContentResolver(), CHARGING_BATTERY_LIGHT_ENABLED,
52+
isChecked ? 1 : 0);
53+
}
54+
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.settings.notification;
18+
19+
import android.content.ContentResolver;
20+
import android.content.Context;
21+
import android.provider.Settings;
22+
23+
import androidx.preference.Preference;
24+
import androidx.preference.PreferenceScreen;
25+
26+
import static android.provider.Settings.Global.LOW_BATTERY_LIGHT_ENABLED;
27+
28+
public class LowBatteryLightPreferenceController extends TogglePreferenceController {
29+
30+
public LowBatteryLightPreferenceController(Context context, String key) {
31+
super(context, key);
32+
}
33+
34+
@Override
35+
public int getAvailabilityStatus() {
36+
return mContext.getResources().getBoolean(
37+
com.android.internal.R.bool.config_intrusiveNotificationLed) ? AVAILABLE
38+
: UNSUPPORTED_ON_DEVICE;
39+
}
40+
41+
@Override
42+
public boolean isChecked() {
43+
boolean enabledByDefault = mContext.getResources().getBoolean(
44+
com.android.internal.R.bool.config_intrusiveBatteryLed);
45+
return Settings.Global.getInt(mContext.getContentResolver(), LOW_BATTERY_LIGHT_ENABLED,
46+
enabledByDefault ? 1 : 0) == 1;
47+
}
48+
49+
@Override
50+
public boolean setChecked(boolean isChecked) {
51+
return Settings.Global.putInt(mContext.getContentResolver(), LOW_BATTERY_LIGHT_ENABLED,
52+
isChecked ? 1 : 0);
53+
}
54+
55+
}

0 commit comments

Comments
 (0)