Cherish:Add ambient edge lightning settings
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
170
src/com/cherish/settings/fragments/EdgeLightningSettings.java
Normal file
170
src/com/cherish/settings/fragments/EdgeLightningSettings.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user