diff --git a/res/values/cherish_arrays.xml b/res/values/cherish_arrays.xml index 4472b86..af5aed5 100644 --- a/res/values/cherish_arrays.xml +++ b/res/values/cherish_arrays.xml @@ -620,33 +620,6 @@ @string/file_header_provider - - - @string/gaming_mode_ringer_off_title - @string/gaming_mode_ringer_vibrate_title - @string/gaming_mode_ringer_dnd_title - @string/gaming_mode_ringer_silent_title - - - 0 - 1 - 2 - 3 - - - - @string/gaming_mode_notifications_off_title - @string/gaming_mode_notifications_notif_title - @string/gaming_mode_notifications_toast_title - @string/gaming_mode_notifications_all_title - - - 0 - 1 - 2 - 3 - - @string/entry_infinite @string/entry_five_minute @@ -1071,23 +1044,6 @@ 3 - - - @string/gaming_mode_headsup_allow - @string/gaming_mode_headsup_dnc - @string/gaming_mode_headsup_clock - @string/gaming_mode_headsup_dialer - @string/gaming_mode_headsup_stop - - - - 0 - 1 - 2 - 3 - 4 - - @string/theming_settings_dashboard_icons_default @@ -1397,5 +1353,4 @@ @string/monet_5 @string/monet_6 - diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index c995a9a..b2aefce 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -683,37 +683,6 @@ Darken image Image height offset - - Gaming Mode - Customize gaming mode preferences - Enable Gaming Mode - Master switch for Gaming Mode - Automatically turn on for these apps - Add apps for Gaming mode - Gaming mode will turn on automatically when these apps are opened and turn off when they are closed - Heads-up Notifications - Allow all headsup notifications - Block all headsup notifications except calls & alarms - Block all headsup notifications except alarms - Block all headsup notifications except calls - Block all headsup notifications - Lock buttons - Disable hardware buttons when Gaming mode is turned on - Disable automatic brightness - Lock screen brightness when Gaming mode is turned on - Ringer in gaming mode - Do not change - Vibrate - Do Not Disturb - Silent - Gaming mode indication - Disabled - Show notification - Show toasts - Show toasts and notification - Dynamic mode - Try detecting and adding gaming apps automatically - Screen edge lighting Show on new notifcation diff --git a/res/xml/cherish_settings_misc.xml b/res/xml/cherish_settings_misc.xml index c5b473c..191ac42 100644 --- a/res/xml/cherish_settings_misc.xml +++ b/res/xml/cherish_settings_misc.xml @@ -17,14 +17,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/misc_title" xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"> - - diff --git a/res/xml/gaming_mode_settings.xml b/res/xml/gaming_mode_settings.xml deleted file mode 100644 index 34bc98d..0000000 --- a/res/xml/gaming_mode_settings.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/res/xml/sleep_mode_settings.xml b/res/xml/sleep_mode_settings.xml index e227254..5b4c7fe 100644 --- a/res/xml/sleep_mode_settings.xml +++ b/res/xml/sleep_mode_settings.xml @@ -79,14 +79,6 @@ android:title="@string/sleep_mode_aggressive_toggle_title" android:summary="@string/sleep_mode_aggressive_toggle_summary" android:defaultValue="true" /> - - mGamingPackages; - private Context mContext; - - private static final int KEY_MASK_HOME = 0x01; - private static final int KEY_MASK_BACK = 0x02; - private static final int KEY_MASK_MENU = 0x04; - private static final int KEY_MASK_APP_SWITCH = 0x10; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // Get launch-able applications - addPreferencesFromResource(R.xml.gaming_mode_settings); - - // mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.add_gaming_mode_package_summary); - - final PreferenceScreen prefScreen = getPreferenceScreen(); - - mHardwareKeysDisable = (SwitchPreference) findPreference(GAMING_MODE_HW_KEYS); - - if (!haveHWkeys()) { - prefScreen.removePreference(mHardwareKeysDisable); - } - - mPackageManager = getPackageManager(); - mPackageAdapter = new PackageListAdapter(getActivity()); - - mGamingPrefList = (PreferenceGroup) findPreference("gamingmode_applications"); - mGamingPrefList.setOrderingAsAdded(false); - - mGamingPackages = new HashMap(); - - 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 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 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 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 map) { - String setting = map == mGamingPackages ? Settings.System.GAMING_MODE_VALUES : Settings.System.GAMING_MODE_DUMMY; - - List settings = new ArrayList(); - 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); - } - - private boolean haveHWkeys() { - final int deviceKeys = getContext().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 hasAppSwitchKey = (deviceKeys & KEY_MASK_APP_SWITCH) != 0; - - return (hasHomeKey || hasBackKey || hasMenuKey || hasAppSwitchKey); - } -} diff --git a/src/com/cherish/settings/preferences/fragments/GamingModeReceiver.java b/src/com/cherish/settings/preferences/fragments/GamingModeReceiver.java deleted file mode 100644 index fc78bb8..0000000 --- a/src/com/cherish/settings/preferences/fragments/GamingModeReceiver.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2019 crDroid Android Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.cherish.settings.fragments; - -import android.app.AlertDialog; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.provider.Settings; -import android.util.Log; -import android.text.TextUtils; - -import com.android.settings.R; -import com.android.internal.util.cherish.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); - } - } -}