Skip to content

Commit ad28325

Browse files
authored
Merge pull request #7 from Derpfest-Peridot/15.0
HDR Brightness modifier
2 parents 9152d51 + b129bf8 commit ad28325

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed

res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13920,4 +13920,8 @@
1392013920
<string name="search_gesture_feature_title">Circle to Search</string>
1392113921
<!-- Summary text for press and hold nav handle OR home button to invoke Circle to Search. [CHAR LIMIT=NONE] -->
1392213922
<string name="search_gesture_feature_summary">Touch and hold the Home button or the navigation handle to search using the content on your screen.</string>
13923+
<!-- HDR Display -->
13924+
<string name="hdr_display_title">HDR Display</string>
13925+
<string name="hdr_display_summary">Enable peak brightness for HDR content. This will increase battery usage</string>
13926+
<string name="hdr_max_brightness_percent_title">HDR Display intensity</string>
1392313927
</resources>

res/xml/display_settings.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<PreferenceScreen
1818
xmlns:android="http://schemas.android.com/apk/res/android"
1919
xmlns:settings="http://schemas.android.com/apk/res-auto"
20+
xmlns:app="http://schemas.android.com/apk/res/com.android.settings"
2021
android:key="display_settings_screen"
2122
android:title="@string/display_settings"
2223
settings:keywords="@string/keywords_display">
@@ -193,6 +194,22 @@
193194
settings:keywords="@string/keywords_refresh_rate"
194195
settings:controller="com.android.settings.display.RefreshRatePreferenceController"/>
195196

197+
<SwitchPreferenceCompat
198+
android:key="hdr_display"
199+
android:title="@string/hdr_display_title"
200+
android:summary="@string/hdr_display_summary"
201+
settings:controller="com.android.settings.display.HdrDisplayPreferenceController"/>
202+
203+
<com.crdroid.settings.preferences.SecureSettingSeekBarPreference
204+
android:key="hdr_max_brightness_percent"
205+
android:title="@string/hdr_max_brightness_percent_title"
206+
android:max="100"
207+
app:min="10"
208+
android:defaultValue="100"
209+
android:dependency="hdr_display"
210+
settings:controller="com.android.settings.display.HdrDisplayBrightnessPreferenceController"
211+
settings:interval="1"/>
212+
196213
<SwitchPreferenceCompat
197214
android:key="show_operator_name"
198215
android:title="@string/show_operator_name_title"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2025 The AxionAOSP Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11+
* KIND, either express or implied. See the License for the specific language governing
12+
* permissions and limitations under the License.
13+
*/
14+
package com.android.settings.display;
15+
16+
import android.content.Context;
17+
import android.os.SystemProperties;
18+
19+
import androidx.preference.Preference;
20+
import androidx.preference.PreferenceScreen;
21+
22+
import com.android.settings.R;
23+
import com.android.settings.core.BasePreferenceController;
24+
25+
public class HdrDisplayBrightnessPreferenceController extends BasePreferenceController {
26+
27+
private static final String HDR_MAX_BRIGHTNESS_PERCENT = "hdr_max_brightness_percent";
28+
29+
public HdrDisplayBrightnessPreferenceController(Context context, String key) {
30+
super(context, key);
31+
}
32+
33+
@Override
34+
public int getAvailabilityStatus() {
35+
return SystemProperties.getBoolean("ro.surface_flinger.has_HDR_display", false)
36+
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
37+
}
38+
39+
@Override
40+
public int getSliceHighlightMenuRes() {
41+
return R.string.menu_key_display;
42+
}
43+
44+
@Override
45+
public void displayPreference(PreferenceScreen screen) {
46+
super.displayPreference(screen);
47+
}
48+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (C) 2025 The AxionAOSP Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11+
* KIND, either express or implied. See the License for the specific language governing
12+
* permissions and limitations under the License.
13+
*/
14+
package com.android.settings.display;
15+
16+
import android.app.ActivityManager;
17+
import android.content.ContentResolver;
18+
import android.content.Context;
19+
import android.database.ContentObserver;
20+
import android.net.Uri;
21+
import android.os.Handler;
22+
import android.os.Looper;
23+
import android.os.SystemProperties;
24+
import android.provider.Settings;
25+
import android.provider.Settings.Secure;
26+
27+
import androidx.annotation.VisibleForTesting;
28+
import androidx.preference.Preference;
29+
import androidx.preference.PreferenceScreen;
30+
31+
import com.android.settings.R;
32+
import com.android.settings.core.TogglePreferenceController;
33+
import com.android.settingslib.core.lifecycle.LifecycleObserver;
34+
import com.android.settingslib.core.lifecycle.events.OnStart;
35+
import com.android.settingslib.core.lifecycle.events.OnStop;
36+
37+
public class HdrDisplayPreferenceController extends TogglePreferenceController
38+
implements LifecycleObserver, OnStart, OnStop {
39+
40+
private static final String HDR_DISPLAY_SETTING = "hdr_display";
41+
42+
@VisibleForTesting
43+
ContentObserver mContentObserver;
44+
private Preference mPreference;
45+
46+
public HdrDisplayPreferenceController(Context context, String key) {
47+
super(context, key);
48+
}
49+
50+
@Override
51+
public int getAvailabilityStatus() {
52+
return SystemProperties.getBoolean("ro.surface_flinger.has_HDR_display", false)
53+
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
54+
}
55+
56+
@Override
57+
public boolean isChecked() {
58+
return Settings.Secure.getInt(mContext.getContentResolver(), HDR_DISPLAY_SETTING, 1) != 0;
59+
}
60+
61+
@Override
62+
public boolean setChecked(boolean isChecked) {
63+
return Settings.Secure.putInt(
64+
mContext.getContentResolver(),
65+
HDR_DISPLAY_SETTING,
66+
isChecked ? 1 : 0
67+
);
68+
}
69+
70+
@Override
71+
public int getSliceHighlightMenuRes() {
72+
return R.string.menu_key_display;
73+
}
74+
75+
@Override
76+
public void onStart() {
77+
if (!isAvailable()) {
78+
return;
79+
}
80+
81+
final ContentResolver cr = mContext.getContentResolver();
82+
mContentObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
83+
@Override
84+
public void onChange(boolean selfChange, Uri uri) {
85+
super.onChange(selfChange, uri);
86+
if (HDR_DISPLAY_SETTING.equals(uri.getLastPathSegment())) {
87+
updateState(mPreference);
88+
}
89+
}
90+
};
91+
92+
cr.registerContentObserver(Settings.Secure.getUriFor(HDR_DISPLAY_SETTING),
93+
false, mContentObserver, ActivityManager.getCurrentUser());
94+
}
95+
96+
@Override
97+
public void onStop() {
98+
if (mContentObserver != null) {
99+
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
100+
mContentObserver = null;
101+
}
102+
}
103+
104+
@Override
105+
public void displayPreference(PreferenceScreen screen) {
106+
super.displayPreference(screen);
107+
mPreference = screen.findPreference(getPreferenceKey());
108+
}
109+
}

0 commit comments

Comments
 (0)