Cherish:Intitial for Android 11

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Hưng Phan
2020-09-26 12:29:26 +07:00
parent e1061bf1a5
commit e6308bab52
59 changed files with 20 additions and 9500 deletions

View File

@@ -34,8 +34,6 @@ import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.util.cherish.AwesomeAnimationHelper;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
@@ -48,39 +46,6 @@ import java.util.HashSet;
import java.util.List;
public class AnimationsSettings extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
private static final String ANIMATION_DURATION = "animation_controls_duration";
private static final String ACTIVITY_OPEN = "activity_open";
private static final String ACTIVITY_CLOSE = "activity_close";
private static final String TASK_OPEN = "task_open";
private static final String TASK_OPEN_BEHIND = "task_open_behind";
private static final String TASK_CLOSE = "task_close";
private static final String TASK_MOVE_TO_FRONT = "task_move_to_front";
private static final String TASK_MOVE_TO_BACK = "task_move_to_back";
private static final String WALLPAPER_OPEN = "wallpaper_open";
private static final String WALLPAPER_CLOSE = "wallpaper_close";
private static final String WALLPAPER_INTRA_OPEN = "wallpaper_intra_open";
private static final String WALLPAPER_INTRA_CLOSE = "wallpaper_intra_close";
private static final String POWER_MENU_ANIMATIONS = "power_menu_animations";
private CustomSeekBarPreference mAnimDuration;
private ListPreference mPowerMenuAnimations;
ListPreference mActivityOpenPref;
ListPreference mActivityClosePref;
ListPreference mTaskOpenPref;
ListPreference mTaskOpenBehind;
ListPreference mTaskClosePref;
ListPreference mTaskMoveToFrontPref;
ListPreference mTaskMoveToBackPref;
ListPreference mWallpaperOpen;
ListPreference mWallpaperClose;
ListPreference mWallpaperIntraOpen;
ListPreference mWallpaperIntraClose;
private int[] mAnimations;
private String[] mAnimationsStrings;
private String[] mAnimationsNum;
@Override
public void onCreate(Bundle icicle) {
@@ -88,209 +53,13 @@ public class AnimationsSettings extends SettingsPreferenceFragment implements On
addPreferencesFromResource(R.xml.cherish_settings_animations);
ContentResolver resolver = getActivity().getContentResolver();
mAnimDuration = (CustomSeekBarPreference) findPreference(ANIMATION_DURATION);
int animdef = Settings.Global.getInt(resolver,
Settings.Global.ANIMATION_CONTROLS_DURATION, 0);
mAnimDuration.setValue(animdef);
mAnimDuration.setOnPreferenceChangeListener(this);
mAnimations = AwesomeAnimationHelper.getAnimationsList();
int animqty = mAnimations.length;
mAnimationsStrings = new String[animqty];
mAnimationsNum = new String[animqty];
for (int i = 0; i < animqty; i++) {
mAnimationsStrings[i] = AwesomeAnimationHelper.getProperName(getActivity().getApplicationContext(), mAnimations[i]);
mAnimationsNum[i] = String.valueOf(mAnimations[i]);
}
mActivityOpenPref = (ListPreference) findPreference(ACTIVITY_OPEN);
mActivityOpenPref.setSummary(getProperSummary(mActivityOpenPref));
mActivityOpenPref.setEntries(mAnimationsStrings);
mActivityOpenPref.setEntryValues(mAnimationsNum);
mActivityOpenPref.setOnPreferenceChangeListener(this);
mActivityClosePref = (ListPreference) findPreference(ACTIVITY_CLOSE);
mActivityClosePref.setSummary(getProperSummary(mActivityClosePref));
mActivityClosePref.setEntries(mAnimationsStrings);
mActivityClosePref.setEntryValues(mAnimationsNum);
mActivityClosePref.setOnPreferenceChangeListener(this);
mTaskOpenPref = (ListPreference) findPreference(TASK_OPEN);
mTaskOpenPref.setSummary(getProperSummary(mTaskOpenPref));
mTaskOpenPref.setEntries(mAnimationsStrings);
mTaskOpenPref.setEntryValues(mAnimationsNum);
mTaskOpenPref.setOnPreferenceChangeListener(this);
mTaskOpenBehind = (ListPreference) findPreference(TASK_OPEN_BEHIND);
mTaskOpenBehind.setSummary(getProperSummary(mTaskOpenBehind));
mTaskOpenBehind.setEntries(mAnimationsStrings);
mTaskOpenBehind.setEntryValues(mAnimationsNum);
mTaskOpenBehind.setOnPreferenceChangeListener(this);
mTaskClosePref = (ListPreference) findPreference(TASK_CLOSE);
mTaskClosePref.setSummary(getProperSummary(mTaskClosePref));
mTaskClosePref.setEntries(mAnimationsStrings);
mTaskClosePref.setEntryValues(mAnimationsNum);
mTaskClosePref.setOnPreferenceChangeListener(this);
mTaskMoveToFrontPref = (ListPreference) findPreference(TASK_MOVE_TO_FRONT);
mTaskMoveToFrontPref.setSummary(getProperSummary(mTaskMoveToFrontPref));
mTaskMoveToFrontPref.setEntries(mAnimationsStrings);
mTaskMoveToFrontPref.setEntryValues(mAnimationsNum);
mTaskMoveToFrontPref.setOnPreferenceChangeListener(this);
mTaskMoveToBackPref = (ListPreference) findPreference(TASK_MOVE_TO_BACK);
mTaskMoveToBackPref.setSummary(getProperSummary(mTaskMoveToBackPref));
mTaskMoveToBackPref.setEntries(mAnimationsStrings);
mTaskMoveToBackPref.setEntryValues(mAnimationsNum);
mTaskMoveToBackPref.setOnPreferenceChangeListener(this);
mWallpaperOpen = (ListPreference) findPreference(WALLPAPER_OPEN);
mWallpaperOpen.setSummary(getProperSummary(mWallpaperOpen));
mWallpaperOpen.setEntries(mAnimationsStrings);
mWallpaperOpen.setEntryValues(mAnimationsNum);
mWallpaperOpen.setOnPreferenceChangeListener(this);
mWallpaperClose = (ListPreference) findPreference(WALLPAPER_CLOSE);
mWallpaperClose.setSummary(getProperSummary(mWallpaperClose));
mWallpaperClose.setEntries(mAnimationsStrings);
mWallpaperClose.setEntryValues(mAnimationsNum);
mWallpaperClose.setOnPreferenceChangeListener(this);
mWallpaperIntraOpen = (ListPreference) findPreference(WALLPAPER_INTRA_OPEN);
mWallpaperIntraOpen.setSummary(getProperSummary(mWallpaperIntraOpen));
mWallpaperIntraOpen.setEntries(mAnimationsStrings);
mWallpaperIntraOpen.setEntryValues(mAnimationsNum);
mWallpaperIntraOpen.setOnPreferenceChangeListener(this);
mWallpaperIntraClose = (ListPreference) findPreference(WALLPAPER_INTRA_CLOSE);
mWallpaperIntraClose.setSummary(getProperSummary(mWallpaperIntraClose));
mWallpaperIntraClose.setEntries(mAnimationsStrings);
mWallpaperIntraClose.setEntryValues(mAnimationsNum);
mWallpaperIntraClose.setOnPreferenceChangeListener(this);
mPowerMenuAnimations = (ListPreference) findPreference(POWER_MENU_ANIMATIONS);
mPowerMenuAnimations.setValue(String.valueOf(Settings.System.getInt(
getContentResolver(), Settings.System.POWER_MENU_ANIMATIONS, 0)));
mPowerMenuAnimations.setSummary(mPowerMenuAnimations.getEntry());
mPowerMenuAnimations.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mAnimDuration) {
int value = (Integer) newValue;
Settings.Global.putInt(resolver,
Settings.Global.ANIMATION_CONTROLS_DURATION, value);
return true;
} else if (preference == mActivityOpenPref) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[0], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mActivityClosePref) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[1], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mTaskOpenPref) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[2], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mTaskClosePref) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[3], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mTaskMoveToFrontPref) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[4], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mTaskMoveToBackPref) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[5], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mWallpaperOpen) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[6], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mWallpaperClose) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[7], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mWallpaperIntraOpen) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[8], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mWallpaperIntraClose) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[9], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mTaskOpenBehind) {
int val = Integer.parseInt((String) newValue);
Settings.Global.putInt(resolver,
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[10], val);
preference.setSummary(getProperSummary(preference));
return true;
} else if (preference == mPowerMenuAnimations) {
Settings.System.putInt(getContentResolver(), Settings.System.POWER_MENU_ANIMATIONS,
Integer.valueOf((String) newValue));
mPowerMenuAnimations.setValue(String.valueOf(newValue));
mPowerMenuAnimations.setSummary(mPowerMenuAnimations.getEntry());
return true;
}
return false;
}
private String getProperSummary(Preference preference) {
String mString = "";
if (preference == mActivityOpenPref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[0];
} else if (preference == mActivityClosePref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[1];
} else if (preference == mTaskOpenPref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[2];
} else if (preference == mTaskClosePref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[3];
} else if (preference == mTaskMoveToFrontPref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[4];
} else if (preference == mTaskMoveToBackPref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[5];
} else if (preference == mWallpaperOpen) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[6];
} else if (preference == mWallpaperClose) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[7];
} else if (preference == mWallpaperIntraOpen) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[8];
} else if (preference == mWallpaperIntraClose) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[9];
} else if (preference == mTaskOpenBehind) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[10];
}
int mNum = Settings.Global.getInt(getActivity().getContentResolver(),
mString, 0);
return mAnimationsStrings[mNum];
}
@Override
public int getMetricsCategory() {

View File

@@ -1,61 +0,0 @@
/*
* Copyright (C) 2014-2016 The Dirty Unicorns 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.Context;
import android.content.ContentResolver;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.Utils;
public class AudioPanelSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.audio_panel);
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
@Override
public void onResume() {
super.onResume();
}
public boolean onPreferenceChange(Preference preference, Object objValue) {
return true;
}
}

View File

@@ -36,67 +36,12 @@ import net.margaritov.preference.colorpicker.ColorPickerPreference;
public class BatteryLightSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private ColorPickerPreference mLowColor;
private ColorPickerPreference mMediumColor;
private ColorPickerPreference mFullColor;
private ColorPickerPreference mReallyFullColor;
private SystemSettingSwitchPreference mLowBatteryBlinking;
private PreferenceCategory mColorCategory;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.battery_light_settings);
PreferenceScreen prefSet = getPreferenceScreen();
mColorCategory = (PreferenceCategory) findPreference("battery_light_cat");
mLowBatteryBlinking = (SystemSettingSwitchPreference)prefSet.findPreference("battery_light_low_blinking");
if (getResources().getBoolean(
com.android.internal.R.bool.config_ledCanPulse)) {
mLowBatteryBlinking.setChecked(Settings.System.getIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_LOW_BLINKING, 0, UserHandle.USER_CURRENT) == 1);
mLowBatteryBlinking.setOnPreferenceChangeListener(this);
} else {
prefSet.removePreference(mLowBatteryBlinking);
}
if (getResources().getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed)) {
int color = Settings.System.getIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_LOW_COLOR, 0xFFFF0000,
UserHandle.USER_CURRENT);
mLowColor = (ColorPickerPreference) findPreference("battery_light_low_color");
mLowColor.setAlphaSliderEnabled(false);
mLowColor.setNewPreviewColor(color);
mLowColor.setOnPreferenceChangeListener(this);
color = Settings.System.getIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_MEDIUM_COLOR, 0xFFFFFF00,
UserHandle.USER_CURRENT);
mMediumColor = (ColorPickerPreference) findPreference("battery_light_medium_color");
mMediumColor.setAlphaSliderEnabled(false);
mMediumColor.setNewPreviewColor(color);
mMediumColor.setOnPreferenceChangeListener(this);
color = Settings.System.getIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_FULL_COLOR, 0xFFFFFF00,
UserHandle.USER_CURRENT);
mFullColor = (ColorPickerPreference) findPreference("battery_light_full_color");
mFullColor.setAlphaSliderEnabled(false);
mFullColor.setNewPreviewColor(color);
mFullColor.setOnPreferenceChangeListener(this);
color = Settings.System.getIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_REALLYFULL_COLOR, 0xFF00FF00,
UserHandle.USER_CURRENT);
mReallyFullColor = (ColorPickerPreference) findPreference("battery_light_reallyfull_color");
mReallyFullColor.setAlphaSliderEnabled(false);
mReallyFullColor.setNewPreviewColor(color);
mReallyFullColor.setOnPreferenceChangeListener(this);
} else {
prefSet.removePreference(mColorCategory);
}
}
@Override
@@ -105,38 +50,7 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference.equals(mLowColor)) {
int color = ((Integer) newValue).intValue();
Settings.System.putIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_LOW_COLOR, color,
UserHandle.USER_CURRENT);
return true;
} else if (preference.equals(mMediumColor)) {
int color = ((Integer) newValue).intValue();
Settings.System.putIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_MEDIUM_COLOR, color,
UserHandle.USER_CURRENT);
return true;
} else if (preference.equals(mFullColor)) {
int color = ((Integer) newValue).intValue();
Settings.System.putIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_FULL_COLOR, color,
UserHandle.USER_CURRENT);
return true;
} else if (preference.equals(mReallyFullColor)) {
int color = ((Integer) newValue).intValue();
Settings.System.putIntForUser(getContentResolver(),
Settings.System.BATTERY_LIGHT_REALLYFULL_COLOR, color,
UserHandle.USER_CURRENT);
return true;
} else if (preference == mLowBatteryBlinking) {
boolean value = (Boolean) newValue;
Settings.System.putIntForUser(getActivity().getContentResolver(),
Settings.System.BATTERY_LIGHT_LOW_BLINKING, value ? 1 : 0,
UserHandle.USER_CURRENT);
mLowBatteryBlinking.setChecked(value);
return true;
}
return false;
}
}

View File

@@ -1,303 +0,0 @@
/*
* Copyright (C) 2017-2018 The Dirty Unicorns 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.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import androidx.preference.ListPreference;
import androidx.preference.SwitchPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.Preference.OnPreferenceChangeListener;
import android.provider.Settings;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
public class ClockSettings extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener {
private static final String STATUS_BAR_CLOCK_SECONDS = "status_bar_clock_seconds";
private static final String STATUS_BAR_CLOCK_STYLE = "statusbar_clock_style";
private static final String STATUS_BAR_AM_PM = "status_bar_am_pm";
private static final String STATUS_BAR_CLOCK_DATE_DISPLAY = "clock_date_display";
private static final String STATUS_BAR_CLOCK_DATE_STYLE = "clock_date_style";
private static final String STATUS_BAR_CLOCK_DATE_FORMAT = "clock_date_format";
private static final String STATUS_BAR_CLOCK_DATE_POSITION = "statusbar_clock_date_position";
public static final int CLOCK_DATE_STYLE_LOWERCASE = 1;
public static final int CLOCK_DATE_STYLE_UPPERCASE = 2;
private static final int CUSTOM_CLOCK_DATE_FORMAT_INDEX = 18;
private SystemSettingSwitchPreference mStatusBarSecondsShow;
private ListPreference mStatusBarClock;
private ListPreference mStatusBarAmPm;
private ListPreference mClockDateDisplay;
private ListPreference mClockDateStyle;
private ListPreference mClockDateFormat;
private ListPreference mClockDatePosition;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.cherish_settings_clock);
PreferenceScreen prefSet = getPreferenceScreen();
ContentResolver resolver = getActivity().getContentResolver();
mStatusBarSecondsShow = (SystemSettingSwitchPreference) findPreference(STATUS_BAR_CLOCK_SECONDS);
mStatusBarClock = (ListPreference) findPreference(STATUS_BAR_CLOCK_STYLE);
mStatusBarAmPm = (ListPreference) findPreference(STATUS_BAR_AM_PM);
mClockDateDisplay = (ListPreference) findPreference(STATUS_BAR_CLOCK_DATE_DISPLAY);
mClockDateStyle = (ListPreference) findPreference(STATUS_BAR_CLOCK_DATE_STYLE);
mClockDatePosition = (ListPreference) findPreference(STATUS_BAR_CLOCK_DATE_POSITION);
mStatusBarSecondsShow.setChecked((Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CLOCK_SECONDS, 0) == 1));
mStatusBarSecondsShow.setOnPreferenceChangeListener(this);
int clockStyle = Settings.System.getInt(resolver,
Settings.System.STATUSBAR_CLOCK_STYLE, 0);
mStatusBarClock.setValue(String.valueOf(clockStyle));
mStatusBarClock.setSummary(mStatusBarClock.getEntry());
mStatusBarClock.setOnPreferenceChangeListener(this);
if (DateFormat.is24HourFormat(getActivity())) {
mStatusBarAmPm.setEnabled(false);
mStatusBarAmPm.setSummary(R.string.status_bar_am_pm_info);
} else {
int statusBarAmPm = Settings.System.getInt(resolver,
Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, 2);
mStatusBarAmPm.setValue(String.valueOf(statusBarAmPm));
mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntry());
mStatusBarAmPm.setOnPreferenceChangeListener(this);
}
int clockDateDisplay = Settings.System.getInt(resolver,
Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, 0);
mClockDateDisplay.setValue(String.valueOf(clockDateDisplay));
mClockDateDisplay.setSummary(mClockDateDisplay.getEntry());
mClockDateDisplay.setOnPreferenceChangeListener(this);
int clockDateStyle = Settings.System.getInt(resolver,
Settings.System.STATUSBAR_CLOCK_DATE_STYLE, 0);
mClockDateStyle.setValue(String.valueOf(clockDateStyle));
mClockDateStyle.setSummary(mClockDateStyle.getEntry());
mClockDateStyle.setOnPreferenceChangeListener(this);
mClockDateFormat = (ListPreference) findPreference(STATUS_BAR_CLOCK_DATE_FORMAT);
mClockDateFormat.setOnPreferenceChangeListener(this);
String value = Settings.System.getString(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_FORMAT);
if (value == null || value.isEmpty()) {
value = "EEE";
}
int index = mClockDateFormat.findIndexOfValue((String) value);
if (index == -1) {
mClockDateFormat.setValueIndex(CUSTOM_CLOCK_DATE_FORMAT_INDEX);
} else {
mClockDateFormat.setValue(value);
}
parseClockDateFormats();
int clockDatePosition = Settings.System.getInt(resolver,
Settings.System.STATUSBAR_CLOCK_DATE_POSITION, 0);
mClockDatePosition.setValue(String.valueOf(clockDatePosition));
mClockDatePosition.setSummary(mClockDatePosition.getEntry());
mClockDatePosition.setOnPreferenceChangeListener(this);
setDateOptions();
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
@Override
public void onResume() {
super.onResume();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
AlertDialog dialog;
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mStatusBarSecondsShow) {
boolean value = (Boolean) newValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_CLOCK_SECONDS, value ? 1 : 0);
return true;
} else if (preference == mStatusBarClock) {
int clockStyle = Integer.parseInt((String) newValue);
int index = mStatusBarClock.findIndexOfValue((String) newValue);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_STYLE, clockStyle);
mStatusBarClock.setSummary(mStatusBarClock.getEntries()[index]);
return true;
} else if (preference == mStatusBarAmPm) {
int statusBarAmPm = Integer.valueOf((String) newValue);
int index = mStatusBarAmPm.findIndexOfValue((String) newValue);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, statusBarAmPm);
mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntries()[index]);
return true;
} else if (preference == mClockDateDisplay) {
int clockDateDisplay = Integer.valueOf((String) newValue);
int index = mClockDateDisplay.findIndexOfValue((String) newValue);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, clockDateDisplay);
mClockDateDisplay.setSummary(mClockDateDisplay.getEntries()[index]);
setDateOptions();
return true;
} else if (preference == mClockDateStyle) {
int clockDateStyle = Integer.valueOf((String) newValue);
int index = mClockDateStyle.findIndexOfValue((String) newValue);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_STYLE, clockDateStyle);
mClockDateStyle.setSummary(mClockDateStyle.getEntries()[index]);
parseClockDateFormats();
return true;
} else if (preference == mClockDateFormat) {
int index = mClockDateFormat.findIndexOfValue((String) newValue);
if (index == CUSTOM_CLOCK_DATE_FORMAT_INDEX) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle(R.string.clock_date_string_edittext_title);
alert.setMessage(R.string.clock_date_string_edittext_summary);
final EditText input = new EditText(getActivity());
String oldText = Settings.System.getString(
getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_FORMAT);
if (oldText != null) {
input.setText(oldText);
}
alert.setView(input);
alert.setPositiveButton(R.string.menu_save, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int whichButton) {
String value = input.getText().toString();
if (value.equals("")) {
return;
}
Settings.System.putString(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_FORMAT, value);
return;
}
});
alert.setNegativeButton(R.string.menu_cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int which) {
return;
}
});
dialog = alert.create();
dialog.show();
} else {
if ((String) newValue != null) {
Settings.System.putString(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_FORMAT, (String) newValue);
}
}
return true;
} else if (preference == mClockDatePosition) {
int val = Integer.parseInt((String) newValue);
int index = mClockDatePosition.findIndexOfValue((String) newValue);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_POSITION, val);
mClockDatePosition.setSummary(mClockDatePosition.getEntries()[index]);
parseClockDateFormats();
return true;
} else if (preference == mClockDatePosition) {
int val = Integer.parseInt((String) newValue);
int index = mClockDatePosition.findIndexOfValue((String) newValue);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_POSITION, val);
mClockDatePosition.setSummary(mClockDatePosition.getEntries()[index]);
parseClockDateFormats();
return true;
}
return false;
}
private void parseClockDateFormats() {
String[] dateEntries = getResources().getStringArray(R.array.clock_date_format_entries_values);
CharSequence parsedDateEntries[];
parsedDateEntries = new String[dateEntries.length];
Date now = new Date();
int lastEntry = dateEntries.length - 1;
int dateFormat = Settings.System.getInt(getActivity()
.getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_STYLE, 0);
for (int i = 0; i < dateEntries.length; i++) {
if (i == lastEntry) {
parsedDateEntries[i] = dateEntries[i];
} else {
String newDate;
CharSequence dateString = DateFormat.format(dateEntries[i], now);
if (dateFormat == CLOCK_DATE_STYLE_LOWERCASE) {
newDate = dateString.toString().toLowerCase();
} else if (dateFormat == CLOCK_DATE_STYLE_UPPERCASE) {
newDate = dateString.toString().toUpperCase();
} else {
newDate = dateString.toString();
}
parsedDateEntries[i] = newDate;
}
}
mClockDateFormat.setEntries(parsedDateEntries);
}
private void setDateOptions() {
int enableDateOptions = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, 0);
if (enableDateOptions == 0) {
mClockDateStyle.setEnabled(false);
mClockDateFormat.setEnabled(false);
mClockDatePosition.setEnabled(false);
} else {
mClockDateStyle.setEnabled(true);
mClockDateFormat.setEnabled(true);
mClockDatePosition.setEnabled(true);
}
}
}

View File

@@ -1,163 +0,0 @@
/*
* Copyright (C) 2020 CherishOS
*
* 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.app.AlertDialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.InputFilter;
import android.text.Spannable;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import android.widget.LinearLayout;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.util.cherish.CherishUtils;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.cherish.settings.preferences.SystemSettingListPreference;
public class CustomCarrierLabel extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener {
public static final String TAG = "CarrierLabel";
private static final String CUSTOM_CARRIER_LABEL = "custom_carrier_label";
private static final String KEY_CARRIER_LABEL = "status_bar_show_carrier";
private PreferenceScreen mCustomCarrierLabel;
private String mCustomCarrierLabelText;
private SystemSettingListPreference mShowCarrierLabel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContentResolver resolver = getActivity().getContentResolver();
addPreferencesFromResource(R.xml.custom_carrier_label);
PreferenceScreen prefSet = getPreferenceScreen();
mCustomCarrierLabel = (PreferenceScreen) findPreference(CUSTOM_CARRIER_LABEL);
updateCustomLabelTextSummary();
mShowCarrierLabel = (SystemSettingListPreference) findPreference(KEY_CARRIER_LABEL);
int showCarrierLabel = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_SHOW_CARRIER, 1);
CharSequence[] NonNotchEntries = { getResources().getString(R.string.show_carrier_disabled),
getResources().getString(R.string.show_carrier_keyguard),
getResources().getString(R.string.show_carrier_statusbar), getResources().getString(
R.string.show_carrier_enabled) };
CharSequence[] NotchEntries = { getResources().getString(R.string.show_carrier_disabled),
getResources().getString(R.string.show_carrier_keyguard) };
CharSequence[] NonNotchValues = {"0", "1" , "2", "3"};
CharSequence[] NotchValues = {"0", "1"};
mShowCarrierLabel.setEntries(CherishUtils.hasNotch(getActivity()) ? NotchEntries : NonNotchEntries);
mShowCarrierLabel.setEntryValues(CherishUtils.hasNotch(getActivity()) ? NotchValues : NonNotchValues);
mShowCarrierLabel.setValue(String.valueOf(showCarrierLabel));
mShowCarrierLabel.setSummary(mShowCarrierLabel.getEntry());
mShowCarrierLabel.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mShowCarrierLabel) {
int value = Integer.parseInt((String) newValue);
updateCarrierLabelSummary(value);
return true;
}
return false;
}
private void updateCarrierLabelSummary(int value) {
Resources res = getResources();
if (value == 0) {
// Carrier Label disabled
mShowCarrierLabel.setSummary(res.getString(R.string.show_carrier_disabled));
} else if (value == 1) {
mShowCarrierLabel.setSummary(res.getString(R.string.show_carrier_keyguard));
} else if (value == 2) {
mShowCarrierLabel.setSummary(res.getString(R.string.show_carrier_statusbar));
} else if (value == 3) {
mShowCarrierLabel.setSummary(res.getString(R.string.show_carrier_enabled));
}
}
public boolean onPreferenceTreeClick(Preference preference) {
ContentResolver resolver = getActivity().getContentResolver();
boolean value;
if (preference == mCustomCarrierLabel) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle(R.string.custom_carrier_label_title);
alert.setMessage(R.string.custom_carrier_label_explain);
LinearLayout container = new LinearLayout(getActivity());
container.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(55, 20, 55, 20);
final EditText input = new EditText(getActivity());
int maxLength = 25;
input.setLayoutParams(lp);
input.setGravity(android.view.Gravity.TOP| Gravity.START);
input.setText(TextUtils.isEmpty(mCustomCarrierLabelText) ? "" : mCustomCarrierLabelText);
input.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLength)});
container.addView(input);
alert.setView(container);
alert.setPositiveButton(getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = ((Spannable) input.getText()).toString().trim();
Settings.System.putString(resolver, Settings.System.CUSTOM_CARRIER_LABEL, value);
updateCustomLabelTextSummary();
Intent i = new Intent();
i.setAction(Intent.ACTION_CUSTOM_CARRIER_LABEL_CHANGED);
getActivity().sendBroadcast(i);
}
});
alert.setNegativeButton(getString(android.R.string.cancel), null);
alert.show();
return true;
}
return false;
}
private void updateCustomLabelTextSummary() {
mCustomCarrierLabelText = Settings.System.getString(
getContentResolver(), Settings.System.CUSTOM_CARRIER_LABEL);
if (TextUtils.isEmpty(mCustomCarrierLabelText)) {
mCustomCarrierLabel.setSummary(R.string.custom_carrier_label_notset);
} else {
mCustomCarrierLabel.setSummary(mCustomCarrierLabelText);
}
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}

View File

@@ -1,132 +0,0 @@
/*
* Copyright (C) 2020 CherishOS
*
* 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.Context;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
public class EdgePulse extends SettingsPreferenceFragment implements
OnPreferenceChangeListener {
private static final String PULSE_AMBIENT_LIGHT_COLOR_LEFT = "pulse_ambient_light_color_left";
private static final String PULSE_AMBIENT_LIGHT_COLOR_RIGHT = "pulse_ambient_light_color_right";
private static final String AMBIENT_NOTIFICATION_LIGHT_ENABLED = "ambient_notification_light_enabled";
private static final String AMBIENT_NOTIFICATION_LIGHT_HIDE_AOD = "ambient_notification_light_hide_aod";
private ColorPickerPreference mLeftEdgeLightColorPreference;
private ColorPickerPreference mRightEdgeLightColorPreference;
private SwitchPreference mAmbientNotifLight;
private SwitchPreference mAmbientContentHide;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.edgepulse_settings);
ContentResolver resolver = getActivity().getContentResolver();
PreferenceScreen prefScreen = getPreferenceScreen();
mLeftEdgeLightColorPreference = (ColorPickerPreference) findPreference(PULSE_AMBIENT_LIGHT_COLOR_LEFT);
mLeftEdgeLightColorPreference.setOnPreferenceChangeListener(this);
int leftEdgeLightColor = Settings.System.getInt(getContentResolver(),
Settings.System.PULSE_AMBIENT_LIGHT_COLOR_LEFT, 0xFF3980FF);
String leftEdgeLightColorHex = String.format("#%08x", (0xFF3980FF & leftEdgeLightColor));
if (leftEdgeLightColorHex.equals("#ff3980ff")) {
mLeftEdgeLightColorPreference.setSummary(R.string.default_string);
} else {
mLeftEdgeLightColorPreference.setSummary(leftEdgeLightColorHex);
}
mLeftEdgeLightColorPreference.setNewPreviewColor(leftEdgeLightColor);
mRightEdgeLightColorPreference = (ColorPickerPreference) findPreference(PULSE_AMBIENT_LIGHT_COLOR_RIGHT);
mRightEdgeLightColorPreference.setOnPreferenceChangeListener(this);
int rightEdgeLightColor = Settings.System.getInt(getContentResolver(),
Settings.System.PULSE_AMBIENT_LIGHT_COLOR_RIGHT, 0xFF3980FF);
String rightEdgeLightColorHex = String.format("#%08x", (0xFF3980FF & rightEdgeLightColor));
if (rightEdgeLightColorHex.equals("#ff3980ff")) {
mRightEdgeLightColorPreference.setSummary(R.string.default_string);
} else {
mRightEdgeLightColorPreference.setSummary(rightEdgeLightColorHex);
}
mRightEdgeLightColorPreference.setNewPreviewColor(rightEdgeLightColor);
mAmbientNotifLight = (SwitchPreference) findPreference(AMBIENT_NOTIFICATION_LIGHT_ENABLED);
mAmbientContentHide = (SwitchPreference) findPreference(AMBIENT_NOTIFICATION_LIGHT_HIDE_AOD);
boolean mAlwaysOnByDefault = getResources().getBoolean(com.android.internal.R.bool.config_dozeAlwaysOnEnabled);
boolean mAODDisabled = Settings.Secure.getIntForUser(resolver,
Settings.Secure.DOZE_ALWAYS_ON, mAlwaysOnByDefault ? 1 : 0,
UserHandle.USER_CURRENT) == 0;
if (!getResources().getBoolean(com.android.internal.R.bool.config_dozeAlwaysOnDisplayAvailable)) {
prefScreen.removePreference(mAmbientNotifLight);
prefScreen.removePreference(mAmbientContentHide);
} else if (!mAODDisabled) {
prefScreen.removePreference(mAmbientContentHide);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mLeftEdgeLightColorPreference) {
String hex = ColorPickerPreference.convertToARGB(
Integer.valueOf(String.valueOf(newValue)));
if (hex.equals("#ff3980ff")) {
preference.setSummary(R.string.default_string);
} else {
preference.setSummary(hex);
}
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putInt(getContentResolver(),
Settings.System.PULSE_AMBIENT_LIGHT_COLOR_LEFT, intHex);
return true;
} else if (preference == mRightEdgeLightColorPreference) {
String hex = ColorPickerPreference.convertToARGB(
Integer.valueOf(String.valueOf(newValue)));
if (hex.equals("#ff3980ff")) {
preference.setSummary(R.string.default_string);
} else {
preference.setSummary(hex);
}
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putInt(getContentResolver(),
Settings.System.PULSE_AMBIENT_LIGHT_COLOR_RIGHT, intHex);
return true;
}
return false;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright (C) 2020 The CherishOS 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.res.Resources;
import android.os.Bundle;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
public class FODIconPickerFragment extends SettingsPreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.cherish_settings_fod_picker);
getActivity().getActionBar().setTitle(R.string.fod_icon_picker_title);
mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.fod_icon_picker_footer);
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}

View File

@@ -1,342 +0,0 @@
/*
* Copyright (C) 2019 crDroid Android 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.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.cherish.settings.preferences.PackageListAdapter;
import com.cherish.settings.preferences.PackageListAdapter.PackageItem;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GamingMode extends SettingsPreferenceFragment
implements Preference.OnPreferenceClickListener {
private static final int DIALOG_GAMING_APPS = 1;
private static final String GAMING_MODE_HW_KEYS = "gaming_mode_hw_keys_toggle";
private SwitchPreference mHardwareKeysDisable;
private PackageListAdapter mPackageAdapter;
private PackageManager mPackageManager;
private PreferenceGroup mGamingPrefList;
private Preference mAddGamingPref;
private String mGamingPackageList;
private Map<String, Package> mGamingPackages;
private Context mContext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get launch-able applications
addPreferencesFromResource(R.xml.cherish_settings_gaming_mode);
mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.add_gaming_mode_package_summary);
final PreferenceScreen prefScreen = getPreferenceScreen();
mHardwareKeysDisable = (SwitchPreference) findPreference(GAMING_MODE_HW_KEYS);
mPackageManager = getPackageManager();
mPackageAdapter = new PackageListAdapter(getActivity());
mGamingPrefList = (PreferenceGroup) findPreference("gamingmode_applications");
mGamingPrefList.setOrderingAsAdded(false);
mGamingPackages = new HashMap<String, Package>();
mAddGamingPref = findPreference("add_gamingmode_packages");
mAddGamingPref.setOnPreferenceClickListener(this);
mContext = getActivity().getApplicationContext();
SettingsObserver observer = new SettingsObserver(new Handler(Looper.getMainLooper()));
observer.observe();
}
@Override
public void onResume() {
super.onResume();
refreshCustomApplicationPrefs();
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
@Override
public int getDialogMetricsCategory(int dialogId) {
if (dialogId == DIALOG_GAMING_APPS) {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
return 0;
}
/**
* Utility classes and supporting methods
*/
@Override
public Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final Dialog dialog;
final ListView list = new ListView(getActivity());
list.setAdapter(mPackageAdapter);
builder.setTitle(R.string.profile_choose_app);
builder.setView(list);
dialog = builder.create();
switch (id) {
case DIALOG_GAMING_APPS:
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Add empty application definition, the user will be able to edit it later
PackageItem info = (PackageItem) parent.getItemAtPosition(position);
addCustomApplicationPref(info.packageName, mGamingPackages);
dialog.cancel();
}
});
}
return dialog;
}
class SettingsObserver extends ContentObserver {
SettingsObserver(Handler handler) {
super(handler);
}
void observe() {
ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.GAMING_MODE_ACTIVE), false, this,
UserHandle.USER_ALL);
}
@Override
public void onChange(boolean selfChange, Uri uri) {
if (uri.equals(Settings.System.getUriFor(
Settings.System.GAMING_MODE_ACTIVE))) {
boolean enable = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.GAMING_MODE_ACTIVE, 0) == 1;
}
}
}
/**
* Application class
*/
private static class Package {
public String name;
/**
* Stores all the application values in one call
* @param name
*/
public Package(String name) {
this.name = name;
}
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(name);
return builder.toString();
}
public static Package fromString(String value) {
if (TextUtils.isEmpty(value)) {
return null;
}
try {
Package item = new Package(value);
return item;
} catch (NumberFormatException e) {
return null;
}
}
};
private void refreshCustomApplicationPrefs() {
if (!parsePackageList()) {
return;
}
// Add the Application Preferences
if (mGamingPrefList != null) {
mGamingPrefList.removeAll();
for (Package pkg : mGamingPackages.values()) {
try {
Preference pref = createPreferenceFromInfo(pkg);
mGamingPrefList.addPreference(pref);
} catch (PackageManager.NameNotFoundException e) {
// Do nothing
}
}
}
// Keep these at the top
mAddGamingPref.setOrder(0);
// Add 'add' options
mGamingPrefList.addPreference(mAddGamingPref);
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == mAddGamingPref) {
showDialog(DIALOG_GAMING_APPS);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.dialog_delete_title)
.setMessage(R.string.dialog_delete_message)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (preference == mGamingPrefList.findPreference(preference.getKey())) {
removeApplicationPref(preference.getKey(), mGamingPackages);
}
}
})
.setNegativeButton(android.R.string.cancel, null);
builder.show();
}
return true;
}
private void addCustomApplicationPref(String packageName, Map<String,Package> map) {
Package pkg = map.get(packageName);
if (pkg == null) {
pkg = new Package(packageName);
map.put(packageName, pkg);
savePackageList(false, map);
refreshCustomApplicationPrefs();
}
}
private Preference createPreferenceFromInfo(Package pkg)
throws PackageManager.NameNotFoundException {
PackageInfo info = mPackageManager.getPackageInfo(pkg.name,
PackageManager.GET_META_DATA);
Preference pref =
new Preference(getActivity());
pref.setKey(pkg.name);
pref.setTitle(info.applicationInfo.loadLabel(mPackageManager));
pref.setIcon(info.applicationInfo.loadIcon(mPackageManager));
pref.setPersistent(false);
pref.setOnPreferenceClickListener(this);
return pref;
}
private void removeApplicationPref(String packageName, Map<String,Package> map) {
if (map.remove(packageName) != null) {
savePackageList(false, map);
refreshCustomApplicationPrefs();
}
}
private boolean parsePackageList() {
boolean parsed = false;
final String gamingModeString = Settings.System.getString(getContentResolver(),
Settings.System.GAMING_MODE_VALUES);
if (!TextUtils.equals(mGamingPackageList, gamingModeString)) {
mGamingPackageList = gamingModeString;
mGamingPackages.clear();
parseAndAddToMap(gamingModeString, mGamingPackages);
parsed = true;
}
return parsed;
}
private void parseAndAddToMap(String baseString, Map<String,Package> map) {
if (baseString == null) {
return;
}
final String[] array = TextUtils.split(baseString, "\\|");
for (String item : array) {
if (TextUtils.isEmpty(item)) {
continue;
}
Package pkg = Package.fromString(item);
map.put(pkg.name, pkg);
}
}
private void savePackageList(boolean preferencesUpdated, Map<String,Package> map) {
String setting = map == mGamingPackages ? Settings.System.GAMING_MODE_VALUES : Settings.System.GAMING_MODE_DUMMY;
List<String> settings = new ArrayList<String>();
for (Package app : map.values()) {
settings.add(app.toString());
}
final String value = TextUtils.join("|", settings);
if (preferencesUpdated) {
if (TextUtils.equals(setting, Settings.System.GAMING_MODE_VALUES)) {
mGamingPackageList = value;
}
}
Settings.System.putString(getContentResolver(),
setting, value);
}
}

View File

@@ -1,51 +0,0 @@
/*
* Copyright (c) 2019 crDroid Android 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.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.internal.util.gaming.GamingModeController;
public class GamingModeReceiver extends BroadcastReceiver {
private static final String TAG = "GamingModeReceiver";
private static final boolean DEBUG = false;
public GamingModeReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null &&
intent.getAction().equals(GamingModeController.GAMING_MODE_TURN_OFF)) {
if (DEBUG) Log.d(TAG, "Received " + GamingModeController.GAMING_MODE_TURN_OFF);
Settings.System.putInt(context.getContentResolver(), Settings.System.GAMING_MODE_ACTIVE, 0);
} else if (intent.getAction() != null &&
intent.getAction().equals(GamingModeController.GAMING_MODE_TURN_ON)) {
if (DEBUG) Log.d(TAG, "Received " + GamingModeController.GAMING_MODE_TURN_ON);
Settings.System.putInt(context.getContentResolver(), Settings.System.GAMING_MODE_ACTIVE, 1);
}
}
}

View File

@@ -1,411 +0,0 @@
/*
* Copyright (C) 2014 The Nitrogen 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.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Bundle;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.cherish.settings.preferences.PackageListAdapter;
import com.cherish.settings.preferences.PackageListAdapter.PackageItem;
import android.provider.Settings;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HeadsUp extends SettingsPreferenceFragment
implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
private static final int DIALOG_STOPLIST_APPS = 0;
private static final int DIALOG_BLACKLIST_APPS = 1;
private static final String PREF_HEADS_UP_TIME_OUT = "heads_up_time_out";
private static final String PREF_HEADS_UP_SNOOZE_TIME = "heads_up_snooze_time";
private PackageListAdapter mPackageAdapter;
private PackageManager mPackageManager;
private PreferenceGroup mStoplistPrefList;
private PreferenceGroup mBlacklistPrefList;
private Preference mAddStoplistPref;
private Preference mAddBlacklistPref;
private ListPreference mHeadsUpTimeOut;
private ListPreference mHeadsUpSnoozeTime;
private String mStoplistPackageList;
private String mBlacklistPackageList;
private Map<String, Package> mStoplistPackages;
private Map<String, Package> mBlacklistPackages;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get launch-able applications
addPreferencesFromResource(R.xml.heads_up_settings);
mPackageManager = getPackageManager();
mPackageAdapter = new PackageListAdapter(getActivity());
mStoplistPrefList = (PreferenceGroup) findPreference("stoplist_applications");
mStoplistPrefList.setOrderingAsAdded(false);
mBlacklistPrefList = (PreferenceGroup) findPreference("blacklist_applications");
mBlacklistPrefList.setOrderingAsAdded(false);
mStoplistPackages = new HashMap<String, Package>();
mBlacklistPackages = new HashMap<String, Package>();
mAddStoplistPref = findPreference("add_stoplist_packages");
mAddBlacklistPref = findPreference("add_blacklist_packages");
mAddStoplistPref.setOnPreferenceClickListener(this);
mAddBlacklistPref.setOnPreferenceClickListener(this);
Resources systemUiResources;
try {
systemUiResources = getPackageManager().getResourcesForApplication("com.android.systemui");
} catch (Exception e) {
return;
}
int defaultTimeOut = systemUiResources.getInteger(systemUiResources.getIdentifier(
"com.android.systemui:integer/heads_up_notification_decay", null, null));
mHeadsUpTimeOut = (ListPreference) findPreference(PREF_HEADS_UP_TIME_OUT);
mHeadsUpTimeOut.setOnPreferenceChangeListener(this);
int headsUpTimeOut = Settings.System.getInt(getContentResolver(),
Settings.System.HEADS_UP_TIMEOUT, defaultTimeOut);
mHeadsUpTimeOut.setValue(String.valueOf(headsUpTimeOut));
updateHeadsUpTimeOutSummary(headsUpTimeOut);
int defaultSnooze = systemUiResources.getInteger(systemUiResources.getIdentifier(
"com.android.systemui:integer/heads_up_default_snooze_length_ms", null, null));
mHeadsUpSnoozeTime = (ListPreference) findPreference(PREF_HEADS_UP_SNOOZE_TIME);
mHeadsUpSnoozeTime.setOnPreferenceChangeListener(this);
int headsUpSnooze = Settings.System.getInt(getContentResolver(),
Settings.System.HEADS_UP_NOTIFICATION_SNOOZE, defaultSnooze);
mHeadsUpSnoozeTime.setValue(String.valueOf(headsUpSnooze));
updateHeadsUpSnoozeTimeSummary(headsUpSnooze);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mHeadsUpTimeOut) {
int headsUpTimeOut = Integer.valueOf((String) newValue);
Settings.System.putInt(getContentResolver(),
Settings.System.HEADS_UP_TIMEOUT,
headsUpTimeOut);
updateHeadsUpTimeOutSummary(headsUpTimeOut);
return true;
} else if (preference == mHeadsUpSnoozeTime) {
int headsUpSnooze = Integer.valueOf((String) newValue);
Settings.System.putInt(getContentResolver(),
Settings.System.HEADS_UP_NOTIFICATION_SNOOZE,
headsUpSnooze);
updateHeadsUpSnoozeTimeSummary(headsUpSnooze);
return true;
}
return false;
}
private void updateHeadsUpTimeOutSummary(int value) {
String summary = getResources().getString(R.string.heads_up_time_out_summary,
value / 1000);
mHeadsUpTimeOut.setSummary(summary);
}
private void updateHeadsUpSnoozeTimeSummary(int value) {
if (value == 0) {
mHeadsUpSnoozeTime.setSummary(getResources().getString(R.string.heads_up_snooze_disabled_summary));
} else if (value == 60000) {
mHeadsUpSnoozeTime.setSummary(getResources().getString(R.string.heads_up_snooze_summary_one_minute));
} else {
String summary = getResources().getString(R.string.heads_up_snooze_summary, value / 60 / 1000);
mHeadsUpSnoozeTime.setSummary(summary);
}
}
@Override
public void onResume() {
super.onResume();
refreshCustomApplicationPrefs();
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
@Override
public int getDialogMetricsCategory(int dialogId) {
if (dialogId == DIALOG_STOPLIST_APPS || dialogId == DIALOG_BLACKLIST_APPS ) {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
return 0;
}
/**
* Utility classes and supporting methods
*/
@Override
public Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final Dialog dialog;
final ListView list = new ListView(getActivity());
list.setAdapter(mPackageAdapter);
builder.setTitle(R.string.profile_choose_app);
builder.setView(list);
dialog = builder.create();
switch (id) {
case DIALOG_STOPLIST_APPS:
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Add empty application definition, the user will be able to edit it later
PackageItem info = (PackageItem) parent.getItemAtPosition(position);
addCustomApplicationPref(info.packageName, mStoplistPackages);
dialog.cancel();
}
});
break;
case DIALOG_BLACKLIST_APPS:
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
PackageItem info = (PackageItem) parent.getItemAtPosition(position);
addCustomApplicationPref(info.packageName, mBlacklistPackages);
dialog.cancel();
}
});
}
return dialog;
}
/**
* Application class
*/
private static class Package {
public String name;
/**
* Stores all the application values in one call
* @param name
*/
public Package(String name) {
this.name = name;
}
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(name);
return builder.toString();
}
public static Package fromString(String value) {
if (TextUtils.isEmpty(value)) {
return null;
}
try {
Package item = new Package(value);
return item;
} catch (NumberFormatException e) {
return null;
}
}
};
private void refreshCustomApplicationPrefs() {
if (!parsePackageList()) {
return;
}
// Add the Application Preferences
if (mStoplistPrefList != null && mBlacklistPrefList != null) {
mStoplistPrefList.removeAll();
mBlacklistPrefList.removeAll();
for (Package pkg : mStoplistPackages.values()) {
try {
Preference pref = createPreferenceFromInfo(pkg);
mStoplistPrefList.addPreference(pref);
} catch (PackageManager.NameNotFoundException e) {
// Do nothing
}
}
for (Package pkg : mBlacklistPackages.values()) {
try {
Preference pref = createPreferenceFromInfo(pkg);
mBlacklistPrefList.addPreference(pref);
} catch (PackageManager.NameNotFoundException e) {
// Do nothing
}
}
}
// Keep these at the top
mAddStoplistPref.setOrder(0);
mAddBlacklistPref.setOrder(0);
// Add 'add' options
mStoplistPrefList.addPreference(mAddStoplistPref);
mBlacklistPrefList.addPreference(mAddBlacklistPref);
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == mAddStoplistPref) {
showDialog(DIALOG_STOPLIST_APPS);
} else if (preference == mAddBlacklistPref) {
showDialog(DIALOG_BLACKLIST_APPS);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.dialog_delete_title)
.setMessage(R.string.dialog_delete_message)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (preference == mBlacklistPrefList.findPreference(preference.getKey())) {
removeApplicationPref(preference.getKey(), mBlacklistPackages);
} else if (preference == mStoplistPrefList.findPreference(preference.getKey())) {
removeApplicationPref(preference.getKey(), mStoplistPackages);
}
}
})
.setNegativeButton(android.R.string.cancel, null);
builder.show();
}
return true;
}
private void addCustomApplicationPref(String packageName, Map<String,Package> map) {
Package pkg = map.get(packageName);
if (pkg == null) {
pkg = new Package(packageName);
map.put(packageName, pkg);
savePackageList(false, map);
refreshCustomApplicationPrefs();
}
}
private Preference createPreferenceFromInfo(Package pkg)
throws PackageManager.NameNotFoundException {
PackageInfo info = mPackageManager.getPackageInfo(pkg.name,
PackageManager.GET_META_DATA);
Preference pref =
new Preference(getActivity());
pref.setKey(pkg.name);
pref.setTitle(info.applicationInfo.loadLabel(mPackageManager));
pref.setIcon(info.applicationInfo.loadIcon(mPackageManager));
pref.setPersistent(false);
pref.setOnPreferenceClickListener(this);
return pref;
}
private void removeApplicationPref(String packageName, Map<String,Package> map) {
if (map.remove(packageName) != null) {
savePackageList(false, map);
refreshCustomApplicationPrefs();
}
}
private boolean parsePackageList() {
boolean parsed = false;
final String stoplistString = Settings.System.getString(getContentResolver(),
Settings.System.HEADS_UP_STOPLIST_VALUES);
final String blacklistString = Settings.System.getString(getContentResolver(),
Settings.System.HEADS_UP_BLACKLIST_VALUES);
if (!TextUtils.equals(mStoplistPackageList, stoplistString)) {
mStoplistPackageList = stoplistString;
mStoplistPackages.clear();
parseAndAddToMap(stoplistString, mStoplistPackages);
parsed = true;
}
if (!TextUtils.equals(mBlacklistPackageList, blacklistString)) {
mBlacklistPackageList = blacklistString;
mBlacklistPackages.clear();
parseAndAddToMap(blacklistString, mBlacklistPackages);
parsed = true;
}
return parsed;
}
private void parseAndAddToMap(String baseString, Map<String,Package> map) {
if (baseString == null) {
return;
}
final String[] array = TextUtils.split(baseString, "\\|");
for (String item : array) {
if (TextUtils.isEmpty(item)) {
continue;
}
Package pkg = Package.fromString(item);
map.put(pkg.name, pkg);
}
}
private void savePackageList(boolean preferencesUpdated, Map<String,Package> map) {
String setting = map == mStoplistPackages
? Settings.System.HEADS_UP_STOPLIST_VALUES
: Settings.System.HEADS_UP_BLACKLIST_VALUES;
List<String> settings = new ArrayList<String>();
for (Package app : map.values()) {
settings.add(app.toString());
}
final String value = TextUtils.join("|", settings);
if (preferencesUpdated) {
if (TextUtils.equals(setting, Settings.System.HEADS_UP_STOPLIST_VALUES)) {
mStoplistPackageList = value;
} else {
mBlacklistPackageList = value;
}
}
Settings.System.putString(getContentResolver(),
setting, value);
}
}

View File

@@ -1,41 +0,0 @@
/*
* Copyright (C) 2019 The PixelExperience 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.Context;
import android.telephony.TelephonyManager;
import com.android.settings.core.BasePreferenceController;
public class IncallFeedbackPreferenceController extends BasePreferenceController {
public IncallFeedbackPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return isVoiceCapable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
private boolean isVoiceCapable() {
TelephonyManager telephony =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
return telephony != null && telephony.isVoiceCapable();
}
}

View File

@@ -42,13 +42,6 @@ import com.cherish.settings.preferences.SystemSettingListPreference;
public class LockScreenSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String FINGERPRINT_VIB = "fingerprint_success_vib";
private static final String FOD_ICON_PICKER_CATEGORY = "fod_icon_picker_category";
private FingerprintManager mFingerprintManager;
private SwitchPreference mFingerprintVib;
private Preference mFODIconPicker;
@Override
public void onCreate(Bundle icicle) {
@@ -58,33 +51,11 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
ContentResolver resolver = getActivity().getContentResolver();
final PreferenceScreen prefScreen = getPreferenceScreen();
Resources resources = getResources();
mFODIconPicker = (Preference) findPreference(FOD_ICON_PICKER_CATEGORY);
if (mFODIconPicker != null
&& !getResources().getBoolean(com.android.internal.R.bool.config_supportsInDisplayFingerprint)) {
prefScreen.removePreference(mFODIconPicker);
}
mFingerprintManager = (FingerprintManager) getActivity().getSystemService(Context.FINGERPRINT_SERVICE);
mFingerprintVib = (SwitchPreference) findPreference(FINGERPRINT_VIB);
if (!mFingerprintManager.isHardwareDetected()){
prefScreen.removePreference(mFingerprintVib);
} else {
mFingerprintVib.setChecked((Settings.System.getInt(getContentResolver(),
Settings.System.FINGERPRINT_SUCCESS_VIB, 1) == 1));
mFingerprintVib.setOnPreferenceChangeListener(this);
}
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mFingerprintVib) {
boolean value = (Boolean) newValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.FINGERPRINT_SUCCESS_VIB, value ? 1 : 0);
return true;
}
return false;
}
@@ -93,4 +64,4 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}
}

View File

@@ -45,22 +45,12 @@ public class MiscSettings extends SettingsPreferenceFragment implements
addPreferencesFromResource(R.xml.cherish_settings_misc);
mGamingMode = (SystemSettingMasterSwitchPreference) findPreference(GAMING_MODE_ENABLED);
mGamingMode.setChecked((Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.GAMING_MODE_ENABLED, 0) == 1));
mGamingMode.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mGamingMode) {
boolean value = (Boolean) objValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.GAMING_MODE_ENABLED, value ? 1 : 0);
return true;
}
return false;
}

View File

@@ -21,17 +21,6 @@ import net.margaritov.preference.colorpicker.ColorPickerPreference;
public class NotificationSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener{
private static final String PULSE_AMBIENT_LIGHT = "pulse_ambient_light";
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 Preference mChargingLeds;
private SystemSettingMasterSwitchPreference mEdgePulse;
private SystemSettingListPreference mFlashOnCall;
private SystemSettingSwitchPreference mFlashOnCallIgnoreDND;
private CustomSeekBarPreference mFlashOnCallRate;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -39,61 +28,13 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
addPreferencesFromResource(R.xml.cherish_settings_notifications);
PreferenceScreen prefScreen = getPreferenceScreen();
ContentResolver resolver = getActivity().getContentResolver();
mChargingLeds = (Preference) findPreference("charging_light");
if (mChargingLeds != null
&& !getResources().getBoolean(
com.android.internal.R.bool.config_intrusiveBatteryLed)) {
prefScreen.removePreference(mChargingLeds);
}
mEdgePulse = (SystemSettingMasterSwitchPreference) findPreference(PULSE_AMBIENT_LIGHT);
mEdgePulse.setOnPreferenceChangeListener(this);
int edgePulse = Settings.System.getInt(getContentResolver(),
PULSE_AMBIENT_LIGHT, 0);
mEdgePulse.setChecked(edgePulse != 0);
mFlashOnCallRate = (CustomSeekBarPreference)
findPreference(PREF_FLASH_ON_CALL_RATE);
int value = Settings.System.getInt(resolver,
Settings.System.FLASHLIGHT_ON_CALL_RATE, 1);
mFlashOnCallRate.setValue(value);
mFlashOnCallRate.setOnPreferenceChangeListener(this);
mFlashOnCallIgnoreDND = (SystemSettingSwitchPreference)
findPreference(PREF_FLASH_ON_CALL_DND);
value = Settings.System.getInt(resolver,
Settings.System.FLASHLIGHT_ON_CALL, 0);
mFlashOnCallIgnoreDND.setVisible(value > 1);
mFlashOnCallRate.setVisible(value != 0);
mFlashOnCall = (SystemSettingListPreference)
findPreference(PREF_FLASH_ON_CALL);
mFlashOnCall.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mEdgePulse) {
boolean value = (Boolean) newValue;
Settings.System.putInt(getContentResolver(),
PULSE_AMBIENT_LIGHT, value ? 1 : 0);
return true;
} else if (preference == mFlashOnCall) {
int value = Integer.parseInt((String) newValue);
Settings.System.putInt(resolver,
Settings.System.FLASHLIGHT_ON_CALL, value);
mFlashOnCallIgnoreDND.setVisible(value > 1);
mFlashOnCallRate.setVisible(value != 0);
return true;
} else if (preference == mFlashOnCallRate) {
int value = (Integer) newValue;
Settings.System.putInt(resolver,
Settings.System.FLASHLIGHT_ON_CALL_RATE, value);
return true;
}
return false;
}

View File

@@ -1,252 +0,0 @@
/*
* Copyright (C) 2020 The Dirty Unicorns 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 java.util.ArrayList;
import java.util.List;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.search.SearchIndexable;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
import com.cherish.settings.preferences.SecureSettingListPreference;
import com.cherish.settings.preferences.SecureSettingSeekBarPreference;
import com.android.internal.util.cherish.CherishUtils;
import android.content.Context;
import android.content.ContentResolver;
import android.graphics.Color;
import android.os.Bundle;
import android.os.UserHandle;
import androidx.preference.PreferenceCategory;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.SwitchPreference;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
@SearchIndexable
public class PulseSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener, Indexable {
private static final String TAG = PulseSettings.class.getSimpleName();
private static final String NAVBAR_PULSE_ENABLED_KEY = "navbar_pulse_enabled";
private static final String LOCKSCREEN_PULSE_ENABLED_KEY = "lockscreen_pulse_enabled";
private static final String AMBIENT_PULSE_ENABLED_KEY = "ambient_pulse_enabled";
private static final String PULSE_SMOOTHING_KEY = "pulse_smoothing_enabled";
private static final String PULSE_COLOR_MODE_KEY = "pulse_color_mode";
private static final String PULSE_COLOR_MODE_CHOOSER_KEY = "pulse_color_user";
private static final String PULSE_COLOR_MODE_LAVA_SPEED_KEY = "pulse_lavalamp_speed";
private static final String PULSE_RENDER_CATEGORY_SOLID = "pulse_2";
private static final String PULSE_RENDER_CATEGORY_FADING = "pulse_fading_bars_category";
private static final String PULSE_RENDER_MODE_KEY = "pulse_render_style";
private static final int RENDER_STYLE_FADING_BARS = 0;
private static final int RENDER_STYLE_SOLID_LINES = 1;
private static final int COLOR_TYPE_ACCENT = 0;
private static final int COLOR_TYPE_USER = 1;
private static final int COLOR_TYPE_LAVALAMP = 2;
private static final int COLOR_TYPE_AUTO = 3;
private SwitchPreference mNavbarPulse;
private SwitchPreference mLockscreenPulse;
private SwitchPreference mAmbientPulse;
private SwitchPreference mPulseSmoothing;
private Preference mRenderMode;
private ListPreference mColorModePref;
private ColorPickerPreference mColorPickerPref;
private Preference mLavaSpeedPref;
private PreferenceCategory mFadingBarsCat;
private PreferenceCategory mSolidBarsCat;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.cherish_settings_pulse);
mFooterPreferenceMixin.createFooterPreference()
.setTitle(R.string.pulse_help_policy_notice_summary);
ContentResolver resolver = getContentResolver();
mNavbarPulse = (SwitchPreference) findPreference(NAVBAR_PULSE_ENABLED_KEY);
boolean navbarPulse = Settings.Secure.getIntForUser(resolver,
Settings.Secure.NAVBAR_PULSE_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
mNavbarPulse.setChecked(navbarPulse);
mNavbarPulse.setOnPreferenceChangeListener(this);
mLockscreenPulse = (SwitchPreference) findPreference(LOCKSCREEN_PULSE_ENABLED_KEY);
boolean lockscreenPulse = Settings.Secure.getIntForUser(resolver,
Settings.Secure.LOCKSCREEN_PULSE_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
mLockscreenPulse.setChecked(lockscreenPulse);
mLockscreenPulse.setOnPreferenceChangeListener(this);
mAmbientPulse = (SwitchPreference) findPreference(AMBIENT_PULSE_ENABLED_KEY);
boolean ambientPulse = Settings.Secure.getIntForUser(resolver,
Settings.Secure.AMBIENT_PULSE_ENABLED, 1, UserHandle.USER_CURRENT) != 0;
mAmbientPulse.setChecked(ambientPulse);
mAmbientPulse.setOnPreferenceChangeListener(this);
mColorModePref = (ListPreference) findPreference(PULSE_COLOR_MODE_KEY);
mColorPickerPref = (ColorPickerPreference) findPreference(PULSE_COLOR_MODE_CHOOSER_KEY);
mLavaSpeedPref = findPreference(PULSE_COLOR_MODE_LAVA_SPEED_KEY);
mColorModePref.setOnPreferenceChangeListener(this);
mColorPickerPref.setDefaultValue(CherishUtils.getThemeAccentColor(getContext()));
int colorMode = Settings.Secure.getIntForUser(getContentResolver(),
Settings.Secure.PULSE_COLOR_MODE, COLOR_TYPE_ACCENT, UserHandle.USER_CURRENT);
if (colorMode == COLOR_TYPE_ACCENT) {
mColorPickerPref.setNewPreviewColor(CherishUtils.getThemeAccentColor(getContext()));
}
updateColorPrefs(colorMode);
mRenderMode = findPreference(PULSE_RENDER_MODE_KEY);
mRenderMode.setOnPreferenceChangeListener(this);
mFadingBarsCat = (PreferenceCategory) findPreference(
PULSE_RENDER_CATEGORY_FADING);
mSolidBarsCat = (PreferenceCategory) findPreference(
PULSE_RENDER_CATEGORY_SOLID);
mPulseSmoothing = (SwitchPreference) findPreference(PULSE_SMOOTHING_KEY);
updateAllPrefs();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getContext().getContentResolver();
if (preference == mNavbarPulse) {
boolean val = (Boolean) newValue;
Settings.Secure.putIntForUser(resolver,
Settings.Secure.NAVBAR_PULSE_ENABLED, val ? 1 : 0, UserHandle.USER_CURRENT);
updateAllPrefs();
return true;
} else if (preference == mLockscreenPulse) {
boolean val = (Boolean) newValue;
Settings.Secure.putIntForUser(resolver,
Settings.Secure.LOCKSCREEN_PULSE_ENABLED, val ? 1 : 0, UserHandle.USER_CURRENT);
updateAllPrefs();
return true;
} else if (preference == mAmbientPulse) {
boolean val = (Boolean) newValue;
Settings.Secure.putIntForUser(resolver,
Settings.Secure.AMBIENT_PULSE_ENABLED, val ? 1 : 0, UserHandle.USER_CURRENT);
updateAllPrefs();
return true;
} else if (preference == mColorModePref) {
updateColorPrefs(Integer.valueOf(String.valueOf(newValue)));
return true;
} else if (preference == mRenderMode) {
updateRenderCategories(Integer.valueOf(String.valueOf(newValue)));
return true;
}
return false;
}
private void updateAllPrefs() {
ContentResolver resolver = getContentResolver();
boolean navbarPulse = Settings.Secure.getIntForUser(resolver,
Settings.Secure.NAVBAR_PULSE_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
boolean lockscreenPulse = Settings.Secure.getIntForUser(resolver,
Settings.Secure.LOCKSCREEN_PULSE_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
boolean ambientPulse = Settings.Secure.getIntForUser(resolver,
Settings.Secure.AMBIENT_PULSE_ENABLED, 0, UserHandle.USER_CURRENT) != 0;
mPulseSmoothing.setEnabled(navbarPulse || lockscreenPulse || ambientPulse);
mColorModePref.setEnabled(navbarPulse || lockscreenPulse || ambientPulse);
if (navbarPulse || lockscreenPulse) {
int colorMode = Settings.Secure.getIntForUser(resolver,
Settings.Secure.PULSE_COLOR_MODE, COLOR_TYPE_ACCENT, UserHandle.USER_CURRENT);
updateColorPrefs(colorMode);
} else {
mColorPickerPref.setEnabled(false);
mLavaSpeedPref.setEnabled(false);
}
mRenderMode.setEnabled(navbarPulse || lockscreenPulse || ambientPulse);
if (navbarPulse || lockscreenPulse || ambientPulse) {
int renderMode = Settings.Secure.getIntForUser(resolver,
Settings.Secure.PULSE_RENDER_STYLE, RENDER_STYLE_SOLID_LINES, UserHandle.USER_CURRENT);
updateRenderCategories(renderMode);
} else {
mFadingBarsCat.setEnabled(false);
mSolidBarsCat.setEnabled(false);
}
}
private void updateColorPrefs(int val) {
switch (val) {
case COLOR_TYPE_ACCENT:
mColorPickerPref.setEnabled(false);
mLavaSpeedPref.setEnabled(false);
break;
case COLOR_TYPE_USER:
mColorPickerPref.setEnabled(true);
mLavaSpeedPref.setEnabled(false);
break;
case COLOR_TYPE_LAVALAMP:
mColorPickerPref.setEnabled(false);
mLavaSpeedPref.setEnabled(true);
break;
case COLOR_TYPE_AUTO:
mColorPickerPref.setEnabled(false);
mLavaSpeedPref.setEnabled(false);
break;
}
}
private void updateRenderCategories(int mode) {
mFadingBarsCat.setEnabled(mode == RENDER_STYLE_FADING_BARS);
mSolidBarsCat.setEnabled(mode == RENDER_STYLE_SOLID_LINES);
}
public static void reset(Context mContext) {
ContentResolver resolver = mContext.getContentResolver();
Settings.Secure.putIntForUser(resolver,
Settings.Secure.LOCKSCREEN_PULSE_ENABLED, 1, UserHandle.USER_CURRENT);
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.cherish_settings_pulse;
result.add(sir);
return result;
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
return keys;
}
};
}

View File

@@ -1,227 +0,0 @@
/*
* Copyright (C) 2019 ion-OS
*
* 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.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.cherish.settings.preferences.CustomSeekBarPreference;
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class QsHeader extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener{
private static final String CUSTOM_HEADER_BROWSE = "custom_header_browse";
private static final String DAYLIGHT_HEADER_PACK = "daylight_header_pack";
private static final String CUSTOM_HEADER_IMAGE_SHADOW = "status_bar_custom_header_shadow";
private static final String CUSTOM_HEADER_PROVIDER = "custom_header_provider";
private static final String FILE_HEADER_SELECT = "file_header_select";
private static final int REQUEST_PICK_IMAGE = 0;
private Preference mHeaderBrowse;
private ListPreference mDaylightHeaderPack;
private CustomSeekBarPreference mHeaderShadow;
private ListPreference mHeaderProvider;
private String mDaylightHeaderProvider;
private Preference mFileHeader;
private String mFileHeaderProvider;
@Override
public void onResume() {
super.onResume();
updateEnablement();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.qs_header);
ContentResolver resolver = getActivity().getContentResolver();
mDaylightHeaderProvider = getResources().getString(R.string.daylight_header_provider);
mFileHeaderProvider = getResources().getString(R.string.file_header_provider);
mHeaderBrowse = findPreference(CUSTOM_HEADER_BROWSE);
mDaylightHeaderPack = (ListPreference) findPreference(DAYLIGHT_HEADER_PACK);
List<String> entries = new ArrayList<String>();
List<String> values = new ArrayList<String>();
getAvailableHeaderPacks(entries, values);
mDaylightHeaderPack.setEntries(entries.toArray(new String[entries.size()]));
mDaylightHeaderPack.setEntryValues(values.toArray(new String[values.size()]));
boolean headerEnabled = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CUSTOM_HEADER, 0) != 0;
updateHeaderProviderSummary(headerEnabled);
mDaylightHeaderPack.setOnPreferenceChangeListener(this);
mHeaderShadow = (CustomSeekBarPreference) findPreference(CUSTOM_HEADER_IMAGE_SHADOW);
final int headerShadow = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CUSTOM_HEADER_SHADOW, 0);
mHeaderShadow.setValue((int)(((double) headerShadow / 255) * 100));
mHeaderShadow.setOnPreferenceChangeListener(this);
mHeaderProvider = (ListPreference) findPreference(CUSTOM_HEADER_PROVIDER);
mHeaderProvider.setOnPreferenceChangeListener(this);
mFileHeader = findPreference(FILE_HEADER_SELECT);
}
private void updateHeaderProviderSummary(boolean headerEnabled) {
mDaylightHeaderPack.setSummary(getResources().getString(R.string.header_provider_disabled));
if (headerEnabled) {
String settingHeaderPackage = Settings.System.getString(getContentResolver(),
Settings.System.STATUS_BAR_DAYLIGHT_HEADER_PACK);
if (settingHeaderPackage != null) {
int valueIndex = mDaylightHeaderPack.findIndexOfValue(settingHeaderPackage);
mDaylightHeaderPack.setValueIndex(valueIndex >= 0 ? valueIndex : 0);
mDaylightHeaderPack.setSummary(mDaylightHeaderPack.getEntry());
}
}
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference == mFileHeader) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_PICK_IMAGE);
return true;
}
return super.onPreferenceTreeClick(preference);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mDaylightHeaderPack) {
String value = (String) newValue;
Settings.System.putString(getContentResolver(),
Settings.System.STATUS_BAR_DAYLIGHT_HEADER_PACK, value);
int valueIndex = mDaylightHeaderPack.findIndexOfValue(value);
mDaylightHeaderPack.setSummary(mDaylightHeaderPack.getEntries()[valueIndex]);
} else if (preference == mHeaderShadow) {
Integer headerShadow = (Integer) newValue;
int realHeaderValue = (int) (((double) headerShadow / 100) * 255);
Settings.System.putInt(getContentResolver(),
Settings.System.STATUS_BAR_CUSTOM_HEADER_SHADOW, realHeaderValue);
} else if (preference == mHeaderProvider) {
String value = (String) newValue;
Settings.System.putString(getContentResolver(),
Settings.System.STATUS_BAR_CUSTOM_HEADER_PROVIDER, value);
int valueIndex = mHeaderProvider.findIndexOfValue(value);
mHeaderProvider.setSummary(mHeaderProvider.getEntries()[valueIndex]);
updateEnablement();
}
return true;
}
private boolean isBrowseHeaderAvailable() {
PackageManager pm = getPackageManager();
Intent browse = new Intent();
browse.setClassName("org.omnirom.omnistyle", "org.omnirom.omnistyle.PickHeaderActivity");
return pm.resolveActivity(browse, 0) != null;
}
private void getAvailableHeaderPacks(List<String> entries, List<String> values) {
Map<String, String> headerMap = new HashMap<String, String>();
Intent i = new Intent();
PackageManager packageManager = getPackageManager();
i.setAction("org.omnirom.DaylightHeaderPack");
for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
String packageName = r.activityInfo.packageName;
String label = r.activityInfo.loadLabel(getPackageManager()).toString();
if (label == null) {
label = r.activityInfo.packageName;
}
headerMap.put(label, packageName);
}
i.setAction("org.omnirom.DaylightHeaderPack1");
for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
String packageName = r.activityInfo.packageName;
String label = r.activityInfo.loadLabel(getPackageManager()).toString();
if (r.activityInfo.name.endsWith(".theme")) {
continue;
}
if (label == null) {
label = packageName;
}
headerMap.put(label, packageName + "/" + r.activityInfo.name);
}
List<String> labelList = new ArrayList<String>();
labelList.addAll(headerMap.keySet());
Collections.sort(labelList);
for (String label : labelList) {
entries.add(label);
values.add(headerMap.get(label));
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent result) {
if (requestCode == REQUEST_PICK_IMAGE) {
if (resultCode != Activity.RESULT_OK) {
return;
}
final Uri imageUri = result.getData();
Settings.System.putString(getContentResolver(), Settings.System.STATUS_BAR_CUSTOM_HEADER_PROVIDER, "file");
Settings.System.putString(getContentResolver(), Settings.System.STATUS_BAR_FILE_HEADER_IMAGE, imageUri.toString());
}
}
private void updateEnablement() {
String providerName = Settings.System.getString(getContentResolver(),
Settings.System.STATUS_BAR_CUSTOM_HEADER_PROVIDER);
if (providerName == null) {
providerName = mDaylightHeaderProvider;
}
if (!providerName.equals(mDaylightHeaderProvider)) {
providerName = mFileHeaderProvider;
}
int valueIndex = mHeaderProvider.findIndexOfValue(providerName);
mHeaderProvider.setValueIndex(valueIndex >= 0 ? valueIndex : 0);
mHeaderProvider.setSummary(mHeaderProvider.getEntry());
mDaylightHeaderPack.setEnabled(providerName.equals(mDaylightHeaderProvider));
mFileHeader.setEnabled(providerName.equals(mFileHeaderProvider));
mHeaderBrowse.setEnabled(isBrowseHeaderAvailable() && providerName.equals(mFileHeaderProvider));
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}

View File

@@ -31,21 +31,6 @@ import java.util.ArrayList;
public class QuickSettings extends SettingsPreferenceFragment implements
OnPreferenceChangeListener {
private static final String QS_BLUR_ALPHA = "qs_blur_alpha";
private static final String QS_BLUR_INTENSITY = "qs_blur_intensity";
private static final String QUICK_PULLDOWN = "quick_pulldown";
private static final String FOOTER_TEXT_STRING = "footer_text_string";
private static final String STATUS_BAR_CUSTOM_HEADER = "status_bar_custom_header";
private static final String QS_HIDE_BATTERY = "qs_hide_battery";
private static final String QS_BATTERY_MODE = "qs_battery_mode";
private ListPreference mQuickPulldown;
private CustomSeekBarPreference mQSBlurAlpha;
private CustomSeekBarPreference mQSBlurIntensity;
private SystemSettingEditTextPreference mFooterString;
private SystemSettingMasterSwitchPreference mCustomHeader;
private SystemSettingSwitchPreference mHideBattery;
private SystemSettingListPreference mQsBatteryMode;
@Override
public void onCreate(Bundle icicle) {
@@ -55,108 +40,13 @@ public class QuickSettings extends SettingsPreferenceFragment implements
PreferenceScreen prefScreen = getPreferenceScreen();
ContentResolver resolver = getActivity().getContentResolver();
mQSBlurAlpha = (CustomSeekBarPreference) findPreference(QS_BLUR_ALPHA);
int qsBlurAlpha = Settings.System.getInt(getContentResolver(),
Settings.System.QS_BLUR_ALPHA, 100);
mQSBlurAlpha.setValue(qsBlurAlpha);
mQSBlurAlpha.setOnPreferenceChangeListener(this);
mQSBlurIntensity = (CustomSeekBarPreference) findPreference(QS_BLUR_INTENSITY);
int qsBlurIntensity = Settings.System.getInt(getContentResolver(),
Settings.System.QS_BLUR_INTENSITY, 30);
mQSBlurIntensity.setValue(qsBlurIntensity);
mQSBlurIntensity.setOnPreferenceChangeListener(this);
mQuickPulldown = (ListPreference) findPreference(QUICK_PULLDOWN);
mQuickPulldown.setOnPreferenceChangeListener(this);
int quickPulldownValue = Settings.System.getIntForUser(resolver,
Settings.System.STATUS_BAR_QUICK_QS_PULLDOWN, 0, UserHandle.USER_CURRENT);
mQuickPulldown.setValue(String.valueOf(quickPulldownValue));
updatePulldownSummary(quickPulldownValue);
mCustomHeader = (SystemSettingMasterSwitchPreference) findPreference(STATUS_BAR_CUSTOM_HEADER);
int qsHeader = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CUSTOM_HEADER, 0);
mCustomHeader.setChecked(qsHeader != 0);
mCustomHeader.setOnPreferenceChangeListener(this);
mQsBatteryMode = (SystemSettingListPreference) findPreference(QS_BATTERY_MODE);
mHideBattery = (SystemSettingSwitchPreference) findPreference(QS_HIDE_BATTERY);
mHideBattery.setOnPreferenceChangeListener(this);
mFooterString = (SystemSettingEditTextPreference) findPreference(FOOTER_TEXT_STRING);
mFooterString.setOnPreferenceChangeListener(this);
String footerString = Settings.System.getString(getContentResolver(),
FOOTER_TEXT_STRING);
if (footerString != null && footerString != "")
mFooterString.setText(footerString);
else {
mFooterString.setText("#KeepTheLove");
Settings.System.putString(getActivity().getContentResolver(),
Settings.System.FOOTER_TEXT_STRING, "#KeepTheLove");
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mQSBlurAlpha) {
int value = (Integer) newValue;
Settings.System.putInt(getContentResolver(),
Settings.System.QS_BLUR_ALPHA, value);
return true;
} else if (preference == mQSBlurIntensity) {
int value = (Integer) newValue;
Settings.System.putInt(getContentResolver(),
Settings.System.QS_BLUR_INTENSITY, value);
return true;
} else if (preference == mQuickPulldown) {
int quickPulldownValue = Integer.valueOf((String) newValue);
Settings.System.putIntForUser(resolver, Settings.System.STATUS_BAR_QUICK_QS_PULLDOWN,
quickPulldownValue, UserHandle.USER_CURRENT);
updatePulldownSummary(quickPulldownValue);
return true;
} else if (preference == mFooterString) {
String value = (String) newValue;
if (value != "" && value != null)
Settings.System.putString(getActivity().getContentResolver(),
Settings.System.FOOTER_TEXT_STRING, value);
else {
mFooterString.setText("#KeepTheLove");
Settings.System.putString(getActivity().getContentResolver(),
Settings.System.FOOTER_TEXT_STRING, "#KeepTheLove");
}
return true;
} else if (preference == mCustomHeader) {
boolean header = (Boolean) newValue;
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_CUSTOM_HEADER, header ? 1 : 0);
return true;
} else if (preference == mHideBattery) {
Boolean value = (Boolean) newValue;
Settings.System.putInt(getContentResolver(),
Settings.System.QS_HIDE_BATTERY, value ? 1 : 0);
mQsBatteryMode.setEnabled(!value);
return true;
}
return false;
}
private void updatePulldownSummary(int value) {
Resources res = getResources();
if (value == 0) {
// quick pulldown deactivated
mQuickPulldown.setSummary(res.getString(R.string.quick_pulldown_off));
} else if (value == 3) {
// quick pulldown always
mQuickPulldown.setSummary(res.getString(R.string.quick_pulldown_summary_always));
} else {
String direction = res.getString(value == 2
? R.string.quick_pulldown_left
: R.string.quick_pulldown_right);
mQuickPulldown.setSummary(res.getString(R.string.quick_pulldown_summary, direction));
}
return false;
}
@Override

View File

@@ -26,12 +26,6 @@ import com.android.settings.SettingsPreferenceFragment;
public class RecentsSettings extends SettingsPreferenceFragment implements
OnPreferenceChangeListener {
private static final String PREF_STOCK_RECENTS_CATEGORY = "stock_recents_category";
private static final String PREF_ALTERNATIVE_RECENTS_CATEGORY = "alternative_recents_category";
private static final String PREF_SWIPE_UP_ENABLED = "swipe_up_enabled_warning";
private PreferenceCategory mStockRecentsCategory;
private PreferenceCategory mAlternativeRecentsCategory;
private Context mContext;
@Override
@@ -41,78 +35,8 @@ public class RecentsSettings extends SettingsPreferenceFragment implements
addPreferencesFromResource(R.xml.cherish_settings_recents);
ContentResolver resolver = getActivity().getContentResolver();
mStockRecentsCategory = (PreferenceCategory) findPreference(PREF_STOCK_RECENTS_CATEGORY);
mAlternativeRecentsCategory =
(PreferenceCategory) findPreference(PREF_ALTERNATIVE_RECENTS_CATEGORY);
// Alternative recents en-/disabling
Preference.OnPreferenceChangeListener alternativeRecentsChangeListener =
new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
updateDependencies(preference, (Boolean) newValue);
return true;
}
};
for (int i = 0; i < mAlternativeRecentsCategory.getPreferenceCount(); i++) {
Preference preference = mAlternativeRecentsCategory.getPreference(i);
if (preference instanceof SystemSettingMasterSwitchPreference) {
preference.setOnPreferenceChangeListener(alternativeRecentsChangeListener);
}
}
updateDependencies();
// Warning for alternative recents when gesture navigation is enabled,
// which directly controls quickstep (launcher) recents.
final int navigationMode = getActivity().getResources()
.getInteger(com.android.internal.R.integer.config_navBarInteractionMode);
// config_navBarInteractionMode:
// 0: 3 button mode (supports slim recents)
// 1: 2 button mode (currently does not support alternative recents)
// 2: gesture only (currently does not support alternative recents)
if (navigationMode != 0) {
for (int i = 0; i < mAlternativeRecentsCategory.getPreferenceCount(); i++) {
Preference preference = mAlternativeRecentsCategory.getPreference(i);
if (PREF_SWIPE_UP_ENABLED.equals(preference.getKey())) {
// We want to have that one enabled
continue;
}
preference.setEnabled(false);
}
} else {
mAlternativeRecentsCategory.removePreference(findPreference(PREF_SWIPE_UP_ENABLED));
}
}
private void updateDependencies() {
updateDependencies(null, null);
}
private void updateDependencies(Preference updatedPreference, Boolean newValue) {
// Disable stock recents category if alternative enabled
boolean alternativeRecentsEnabled = newValue != null && newValue;
if (!alternativeRecentsEnabled) {
for (int i = 0; i < mAlternativeRecentsCategory.getPreferenceCount(); i++) {
Preference preference = mAlternativeRecentsCategory.getPreference(i);
if (preference == updatedPreference) {
// Already used newValue
continue;
}
if (preference instanceof SystemSettingMasterSwitchPreference
&& ((SystemSettingMasterSwitchPreference) preference).isChecked()) {
alternativeRecentsEnabled = true;
break;
}
}
}
if (mStockRecentsCategory != null) {
mStockRecentsCategory.setEnabled(!alternativeRecentsEnabled);
}
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
@@ -124,4 +48,4 @@ public class RecentsSettings extends SettingsPreferenceFragment implements
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}
}

View File

@@ -1,38 +0,0 @@
/*
* Copyright (C) 2018 Havoc-OS
*
* 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.os.Bundle;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.R;
public class SlimRecentAppSidebar extends SettingsPreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.slim_recent_app_sidebar);
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}

View File

@@ -1,106 +0,0 @@
/*
* Copyright (C) 2018 Havoc-OS
*
* 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.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.R;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
public class SlimRecentAppSidebarStyle extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener {
private static final String RECENT_APP_SIDEBAR_TEXT_COLOR = "recent_app_sidebar_text_color";
private static final String RECENT_APP_SIDEBAR_BG_COLOR = "recent_app_sidebar_bg_color";
private ColorPickerPreference mRecentSidebarTextColor;
private ColorPickerPreference mRecentSidebarBgColor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.slim_recent_app_sidebar_style);
mRecentSidebarTextColor = (ColorPickerPreference) findPreference(RECENT_APP_SIDEBAR_TEXT_COLOR);
mRecentSidebarTextColor.setOnPreferenceChangeListener(this);
final int intColor = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.RECENT_APP_SIDEBAR_TEXT_COLOR, 0xffffffff);
String hexColor = String.format("#%08x", (0xffffffff & intColor));
if (hexColor.equals("#ffffffff")) {
mRecentSidebarTextColor.setSummary(R.string.default_string);
} else {
mRecentSidebarTextColor.setSummary(hexColor);
}
mRecentSidebarTextColor.setNewPreviewColor(intColor);
mRecentSidebarBgColor = (ColorPickerPreference) findPreference(RECENT_APP_SIDEBAR_BG_COLOR);
mRecentSidebarBgColor.setOnPreferenceChangeListener(this);
final int intColorCard = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.RECENT_APP_SIDEBAR_BG_COLOR, 0x00ffffff);
String hexColorCard = String.format("#%08x", (0x00ffffff & intColorCard));
if (hexColorCard.equals("#00ffffff")) {
mRecentSidebarBgColor.setSummary(R.string.default_string);
} else {
mRecentSidebarBgColor.setSummary(hexColorCard);
}
mRecentSidebarBgColor.setNewPreviewColor(intColorCard);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mRecentSidebarTextColor) {
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.putIntForUser(getContext().getContentResolver(),
Settings.System.RECENT_APP_SIDEBAR_TEXT_COLOR,
intHex, UserHandle.USER_CURRENT);
return true;
} else if (preference == mRecentSidebarBgColor) {
String hex = ColorPickerPreference.convertToARGB(
Integer.valueOf(String.valueOf(newValue)));
if (hex.equals("#00ffffff")) {
preference.setSummary(R.string.default_string);
} else {
preference.setSummary(hex);
}
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putIntForUser(getContext().getContentResolver(),
Settings.System.RECENT_APP_SIDEBAR_BG_COLOR,
intHex, UserHandle.USER_CURRENT);
return true;
}
return false;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}

View File

@@ -1,392 +0,0 @@
/*
* Copyright (C) 2017 AICP
*
* 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.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.R;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
public class SlimRecents extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener, DialogInterface.OnDismissListener {
private static final String RECENT_PANEL_LEFTY_MODE = "recent_panel_lefty_mode";
private static final String RECENT_ICON_PACK = "slim_icon_pack";
private static final String RECENT_PANEL_BG_COLOR = "recent_panel_bg_color";
private static final String RECENT_CARD_BG_COLOR = "recent_card_bg_color";
private static final String SLIM_MEM_BAR_COLOR = "slim_mem_bar_color";
private static final String SLIM_MEM_TEXT_COLOR = "slim_mem_text_color";
private SwitchPreference mRecentPanelLeftyMode;
private Preference mIconPack;
private ColorPickerPreference mRecentPanelBgColor;
private ColorPickerPreference mRecentCardBgColor;
private ColorPickerPreference mMemBarColor;
private ColorPickerPreference mMemTextColor;
// Icon pack
private final static String[] sSupportedActions = new String[] {
"org.adw.launcher.THEMES",
"com.gau.go.launcherex.theme"
};
private static final String[] sSupportedCategories = new String[] {
"com.fede.launcher.THEME_ICONPACK",
"com.anddoes.launcher.THEME",
"com.teslacoilsw.launcher.THEME"
};
private AlertDialog mDialog;
private ListView mListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.slim_recents);
mRecentPanelLeftyMode = (SwitchPreference) findPreference(RECENT_PANEL_LEFTY_MODE);
mRecentPanelLeftyMode.setOnPreferenceChangeListener(this);
mIconPack = findPreference(RECENT_ICON_PACK);
// Recent panel background color
mRecentPanelBgColor = (ColorPickerPreference) findPreference(RECENT_PANEL_BG_COLOR);
mRecentPanelBgColor.setOnPreferenceChangeListener(this);
final int intColor = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.RECENT_PANEL_BG_COLOR, 0x00ffffff);
String hexColor = String.format("#%08x", (0x00ffffff & intColor));
if (hexColor.equals("#00ffffff")) {
mRecentPanelBgColor.setSummary(R.string.default_string);
} else {
mRecentPanelBgColor.setSummary(hexColor);
}
mRecentPanelBgColor.setNewPreviewColor(intColor);
// Recent card background color
mRecentCardBgColor = (ColorPickerPreference) findPreference(RECENT_CARD_BG_COLOR);
mRecentCardBgColor.setOnPreferenceChangeListener(this);
final int intColorCard = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.RECENT_CARD_BG_COLOR, 0x00ffffff);
String hexColorCard = String.format("#%08x", (0x00ffffff & intColorCard));
if (hexColorCard.equals("#00ffffff")) {
mRecentCardBgColor.setSummary(R.string.default_auto_string);
} else {
mRecentCardBgColor.setSummary(hexColorCard);
}
mRecentCardBgColor.setNewPreviewColor(intColorCard);
mMemBarColor = (ColorPickerPreference) findPreference(SLIM_MEM_BAR_COLOR);
mMemBarColor.setOnPreferenceChangeListener(this);
final int intMemColor = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.SLIM_MEM_BAR_COLOR, 0xffffffff);
String hexMemColor = String.format("#%08x", (0xffffffff & intMemColor));
if (hexMemColor.equals("#ffffffff")) {
mMemBarColor.setSummary(R.string.default_string);
} else {
mMemBarColor.setSummary(hexMemColor);
}
mMemBarColor.setNewPreviewColor(intMemColor);
mMemTextColor = (ColorPickerPreference) findPreference(SLIM_MEM_TEXT_COLOR);
mMemTextColor.setOnPreferenceChangeListener(this);
final int intTextColor = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.SLIM_MEM_TEXT_COLOR, 0xffffffff);
String hexTextColor = String.format("#%08x", (0xffffffff & intTextColor));
if (hexTextColor.equals("#ffffffff")) {
mMemTextColor.setSummary(R.string.default_string);
} else {
mMemTextColor.setSummary(hexTextColor);
}
mMemTextColor.setNewPreviewColor(intTextColor);
}
@Override
public void onResume() {
super.onResume();
boolean recentLeftyMode = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.RECENT_PANEL_GRAVITY, Gravity.END) == Gravity.START;
mRecentPanelLeftyMode.setChecked(recentLeftyMode);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mRecentPanelLeftyMode) {
Settings.System.putInt(getContext().getContentResolver(),
Settings.System.RECENT_PANEL_GRAVITY,
((Boolean) newValue) ? Gravity.START : Gravity.END);
return true;
} else if (preference == mRecentPanelBgColor) {
String hex = ColorPickerPreference.convertToARGB(
Integer.valueOf(String.valueOf(newValue)));
if (hex.equals("#00ffffff")) {
preference.setSummary(R.string.default_string);
} else {
preference.setSummary(hex);
}
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putIntForUser(getContext().getContentResolver(),
Settings.System.RECENT_PANEL_BG_COLOR,
intHex, UserHandle.USER_CURRENT);
return true;
} else if (preference == mRecentCardBgColor) {
String hex = ColorPickerPreference.convertToARGB(
Integer.valueOf(String.valueOf(newValue)));
if (hex.equals("#00ffffff")) {
preference.setSummary(R.string.default_auto_string);
} else {
preference.setSummary(hex);
}
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putIntForUser(getContext().getContentResolver(),
Settings.System.RECENT_CARD_BG_COLOR,
intHex, UserHandle.USER_CURRENT);
return true;
} else if (preference == mMemBarColor) {
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.putIntForUser(getContext().getContentResolver(),
Settings.System.SLIM_MEM_BAR_COLOR,
intHex, UserHandle.USER_CURRENT);
return true;
} else if (preference == mMemTextColor) {
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.putIntForUser(getContext().getContentResolver(),
Settings.System.SLIM_MEM_TEXT_COLOR,
intHex, UserHandle.USER_CURRENT);
return true;
}
return false;
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference == mIconPack) {
pickIconPack(getContext());
return true;
} else {
return super.onPreferenceTreeClick(preference);
}
}
/** Slim Recents Icon Pack Dialog **/
private void pickIconPack(final Context context) {
if (mDialog != null) {
return;
}
Map<String, IconPackInfo> supportedPackages = getSupportedPackages(context);
if (supportedPackages.isEmpty()) {
Toast.makeText(context, R.string.no_iconpacks_summary, Toast.LENGTH_SHORT).show();
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle(R.string.dialog_pick_iconpack_title)
.setOnDismissListener(this)
.setNegativeButton(R.string.cancel, null)
.setView(createDialogView(context, supportedPackages));
mDialog = builder.show();
}
private View createDialogView(final Context context, Map<String, IconPackInfo> supportedPackages) {
final LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = inflater.inflate(R.layout.dialog_iconpack, null);
final IconAdapter adapter = new IconAdapter(context, supportedPackages);
mListView = (ListView) view.findViewById(R.id.iconpack_list);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (adapter.isCurrentIconPack(position)) {
return;
}
String selectedPackage = adapter.getItem(position);
Settings.System.putString(getContext().getContentResolver(),
Settings.System.SLIM_RECENTS_ICON_PACK, selectedPackage);
mDialog.dismiss();
}
});
return view;
}
@Override
public void onDismiss(DialogInterface dialog) {
if (mDialog != null) {
mDialog = null;
}
}
private static class IconAdapter extends BaseAdapter {
ArrayList<IconPackInfo> mSupportedPackages;
LayoutInflater mLayoutInflater;
String mCurrentIconPack;
int mCurrentIconPackPosition = -1;
IconAdapter(Context ctx, Map<String, IconPackInfo> supportedPackages) {
mLayoutInflater = LayoutInflater.from(ctx);
mSupportedPackages = new ArrayList<IconPackInfo>(supportedPackages.values());
Collections.sort(mSupportedPackages, new Comparator<IconPackInfo>() {
@Override
public int compare(IconPackInfo lhs, IconPackInfo rhs) {
return lhs.label.toString().compareToIgnoreCase(rhs.label.toString());
}
});
Resources res = ctx.getResources();
String defaultLabel = res.getString(R.string.default_iconpack_title);
Drawable icon = res.getDrawable(android.R.drawable.sym_def_app_icon);
mSupportedPackages.add(0, new IconPackInfo(defaultLabel, icon, ""));
mCurrentIconPack = Settings.System.getString(ctx.getContentResolver(),
Settings.System.SLIM_RECENTS_ICON_PACK);
}
@Override
public int getCount() {
return mSupportedPackages.size();
}
@Override
public String getItem(int position) {
return (String) mSupportedPackages.get(position).packageName;
}
@Override
public long getItemId(int position) {
return 0;
}
public boolean isCurrentIconPack(int position) {
return mCurrentIconPackPosition == position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.iconpack_view_radio, null);
}
IconPackInfo info = mSupportedPackages.get(position);
TextView txtView = (TextView) convertView.findViewById(R.id.title);
txtView.setText(info.label);
ImageView imgView = (ImageView) convertView.findViewById(R.id.icon);
imgView.setImageDrawable(info.icon);
RadioButton radioButton = (RadioButton) convertView.findViewById(R.id.radio);
boolean isCurrentIconPack = info.packageName.equals(mCurrentIconPack);
radioButton.setChecked(isCurrentIconPack);
if (isCurrentIconPack) {
mCurrentIconPackPosition = position;
}
return convertView;
}
}
private Map<String, IconPackInfo> getSupportedPackages(Context context) {
Intent i = new Intent();
Map<String, IconPackInfo> packages = new HashMap<String, IconPackInfo>();
PackageManager packageManager = context.getPackageManager();
for (String action : sSupportedActions) {
i.setAction(action);
for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
IconPackInfo info = new IconPackInfo(r, packageManager);
packages.put(r.activityInfo.packageName, info);
}
}
i = new Intent(Intent.ACTION_MAIN);
for (String category : sSupportedCategories) {
i.addCategory(category);
for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
IconPackInfo info = new IconPackInfo(r, packageManager);
packages.put(r.activityInfo.packageName, info);
}
i.removeCategory(category);
}
return packages;
}
private static class IconPackInfo {
String packageName;
CharSequence label;
Drawable icon;
IconPackInfo(ResolveInfo r, PackageManager packageManager) {
packageName = r.activityInfo.packageName;
icon = r.loadIcon(packageManager);
label = r.loadLabel(packageManager);
}
IconPackInfo(){
}
public IconPackInfo(String label, Drawable icon, String packageName) {
this.label = label;
this.icon = icon;
this.packageName = packageName;
}
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}

View File

@@ -1,294 +0,0 @@
/*
* Copyright (C) 2017 The ABC rom
* Copyright (C) 2017 AICP
*
* 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.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.RadioButton;
import android.widget.ListView;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.R;
import com.cherish.settings.preferences.PackageListAdapter;
import com.cherish.settings.preferences.PackageListAdapter.PackageItem;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
public class SlimRecentsBlacklist extends SettingsPreferenceFragment implements
Preference.OnPreferenceClickListener {
private static final String TAG = "SlimRecentsBlacklist";
private static final int DIALOG_BLACKLIST_APPS = 1;
private PackageListAdapter mPackageAdapter;
private PackageManager mPackageManager;
private PreferenceGroup mBlacklistPrefList;
private Preference mAddBlacklistPref;
private String mBlacklistPackageList;
private Map<String, Package> mBlacklistPackages;
private AlertDialog mDialog;
private ListView mListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.slim_recents_blacklist);
initializeAllPreferences();
}
@Override
public Dialog onCreateDialog(int dialogId) {
switch (dialogId) {
case DIALOG_BLACKLIST_APPS: {
Dialog dialog;
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
final ListView list = new ListView(getActivity());
list.setAdapter(mPackageAdapter);
alertDialog.setTitle(R.string.profile_choose_app);
alertDialog.setView(list);
dialog = alertDialog.create();
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Add empty application definition, the user will be able to edit it later
PackageItem info = (PackageItem) parent.getItemAtPosition(position);
addCustomApplicationPref(info.packageName, mBlacklistPackages);
dialog.cancel();
}
});
return dialog;
}
}
return super.onCreateDialog(dialogId);
}
@Override
public int getDialogMetricsCategory(int dialogId) {
switch (dialogId) {
case DIALOG_BLACKLIST_APPS:
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
default:
return 0;
}
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
@Override
public void onResume() {
super.onResume();
refreshCustomApplicationPrefs();
}
private void initializeAllPreferences() {
mPackageManager = getActivity().getPackageManager();
mPackageAdapter = new PackageListAdapter(getActivity());
//mBlacklistPrefList = (PreferenceGroup) findPreference("blacklist_applications");
mBlacklistPrefList = getPreferenceScreen();
mBlacklistPrefList.setOrderingAsAdded(false);
mBlacklistPackages = new HashMap<String, Package>();
mAddBlacklistPref = findPreference("add_blacklist_packages");
mAddBlacklistPref.setOnPreferenceClickListener(this);
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == mAddBlacklistPref) {
showDialog(DIALOG_BLACKLIST_APPS);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.dialog_delete_title)
.setMessage(R.string.dialog_delete_message)
//.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
removeApplicationPref(preference.getKey(), mBlacklistPackages);
}
})
.setNegativeButton(android.R.string.cancel, null);
builder.show();
}
return true;
}
/**
* Application class
*/
private static class Package {
public String name;
/**
* Stores all the application values in one call
* @param name
*/
public Package(String name) {
this.name = name;
}
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(name);
return builder.toString();
}
public static Package fromString(String value) {
if (TextUtils.isEmpty(value)) {
return null;
}
try {
Package item = new Package(value);
return item;
} catch (NumberFormatException e) {
return null;
}
}
};
private void refreshCustomApplicationPrefs() {
if (!parsePackageList()) {
return;
}
// Add the Application Preferences
if (mBlacklistPrefList != null) {
mBlacklistPrefList.removeAll();
for (Package pkg : mBlacklistPackages.values()) {
try {
Preference pref = createPreferenceFromInfo(pkg);
mBlacklistPrefList.addPreference(pref);
} catch (PackageManager.NameNotFoundException e) {
// Do nothing
}
}
}
// Keep these at the top
mAddBlacklistPref.setOrder(0);
// Add 'add' options
mBlacklistPrefList.addPreference(mAddBlacklistPref);
}
private void addCustomApplicationPref(String packageName, Map<String,Package> map) {
Package pkg = map.get(packageName);
if (pkg == null) {
pkg = new Package(packageName);
map.put(packageName, pkg);
savePackageList(false, map);
refreshCustomApplicationPrefs();
}
}
private Preference createPreferenceFromInfo(Package pkg)
throws PackageManager.NameNotFoundException {
PackageInfo info = mPackageManager.getPackageInfo(pkg.name,
PackageManager.GET_META_DATA);
Preference pref =
new Preference(getActivity());
pref.setKey(pkg.name);
pref.setTitle(info.applicationInfo.loadLabel(mPackageManager));
pref.setIcon(info.applicationInfo.loadIcon(mPackageManager));
pref.setPersistent(false);
pref.setOnPreferenceClickListener(this);
return pref;
}
private void removeApplicationPref(String packageName, Map<String,Package> map) {
if (map.remove(packageName) != null) {
savePackageList(false, map);
refreshCustomApplicationPrefs();
}
}
private boolean parsePackageList() {
boolean parsed = false;
final String blacklistString = Settings.System.getString(getActivity().getContentResolver(),
Settings.System.SLIM_RECENTS_BLACKLIST_VALUES);
if (!TextUtils.equals(mBlacklistPackageList, blacklistString)) {
mBlacklistPackageList = blacklistString;
mBlacklistPackages.clear();
parseAndAddToMap(blacklistString, mBlacklistPackages);
parsed = true;
}
return parsed;
}
private void parseAndAddToMap(String baseString, Map<String,Package> map) {
if (baseString == null) {
return;
}
final String[] array = TextUtils.split(baseString, "\\|");
for (String item : array) {
if (TextUtils.isEmpty(item)) {
continue;
}
Package pkg = Package.fromString(item);
map.put(pkg.name, pkg);
}
}
private void savePackageList(boolean preferencesUpdated, Map<String,Package> map) {
String setting = Settings.System.SLIM_RECENTS_BLACKLIST_VALUES;
List<String> settings = new ArrayList<String>();
for (Package app : map.values()) {
settings.add(app.toString());
}
final String value = TextUtils.join("|", settings);
if (preferencesUpdated) {
mBlacklistPackageList = value;
}
Settings.System.putString(getActivity().getContentResolver(),
setting, value);
}
}

View File

@@ -39,28 +39,6 @@ import java.util.Collections;
public class StatusBarSettings extends SettingsPreferenceFragment implements
OnPreferenceChangeListener {
private static final String STATUS_BAR_CLOCK = "status_bar_clock";
private static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
private static final String STATUS_BAR_BATTERY_TEXT_CHARGING = "status_bar_battery_text_charging";
private static final String STATUS_BAR_BATTERY_CHARGING_BOLT = "status_bar_battery_charging_bolt";
private static final String BATTERY_PERCENTAGE_HIDDEN = "0";
private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
private static final String BATTERY_BAR = "battery_bar_settings";
private static final int BATTERY_STYLE_Q = 0;
private static final int BATTERY_STYLE_DOTTED_CIRCLE = 1;
private static final int BATTERY_STYLE_CIRCLE = 2;
private static final int BATTERY_STYLE_TEXT = 3;
private static final int BATTERY_STYLE_HIDDEN = 4;
private SystemSettingMasterSwitchPreference mStatusBarClockShow;
private ListPreference mBatteryPercent;
private ListPreference mBatteryStyle;
private SwitchPreference mBatteryCharging;
private CustomSeekBarPreference mThreshold;
private SystemSettingSwitchPreference mNetMonitor;
private SwitchPreference mBatteryBolt;
private SystemSettingMasterSwitchPreference mBatteryBar;
@Override
public void onCreate(Bundle icicle) {
@@ -71,119 +49,14 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
ContentResolver resolver = getActivity().getContentResolver();
PreferenceScreen prefSet = getPreferenceScreen();
mStatusBarClockShow = (SystemSettingMasterSwitchPreference) findPreference(STATUS_BAR_CLOCK);
mStatusBarClockShow.setChecked((Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CLOCK, 1) == 1));
mStatusBarClockShow.setOnPreferenceChangeListener(this);
mBatteryPercent = (ListPreference) findPreference(STATUS_BAR_SHOW_BATTERY_PERCENT);
mBatteryCharging = (SwitchPreference) findPreference(STATUS_BAR_BATTERY_TEXT_CHARGING);
mBatteryCharging.setOnPreferenceChangeListener(this);
mBatteryBolt = (SwitchPreference) findPreference(STATUS_BAR_BATTERY_CHARGING_BOLT);
mBatteryBolt.setOnPreferenceChangeListener(this);
mBatteryStyle = (ListPreference) findPreference(STATUS_BAR_BATTERY_STYLE);
int batterystyle = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_Q);
mBatteryStyle.setOnPreferenceChangeListener(this);
updateBatteryOptions(batterystyle);
boolean isNetMonitorEnabled = Settings.System.getIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_STATE, 1, UserHandle.USER_CURRENT) == 1;
mNetMonitor = (SystemSettingSwitchPreference) findPreference("network_traffic_state");
mNetMonitor.setChecked(isNetMonitorEnabled);
mNetMonitor.setOnPreferenceChangeListener(this);
int value = Settings.System.getIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, 1, UserHandle.USER_CURRENT);
mThreshold = (CustomSeekBarPreference) findPreference("network_traffic_autohide_threshold");
mThreshold.setValue(value);
mThreshold.setOnPreferenceChangeListener(this);
mThreshold.setEnabled(isNetMonitorEnabled);
mBatteryBar = (SystemSettingMasterSwitchPreference)
findPreference(BATTERY_BAR);
mBatteryBar.setOnPreferenceChangeListener(this);
boolean enabled = Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_LOCATION, 0) != 0;
mBatteryBar.setChecked(enabled);
}
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
if (preference == mStatusBarClockShow) {
boolean value = (Boolean) objValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_CLOCK, value ? 1 : 0);
return true;
} else if (preference == mBatteryStyle) {
int value = Integer.parseInt((String) objValue);
updateBatteryOptions(value);
return true;
} else if (preference == mNetMonitor) {
boolean value = (Boolean) objValue;
Settings.System.putIntForUser(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_STATE, value ? 1 : 0,
UserHandle.USER_CURRENT);
mNetMonitor.setChecked(value);
mThreshold.setEnabled(value);
return true;
} else if (preference == mThreshold) {
int val = (Integer) objValue;
Settings.System.putIntForUser(getContentResolver(),
Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, val,
UserHandle.USER_CURRENT);
return true;
} else if (preference == mBatteryCharging) {
boolean enabled = (Boolean) objValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_BATTERY_TEXT_CHARGING,
enabled ? 1 : 0);
updateBoltEnablement();
return true;
} else if (preference == mBatteryBolt) {
boolean enabled = (Boolean) objValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_BATTERY_CHARGING_BOLT,
enabled ? 1 : 0);
return true;
} else if (preference == mBatteryBar) {
boolean enabled = (boolean) objValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.BATTERY_BAR_LOCATION, enabled ? 1 : 0);
return true;
}
return false;
}
private void updateBatteryOptions(int batterystyle) {
boolean enabled = batterystyle != BATTERY_STYLE_TEXT && batterystyle != BATTERY_STYLE_HIDDEN;
if (batterystyle == BATTERY_STYLE_HIDDEN) {
mBatteryPercent.setValue(BATTERY_PERCENTAGE_HIDDEN);
mBatteryPercent.setSummary(mBatteryPercent.getEntry());
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
}
mBatteryCharging.setEnabled(enabled);
mBatteryPercent.setEnabled(enabled);
updateBoltEnablement();
}
private void updateBoltEnablement() {
int batteryStyle = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_Q);
boolean precentOnCharging = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_BATTERY_TEXT_CHARGING, 1) == 1;
boolean textEnabled = batteryStyle == BATTERY_STYLE_TEXT ||
(batteryStyle == BATTERY_STYLE_HIDDEN && precentOnCharging);
mBatteryBolt.setEnabled(textEnabled);
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;

View File

@@ -43,33 +43,6 @@ import net.margaritov.preference.colorpicker.ColorPickerPreference;
public class ThemeSettings extends SettingsPreferenceFragment implements
OnPreferenceChangeListener {
private static final String PREF_THEME_SWITCH = "theme_switch";
private static final String SYSUI_ROUNDED_SIZE = "sysui_rounded_size";
private static final String SYSUI_ROUNDED_CONTENT_PADDING = "sysui_rounded_content_padding";
private static final String SYSUI_STATUS_BAR_PADDING = "sysui_status_bar_padding";
private static final String SYSUI_ROUNDED_FWVALS = "sysui_rounded_fwvals";
private static final String SWITCH_STYLE = "switch_style";
private static final String QS_TILE_STYLE = "qs_tile_style";
private static final String QS_HEADER_STYLE = "qs_header_style";
private static final String BRIGHTNESS_SLIDER_STYLE = "brightness_slider_style";
private static final String NAVBAR_STYLE = "navbar_style";
private static final String UI_STYLE = "ui_style";
private UiModeManager mUiModeManager;
private IOverlayManager mOverlayService;
private ListPreference mThemeSwitch;
private CustomSeekBarPreference mCornerRadius;
private CustomSeekBarPreference mContentPadding;
private CustomSeekBarPreference mSBPadding;
private SwitchPreference mRoundedFwvals;
private ListPreference mSwitchStyle;
private ListPreference mQsTileStyle;
private ListPreference mQsHeaderStyle;
private ListPreference mBrightnessSliderStyle;
private ListPreference mUIStyle;
private ListPreference mNavbarStyle;
@Override
public void onCreate(Bundle icicle) {
@@ -79,377 +52,14 @@ public class ThemeSettings extends SettingsPreferenceFragment implements
PreferenceScreen prefScreen = getPreferenceScreen();
ContentResolver resolver = getActivity().getContentResolver();
Resources res = null;
Context ctx = getContext();
float density = Resources.getSystem().getDisplayMetrics().density;
try {
res = ctx.getPackageManager().getResourcesForApplication("com.android.systemui");
} catch (NameNotFoundException e) {
e.printStackTrace();
}
mUIStyle = (ListPreference) findPreference(UI_STYLE);
int UIStyle = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.UI_STYLE, 0);
int UIStyleValue = getOverlayPosition(ThemesUtils.UI_THEMES);
if (UIStyleValue != 0) {
mUIStyle.setValue(String.valueOf(UIStyle));
}
mUIStyle.setSummary(mUIStyle.getEntry());
mUIStyle.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mUIStyle) {
String value = (String) newValue;
Settings.System.putInt(getActivity().getContentResolver(), Settings.System.UI_STYLE, Integer.valueOf(value));
int valueIndex = mUIStyle.findIndexOfValue(value);
mUIStyle.setSummary(mUIStyle.getEntries()[valueIndex]);
String overlayName = getOverlayName(ThemesUtils.UI_THEMES);
if (overlayName != null) {
handleOverlays(overlayName, false, mOverlayService);
}
if (valueIndex > 0) {
handleOverlays(ThemesUtils.UI_THEMES[valueIndex],
true, mOverlayService);
}
return true;
}
return false;
}
});
mBrightnessSliderStyle = (ListPreference) findPreference(BRIGHTNESS_SLIDER_STYLE);
int BrightnessSliderStyle = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.BRIGHTNESS_SLIDER_STYLE, 0);
int BrightnessSliderStyleValue = getOverlayPosition(ThemesUtils.BRIGHTNESS_SLIDER_THEMES);
if (BrightnessSliderStyleValue != 0) {
mBrightnessSliderStyle.setValue(String.valueOf(BrightnessSliderStyle));
}
mBrightnessSliderStyle.setSummary(mBrightnessSliderStyle.getEntry());
mBrightnessSliderStyle.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mBrightnessSliderStyle) {
String value = (String) newValue;
Settings.System.putInt(getActivity().getContentResolver(), Settings.System.BRIGHTNESS_SLIDER_STYLE, Integer.valueOf(value));
int valueIndex = mBrightnessSliderStyle.findIndexOfValue(value);
mBrightnessSliderStyle.setSummary(mBrightnessSliderStyle.getEntries()[valueIndex]);
String overlayName = getOverlayName(ThemesUtils.BRIGHTNESS_SLIDER_THEMES);
if (overlayName != null) {
handleOverlays(overlayName, false, mOverlayService);
}
if (valueIndex > 0) {
handleOverlays(ThemesUtils.BRIGHTNESS_SLIDER_THEMES[valueIndex],
true, mOverlayService);
}
return true;
}
return false;
}
});
mNavbarStyle = (ListPreference) findPreference(NAVBAR_STYLE);
int navbarStyle = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.NAVBAR_STYLE, 0);
int navbarStyleValue = getOverlayPosition(ThemesUtils.NAVBAR_STYLES);
if (navbarStyleValue != 0) {
mNavbarStyle.setValue(String.valueOf(navbarStyle));
}
mNavbarStyle.setSummary(mNavbarStyle.getEntry());
mNavbarStyle.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mNavbarStyle) {
String value = (String) newValue;
Settings.System.putInt(getActivity().getContentResolver(), Settings.System.NAVBAR_STYLE, Integer.valueOf(value));
int valueIndex = mNavbarStyle.findIndexOfValue(value);
mNavbarStyle.setSummary(mNavbarStyle.getEntries()[valueIndex]);
String overlayName = getOverlayName(ThemesUtils.NAVBAR_STYLES);
if (overlayName != null) {
handleOverlays(overlayName, false, mOverlayService);
}
if (valueIndex > 0) {
handleOverlays(ThemesUtils.NAVBAR_STYLES[valueIndex],
true, mOverlayService);
}
return true;
}
return false;
}
});
// Rounded Corner Radius
mCornerRadius = (CustomSeekBarPreference) findPreference(SYSUI_ROUNDED_SIZE);
int resourceIdRadius = (int) ctx.getResources().getDimension(com.android.internal.R.dimen.rounded_corner_radius);
int cornerRadius = Settings.Secure.getIntForUser(ctx.getContentResolver(), Settings.Secure.SYSUI_ROUNDED_SIZE,
((int) (resourceIdRadius / density)), UserHandle.USER_CURRENT);
mCornerRadius.setValue(cornerRadius);
mCornerRadius.setOnPreferenceChangeListener(this);
// Rounded Content Padding
mContentPadding = (CustomSeekBarPreference) findPreference(SYSUI_ROUNDED_CONTENT_PADDING);
int resourceIdPadding = res.getIdentifier("com.android.systemui:dimen/rounded_corner_content_padding", null,
null);
int contentPadding = Settings.Secure.getIntForUser(ctx.getContentResolver(),
Settings.Secure.SYSUI_ROUNDED_CONTENT_PADDING,
(int) (res.getDimension(resourceIdPadding) / density), UserHandle.USER_CURRENT);
mContentPadding.setValue(contentPadding);
mContentPadding.setOnPreferenceChangeListener(this);
// Status Bar Content Padding
mSBPadding = (CustomSeekBarPreference) findPreference(SYSUI_STATUS_BAR_PADDING);
int resourceIdSBPadding = res.getIdentifier("com.android.systemui:dimen/status_bar_extra_padding", null,
null);
int sbPadding = Settings.Secure.getIntForUser(ctx.getContentResolver(),
Settings.Secure.SYSUI_STATUS_BAR_PADDING,
(int) (res.getDimension(resourceIdSBPadding) / density), UserHandle.USER_CURRENT);
mSBPadding.setValue(sbPadding);
mSBPadding.setOnPreferenceChangeListener(this);
// Rounded use Framework Values
mRoundedFwvals = (SwitchPreference) findPreference(SYSUI_ROUNDED_FWVALS);
mRoundedFwvals.setOnPreferenceChangeListener(this);
mSwitchStyle = (ListPreference) findPreference(SWITCH_STYLE);
int switchStyle = Settings.System.getInt(resolver,
Settings.System.SWITCH_STYLE, 1);
int switchValueIndex = mSwitchStyle.findIndexOfValue(String.valueOf(switchStyle));
mSwitchStyle.setValueIndex(switchValueIndex >= 0 ? switchValueIndex : 0);
mSwitchStyle.setSummary(mSwitchStyle.getEntry());
mSwitchStyle.setOnPreferenceChangeListener(this);
mQsTileStyle = (ListPreference) findPreference(QS_TILE_STYLE);
int qsTileStyle = Settings.System.getIntForUser(resolver,
Settings.System.QS_TILE_STYLE, 0, UserHandle.USER_CURRENT);
int valueIndex = mQsTileStyle.findIndexOfValue(String.valueOf(qsTileStyle));
mQsTileStyle.setValueIndex(valueIndex >= 0 ? valueIndex : 0);
mQsTileStyle.setSummary(mQsTileStyle.getEntry());
mQsTileStyle.setOnPreferenceChangeListener(this);
mQsHeaderStyle = (ListPreference)findPreference(QS_HEADER_STYLE);
int qsHeaderStyle = Settings.System.getInt(resolver,
Settings.System.QS_HEADER_STYLE, 0);
int qsvalueIndex = mQsHeaderStyle.findIndexOfValue(String.valueOf(qsHeaderStyle));
mQsHeaderStyle.setValueIndex(qsvalueIndex >= 0 ? qsvalueIndex : 0);
mQsHeaderStyle.setSummary(mQsHeaderStyle.getEntry());
mQsHeaderStyle.setOnPreferenceChangeListener(this);
mOverlayService = IOverlayManager.Stub
.asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE));
mUiModeManager = getContext().getSystemService(UiModeManager.class);
setupThemeSwitchPref();
}
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mThemeSwitch) {
String theme_switch = (String) objValue;
final Context context = getContext();
switch (theme_switch) {
case "1":
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.SOLARIZED_DARK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.BAKED_GREEN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.CHOCO_X);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.PITCH_BLACK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.DARK_GREY);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.MATERIAL_OCEAN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.CLEAR_SPRING);
break;
case "2":
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CLEAR_SPRING);
break;
case "3":
handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CLEAR_SPRING);
break;
case "4":
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK);
handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CLEAR_SPRING);
break;
case "5":
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN);
handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CLEAR_SPRING);
break;
case "6":
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X);
handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CLEAR_SPRING);
break;
case "7":
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK);
handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CLEAR_SPRING);
break;
case "8":
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY);
handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CLEAR_SPRING);
break;
case "9":
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY);
handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN);
handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CLEAR_SPRING);
break;
}
try {
mOverlayService.reloadAndroidAssets(UserHandle.USER_CURRENT);
mOverlayService.reloadAssets("com.android.settings", UserHandle.USER_CURRENT);
mOverlayService.reloadAssets("com.android.systemui", UserHandle.USER_CURRENT);
} catch (RemoteException ignored) {
}
} else if (preference == mCornerRadius) {
Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.SYSUI_ROUNDED_SIZE,
(int) objValue, UserHandle.USER_CURRENT);
} else if (preference == mContentPadding) {
Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.SYSUI_ROUNDED_CONTENT_PADDING,
(int) objValue, UserHandle.USER_CURRENT);
} else if (preference == mSBPadding) {
Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.SYSUI_STATUS_BAR_PADDING,
(int) objValue, UserHandle.USER_CURRENT);
} else if (preference == mRoundedFwvals) {
restoreCorners();
} else if (preference == mSwitchStyle) {
String value = (String) objValue;
Settings.System.putInt(resolver, Settings.System.SWITCH_STYLE, Integer.valueOf(value));
int valueIndex = mSwitchStyle.findIndexOfValue(value);
mSwitchStyle.setSummary(mSwitchStyle.getEntries()[valueIndex]);
} else if (preference == mQsTileStyle) {
int qsTileStyleValue = Integer.valueOf((String) objValue);
Settings.System.putIntForUser(resolver,
Settings.System.QS_TILE_STYLE, qsTileStyleValue, UserHandle.USER_CURRENT);
mQsTileStyle.setSummary(mQsTileStyle.getEntries()[qsTileStyleValue]);
} else if (preference == mQsHeaderStyle) {
String value = (String) objValue;
Settings.System.putInt(resolver,
Settings.System.QS_HEADER_STYLE, Integer.valueOf(value));
int newIndex = mQsHeaderStyle.findIndexOfValue(value);
mQsHeaderStyle.setSummary(mQsHeaderStyle.getEntries()[newIndex]);
}
return true;
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
return false;
}
private void setupThemeSwitchPref() {
mThemeSwitch = (ListPreference) findPreference(PREF_THEME_SWITCH);
mThemeSwitch.setOnPreferenceChangeListener(this);
if (CherishUtils.isThemeEnabled("com.android.theme.clearspring.system")) {
mThemeSwitch.setValue("9");
} else if (CherishUtils.isThemeEnabled("com.android.theme.darkgrey.system")) {
mThemeSwitch.setValue("7");
} else if (CherishUtils.isThemeEnabled("com.android.theme.pitchblack.system")) {
mThemeSwitch.setValue("6");
} else if (CherishUtils.isThemeEnabled("com.android.theme.materialocean.system")) {
mThemeSwitch.setValue("8");
} else if (CherishUtils.isThemeEnabled("com.android.theme.chocox.system")) {
mThemeSwitch.setValue("5");
} else if (CherishUtils.isThemeEnabled("com.android.theme.bakedgreen.system")) {
mThemeSwitch.setValue("4");
} else if (CherishUtils.isThemeEnabled("com.android.theme.solarizeddark.system")) {
mThemeSwitch.setValue("3");
} else if (mUiModeManager.getNightMode() == UiModeManager.MODE_NIGHT_YES) {
mThemeSwitch.setValue("2");
} else {
mThemeSwitch.setValue("1");
}
}
private void handleBackgrounds(Boolean state, Context context, int mode, String[] overlays) {
if (context != null) {
Objects.requireNonNull(context.getSystemService(UiModeManager.class))
.setNightMode(mode);
}
for (int i = 0; i < overlays.length; i++) {
String background = overlays[i];
try {
mOverlayService.setEnabled(background, state, USER_SYSTEM);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
private void restoreCorners() {
Resources res = null;
float density = Resources.getSystem().getDisplayMetrics().density;
Context ctx = getContext();
try {
res = ctx.getPackageManager().getResourcesForApplication("com.android.systemui");
} catch (NameNotFoundException e) {
e.printStackTrace();
}
int resourceIdRadius = (int) ctx.getResources().getDimension(com.android.internal.R.dimen.rounded_corner_radius);
int resourceIdPadding = res.getIdentifier("com.android.systemui:dimen/rounded_corner_content_padding", null,
null);
int resourceIdSBPadding = res.getIdentifier("com.android.systemui:dimen/status_bar_extra_padding", null,
null);
mCornerRadius.setValue((int) (resourceIdRadius / density));
mContentPadding.setValue((int) (res.getDimension(resourceIdPadding) / density));
mSBPadding.setValue((int) (res.getDimension(resourceIdSBPadding) / density));
}
private String getOverlayName(String[] overlays) {
String overlayName = null;
for (int i = 0; i < overlays.length; i++) {
String overlay = overlays[i];
if (CherishUtils.isThemeEnabled(overlay)) {
overlayName = overlay;
}
}
return overlayName;
}
private int getOverlayPosition(String[] overlays) {
int position = -1;
for (int i = 0; i < overlays.length; i++) {
String overlay = overlays[i];
if (CherishUtils.isThemeEnabled(overlay)) {
position = i;
}
}
return position;
}
@Override
public int getMetricsCategory() {

View File

@@ -1,259 +0,0 @@
/*
* Copyright (C) 2013 Android Open Kang Project
* Copyright (C) 2017 faust93 at monumentum@gmail.com
*
* 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.Context;
import android.content.Intent;
import android.content.ContentResolver;
import android.content.res.Resources;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.android.settingslib.search.SearchIndexable;
import com.cherish.settings.preferences.CustomSeekBarPreference;
import java.util.ArrayList;
import java.util.List;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
@SearchIndexable
public class BatteryBar extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener, Indexable {
private static final String PREF_BATT_BAR = "battery_bar_list";
private static final String PREF_BATT_BAR_STYLE = "battery_bar_style";
private static final String PREF_BATT_BAR_COLOR = "battery_bar_color";
private static final String PREF_BATT_BAR_CHARGING_COLOR = "battery_bar_charging_color";
private static final String PREF_BATT_BAR_LOW_COLOR_WARNING = "battery_bar_battery_low_color_warning";
private static final String PREF_BATT_BAR_USE_GRADIENT_COLOR = "battery_bar_use_gradient_color";
private static final String PREF_BATT_BAR_LOW_COLOR = "battery_bar_low_color";
private static final String PREF_BATT_BAR_HIGH_COLOR = "battery_bar_high_color";
private static final String PREF_BATT_BAR_WIDTH = "battery_bar_thickness";
private static final String PREF_BATT_ANIMATE = "battery_bar_animate";
private Context mContext;
private ListPreference mBatteryBar;
private ListPreference mBatteryBarStyle;
private CustomSeekBarPreference mBatteryBarThickness;
private SwitchPreference mBatteryBarChargingAnimation;
private SwitchPreference mBatteryBarUseGradient;
private ColorPickerPreference mBatteryBarColor;
private ColorPickerPreference mBatteryBarChargingColor;
private ColorPickerPreference mBatteryBarBatteryLowColor;
private ColorPickerPreference mBatteryBarBatteryLowColorWarn;
private ColorPickerPreference mBatteryBarBatteryHighColor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.battery_bar);
mContext = (Context) getActivity();
final ContentResolver resolver = getActivity().getContentResolver();
PreferenceScreen prefSet = getPreferenceScreen();
mBatteryBar = (ListPreference) findPreference(PREF_BATT_BAR);
mBatteryBar.setOnPreferenceChangeListener(this);
boolean enabled = Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_LOCATION, 0) != 0;
if (enabled) {
mBatteryBar.setValue((Settings.System.getInt(resolver, Settings.System.BATTERY_BAR_LOCATION, 0)) + "");
mBatteryBar.setSummary(mBatteryBar.getEntry());
} else {
mBatteryBar.setEnabled(false);
mBatteryBar.setSummary(R.string.enable_first);
}
mBatteryBarStyle = (ListPreference) findPreference(PREF_BATT_BAR_STYLE);
mBatteryBarStyle.setOnPreferenceChangeListener(this);
mBatteryBarStyle.setValue((Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_STYLE, 0)) + "");
mBatteryBarStyle.setSummary(mBatteryBarStyle.getEntry());
mBatteryBarColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_COLOR);
mBatteryBarColor.setNewPreviewColor(Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_COLOR, Color.WHITE));
mBatteryBarColor.setOnPreferenceChangeListener(this);
mBatteryBarChargingColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_CHARGING_COLOR);
mBatteryBarChargingColor.setNewPreviewColor(Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_CHARGING_COLOR, Color.WHITE));
mBatteryBarChargingColor.setOnPreferenceChangeListener(this);
mBatteryBarBatteryLowColorWarn = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_LOW_COLOR_WARNING);
mBatteryBarBatteryLowColorWarn.setNewPreviewColor(Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_BATTERY_LOW_COLOR_WARNING,Color.WHITE));
mBatteryBarBatteryLowColorWarn.setOnPreferenceChangeListener(this);
mBatteryBarBatteryLowColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_LOW_COLOR);
mBatteryBarBatteryLowColor.setNewPreviewColor(Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_LOW_COLOR, Color.WHITE));
mBatteryBarBatteryLowColor.setOnPreferenceChangeListener(this);
mBatteryBarBatteryHighColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_HIGH_COLOR);
mBatteryBarBatteryHighColor.setNewPreviewColor(Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_HIGH_COLOR, Color.WHITE));
mBatteryBarBatteryHighColor.setOnPreferenceChangeListener(this);
mBatteryBarUseGradient = (SwitchPreference) findPreference(PREF_BATT_BAR_USE_GRADIENT_COLOR);
mBatteryBarUseGradient.setChecked(Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_USE_GRADIENT_COLOR, 0) == 1);
mBatteryBarChargingAnimation = (SwitchPreference) findPreference(PREF_BATT_ANIMATE);
mBatteryBarChargingAnimation.setChecked(Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_ANIMATE, 0) == 1);
mBatteryBarThickness = (CustomSeekBarPreference) prefSet.findPreference(PREF_BATT_BAR_WIDTH);
mBatteryBarThickness.setValue(Settings.System.getInt(resolver,
Settings.System.BATTERY_BAR_THICKNESS, 1));
mBatteryBarThickness.setOnPreferenceChangeListener(this);
updateBatteryBarOptions();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mBatteryBarColor) {
int intHex = (Integer) newValue;
Settings.System.putInt(resolver,
Settings.System.BATTERY_BAR_COLOR, intHex);
return true;
} else if (preference == mBatteryBarChargingColor) {
int intHex = (Integer) newValue;
Settings.System.putInt(resolver,
Settings.System.BATTERY_BAR_CHARGING_COLOR, intHex);
return true;
} else if (preference == mBatteryBarBatteryLowColor) {
int intHex = (Integer) newValue;
Settings.System.putInt(resolver,
Settings.System.BATTERY_BAR_LOW_COLOR, intHex);
return true;
} else if (preference == mBatteryBarBatteryLowColorWarn) {
int intHex = (Integer) newValue;
Settings.System.putInt(resolver,
Settings.System.BATTERY_BAR_BATTERY_LOW_COLOR_WARNING, intHex);
return true;
} else if (preference == mBatteryBarBatteryHighColor) {
int intHex = (Integer) newValue;
Settings.System.putInt(resolver,
Settings.System.BATTERY_BAR_HIGH_COLOR, intHex);
return true;
} else if (preference == mBatteryBar) {
int val = Integer.parseInt((String) newValue);
int index = mBatteryBar.findIndexOfValue((String) newValue);
Settings.System.putInt(resolver,
Settings.System.BATTERY_BAR_LOCATION, val);
mBatteryBar.setSummary(mBatteryBar.getEntries()[index]);
updateBatteryBarOptions();
return true;
} else if (preference == mBatteryBarStyle) {
int val = Integer.parseInt((String) newValue);
int index = mBatteryBarStyle.findIndexOfValue((String) newValue);
Settings.System.putInt(resolver,
Settings.System.BATTERY_BAR_STYLE, val);
mBatteryBarStyle.setSummary(mBatteryBarStyle.getEntries()[index]);
return true;
} else if (preference == mBatteryBarThickness) {
int val = (Integer) newValue;
Settings.System.putInt(resolver,
Settings.System.BATTERY_BAR_THICKNESS, val);
return true;
}
return false;
}
public boolean onPreferenceTreeClick(Preference preference) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mBatteryBarChargingAnimation) {
boolean value = mBatteryBarChargingAnimation.isChecked();
Settings.System.putInt(resolver,
Settings.System.BATTERY_BAR_ANIMATE, value ? 1 : 0);
return true;
} else if (preference == mBatteryBarUseGradient) {
boolean value = mBatteryBarUseGradient.isChecked();
Settings.System.putInt(getContentResolver(),
Settings.System.BATTERY_BAR_USE_GRADIENT_COLOR, value ? 1 : 0);
return true;
}
return false;
}
private void updateBatteryBarOptions() {
boolean enabled = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.BATTERY_BAR_LOCATION, 0) != 0;
mBatteryBarStyle.setEnabled(enabled);
mBatteryBarThickness.setEnabled(enabled);
mBatteryBarChargingAnimation.setEnabled(enabled);
mBatteryBarColor.setEnabled(enabled);
mBatteryBarChargingColor.setEnabled(enabled);
mBatteryBarUseGradient.setEnabled(enabled);
mBatteryBarBatteryLowColor.setEnabled(enabled);
mBatteryBarBatteryHighColor.setEnabled(enabled);
mBatteryBarBatteryLowColorWarn.setEnabled(enabled);
}
@Override
public int getMetricsCategory() {
return MetricsEvent.CHERISH_SETTINGS;
}
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.battery_bar;
result.add(sir);
return result;
}
@Override
public List<String> getNonIndexableKeys(Context context) {
List<String> keys = super.getNonIndexableKeys(context);
return keys;
}
};
}