diff --git a/parts/src/org/lineageos/settings/doze/DozeSettingsFragment.java b/parts/src/org/lineageos/settings/doze/DozeSettingsFragment.java index de862cf..54f1930 100644 --- a/parts/src/org/lineageos/settings/doze/DozeSettingsFragment.java +++ b/parts/src/org/lineageos/settings/doze/DozeSettingsFragment.java @@ -117,6 +117,7 @@ public class DozeSettingsFragment extends PreferenceFragment mWakeOnGesturePreference.setDependency(DozeUtils.ALWAYS_ON_DISPLAY); pickupSensorCategory.setDependency(DozeUtils.ALWAYS_ON_DISPLAY); proximitySensorCategory.setDependency(DozeUtils.ALWAYS_ON_DISPLAY); + DozeUtils.updateDozeBrightnessIcon(getContext(), mDozeBrightnessPreference); } } @@ -166,23 +167,12 @@ public class DozeSettingsFragment extends PreferenceFragment if (!DozeUtils.DOZE_BRIGHTNESS_AUTO.equals((String) newValue)) { DozeUtils.setDozeMode((String) newValue); } - switch ((String) newValue) { - case DozeUtils.DOZE_BRIGHTNESS_LBM: - mDozeBrightnessPreference.setIcon(R.drawable.ic_doze_brightness_low); - break; - case DozeUtils.DOZE_BRIGHTNESS_HBM: - mDozeBrightnessPreference.setIcon(R.drawable.ic_doze_brightness_high); - break; - case DozeUtils.DOZE_BRIGHTNESS_DARK: - mDozeBrightnessPreference.setIcon(R.drawable.ic_doze_brightness_dark); - break; - case DozeUtils.DOZE_BRIGHTNESS_AUTO: - mDozeBrightnessPreference.setIcon(R.drawable.ic_doze_brightness_auto); - break; - } } - mHandler.post(() -> DozeUtils.checkDozeService(getActivity())); + mHandler.post(() -> { + DozeUtils.checkDozeService(getActivity()); + DozeUtils.updateDozeBrightnessIcon(getContext(), mDozeBrightnessPreference); + }); return true; } @@ -199,6 +189,7 @@ public class DozeSettingsFragment extends PreferenceFragment DozeUtils.enableAlwaysOn(getActivity(), false); mAlwaysOnDisplayPreference.setChecked(false); mDozeBrightnessPreference.setValue(DozeUtils.DOZE_BRIGHTNESS_LBM); + DozeUtils.updateDozeBrightnessIcon(getContext(), mDozeBrightnessPreference); mPickUpPreference.setChecked(false); mHandwavePreference.setChecked(false); mPocketPreference.setChecked(false); diff --git a/parts/src/org/lineageos/settings/doze/DozeUtils.java b/parts/src/org/lineageos/settings/doze/DozeUtils.java index 3a21083..889e60d 100644 --- a/parts/src/org/lineageos/settings/doze/DozeUtils.java +++ b/parts/src/org/lineageos/settings/doze/DozeUtils.java @@ -28,8 +28,10 @@ import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; import android.util.Log; +import androidx.preference.ListPreference; import androidx.preference.PreferenceManager; +import org.lineageos.settings.R; import org.lineageos.settings.utils.FileUtils; import static android.provider.Settings.Secure.DOZE_ALWAYS_ON; @@ -186,4 +188,22 @@ public final class DozeUtils { } return null; } + + protected static void updateDozeBrightnessIcon(Context context, ListPreference preference) { + switch (PreferenceManager.getDefaultSharedPreferences(context).getString( + DOZE_BRIGHTNESS_KEY, DOZE_BRIGHTNESS_LBM)) { + case DozeUtils.DOZE_BRIGHTNESS_LBM: + preference.setIcon(R.drawable.ic_doze_brightness_low); + break; + case DozeUtils.DOZE_BRIGHTNESS_HBM: + preference.setIcon(R.drawable.ic_doze_brightness_high); + break; + case DozeUtils.DOZE_BRIGHTNESS_DARK: + preference.setIcon(R.drawable.ic_doze_brightness_dark); + break; + case DozeUtils.DOZE_BRIGHTNESS_AUTO: + preference.setIcon(R.drawable.ic_doze_brightness_auto); + break; + } + } }