Cherish: Bring back Gaming mode [3/3]

Signed-off-by: DennySPB <dennyspb@gmail.com>
Change-Id: I4ffb0bdf8453068eb049da4823fea6da33346446
This commit is contained in:
Pranav Vashi
2019-11-17 22:47:35 +05:30
committed by Hung Phan
parent 879faa2953
commit 6ad6b05a6c
10 changed files with 637 additions and 12 deletions

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2020 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="M7,6H17A6,6 0 0,1 23,12A6,6 0 0,1 17,18C15.22,18 13.63,17.23 12.53,16H11.47C10.37,17.23 8.78,18 7,18A6,6 0 0,1 1,12A6,6 0 0,1 7,6M6,9V11H4V13H6V15H8V13H10V11H8V9H6M15.5,12A1.5,1.5 0 0,0 14,13.5A1.5,1.5 0 0,0 15.5,15A1.5,1.5 0 0,0 17,13.5A1.5,1.5 0 0,0 15.5,12M18.5,9A1.5,1.5 0 0,0 17,10.5A1.5,1.5 0 0,0 18.5,12A1.5,1.5 0 0,0 20,10.5A1.5,1.5 0 0,0 18.5,9Z" />
</vector>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2017-2019 crDroid Android Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z"/>
</vector>

View File

@@ -179,8 +179,6 @@
<string name="battery_percentage_off">Tắt</string>
<string name="battery_percentage_next">Bật</string>
<string name="battery_percentage_inside">Đã bật (biểu tượng bên trong)</string>
<string name="battery_percentage_estimate">Đã bật (ước tính)</string>
<string name="battery_percentage_percentage_estimate">Đã bật (phần trăm | ước tính)</string>
<!-- Network traffic -->
<string name="traffic_title">Hiển thị tốc độ mạng</string>
<string name="traffic_title_summary">Tùy chỉnh chỉ số lưu lượng mạng</string>
@@ -393,4 +391,37 @@
<!-- Force expanded notifications -->
<string name="force_expanded_notifications_title">Buộc mở rộng thông báo</string>
<string name="force_expanded_notifications_summary">Chỉ có sẵn cho các ứng dụng hỗ trợ thông báo mở rộng</string>
<!-- Switch styles -->
<string name="switch_style_title">Chuyển đổi ngoại hình</string>
<string name="switch_default">Mặc định</string>
<string name="switch_md2">Material Design 2</string>
<string name="switch_oneplus">OnePlus</string>
<string name="switch_narrow">Hẹp</string>
<string name="switch_contained">Bộ chứa</string>
<string name="switch_retro">Retro</string>
<string name="switch_stockish">Stockish</string>
<!-- Gaming mode -->
<string name="gaming_mode_title">Chế độ chơi game</string>
<string name="gaming_mode_summary">Tùy chỉnh tùy chọn chế độ trò chơi</string>
<string name="gaming_mode_app_picker_title">Tự động bật cho các ứng dụng này</string>
<string name="add_gaming_mode_package_title">Thêm ứng dụng cho chế độ chơi game</string>
<string name="add_gaming_mode_package_summary">Chế độ chơi game sẽ tự động bật tắt đối với các ứng dụng này</string>
<string name="gaming_mode_headsup_title">Chặn thông báo</string>
<string name="gaming_mode_headsup_summary">Chặn tất cả các thông báo nổi ngoại trừ cuộc gọi</string>
<string name="gaming_mode_hardware_keys_title">Khóa phím</string>
<string name="gaming_mode_hardware_keys_summary">Vô hiệu hóa phím cứng khi chế độ trò chơi được bật</string>
<string name="gaming_mode_brightness_title">Vô hiệu hóa độ sáng tự động</string>
<string name="gaming_mode_brightness_summary">Khóa độ sáng màn hình khi chế độ trò chơi được bật</string>
<string name="gaming_mode_ringer_title">Chuông trong chế độ trò chơi</string>
<string name="gaming_mode_ringer_off_title">Không thay đổi</string>
<string name="gaming_mode_ringer_vibrate_title">Rung</string>
<string name="gaming_mode_ringer_dnd_title">Không làm phiền</string>
<string name="gaming_mode_ringer_silent_title">Im lặng</string>
<string name="gaming_mode_notifications_title">Thông báo chế độ chơi game</string>
<string name="gaming_mode_notifications_off_title">Đã tắt</string>
<string name="gaming_mode_notifications_notif_title">Hiển thị thông báo</string>
<string name="gaming_mode_notifications_toast_title">Hiện thông báo nhanh</string>
<string name="gaming_mode_notifications_all_title">Hiện thông báo nhanh và thông báo</string>
<string name="gaming_mode_dynamic_title">Chế độ động</string>
<string name="gaming_mode_dynamic_summary">Tự động phát hiện và thêm trò chơi</string>
</resources>

View File

@@ -373,4 +373,31 @@
<item>5</item>
<item>6</item>
</string-array>
<!-- Gaming mode -->
<string-array name="gaming_mode_ringer_entries">
<item>@string/gaming_mode_ringer_off_title</item>
<item>@string/gaming_mode_ringer_vibrate_title</item>
<item>@string/gaming_mode_ringer_dnd_title</item>
<item>@string/gaming_mode_ringer_silent_title</item>
</string-array>
<string-array name="gaming_mode_ringer_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="gaming_mode_notifications_entries">
<item>@string/gaming_mode_notifications_off_title</item>
<item>@string/gaming_mode_notifications_notif_title</item>
<item>@string/gaming_mode_notifications_toast_title</item>
<item>@string/gaming_mode_notifications_all_title</item>
</string-array>
<string-array name="gaming_mode_notifications_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
</resources>

View File

@@ -450,5 +450,30 @@
<string name="switch_contained">Contained</string>
<string name="switch_retro">Retro</string>
<string name="switch_stockish">Stockish</string>
<!-- Gaming mode -->
<string name="gaming_mode_title">Gaming Mode</string>
<string name="gaming_mode_summary">Customize gaming mode preferences</string>
<string name="gaming_mode_app_picker_title">Automatically turn on for these apps</string>
<string name="add_gaming_mode_package_title">Add apps for Gaming mode</string>
<string name="add_gaming_mode_package_summary">Gaming mode will turn on automatically when these apps are opened and turn off when they are closed</string>
<string name="gaming_mode_headsup_title">Block notifications</string>
<string name="gaming_mode_headsup_summary">Block all headsup messages except calls</string>
<string name="gaming_mode_hardware_keys_title">Lock buttons</string>
<string name="gaming_mode_hardware_keys_summary">Disable hardware buttons when Gaming mode is turned on</string>
<string name="gaming_mode_brightness_title">Disable automatic brightness</string>
<string name="gaming_mode_brightness_summary">Lock screen brightness when Gaming mode is turned on</string>
<string name="gaming_mode_ringer_title">Ringer in gaming mode</string>
<string name="gaming_mode_ringer_off_title">Do not change</string>
<string name="gaming_mode_ringer_vibrate_title">Vibrate</string>
<string name="gaming_mode_ringer_dnd_title">Do Not Disturb</string>
<string name="gaming_mode_ringer_silent_title">Silent</string>
<string name="gaming_mode_notifications_title">Gaming mode indication</string>
<string name="gaming_mode_notifications_off_title">Disabled</string>
<string name="gaming_mode_notifications_notif_title">Show notification</string>
<string name="gaming_mode_notifications_toast_title">Show toasts</string>
<string name="gaming_mode_notifications_all_title">Show toasts and notification</string>
<string name="gaming_mode_dynamic_title">Dynamic mode</string>
<string name="gaming_mode_dynamic_summary">Try detecting and adding gaming apps automatically</string>
</resources>

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016-2019 crDroid Android Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<preferencesScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:title="@string/gaming_mode_title">
<com.cherish.settings.preferences.SystemSettingSwitchpreferences
android:key="gaming_mode_headsup_toggle"
android:title="@string/gaming_mode_headsup_title"
android:summary="@string/gaming_mode_headsup_summary"
android:defaultValue="true" />
<com.cherish.settings.preferences.SystemSettingSwitchpreferences
android:key="gaming_mode_hw_keys_toggle"
android:title="@string/gaming_mode_hardware_keys_title"
android:summary="@string/gaming_mode_hardware_keys_summary"
android:defaultValue="false" />
<com.cherish.settings.preferences.SystemSettingSwitchpreferences
android:key="gaming_mode_manual_brightness_toggle"
android:title="@string/gaming_mode_brightness_title"
android:summary="@string/gaming_mode_brightness_summary"
android:defaultValue="true" />
<com.cherish.settings.preferences.SystemSettingListpreferences
android:key="gaming_mode_ringer_mode"
android:title="@string/gaming_mode_ringer_title"
android:entries="@array/gaming_mode_ringer_entries"
android:entryValues="@array/gaming_mode_ringer_values"
android:defaultValue="0"
android:summary="%s" />
<com.cherish.settings.preferences.SystemSettingListpreferences
android:key="gaming_mode_notifications"
android:title="@string/gaming_mode_notifications_title"
android:entries="@array/gaming_mode_notifications_entries"
android:entryValues="@array/gaming_mode_notifications_values"
android:defaultValue="3"
android:summary="%s" />
<com.cherish.settings.preferences.SystemSettingSwitchpreferences
android:key="gaming_mode_dynamic_state"
android:title="@string/gaming_mode_dynamic_title"
android:summary="@string/gaming_mode_dynamic_summary"
android:defaultValue="false" />
<preferencesCategory
android:title="@string/gaming_mode_app_picker_title"
android:key="gamingmode_applications">
<preferences
android:key="add_gamingmode_packages"
android:icon="@drawable/ic_menu_add_white"
android:title="@string/add_gaming_mode_package_title" />
</preferencesCategory>
</preferencesScreen>

View File

@@ -18,6 +18,14 @@
android:title="@string/misc_title"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<com.cherish.settings.preferences.SystemSettingMasterSwitchPreference
android:key="gaming_mode_enabled"
android:icon="@drawable/ic_gaming_mode"
android:fragment="com.cherish.settings.fragments.GamingMode"
android:title="@string/gaming_mode_title"
android:summary="@string/gaming_mode_summary"
android:defaultValue="false" />
<com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="wake_when_plugged_or_unplugged"
android:icon="@drawable/ic_plug"

View File

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

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2019 crDroid Android Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.cherish.settings.fragments;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.internal.util.gaming.GamingModeController;
public class GamingModeReceiver extends BroadcastReceiver {
private static final String TAG = "GamingModeReceiver";
private static final boolean DEBUG = false;
public GamingModeReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null &&
intent.getAction().equals(GamingModeController.GAMING_MODE_TURN_OFF)) {
if (DEBUG) Log.d(TAG, "Received " + GamingModeController.GAMING_MODE_TURN_OFF);
Settings.System.putInt(context.getContentResolver(), Settings.System.GAMING_MODE_ACTIVE, 0);
} else if (intent.getAction() != null &&
intent.getAction().equals(GamingModeController.GAMING_MODE_TURN_ON)) {
if (DEBUG) Log.d(TAG, "Received " + GamingModeController.GAMING_MODE_TURN_ON);
Settings.System.putInt(context.getContentResolver(), Settings.System.GAMING_MODE_ACTIVE, 1);
}
}
}

View File

@@ -2,44 +2,65 @@ 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.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.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.UserHandle;
import android.content.ContentResolver;
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 com.cherish.settings.preferences.CustomSeekBarPreference;
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 java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import com.android.settings.SettingsPreferenceFragment;
import com.cherish.settings.preferences.SystemSettingMasterSwitchPreference;
public class MiscSettings extends SettingsPreferenceFragment implements
OnPreferenceChangeListener {
private static final String GAMING_MODE_ENABLED = "gaming_mode_enabled";
private SystemSettingMasterSwitchPreference mGamingMode;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
ContentResolver resolver = getActivity().getContentResolver();
addPreferencesFromResource(R.xml.cherish_settings_misc);
mGamingMode = (SystemSettingMasterSwitchPreference) findPreference(GAMING_MODE_ENABLED);
mGamingMode.setChecked((Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.GAMING_MODE_ENABLED, 0) == 1));
mGamingMode.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mGamingMode) {
boolean value = (Boolean) objValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.GAMING_MODE_ENABLED, value ? 1 : 0);
return true;
}
return false;
}