Cherish:Add ambient edge lightning settings

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
idoybh
2021-12-11 01:05:07 +00:00
committed by Hưng Phan
parent 39d8d998eb
commit fb5f6fa3ca
6 changed files with 321 additions and 0 deletions

View File

@@ -293,4 +293,38 @@
<item>2</item>
</string-array>
<!-- Edge lightning timeout -->
<string-array name="ambient_notification_light_timeout_entries" translatable="false">
<item>@string/ambient_notification_light_timeout_forever</item>
<item>@string/ambient_notification_light_timeout_half_minute</item>
<item>@string/ambient_notification_light_timeout_minute</item>
<item>@string/ambient_notification_light_timeout_three_minutes</item>
<item>@string/ambient_notification_light_timeout_five_minutes</item>
<item>@string/ambient_notification_light_timeout_ten_minutes</item>
</string-array>
<string-array name="ambient_notification_light_timeout_values" translatable="false">
<item>0</item>
<item>30</item>
<item>60</item>
<item>180</item>
<item>300</item>
<item>600</item>
</string-array>
<!-- Edge lightning color mode -->
<string-array name="ambient_notification_color_mode_entries" translatable="false">
<item>@string/ambient_notification_color_mode_accent</item>
<item>@string/ambient_notification_color_mode_wall</item>
<item>@string/ambient_notification_color_mode_notification</item>
<item>@string/ambient_notification_color_mode_custom</item>
</string-array>
<string-array name="ambient_notification_color_mode_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
</resources>

View File

@@ -14,6 +14,9 @@
<!-- App Title -->
<string name="cherish_settings_title">Cherish Settings</string>
<!-- Units -->
<string name="unit_seconds">seconds</string>
<!-- Categories -->
<string name="button_title">Buttons</string>
<string name="button_summary">Hardware keys, Navigation bar</string>
@@ -402,4 +405,30 @@
<string name="always_on_display_schedule_mixed_sunset">Turns on from sunset till a time</string>
<string name="always_on_display_schedule_mixed_sunrise">Turns on from a time till sunrise</string>
<!-- Pulse notifications lightning -->
<string name="pulse_ambient_light_title">Ambient edge lightning</string>
<string name="pulse_ambient_light_summary">Light ambient edges for pulsing notifications</string>
<string name="ambient_notification_light_enabled_title">Show on AOD</string>
<string name="ambient_notification_light_enabled_summary">Keep showing edge lightning on AOD</string>
<string name="ambient_notification_light_hide_aod_title">Hide AOD content</string>
<string name="ambient_notification_light_hide_aod_summary">Hide AOD content when edges are lighted</string>
<string name="ambient_notification_light_duration_title">Duration</string>
<string name="ambient_notification_light_duration_summary">Time it takes for each animation to complete</string>
<string name="ambient_notification_light_repeats_title">Repeats</string>
<string name="ambient_notification_light_repeats_summary">Amount of times the animation should show\n0 for infinite</string>
<string name="ambient_notification_light_timeout_title">Timeout</string>
<string name="ambient_notification_light_timeout_forever">Forever</string>
<string name="ambient_notification_light_timeout_half_minute">30 seconds</string>
<string name="ambient_notification_light_timeout_minute">1 minute</string>
<string name="ambient_notification_light_timeout_three_minutes">3 minutes</string>
<string name="ambient_notification_light_timeout_five_minutes">5 minutes</string>
<string name="ambient_notification_light_timeout_ten_minutes">10 minutes</string>
<string name="set_to_zero">Set repeats to 0 to enable</string>
<string name="ambient_notification_color_mode_title">Color mode</string>
<string name="ambient_notification_color_mode_accent">Accent color</string>
<string name="ambient_notification_color_mode_wall">Wallpaper dominant color</string>
<string name="ambient_notification_color_mode_notification">Notification icon color</string>
<string name="ambient_notification_color_mode_custom">@string/ambient_notification_light_color_title</string>
<string name="ambient_notification_light_color_title">Custom color</string>
</resources>

View File

@@ -83,6 +83,14 @@
android:key="charging_light"
android:fragment="com.cherish.settings.fragments.BatteryLightSettings"
android:title="@string/battery_light_settings" />
<!-- Pulse notifications lightning -->
<com.cherish.settings.preferences.SystemSettingMasterSwitchPreference
android:key="pulse_ambient_light"
android:title="@string/pulse_ambient_light_title"
android:summary="@string/pulse_ambient_light_summary"
android:fragment="com.cherish.settings.fragments.EdgeLightningSettings"
android:defaultValue="false" />
<PreferenceCategory
android:key="headsup_notifications_category"

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 Yet Another AOSP Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/pulse_ambient_light_title"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="ambient_notification_light_enabled"
android:title="@string/ambient_notification_light_enabled_title"
android:summary="@string/ambient_notification_light_enabled_summary"
android:defaultValue="false" />
<com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="ambient_notification_light_hide_aod"
android:title="@string/ambient_notification_light_hide_aod_title"
android:summary="@string/ambient_notification_light_hide_aod_summary"
android:defaultValue="false"
android:dependency="ambient_notification_light_enabled" />
<com.cherish.settings.preferences.CustomSeekBarPreference
android:key="ambient_notification_light_duration"
android:title="@string/ambient_notification_light_duration_title"
android:summary="@string/ambient_notification_light_duration_summary"
android:max="5"
settings:min="1"
settings:defaultValue="2"
settings:units="@string/unit_seconds" />
<com.cherish.settings.preferences.CustomSeekBarPreference
android:key="ambient_notification_light_repeats"
android:title="@string/ambient_notification_light_repeats_title"
android:summary="@string/ambient_notification_light_repeats_summary"
android:max="10"
settings:min="0"
settings:defaultValue="0" />
<com.cherish.settings.preferences.SystemSettingListPreference
android:key="ambient_notification_light_timeout"
android:title="@string/ambient_notification_light_timeout_title"
android:entries="@array/ambient_notification_light_timeout_entries"
android:entryValues="@array/ambient_notification_light_timeout_values"
android:defaultValue="0" />
<com.cherish.settings.preferences.SystemSettingListPreference
android:key="ambient_notification_color_mode"
android:title="@string/ambient_notification_color_mode_title"
android:entries="@array/ambient_notification_color_mode_entries"
android:entryValues="@array/ambient_notification_color_mode_values"
android:defaultValue="0" />
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="ambient_notification_light_color"
android:title="@string/ambient_notification_light_color_title" />
</PreferenceScreen>

View File

@@ -0,0 +1,170 @@
/*
* Copyright (C) 2020 Yet Another AOSP Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.cherish.settings.fragments;
import android.content.ContentResolver;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserHandle;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import android.provider.Settings;
import android.util.TypedValue;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
import com.cherish.settings.preferences.CustomSeekBarPreference;
import com.cherish.settings.preferences.SystemSettingListPreference;
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
public class EdgeLightningSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static String KEY_DURATION = "ambient_notification_light_duration";
private static String KEY_REPEATS = "ambient_notification_light_repeats";
private static String KEY_TIMEOUT = "ambient_notification_light_timeout";
private static String KEY_COLOR_MODE = "ambient_notification_color_mode";
private static String KEY_COLOR = "ambient_notification_light_color";
private CustomSeekBarPreference mDurationPref;
private CustomSeekBarPreference mRepeatsPref;
private SystemSettingListPreference mTimeoutPref;
private SystemSettingListPreference mColorModePref;
private ColorPickerPreference mColorPref;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.edge_lightning_settings);
final ContentResolver resolver = getContentResolver();
final int accentColor = getAccentColor();
mDurationPref = (CustomSeekBarPreference) findPreference(KEY_DURATION);
int value = Settings.System.getIntForUser(resolver,
KEY_DURATION, 2, UserHandle.USER_CURRENT);
mDurationPref.setValue(value);
mDurationPref.setOnPreferenceChangeListener(this);
mRepeatsPref = (CustomSeekBarPreference) findPreference(KEY_REPEATS);
int repeats = Settings.System.getIntForUser(resolver,
KEY_REPEATS, 0, UserHandle.USER_CURRENT);
mRepeatsPref.setValue(repeats);
mRepeatsPref.setOnPreferenceChangeListener(this);
mTimeoutPref = (SystemSettingListPreference) findPreference(KEY_TIMEOUT);
value = Settings.System.getIntForUser(resolver,
KEY_TIMEOUT, accentColor, UserHandle.USER_CURRENT);
mTimeoutPref.setValue(Integer.toString(value));
mTimeoutPref.setSummary(mTimeoutPref.getEntry());
mTimeoutPref.setOnPreferenceChangeListener(this);
updateTimeoutEnablement(repeats);
mColorPref = (ColorPickerPreference) findPreference(KEY_COLOR);
value = Settings.System.getIntForUser(resolver,
KEY_COLOR, accentColor, UserHandle.USER_CURRENT);
mColorPref.setDefaultColor(accentColor);
String colorHex = String.format("#%08x", (0xFFFFFFFF & value));
if (value == accentColor) {
mColorPref.setSummary(R.string.default_string);
} else {
mColorPref.setSummary(colorHex);
}
mColorPref.setNewPreviewColor(value);
mColorPref.setOnPreferenceChangeListener(this);
mColorModePref = (SystemSettingListPreference) findPreference(KEY_COLOR_MODE);
value = Settings.System.getIntForUser(resolver,
KEY_COLOR_MODE, 0, UserHandle.USER_CURRENT);
mColorModePref.setValue(Integer.toString(value));
mColorModePref.setSummary(mColorModePref.getEntry());
mColorModePref.setOnPreferenceChangeListener(this);
mColorPref.setEnabled(value == 3);
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
final ContentResolver resolver = getContentResolver();
if (preference == mDurationPref) {
int value = (Integer) newValue;
Settings.System.putIntForUser(resolver,
KEY_DURATION, value, UserHandle.USER_CURRENT);
return true;
} else if (preference == mRepeatsPref) {
int value = (Integer) newValue;
Settings.System.putIntForUser(resolver,
KEY_REPEATS, value, UserHandle.USER_CURRENT);
updateTimeoutEnablement(value);
return true;
} else if (preference == mTimeoutPref) {
int value = Integer.valueOf((String) newValue);
int index = mTimeoutPref.findIndexOfValue((String) newValue);
mTimeoutPref.setSummary(mTimeoutPref.getEntries()[index]);
Settings.System.putIntForUser(resolver,
KEY_TIMEOUT, value, UserHandle.USER_CURRENT);
return true;
} else if (preference == mColorModePref) {
int value = Integer.valueOf((String) newValue);
int index = mColorModePref.findIndexOfValue((String) newValue);
mColorModePref.setSummary(mColorModePref.getEntries()[index]);
Settings.System.putIntForUser(resolver,
KEY_COLOR_MODE, value, UserHandle.USER_CURRENT);
mColorPref.setEnabled(value == 3);
return true;
} else if (preference == mColorPref) {
int accentColor = getAccentColor();
String hex = ColorPickerPreference.convertToARGB(
Integer.valueOf(String.valueOf(newValue)));
if (hex.equals(String.format("#%08x", (0xFFFFFFFF & accentColor)))) {
preference.setSummary(R.string.default_string);
} else {
preference.setSummary(hex);
}
int color = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putIntForUser(resolver,
KEY_COLOR, color, UserHandle.USER_CURRENT);
return true;
}
return false;
}
private int getAccentColor() {
final TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.colorAccent, value, true);
return value.data;
}
private void updateTimeoutEnablement(int repeats) {
if (repeats == 0) {
int value = Settings.System.getIntForUser(getContentResolver(),
KEY_TIMEOUT, 0, UserHandle.USER_CURRENT);
mTimeoutPref.setValue(Integer.toString(value));
mTimeoutPref.setSummary(mTimeoutPref.getEntry());
mTimeoutPref.setEnabled(true);
} else {
mTimeoutPref.setSummary(R.string.set_to_zero);
mTimeoutPref.setEnabled(false);
}
}
}

View File

@@ -43,7 +43,9 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
private static final String PREF_FLASH_ON_CALL = "flashlight_on_call";
private static final String PREF_FLASH_ON_CALL_DND = "flashlight_on_call_ignore_dnd";
private static final String PREF_FLASH_ON_CALL_RATE = "flashlight_on_call_rate";
private static final String KEY_EDGE_LIGHTNING = "pulse_ambient_light";
private SystemSettingMasterSwitchPreference mEdgeLightning;
private SystemSettingListPreference mFlashOnCall;
private SystemSettingSwitchPreference mFlashOnCallIgnoreDND;
private CustomSeekBarPreference mFlashOnCallRate;
@@ -79,6 +81,13 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
mFlashOnCall = (SystemSettingListPreference)
findPreference(PREF_FLASH_ON_CALL);
mFlashOnCall.setOnPreferenceChangeListener(this);
mEdgeLightning = (SystemSettingMasterSwitchPreference)
findPreference(KEY_EDGE_LIGHTNING);
boolean enabled = Settings.System.getIntForUser(resolver,
KEY_EDGE_LIGHTNING, 0, UserHandle.USER_CURRENT) == 1;
mEdgeLightning.setChecked(enabled);
mEdgeLightning.setOnPreferenceChangeListener(this);
mChargingLeds = (Preference) findPreference("charging_light");
if (mChargingLeds != null
@@ -104,6 +113,11 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
Settings.System.putInt(resolver,
Settings.System.FLASHLIGHT_ON_CALL_RATE, value);
return true;
} else if (preference == mEdgeLightning) {
boolean value = (Boolean) newValue;
Settings.System.putIntForUser(resolver, KEY_EDGE_LIGHTNING,
value ? 1 : 0, UserHandle.USER_CURRENT);
return true;
}
return false;
}