@/SKULSHADY - Clean up and adapted for A11 SDB: improvise the enabling/disabling of colorpicker preference to avoid fc Co-authored-by: maxwen <max.weninger@gmail.com> Co-authored-by: Ido Ben-Hur <idoybh2@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
193 lines
8.9 KiB
Java
193 lines
8.9 KiB
Java
package com.cherish.settings.fragments;
|
|
|
|
import com.android.internal.logging.nano.MetricsProto;
|
|
|
|
import android.app.AlertDialog;
|
|
import android.app.Dialog;
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.graphics.Color;
|
|
import android.os.Bundle;
|
|
import android.os.UserHandle;
|
|
import android.content.ContentResolver;
|
|
import com.android.settings.R;
|
|
import android.content.res.Resources;
|
|
import androidx.preference.Preference;
|
|
import androidx.preference.Preference.OnPreferenceChangeListener;
|
|
import androidx.preference.PreferenceCategory;
|
|
import androidx.preference.PreferenceScreen;
|
|
import android.provider.Settings;
|
|
import androidx.preference.ListPreference;
|
|
|
|
import com.android.settings.SettingsPreferenceFragment;
|
|
import com.android.settings.search.BaseSearchIndexProvider;
|
|
import com.android.settingslib.search.SearchIndexable;
|
|
import android.provider.SearchIndexableResource;
|
|
import com.cherish.settings.preferences.SystemSettingMasterSwitchPreference;
|
|
import com.cherish.settings.preferences.SystemSettingSeekBarPreference;
|
|
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
|
import com.cherish.settings.preferences.SystemSettingListPreference;
|
|
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
|
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
|
import com.android.internal.util.cherish.CherishUtils;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
|
public class NotificationSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener{
|
|
|
|
private static final String INCALL_VIB_OPTIONS = "incall_vib_options";
|
|
private static final String ALERT_SLIDER_PREF = "alert_slider_notifications";
|
|
|
|
private static final String AMBIENT_LIGHT_COLOR = "ambient_notification_color_mode";
|
|
private static final String AMBIENT_LIGHT_CUSTOM_COLOR = "ambient_notification_light_color";
|
|
private static final String AMBIENT_LIGHT_DURATION = "ambient_notification_light_duration";
|
|
private static final String AMBIENT_LIGHT_REPEAT_COUNT = "ambient_notification_light_repeats";
|
|
|
|
private SystemSettingListPreference mEdgeLightColorMode;
|
|
private ColorPickerPreference mEdgeLightColor;
|
|
private CustomSeekBarPreference mEdgeLightDuration;
|
|
private CustomSeekBarPreference mEdgeLightRepeatCount;
|
|
|
|
private Preference mChargingLeds;
|
|
private Preference mAlertSlider;
|
|
@Override
|
|
public void onCreate(Bundle icicle) {
|
|
super.onCreate(icicle);
|
|
|
|
addPreferencesFromResource(R.xml.cherish_settings_notifications);
|
|
ContentResolver resolver = getActivity().getContentResolver();
|
|
final PreferenceScreen prefScreen = getPreferenceScreen();
|
|
final Resources res = getResources();
|
|
|
|
mAlertSlider = (Preference) prefScreen.findPreference(ALERT_SLIDER_PREF);
|
|
boolean mAlertSliderAvailable = res.getBoolean(
|
|
com.android.internal.R.bool.config_hasAlertSlider);
|
|
if (!mAlertSliderAvailable)
|
|
prefScreen.removePreference(mAlertSlider);
|
|
|
|
mChargingLeds = (Preference) findPreference("charging_light");
|
|
if (mChargingLeds != null
|
|
&& !getResources().getBoolean(
|
|
com.android.internal.R.bool.config_intrusiveBatteryLed)) {
|
|
prefScreen.removePreference(mChargingLeds);
|
|
}
|
|
|
|
Context context = getContext();
|
|
|
|
mEdgeLightColorMode = (SystemSettingListPreference) findPreference(AMBIENT_LIGHT_COLOR);
|
|
int edgeLightColorMode = Settings.System.getIntForUser(getContentResolver(),
|
|
Settings.System.NOTIFICATION_PULSE_COLOR_MODE, 0, UserHandle.USER_CURRENT);
|
|
mEdgeLightColorMode.setValue(String.valueOf(edgeLightColorMode));
|
|
mEdgeLightColorMode.setSummary(mEdgeLightColorMode.getEntry());
|
|
mEdgeLightColorMode.setOnPreferenceChangeListener(this);
|
|
|
|
mEdgeLightColor = (ColorPickerPreference) findPreference(AMBIENT_LIGHT_CUSTOM_COLOR);
|
|
int edgeLightColor = Settings.System.getInt(getContentResolver(),
|
|
Settings.System.NOTIFICATION_PULSE_COLOR, 0xFFFFFFFF);
|
|
mEdgeLightColor.setNewPreviewColor(edgeLightColor);
|
|
String edgeLightColorHex = String.format("#%08x", (0xFFFFFFFF & edgeLightColor));
|
|
if (edgeLightColorHex.equals("#ffffffff")) {
|
|
mEdgeLightColor.setSummary(R.string.default_string);
|
|
} else {
|
|
mEdgeLightColor.setSummary(edgeLightColorHex);
|
|
}
|
|
mEdgeLightColor.setOnPreferenceChangeListener(this);
|
|
|
|
mEdgeLightDuration = (CustomSeekBarPreference) findPreference(AMBIENT_LIGHT_DURATION);
|
|
int lightDuration = Settings.System.getIntForUser(getContentResolver(),
|
|
Settings.System.NOTIFICATION_PULSE_DURATION, 2, UserHandle.USER_CURRENT);
|
|
mEdgeLightDuration.setValue(lightDuration);
|
|
mEdgeLightDuration.setOnPreferenceChangeListener(this);
|
|
|
|
mEdgeLightRepeatCount = (CustomSeekBarPreference) findPreference(AMBIENT_LIGHT_REPEAT_COUNT);
|
|
int edgeLightRepeatCount = Settings.System.getIntForUser(getContentResolver(),
|
|
Settings.System.NOTIFICATION_PULSE_REPEATS, 0, UserHandle.USER_CURRENT);
|
|
mEdgeLightRepeatCount.setValue(edgeLightRepeatCount);
|
|
mEdgeLightRepeatCount.setOnPreferenceChangeListener(this);
|
|
|
|
PreferenceCategory incallVibCategory = (PreferenceCategory) findPreference(INCALL_VIB_OPTIONS);
|
|
if (!CherishUtils.isVoiceCapable(getActivity())) {
|
|
prefScreen.removePreference(incallVibCategory);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
ContentResolver resolver = getActivity().getContentResolver();
|
|
if (preference == mEdgeLightColorMode) {
|
|
int edgeLightColorMode = Integer.valueOf((String) newValue);
|
|
int index = mEdgeLightColorMode.findIndexOfValue((String) newValue);
|
|
Settings.System.putIntForUser(getContentResolver(),
|
|
Settings.System.NOTIFICATION_PULSE_COLOR_MODE, edgeLightColorMode, UserHandle.USER_CURRENT);
|
|
mEdgeLightColorMode.setSummary(mEdgeLightColorMode.getEntries()[index]);
|
|
if (edgeLightColorMode == 3) {
|
|
mEdgeLightColor.setEnabled(true);
|
|
} else {
|
|
mEdgeLightColor.setEnabled(false);
|
|
}
|
|
return true;
|
|
} else if (preference == mEdgeLightColor) {
|
|
String hex = ColorPickerPreference.convertToARGB(
|
|
Integer.valueOf(String.valueOf(newValue)));
|
|
if (hex.equals("#ffffffff")) {
|
|
preference.setSummary(R.string.default_string);
|
|
} else {
|
|
preference.setSummary(hex);
|
|
}
|
|
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
|
Settings.System.putInt(getContentResolver(),
|
|
Settings.System.NOTIFICATION_PULSE_COLOR, intHex);
|
|
return true;
|
|
} else if (preference == mEdgeLightDuration) {
|
|
int value = (Integer) newValue;
|
|
Settings.System.putIntForUser(getContentResolver(),
|
|
Settings.System.NOTIFICATION_PULSE_DURATION, value, UserHandle.USER_CURRENT);
|
|
return true;
|
|
} else if (preference == mEdgeLightRepeatCount) {
|
|
int value = (Integer) newValue;
|
|
Settings.System.putIntForUser(getContentResolver(),
|
|
Settings.System.NOTIFICATION_PULSE_REPEATS, value, UserHandle.USER_CURRENT);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public int getMetricsCategory() {
|
|
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
|
}
|
|
|
|
/**
|
|
* For Search.
|
|
*/
|
|
|
|
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
new BaseSearchIndexProvider() {
|
|
|
|
@Override
|
|
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
|
boolean enabled) {
|
|
ArrayList<SearchIndexableResource> result =
|
|
new ArrayList<SearchIndexableResource>();
|
|
SearchIndexableResource sir = new SearchIndexableResource(context);
|
|
sir.xmlResId = R.xml.cherish_settings_notifications;
|
|
result.add(sir);
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
public List<String> getNonIndexableKeys(Context context) {
|
|
List<String> keys = super.getNonIndexableKeys(context);
|
|
final Resources res = context.getResources();
|
|
boolean mAlertSliderAvailable = res.getBoolean(
|
|
com.android.internal.R.bool.config_hasAlertSlider);
|
|
if (!mAlertSliderAvailable)
|
|
keys.add(ALERT_SLIDER_PREF);
|
|
return keys;
|
|
}
|
|
};
|
|
}
|