Cherish:Cleanup for android 12
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Yet Another AOSP Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import static com.cherish.settings.fragments.LockScreenSettings.MODE_DISABLED;
|
||||
import static com.cherish.settings.fragments.LockScreenSettings.MODE_NIGHT;
|
||||
import static com.cherish.settings.fragments.LockScreenSettings.MODE_TIME;
|
||||
import static com.cherish.settings.fragments.LockScreenSettings.MODE_MIXED_SUNSET;
|
||||
import static com.cherish.settings.fragments.LockScreenSettings.MODE_MIXED_SUNRISE;
|
||||
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.format.DateFormat;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import com.cherish.settings.preferences.SecureSettingListPreference;
|
||||
|
||||
@SearchIndexable
|
||||
public class AODSchedule extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String MODE_KEY = "doze_always_on_auto_mode";
|
||||
private static final String SINCE_PREF_KEY = "doze_always_on_auto_since";
|
||||
private static final String TILL_PREF_KEY = "doze_always_on_auto_till";
|
||||
|
||||
private SecureSettingListPreference mModePref;
|
||||
private Preference mSincePref;
|
||||
private Preference mTillPref;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.cherish_settings_aod_schedule);
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
mSincePref = findPreference(SINCE_PREF_KEY);
|
||||
mSincePref.setOnPreferenceClickListener(this);
|
||||
mTillPref = findPreference(TILL_PREF_KEY);
|
||||
mTillPref.setOnPreferenceClickListener(this);
|
||||
|
||||
int mode = Settings.Secure.getIntForUser(resolver,
|
||||
MODE_KEY, MODE_DISABLED, UserHandle.USER_CURRENT);
|
||||
mModePref = (SecureSettingListPreference) findPreference(MODE_KEY);
|
||||
mModePref.setValue(String.valueOf(mode));
|
||||
mModePref.setSummary(mModePref.getEntry());
|
||||
mModePref.setOnPreferenceChangeListener(this);
|
||||
|
||||
updateTimeEnablement(mode);
|
||||
updateTimeSummary(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
int value = Integer.valueOf((String) objValue);
|
||||
int index = mModePref.findIndexOfValue((String) objValue);
|
||||
mModePref.setSummary(mModePref.getEntries()[index]);
|
||||
Settings.Secure.putIntForUser(getActivity().getContentResolver(),
|
||||
MODE_KEY, value, UserHandle.USER_CURRENT);
|
||||
updateTimeEnablement(value);
|
||||
updateTimeSummary(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String[] times = getCustomTimeSetting();
|
||||
boolean isSince = preference == mSincePref;
|
||||
int hour, minute; hour = minute = 0;
|
||||
TimePickerDialog.OnTimeSetListener listener = new TimePickerDialog.OnTimeSetListener() {
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
updateTimeSetting(isSince, hourOfDay, minute);
|
||||
}
|
||||
};
|
||||
if (isSince) {
|
||||
String[] sinceValues = times[0].split(":", 0);
|
||||
hour = Integer.parseInt(sinceValues[0]);
|
||||
minute = Integer.parseInt(sinceValues[1]);
|
||||
} else {
|
||||
String[] tillValues = times[1].split(":", 0);
|
||||
hour = Integer.parseInt(tillValues[0]);
|
||||
minute = Integer.parseInt(tillValues[1]);
|
||||
}
|
||||
TimePickerDialog dialog = new TimePickerDialog(getContext(), listener,
|
||||
hour, minute, DateFormat.is24HourFormat(getContext()));
|
||||
dialog.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
private String[] getCustomTimeSetting() {
|
||||
String value = Settings.Secure.getStringForUser(getActivity().getContentResolver(),
|
||||
Settings.Secure.DOZE_ALWAYS_ON_AUTO_TIME, UserHandle.USER_CURRENT);
|
||||
if (value == null || value.equals("")) value = "20:00,07:00";
|
||||
return value.split(",", 0);
|
||||
}
|
||||
|
||||
private void updateTimeEnablement(int mode) {
|
||||
mSincePref.setEnabled(mode == MODE_TIME || mode == MODE_MIXED_SUNRISE);
|
||||
mTillPref.setEnabled(mode == MODE_TIME || mode == MODE_MIXED_SUNSET);
|
||||
}
|
||||
|
||||
private void updateTimeSummary(int mode) {
|
||||
updateTimeSummary(getCustomTimeSetting(), mode);
|
||||
}
|
||||
|
||||
private void updateTimeSummary(String[] times, int mode) {
|
||||
if (mode == MODE_DISABLED) {
|
||||
mSincePref.setSummary("-");
|
||||
mTillPref.setSummary("-");
|
||||
return;
|
||||
}
|
||||
if (mode == MODE_NIGHT) {
|
||||
mSincePref.setSummary(R.string.always_on_display_schedule_sunset);
|
||||
mTillPref.setSummary(R.string.always_on_display_schedule_sunrise);
|
||||
return;
|
||||
}
|
||||
if (mode == MODE_MIXED_SUNSET) {
|
||||
mSincePref.setSummary(R.string.always_on_display_schedule_sunset);
|
||||
} else if (mode == MODE_MIXED_SUNRISE) {
|
||||
mTillPref.setSummary(R.string.always_on_display_schedule_sunrise);
|
||||
}
|
||||
if (DateFormat.is24HourFormat(getContext())) {
|
||||
if (mode != MODE_MIXED_SUNSET) mSincePref.setSummary(times[0]);
|
||||
if (mode != MODE_MIXED_SUNRISE) mTillPref.setSummary(times[1]);
|
||||
return;
|
||||
}
|
||||
String[] sinceValues = times[0].split(":", 0);
|
||||
String[] tillValues = times[1].split(":", 0);
|
||||
int sinceHour = Integer.parseInt(sinceValues[0]);
|
||||
int tillHour = Integer.parseInt(tillValues[0]);
|
||||
String sinceSummary = "";
|
||||
String tillSummary = "";
|
||||
if (sinceHour > 12) {
|
||||
sinceHour -= 12;
|
||||
sinceSummary += String.valueOf(sinceHour) + ":" + sinceValues[1] + " PM";
|
||||
} else {
|
||||
sinceSummary = times[0].substring(1) + " AM";
|
||||
}
|
||||
if (tillHour > 12) {
|
||||
tillHour -= 12;
|
||||
tillSummary += String.valueOf(tillHour) + ":" + tillValues[1] + " PM";
|
||||
} else {
|
||||
tillSummary = times[0].substring(1) + " AM";
|
||||
}
|
||||
if (mode != MODE_MIXED_SUNSET) mSincePref.setSummary(sinceSummary);
|
||||
if (mode != MODE_MIXED_SUNRISE) mTillPref.setSummary(tillSummary);
|
||||
}
|
||||
|
||||
private void updateTimeSetting(boolean since, int hour, int minute) {
|
||||
String[] times = getCustomTimeSetting();
|
||||
String nHour = "";
|
||||
String nMinute = "";
|
||||
if (hour < 10) nHour += "0";
|
||||
if (minute < 10) nMinute += "0";
|
||||
nHour += String.valueOf(hour);
|
||||
nMinute += String.valueOf(minute);
|
||||
times[since ? 0 : 1] = nHour + ":" + nMinute;
|
||||
Settings.Secure.putStringForUser(getActivity().getContentResolver(),
|
||||
Settings.Secure.DOZE_ALWAYS_ON_AUTO_TIME,
|
||||
times[0] + "," + times[1], UserHandle.USER_CURRENT);
|
||||
updateTimeSummary(times, Integer.parseInt(mModePref.getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.cherish_settings_aod_schedule);
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The LiquidSmooth Project
|
||||
* (C) 2017 faust93 at monumentum@gmail.com
|
||||
* (C) 2018 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.AlarmManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
public class AlarmBlocker extends SettingsPreferenceFragment {
|
||||
|
||||
private static final String TAG = "AlarmBlocker";
|
||||
|
||||
private Switch mBlockerEnabled;
|
||||
private ListView mAlarmList;
|
||||
private List<String> mSeenAlarms;
|
||||
private List<String> mBlockedAlarms;
|
||||
private LayoutInflater mInflater;
|
||||
private Map<String, Boolean> mAlarmState;
|
||||
private AlarmListAdapter mListAdapter;
|
||||
private boolean mEnabled;
|
||||
private AlertDialog mAlertDialog;
|
||||
private boolean mAlertShown = false;
|
||||
private TextView mAlarmListHeader;
|
||||
|
||||
private static final int MENU_RELOAD = Menu.FIRST;
|
||||
private static final int MENU_SAVE = Menu.FIRST + 1;
|
||||
|
||||
public class AlarmListAdapter extends ArrayAdapter<String> {
|
||||
|
||||
public AlarmListAdapter(Context context, int resource, List<String> values) {
|
||||
super(context, R.layout.alarm_item, resource, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View rowView = mInflater.inflate(R.layout.alarm_item, parent, false);
|
||||
final CheckBox check = (CheckBox)rowView.findViewById(R.id.alarm_blocked);
|
||||
check.setText(mSeenAlarms.get(position));
|
||||
|
||||
Boolean checked = mAlarmState.get(check.getText().toString());
|
||||
check.setChecked(checked.booleanValue());
|
||||
|
||||
if(checked.booleanValue()) {
|
||||
check.setTextColor(getResources().getColor(android.R.color.holo_red_light));
|
||||
}
|
||||
|
||||
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton v, boolean checked) {
|
||||
mAlarmState.put(v.getText().toString(), new Boolean(checked));
|
||||
if(checked) {
|
||||
check.setTextColor(getResources().getColor(android.R.color.holo_red_light));
|
||||
mListAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
check.setTextColor(getResources().getColor(android.R.color.primary_text_dark));
|
||||
mListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
return rowView;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.d(TAG, "running");
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
mInflater = inflater;
|
||||
setHasOptionsMenu(true);
|
||||
return inflater.inflate(R.layout.alarm_blocker, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
mAlarmState = new HashMap<String, Boolean>();
|
||||
updateSeenAlarmsList();
|
||||
updateBlockedAlarmsList();
|
||||
|
||||
mBlockerEnabled = (Switch) getActivity().findViewById(
|
||||
R.id.alarm_blocker_switch);
|
||||
mAlarmList = (ListView) getActivity().findViewById(
|
||||
R.id.alarm_list);
|
||||
mAlarmListHeader = (TextView) getActivity().findViewById(
|
||||
R.id.alarm_list_header);
|
||||
|
||||
mListAdapter = new AlarmListAdapter(getActivity(), android.R.layout.simple_list_item_multiple_choice,
|
||||
mSeenAlarms);
|
||||
mAlarmList.setAdapter(mListAdapter);
|
||||
|
||||
updateSwitches();
|
||||
|
||||
// after updateSwitches!!!
|
||||
mBlockerEnabled
|
||||
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton v, boolean checked) {
|
||||
if (checked && isFirstEnable() && !mAlertShown) {
|
||||
showAlert();
|
||||
mAlertShown = true;
|
||||
}
|
||||
|
||||
Settings.Global.putInt(getActivity().getContentResolver(),
|
||||
Settings.Global.ALARM_BLOCKING_ENABLED,
|
||||
checked ? 1 : 0);
|
||||
|
||||
updateSwitches();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
private boolean isFirstEnable() {
|
||||
return Settings.Global.getString(getActivity().getContentResolver(),
|
||||
Settings.Global.ALARM_BLOCKING_LIST) == null;
|
||||
}
|
||||
|
||||
private void updateSwitches() {
|
||||
mBlockerEnabled.setChecked(Settings.Global.getInt(getActivity().getContentResolver(),
|
||||
Settings.Global.ALARM_BLOCKING_ENABLED, 0) == 1);
|
||||
|
||||
mEnabled = mBlockerEnabled.isChecked();
|
||||
mAlarmList.setVisibility(mEnabled ?View.VISIBLE : View.INVISIBLE);
|
||||
mAlarmListHeader.setVisibility(mEnabled ?View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
|
||||
private void updateSeenAlarmsList() {
|
||||
AlarmManager pm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
|
||||
Log.d(TAG, pm.getSeenAlarms());
|
||||
|
||||
String seenAlarms = pm.getSeenAlarms();
|
||||
mSeenAlarms = new ArrayList<String>();
|
||||
|
||||
if (seenAlarms!=null && seenAlarms.length()!=0) {
|
||||
String[] parts = seenAlarms.split("\\|");
|
||||
for(int i = 0; i < parts.length; i++) {
|
||||
mSeenAlarms.add(parts[i]);
|
||||
mAlarmState.put(parts[i], new Boolean(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBlockedAlarmsList() {
|
||||
String blockedAlarmList = Settings.Global.getString(getActivity().getContentResolver(),
|
||||
Settings.Global.ALARM_BLOCKING_LIST);
|
||||
|
||||
mBlockedAlarms = new ArrayList<String>();
|
||||
|
||||
if (blockedAlarmList!=null && blockedAlarmList.length()!=0) {
|
||||
String[] parts = blockedAlarmList.split("\\|");
|
||||
for(int i = 0; i < parts.length; i++) {
|
||||
mBlockedAlarms.add(parts[i]);
|
||||
|
||||
// add all blocked but not seen so far
|
||||
if(!mSeenAlarms.contains(parts[i])) {
|
||||
mSeenAlarms.add(parts[i]);
|
||||
}
|
||||
mAlarmState.put(parts[i], new Boolean(true));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(mSeenAlarms);
|
||||
}
|
||||
|
||||
private void save() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Iterator<String> nextState = mAlarmState.keySet().iterator();
|
||||
while(nextState.hasNext()) {
|
||||
String name = nextState.next();
|
||||
Boolean state=mAlarmState.get(name);
|
||||
if(state.booleanValue()) {
|
||||
buffer.append(name + "|");
|
||||
}
|
||||
}
|
||||
if(buffer.length()>0) {
|
||||
buffer.deleteCharAt(buffer.length() - 1);
|
||||
}
|
||||
Settings.Global.putString(getActivity().getContentResolver(),
|
||||
Settings.Global.ALARM_BLOCKING_LIST, buffer.toString());
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
mAlarmState = new HashMap<String, Boolean>();
|
||||
updateSeenAlarmsList();
|
||||
updateBlockedAlarmsList();
|
||||
|
||||
mListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.add(0, MENU_RELOAD, 0, R.string.alarm_blocker_reload)
|
||||
.setIcon(com.android.internal.R.drawable.ic_menu_refresh)
|
||||
.setAlphabeticShortcut('r')
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
|
||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
menu.add(0, MENU_SAVE, 0, R.string.alarm_blocker_save)
|
||||
.setIcon(R.drawable.ic_wakelockblocker_save)
|
||||
.setAlphabeticShortcut('s')
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
|
||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_RELOAD:
|
||||
if (mEnabled) {
|
||||
reload();
|
||||
}
|
||||
return true;
|
||||
case MENU_SAVE:
|
||||
if (mEnabled) {
|
||||
save();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset(Context mContext) {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.Global.putInt(resolver,
|
||||
Settings.Global.ALARM_BLOCKING_ENABLED, 0);
|
||||
}
|
||||
|
||||
private void showAlert() {
|
||||
/* Display the warning dialog */
|
||||
mAlertDialog = new AlertDialog.Builder(getActivity()).create();
|
||||
mAlertDialog.setTitle(R.string.alarm_blocker_warning_title);
|
||||
mAlertDialog.setMessage(getResources().getString(R.string.alarm_blocker_warning));
|
||||
mAlertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
|
||||
getResources().getString(com.android.internal.R.string.ok),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
mAlertDialog.show();
|
||||
}
|
||||
}
|
||||
@@ -55,25 +55,6 @@ import java.util.List;
|
||||
public class AnimationsSettings extends SettingsPreferenceFragment
|
||||
implements OnPreferenceChangeListener {
|
||||
|
||||
private static final String KEY_TOAST_ANIMATION = "toast_animation";
|
||||
private static final String KEY_LISTVIEW_ANIMATION = "listview_animation";
|
||||
private static final String KEY_LISTVIEW_INTERPOLATOR = "listview_interpolator";
|
||||
private static final String SCROLLINGCACHE_PREF = "pref_scrollingcache";
|
||||
private static final String SCROLLINGCACHE_PERSIST_PROP = "persist.sys.scrollingcache";
|
||||
private static final String SCROLLINGCACHE_DEFAULT = "2";
|
||||
private static final String KEY_SCREEN_OFF_ANIMATION = "screen_off_animation";
|
||||
|
||||
private ListPreference mToastAnimation;
|
||||
private ListPreference mScrollingCachePref;
|
||||
private ListPreference mListViewAnimation;
|
||||
private ListPreference mListViewInterpolator;
|
||||
private ListPreference mScreenOffAnimation;
|
||||
|
||||
private int[] mAnimations;
|
||||
private String[] mAnimationsStrings;
|
||||
private String[] mAnimationsNum;
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
@@ -85,41 +66,6 @@ public class AnimationsSettings extends SettingsPreferenceFragment
|
||||
addPreferencesFromResource(R.xml.cherish_settings_animations);
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
PreferenceScreen prefs = getPreferenceScreen();
|
||||
mContext = getActivity();
|
||||
|
||||
mToastAnimation = (ListPreference) findPreference(KEY_TOAST_ANIMATION);
|
||||
mToastAnimation.setSummary(mToastAnimation.getEntry());
|
||||
int CurrentToastAnimation = Settings.Global.getInt(getContentResolver(), Settings.Global.TOAST_ANIMATION, 1);
|
||||
mToastAnimation.setValueIndex(CurrentToastAnimation); //set to index of default value
|
||||
mToastAnimation.setSummary(mToastAnimation.getEntries()[CurrentToastAnimation]);
|
||||
mToastAnimation.setOnPreferenceChangeListener(this);
|
||||
|
||||
mListViewAnimation = (ListPreference) findPreference(KEY_LISTVIEW_ANIMATION);
|
||||
int listviewanimation = Settings.Global.getInt(getContentResolver(),
|
||||
Settings.Global.LISTVIEW_ANIMATION, 0);
|
||||
mListViewAnimation.setValue(String.valueOf(listviewanimation));
|
||||
mListViewAnimation.setSummary(mListViewAnimation.getEntry());
|
||||
mListViewAnimation.setOnPreferenceChangeListener(this);
|
||||
|
||||
mListViewInterpolator = (ListPreference) findPreference(KEY_LISTVIEW_INTERPOLATOR);
|
||||
int listviewinterpolator = Settings.Global.getInt(getContentResolver(),
|
||||
Settings.Global.LISTVIEW_INTERPOLATOR, 0);
|
||||
mListViewInterpolator.setValue(String.valueOf(listviewinterpolator));
|
||||
mListViewInterpolator.setSummary(mListViewInterpolator.getEntry());
|
||||
mListViewInterpolator.setOnPreferenceChangeListener(this);
|
||||
mListViewInterpolator.setEnabled(listviewanimation > 0);
|
||||
|
||||
mScrollingCachePref = (ListPreference) findPreference(SCROLLINGCACHE_PREF);
|
||||
mScrollingCachePref.setValue(SystemProperties.get(SCROLLINGCACHE_PERSIST_PROP,
|
||||
SystemProperties.get(SCROLLINGCACHE_PERSIST_PROP, SCROLLINGCACHE_DEFAULT)));
|
||||
mScrollingCachePref.setOnPreferenceChangeListener(this);
|
||||
|
||||
mScreenOffAnimation = (ListPreference) findPreference(KEY_SCREEN_OFF_ANIMATION);
|
||||
int screenOffAnimation = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.SCREEN_OFF_ANIMATION, 0);
|
||||
mScreenOffAnimation.setValue(Integer.toString(screenOffAnimation));
|
||||
mScreenOffAnimation.setSummary(mScreenOffAnimation.getEntry());
|
||||
mScreenOffAnimation.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,39 +76,6 @@ public class AnimationsSettings extends SettingsPreferenceFragment
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mToastAnimation) {
|
||||
int index = mToastAnimation.findIndexOfValue((String) newValue);
|
||||
Settings.Global.putString(getContentResolver(), Settings.Global.TOAST_ANIMATION, (String) newValue);
|
||||
mToastAnimation.setSummary(mToastAnimation.getEntries()[index]);
|
||||
Toast.makeText(mContext, "Toast Test", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
} else if (preference == mListViewAnimation) {
|
||||
int value = Integer.parseInt((String) newValue);
|
||||
int index = mListViewAnimation.findIndexOfValue((String) newValue);
|
||||
Settings.Global.putInt(getContentResolver(),
|
||||
Settings.Global.LISTVIEW_ANIMATION, value);
|
||||
mListViewAnimation.setSummary(mListViewAnimation.getEntries()[index]);
|
||||
mListViewInterpolator.setEnabled(value > 0);
|
||||
return true;
|
||||
} else if (preference == mListViewInterpolator) {
|
||||
int value = Integer.parseInt((String) newValue);
|
||||
int index = mListViewInterpolator.findIndexOfValue((String) newValue);
|
||||
Settings.Global.putInt(getContentResolver(),
|
||||
Settings.Global.LISTVIEW_INTERPOLATOR, value);
|
||||
mListViewInterpolator.setSummary(mListViewInterpolator.getEntries()[index]);
|
||||
return true;
|
||||
} else if (preference == mScreenOffAnimation) {
|
||||
int value = Integer.valueOf((String) newValue);
|
||||
int index = mScreenOffAnimation.findIndexOfValue((String) newValue);
|
||||
mScreenOffAnimation.setSummary(mScreenOffAnimation.getEntries()[index]);
|
||||
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_ANIMATION, value);
|
||||
return true;
|
||||
} else if (preference == mScrollingCachePref) {
|
||||
if (newValue != null) {
|
||||
SystemProperties.set(SCROLLINGCACHE_PERSIST_PROP, (String) newValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,244 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 The Evolution X Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
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.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
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(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class BatteryBarSettings extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String PREF_BATT_BAR_NO_NAVBAR = "statusbar_battery_bar_no_navbar_list";
|
||||
private static final String PREF_BATT_BAR_STYLE = "statusbar_battery_bar_style";
|
||||
private static final String PREF_BATT_BAR_COLOR = "statusbar_battery_bar_color";
|
||||
private static final String PREF_BATT_BAR_CHARGING_COLOR = "statusbar_battery_bar_charging_color";
|
||||
private static final String PREF_BATT_BAR_BATTERY_LOW_COLOR = "statusbar_battery_bar_battery_low_color";
|
||||
private static final String PREF_BATT_BAR_WIDTH = "statusbar_battery_bar_thickness";
|
||||
private static final String PREF_BATT_ANIMATE = "statusbar_battery_bar_animate";
|
||||
private static final String PREF_BATT_USE_CHARGING_COLOR = "statusbar_battery_bar_enable_charging_color";
|
||||
private static final String PREF_BATT_BLEND_COLOR = "statusbar_battery_bar_blend_color";
|
||||
private static final String PREF_BATT_BLEND_COLOR_REVERSE = "statusbar_battery_bar_blend_color_reverse";
|
||||
|
||||
private ListPreference mBatteryBarNoNavbar;
|
||||
private ListPreference mBatteryBarStyle;
|
||||
private CustomSeekBarPreference mBatteryBarThickness;
|
||||
private SwitchPreference mBatteryBarChargingAnimation;
|
||||
private SwitchPreference mBatteryBarUseChargingColor;
|
||||
private SwitchPreference mBatteryBarBlendColor;
|
||||
private SwitchPreference mBatteryBarBlendColorReverse;
|
||||
private ColorPickerPreference mBatteryBarColor;
|
||||
private ColorPickerPreference mBatteryBarChargingColor;
|
||||
private ColorPickerPreference mBatteryBarBatteryLowColor;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.battery_bar);
|
||||
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
int intColor;
|
||||
String hexColor;
|
||||
|
||||
mBatteryBarNoNavbar = (ListPreference) prefSet.findPreference(PREF_BATT_BAR_NO_NAVBAR);
|
||||
mBatteryBarNoNavbar.setValue((Settings.System.getInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR, 0)) + "");
|
||||
mBatteryBarNoNavbar.setSummary(mBatteryBarNoNavbar.getEntry());
|
||||
mBatteryBarNoNavbar.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryBarStyle = (ListPreference) prefSet.findPreference(PREF_BATT_BAR_STYLE);
|
||||
mBatteryBarStyle.setValue((Settings.System.getInt(resolver,
|
||||
Settings.System.STATUSBAR_BATTERY_BAR_STYLE, 0)) + "");
|
||||
mBatteryBarStyle.setSummary(mBatteryBarStyle.getEntry());
|
||||
mBatteryBarStyle.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryBarColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_COLOR);
|
||||
intColor = Settings.System.getInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_COLOR, Color.WHITE);
|
||||
hexColor = String.format("#%08x", (0xffffff & intColor));
|
||||
mBatteryBarColor.setNewPreviewColor(intColor);
|
||||
mBatteryBarColor.setSummary(hexColor);
|
||||
mBatteryBarColor.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryBarChargingColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_CHARGING_COLOR);
|
||||
intColor = Settings.System.getInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_CHARGING_COLOR, Color.WHITE);
|
||||
hexColor = String.format("#%08x", (0xffffff & intColor));
|
||||
mBatteryBarChargingColor.setNewPreviewColor(intColor);
|
||||
mBatteryBarChargingColor.setSummary(hexColor);
|
||||
mBatteryBarChargingColor.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryBarBatteryLowColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_BATTERY_LOW_COLOR);
|
||||
intColor = Settings.System.getInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_BATTERY_LOW_COLOR, Color.WHITE);
|
||||
hexColor = String.format("#%08x", (0xffffff & intColor));
|
||||
mBatteryBarBatteryLowColor.setNewPreviewColor(intColor);
|
||||
mBatteryBarBatteryLowColor.setSummary(hexColor);
|
||||
mBatteryBarBatteryLowColor.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryBarChargingAnimation = (SwitchPreference) prefSet.findPreference(PREF_BATT_ANIMATE);
|
||||
mBatteryBarChargingAnimation.setChecked(Settings.System.getInt(resolver,
|
||||
Settings.System.STATUSBAR_BATTERY_BAR_ANIMATE, 0) == 1);
|
||||
mBatteryBarChargingAnimation.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryBarThickness = (CustomSeekBarPreference) prefSet.findPreference(PREF_BATT_BAR_WIDTH);
|
||||
mBatteryBarThickness.setValue(Settings.System.getInt(resolver,
|
||||
Settings.System.STATUSBAR_BATTERY_BAR_THICKNESS, 1));
|
||||
mBatteryBarThickness.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryBarUseChargingColor = (SwitchPreference) findPreference(PREF_BATT_USE_CHARGING_COLOR);
|
||||
mBatteryBarBlendColor = (SwitchPreference) findPreference(PREF_BATT_BLEND_COLOR);
|
||||
mBatteryBarBlendColorReverse = (SwitchPreference) findPreference(PREF_BATT_BLEND_COLOR_REVERSE);
|
||||
|
||||
updateBatteryBarOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mBatteryBarColor) {
|
||||
String hex = ColorPickerPreference.convertToARGB(Integer
|
||||
.parseInt(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.STATUSBAR_BATTERY_BAR_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mBatteryBarChargingColor) {
|
||||
String hex = ColorPickerPreference.convertToARGB(Integer
|
||||
.parseInt(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.STATUSBAR_BATTERY_BAR_CHARGING_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mBatteryBarBatteryLowColor) {
|
||||
String hex = ColorPickerPreference.convertToARGB(Integer
|
||||
.parseInt(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.STATUSBAR_BATTERY_BAR_BATTERY_LOW_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mBatteryBarNoNavbar) {
|
||||
int val = Integer.parseInt((String) newValue);
|
||||
int index = mBatteryBarNoNavbar.findIndexOfValue((String) newValue);
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.STATUSBAR_BATTERY_BAR, val);
|
||||
mBatteryBarNoNavbar.setSummary(mBatteryBarNoNavbar.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.STATUSBAR_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.STATUSBAR_BATTERY_BAR_THICKNESS, val);
|
||||
return true;
|
||||
} else if (preference == mBatteryBarChargingAnimation) {
|
||||
int val = ((Boolean) newValue) ? 1 : 0;
|
||||
Settings.System.putInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_ANIMATE, val);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateBatteryBarOptions() {
|
||||
if (Settings.System.getInt(getActivity().getContentResolver(),
|
||||
Settings.System.STATUSBAR_BATTERY_BAR, 0) == 0) {
|
||||
mBatteryBarStyle.setEnabled(false);
|
||||
mBatteryBarThickness.setEnabled(false);
|
||||
mBatteryBarChargingAnimation.setEnabled(false);
|
||||
mBatteryBarColor.setEnabled(false);
|
||||
mBatteryBarChargingColor.setEnabled(false);
|
||||
mBatteryBarBatteryLowColor.setEnabled(false);
|
||||
mBatteryBarUseChargingColor.setEnabled(false);
|
||||
mBatteryBarBlendColor.setEnabled(false);
|
||||
mBatteryBarBlendColorReverse.setEnabled(false);
|
||||
} else {
|
||||
mBatteryBarStyle.setEnabled(true);
|
||||
mBatteryBarThickness.setEnabled(true);
|
||||
mBatteryBarChargingAnimation.setEnabled(true);
|
||||
mBatteryBarColor.setEnabled(true);
|
||||
mBatteryBarChargingColor.setEnabled(true);
|
||||
mBatteryBarBatteryLowColor.setEnabled(true);
|
||||
mBatteryBarUseChargingColor.setEnabled(true);
|
||||
mBatteryBarBlendColor.setEnabled(true);
|
||||
mBatteryBarBlendColorReverse.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.battery_bar;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The ABC rom
|
||||
*
|
||||
* 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.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
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
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.battery_light_settings;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -52,47 +52,6 @@ import java.util.List;
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class ButtonSettings extends ActionFragment implements OnPreferenceChangeListener {
|
||||
|
||||
//Keys
|
||||
private static final String KEY_BUTTON_BRIGHTNESS = "button_brightness";
|
||||
private static final String KEY_BUTTON_BRIGHTNESS_SW = "button_brightness_sw";
|
||||
private static final String KEY_BACKLIGHT_TIMEOUT = "backlight_timeout";
|
||||
private static final String HWKEY_DISABLE = "hardware_keys_disable";
|
||||
private static final String PIXEL_ANIMATION_NAVIGATION = "pixel_nav_animation";
|
||||
|
||||
private static final String KEY_NAVIGATION_BAR_ARROWS = "navigation_bar_menu_arrow_keys";
|
||||
private static final String INVERT_NAVIGATION = "sysui_nav_bar_inverse";
|
||||
private static final String NAVBAR_VISIBILITY = "navigation_bar_show_new";
|
||||
|
||||
// category keys
|
||||
private static final String CATEGORY_HWKEY = "hardware_keys";
|
||||
private static final String CATEGORY_HOME = "home_key";
|
||||
private static final String CATEGORY_MENU = "menu_key";
|
||||
private static final String CATEGORY_BACK = "back_key";
|
||||
private static final String CATEGORY_ASSIST = "assist_key";
|
||||
private static final String CATEGORY_APPSWITCH = "app_switch_key";
|
||||
|
||||
// Masks for checking presence of hardware keys.
|
||||
// Must match values in frameworks/base/core/res/res/values/config.xml
|
||||
// Masks for checking presence of hardware keys.
|
||||
// Must match values in frameworks/base/core/res/res/values/config.xml
|
||||
public static final int KEY_MASK_HOME = 0x01;
|
||||
public static final int KEY_MASK_BACK = 0x02;
|
||||
public static final int KEY_MASK_MENU = 0x04;
|
||||
public static final int KEY_MASK_ASSIST = 0x08;
|
||||
public static final int KEY_MASK_APP_SWITCH = 0x10;
|
||||
public static final int KEY_MASK_CAMERA = 0x20;
|
||||
public static final int KEY_MASK_VOLUME = 0x40;
|
||||
|
||||
private ListPreference mBacklightTimeout;
|
||||
private CustomSeekBarPreference mButtonBrightness;
|
||||
private SwitchPreference mButtonBrightness_sw;
|
||||
private SwitchPreference mHwKeyDisable;
|
||||
private SystemSettingSwitchPreference mPixelAnimationNavigation;
|
||||
private SecureSettingSwitchPreference mInvertNavigation;
|
||||
private SwitchPreference mNavbarVisibility;
|
||||
private boolean mIsNavSwitchingMode = false;
|
||||
private Handler mHandler;
|
||||
private SystemSettingSwitchPreference mNavigationArrowKeys;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -102,200 +61,12 @@ public class ButtonSettings extends ActionFragment implements OnPreferenceChange
|
||||
final Resources res = getResources();
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
|
||||
mNavbarVisibility = (SwitchPreference) findPreference(NAVBAR_VISIBILITY);
|
||||
mNavigationArrowKeys = (SystemSettingSwitchPreference) findPreference(KEY_NAVIGATION_BAR_ARROWS);
|
||||
|
||||
boolean showing = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.FORCE_SHOW_NAVBAR,
|
||||
ActionUtils.hasNavbarByDefault(getActivity()) ? 1 : 0) != 0;
|
||||
updateBarVisibleAndUpdatePrefs(showing);
|
||||
mNavbarVisibility.setOnPreferenceChangeListener(this);
|
||||
|
||||
mHandler = new Handler();
|
||||
|
||||
mPixelAnimationNavigation = findPreference(PIXEL_ANIMATION_NAVIGATION);
|
||||
mInvertNavigation = findPreference(INVERT_NAVIGATION);
|
||||
// On three button nav
|
||||
if (com.android.internal.util.cherish.CherishUtils.isThemeEnabled("com.android.internal.systemui.navbar.threebutton")) {
|
||||
mPixelAnimationNavigation.setSummary(getString(R.string.pixel_navbar_anim_summary));
|
||||
mInvertNavigation.setSummary(getString(R.string.navigation_bar_invert_layout_summary));
|
||||
// On two button nav
|
||||
} else if (com.android.internal.util.cherish.CherishUtils.isThemeEnabled("com.android.internal.systemui.navbar.twobutton")) {
|
||||
mPixelAnimationNavigation.setSummary(getString(R.string.pixel_navbar_anim_summary));
|
||||
mInvertNavigation.setSummary(getString(R.string.navigation_bar_invert_layout_summary));
|
||||
// On gesture nav
|
||||
} else {
|
||||
mPixelAnimationNavigation.setSummary(getString(R.string.unsupported_gestures));
|
||||
mInvertNavigation.setSummary(getString(R.string.unsupported_gestures));
|
||||
mPixelAnimationNavigation.setEnabled(false);
|
||||
mInvertNavigation.setEnabled(false);
|
||||
}
|
||||
|
||||
final boolean needsNavbar = ActionUtils.hasNavbarByDefault(getActivity());
|
||||
final PreferenceCategory hwkeyCat = (PreferenceCategory) prefScreen
|
||||
.findPreference(CATEGORY_HWKEY);
|
||||
int keysDisabled = 0;
|
||||
if (!needsNavbar) {
|
||||
mHwKeyDisable = (SwitchPreference) findPreference(HWKEY_DISABLE);
|
||||
keysDisabled = Settings.Secure.getIntForUser(getContentResolver(),
|
||||
Settings.Secure.HARDWARE_KEYS_DISABLE, 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
mHwKeyDisable.setChecked(keysDisabled != 0);
|
||||
mHwKeyDisable.setOnPreferenceChangeListener(this);
|
||||
|
||||
final boolean variableBrightness = getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_deviceHasVariableButtonBrightness);
|
||||
|
||||
mBacklightTimeout =
|
||||
(ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT);
|
||||
|
||||
mButtonBrightness =
|
||||
(CustomSeekBarPreference) findPreference(KEY_BUTTON_BRIGHTNESS);
|
||||
|
||||
mButtonBrightness_sw =
|
||||
(SwitchPreference) findPreference(KEY_BUTTON_BRIGHTNESS_SW);
|
||||
|
||||
if (mBacklightTimeout != null) {
|
||||
mBacklightTimeout.setOnPreferenceChangeListener(this);
|
||||
int BacklightTimeout = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.BUTTON_BACKLIGHT_TIMEOUT, 5000);
|
||||
mBacklightTimeout.setValue(Integer.toString(BacklightTimeout));
|
||||
mBacklightTimeout.setSummary(mBacklightTimeout.getEntry());
|
||||
}
|
||||
|
||||
if (variableBrightness) {
|
||||
hwkeyCat.removePreference(mButtonBrightness_sw);
|
||||
if (mButtonBrightness != null) {
|
||||
float ButtonBrightness = Settings.System.getFloat(getContentResolver(),
|
||||
Settings.System.BUTTON_BRIGHTNESS, 1.0f);
|
||||
mButtonBrightness.setValue((int)(ButtonBrightness * 100.0f));
|
||||
mButtonBrightness.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
} else {
|
||||
hwkeyCat.removePreference(mButtonBrightness);
|
||||
if (mButtonBrightness_sw != null) {
|
||||
mButtonBrightness_sw.setChecked((Settings.System.getFloat(getContentResolver(),
|
||||
Settings.System.BUTTON_BRIGHTNESS, 1.0f) == 1));
|
||||
mButtonBrightness_sw.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
prefScreen.removePreference(hwkeyCat);
|
||||
}
|
||||
|
||||
// bits for hardware keys present on device
|
||||
final int deviceKeys = getResources().getInteger(
|
||||
com.android.internal.R.integer.config_deviceHardwareKeys);
|
||||
|
||||
// read bits for present hardware keys
|
||||
final boolean hasHomeKey = (deviceKeys & KEY_MASK_HOME) != 0;
|
||||
final boolean hasBackKey = (deviceKeys & KEY_MASK_BACK) != 0;
|
||||
final boolean hasMenuKey = (deviceKeys & KEY_MASK_MENU) != 0;
|
||||
final boolean hasAssistKey = (deviceKeys & KEY_MASK_ASSIST) != 0;
|
||||
final boolean hasAppSwitchKey = (deviceKeys & KEY_MASK_APP_SWITCH) != 0;
|
||||
|
||||
// load categories and init/remove preferences based on device
|
||||
// configuration
|
||||
final PreferenceCategory backCategory =
|
||||
(PreferenceCategory) prefScreen.findPreference(CATEGORY_BACK);
|
||||
final PreferenceCategory homeCategory =
|
||||
(PreferenceCategory) prefScreen.findPreference(CATEGORY_HOME);
|
||||
final PreferenceCategory menuCategory =
|
||||
(PreferenceCategory) prefScreen.findPreference(CATEGORY_MENU);
|
||||
final PreferenceCategory assistCategory =
|
||||
(PreferenceCategory) prefScreen.findPreference(CATEGORY_ASSIST);
|
||||
final PreferenceCategory appSwitchCategory =
|
||||
(PreferenceCategory) prefScreen.findPreference(CATEGORY_APPSWITCH);
|
||||
|
||||
// back key
|
||||
if (!hasBackKey) {
|
||||
prefScreen.removePreference(backCategory);
|
||||
}
|
||||
|
||||
// home key
|
||||
if (!hasHomeKey) {
|
||||
prefScreen.removePreference(homeCategory);
|
||||
}
|
||||
|
||||
// App switch key (recents)
|
||||
if (!hasAppSwitchKey) {
|
||||
prefScreen.removePreference(appSwitchCategory);
|
||||
}
|
||||
|
||||
// menu key
|
||||
if (!hasMenuKey) {
|
||||
prefScreen.removePreference(menuCategory);
|
||||
}
|
||||
|
||||
// search/assist key
|
||||
if (!hasAssistKey) {
|
||||
prefScreen.removePreference(assistCategory);
|
||||
}
|
||||
|
||||
// let super know we can load ActionPreferences
|
||||
onPreferenceScreenLoaded(ActionConstants.getDefaults(ActionConstants.HWKEYS));
|
||||
|
||||
// load preferences first
|
||||
setActionPreferencesEnabled(keysDisabled == 0);
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mBacklightTimeout) {
|
||||
String BacklightTimeout = (String) newValue;
|
||||
int BacklightTimeoutValue = Integer.parseInt(BacklightTimeout);
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.BUTTON_BACKLIGHT_TIMEOUT, BacklightTimeoutValue);
|
||||
int BacklightTimeoutIndex = mBacklightTimeout
|
||||
.findIndexOfValue(BacklightTimeout);
|
||||
mBacklightTimeout
|
||||
.setSummary(mBacklightTimeout.getEntries()[BacklightTimeoutIndex]);
|
||||
return true;
|
||||
} else if (preference == mButtonBrightness) {
|
||||
float value = (Integer) newValue;
|
||||
Settings.System.putFloat(getActivity().getContentResolver(),
|
||||
Settings.System.BUTTON_BRIGHTNESS, value / 100.0f);
|
||||
return true;
|
||||
} else if (preference == mButtonBrightness_sw) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.System.putFloat(getActivity().getContentResolver(),
|
||||
Settings.System.BUTTON_BRIGHTNESS, value ? 1.0f : -1.0f);
|
||||
return true;
|
||||
} else if (preference == mHwKeyDisable) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.Secure.putInt(getContentResolver(), Settings.Secure.HARDWARE_KEYS_DISABLE,
|
||||
value ? 1 : 0);
|
||||
setActionPreferencesEnabled(!value);
|
||||
return true;
|
||||
} else if (preference.equals(mNavbarVisibility)) {
|
||||
if (mIsNavSwitchingMode) {
|
||||
return false;
|
||||
}
|
||||
mIsNavSwitchingMode = true;
|
||||
boolean showing = ((Boolean)newValue);
|
||||
Settings.System.putInt(getContentResolver(), Settings.System.FORCE_SHOW_NAVBAR,
|
||||
showing ? 1 : 0);
|
||||
updateBarVisibleAndUpdatePrefs(showing);
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mIsNavSwitchingMode = false;
|
||||
}
|
||||
}, 1500);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateBarVisibleAndUpdatePrefs(boolean showing) {
|
||||
mNavbarVisibility.setChecked(showing);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean usesExtendedActionsList() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
|
||||
@@ -1,387 +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.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.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class ClockSettings extends SettingsPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
|
||||
private static final String STATUS_BAR_CLOCK = "status_bar_clock";
|
||||
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_COLOR = "status_bar_clock_color";
|
||||
private static final String STATUS_BAR_CLOCK_SIZE = "status_bar_clock_size";
|
||||
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 static final String STATUS_BAR_CLOCK_DATE_POSITION = "statusbar_clock_date_position";
|
||||
private static final String QS_HEADER_CLOCK_SIZE = "qs_header_clock_size";
|
||||
|
||||
static final int DEFAULT_STATUS_CLOCK_COLOR = 0xffffffff;
|
||||
|
||||
private SystemSettingSwitchPreference mStatusBarClockShow;
|
||||
private SystemSettingSwitchPreference mStatusBarSecondsShow;
|
||||
private ListPreference mStatusBarClock;
|
||||
private ListPreference mStatusBarAmPm;
|
||||
private ListPreference mClockDateDisplay;
|
||||
private ListPreference mClockDateStyle;
|
||||
private ListPreference mClockDateFormat;
|
||||
private ColorPickerPreference mClockColor;
|
||||
private CustomSeekBarPreference mClockSize;
|
||||
private ListPreference mClockDatePosition;
|
||||
private CustomSeekBarPreference mQsClockSize;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.clock_settings);
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
int intColor;
|
||||
String hexColor;
|
||||
|
||||
// clock settings
|
||||
mStatusBarClockShow = (SystemSettingSwitchPreference) findPreference(STATUS_BAR_CLOCK);
|
||||
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);
|
||||
|
||||
mQsClockSize = (CustomSeekBarPreference) findPreference(QS_HEADER_CLOCK_SIZE);
|
||||
int qsClockSize = Settings.System.getInt(resolver,
|
||||
Settings.System.QS_HEADER_CLOCK_SIZE, 14);
|
||||
mQsClockSize.setValue(qsClockSize / 1);
|
||||
mQsClockSize.setOnPreferenceChangeListener(this);
|
||||
|
||||
mStatusBarClockShow.setChecked((Settings.System.getInt(resolver,
|
||||
Settings.System.STATUS_BAR_CLOCK, 1) == 1));
|
||||
mStatusBarClockShow.setOnPreferenceChangeListener(this);
|
||||
|
||||
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);
|
||||
|
||||
mClockColor = (ColorPickerPreference) findPreference(STATUS_BAR_CLOCK_COLOR);
|
||||
mClockColor.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(resolver,
|
||||
Settings.System.STATUS_BAR_CLOCK_COLOR, DEFAULT_STATUS_CLOCK_COLOR);
|
||||
hexColor = String.format("#%08x", (0xffffffff & intColor));
|
||||
mClockColor.setSummary(hexColor);
|
||||
mClockColor.setNewPreviewColor(intColor);
|
||||
|
||||
mClockSize = (CustomSeekBarPreference) findPreference(STATUS_BAR_CLOCK_SIZE);
|
||||
int clockSize = Settings.System.getInt(resolver,
|
||||
Settings.System.STATUS_BAR_CLOCK_SIZE, 14);
|
||||
mClockSize.setValue(clockSize / 1);
|
||||
mClockSize.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();
|
||||
|
||||
mClockDatePosition.setValue(Integer.toString(Settings.System.getInt(getActivity()
|
||||
.getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_POSITION,
|
||||
0)));
|
||||
mClockDatePosition.setSummary(mClockDatePosition.getEntry());
|
||||
mClockDatePosition.setOnPreferenceChangeListener(this);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
AlertDialog dialog;
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
if (preference == mStatusBarClockShow) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.STATUS_BAR_CLOCK, value ? 1 : 0);
|
||||
return true;
|
||||
} else 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 == mClockColor) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.STATUS_BAR_CLOCK_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mClockSize) {
|
||||
int width = ((Integer)newValue).intValue();
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.STATUS_BAR_CLOCK_SIZE, width);
|
||||
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]);
|
||||
if (clockDateDisplay == 0) {
|
||||
mClockDateStyle.setEnabled(false);
|
||||
mClockDateFormat.setEnabled(false);
|
||||
mClockDatePosition.setEnabled(false);
|
||||
} else {
|
||||
mClockDateStyle.setEnabled(true);
|
||||
mClockDateFormat.setEnabled(true);
|
||||
mClockDatePosition.setEnabled(true);
|
||||
}
|
||||
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 == mQsClockSize) {
|
||||
int width = ((Integer)newValue).intValue();
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.QS_HEADER_CLOCK_SIZE, width);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.clock_settings;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,188 +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.Context;
|
||||
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.Spannable;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.EditText;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.ListPreference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
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 STATUS_BAR_CARRIER_COLOR = "status_bar_carrier_color";
|
||||
private static final String STATUS_BAR_CARRIER_FONT_SIZE = "status_bar_carrier_font_size";
|
||||
|
||||
static final int DEFAULT_STATUS_CARRIER_COLOR = 0xffffffff;
|
||||
|
||||
private PreferenceScreen mCustomCarrierLabel;
|
||||
private String mCustomCarrierLabelText;
|
||||
private ColorPickerPreference mCarrierColorPicker;
|
||||
private CustomSeekBarPreference mStatusBarCarrierSize;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.custom_carrier_label);
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
int intColor;
|
||||
String hexColor;
|
||||
|
||||
// custom carrier label
|
||||
mCustomCarrierLabel = (PreferenceScreen) findPreference(CUSTOM_CARRIER_LABEL);
|
||||
updateCustomLabelTextSummary();
|
||||
|
||||
mCarrierColorPicker = (ColorPickerPreference) findPreference(STATUS_BAR_CARRIER_COLOR);
|
||||
mCarrierColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(resolver,
|
||||
Settings.System.STATUS_BAR_CARRIER_COLOR, DEFAULT_STATUS_CARRIER_COLOR);
|
||||
hexColor = String.format("#%08x", (0xffffffff & intColor));
|
||||
mCarrierColorPicker.setSummary(hexColor);
|
||||
mCarrierColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
mStatusBarCarrierSize = (CustomSeekBarPreference) findPreference(STATUS_BAR_CARRIER_FONT_SIZE);
|
||||
int StatusBarCarrierSize = Settings.System.getInt(resolver,
|
||||
Settings.System.STATUS_BAR_CARRIER_FONT_SIZE, 14);
|
||||
mStatusBarCarrierSize.setValue(StatusBarCarrierSize / 1);
|
||||
mStatusBarCarrierSize.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
if (preference == mCarrierColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.STATUS_BAR_CARRIER_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mStatusBarCarrierSize) {
|
||||
int width = ((Integer)newValue).intValue();
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.STATUS_BAR_CARRIER_FONT_SIZE, width);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
boolean value;
|
||||
if (preference.getKey().equals(CUSTOM_CARRIER_LABEL)) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
||||
alert.setTitle(R.string.custom_carrier_label_title);
|
||||
alert.setMessage(R.string.custom_carrier_label_explain);
|
||||
// Set an EditText view to get user input
|
||||
final EditText input = new EditText(getActivity());
|
||||
input.setText(TextUtils.isEmpty(mCustomCarrierLabelText) ? "" : mCustomCarrierLabelText);
|
||||
input.setSelection(input.getText().length());
|
||||
alert.setView(input);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.custom_carrier_label;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The exTHmUI Open Source 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 com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import com.android.internal.util.hwkeys.ActionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.cherish.settings.preferences.PackageListPreference;
|
||||
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
|
||||
public class GamingModeSettings extends SettingsPreferenceFragment {
|
||||
|
||||
private static final String GAMING_MODE_DISABLE_HW_KEYS = "gaming_mode_disable_hw_keys";
|
||||
private static final String GAMING_MODE_DISABLE_GESTURE = "gaming_mode_disable_gesture";
|
||||
|
||||
private PackageListPreference mGamingPrefList;
|
||||
|
||||
private SystemSettingSwitchPreference mHardwareKeysDisable;
|
||||
private SystemSettingSwitchPreference mGestureDisable;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings_gaming);
|
||||
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
final boolean hasNavbar = ActionUtils.hasNavbarByDefault(getActivity());
|
||||
|
||||
mGamingPrefList = (PackageListPreference) findPreference("gaming_mode_app_list");
|
||||
mGamingPrefList.setRemovedListKey(Settings.System.GAMING_MODE_REMOVED_APP_LIST);
|
||||
|
||||
mHardwareKeysDisable = (SystemSettingSwitchPreference) findPreference(GAMING_MODE_DISABLE_HW_KEYS);
|
||||
mGestureDisable = (SystemSettingSwitchPreference) findPreference(GAMING_MODE_DISABLE_GESTURE);
|
||||
|
||||
if (hasNavbar) {
|
||||
prefScreen.removePreference(mHardwareKeysDisable);
|
||||
} else {
|
||||
prefScreen.removePreference(mGestureDisable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
}
|
||||
@@ -22,39 +22,14 @@ import java.util.List;
|
||||
public class GestureSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String KEY_TORCH_LONG_PRESS_POWER_TIMEOUT =
|
||||
"torch_long_press_power_timeout";
|
||||
|
||||
private ListPreference mTorchLongPressPowerTimeout;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings_gestures);
|
||||
|
||||
mTorchLongPressPowerTimeout =
|
||||
(ListPreference) findPreference(KEY_TORCH_LONG_PRESS_POWER_TIMEOUT);
|
||||
|
||||
mTorchLongPressPowerTimeout.setOnPreferenceChangeListener(this);
|
||||
int TorchTimeout = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.TORCH_LONG_PRESS_POWER_TIMEOUT, 0);
|
||||
mTorchLongPressPowerTimeout.setValue(Integer.toString(TorchTimeout));
|
||||
mTorchLongPressPowerTimeout.setSummary(mTorchLongPressPowerTimeout.getEntry());
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (preference == mTorchLongPressPowerTimeout) {
|
||||
String TorchTimeout = (String) newValue;
|
||||
int TorchTimeoutValue = Integer.parseInt(TorchTimeout);
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.TORCH_LONG_PRESS_POWER_TIMEOUT, TorchTimeoutValue);
|
||||
int TorchTimeoutIndex = mTorchLongPressPowerTimeout
|
||||
.findIndexOfValue(TorchTimeout);
|
||||
mTorchLongPressPowerTimeout
|
||||
.setSummary(mTorchLongPressPowerTimeout.getEntries()[TorchTimeoutIndex]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class HAFRAppChooserAdapter extends BaseAdapter implements Filterable {
|
||||
|
||||
final Context mContext;
|
||||
final Handler mHandler;
|
||||
final PackageManager mPackageManager;
|
||||
final LayoutInflater mLayoutInflater;
|
||||
|
||||
protected List<PackageInfo> mInstalledAppInfo;
|
||||
protected List<AppItem> mInstalledApps = new LinkedList<AppItem>();
|
||||
protected List<PackageInfo> mTemporarylist;
|
||||
|
||||
boolean isUpdating;
|
||||
boolean hasLauncherFilter = false;
|
||||
|
||||
public HAFRAppChooserAdapter(Context context) {
|
||||
mContext = context;
|
||||
mHandler = new Handler();
|
||||
mPackageManager = mContext.getPackageManager();
|
||||
mLayoutInflater = (LayoutInflater) mContext
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mInstalledAppInfo = mPackageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
|
||||
mTemporarylist = mInstalledAppInfo;
|
||||
}
|
||||
|
||||
public synchronized void update() {
|
||||
onStartUpdate();
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
isUpdating = true;
|
||||
final List<AppItem> temp = new LinkedList<AppItem>();
|
||||
for (PackageInfo info : mTemporarylist) {
|
||||
final AppItem item = new AppItem();
|
||||
item.title = info.applicationInfo.loadLabel(mPackageManager);
|
||||
item.icon = info.applicationInfo.loadIcon(mPackageManager);
|
||||
item.packageName = info.packageName;
|
||||
final int index = Collections.binarySearch(temp, item);
|
||||
final boolean isLauncherApp =
|
||||
mPackageManager.getLaunchIntentForPackage(info.packageName) != null;
|
||||
if (!hasLauncherFilter || isLauncherApp) {
|
||||
if (index < 0) {
|
||||
temp.add((-index - 1), item);
|
||||
} else {
|
||||
temp.add((index + 1), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mInstalledApps = temp;
|
||||
notifyDataSetChanged();
|
||||
isUpdating = false;
|
||||
onFinishUpdate();
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public abstract void onStartUpdate();
|
||||
|
||||
public abstract void onFinishUpdate();
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mInstalledApps.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppItem getItem(int position) {
|
||||
if (position >= mInstalledApps.size()) {
|
||||
return mInstalledApps.get(mInstalledApps.size());
|
||||
} else if (position < 0) {
|
||||
return mInstalledApps.get(0);
|
||||
}
|
||||
|
||||
return mInstalledApps.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
if (position < 0 || position >= mInstalledApps.size()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return getItem(position).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
if (convertView != null) {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
} else {
|
||||
convertView = mLayoutInflater.inflate(R.layout.view_app_list, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.name = (TextView) convertView.findViewById(android.R.id.title);
|
||||
holder.icon = (ImageView) convertView.findViewById(android.R.id.icon);
|
||||
holder.pkg = (TextView) convertView.findViewById(android.R.id.message);
|
||||
convertView.setTag(holder);
|
||||
}
|
||||
AppItem appInfo = getItem(position);
|
||||
|
||||
holder.name.setText(appInfo.title);
|
||||
holder.pkg.setText(appInfo.packageName);
|
||||
holder.icon.setImageDrawable(appInfo.icon);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return new Filter() {
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
if (TextUtils.isEmpty(constraint)) {
|
||||
// No filter implemented we return all the list
|
||||
mTemporarylist = mInstalledAppInfo;
|
||||
return new FilterResults();
|
||||
}
|
||||
|
||||
ArrayList<PackageInfo> FilteredList = new ArrayList<PackageInfo>();
|
||||
for (PackageInfo data : mInstalledAppInfo) {
|
||||
final String filterText = constraint.toString().toLowerCase(Locale.ENGLISH);
|
||||
try {
|
||||
if (data.applicationInfo.loadLabel(mPackageManager).toString()
|
||||
.toLowerCase(Locale.ENGLISH).contains(filterText)) {
|
||||
FilteredList.add(data);
|
||||
} else if (data.packageName.contains(filterText)) {
|
||||
FilteredList.add(data);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
mTemporarylist = FilteredList;
|
||||
return new FilterResults();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public class AppItem implements Comparable<AppItem> {
|
||||
public CharSequence title;
|
||||
public String packageName;
|
||||
public Drawable icon;
|
||||
|
||||
@Override
|
||||
public int compareTo(AppItem another) {
|
||||
return this.title.toString().compareTo(another.title.toString());
|
||||
}
|
||||
}
|
||||
|
||||
static class ViewHolder {
|
||||
TextView name;
|
||||
ImageView icon;
|
||||
TextView pkg;
|
||||
}
|
||||
|
||||
protected void setLauncherFilter(boolean enabled) {
|
||||
hasLauncherFilter = enabled;
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Filter;
|
||||
import android.widget.ImageButton;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public abstract class HAFRAppChooserDialog extends Dialog {
|
||||
|
||||
final HAFRAppChooserAdapter dAdapter;
|
||||
final ProgressBar dProgressBar;
|
||||
final ListView dListView;
|
||||
final EditText dSearch;
|
||||
final ImageButton dButton;
|
||||
|
||||
private int mId;
|
||||
|
||||
public HAFRAppChooserDialog(Context context) {
|
||||
super(context);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.dialog_app_chooser_list);
|
||||
|
||||
dListView = (ListView) findViewById(R.id.listView1);
|
||||
dSearch = (EditText) findViewById(R.id.searchText);
|
||||
dButton = (ImageButton) findViewById(R.id.searchButton);
|
||||
dProgressBar = (ProgressBar) findViewById(R.id.progressBar1);
|
||||
|
||||
dAdapter = new HAFRAppChooserAdapter(context) {
|
||||
@Override
|
||||
public void onStartUpdate() {
|
||||
dProgressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishUpdate() {
|
||||
dProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
};
|
||||
|
||||
dListView.setAdapter(dAdapter);
|
||||
dListView.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
|
||||
HAFRAppChooserAdapter.AppItem info = (HAFRAppChooserAdapter.AppItem) av
|
||||
.getItemAtPosition(pos);
|
||||
onListViewItemClick(info, mId);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dAdapter.getFilter().filter(dSearch.getText().toString(), new Filter.FilterListener() {
|
||||
public void onFilterComplete(int count) {
|
||||
dAdapter.update();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
dSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
dAdapter.getFilter().filter(dSearch.getText().toString(), new Filter.FilterListener() {
|
||||
public void onFilterComplete(int count) {
|
||||
dAdapter.update();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
dAdapter.update();
|
||||
}
|
||||
|
||||
public void show(int id) {
|
||||
mId = id;
|
||||
show();
|
||||
}
|
||||
|
||||
public void setLauncherFilter(boolean enabled) {
|
||||
dAdapter.setLauncherFilter(enabled);
|
||||
}
|
||||
|
||||
public abstract void onListViewItemClick(HAFRAppChooserAdapter.AppItem info, int id);
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.cherish.settings.fragments.HAFRAppChooserAdapter.AppItem;
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HAFRAppListActivity extends Activity {
|
||||
|
||||
/* others */
|
||||
static final int ID_ADD_APP = 1;
|
||||
|
||||
/* main stuff */
|
||||
SharedPreferences mPref;
|
||||
HAFRAppListAdapter mPkgAdapter;
|
||||
ListView mListView;
|
||||
|
||||
/* app dialog stuff */
|
||||
HAFRAppChooserDialog dDialog;
|
||||
ArrayList<String> excludeFromRecentsList;
|
||||
public static final String KEY_PREFERENCE_APPS = "hide_recents_apps_pref";
|
||||
|
||||
@Override
|
||||
@SuppressLint("WorldReadableFiles")
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setTitle(getResources().getText(R.string.hide_apps_from_recents_title));
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
mPref = getSharedPreferences(KEY_PREFERENCE_APPS, MODE_PRIVATE);
|
||||
loadList();
|
||||
initAppList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
// Avoid WindowLeaked Exception
|
||||
// http://publicstaticdroidmain.com/2012/01/avoiding-android-memory-leaks-part-1/
|
||||
if (dDialog != null && dDialog.isShowing()) {
|
||||
dDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuItem add = menu.add(Menu.NONE, ID_ADD_APP, 0, R.string.hide_from_recents_add_app);
|
||||
add.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case ID_ADD_APP:
|
||||
dDialog.show(ID_ADD_APP);
|
||||
break;
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void initAppList() {
|
||||
dDialog = new HAFRAppChooserDialog(this) {
|
||||
@Override
|
||||
public void onListViewItemClick(AppItem info, int id) {
|
||||
addApp(info.packageName);
|
||||
}
|
||||
};
|
||||
dDialog.setLauncherFilter(true);
|
||||
}
|
||||
|
||||
private void loadList() {
|
||||
final Map<String, Integer> list = getSetStrings();
|
||||
mPkgAdapter = new HAFRAppListAdapter(this, list) {
|
||||
@Override
|
||||
public void onRemoveButtonPress(PackageItem app_info) {
|
||||
removeApp(app_info.packageName);
|
||||
}
|
||||
};
|
||||
mListView = new ListView(this);
|
||||
mListView.setAdapter(mPkgAdapter);
|
||||
setContentView(mListView);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Integer> getSetStrings() {
|
||||
return (Map<String, Integer>) mPref.getAll();
|
||||
}
|
||||
|
||||
public void removeApp(String pkg) {
|
||||
|
||||
Editor editor = mPref.edit().clear();
|
||||
excludeFromRecentsList = new ArrayList<String>();
|
||||
List<ArrayList<String>> tempItemList2 = new ArrayList<ArrayList<String>>();
|
||||
List<String> tempItemList3 = new ArrayList<String>();
|
||||
|
||||
for (HAFRAppListAdapter.PackageItem item : mPkgAdapter.getList()) {
|
||||
if (!item.packageName.equals(pkg)) {
|
||||
excludeFromRecentsList.add(item.packageName);
|
||||
}
|
||||
}
|
||||
|
||||
PackageManager packageManager = getApplicationContext().getPackageManager();
|
||||
|
||||
for (int i = 0; i < excludeFromRecentsList.size(); i++) {
|
||||
try {
|
||||
tempItemList2.add(new ArrayList<String>(Arrays.asList((String) packageManager.getApplicationLabel(packageManager.getApplicationInfo(excludeFromRecentsList.get(i), PackageManager.GET_META_DATA)), excludeFromRecentsList.get(i))));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Collections.sort(tempItemList2, new Comparator<ArrayList<String>>() {
|
||||
@Override
|
||||
public int compare(ArrayList<String> o1, ArrayList<String> o2) {
|
||||
return o1.get(0).toLowerCase().compareTo(o2.get(0).toLowerCase());
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < excludeFromRecentsList.size(); i++) {
|
||||
tempItemList3.add(tempItemList2.get(i).get(1));
|
||||
}
|
||||
|
||||
|
||||
for (HAFRAppListAdapter.PackageItem item : mPkgAdapter.getList()) {
|
||||
editor.putInt(item.packageName, tempItemList3.indexOf(item.packageName));
|
||||
}
|
||||
editor.commit();
|
||||
saveExcludeFromRecentsString();
|
||||
updateList();
|
||||
}
|
||||
|
||||
public void addApp(String pkg) {
|
||||
Editor editor = mPref.edit().clear();
|
||||
excludeFromRecentsList = new ArrayList<String>();
|
||||
List<ArrayList<String>> tempItemList2 = new ArrayList<ArrayList<String>>();
|
||||
List<String> tempItemList3 = new ArrayList<String>();
|
||||
|
||||
for (HAFRAppListAdapter.PackageItem item : mPkgAdapter.getList()) {
|
||||
excludeFromRecentsList.add(item.packageName);
|
||||
}
|
||||
|
||||
excludeFromRecentsList.add(pkg);
|
||||
PackageManager packageManager = getApplicationContext().getPackageManager();
|
||||
|
||||
for (int i = 0; i < excludeFromRecentsList.size(); i++) {
|
||||
try {
|
||||
tempItemList2.add(new ArrayList<String>(Arrays.asList((String) packageManager.getApplicationLabel(packageManager.getApplicationInfo(excludeFromRecentsList.get(i), PackageManager.GET_META_DATA)), excludeFromRecentsList.get(i))));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Collections.sort(tempItemList2, new Comparator<ArrayList<String>>() {
|
||||
@Override
|
||||
public int compare(ArrayList<String> o1, ArrayList<String> o2) {
|
||||
return o1.get(0).toLowerCase().compareTo(o2.get(0).toLowerCase());
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < excludeFromRecentsList.size(); i++) {
|
||||
tempItemList3.add(tempItemList2.get(i).get(1));
|
||||
}
|
||||
|
||||
|
||||
for (HAFRAppListAdapter.PackageItem item : mPkgAdapter.getList()) {
|
||||
editor.putInt(item.packageName, tempItemList3.indexOf(item.packageName));
|
||||
}
|
||||
|
||||
editor.putInt(pkg, tempItemList3.indexOf(pkg));
|
||||
editor.commit();
|
||||
saveExcludeFromRecentsString();
|
||||
updateList();
|
||||
}
|
||||
|
||||
private void saveExcludeFromRecentsString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String name : excludeFromRecentsList) {
|
||||
sb.append(name + "|");
|
||||
}
|
||||
|
||||
if (sb.length() > 0) {
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
}
|
||||
|
||||
Log.d("Myself5", sb.toString());
|
||||
Settings.System.putString(getContentResolver(),
|
||||
Settings.System.HIDE_FROM_RECENTS_LIST, sb.toString());
|
||||
}
|
||||
|
||||
public void updateList() {
|
||||
mPkgAdapter.update(getSetStrings());
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class HAFRAppListAdapter extends BaseAdapter {
|
||||
|
||||
final Context mContext;
|
||||
final Handler mHandler;
|
||||
final PackageManager mPackageManager;
|
||||
final LayoutInflater mLayoutInflater;
|
||||
|
||||
protected LinkedList<PackageItem> mApps = new LinkedList<PackageItem>();
|
||||
|
||||
public HAFRAppListAdapter(Context context, Map<String, Integer> list) {
|
||||
mContext = context;
|
||||
mHandler = new Handler();
|
||||
mPackageManager = context.getPackageManager();
|
||||
mLayoutInflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
update(list);
|
||||
}
|
||||
|
||||
public void update(final Map<String, Integer> app_array) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (mApps) {
|
||||
final PackageItem[] array = new PackageItem[app_array.size() * 2];
|
||||
for (String pkg_name : app_array.keySet()) {
|
||||
try {
|
||||
ApplicationInfo ai = mPackageManager.getApplicationInfo(pkg_name, 0);
|
||||
final PackageItem item = new PackageItem();
|
||||
item.title = ai.loadLabel(mPackageManager);
|
||||
item.icon = ai.loadIcon(mPackageManager);
|
||||
item.packageName = ai.packageName;
|
||||
array[app_array.get(pkg_name)] = item;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
final LinkedList<PackageItem> temp = new LinkedList<PackageItem>();
|
||||
for (int x = 0; x < array.length; x++) {
|
||||
if (array[x] != null) {
|
||||
temp.add(array[x]);
|
||||
}
|
||||
}
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mApps.clear();
|
||||
mApps = temp;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mApps.size();
|
||||
}
|
||||
|
||||
public LinkedList<PackageItem> getList() {
|
||||
return mApps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageItem getItem(int position) {
|
||||
return mApps.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
if (position < 0 || position >= mApps.size()) {
|
||||
return -1;
|
||||
}
|
||||
return mApps.get(position).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStableIds() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
if (convertView != null) {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
} else {
|
||||
convertView = mLayoutInflater.inflate(R.layout.view_package_list, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.name = (TextView) convertView.findViewById(android.R.id.title);
|
||||
holder.icon = (ImageView) convertView.findViewById(android.R.id.icon);
|
||||
holder.pkg = (TextView) convertView.findViewById(android.R.id.message);
|
||||
holder.remove = (ImageButton) convertView.findViewById(R.id.removeButton);
|
||||
convertView.setTag(holder);
|
||||
}
|
||||
final PackageItem appInfo = getItem(position);
|
||||
|
||||
holder.name.setText(appInfo.title);
|
||||
holder.pkg.setText(appInfo.packageName);
|
||||
holder.icon.setImageDrawable(appInfo.icon);
|
||||
holder.remove.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onRemoveButtonPress(appInfo);
|
||||
}
|
||||
});
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public abstract void onRemoveButtonPress(PackageItem app_info);
|
||||
|
||||
public class PackageItem implements Comparable<PackageItem> {
|
||||
public CharSequence title;
|
||||
public String packageName;
|
||||
public Drawable icon;
|
||||
|
||||
@Override
|
||||
public int compareTo(PackageItem another) {
|
||||
return this.title.toString().compareTo(another.title.toString());
|
||||
}
|
||||
}
|
||||
|
||||
static class ViewHolder {
|
||||
TextView name;
|
||||
ImageView icon;
|
||||
TextView pkg;
|
||||
ImageButton remove;
|
||||
}
|
||||
}
|
||||
@@ -1,376 +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.Context;
|
||||
import android.content.DialogInterface;
|
||||
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 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 com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class HeadsUpSettings extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceClickListener {
|
||||
|
||||
private static final int DIALOG_STOPLIST_APPS = 0;
|
||||
private static final int DIALOG_BLACKLIST_APPS = 1;
|
||||
|
||||
private PackageListAdapter mPackageAdapter;
|
||||
private PackageManager mPackageManager;
|
||||
private PreferenceGroup mStoplistPrefList;
|
||||
private PreferenceGroup mBlacklistPrefList;
|
||||
private Preference mAddStoplistPref;
|
||||
private Preference mAddBlacklistPref;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.heads_up_settings;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,353 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Bundle;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MenuInflater;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class LockColors extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String TAG = "LockscreenColors";
|
||||
|
||||
private static final String LOCKSCREEN_PHONE_ICON_COLOR = "lockscreen_phone_icon_color";
|
||||
private static final String LOCKSCREEN_CAMERA_ICON_COLOR = "lockscreen_camera_icon_color";
|
||||
private static final String LOCKSCREEN_INDICATION_TEXT_COLOR = "lockscreen_indication_text_color";
|
||||
private static final String LOCKSCREEN_CLOCK_COLOR = "lockscreen_clock_color";
|
||||
private static final String LOCKSCREEN_CLOCK_DATE_COLOR = "lockscreen_clock_date_color";
|
||||
private static final String LOCKSCREEN_OWNER_INFO_COLOR = "lockscreen_owner_info_color";
|
||||
private static final String LOCKSCREEN_WEATHER_TEMP_COLOR = "lockscreen_weather_temp_color";
|
||||
private static final String LOCKSCREEN_WEATHER_CITY_COLOR = "lockscreen_weather_city_color";
|
||||
private static final String LOCKSCREEN_WEATHER_ICON_COLOR = "lockscreen_weather_icon_color";
|
||||
|
||||
static final int DEFAULT = 0xffffffff;
|
||||
static final int TRANSPARENT = 0x99FFFFFF;
|
||||
|
||||
private static final int MENU_RESET = Menu.FIRST;
|
||||
|
||||
private ColorPickerPreference mLockscreenPhoneColorPicker;
|
||||
private ColorPickerPreference mLockscreenCameraColorPicker;
|
||||
private ColorPickerPreference mLockscreenIndicationTextColorPicker;
|
||||
private ColorPickerPreference mLockscreenClockColorPicker;
|
||||
private ColorPickerPreference mLockscreenClockDateColorPicker;
|
||||
private ColorPickerPreference mLockscreenOwnerInfoColorPicker;
|
||||
private ColorPickerPreference mWeatherRightTextColorPicker;
|
||||
private ColorPickerPreference mWeatherLeftTextColorPicker;
|
||||
private ColorPickerPreference mWeatherIconColorPicker;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.lock_colors);
|
||||
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
int intColor;
|
||||
String hexColor;
|
||||
|
||||
mLockscreenPhoneColorPicker = (ColorPickerPreference) findPreference(LOCKSCREEN_PHONE_ICON_COLOR);
|
||||
mLockscreenPhoneColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_PHONE_ICON_COLOR, TRANSPARENT);
|
||||
hexColor = String.format("#%08x", (0x99FFFFFF & intColor));
|
||||
mLockscreenPhoneColorPicker.setSummary(hexColor);
|
||||
mLockscreenPhoneColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
mLockscreenCameraColorPicker = (ColorPickerPreference) findPreference(LOCKSCREEN_CAMERA_ICON_COLOR);
|
||||
mLockscreenCameraColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CAMERA_ICON_COLOR, TRANSPARENT);
|
||||
hexColor = String.format("#%08x", (0x99FFFFFF & intColor));
|
||||
mLockscreenCameraColorPicker.setSummary(hexColor);
|
||||
mLockscreenCameraColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
mLockscreenIndicationTextColorPicker = (ColorPickerPreference) findPreference(LOCKSCREEN_INDICATION_TEXT_COLOR);
|
||||
mLockscreenIndicationTextColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_INDICATION_TEXT_COLOR, DEFAULT);
|
||||
hexColor = String.format("#%08x", (0xffffffff & intColor));
|
||||
mLockscreenIndicationTextColorPicker.setSummary(hexColor);
|
||||
mLockscreenIndicationTextColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
mLockscreenClockColorPicker = (ColorPickerPreference) findPreference(LOCKSCREEN_CLOCK_COLOR);
|
||||
mLockscreenClockColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CLOCK_COLOR, DEFAULT);
|
||||
hexColor = String.format("#%08x", (0xffffffff & intColor));
|
||||
mLockscreenClockColorPicker.setSummary(hexColor);
|
||||
mLockscreenClockColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
mLockscreenClockDateColorPicker = (ColorPickerPreference) findPreference(LOCKSCREEN_CLOCK_DATE_COLOR);
|
||||
mLockscreenClockDateColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CLOCK_DATE_COLOR, DEFAULT);
|
||||
hexColor = String.format("#%08x", (0xffffffff & intColor));
|
||||
mLockscreenClockDateColorPicker.setSummary(hexColor);
|
||||
mLockscreenClockDateColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
mLockscreenOwnerInfoColorPicker = (ColorPickerPreference) findPreference(LOCKSCREEN_OWNER_INFO_COLOR);
|
||||
mLockscreenOwnerInfoColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(resolver,
|
||||
Settings.System.LOCKSCREEN_OWNER_INFO_COLOR, DEFAULT);
|
||||
hexColor = String.format("#%08x", (0xffffffff & intColor));
|
||||
mLockscreenOwnerInfoColorPicker.setSummary(hexColor);
|
||||
mLockscreenOwnerInfoColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
mWeatherRightTextColorPicker = (ColorPickerPreference) findPreference(LOCKSCREEN_WEATHER_TEMP_COLOR);
|
||||
mWeatherRightTextColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCK_SCREEN_WEATHER_TEMP_COLOR, DEFAULT);
|
||||
hexColor = String.format("#%08x", (0xffffffff & intColor));
|
||||
mWeatherRightTextColorPicker.setSummary(hexColor);
|
||||
mWeatherRightTextColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
mWeatherLeftTextColorPicker = (ColorPickerPreference) findPreference(LOCKSCREEN_WEATHER_CITY_COLOR);
|
||||
mWeatherLeftTextColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCK_SCREEN_WEATHER_CITY_COLOR, DEFAULT);
|
||||
hexColor = String.format("#%08x", (0xffffffff & intColor));
|
||||
mWeatherLeftTextColorPicker.setSummary(hexColor);
|
||||
mWeatherLeftTextColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
mWeatherIconColorPicker = (ColorPickerPreference) findPreference(LOCKSCREEN_WEATHER_ICON_COLOR);
|
||||
mWeatherIconColorPicker.setOnPreferenceChangeListener(this);
|
||||
intColor = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCK_SCREEN_WEATHER_ICON_COLOR, TRANSPARENT);
|
||||
hexColor = String.format("#%08x", (0x99FFFFFF & intColor));
|
||||
mWeatherIconColorPicker.setSummary(hexColor);
|
||||
mWeatherIconColorPicker.setNewPreviewColor(intColor);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mLockscreenCameraColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CAMERA_ICON_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mLockscreenPhoneColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_PHONE_ICON_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mLockscreenIndicationTextColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_INDICATION_TEXT_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mLockscreenClockColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CLOCK_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mLockscreenClockDateColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CLOCK_DATE_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mLockscreenOwnerInfoColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_OWNER_INFO_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mWeatherRightTextColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.LOCK_SCREEN_WEATHER_TEMP_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mWeatherLeftTextColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.LOCK_SCREEN_WEATHER_CITY_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mWeatherIconColorPicker) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.LOCK_SCREEN_WEATHER_ICON_COLOR, intHex);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.add(0, MENU_RESET, 0, R.string.reset)
|
||||
.setIcon(R.drawable.ic_action_reset_alpha)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_RESET:
|
||||
resetToDefault();
|
||||
return true;
|
||||
default:
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetToDefault() {
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
|
||||
alertDialog.setTitle(R.string.lockscreen_colors_reset_title);
|
||||
alertDialog.setMessage(R.string.lockscreen_colors_reset_message);
|
||||
alertDialog.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
resetValues();
|
||||
}
|
||||
});
|
||||
alertDialog.setNegativeButton(R.string.cancel, null);
|
||||
alertDialog.create().show();
|
||||
}
|
||||
|
||||
private void resetValues() {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_PHONE_ICON_COLOR, TRANSPARENT);
|
||||
mLockscreenPhoneColorPicker.setNewPreviewColor(TRANSPARENT);
|
||||
mLockscreenPhoneColorPicker.setSummary(R.string.default_string);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CAMERA_ICON_COLOR, TRANSPARENT);
|
||||
mLockscreenCameraColorPicker.setNewPreviewColor(TRANSPARENT);
|
||||
mLockscreenCameraColorPicker.setSummary(R.string.default_string);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_INDICATION_TEXT_COLOR, DEFAULT);
|
||||
mLockscreenIndicationTextColorPicker.setNewPreviewColor(DEFAULT);
|
||||
mLockscreenIndicationTextColorPicker.setSummary(R.string.default_string);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CLOCK_COLOR, DEFAULT);
|
||||
mLockscreenClockColorPicker.setNewPreviewColor(DEFAULT);
|
||||
mLockscreenClockColorPicker.setSummary(R.string.default_string);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CLOCK_DATE_COLOR, DEFAULT);
|
||||
mLockscreenClockDateColorPicker.setNewPreviewColor(DEFAULT);
|
||||
mLockscreenClockDateColorPicker.setSummary(R.string.default_string);
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.LOCKSCREEN_OWNER_INFO_COLOR, DEFAULT);
|
||||
mLockscreenOwnerInfoColorPicker.setNewPreviewColor(DEFAULT);
|
||||
mLockscreenOwnerInfoColorPicker.setSummary(R.string.default_string);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCK_SCREEN_WEATHER_TEMP_COLOR, DEFAULT);
|
||||
mWeatherRightTextColorPicker.setNewPreviewColor(DEFAULT);
|
||||
mWeatherRightTextColorPicker.setSummary(R.string.default_string);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCK_SCREEN_WEATHER_CITY_COLOR, DEFAULT);
|
||||
mWeatherLeftTextColorPicker.setNewPreviewColor(DEFAULT);
|
||||
mWeatherLeftTextColorPicker.setSummary(R.string.default_string);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCK_SCREEN_WEATHER_ICON_COLOR, DEFAULT);
|
||||
mWeatherIconColorPicker.setNewPreviewColor(DEFAULT);
|
||||
mWeatherIconColorPicker.setSummary(R.string.default_string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.lock_colors;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -41,7 +41,6 @@ import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.internal.util.cherish.FodUtils;
|
||||
import com.android.internal.util.cherish.CherishUtils;
|
||||
import com.cherish.settings.preferences.SystemSettingListPreference;
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
@@ -59,36 +58,6 @@ import java.util.List;
|
||||
public class LockScreenSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String CUSTOM_TEXT_CLOCK_FONTS = "custom_text_clock_fonts";
|
||||
private static final String CLOCK_FONT_SIZE = "lockclock_font_size";
|
||||
private static final String CUSTOM_TEXT_CLOCK_FONT_SIZE = "custom_text_clock_font_size";
|
||||
private static final String DATE_FONT_SIZE = "lockdate_font_size";
|
||||
private static final String LOCKOWNER_FONT_SIZE = "lockowner_font_size";
|
||||
private static final String AOD_SCHEDULE_KEY = "always_on_display_schedule";
|
||||
private static final String FOD_ANIMATION_CATEGORY = "fod_animations";
|
||||
private static final String FOD_ICON_PICKER_CATEGORY = "fod_icon_picker";
|
||||
private static final String PREF_LS_CLOCK_SELECTION = "lockscreen_clock_selection";
|
||||
private static final String PREF_LS_CLOCK_ANIM_SELECTION = "lockscreen_clock_animation_selection";
|
||||
private static final String LOTTIE_ANIMATION_SIZE = "lockscreen_clock_animation_size";
|
||||
private ContentResolver mResolver;
|
||||
private Preference FODSettings;
|
||||
|
||||
static final int MODE_DISABLED = 0;
|
||||
static final int MODE_NIGHT = 1;
|
||||
static final int MODE_TIME = 2;
|
||||
static final int MODE_MIXED_SUNSET = 3;
|
||||
static final int MODE_MIXED_SUNRISE = 4;
|
||||
|
||||
private CustomSeekBarPreference mClockFontSize;
|
||||
private CustomSeekBarPreference mDateFontSize;
|
||||
private CustomSeekBarPreference mOwnerInfoFontSize;
|
||||
private CustomSeekBarPreference mCustomTextClockFontSize;
|
||||
private PreferenceCategory mFODIconPickerCategory;
|
||||
private SecureSettingListPreference mLockClockSelection;
|
||||
private SystemSettingListPreference mLockClockAnimSelection;
|
||||
private CustomSeekBarPreference mLottieAnimationSize;
|
||||
private Preference mAODPref;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -107,133 +76,15 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mLottieAnimationSize = (CustomSeekBarPreference) findPreference(LOTTIE_ANIMATION_SIZE);
|
||||
int lottieSize = Settings.System.getIntForUser(ctx.getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CLOCK_ANIMATION_SIZE, res.getIdentifier("com.android.systemui:dimen/lottie_animation_width_height", null, null), UserHandle.USER_CURRENT);
|
||||
mLottieAnimationSize.setValue(lottieSize);
|
||||
mLottieAnimationSize.setOnPreferenceChangeListener(this);
|
||||
|
||||
mLockClockAnimSelection = (SystemSettingListPreference) findPreference(PREF_LS_CLOCK_ANIM_SELECTION);
|
||||
|
||||
mLockClockSelection = (SecureSettingListPreference) findPreference(PREF_LS_CLOCK_SELECTION);
|
||||
int val = Settings.Secure.getIntForUser(resolver,
|
||||
Settings.Secure.LOCKSCREEN_CLOCK_SELECTION, 2, UserHandle.USER_CURRENT);
|
||||
mLockClockSelection.setOnPreferenceChangeListener(this);
|
||||
if (val > 3 && val < 8) {
|
||||
mLockClockAnimSelection.setEnabled(true);
|
||||
mLottieAnimationSize.setEnabled(true);
|
||||
} else {
|
||||
mLockClockAnimSelection.setEnabled(false);
|
||||
mLottieAnimationSize.setEnabled(false);
|
||||
}
|
||||
|
||||
mFODIconPickerCategory = findPreference(FOD_ICON_PICKER_CATEGORY);
|
||||
if (mFODIconPickerCategory != null && !FodUtils.hasFodSupport(getContext())) {
|
||||
prefScreen.removePreference(mFODIconPickerCategory);
|
||||
}
|
||||
|
||||
final PreferenceCategory fodCat = (PreferenceCategory) prefScreen
|
||||
.findPreference(FOD_ANIMATION_CATEGORY);
|
||||
final boolean isFodAnimationResources = CherishUtils.isPackageInstalled(getContext(),
|
||||
getResources().getString(com.android.internal.R.string.config_fodAnimationPackage));
|
||||
if (!isFodAnimationResources) {
|
||||
prefScreen.removePreference(fodCat);
|
||||
}
|
||||
|
||||
// Lock Clock Size
|
||||
mClockFontSize = (CustomSeekBarPreference) findPreference(CLOCK_FONT_SIZE);
|
||||
mClockFontSize.setValue(Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCKCLOCK_FONT_SIZE, 78));
|
||||
mClockFontSize.setOnPreferenceChangeListener(this);
|
||||
|
||||
// Lock Date Size
|
||||
mDateFontSize = (CustomSeekBarPreference) findPreference(DATE_FONT_SIZE);
|
||||
mDateFontSize.setValue(Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCKDATE_FONT_SIZE, 18));
|
||||
mDateFontSize.setOnPreferenceChangeListener(this);
|
||||
|
||||
// Lockscren OwnerInfo Size
|
||||
mOwnerInfoFontSize = (CustomSeekBarPreference) findPreference(LOCKOWNER_FONT_SIZE);
|
||||
mOwnerInfoFontSize.setValue(Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.LOCKOWNER_FONT_SIZE,21));
|
||||
mOwnerInfoFontSize.setOnPreferenceChangeListener(this);
|
||||
|
||||
// Custom Text Clock Size
|
||||
mCustomTextClockFontSize = (CustomSeekBarPreference) findPreference(CUSTOM_TEXT_CLOCK_FONT_SIZE);
|
||||
mCustomTextClockFontSize.setValue(Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.CUSTOM_TEXT_CLOCK_FONT_SIZE, 40));
|
||||
mCustomTextClockFontSize.setOnPreferenceChangeListener(this);
|
||||
|
||||
mAODPref = findPreference(AOD_SCHEDULE_KEY);
|
||||
updateAlwaysOnSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateAlwaysOnSummary();
|
||||
}
|
||||
|
||||
private void updateAlwaysOnSummary() {
|
||||
if (mAODPref == null) return;
|
||||
int mode = Settings.Secure.getIntForUser(getActivity().getContentResolver(),
|
||||
Settings.Secure.DOZE_ALWAYS_ON_AUTO_MODE, MODE_DISABLED, UserHandle.USER_CURRENT);
|
||||
switch (mode) {
|
||||
default:
|
||||
case MODE_DISABLED:
|
||||
mAODPref.setSummary(R.string.disabled);
|
||||
break;
|
||||
case MODE_NIGHT:
|
||||
mAODPref.setSummary(R.string.night_display_auto_mode_twilight);
|
||||
break;
|
||||
case MODE_TIME:
|
||||
mAODPref.setSummary(R.string.night_display_auto_mode_custom);
|
||||
break;
|
||||
case MODE_MIXED_SUNSET:
|
||||
mAODPref.setSummary(R.string.always_on_display_schedule_mixed_sunset);
|
||||
break;
|
||||
case MODE_MIXED_SUNRISE:
|
||||
mAODPref.setSummary(R.string.always_on_display_schedule_mixed_sunrise);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mClockFontSize) {
|
||||
int top = (Integer) newValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCKCLOCK_FONT_SIZE, top*1);
|
||||
return true;
|
||||
} else if (preference == mCustomTextClockFontSize) {
|
||||
int top = (Integer) newValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.CUSTOM_TEXT_CLOCK_FONT_SIZE, top*1);
|
||||
return true;
|
||||
} else if (preference == mDateFontSize) {
|
||||
int top = (Integer) newValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.LOCKDATE_FONT_SIZE, top*1);
|
||||
return true;
|
||||
} else if (preference == mLottieAnimationSize) {
|
||||
int value = (Integer) newValue;
|
||||
Settings.System.putIntForUser(getContext().getContentResolver(),
|
||||
Settings.System.LOCKSCREEN_CLOCK_ANIMATION_SIZE, value, UserHandle.USER_CURRENT);
|
||||
return true;
|
||||
} else if (preference == mLockClockSelection) {
|
||||
int val = Integer.parseInt((String) newValue);
|
||||
Settings.Secure.putInt(resolver,
|
||||
Settings.Secure.LOCKSCREEN_CLOCK_SELECTION, val);
|
||||
if (val > 3 && val < 8) {
|
||||
mLockClockAnimSelection.setEnabled(true);
|
||||
mLottieAnimationSize.setEnabled(true);
|
||||
} else {
|
||||
mLockClockAnimSelection.setEnabled(false);
|
||||
mLottieAnimationSize.setEnabled(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -263,9 +114,6 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
if (!FodUtils.hasFodSupport(context)) {
|
||||
keys.add(FOD_ICON_PICKER_CATEGORY);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,29 +45,12 @@ import java.util.List;
|
||||
public class MiscSettings extends SettingsPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
|
||||
private static final String SMART_PIXELS = "smart_pixels";
|
||||
private static final String SYSUI_ROUNDED_SIZE = "sysui_rounded_size";
|
||||
private static final String SYSUI_ROUNDED_FWVALS = "sysui_rounded_fwvals";
|
||||
private static final String KEY_PULSE_BRIGHTNESS = "ambient_pulse_brightness";
|
||||
private static final String KEY_DOZE_BRIGHTNESS = "ambient_doze_brightness";
|
||||
private static final String CUSTOM_STATUSBAR_PADDING_START = "custom_statusbar_padding_start";
|
||||
private static final String CUSTOM_STATUSBAR_PADDING_END = "custom_statusbar_padding_end";
|
||||
|
||||
private CustomSeekBarPreference mCornerRadius;
|
||||
private CustomSeekBarPreference mCustomStatusbarPaddingStart;
|
||||
private CustomSeekBarPreference mCustomStatusbarPaddingEnd;
|
||||
private CustomSeekBarPreference mContentPadding;
|
||||
private SecureSettingSwitchPreference mRoundedFwvals;
|
||||
private CustomSeekBarPreference mPulseBrightness;
|
||||
private CustomSeekBarPreference mDozeBrightness;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings_misc);
|
||||
updateSmartPixelsPreference();
|
||||
|
||||
Resources res = null;
|
||||
Context ctx = getContext();
|
||||
@@ -79,110 +62,13 @@ public class MiscSettings extends SettingsPreferenceFragment implements
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
mCustomStatusbarPaddingStart = (CustomSeekBarPreference) findPreference(CUSTOM_STATUSBAR_PADDING_START);
|
||||
int customStatusbarPaddingStart = Settings.System.getIntForUser(ctx.getContentResolver(),
|
||||
Settings.System.CUSTOM_STATUSBAR_PADDING_START, res.getIdentifier("com.android.systemui:dimen/status_bar_padding_start", null, null), UserHandle.USER_CURRENT);
|
||||
mCustomStatusbarPaddingStart.setValue(customStatusbarPaddingStart);
|
||||
mCustomStatusbarPaddingStart.setOnPreferenceChangeListener(this);
|
||||
|
||||
mCustomStatusbarPaddingEnd = (CustomSeekBarPreference) findPreference(CUSTOM_STATUSBAR_PADDING_END);
|
||||
int customStatusbarPaddingEnd = Settings.System.getIntForUser(getActivity().getContentResolver(),
|
||||
Settings.System.CUSTOM_STATUSBAR_PADDING_END, res.getIdentifier("com.android.systemui:dimen/status_bar_padding_end", null, null), UserHandle.USER_CURRENT);
|
||||
mCustomStatusbarPaddingEnd.setValue(customStatusbarPaddingEnd);
|
||||
mCustomStatusbarPaddingEnd.setOnPreferenceChangeListener(this);
|
||||
|
||||
// Rounded use Framework Values
|
||||
mRoundedFwvals = (SecureSettingSwitchPreference) findPreference(SYSUI_ROUNDED_FWVALS);
|
||||
mRoundedFwvals.setOnPreferenceChangeListener(this);
|
||||
|
||||
int defaultDoze = getResources().getInteger(
|
||||
com.android.internal.R.integer.config_screenBrightnessDoze);
|
||||
int defaultPulse = getResources().getInteger(
|
||||
com.android.internal.R.integer.config_screenBrightnessPulse);
|
||||
if (defaultPulse == -1) {
|
||||
defaultPulse = defaultDoze;
|
||||
}
|
||||
|
||||
mPulseBrightness = (CustomSeekBarPreference) findPreference(KEY_PULSE_BRIGHTNESS);
|
||||
int value = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.PULSE_BRIGHTNESS, defaultPulse);
|
||||
mPulseBrightness.setValue(value);
|
||||
mPulseBrightness.setOnPreferenceChangeListener(this);
|
||||
|
||||
mDozeBrightness = (CustomSeekBarPreference) findPreference(KEY_DOZE_BRIGHTNESS);
|
||||
value = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.DOZE_BRIGHTNESS, defaultDoze);
|
||||
mDozeBrightness.setValue(value);
|
||||
mDozeBrightness.setOnPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
private void updateSmartPixelsPreference() {
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
boolean enableSmartPixels = getContext().getResources().
|
||||
getBoolean(com.android.internal.R.bool.config_enableSmartPixels);
|
||||
Preference smartPixels = findPreference(SMART_PIXELS);
|
||||
|
||||
if (!enableSmartPixels){
|
||||
prefSet.removePreference(smartPixels);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
if (preference == mCornerRadius) {
|
||||
Settings.Secure.putIntForUser(getContext().getContentResolver(), Settings.Secure.SYSUI_ROUNDED_SIZE,
|
||||
(int) objValue, UserHandle.USER_CURRENT);
|
||||
return true;
|
||||
} else if (preference == mRoundedFwvals) {
|
||||
restoreCorners();
|
||||
return true;
|
||||
} else if (preference == mPulseBrightness) {
|
||||
int value = (Integer) objValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.PULSE_BRIGHTNESS, value);
|
||||
return true;
|
||||
} else if (preference == mDozeBrightness) {
|
||||
int value = (Integer) objValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.DOZE_BRIGHTNESS, value);
|
||||
return true;
|
||||
} else if (preference == mCustomStatusbarPaddingStart) {
|
||||
int value = (Integer) objValue;
|
||||
Settings.System.putIntForUser(getContext().getContentResolver(),
|
||||
Settings.System.CUSTOM_STATUSBAR_PADDING_START, value, UserHandle.USER_CURRENT);
|
||||
return true;
|
||||
} else if (preference == mCustomStatusbarPaddingEnd) {
|
||||
int value = (Integer) objValue;
|
||||
Settings.System.putIntForUser(getContext().getContentResolver(),
|
||||
Settings.System.CUSTOM_STATUSBAR_PADDING_END, value, UserHandle.USER_CURRENT);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
mCornerRadius.setValue((int) (resourceIdRadius / density));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
|
||||
@@ -38,24 +38,6 @@ import java.util.List;
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class NotificationSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener{
|
||||
|
||||
private static final String NOTIFICATION_PULSE_COLOR = "ambient_notification_light_color";
|
||||
private static final String NOTIFICATION_PULSE_DURATION = "notification_pulse_duration";
|
||||
private static final String NOTIFICATION_PULSE_REPEATS = "notification_pulse_repeats";
|
||||
private static final String PULSE_COLOR_MODE_PREF = "ambient_notification_light_color_mode";
|
||||
private static final String INCALL_VIB_OPTIONS = "incall_vib_options";
|
||||
private static final String KEY_AMBIENT = "ambient_notification_light_enabled";
|
||||
private static final String ALERT_SLIDER_PREF = "alert_slider_notifications";
|
||||
private static final String KEY_CHARGING_LIGHT = "charging_light";
|
||||
private static final String LED_CATEGORY = "led";
|
||||
|
||||
private Preference mChargingLeds;
|
||||
private PreferenceCategory mLedCategory;
|
||||
private ColorPickerPreference mEdgeLightColorPreference;
|
||||
private CustomSeekBarPreference mEdgeLightDurationPreference;
|
||||
private CustomSeekBarPreference mEdgeLightRepeatCountPreference;
|
||||
private ListPreference mColorMode;
|
||||
private SystemSettingSwitchPreference mAmbientPref;
|
||||
private Preference mAlertSlider;
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -64,132 +46,11 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
final Resources res = getResources();
|
||||
|
||||
mAlertSlider = (Preference) prefScreen.findPreference(ALERT_SLIDER_PREF);
|
||||
boolean mAlertSliderAvailable = res.getBoolean(
|
||||
com.android.internal.R.bool.config_hasAlertSlider);
|
||||
if (!mAlertSliderAvailable)
|
||||
prefScreen.removePreference(mAlertSlider);
|
||||
|
||||
boolean hasLED = res.getBoolean(
|
||||
com.android.internal.R.bool.config_hasNotificationLed);
|
||||
if (hasLED) {
|
||||
mChargingLeds = findPreference(KEY_CHARGING_LIGHT);
|
||||
if (mChargingLeds != null
|
||||
&& !res.getBoolean(
|
||||
com.android.internal.R.bool.config_intrusiveBatteryLed)) {
|
||||
prefScreen.removePreference(mChargingLeds);
|
||||
}
|
||||
} else {
|
||||
mLedCategory = findPreference(LED_CATEGORY);
|
||||
mLedCategory.setVisible(false);
|
||||
}
|
||||
|
||||
PreferenceCategory incallVibCategory = (PreferenceCategory) findPreference(INCALL_VIB_OPTIONS);
|
||||
if (!CherishUtils.isVoiceCapable(getActivity())) {
|
||||
prefScreen.removePreference(incallVibCategory);
|
||||
}
|
||||
|
||||
mAmbientPref = (SystemSettingSwitchPreference) findPreference(KEY_AMBIENT);
|
||||
boolean aodEnabled = Settings.Secure.getIntForUser(resolver,
|
||||
Settings.Secure.DOZE_ALWAYS_ON, 0, UserHandle.USER_CURRENT) == 1;
|
||||
if (!aodEnabled) {
|
||||
mAmbientPref.setChecked(false);
|
||||
mAmbientPref.setEnabled(false);
|
||||
mAmbientPref.setSummary(R.string.aod_disabled);
|
||||
}
|
||||
|
||||
mEdgeLightRepeatCountPreference = (CustomSeekBarPreference) findPreference(NOTIFICATION_PULSE_REPEATS);
|
||||
mEdgeLightRepeatCountPreference.setOnPreferenceChangeListener(this);
|
||||
int repeats = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_REPEATS, 0);
|
||||
mEdgeLightRepeatCountPreference.setValue(repeats);
|
||||
|
||||
mEdgeLightDurationPreference = (CustomSeekBarPreference) findPreference(NOTIFICATION_PULSE_DURATION);
|
||||
mEdgeLightDurationPreference.setOnPreferenceChangeListener(this);
|
||||
int duration = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_DURATION, 2);
|
||||
mEdgeLightDurationPreference.setValue(duration);
|
||||
|
||||
mColorMode = (ListPreference) findPreference(PULSE_COLOR_MODE_PREF);
|
||||
int value;
|
||||
boolean colorModeAutomatic = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_COLOR_AUTOMATIC, 0) != 0;
|
||||
boolean colorModeAccent = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_ACCENT, 0) != 0;
|
||||
if (colorModeAutomatic) {
|
||||
value = 0;
|
||||
} else if (colorModeAccent) {
|
||||
value = 1;
|
||||
} else {
|
||||
value = 2;
|
||||
}
|
||||
|
||||
mColorMode.setValue(Integer.toString(value));
|
||||
mColorMode.setSummary(mColorMode.getEntry());
|
||||
mColorMode.setOnPreferenceChangeListener(this);
|
||||
|
||||
mEdgeLightColorPreference = (ColorPickerPreference) findPreference(NOTIFICATION_PULSE_COLOR);
|
||||
int edgeLightColor = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_COLOR, 0xFF3980FF);
|
||||
mEdgeLightColorPreference.setNewPreviewColor(edgeLightColor);
|
||||
mEdgeLightColorPreference.setAlphaSliderEnabled(false);
|
||||
String edgeLightColorHex = String.format("#%08x", (0xFF3980FF & edgeLightColor));
|
||||
if (edgeLightColorHex.equals("#ff1a73e8")) {
|
||||
mEdgeLightColorPreference.setSummary(R.string.color_default);
|
||||
} else {
|
||||
mEdgeLightColorPreference.setSummary(edgeLightColorHex);
|
||||
}
|
||||
mEdgeLightColorPreference.setOnPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (preference == mEdgeLightColorPreference) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(newValue)));
|
||||
if (hex.equals("#ff1a73e8")) {
|
||||
preference.setSummary(R.string.color_default);
|
||||
} else {
|
||||
preference.setSummary(hex);
|
||||
}
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_COLOR, intHex);
|
||||
return true;
|
||||
} else if (preference == mEdgeLightRepeatCountPreference) {
|
||||
int value = (Integer) newValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_REPEATS, value);
|
||||
return true;
|
||||
} else if (preference == mEdgeLightDurationPreference) {
|
||||
int value = (Integer) newValue;
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_DURATION, value);
|
||||
return true;
|
||||
} else if (preference == mColorMode) {
|
||||
int value = Integer.valueOf((String) newValue);
|
||||
int index = mColorMode.findIndexOfValue((String) newValue);
|
||||
mColorMode.setSummary(mColorMode.getEntries()[index]);
|
||||
if (value == 0) {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_COLOR_AUTOMATIC, 1);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_ACCENT, 0);
|
||||
} else if (value == 1) {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_COLOR_AUTOMATIC, 0);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_ACCENT, 1);
|
||||
} else {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_COLOR_AUTOMATIC, 0);
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.NOTIFICATION_PULSE_ACCENT, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -220,10 +81,6 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
final Resources res = context.getResources();
|
||||
boolean mAlertSliderAvailable = res.getBoolean(
|
||||
com.android.internal.R.bool.config_hasAlertSlider);
|
||||
if (!mAlertSliderAvailable)
|
||||
keys.add(ALERT_SLIDER_PREF);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -46,10 +46,6 @@ import java.util.List;
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class PowerMenuSettings extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String POWER_MENU_ANIMATIONS = "power_menu_animations";
|
||||
|
||||
private ListPreference mPowerMenuAnimations;
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -58,24 +54,10 @@ public class PowerMenuSettings extends SettingsPreferenceFragment
|
||||
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
|
||||
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) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 NezukoOS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (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 android.content.DialogInterface;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.os.UserHandle;
|
||||
import com.cherish.settings.preferences.SystemSettingListPreference;
|
||||
import androidx.preference.*;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Toast;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class PowerSaving extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
|
||||
|
||||
private static final String POWER_PROFILE = "power_profile_type";
|
||||
|
||||
private SystemSettingListPreference mPowerProfile;
|
||||
|
||||
public static final String[] POWER_MODE_PROFILES = {
|
||||
"advertise_is_enabled=false,datasaver_disabled=true,enable_night_mode=false,launch_boost_disabled=false,vibration_disabled=false,animation_disabled=false,soundtrigger_disabled=false,fullbackup_deferred=true,keyvaluebackup_deferred=true,firewall_disabled=false,gps_mode=4,adjust_brightness_disabled=true,adjust_brightness_factor=0.5,force_all_apps_standby=false,force_background_check=false,optional_sensors_disabled=true,aod_disabled=false,quick_doze_enabled=true",
|
||||
"null",
|
||||
"advertise_is_enabled=true,datasaver_disabled=true,enable_night_mode=true,launch_boost_disabled=false,vibration_disabled=false,animation_disabled=false,soundtrigger_disabled=false,fullbackup_deferred=true,keyvaluebackup_deferred=true,firewall_disabled=false,gps_mode=4,adjust_brightness_disabled=true,adjust_brightness_factor=0.75,force_all_apps_standby=false,force_background_check=false,optional_sensors_disabled=true,aod_disabled=true,quick_doze_enabled=true",
|
||||
"advertise_is_enabled=true,datasaver_disabled=false,enable_night_mode=true,launch_boost_disabled=true,vibration_disabled=true,animation_disabled=false,soundtrigger_disabled=true,fullbackup_deferred=true,keyvaluebackup_deferred=true,firewall_disabled=true,gps_mode=2,adjust_brightness_disabled=false,adjust_brightness_factor=0.6,force_all_apps_standby=true,force_background_check=true,optional_sensors_disabled=true,aod_disabled=true,quick_doze_enabled=true",
|
||||
"advertise_is_enabled=true,datasaver_disabled=false,enable_night_mode=true,launch_boost_disabled=true,vibration_disabled=true,animation_disabled=true,soundtrigger_disabled=true,fullbackup_deferred=true,keyvaluebackup_deferred=true,firewall_disabled=true,gps_mode=2,adjust_brightness_disabled=false,adjust_brightness_factor=0.5,force_all_apps_standby=true,force_background_check=true,optional_sensors_disabled=true,aod_disabled=true,quick_doze_enabled=true",
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.cherish_settings_powersave);
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
mPowerProfile = (SystemSettingListPreference) findPreference(POWER_PROFILE);
|
||||
mPowerProfile.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (preference == mPowerProfile){
|
||||
int profile = Integer.valueOf((String) newValue);
|
||||
for (int i = 0; i < POWER_MODE_PROFILES.length; i++) {
|
||||
if(profile == i){
|
||||
if (profile != 1){
|
||||
Settings.Global.putString(getActivity().getContentResolver(), Settings.Global.BATTERY_SAVER_CONSTANTS, POWER_MODE_PROFILES[i]);
|
||||
} else{
|
||||
Settings.Global.putString(getActivity().getContentResolver(), Settings.Global.BATTERY_SAVER_CONSTANTS, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
}
|
||||
@@ -1,246 +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 android.app.ActionBar;
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
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.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
public class PulseSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
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.pulse_settings);
|
||||
|
||||
ContentResolver resolver = getContext().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, 0, 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);
|
||||
int userColor = Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.PULSE_COLOR_USER, 0xffffffff);
|
||||
mColorPickerPref.setOnPreferenceChangeListener(this);
|
||||
mLavaSpeedPref = findPreference(PULSE_COLOR_MODE_LAVA_SPEED_KEY);
|
||||
mColorModePref.setOnPreferenceChangeListener(this);
|
||||
|
||||
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 == mColorPickerPref) {
|
||||
int value = (Integer) newValue;
|
||||
Settings.Secure.putInt(resolver,
|
||||
Settings.Secure.PULSE_COLOR_USER, value);
|
||||
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 = getContext().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, 1, UserHandle.USER_CURRENT) != 0;
|
||||
|
||||
boolean ambientPulse = Settings.Secure.getIntForUser(resolver,
|
||||
Settings.Secure.AMBIENT_PULSE_ENABLED, 1, 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_LAVALAMP, 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.pulse_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,257 +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.Context;
|
||||
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 com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.qs_header;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -36,13 +36,6 @@ import java.util.ArrayList;
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class QuickSettings extends SettingsPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
|
||||
private static final String FOOTER_TEXT_STRING = "footer_text_string";
|
||||
private static final String STATUS_BAR_CUSTOM_HEADER = "status_bar_custom_header";
|
||||
|
||||
private SystemSettingEditTextPreference mFooterString;
|
||||
private SystemSettingMasterSwitchPreference mCustomHeader;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -51,46 +44,11 @@ public class QuickSettings extends SettingsPreferenceFragment implements
|
||||
|
||||
PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
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);
|
||||
|
||||
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 == 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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.os.Bundle;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.content.res.Resources;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import android.provider.Settings;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import java.util.Locale;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class SBWeather extends SettingsPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_sb_weather);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.cherish_sb_weather;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,280 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Android Open Kang Project
|
||||
* (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.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.content.res.Resources;
|
||||
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 android.provider.Settings;
|
||||
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.R;
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class ScreenStateToggles extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String TAG = "ScreenStateToggles";
|
||||
private static final String SCREEN_STATE_TOOGLES_ENABLE = "screen_state_toggles_enable_key";
|
||||
private static final String SCREEN_STATE_TOOGLES_TWOG = "screen_state_toggles_twog";
|
||||
private static final String SCREEN_STATE_TOGGLES_THREEG = "screen_state_toggles_threeg";
|
||||
private static final String SCREEN_STATE_TOOGLES_GPS = "screen_state_toggles_gps";
|
||||
private static final String SCREEN_STATE_TOOGLES_MOBILE_DATA = "screen_state_toggles_mobile_data";
|
||||
private static final String SCREEN_STATE_ON_DELAY = "screen_state_on_delay";
|
||||
private static final String SCREEN_STATE_OFF_DELAY = "screen_state_off_delay";
|
||||
private static final String SCREEN_STATE_CATGEGORY_LOCATION = "screen_state_toggles_location_key";
|
||||
private static final String SCREEN_STATE_CATGEGORY_MOBILE_DATA = "screen_state_toggles_mobile_key";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private SwitchPreference mEnableScreenStateToggles;
|
||||
private SwitchPreference mEnableScreenStateTogglesTwoG;
|
||||
private SwitchPreference mEnableScreenStateTogglesThreeG;
|
||||
private SwitchPreference mEnableScreenStateTogglesGps;
|
||||
private SwitchPreference mEnableScreenStateTogglesMobileData;
|
||||
private CustomSeekBarPreference mSecondsOffDelay;
|
||||
private CustomSeekBarPreference mSecondsOnDelay;
|
||||
private PreferenceCategory mMobileDateCategory;
|
||||
private PreferenceCategory mLocationCategory;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.screen_state_toggles);
|
||||
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
final PreferenceScreen prefSet = getPreferenceScreen();
|
||||
Resources resources = getResources();
|
||||
|
||||
mContext = (Context) getActivity();
|
||||
|
||||
mEnableScreenStateToggles = (SwitchPreference) findPreference(
|
||||
SCREEN_STATE_TOOGLES_ENABLE);
|
||||
|
||||
int enabled = Settings.System.getInt(resolver, Settings.System.START_SCREEN_STATE_SERVICE, 0);
|
||||
|
||||
mEnableScreenStateToggles.setChecked(enabled != 0);
|
||||
mEnableScreenStateToggles.setOnPreferenceChangeListener(this);
|
||||
|
||||
mSecondsOffDelay = (CustomSeekBarPreference) findPreference(SCREEN_STATE_OFF_DELAY);
|
||||
int offd = Settings.System.getInt(resolver,
|
||||
Settings.System.SCREEN_STATE_OFF_DELAY, 0);
|
||||
mSecondsOffDelay.setValue(offd);
|
||||
mSecondsOffDelay.setOnPreferenceChangeListener(this);
|
||||
|
||||
mSecondsOnDelay = (CustomSeekBarPreference) findPreference(SCREEN_STATE_ON_DELAY);
|
||||
int ond = Settings.System.getInt(resolver,
|
||||
Settings.System.SCREEN_STATE_ON_DELAY, 0);
|
||||
mSecondsOnDelay.setValue(ond);
|
||||
mSecondsOnDelay.setOnPreferenceChangeListener(this);
|
||||
|
||||
mMobileDateCategory = (PreferenceCategory) findPreference(
|
||||
SCREEN_STATE_CATGEGORY_MOBILE_DATA);
|
||||
mLocationCategory = (PreferenceCategory) findPreference(
|
||||
SCREEN_STATE_CATGEGORY_LOCATION);
|
||||
|
||||
mEnableScreenStateTogglesTwoG = (SwitchPreference) findPreference(
|
||||
SCREEN_STATE_TOOGLES_TWOG);
|
||||
|
||||
mEnableScreenStateTogglesThreeG = (SwitchPreference) findPreference(
|
||||
SCREEN_STATE_TOGGLES_THREEG);
|
||||
|
||||
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
if (!cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)){
|
||||
getPreferenceScreen().removePreference(mEnableScreenStateTogglesTwoG);
|
||||
getPreferenceScreen().removePreference(mEnableScreenStateTogglesThreeG);
|
||||
} else {
|
||||
mEnableScreenStateTogglesTwoG.setChecked((
|
||||
Settings.System.getInt(resolver, Settings.System.SCREEN_STATE_TWOG, 0) == 1));
|
||||
mEnableScreenStateTogglesTwoG.setOnPreferenceChangeListener(this);
|
||||
mEnableScreenStateTogglesThreeG.setChecked((
|
||||
Settings.System.getIntForUser(resolver,
|
||||
Settings.System.SCREEN_STATE_THREEG, 0, UserHandle.USER_CURRENT) == 1));
|
||||
mEnableScreenStateTogglesThreeG.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
mEnableScreenStateTogglesMobileData = (SwitchPreference) findPreference(
|
||||
SCREEN_STATE_TOOGLES_MOBILE_DATA);
|
||||
|
||||
if (!cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)){
|
||||
getPreferenceScreen().removePreference(mEnableScreenStateTogglesMobileData);
|
||||
} else {
|
||||
mEnableScreenStateTogglesMobileData.setChecked((
|
||||
Settings.System.getInt(resolver, Settings.System.SCREEN_STATE_MOBILE_DATA, 0) == 1));
|
||||
mEnableScreenStateTogglesMobileData.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
// Only enable these controls if this user is allowed to change location
|
||||
// sharing settings.
|
||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||
boolean isLocationChangeAllowed = !um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION);
|
||||
|
||||
// TODO: check if gps is available on this device?
|
||||
mEnableScreenStateTogglesGps = (SwitchPreference) findPreference(
|
||||
SCREEN_STATE_TOOGLES_GPS);
|
||||
|
||||
if (!isLocationChangeAllowed){
|
||||
getPreferenceScreen().removePreference(mEnableScreenStateTogglesGps);
|
||||
mEnableScreenStateTogglesGps = null;
|
||||
} else {
|
||||
mEnableScreenStateTogglesGps.setChecked((
|
||||
Settings.System.getInt(getActivity().getContentResolver(), Settings.System.SCREEN_STATE_GPS, 0) == 1));
|
||||
mEnableScreenStateTogglesGps.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
mMobileDateCategory.setEnabled(enabled != 0);
|
||||
mLocationCategory.setEnabled(enabled != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
if (preference == mEnableScreenStateToggles) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.START_SCREEN_STATE_SERVICE, value ? 1 : 0);
|
||||
|
||||
Intent service = (new Intent())
|
||||
.setClassName("com.android.systemui", "com.android.systemui.screenstate.ScreenStateService");
|
||||
if (value) {
|
||||
getActivity().stopService(service);
|
||||
getActivity().startService(service);
|
||||
} else {
|
||||
getActivity().stopService(service);
|
||||
}
|
||||
|
||||
mMobileDateCategory.setEnabled(value);
|
||||
mLocationCategory.setEnabled(value);
|
||||
|
||||
return true;
|
||||
} else if (preference == mEnableScreenStateTogglesTwoG) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.SCREEN_STATE_TWOG, value ? 1 : 0);
|
||||
|
||||
Intent intent = new Intent("android.intent.action.SCREEN_STATE_SERVICE_UPDATE");
|
||||
mContext.sendBroadcast(intent);
|
||||
|
||||
return true;
|
||||
} else if (preference == mEnableScreenStateTogglesThreeG) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.SCREEN_STATE_THREEG, value ? 1 : 0, UserHandle.USER_CURRENT);
|
||||
|
||||
Intent intent = new Intent("android.intent.action.SCREEN_STATE_SERVICE_UPDATE");
|
||||
mContext.sendBroadcast(intent);
|
||||
return true;
|
||||
} else if (preference == mEnableScreenStateTogglesGps) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.SCREEN_STATE_GPS, value ? 1 : 0);
|
||||
|
||||
Intent intent = new Intent("android.intent.action.SCREEN_STATE_SERVICE_UPDATE");
|
||||
mContext.sendBroadcast(intent);
|
||||
|
||||
return true;
|
||||
} else if (preference == mEnableScreenStateTogglesMobileData) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.SCREEN_STATE_MOBILE_DATA, value ? 1 : 0);
|
||||
|
||||
Intent intent = new Intent("android.intent.action.SCREEN_STATE_SERVICE_UPDATE");
|
||||
mContext.sendBroadcast(intent);
|
||||
|
||||
return true;
|
||||
} else if (preference == mSecondsOffDelay) {
|
||||
int delay = (Integer) newValue;
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.SCREEN_STATE_OFF_DELAY, delay, UserHandle.USER_CURRENT);
|
||||
|
||||
return true;
|
||||
} else if (preference == mSecondsOnDelay) {
|
||||
int delay = (Integer) newValue;
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.SCREEN_STATE_ON_DELAY, delay, UserHandle.USER_CURRENT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
private void restartService(){
|
||||
Intent service = (new Intent())
|
||||
.setClassName("com.android.systemui", "com.android.systemui.screenstate.ScreenStateService");
|
||||
getActivity().stopService(service);
|
||||
getActivity().startService(service);
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.screen_state_toggles;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,404 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2021 The Evolution X Project
|
||||
* Copyright (C) 2019-2021 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.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.format.DateFormat;
|
||||
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.SwitchPreference;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import com.cherish.settings.preferences.AppListPreference;
|
||||
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;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class SensorBlockSettings extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceClickListener {
|
||||
|
||||
private static final int DIALOG_BLOCKED_APPS = 1;
|
||||
private static final String SENSOR_BLOCK = "sensor_block";
|
||||
private static final String SENSOR_BLOCK_FOOTER = "sensor_block_footer";
|
||||
|
||||
private PackageListAdapter mPackageAdapter;
|
||||
private PackageManager mPackageManager;
|
||||
private PreferenceGroup mSensorBlockPrefList;
|
||||
private Preference mAddSensorBlockPref;
|
||||
private Preference mSleepMode;
|
||||
|
||||
private String mBlockedPackageList;
|
||||
private Map<String, Package> mBlockedPackages;
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// Get launch-able applications
|
||||
addPreferencesFromResource(R.xml.settings_sensor_block);
|
||||
|
||||
findPreference(SENSOR_BLOCK_FOOTER).setTitle(R.string.add_sensor_block_package_summary);
|
||||
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
|
||||
mPackageManager = getPackageManager();
|
||||
mPackageAdapter = new PackageListAdapter(getActivity());
|
||||
|
||||
mSensorBlockPrefList = (PreferenceGroup) findPreference("sensor_block_applications");
|
||||
mSensorBlockPrefList.setOrderingAsAdded(false);
|
||||
|
||||
mBlockedPackages = new HashMap<String, Package>();
|
||||
|
||||
mAddSensorBlockPref = findPreference("add_sensor_block_packages");
|
||||
|
||||
mAddSensorBlockPref.setOnPreferenceClickListener(this);
|
||||
|
||||
mContext = getActivity().getApplicationContext();
|
||||
|
||||
mSleepMode = findPreference("sleep_mode");
|
||||
updateSleepModeSummary();
|
||||
}
|
||||
|
||||
private void updateSleepModeSummary() {
|
||||
if (mSleepMode == null) return;
|
||||
boolean enabled = Settings.Secure.getIntForUser(getActivity().getContentResolver(),
|
||||
Settings.Secure.SLEEP_MODE_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
|
||||
int mode = Settings.Secure.getIntForUser(getActivity().getContentResolver(),
|
||||
Settings.Secure.SLEEP_MODE_AUTO_MODE, 0, UserHandle.USER_CURRENT);
|
||||
String timeValue = Settings.Secure.getStringForUser(getActivity().getContentResolver(),
|
||||
Settings.Secure.SLEEP_MODE_AUTO_TIME, UserHandle.USER_CURRENT);
|
||||
if (timeValue == null || timeValue.equals("")) timeValue = "20:00,07:00";
|
||||
String[] time = timeValue.split(",", 0);
|
||||
String outputFormat = DateFormat.is24HourFormat(getContext()) ? "HH:mm" : "h:mm a";
|
||||
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormat);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
LocalTime sinceValue = LocalTime.parse(time[0], formatter);
|
||||
LocalTime tillValue = LocalTime.parse(time[1], formatter);
|
||||
String detail;
|
||||
switch (mode) {
|
||||
default:
|
||||
case 0:
|
||||
detail = getActivity().getString(enabled
|
||||
? R.string.night_display_summary_on_auto_mode_never
|
||||
: R.string.night_display_summary_off_auto_mode_never);
|
||||
break;
|
||||
case 1:
|
||||
detail = getActivity().getString(enabled
|
||||
? R.string.night_display_summary_on_auto_mode_twilight
|
||||
: R.string.night_display_summary_off_auto_mode_twilight);
|
||||
break;
|
||||
case 2:
|
||||
if (enabled) {
|
||||
detail = getActivity().getString(R.string.night_display_summary_on_auto_mode_custom, tillValue.format(outputFormatter));
|
||||
} else {
|
||||
detail = getActivity().getString(R.string.night_display_summary_off_auto_mode_custom, sinceValue.format(outputFormatter));
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (enabled) {
|
||||
detail = getActivity().getString(R.string.night_display_summary_on_auto_mode_custom, tillValue.format(outputFormatter));
|
||||
} else {
|
||||
detail = getActivity().getString(R.string.night_display_summary_off_auto_mode_twilight);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (enabled) {
|
||||
detail = getActivity().getString(R.string.night_display_summary_on_auto_mode_twilight);
|
||||
} else {
|
||||
detail = getActivity().getString(R.string.night_display_summary_off_auto_mode_custom, sinceValue.format(outputFormatter));
|
||||
}
|
||||
break;
|
||||
}
|
||||
String summary = getActivity().getString(enabled
|
||||
? R.string.night_display_summary_on
|
||||
: R.string.night_display_summary_off, detail);
|
||||
mSleepMode.setSummary(summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
refreshCustomApplicationPrefs();
|
||||
updateSleepModeSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
updateSleepModeSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogMetricsCategory(int dialogId) {
|
||||
if (dialogId == DIALOG_BLOCKED_APPS) {
|
||||
return 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_BLOCKED_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, mBlockedPackages);
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public static void reset(Context mContext) {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.SENSOR_BLOCK, 0, UserHandle.USER_CURRENT);
|
||||
Settings.System.putString(resolver,
|
||||
Settings.System.SENSOR_BLOCKED_APP, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (mSensorBlockPrefList != null) {
|
||||
mSensorBlockPrefList.removeAll();
|
||||
|
||||
for (Package pkg : mBlockedPackages.values()) {
|
||||
try {
|
||||
Preference pref = createPreferenceFromInfo(pkg);
|
||||
mSensorBlockPrefList.addPreference(pref);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// Keep these at the top
|
||||
mAddSensorBlockPref.setOrder(0);
|
||||
// Add 'add' options
|
||||
mSensorBlockPrefList.addPreference(mAddSensorBlockPref);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference == mAddSensorBlockPref) {
|
||||
showDialog(DIALOG_BLOCKED_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 == mSensorBlockPrefList.findPreference(preference.getKey())) {
|
||||
removeApplicationPref(preference.getKey(), mBlockedPackages);
|
||||
}
|
||||
}
|
||||
})
|
||||
.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 AppListPreference(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;
|
||||
|
||||
String sensorBlockString = Settings.System.getString(getContentResolver(),
|
||||
Settings.System.SENSOR_BLOCKED_APP);
|
||||
|
||||
if (sensorBlockString != null &&
|
||||
!TextUtils.equals(mBlockedPackageList, sensorBlockString)) {
|
||||
mBlockedPackageList = sensorBlockString;
|
||||
mBlockedPackages.clear();
|
||||
parseAndAddToMap(sensorBlockString, mBlockedPackages);
|
||||
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 == mBlockedPackages
|
||||
? Settings.System.SENSOR_BLOCKED_APP
|
||||
: Settings.System.SENSOR_BLOCKED_APP_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.SENSOR_BLOCKED_APP)) {
|
||||
mBlockedPackageList = value;
|
||||
}
|
||||
}
|
||||
Settings.System.putString(getContentResolver(),
|
||||
setting, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.settings_sensor_block);
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.app.TimePickerDialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.format.DateFormat;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import androidx.preference.DropDownPreference;
|
||||
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;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.LocalTime;
|
||||
|
||||
public class SleepMode extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String MODE_KEY = "sleep_mode_auto_mode";
|
||||
private static final String SINCE_PREF_KEY = "sleep_mode_auto_since";
|
||||
private static final String TILL_PREF_KEY = "sleep_mode_auto_till";
|
||||
private static final String KEY_SLEEP_BUTTON = "sleep_mode_button";
|
||||
private static final String TOGGLES_CATEGORY_KEY = "sleep_mode_toggles";
|
||||
|
||||
private PreferenceCategory mToggles;
|
||||
private DropDownPreference mModePref;
|
||||
private Preference mSincePref;
|
||||
private Preference mTillPref;
|
||||
private Button mTurnOnButton;
|
||||
private Button mTurnOffButton;
|
||||
private Context mContext;
|
||||
private Handler mHandler;
|
||||
private ContentResolver mContentResolver;
|
||||
private boolean mIsNavSwitchingMode = false;
|
||||
|
||||
private final View.OnClickListener mButtonListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mTurnOnButton || v == mTurnOffButton) {
|
||||
boolean enabled = Settings.Secure.getIntForUser(mContentResolver,
|
||||
Settings.Secure.SLEEP_MODE_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
|
||||
enableSleepMode(!enabled);
|
||||
updateStateInternal();
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mIsNavSwitchingMode = false;
|
||||
}
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.sleep_mode_settings);
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
|
||||
mContext = getContext();
|
||||
mHandler = new Handler();
|
||||
mContentResolver = getActivity().getContentResolver();
|
||||
|
||||
SettingsObserver settingsObserver = new SettingsObserver(new Handler());
|
||||
settingsObserver.observe();
|
||||
|
||||
mSincePref = findPreference(SINCE_PREF_KEY);
|
||||
mSincePref.setOnPreferenceClickListener(this);
|
||||
mTillPref = findPreference(TILL_PREF_KEY);
|
||||
mTillPref.setOnPreferenceClickListener(this);
|
||||
|
||||
int mode = Settings.Secure.getIntForUser(mContentResolver,
|
||||
MODE_KEY, 0, UserHandle.USER_CURRENT);
|
||||
mModePref = (DropDownPreference) findPreference(MODE_KEY);
|
||||
mModePref.setValue(String.valueOf(mode));
|
||||
mModePref.setSummary(mModePref.getEntry());
|
||||
mModePref.setOnPreferenceChangeListener(this);
|
||||
|
||||
mToggles = findPreference(TOGGLES_CATEGORY_KEY);
|
||||
|
||||
LayoutPreference preference = findPreference(KEY_SLEEP_BUTTON);
|
||||
mTurnOnButton = preference.findViewById(R.id.sleep_mode_on_button);
|
||||
mTurnOnButton.setOnClickListener(mButtonListener);
|
||||
mTurnOffButton = preference.findViewById(R.id.sleep_mode_off_button);
|
||||
mTurnOffButton.setOnClickListener(mButtonListener);
|
||||
|
||||
updateTimeEnablement(mode);
|
||||
updateTimeSummary(mode);
|
||||
updateStateInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
if (preference == mModePref) {
|
||||
int value = Integer.parseInt((String) objValue);
|
||||
int index = mModePref.findIndexOfValue((String) objValue);
|
||||
mModePref.setSummary(mModePref.getEntries()[index]);
|
||||
Settings.Secure.putIntForUser(mContentResolver,
|
||||
MODE_KEY, value, UserHandle.USER_CURRENT);
|
||||
updateTimeEnablement(value);
|
||||
updateTimeSummary(value);
|
||||
updateStateInternal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference == mSincePref || preference == mTillPref) {
|
||||
String[] times = getCustomTimeSetting();
|
||||
boolean isSince = preference == mSincePref;
|
||||
int hour, minute;
|
||||
TimePickerDialog.OnTimeSetListener listener = (view, hourOfDay, minute1) -> {
|
||||
updateTimeSetting(isSince, hourOfDay, minute1);
|
||||
};
|
||||
if (isSince) {
|
||||
String[] sinceValues = times[0].split(":", 0);
|
||||
hour = Integer.parseInt(sinceValues[0]);
|
||||
minute = Integer.parseInt(sinceValues[1]);
|
||||
} else {
|
||||
String[] tillValues = times[1].split(":", 0);
|
||||
hour = Integer.parseInt(tillValues[0]);
|
||||
minute = Integer.parseInt(tillValues[1]);
|
||||
}
|
||||
TimePickerDialog dialog = new TimePickerDialog(mContext, listener,
|
||||
hour, minute, DateFormat.is24HourFormat(mContext));
|
||||
dialog.show();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String[] getCustomTimeSetting() {
|
||||
String value = Settings.Secure.getStringForUser(mContentResolver,
|
||||
Settings.Secure.SLEEP_MODE_AUTO_TIME, UserHandle.USER_CURRENT);
|
||||
if (value == null || value.equals("")) value = "20:00,07:00";
|
||||
return value.split(",", 0);
|
||||
}
|
||||
|
||||
private void updateTimeEnablement(int mode) {
|
||||
mSincePref.setVisible(mode == 2 || mode == 4);
|
||||
mTillPref.setVisible(mode == 2 || mode == 3);
|
||||
}
|
||||
|
||||
private void updateTimeSummary(int mode) {
|
||||
updateTimeSummary(getCustomTimeSetting(), mode);
|
||||
}
|
||||
|
||||
private void updateTimeSummary(String[] times, int mode) {
|
||||
if (mode == 0) {
|
||||
mSincePref.setSummary("-");
|
||||
mTillPref.setSummary("-");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == 1) {
|
||||
mSincePref.setSummary(R.string.sleep_mode_schedule_sunset);
|
||||
mTillPref.setSummary(R.string.sleep_mode_schedule_sunrise);
|
||||
return;
|
||||
}
|
||||
|
||||
String outputFormat = DateFormat.is24HourFormat(mContext) ? "HH:mm" : "h:mm a";
|
||||
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormat);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
LocalTime sinceDT = LocalTime.parse(times[0], formatter);
|
||||
LocalTime tillDT = LocalTime.parse(times[1], formatter);
|
||||
|
||||
if (mode == 3) {
|
||||
mSincePref.setSummary(R.string.sleep_mode_schedule_sunset);
|
||||
mTillPref.setSummary(tillDT.format(outputFormatter));
|
||||
} else if (mode == 4) {
|
||||
mTillPref.setSummary(R.string.sleep_mode_schedule_sunrise);
|
||||
mSincePref.setSummary(sinceDT.format(outputFormatter));
|
||||
} else {
|
||||
mSincePref.setSummary(sinceDT.format(outputFormatter));
|
||||
mTillPref.setSummary(tillDT.format(outputFormatter));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTimeSetting(boolean since, int hour, int minute) {
|
||||
String[] times = getCustomTimeSetting();
|
||||
String nHour = "";
|
||||
String nMinute = "";
|
||||
if (hour < 10) nHour += "0";
|
||||
if (minute < 10) nMinute += "0";
|
||||
nHour += String.valueOf(hour);
|
||||
nMinute += String.valueOf(minute);
|
||||
times[since ? 0 : 1] = nHour + ":" + nMinute;
|
||||
Settings.Secure.putStringForUser(mContentResolver,
|
||||
Settings.Secure.SLEEP_MODE_AUTO_TIME,
|
||||
times[0] + "," + times[1], UserHandle.USER_CURRENT);
|
||||
updateTimeSummary(times, Integer.parseInt(mModePref.getValue()));
|
||||
}
|
||||
|
||||
private void updateStateInternal() {
|
||||
if (mTurnOnButton == null || mTurnOffButton == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int mode = Settings.Secure.getIntForUser(mContentResolver,
|
||||
MODE_KEY, 0, UserHandle.USER_CURRENT);
|
||||
boolean isActivated = Settings.Secure.getIntForUser(mContentResolver,
|
||||
Settings.Secure.SLEEP_MODE_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
|
||||
String timeValue = Settings.Secure.getStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.SLEEP_MODE_AUTO_TIME, UserHandle.USER_CURRENT);
|
||||
if (timeValue == null || timeValue.equals("")) timeValue = "20:00,07:00";
|
||||
String[] time = timeValue.split(",", 0);
|
||||
String outputFormat = DateFormat.is24HourFormat(mContext) ? "HH:mm" : "h:mm a";
|
||||
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormat);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
LocalTime sinceValue = LocalTime.parse(time[0], formatter);
|
||||
LocalTime tillValue = LocalTime.parse(time[1], formatter);
|
||||
|
||||
String buttonText;
|
||||
|
||||
switch (mode) {
|
||||
default:
|
||||
case 0:
|
||||
buttonText = mContext.getString(isActivated ? R.string.night_display_activation_off_manual
|
||||
: R.string.night_display_activation_on_manual);
|
||||
break;
|
||||
case 1:
|
||||
buttonText = mContext.getString(isActivated ? R.string.night_display_activation_off_twilight
|
||||
: R.string.night_display_activation_on_twilight);
|
||||
break;
|
||||
case 2:
|
||||
if (isActivated) {
|
||||
buttonText = mContext.getString(R.string.night_display_activation_off_custom, sinceValue.format(outputFormatter));
|
||||
} else {
|
||||
buttonText = mContext.getString(R.string.night_display_activation_on_custom, tillValue.format(outputFormatter));
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (isActivated) {
|
||||
buttonText = mContext.getString(R.string.night_display_activation_off_twilight);
|
||||
} else {
|
||||
buttonText = mContext.getString(R.string.night_display_activation_on_custom, tillValue.format(outputFormatter));
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (isActivated) {
|
||||
buttonText = mContext.getString(R.string.night_display_activation_off_custom, sinceValue.format(outputFormatter));
|
||||
} else {
|
||||
buttonText = mContext.getString(R.string.night_display_activation_on_twilight);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (isActivated) {
|
||||
mTurnOnButton.setVisibility(View.GONE);
|
||||
mTurnOffButton.setVisibility(View.VISIBLE);
|
||||
mTurnOffButton.setText(buttonText);
|
||||
mToggles.setEnabled(false);
|
||||
} else {
|
||||
mTurnOnButton.setVisibility(View.VISIBLE);
|
||||
mTurnOffButton.setVisibility(View.GONE);
|
||||
mTurnOnButton.setText(buttonText);
|
||||
mToggles.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void enableSleepMode(boolean enable) {
|
||||
if (mIsNavSwitchingMode) return;
|
||||
mIsNavSwitchingMode = true;
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.SLEEP_MODE_ENABLED, enable ? 1 : 0, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
private class SettingsObserver extends ContentObserver {
|
||||
SettingsObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
void observe() {
|
||||
ContentResolver resolver = mContentResolver;
|
||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||
Settings.Secure.SLEEP_MODE_ENABLED), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||
Settings.Secure.SLEEP_MODE_AUTO_MODE), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
updateStateInternal();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.util.custom.SleepModeController;
|
||||
|
||||
public class SleepModeReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "SleepModeReceiver";
|
||||
|
||||
public SleepModeReceiver() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction() != null &&
|
||||
intent.getAction().equals(SleepModeController.SLEEP_MODE_TURN_OFF)) {
|
||||
Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.SLEEP_MODE_ENABLED, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,18 +47,6 @@ import java.util.Collections;
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class StatusBarSettings extends SettingsPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
|
||||
private static final String STATUS_BAR_LOGO = "status_bar_logo";
|
||||
|
||||
private SystemSettingMasterSwitchPreference mStatusBarLogo;
|
||||
|
||||
private static final String PREF_KEY_CUTOUT = "cutout_settings";
|
||||
private static final String VOLTE_ICON_STYLE = "volte_icon_style";
|
||||
private static final String VOWIFI_ICON_STYLE = "vowifi_icon_style";
|
||||
|
||||
private SystemSettingListPreference mVolteIconStyle;
|
||||
private SystemSettingListPreference mVowifiIconStyle;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -68,56 +56,11 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
|
||||
mStatusBarLogo = (SystemSettingMasterSwitchPreference) findPreference(STATUS_BAR_LOGO);
|
||||
mStatusBarLogo.setChecked((Settings.System.getInt(getActivity().getContentResolver(),
|
||||
Settings.System.STATUS_BAR_LOGO, 0) == 1));
|
||||
mStatusBarLogo.setOnPreferenceChangeListener(this);
|
||||
|
||||
Preference mCutoutPref = (Preference) findPreference(PREF_KEY_CUTOUT);
|
||||
|
||||
String hasDisplayCutout = getResources().getString(com.android.internal.R.string.config_mainBuiltInDisplayCutout);
|
||||
|
||||
mVolteIconStyle = (SystemSettingListPreference) findPreference(VOLTE_ICON_STYLE);
|
||||
int volteIconStyle = Settings.System.getInt(getActivity().getContentResolver(),
|
||||
Settings.System.VOLTE_ICON_STYLE, 0);
|
||||
mVolteIconStyle.setValue(String.valueOf(volteIconStyle));
|
||||
mVolteIconStyle.setOnPreferenceChangeListener(this);
|
||||
|
||||
mVowifiIconStyle = (SystemSettingListPreference) findPreference(VOWIFI_ICON_STYLE);
|
||||
int vowifiIconStyle = Settings.System.getInt(getActivity().getContentResolver(),
|
||||
Settings.System.VOWIFI_ICON_STYLE, 0);
|
||||
mVowifiIconStyle.setValue(String.valueOf(vowifiIconStyle));
|
||||
mVowifiIconStyle.setOnPreferenceChangeListener(this);
|
||||
|
||||
if (TextUtils.isEmpty(hasDisplayCutout)) {
|
||||
getPreferenceScreen().removePreference(mCutoutPref);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mStatusBarLogo) {
|
||||
boolean value = (Boolean) objValue;
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.STATUS_BAR_LOGO, value ? 1 : 0);
|
||||
return true;
|
||||
}else if (preference == mVolteIconStyle) {
|
||||
int volteIconStyle = Integer.parseInt(((String) objValue).toString());
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.VOLTE_ICON_STYLE, volteIconStyle);
|
||||
mVolteIconStyle.setValue(String.valueOf(volteIconStyle));
|
||||
CherishUtils.showSystemUiRestartDialog(getContext());
|
||||
return true;
|
||||
} else if (preference == mVowifiIconStyle) {
|
||||
int vowifiIconStyle = Integer.parseInt(((String) objValue).toString());
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.VOWIFI_ICON_STYLE, vowifiIconStyle);
|
||||
mVowifiIconStyle.setValue(String.valueOf(vowifiIconStyle));
|
||||
CherishUtils.showSystemUiRestartDialog(getContext());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 TenX-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.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
|
||||
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.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class StatusbarLogo extends SettingsPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstance) {
|
||||
super.onCreate(savedInstance);
|
||||
addPreferencesFromResource(R.xml.statusbar_logo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.statusbar_logo;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import static com.cherish.settings.utils.Utils.handleOverlays;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import static android.os.UserHandle.USER_SYSTEM;
|
||||
import android.app.Activity;
|
||||
@@ -39,8 +37,6 @@ import androidx.preference.SwitchPreference;
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settings.display.OverlayCategoryPreferenceController;
|
||||
import com.android.settings.display.FontPickerPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import android.provider.Settings;
|
||||
import com.android.settings.R;
|
||||
@@ -61,7 +57,6 @@ import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.android.internal.util.cherish.ThemesUtils;
|
||||
import com.android.internal.util.cherish.CherishUtils;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.cherish.settings.preferences.SystemSettingListPreference;
|
||||
@@ -72,51 +67,12 @@ import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
||||
public class ThemeSettings extends DashboardFragment implements OnPreferenceChangeListener {
|
||||
|
||||
public static final String TAG = "ThemeSettings";
|
||||
private static final String BRIGHTNESS_SLIDER_STYLE = "brightness_slider_style";
|
||||
private static final String SYSTEM_SLIDER_STYLE = "system_slider_style";
|
||||
private static final String UI_STYLE = "ui_style";
|
||||
private static final String PREF_PANEL_BG = "panel_bg";
|
||||
private static final String PREF_THEME_SWITCH = "theme_switch";
|
||||
private static final String QS_HEADER_STYLE = "qs_header_style";
|
||||
private static final String QS_TILE_STYLE = "qs_tile_style";
|
||||
private static final String PREF_RGB_ACCENT_PICKER_DARK = "rgb_accent_picker_dark";
|
||||
private static final String PREF_NB_COLOR = "navbar_color";
|
||||
static final int DEFAULT_QS_PANEL_COLOR = 0xffffffff;
|
||||
static final int DEFAULT = 0xff1a73e8;
|
||||
private static final String QS_PANEL_COLOR = "qs_panel_color";
|
||||
private static final String SWITCH_STYLE = "switch_style";
|
||||
private static final String HIDE_NOTCH = "display_hide_notch";
|
||||
private static final int MENU_RESET = Menu.FIRST;
|
||||
|
||||
private SystemSettingListPreference mSwitchStyle;
|
||||
private ColorPickerPreference mQsPanelColor;
|
||||
private Context mContext;
|
||||
|
||||
private IOverlayManager mOverlayService;
|
||||
private UiModeManager mUiModeManager;
|
||||
private ColorPickerPreference rgbAccentPickerDark;
|
||||
private ListPreference mThemeSwitch;
|
||||
private ListPreference mBrightnessSliderStyle;
|
||||
private ListPreference mSystemSliderStyle;
|
||||
private ListPreference mUIStyle;
|
||||
private ListPreference mPanelBg;
|
||||
private ListPreference mQsHeaderStyle;
|
||||
private ListPreference mQsTileStyle;
|
||||
private ListPreference mGesbar;
|
||||
private SystemSettingSwitchPreference mHideNotch;
|
||||
|
||||
private IntentFilter mIntentFilter;
|
||||
private static FontPickerPreferenceController mFontPickerPreference;
|
||||
|
||||
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals("com.android.server.ACTION_FONT_CHANGED")) {
|
||||
mFontPickerPreference.stopProgress();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
@@ -137,19 +93,6 @@ public class ThemeSettings extends DashboardFragment implements OnPreferenceChan
|
||||
Context context, Lifecycle lifecycle, Fragment fragment) {
|
||||
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new OverlayCategoryPreferenceController(context,
|
||||
"android.theme.customization.font"));
|
||||
controllers.add(new OverlayCategoryPreferenceController(context,
|
||||
"android.theme.customization.adaptive_icon_shape"));
|
||||
controllers.add(new OverlayCategoryPreferenceController(context,
|
||||
"android.theme.customization.icon_pack.android"));
|
||||
controllers.add(new OverlayCategoryPreferenceController(context,
|
||||
"android.theme.customization.statusbar_height"));
|
||||
controllers.add(new OverlayCategoryPreferenceController(context,
|
||||
"android.theme.customization.signal_icon"));
|
||||
controllers.add(new OverlayCategoryPreferenceController(context,
|
||||
"android.theme.customization.wifi_icon"));
|
||||
controllers.add(mFontPickerPreference = new FontPickerPreferenceController(context, lifecycle));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@@ -161,138 +104,7 @@ public class ThemeSettings extends DashboardFragment implements OnPreferenceChan
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
final Resources res = getResources();
|
||||
mContext = getActivity();
|
||||
|
||||
mIntentFilter = new IntentFilter();
|
||||
mIntentFilter.addAction("com.android.server.ACTION_FONT_CHANGED");
|
||||
|
||||
mHideNotch = (SystemSettingSwitchPreference) prefScreen.findPreference(HIDE_NOTCH);
|
||||
boolean mHideNotchSupported = res.getBoolean(
|
||||
com.android.internal.R.bool.config_showHideNotchSettings);
|
||||
if (!mHideNotchSupported) {
|
||||
prefScreen.removePreference(mHideNotch);
|
||||
}
|
||||
|
||||
mSwitchStyle = (SystemSettingListPreference)findPreference(SWITCH_STYLE);
|
||||
int switchStyle = Settings.System.getInt(resolver,Settings.System.SWITCH_STYLE, 2);
|
||||
int switchIndex = mSwitchStyle.findIndexOfValue(String.valueOf(switchStyle));
|
||||
mSwitchStyle.setValueIndex(switchIndex >= 0 ? switchIndex : 0);
|
||||
mSwitchStyle.setSummary(mSwitchStyle.getEntry());
|
||||
mSwitchStyle.setOnPreferenceChangeListener(this);
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
mPanelBg = (ListPreference) findPreference(PREF_PANEL_BG);
|
||||
int mPanelValue = getOverlayPosition(ThemesUtils.PANEL_BG_STYLE);
|
||||
if (mPanelValue != -1) {
|
||||
mPanelBg.setValue(String.valueOf(mPanelValue + 2));
|
||||
} else {
|
||||
mPanelBg.setValue("1");
|
||||
}
|
||||
mPanelBg.setSummary(mPanelBg.getEntry());
|
||||
mPanelBg.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);
|
||||
|
||||
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);
|
||||
|
||||
mQsPanelColor = (ColorPickerPreference)findPreference(QS_PANEL_COLOR);
|
||||
mQsPanelColor.setOnPreferenceChangeListener(this);
|
||||
int intColor = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.QS_PANEL_BG_COLOR, DEFAULT_QS_PANEL_COLOR, UserHandle.USER_CURRENT);
|
||||
String hexColor = String.format("#%08x", (0xFFFFFFFF & intColor));
|
||||
mQsPanelColor.setSummary(hexColor);
|
||||
mQsPanelColor.setNewPreviewColor(intColor);
|
||||
|
||||
mUiModeManager = getContext().getSystemService(UiModeManager.class);
|
||||
|
||||
mOverlayService = IOverlayManager.Stub
|
||||
.asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE));
|
||||
|
||||
rgbAccentPickerDark = (ColorPickerPreference) findPreference(PREF_RGB_ACCENT_PICKER_DARK);
|
||||
String colorValDark = Settings.Secure.getStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCENT_DARK, UserHandle.USER_CURRENT);
|
||||
int colorDark = (colorValDark == null)
|
||||
? DEFAULT
|
||||
: Color.parseColor("#" + colorValDark);
|
||||
rgbAccentPickerDark.setNewPreviewColor(colorDark);
|
||||
rgbAccentPickerDark.setOnPreferenceChangeListener(this);
|
||||
setSystemSliderPref();
|
||||
setupNavbarSwitchPref();
|
||||
}
|
||||
|
||||
public String getPreferenceKey() {
|
||||
return QS_PANEL_COLOR;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
@@ -301,228 +113,7 @@ public class ThemeSettings extends DashboardFragment implements OnPreferenceChan
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == rgbAccentPickerDark) {
|
||||
int colorDark = (Integer) objValue;
|
||||
String hexColor = String.format("%08X", (0xFFFFFFFF & colorDark));
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCENT_DARK,
|
||||
hexColor, UserHandle.USER_CURRENT);
|
||||
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 == mPanelBg) {
|
||||
String panelbg = (String) objValue;
|
||||
int panelBgValue = Integer.parseInt(panelbg);
|
||||
mPanelBg.setValue(String.valueOf(panelBgValue));
|
||||
String overlayName = getOverlayName(ThemesUtils.PANEL_BG_STYLE);
|
||||
if (overlayName != null) {
|
||||
handleOverlays(overlayName, false, mOverlayService);
|
||||
}
|
||||
if (panelBgValue > 1) {
|
||||
CherishUtils.showSystemUiRestartDialog(getContext());
|
||||
handleOverlays(ThemesUtils.PANEL_BG_STYLE[panelBgValue -2],
|
||||
true, mOverlayService);
|
||||
|
||||
}
|
||||
mPanelBg.setSummary(mPanelBg.getEntry());
|
||||
} 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]);
|
||||
}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 == mSystemSliderStyle) {
|
||||
String slider_style = (String) objValue;
|
||||
final Context context = getContext();
|
||||
switch (slider_style) {
|
||||
case "1":
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_DANIEL, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEMINII, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUND, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUNDSTROKE, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMESTROKE, false, mOverlayService);
|
||||
break;
|
||||
case "2":
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_DANIEL, true, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEMINII, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUND, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUNDSTROKE, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMESTROKE, false, mOverlayService);
|
||||
break;
|
||||
case "3":
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_DANIEL, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEMINII, true, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUND, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUNDSTROKE, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMESTROKE, false, mOverlayService);
|
||||
break;
|
||||
case "4":
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_DANIEL, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEMINII, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUND, true, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUNDSTROKE, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMESTROKE, false, mOverlayService);
|
||||
break;
|
||||
case "5":
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_DANIEL, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEMINII, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUND, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUNDSTROKE, true, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMESTROKE, false, mOverlayService);
|
||||
break;
|
||||
case "6":
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_DANIEL, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEMINII, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUND, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMEROUNDSTROKE, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.SYSTEM_SLIDER_MEMESTROKE, true, mOverlayService);
|
||||
break;
|
||||
}
|
||||
} 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 == mQsPanelColor) {
|
||||
String hex = ColorPickerPreference.convertToARGB(
|
||||
Integer.valueOf(String.valueOf(objValue)));
|
||||
preference.setSummary(hex);
|
||||
int intHex = ColorPickerPreference.convertToColorInt(hex);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.QS_PANEL_BG_COLOR, intHex, UserHandle.USER_CURRENT);
|
||||
} else if (preference == mGesbar){
|
||||
String nbSwitch = (String) objValue;
|
||||
final Context context = getContext();
|
||||
switch (nbSwitch) {
|
||||
case "1":
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_ORCD, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_OPRD, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_PURP, false, mOverlayService);
|
||||
break;
|
||||
case "2":
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_ORCD, true, mOverlayService);
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_OPRD, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_PURP, false, mOverlayService);
|
||||
break;
|
||||
case "3":
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_ORCD, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_OPRD, true, mOverlayService);
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_PURP, false, mOverlayService);
|
||||
break;
|
||||
case "4":
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_ORCD, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_OPRD, false, mOverlayService);
|
||||
handleOverlays(ThemesUtils.NAVBAR_COLOR_PURP, true, mOverlayService);
|
||||
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) {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setSystemSliderPref() {
|
||||
mSystemSliderStyle = (ListPreference) findPreference(SYSTEM_SLIDER_STYLE);
|
||||
mSystemSliderStyle.setOnPreferenceChangeListener(this);
|
||||
if (CherishUtils.isThemeEnabled("com.android.system.slider.memestroke")) {
|
||||
mSystemSliderStyle.setValue("6");
|
||||
} else if (CherishUtils.isThemeEnabled("com.android.system.slider.memeroundstroke")) {
|
||||
mSystemSliderStyle.setValue("5");
|
||||
} else if (CherishUtils.isThemeEnabled("com.android.system.slider.memeround")) {
|
||||
mSystemSliderStyle.setValue("4");
|
||||
} else if (CherishUtils.isThemeEnabled("com.android.system.slider.mememini")) {
|
||||
mSystemSliderStyle.setValue("3");
|
||||
} else if (CherishUtils.isThemeEnabled("com.android.system.slider.daniel")) {
|
||||
mSystemSliderStyle.setValue("2");
|
||||
} else {
|
||||
mSystemSliderStyle.setValue("1");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupNavbarSwitchPref() {
|
||||
mGesbar = (ListPreference) findPreference(PREF_NB_COLOR);
|
||||
mGesbar.setOnPreferenceChangeListener(this);
|
||||
if (CherishUtils.isNavbarColor("com.gnonymous.gvisualmod.pgm_purp")){
|
||||
mGesbar.setValue("4");
|
||||
} else if (CherishUtils.isNavbarColor("com.gnonymous.gvisualmod.pgm_oprd")){
|
||||
mGesbar.setValue("3");
|
||||
} else if (CherishUtils.isNavbarColor("com.gnonymous.gvisualmod.pgm_orcd")){
|
||||
mGesbar.setValue("2");
|
||||
}
|
||||
else{
|
||||
mGesbar.setValue("1");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.add(0, MENU_RESET, 0, R.string.reset)
|
||||
.setIcon(R.drawable.ic_menu_reset)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_RESET:
|
||||
resetToDefault();
|
||||
return true;
|
||||
default:
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetToDefault() {
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
|
||||
alertDialog.setTitle(R.string.theme_option_reset_title);
|
||||
alertDialog.setMessage(R.string.theme_option_reset_message);
|
||||
alertDialog.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
resetValues();
|
||||
}
|
||||
});
|
||||
alertDialog.setNegativeButton(R.string.cancel, null);
|
||||
alertDialog.create().show();
|
||||
}
|
||||
|
||||
private void resetValues() {
|
||||
final Context context = getContext();
|
||||
rgbAccentPickerDark = (ColorPickerPreference) findPreference(PREF_RGB_ACCENT_PICKER_DARK);
|
||||
rgbAccentPickerDark.setNewPreviewColor(DEFAULT);
|
||||
}
|
||||
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -530,21 +121,6 @@ private int getOverlayPosition(String[] overlays) {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
final Context context = getActivity();
|
||||
context.registerReceiver(mIntentReceiver, mIntentFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
final Context context = getActivity();
|
||||
context.unregisterReceiver(mIntentReceiver);
|
||||
mFontPickerPreference.stopProgress();
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
@@ -1,231 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 AospExtended ROM 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.ActivityManagerNative;
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManagerGlobal;
|
||||
import android.view.IWindowManager;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
import com.cherish.settings.preferences.SystemSettingListPreference;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class Traffic extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
|
||||
|
||||
private static final String NETWORK_TRAFFIC_FONT_SIZE = "network_traffic_font_size";
|
||||
|
||||
private ListPreference mNetTrafficLocation;
|
||||
private ListPreference mNetTrafficType;
|
||||
private ListPreference mNetTrafficLayout;
|
||||
private CustomSeekBarPreference mNetTrafficSize;
|
||||
private CustomSeekBarPreference mThreshold;
|
||||
private SystemSettingSwitchPreference mShowArrows;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.traffic);
|
||||
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
final PreferenceScreen prefSet = getPreferenceScreen();
|
||||
|
||||
int NetTrafficSize = Settings.System.getInt(resolver,
|
||||
Settings.System.NETWORK_TRAFFIC_FONT_SIZE, 42);
|
||||
mNetTrafficSize = (CustomSeekBarPreference) findPreference(NETWORK_TRAFFIC_FONT_SIZE);
|
||||
mNetTrafficSize.setValue(NetTrafficSize / 1);
|
||||
mNetTrafficSize.setOnPreferenceChangeListener(this);
|
||||
|
||||
int type = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.NETWORK_TRAFFIC_TYPE, 0, UserHandle.USER_CURRENT);
|
||||
mNetTrafficType = (ListPreference) findPreference("network_traffic_type");
|
||||
mNetTrafficType.setValue(String.valueOf(type));
|
||||
mNetTrafficType.setSummary(mNetTrafficType.getEntry());
|
||||
mNetTrafficType.setOnPreferenceChangeListener(this);
|
||||
|
||||
int netlayout = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.NETWORK_TRAFFIC_LAYOUT, 0, UserHandle.USER_CURRENT);
|
||||
mNetTrafficLayout = (ListPreference) findPreference("network_traffic_layout");
|
||||
mNetTrafficLayout.setValue(String.valueOf(netlayout));
|
||||
mNetTrafficLayout.setSummary(mNetTrafficLayout.getEntry());
|
||||
mNetTrafficLayout.setOnPreferenceChangeListener(this);
|
||||
|
||||
mNetTrafficLocation = (ListPreference) findPreference("network_traffic_location");
|
||||
int location = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.NETWORK_TRAFFIC_VIEW_LOCATION, 0, UserHandle.USER_CURRENT);
|
||||
mNetTrafficLocation.setOnPreferenceChangeListener(this);
|
||||
|
||||
int trafvalue = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, 1, UserHandle.USER_CURRENT);
|
||||
mThreshold = (CustomSeekBarPreference) findPreference("network_traffic_autohide_threshold");
|
||||
mThreshold.setValue(trafvalue);
|
||||
mThreshold.setOnPreferenceChangeListener(this);
|
||||
mShowArrows = (SystemSettingSwitchPreference) findPreference("network_traffic_arrow");
|
||||
|
||||
int netMonitorEnabled = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.NETWORK_TRAFFIC_STATE, 0, UserHandle.USER_CURRENT);
|
||||
if (netMonitorEnabled == 1) {
|
||||
mNetTrafficLocation.setValue(String.valueOf(location+1));
|
||||
updateTrafficLocation(location+1);
|
||||
} else {
|
||||
mNetTrafficLocation.setValue("0");
|
||||
updateTrafficLocation(0);
|
||||
}
|
||||
mNetTrafficLocation.setSummary(mNetTrafficLocation.getEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
if (preference == mNetTrafficLocation) {
|
||||
int location = Integer.valueOf((String) objValue);
|
||||
int index = mNetTrafficLocation.findIndexOfValue((String) objValue);
|
||||
mNetTrafficLocation.setSummary(mNetTrafficLocation.getEntries()[index]);
|
||||
if (location > 0) {
|
||||
// Convert the selected location mode from our list {0,1,2} and store it to "view location" setting: 0=sb; 1=expanded sb
|
||||
Settings.System.putIntForUser(getActivity().getContentResolver(),
|
||||
Settings.System.NETWORK_TRAFFIC_VIEW_LOCATION, location-1, UserHandle.USER_CURRENT);
|
||||
// And also enable the net monitor
|
||||
Settings.System.putIntForUser(getActivity().getContentResolver(),
|
||||
Settings.System.NETWORK_TRAFFIC_STATE, 1, UserHandle.USER_CURRENT);
|
||||
updateTrafficLocation(location+1);
|
||||
} else { // Disable net monitor completely
|
||||
Settings.System.putIntForUser(getActivity().getContentResolver(),
|
||||
Settings.System.NETWORK_TRAFFIC_STATE, 0, UserHandle.USER_CURRENT);
|
||||
updateTrafficLocation(location);
|
||||
}
|
||||
return true;
|
||||
} else if (preference == mNetTrafficLayout) {
|
||||
int val = Integer.valueOf((String) objValue);
|
||||
Settings.System.putIntForUser(getContentResolver(),
|
||||
Settings.System.NETWORK_TRAFFIC_LAYOUT, val,
|
||||
UserHandle.USER_CURRENT);
|
||||
int index = mNetTrafficLayout.findIndexOfValue((String) objValue);
|
||||
mNetTrafficLayout.setSummary(mNetTrafficLayout.getEntries()[index]);
|
||||
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 == mNetTrafficType) {
|
||||
int val = Integer.valueOf((String) objValue);
|
||||
Settings.System.putIntForUser(getContentResolver(),
|
||||
Settings.System.NETWORK_TRAFFIC_TYPE, val,
|
||||
UserHandle.USER_CURRENT);
|
||||
int index = mNetTrafficType.findIndexOfValue((String) objValue);
|
||||
mNetTrafficType.setSummary(mNetTrafficType.getEntries()[index]);
|
||||
return true;
|
||||
} else if (preference == mNetTrafficSize) {
|
||||
int width = ((Integer)objValue).intValue();
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.NETWORK_TRAFFIC_FONT_SIZE, width);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updateTrafficLocation(int location) {
|
||||
switch(location){
|
||||
case 0:
|
||||
mThreshold.setEnabled(false);
|
||||
mShowArrows.setEnabled(false);
|
||||
mNetTrafficType.setEnabled(false);
|
||||
mNetTrafficSize.setEnabled(false);
|
||||
mNetTrafficLayout.setEnabled(false);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
mThreshold.setEnabled(true);
|
||||
mShowArrows.setEnabled(true);
|
||||
mNetTrafficType.setEnabled(true);
|
||||
mNetTrafficSize.setEnabled(true);
|
||||
mNetTrafficLayout.setEnabled(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.traffic;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -23,40 +23,15 @@ import java.util.List;
|
||||
public class VolumeRockerSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String VOLUME_KEY_CURSOR_CONTROL = "volume_key_cursor_control";
|
||||
|
||||
private ListPreference mVolumeKeyCursorControl;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings_volume);
|
||||
|
||||
// volume key cursor control
|
||||
mVolumeKeyCursorControl = (ListPreference) findPreference(VOLUME_KEY_CURSOR_CONTROL);
|
||||
if (mVolumeKeyCursorControl != null) {
|
||||
mVolumeKeyCursorControl.setOnPreferenceChangeListener(this);
|
||||
int volumeRockerCursorControl = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.VOLUME_KEY_CURSOR_CONTROL, 0);
|
||||
mVolumeKeyCursorControl.setValue(Integer.toString(volumeRockerCursorControl));
|
||||
mVolumeKeyCursorControl.setSummary(mVolumeKeyCursorControl.getEntry());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
if (preference == mVolumeKeyCursorControl) {
|
||||
String volumeKeyCursorControl = (String) value;
|
||||
int volumeKeyCursorControlValue = Integer.parseInt(volumeKeyCursorControl);
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.VOLUME_KEY_CURSOR_CONTROL, volumeKeyCursorControlValue);
|
||||
int volumeKeyCursorControlIndex = mVolumeKeyCursorControl
|
||||
.findIndexOfValue(volumeKeyCursorControl);
|
||||
mVolumeKeyCursorControl
|
||||
.setSummary(mVolumeKeyCursorControl.getEntries()[volumeKeyCursorControlIndex]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,302 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The LiquidSmooth Project
|
||||
* (C) 2018 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.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.os.UserHandle;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
public class WakeLockBlocker extends SettingsPreferenceFragment {
|
||||
|
||||
private static final String TAG = "WakeLockBlocker";
|
||||
|
||||
private Switch mBlockerEnabled;
|
||||
private ListView mWakeLockList;
|
||||
private List<String> mSeenWakeLocks;
|
||||
private List<String> mBlockedWakeLocks;
|
||||
private LayoutInflater mInflater;
|
||||
private Map<String, Boolean> mWakeLockState;
|
||||
private WakeLockListAdapter mListAdapter;
|
||||
private boolean mEnabled;
|
||||
private AlertDialog mAlertDialog;
|
||||
private boolean mAlertShown = false;
|
||||
private TextView mWakeLockListHeader;
|
||||
|
||||
private static final int MENU_RELOAD = Menu.FIRST;
|
||||
private static final int MENU_SAVE = Menu.FIRST + 1;
|
||||
|
||||
public class WakeLockListAdapter extends ArrayAdapter<String> {
|
||||
|
||||
public WakeLockListAdapter(Context context, int resource, List<String> values) {
|
||||
super(context, R.layout.wakelock_item, resource, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View rowView = mInflater.inflate(R.layout.wakelock_item, parent, false);
|
||||
final CheckBox check = (CheckBox)rowView.findViewById(R.id.wakelock_blocked);
|
||||
check.setText(mSeenWakeLocks.get(position));
|
||||
|
||||
Boolean checked = mWakeLockState.get(check.getText().toString());
|
||||
check.setChecked(checked.booleanValue());
|
||||
|
||||
if(checked.booleanValue()) {
|
||||
check.setTextColor(getResources().getColor(android.R.color.holo_red_light));
|
||||
}
|
||||
|
||||
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton v, boolean checked) {
|
||||
mWakeLockState.put(v.getText().toString(), new Boolean(checked));
|
||||
if(checked) {
|
||||
check.setTextColor(getResources().getColor(android.R.color.holo_red_light));
|
||||
mListAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
check.setTextColor(getResources().getColor(android.R.color.primary_text_dark));
|
||||
mListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
return rowView;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.d(TAG, "running");
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
mInflater = inflater;
|
||||
setHasOptionsMenu(true);
|
||||
return inflater.inflate(R.layout.wakelock_blocker, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
mWakeLockState = new HashMap<String, Boolean>();
|
||||
updateSeenWakeLocksList();
|
||||
updateBlockedWakeLocksList();
|
||||
|
||||
mBlockerEnabled = (Switch) getActivity().findViewById(
|
||||
R.id.wakelock_blocker_switch);
|
||||
mWakeLockList = (ListView) getActivity().findViewById(
|
||||
R.id.wakelock_list);
|
||||
mWakeLockListHeader = (TextView) getActivity().findViewById(
|
||||
R.id.wakelock_list_header);
|
||||
|
||||
mListAdapter = new WakeLockListAdapter(getActivity(), android.R.layout.simple_list_item_multiple_choice,
|
||||
mSeenWakeLocks);
|
||||
mWakeLockList.setAdapter(mListAdapter);
|
||||
|
||||
updateSwitches();
|
||||
|
||||
// after updateSwitches!!!
|
||||
mBlockerEnabled
|
||||
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton v, boolean checked) {
|
||||
if (checked && isFirstEnable() && !mAlertShown) {
|
||||
showAlert();
|
||||
mAlertShown = true;
|
||||
}
|
||||
|
||||
Settings.Global.putInt(getActivity().getContentResolver(),
|
||||
Settings.Global.WAKELOCK_BLOCKING_ENABLED,
|
||||
checked ? 1 : 0);
|
||||
|
||||
updateSwitches();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isFirstEnable() {
|
||||
return Settings.Global.getString(getActivity().getContentResolver(),
|
||||
Settings.Global.WAKELOCK_BLOCKING_LIST) == null;
|
||||
}
|
||||
|
||||
private void updateSwitches() {
|
||||
mBlockerEnabled.setChecked(Settings.Global.getInt(getActivity().getContentResolver(),
|
||||
Settings.Global.WAKELOCK_BLOCKING_ENABLED, 0) == 1);
|
||||
|
||||
|
||||
mEnabled = mBlockerEnabled.isChecked();
|
||||
//mWakeLockList.setEnabled(mEnabled);
|
||||
mWakeLockList.setVisibility(mEnabled ?View.VISIBLE : View.INVISIBLE);
|
||||
mWakeLockListHeader.setVisibility(mEnabled ?View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
|
||||
private void updateSeenWakeLocksList() {
|
||||
PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
|
||||
Log.d(TAG, pm.getSeenWakeLocks());
|
||||
|
||||
String seenWakeLocks = pm.getSeenWakeLocks();
|
||||
mSeenWakeLocks = new ArrayList<String>();
|
||||
|
||||
if (seenWakeLocks!=null && seenWakeLocks.length()!=0) {
|
||||
String[] parts = seenWakeLocks.split("\\|");
|
||||
for(int i = 0; i < parts.length; i++) {
|
||||
mSeenWakeLocks.add(parts[i]);
|
||||
mWakeLockState.put(parts[i], new Boolean(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBlockedWakeLocksList() {
|
||||
String blockedWakelockList = Settings.Global.getString(getActivity().getContentResolver(),
|
||||
Settings.Global.WAKELOCK_BLOCKING_LIST);
|
||||
|
||||
mBlockedWakeLocks = new ArrayList<String>();
|
||||
|
||||
if (blockedWakelockList!=null && blockedWakelockList.length()!=0) {
|
||||
String[] parts = blockedWakelockList.split("\\|");
|
||||
for(int i = 0; i < parts.length; i++) {
|
||||
mBlockedWakeLocks.add(parts[i]);
|
||||
|
||||
// add all blocked but not seen so far
|
||||
if(!mSeenWakeLocks.contains(parts[i])) {
|
||||
mSeenWakeLocks.add(parts[i]);
|
||||
}
|
||||
mWakeLockState.put(parts[i], new Boolean(true));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(mSeenWakeLocks);
|
||||
}
|
||||
|
||||
private void save() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Iterator<String> nextState = mWakeLockState.keySet().iterator();
|
||||
while(nextState.hasNext()) {
|
||||
String name = nextState.next();
|
||||
Boolean state=mWakeLockState.get(name);
|
||||
if(state.booleanValue()) {
|
||||
buffer.append(name + "|");
|
||||
}
|
||||
}
|
||||
if(buffer.length() > 0) {
|
||||
buffer.deleteCharAt(buffer.length() - 1);
|
||||
}
|
||||
Log.d(TAG, buffer.toString());
|
||||
Settings.Global.putString(getActivity().getContentResolver(),
|
||||
Settings.Global.WAKELOCK_BLOCKING_LIST, buffer.toString());
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
mWakeLockState = new HashMap<String, Boolean>();
|
||||
updateSeenWakeLocksList();
|
||||
updateBlockedWakeLocksList();
|
||||
|
||||
mListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.add(0, MENU_RELOAD, 0, R.string.wakelock_blocker_reload)
|
||||
.setIcon(com.android.internal.R.drawable.ic_menu_refresh)
|
||||
.setAlphabeticShortcut('r')
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
|
||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
menu.add(0, MENU_SAVE, 0, R.string.wakelock_blocker_save)
|
||||
.setIcon(R.drawable.ic_wakelockblocker_save)
|
||||
.setAlphabeticShortcut('s')
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
|
||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_RELOAD:
|
||||
if (mEnabled) {
|
||||
reload();
|
||||
}
|
||||
return true;
|
||||
case MENU_SAVE:
|
||||
if (mEnabled) {
|
||||
save();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset(Context mContext) {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.Global.putInt(resolver,
|
||||
Settings.Global.WAKELOCK_BLOCKING_ENABLED, 0);
|
||||
}
|
||||
|
||||
private void showAlert() {
|
||||
/* Display the warning dialog */
|
||||
mAlertDialog = new AlertDialog.Builder(getActivity()).create();
|
||||
mAlertDialog.setTitle(R.string.wakelock_blocker_warning_title);
|
||||
mAlertDialog.setMessage(getResources().getString(R.string.wakelock_blocker_warning));
|
||||
mAlertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
|
||||
getResources().getString(com.android.internal.R.string.ok),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
mAlertDialog.show();
|
||||
}
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 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.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.cherish.settings.preferences.SystemSettingListPreference;
|
||||
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class StatusbarBatterySettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String QS_BATTERY_PERCENTAGE = "qs_battery_percentage";
|
||||
private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
|
||||
private static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
|
||||
private static final String TEXT_CHARGING_SYMBOL = "text_charging_symbol";
|
||||
|
||||
private static final String LEFT_BATTERY_TEXT = "do_left_battery_text";
|
||||
|
||||
private ListPreference mBatteryPercent;
|
||||
private ListPreference mBatteryStyle;
|
||||
private SystemSettingListPreference mChargingSymbol;
|
||||
private SwitchPreference mQsBatteryPercent;
|
||||
private int mBatteryPercentValue;
|
||||
|
||||
private SystemSettingSwitchPreference mLeftBatteryText;
|
||||
|
||||
private static final int BATTERY_STYLE_PORTRAIT = 0;
|
||||
private static final int BATTERY_STYLE_TEXT = 6;
|
||||
private static final int BATTERY_STYLE_HIDDEN = 7;
|
||||
private static final int BATTERY_PERCENT_HIDDEN = 0;
|
||||
//private static final int BATTERY_PERCENT_SHOW_INSIDE = 1;
|
||||
//private static final int BATTERY_PERCENT_SHOW_OUTSIDE = 2;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.cherish_settings_statusbar_battery);
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
int batterystyle = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_PORTRAIT, UserHandle.USER_CURRENT);
|
||||
mBatteryStyle = findPreference("status_bar_battery_style");
|
||||
mBatteryStyle.setValue(String.valueOf(batterystyle));
|
||||
mBatteryStyle.setSummary(mBatteryStyle.getEntry());
|
||||
mBatteryStyle.setOnPreferenceChangeListener(this);
|
||||
|
||||
mLeftBatteryText = (SystemSettingSwitchPreference) findPreference(LEFT_BATTERY_TEXT);
|
||||
mLeftBatteryText.setChecked((Settings.System.getInt(resolver,
|
||||
Settings.System.DO_LEFT_BATTERY_TEXT, 0) == 1));
|
||||
mLeftBatteryText.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryPercentValue = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, BATTERY_PERCENT_HIDDEN, UserHandle.USER_CURRENT);
|
||||
mBatteryPercent = (ListPreference) findPreference("status_bar_show_battery_percent");
|
||||
mBatteryPercent.setValue(String.valueOf(mBatteryPercentValue));
|
||||
mBatteryPercent.setSummary(mBatteryPercent.getEntry());
|
||||
mBatteryPercent.setOnPreferenceChangeListener(this);
|
||||
mBatteryPercent.setEnabled(
|
||||
batterystyle != BATTERY_STYLE_TEXT && batterystyle != BATTERY_STYLE_HIDDEN);
|
||||
|
||||
mChargingSymbol = (SystemSettingListPreference) findPreference("text_charging_symbol");
|
||||
mChargingSymbol.setEnabled(
|
||||
batterystyle != BATTERY_STYLE_PORTRAIT && batterystyle != BATTERY_STYLE_HIDDEN);
|
||||
|
||||
mQsBatteryPercent = (SwitchPreference) findPreference(QS_BATTERY_PERCENTAGE);
|
||||
mQsBatteryPercent.setChecked((Settings.System.getInt(
|
||||
getActivity().getApplicationContext().getContentResolver(),
|
||||
Settings.System.QS_SHOW_BATTERY_PERCENT, 0) == 1));
|
||||
mQsBatteryPercent.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mBatteryStyle) {
|
||||
int batterystyle = Integer.parseInt((String) newValue);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_BATTERY_STYLE, batterystyle,
|
||||
UserHandle.USER_CURRENT);
|
||||
int index = mBatteryStyle.findIndexOfValue((String) newValue);
|
||||
mBatteryStyle.setSummary(mBatteryStyle.getEntries()[index]);
|
||||
mBatteryPercent.setEnabled(
|
||||
batterystyle != BATTERY_STYLE_TEXT && batterystyle != BATTERY_STYLE_HIDDEN);
|
||||
mLeftBatteryText.setEnabled(
|
||||
batterystyle != BATTERY_STYLE_TEXT && batterystyle != BATTERY_STYLE_HIDDEN);
|
||||
mChargingSymbol.setEnabled(
|
||||
batterystyle != BATTERY_STYLE_PORTRAIT && batterystyle != BATTERY_STYLE_HIDDEN);
|
||||
return true;
|
||||
} else if (preference == mBatteryPercent) {
|
||||
mBatteryPercentValue = Integer.parseInt((String) newValue);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, mBatteryPercentValue,
|
||||
UserHandle.USER_CURRENT);
|
||||
int index = mBatteryPercent.findIndexOfValue((String) newValue);
|
||||
mBatteryPercent.setSummary(mBatteryPercent.getEntries()[index]);
|
||||
return true;
|
||||
} else if (preference == mQsBatteryPercent) {
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.QS_SHOW_BATTERY_PERCENT,
|
||||
(Boolean) newValue ? 1 : 0);
|
||||
return true;
|
||||
} else if (preference == mLeftBatteryText) {
|
||||
boolean value = (Boolean) newValue;
|
||||
Settings.System.putInt(resolver,
|
||||
Settings.System.DO_LEFT_BATTERY_TEXT, value ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.cherish_settings_statusbar_battery;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.cherish.settings.fragments.gaming;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import android.provider.Settings;
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
public class DanmakuSettings extends SettingsPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings_gaming_danmaku);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.cherish.settings.fragments.gaming;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import android.provider.Settings;
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
public class QuickStartAppSettings extends SettingsPreferenceFragment implements
|
||||
OnPreferenceChangeListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.cherish_settings_gaming_qs_app);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 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.lockscreen;
|
||||
|
||||
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.MetricsEvent;
|
||||
|
||||
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_fod_icon_picker);
|
||||
|
||||
getActivity().getActionBar().setTitle(R.string.fod_icon_picker_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 AOSiP
|
||||
*
|
||||
* 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.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class AppListPreference extends Preference {
|
||||
|
||||
public AppListPreference(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
public AppListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
public AppListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public AppListPreference(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setLayoutResource(R.layout.app_list_preference_view);
|
||||
}
|
||||
}
|
||||
@@ -1,439 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 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.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.provider.Settings;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import androidx.core.content.res.TypedArrayUtils;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
public class FODIconPicker extends LayoutPreference {
|
||||
|
||||
private boolean mAllowDividerAbove;
|
||||
private boolean mAllowDividerBelow;
|
||||
|
||||
private View mRootView;
|
||||
|
||||
private static ImageButton Button0;
|
||||
private static ImageButton Button1;
|
||||
private static ImageButton Button2;
|
||||
private static ImageButton Button3;
|
||||
private static ImageButton Button4;
|
||||
private static ImageButton Button5;
|
||||
private static ImageButton Button6;
|
||||
private static ImageButton Button7;
|
||||
private static ImageButton Button8;
|
||||
private static ImageButton Button9;
|
||||
private static ImageButton Button10;
|
||||
private static ImageButton Button11;
|
||||
private static ImageButton Button12;
|
||||
private static ImageButton Button13;
|
||||
private static ImageButton Button14;
|
||||
private static ImageButton Button15;
|
||||
private static ImageButton Button16;
|
||||
private static ImageButton Button17;
|
||||
private static ImageButton Button18;
|
||||
private static ImageButton Button19;
|
||||
private static ImageButton Button20;
|
||||
private static ImageButton Button21;
|
||||
private static ImageButton Button22;
|
||||
private static ImageButton Button23;
|
||||
private static ImageButton Button24;
|
||||
private static ImageButton Button25;
|
||||
private static ImageButton Button26;
|
||||
private static ImageButton Button27;
|
||||
|
||||
private static final String TAG = "FODIconPicker";
|
||||
|
||||
public FODIconPicker(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0 /* defStyleAttr */);
|
||||
}
|
||||
|
||||
public FODIconPicker(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Preference);
|
||||
mAllowDividerAbove = TypedArrayUtils.getBoolean(a, R.styleable.Preference_allowDividerAbove,
|
||||
R.styleable.Preference_allowDividerAbove, false);
|
||||
mAllowDividerBelow = TypedArrayUtils.getBoolean(a, R.styleable.Preference_allowDividerBelow,
|
||||
R.styleable.Preference_allowDividerBelow, false);
|
||||
a.recycle();
|
||||
|
||||
a = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.Preference, defStyleAttr, 0);
|
||||
int layoutResource = a.getResourceId(R.styleable.Preference_android_layout, 0);
|
||||
if (layoutResource == 0) {
|
||||
throw new IllegalArgumentException("LayoutPreference requires a layout to be defined");
|
||||
}
|
||||
a.recycle();
|
||||
|
||||
// Need to create view now so that findViewById can be called immediately.
|
||||
final View view = LayoutInflater.from(getContext())
|
||||
.inflate(layoutResource, null, false);
|
||||
setView(view, context);
|
||||
}
|
||||
|
||||
private void setView(View view, Context context) {
|
||||
setLayoutResource(R.layout.layout_preference_frame);
|
||||
mRootView = view;
|
||||
setShouldDisableView(false);
|
||||
Button0 = findViewById(R.id.fodicon0_button);
|
||||
Button1 = findViewById(R.id.fodicon1_button);
|
||||
Button2 = findViewById(R.id.fodicon2_button);
|
||||
Button3 = findViewById(R.id.fodicon3_button);
|
||||
Button4 = findViewById(R.id.fodicon4_button);
|
||||
Button5 = findViewById(R.id.fodicon5_button);
|
||||
Button6 = findViewById(R.id.fodicon6_button);
|
||||
Button7 = findViewById(R.id.fodicon7_button);
|
||||
Button8 = findViewById(R.id.fodicon8_button);
|
||||
Button9 = findViewById(R.id.fodicon9_button);
|
||||
Button10 = findViewById(R.id.fodicon10_button);
|
||||
Button11 = findViewById(R.id.fodicon11_button);
|
||||
Button12 = findViewById(R.id.fodicon12_button);
|
||||
Button13 = findViewById(R.id.fodicon13_button);
|
||||
Button14 = findViewById(R.id.fodicon14_button);
|
||||
Button15 = findViewById(R.id.fodicon15_button);
|
||||
Button16 = findViewById(R.id.fodicon16_button);
|
||||
Button17 = findViewById(R.id.fodicon17_button);
|
||||
Button18 = findViewById(R.id.fodicon18_button);
|
||||
Button19 = findViewById(R.id.fodicon19_button);
|
||||
Button20 = findViewById(R.id.fodicon20_button);
|
||||
Button21 = findViewById(R.id.fodicon21_button);
|
||||
Button22 = findViewById(R.id.fodicon22_button);
|
||||
Button23 = findViewById(R.id.fodicon23_button);
|
||||
Button24 = findViewById(R.id.fodicon24_button);
|
||||
Button25 = findViewById(R.id.fodicon25_button);
|
||||
Button26 = findViewById(R.id.fodicon26_button);
|
||||
Button27 = findViewById(R.id.fodicon27_button);
|
||||
|
||||
int defaultfodicon = Settings.System.getInt(
|
||||
context.getContentResolver(), Settings.System.FOD_ICON, 0);
|
||||
if (defaultfodicon==0) {
|
||||
updateHighlightedItem(Button0, context);
|
||||
} else if (defaultfodicon == 1) {
|
||||
updateHighlightedItem(Button1, context);
|
||||
} else if (defaultfodicon == 2) {
|
||||
updateHighlightedItem(Button2, context);
|
||||
} else if (defaultfodicon == 3) {
|
||||
updateHighlightedItem(Button3, context);
|
||||
} else if (defaultfodicon == 4) {
|
||||
updateHighlightedItem(Button4, context);
|
||||
} else if (defaultfodicon == 5) {
|
||||
updateHighlightedItem(Button5, context);
|
||||
} else if (defaultfodicon == 6) {
|
||||
updateHighlightedItem(Button6, context);
|
||||
} else if (defaultfodicon == 7) {
|
||||
updateHighlightedItem(Button7, context);
|
||||
} else if (defaultfodicon == 8) {
|
||||
updateHighlightedItem(Button8, context);
|
||||
} else if (defaultfodicon == 9) {
|
||||
updateHighlightedItem(Button9, context);
|
||||
} else if (defaultfodicon == 10) {
|
||||
updateHighlightedItem(Button10, context);
|
||||
} else if (defaultfodicon == 11) {
|
||||
updateHighlightedItem(Button11, context);
|
||||
} else if (defaultfodicon == 12) {
|
||||
updateHighlightedItem(Button12, context);
|
||||
} else if (defaultfodicon == 13) {
|
||||
updateHighlightedItem(Button13, context);
|
||||
} else if (defaultfodicon == 14) {
|
||||
updateHighlightedItem(Button14, context);
|
||||
} else if (defaultfodicon == 15) {
|
||||
updateHighlightedItem(Button15, context);
|
||||
} else if (defaultfodicon == 16) {
|
||||
updateHighlightedItem(Button16, context);
|
||||
} else if (defaultfodicon == 17) {
|
||||
updateHighlightedItem(Button17, context);
|
||||
} else if (defaultfodicon == 18) {
|
||||
updateHighlightedItem(Button18, context);
|
||||
} else if (defaultfodicon == 19) {
|
||||
updateHighlightedItem(Button19, context);
|
||||
} else if (defaultfodicon == 20) {
|
||||
updateHighlightedItem(Button20, context);
|
||||
} else if (defaultfodicon == 21) {
|
||||
updateHighlightedItem(Button21, context);
|
||||
} else if (defaultfodicon == 22) {
|
||||
updateHighlightedItem(Button22, context);
|
||||
} else if (defaultfodicon == 23) {
|
||||
updateHighlightedItem(Button23, context);
|
||||
} else if (defaultfodicon == 24) {
|
||||
updateHighlightedItem(Button24, context);
|
||||
} else if (defaultfodicon == 25) {
|
||||
updateHighlightedItem(Button25, context);
|
||||
} else if (defaultfodicon == 26) {
|
||||
updateHighlightedItem(Button25, context);
|
||||
} else if (defaultfodicon == 27) {
|
||||
updateHighlightedItem(Button25, context);
|
||||
}
|
||||
|
||||
Button0.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(0, context);
|
||||
updateHighlightedItem(Button0, context);
|
||||
}
|
||||
});
|
||||
Button1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(1, context);
|
||||
updateHighlightedItem(Button1, context);
|
||||
}
|
||||
});
|
||||
Button2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(2, context);
|
||||
updateHighlightedItem(Button2, context);
|
||||
}
|
||||
});
|
||||
Button3.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(3, context);
|
||||
updateHighlightedItem(Button3, context);
|
||||
}
|
||||
});
|
||||
Button4.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(4, context);
|
||||
updateHighlightedItem(Button4, context);
|
||||
}
|
||||
});
|
||||
Button5.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(5, context);
|
||||
updateHighlightedItem(Button5, context);
|
||||
}
|
||||
});
|
||||
Button6.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(6, context);
|
||||
updateHighlightedItem(Button6, context);
|
||||
}
|
||||
});
|
||||
Button7.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(7, context);
|
||||
updateHighlightedItem(Button7, context);
|
||||
}
|
||||
});
|
||||
Button8.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(8, context);
|
||||
updateHighlightedItem(Button8, context);
|
||||
}
|
||||
});
|
||||
Button9.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(9, context);
|
||||
updateHighlightedItem(Button9, context);
|
||||
}
|
||||
});
|
||||
Button10.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(10, context);
|
||||
updateHighlightedItem(Button10, context);
|
||||
}
|
||||
});
|
||||
Button11.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(11, context);
|
||||
updateHighlightedItem(Button11, context);
|
||||
}
|
||||
});
|
||||
Button12.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(12, context);
|
||||
updateHighlightedItem(Button12, context);
|
||||
}
|
||||
});
|
||||
Button13.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(13, context);
|
||||
updateHighlightedItem(Button13, context);
|
||||
}
|
||||
});
|
||||
Button14.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(14, context);
|
||||
updateHighlightedItem(Button14, context);
|
||||
}
|
||||
});
|
||||
Button15.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(15, context);
|
||||
updateHighlightedItem(Button15, context);
|
||||
}
|
||||
});
|
||||
Button16.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(16, context);
|
||||
updateHighlightedItem(Button16, context);
|
||||
}
|
||||
});
|
||||
Button17.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(17, context);
|
||||
updateHighlightedItem(Button17, context);
|
||||
}
|
||||
});
|
||||
Button18.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(18, context);
|
||||
updateHighlightedItem(Button18, context);
|
||||
}
|
||||
});
|
||||
Button19.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(19, context);
|
||||
updateHighlightedItem(Button19, context);
|
||||
}
|
||||
});
|
||||
Button20.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(20, context);
|
||||
updateHighlightedItem(Button20, context);
|
||||
}
|
||||
});
|
||||
Button21.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(21, context);
|
||||
updateHighlightedItem(Button21, context);
|
||||
}
|
||||
});
|
||||
Button22.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(22, context);
|
||||
updateHighlightedItem(Button22, context);
|
||||
}
|
||||
});
|
||||
Button23.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(23, context);
|
||||
updateHighlightedItem(Button23, context);
|
||||
}
|
||||
});
|
||||
Button24.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(24, context);
|
||||
updateHighlightedItem(Button24, context);
|
||||
}
|
||||
});
|
||||
Button25.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(25, context);
|
||||
updateHighlightedItem(Button25, context);
|
||||
}
|
||||
});
|
||||
Button26.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(26, context);
|
||||
updateHighlightedItem(Button26, context);
|
||||
}
|
||||
});
|
||||
Button27.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateSettings(27, context);
|
||||
updateHighlightedItem(Button27, context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateSettings(int fodicon, Context context) {
|
||||
Settings.System.putInt(context.getContentResolver(), Settings.System.FOD_ICON, fodicon);
|
||||
}
|
||||
|
||||
private void updateHighlightedItem(ImageButton activebutton, Context context) {
|
||||
int defaultcolor = context.getResources().getColor(R.color.fod_item_background_stroke_color);
|
||||
ColorStateList defaulttint = ColorStateList.valueOf(defaultcolor);
|
||||
Button0.setBackgroundTintList(defaulttint);
|
||||
Button1.setBackgroundTintList(defaulttint);
|
||||
Button2.setBackgroundTintList(defaulttint);
|
||||
Button3.setBackgroundTintList(defaulttint);
|
||||
Button4.setBackgroundTintList(defaulttint);
|
||||
Button5.setBackgroundTintList(defaulttint);
|
||||
Button6.setBackgroundTintList(defaulttint);
|
||||
Button7.setBackgroundTintList(defaulttint);
|
||||
Button8.setBackgroundTintList(defaulttint);
|
||||
Button9.setBackgroundTintList(defaulttint);
|
||||
Button10.setBackgroundTintList(defaulttint);
|
||||
Button11.setBackgroundTintList(defaulttint);
|
||||
Button12.setBackgroundTintList(defaulttint);
|
||||
Button13.setBackgroundTintList(defaulttint);
|
||||
Button14.setBackgroundTintList(defaulttint);
|
||||
Button15.setBackgroundTintList(defaulttint);
|
||||
Button16.setBackgroundTintList(defaulttint);
|
||||
Button17.setBackgroundTintList(defaulttint);
|
||||
Button18.setBackgroundTintList(defaulttint);
|
||||
Button19.setBackgroundTintList(defaulttint);
|
||||
Button20.setBackgroundTintList(defaulttint);
|
||||
Button21.setBackgroundTintList(defaulttint);
|
||||
Button22.setBackgroundTintList(defaulttint);
|
||||
Button23.setBackgroundTintList(defaulttint);
|
||||
Button24.setBackgroundTintList(defaulttint);
|
||||
Button25.setBackgroundTintList(defaulttint);
|
||||
Button26.setBackgroundTintList(defaulttint);
|
||||
Button27.setBackgroundTintList(defaulttint);
|
||||
activebutton.setBackgroundTintList(Utils.getColorAttr(getContext(), android.R.attr.colorAccent));
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The exTHmUI Open Source 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.preferences;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.provider.Settings;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ListView;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.cherish.settings.preferences.PackageListAdapter;
|
||||
import com.cherish.settings.preferences.PackageListAdapter.PackageItem;
|
||||
|
||||
public class PackageListPreference extends PreferenceCategory implements
|
||||
Preference.OnPreferenceClickListener {
|
||||
|
||||
private Context mContext;
|
||||
private String mRemovedListKey;
|
||||
|
||||
private PackageListAdapter mPackageAdapter;
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
private Preference mAddPackagePref;
|
||||
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
private ArrayList<String> mGamingPackages = new ArrayList<>();
|
||||
private ArrayList<String> mRemovedPackages = new ArrayList<>();
|
||||
|
||||
public PackageListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mContext = context;
|
||||
|
||||
mPackageManager = mContext.getPackageManager();
|
||||
mPackageAdapter = new PackageListAdapter(mContext);
|
||||
|
||||
mContentResolver = mContext.getApplicationContext().getContentResolver();
|
||||
|
||||
mAddPackagePref = makeAddPref();
|
||||
|
||||
this.setOrderingAsAdded(false);
|
||||
}
|
||||
|
||||
private Preference makeAddPref() {
|
||||
Preference pref = new Preference(mContext);
|
||||
pref.setTitle(R.string.add_package_to_title);
|
||||
pref.setIcon(R.drawable.ic_add);
|
||||
pref.setPersistent(false);
|
||||
pref.setOnPreferenceClickListener(this);
|
||||
return pref;
|
||||
}
|
||||
|
||||
public void setRemovedListKey(String key) {
|
||||
mRemovedListKey = key;
|
||||
if (isAttached()) {
|
||||
refreshCustomApplicationPrefs();
|
||||
}
|
||||
}
|
||||
|
||||
private ApplicationInfo getAppInfo(String packageName) {
|
||||
try {
|
||||
return mPackageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void parsePackageList() {
|
||||
mGamingPackages.clear();
|
||||
mRemovedPackages.clear();
|
||||
|
||||
String packageListData = Settings.System.getString(mContentResolver, getKey());
|
||||
if (!TextUtils.isEmpty(packageListData)) {
|
||||
String[] packageListArray = packageListData.split(";");
|
||||
mGamingPackages.addAll(Arrays.asList(packageListArray));
|
||||
}
|
||||
if (!TextUtils.isEmpty(mRemovedListKey)) {
|
||||
String removedPackageListData = Settings.System.getString(mContentResolver, mRemovedListKey);
|
||||
if (!TextUtils.isEmpty(removedPackageListData)) {
|
||||
String[] packageListArray = removedPackageListData.split(";");
|
||||
mRemovedPackages.addAll(Arrays.asList(packageListArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshCustomApplicationPrefs() {
|
||||
parsePackageList();
|
||||
removeAll();
|
||||
addPreference(mAddPackagePref);
|
||||
for (String pkg : mGamingPackages) {
|
||||
addPackageToPref(pkg);
|
||||
}
|
||||
}
|
||||
|
||||
private void savePackagesList() {
|
||||
String packageListData = String.join(";", mGamingPackages);
|
||||
Settings.System.putString(mContentResolver, getKey(), packageListData);
|
||||
if (!TextUtils.isEmpty(mRemovedListKey)) {
|
||||
String removedPackageListData = String.join(";", mRemovedPackages);
|
||||
Settings.System.putString(mContentResolver, mRemovedListKey, removedPackageListData);
|
||||
}
|
||||
}
|
||||
|
||||
private void addPackageToPref(String packageName) {
|
||||
Preference pref = new Preference(mContext);
|
||||
ApplicationInfo appInfo = getAppInfo(packageName);
|
||||
if (appInfo == null) return;
|
||||
pref.setKey(packageName);
|
||||
pref.setTitle(appInfo.loadLabel(mPackageManager));
|
||||
pref.setIcon(appInfo.loadIcon(mPackageManager));
|
||||
pref.setPersistent(false);
|
||||
pref.setOnPreferenceClickListener(this);
|
||||
addPreference(pref);
|
||||
}
|
||||
|
||||
private void addPackageToList(String packageName) {
|
||||
if (!mGamingPackages.contains(packageName)) {
|
||||
mGamingPackages.add(packageName);
|
||||
addPackageToPref(packageName);
|
||||
}
|
||||
mRemovedPackages.remove(packageName);
|
||||
savePackagesList();
|
||||
}
|
||||
|
||||
private void removePackageFromList(String packageName) {
|
||||
if (!mRemovedPackages.contains(packageName)) {
|
||||
mRemovedPackages.add(packageName);
|
||||
}
|
||||
mGamingPackages.remove(packageName);
|
||||
savePackagesList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached() {
|
||||
super.onAttached();
|
||||
refreshCustomApplicationPrefs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
if (preference == mAddPackagePref) {
|
||||
ListView appsList = new ListView(mContext);
|
||||
appsList.setAdapter(mPackageAdapter);
|
||||
builder.setTitle(R.string.profile_choose_app);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
builder.setView(appsList);
|
||||
final Dialog dialog = builder.create();
|
||||
appsList.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
PackageItem info = (PackageItem) parent.getItemAtPosition(position);
|
||||
addPackageToList(info.packageName);
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
} else if (preference == findPreference(preference.getKey())) {
|
||||
builder.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) {
|
||||
removePackageFromList(preference.getKey());
|
||||
removePreference(preference);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Potato Open Sauce 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.os.Bundle;
|
||||
import android.content.Context;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceFragment;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CutoutFragment extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener, Indexable {
|
||||
|
||||
private static final String KEY_DISPLAY_CUTOUT_STYLE = "display_cutout_style";
|
||||
private ListPreference mCutoutStyle;
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (preference == mCutoutStyle) {
|
||||
String value = (String) newValue;
|
||||
Settings.System.putInt(getContentResolver(), Settings.System.DISPLAY_CUTOUT_MODE, Integer.valueOf(value));
|
||||
int valueIndex = mCutoutStyle.findIndexOfValue(value);
|
||||
mCutoutStyle.setValueIndex(valueIndex >= 0 ? valueIndex : 0);
|
||||
mCutoutStyle.setSummary(mCutoutStyle.getEntries()[valueIndex]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.cutout);
|
||||
mCutoutStyle = (ListPreference) findPreference(KEY_DISPLAY_CUTOUT_STYLE);
|
||||
int cutoutStyle = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.DISPLAY_CUTOUT_MODE, 0);
|
||||
int valueIndex = mCutoutStyle.findIndexOfValue(String.valueOf(cutoutStyle));
|
||||
mCutoutStyle.setValueIndex(valueIndex >= 0 ? valueIndex : 0);
|
||||
mCutoutStyle.setSummary(mCutoutStyle.getEntry());
|
||||
mCutoutStyle.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, boolean enabled) {
|
||||
List<SearchIndexableResource> indexables = new ArrayList<>();
|
||||
SearchIndexableResource indexable = new SearchIndexableResource(context);
|
||||
indexable.xmlResId = R.xml.cutout;
|
||||
indexables.add(indexable);
|
||||
return indexables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The OmniROM Project
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@SearchIndexable
|
||||
public class OmniJawsSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
private static final String TAG = "OmniJawsSettings";
|
||||
private static final String CATEGORY_WEATHER = "weather_category";
|
||||
private static final String WEATHER_ICON_PACK = "weather_icon_pack";
|
||||
private static final String DEFAULT_WEATHER_ICON_PACKAGE = "org.omnirom.omnijaws";
|
||||
private static final String DEFAULT_WEATHER_ICON_PREFIX = "outline";
|
||||
private static final String WEATHER_SERVICE_PACKAGE = "org.omnirom.omnijaws";
|
||||
private static final String CHRONUS_ICON_PACK_INTENT = "com.dvtonder.chronus.ICON_PACK";
|
||||
|
||||
private PreferenceCategory mWeatherCategory;
|
||||
private ListPreference mWeatherIconPack;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.omnijaws_settings);
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
|
||||
mWeatherCategory = (PreferenceCategory) prefScreen.findPreference(CATEGORY_WEATHER);
|
||||
if (mWeatherCategory != null) {
|
||||
prefScreen.removePreference(mWeatherCategory);
|
||||
} else {
|
||||
String settingHeaderPackage = Settings.System.getString(getContentResolver(),
|
||||
Settings.System.OMNIJAWS_WEATHER_ICON_PACK);
|
||||
if (settingHeaderPackage == null) {
|
||||
settingHeaderPackage = DEFAULT_WEATHER_ICON_PACKAGE + "." + DEFAULT_WEATHER_ICON_PREFIX;
|
||||
}
|
||||
mWeatherIconPack = (ListPreference) findPreference(WEATHER_ICON_PACK);
|
||||
|
||||
List<String> entries = new ArrayList<String>();
|
||||
List<String> values = new ArrayList<String>();
|
||||
getAvailableWeatherIconPacks(entries, values);
|
||||
mWeatherIconPack.setEntries(entries.toArray(new String[entries.size()]));
|
||||
mWeatherIconPack.setEntryValues(values.toArray(new String[values.size()]));
|
||||
|
||||
int valueIndex = mWeatherIconPack.findIndexOfValue(settingHeaderPackage);
|
||||
if (valueIndex == -1) {
|
||||
// no longer found
|
||||
settingHeaderPackage = DEFAULT_WEATHER_ICON_PACKAGE + "." + DEFAULT_WEATHER_ICON_PREFIX;
|
||||
Settings.System.putString(getContentResolver(),
|
||||
Settings.System.OMNIJAWS_WEATHER_ICON_PACK, settingHeaderPackage);
|
||||
valueIndex = mWeatherIconPack.findIndexOfValue(settingHeaderPackage);
|
||||
}
|
||||
mWeatherIconPack.setValueIndex(valueIndex >= 0 ? valueIndex : 0);
|
||||
mWeatherIconPack.setSummary(mWeatherIconPack.getEntry());
|
||||
mWeatherIconPack.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
if (preference == mWeatherIconPack) {
|
||||
String value = (String) objValue;
|
||||
Settings.System.putString(getContentResolver(),
|
||||
Settings.System.OMNIJAWS_WEATHER_ICON_PACK, value);
|
||||
int valueIndex = mWeatherIconPack.findIndexOfValue(value);
|
||||
mWeatherIconPack.setSummary(mWeatherIconPack.getEntries()[valueIndex]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void getAvailableWeatherIconPacks(List<String> entries, List<String> values) {
|
||||
Intent i = new Intent();
|
||||
PackageManager packageManager = getPackageManager();
|
||||
i.setAction("org.omnirom.WeatherIconPack");
|
||||
for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
|
||||
String packageName = r.activityInfo.packageName;
|
||||
if (packageName.equals(DEFAULT_WEATHER_ICON_PACKAGE)) {
|
||||
values.add(0, r.activityInfo.name);
|
||||
} else {
|
||||
values.add(r.activityInfo.name);
|
||||
}
|
||||
String label = r.activityInfo.loadLabel(getPackageManager()).toString();
|
||||
if (label == null) {
|
||||
label = r.activityInfo.packageName;
|
||||
}
|
||||
if (packageName.equals(DEFAULT_WEATHER_ICON_PACKAGE)) {
|
||||
entries.add(0, label);
|
||||
} else {
|
||||
entries.add(label);
|
||||
}
|
||||
}
|
||||
i = new Intent(Intent.ACTION_MAIN);
|
||||
i.addCategory(CHRONUS_ICON_PACK_INTENT);
|
||||
for (ResolveInfo r : packageManager.queryIntentActivities(i, 0)) {
|
||||
String packageName = r.activityInfo.packageName;
|
||||
values.add(packageName + ".weather");
|
||||
String label = r.activityInfo.loadLabel(getPackageManager()).toString();
|
||||
if (label == null) {
|
||||
label = r.activityInfo.packageName;
|
||||
}
|
||||
entries.add(label);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOmniJawsEnabled() {
|
||||
final Uri SETTINGS_URI
|
||||
= Uri.parse("content://org.omnirom.omnijaws.provider/settings");
|
||||
|
||||
final String[] SETTINGS_PROJECTION = new String[] {
|
||||
"enabled"
|
||||
};
|
||||
|
||||
final Cursor c = getContentResolver().query(SETTINGS_URI, SETTINGS_PROJECTION,
|
||||
null, null, null);
|
||||
if (c != null) {
|
||||
int count = c.getCount();
|
||||
if (count == 1) {
|
||||
c.moveToPosition(0);
|
||||
boolean enabled = c.getInt(0) == 1;
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.omnijaws_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 CarbonROM
|
||||
*
|
||||
* 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.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class SmartPixels extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
private static final String TAG = "SmartPixels";
|
||||
private static final String ENABLE = "smart_pixels_enable";
|
||||
private static final String FOOTER = "smart_pixels_footer";
|
||||
private static final String ON_POWER_SAVE = "smart_pixels_on_power_save";
|
||||
|
||||
private Handler mHandler = new Handler();
|
||||
private SmartPixelsObserver mSmartPixelsObserver;
|
||||
private SystemSettingSwitchPreference mSmartPixelsEnable;
|
||||
private SystemSettingSwitchPreference mSmartPixelsOnPowerSave;
|
||||
|
||||
private boolean mIsSmartPixelsEnabled;
|
||||
private boolean mIsSmartPixelsOnPowerSave;
|
||||
|
||||
ContentResolver resolver;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings_smart_pixels);
|
||||
|
||||
findPreference(FOOTER).setTitle(R.string.smart_pixels_warning_text);
|
||||
|
||||
resolver = getActivity().getContentResolver();
|
||||
|
||||
mSmartPixelsEnable = (SystemSettingSwitchPreference) findPreference(ENABLE);
|
||||
mSmartPixelsOnPowerSave = (SystemSettingSwitchPreference) findPreference(ON_POWER_SAVE);
|
||||
|
||||
mSmartPixelsObserver = new SmartPixelsObserver(mHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (mSmartPixelsObserver != null) {
|
||||
mSmartPixelsObserver.register();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (mSmartPixelsObserver != null) {
|
||||
mSmartPixelsObserver.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
final String key = preference.getKey();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updatePreferences() {
|
||||
mIsSmartPixelsEnabled = (Settings.System.getIntForUser(
|
||||
resolver, Settings.System.SMART_PIXELS_ENABLE,
|
||||
0, UserHandle.USER_CURRENT) == 1);
|
||||
mIsSmartPixelsOnPowerSave = (Settings.System.getIntForUser(
|
||||
resolver, Settings.System.SMART_PIXELS_ON_POWER_SAVE,
|
||||
0, UserHandle.USER_CURRENT) == 1);
|
||||
|
||||
mSmartPixelsEnable.setChecked(mIsSmartPixelsEnabled);
|
||||
mSmartPixelsOnPowerSave.setChecked(mIsSmartPixelsOnPowerSave);
|
||||
}
|
||||
|
||||
private class SmartPixelsObserver extends ContentObserver {
|
||||
public SmartPixelsObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
resolver.registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.SMART_PIXELS_ENABLE),
|
||||
false, this, UserHandle.USER_CURRENT);
|
||||
resolver.registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.SMART_PIXELS_ON_POWER_SAVE),
|
||||
false, this, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
resolver.unregisterContentObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
updatePreferences();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result =
|
||||
new ArrayList<SearchIndexableResource>();
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
if (context.getResources().
|
||||
getBoolean(com.android.internal.R.bool.config_enableSmartPixels)) {
|
||||
sir.xmlResId = R.xml.cherish_settings_smart_pixels;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Pure Nexus 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.SharedPreferences;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceFragment;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SearchIndexable
|
||||
public class VolumeStepsFragment extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String TAG = "VolumeSteps";
|
||||
private static final String VOLUME_STEP_DEFAULTS = "volume_step_defaults";
|
||||
private static final String FIRST_RUN_KEY = "first_run";
|
||||
|
||||
// base map of all preference keys and the associated stream
|
||||
private static final Map<String, Integer> volume_map = new HashMap<String, Integer>();
|
||||
static {
|
||||
volume_map.put("volume_steps_alarm", new Integer(AudioManager.STREAM_ALARM));
|
||||
volume_map.put("volume_steps_dtmf", new Integer(AudioManager.STREAM_DTMF));
|
||||
volume_map.put("volume_steps_music", new Integer(AudioManager.STREAM_MUSIC));
|
||||
volume_map.put("volume_steps_notification", new Integer(AudioManager.STREAM_NOTIFICATION));
|
||||
volume_map.put("volume_steps_ring", new Integer(AudioManager.STREAM_RING));
|
||||
volume_map.put("volume_steps_system", new Integer(AudioManager.STREAM_SYSTEM));
|
||||
volume_map.put("volume_steps_voice_call", new Integer(AudioManager.STREAM_VOICE_CALL));
|
||||
}
|
||||
|
||||
// entries to remove on non-telephony devices
|
||||
private static final Set<String> telephony_set = new HashSet<String>();
|
||||
static {
|
||||
telephony_set.add("volume_steps_dtmf");
|
||||
telephony_set.add("volume_steps_ring");
|
||||
telephony_set.add("volume_steps_voice_call");
|
||||
}
|
||||
|
||||
// set of available pref keys after device configuration filter
|
||||
private Set<String> mAvailableKeys = new HashSet<String>();
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.volume_steps_fragment);
|
||||
mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
|
||||
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
mAvailableKeys = volume_map.keySet();
|
||||
|
||||
// remove invalid audio stream prefs
|
||||
boolean isPhone = TelephonyManager.getDefault().getCurrentPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
|
||||
|
||||
if (!isPhone) {
|
||||
// remove telephony keys from available set
|
||||
mAvailableKeys.removeAll(telephony_set);
|
||||
for (String key : telephony_set) {
|
||||
Preference toRemove = prefScreen.findPreference(key);
|
||||
if (toRemove != null) {
|
||||
prefScreen.removePreference(toRemove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check prefs for initial run of this fragment
|
||||
final boolean firstRun = checkForFirstRun();
|
||||
|
||||
// entries array isn't translatable ugh
|
||||
final String defEntry = getString(R.string.volume_steps_reset);
|
||||
|
||||
// initialize prefs: set defaults if first run, set listeners and update values
|
||||
for (String key : mAvailableKeys) {
|
||||
Preference pref = prefScreen.findPreference(key);
|
||||
if (pref == null || !(pref instanceof ListPreference)) {
|
||||
continue;
|
||||
}
|
||||
final ListPreference listPref = (ListPreference) pref;
|
||||
int steps = mAudioManager.getStreamMaxVolume(volume_map.get(key));
|
||||
if (firstRun) {
|
||||
saveDefaultSteps(listPref, steps);
|
||||
}
|
||||
final int defSteps = getDefaultSteps(listPref);
|
||||
CharSequence[] entries = new CharSequence[listPref.getEntries().length + 1];
|
||||
CharSequence[] values = new CharSequence[listPref.getEntryValues().length + 1];
|
||||
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (i == 0) {
|
||||
entries[i] = defEntry;
|
||||
values[i] = String.valueOf(defSteps);
|
||||
continue;
|
||||
}
|
||||
entries[i] = listPref.getEntries()[i - 1];
|
||||
values[i] = listPref.getEntryValues()[i - 1];
|
||||
}
|
||||
listPref.setEntries(entries);
|
||||
listPref.setEntryValues(values);
|
||||
updateVolumeStepPrefs(listPref, steps);
|
||||
listPref.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
if (preference.hasKey() && mAvailableKeys.contains(preference.getKey())) {
|
||||
commitVolumeSteps(preference, Integer.parseInt(objValue.toString()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private SharedPreferences getDefaultStepsPrefs() {
|
||||
return getActivity().getSharedPreferences(VOLUME_STEP_DEFAULTS,
|
||||
Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
// test for initial run of this fragment
|
||||
private boolean checkForFirstRun() {
|
||||
String isFirstRun = getDefaultStepsPrefs().getString(FIRST_RUN_KEY, null);
|
||||
if (isFirstRun == null) {
|
||||
getDefaultStepsPrefs().edit().putString(FIRST_RUN_KEY, "first_run_initialized").commit();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getDefaultSteps(Preference pref) {
|
||||
if (pref == null || !(pref instanceof ListPreference)) {
|
||||
// unlikely
|
||||
return -1;
|
||||
}
|
||||
String key = pref.getKey();
|
||||
String value = getDefaultStepsPrefs().getString(key, null);
|
||||
if (value == null) {
|
||||
// unlikely
|
||||
return -1;
|
||||
}
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
// on the initial run, let's store true device defaults in sharedPrefs
|
||||
private void saveDefaultSteps(Preference volPref, int defaultSteps) {
|
||||
String key = volPref.getKey();
|
||||
getDefaultStepsPrefs().edit().putString(key, String.valueOf(defaultSteps)).commit();
|
||||
}
|
||||
|
||||
private void updateVolumeStepPrefs(Preference pref, int steps) {
|
||||
if (pref == null || !(pref instanceof ListPreference)) {
|
||||
return;
|
||||
}
|
||||
final ListPreference listPref = (ListPreference) pref;
|
||||
listPref.setSummary(String.valueOf(steps));
|
||||
listPref.setValue(String.valueOf(steps));
|
||||
}
|
||||
|
||||
private void commitVolumeSteps(Preference pref, int steps) {
|
||||
Settings.System.putInt(getActivity().getContentResolver(), pref.getKey(), steps);
|
||||
mAudioManager.setStreamMaxVolume(volume_map.get(pref.getKey()), steps);
|
||||
updateVolumeStepPrefs(pref, steps);
|
||||
Log.i(TAG, "Volume steps:" + pref.getKey() + "" + String.valueOf(steps));
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.volume_steps_fragment;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final List<String> keys = super.getNonIndexableKeys(context);
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -29,12 +29,4 @@ import com.android.settings.R;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static void handleOverlays(String packagename, Boolean state, IOverlayManager mOverlayManager) {
|
||||
try {
|
||||
mOverlayManager.setEnabled(packagename, state, USER_SYSTEM);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user