Cherish: Add GamingMode support [3/3]
Change-Id: I27960bbbf982a4cd855524baa743ed6647a2f0be Reviewed-on: https://review.exthmui.cn/c/android_packages_apps_exTHmSettings/+/209 Signed-off-by: cjybyjk <cjybyjk@zjnu.edu.cn> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
9
res/drawable/ic_add.xml
Normal file
9
res/drawable/ic_add.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorControlNormal"
|
||||
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
</vector>
|
||||
9
res/drawable/ic_gaming_image.xml
Normal file
9
res/drawable/ic_gaming_image.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:pathData="M21,6L3,6c-1.1,0 -2,0.9 -2,2v8c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,8c0,-1.1 -0.9,-2 -2,-2zM11,13L8,13v3L6,16v-3L3,13v-2h3L6,8h2v3h3v2zM15.5,15c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM19.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S18.67,9 19.5,9s1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z"
|
||||
android:fillColor="?android:attr/colorPrimary"/>
|
||||
</vector>
|
||||
@@ -1342,4 +1342,48 @@
|
||||
<string name="monet_accuracy">Monet Accuracy</string>
|
||||
<string name="monet_accuracy_summary">The More Accurate the slower (Def 16)</string>
|
||||
|
||||
<string name="add_package_to_title">Add application</string>
|
||||
|
||||
<!-- Gaming mode -->
|
||||
<string name="gaming_title">Gaming mode</string>
|
||||
<string name="gaming_mode_enabled_title">Enable gaming mode</string>
|
||||
<string name="gaming_mode_disable_auto_brightness_title">Disable automatic brightness</string>
|
||||
<string name="gaming_mode_disable_auto_brightness_summary">Disable auto brightness when entering game mode</string>
|
||||
<string name="gaming_mode_notification_danmaku_title">Notification Danmaku</string>
|
||||
<string name="gaming_mode_notification_danmaku_summary">Display the notification content in the form of danmaku in the game</string>
|
||||
<string name="gaming_mode_quick_start_apps_title">Quick Start Apps</string>
|
||||
<string name="gaming_mode_quick_start_apps_summary">Choose the application that you want to launch with a floating ball</string>
|
||||
|
||||
<string name="gaming_mode_performance">Performance</string>
|
||||
<string name="gaming_mode_use_game_driver_title">Use game driver</string>
|
||||
<string name="gaming_mode_use_game_driver_summary">Use specific drivers for games</string>
|
||||
<string name="gaming_mode_change_performance_title">Performance tuning</string>
|
||||
<string name="gaming_mode_change_performance_summary">Adjust performance level when starting game</string>
|
||||
<string name="gaming_mode_performance_title">Performance level</string>
|
||||
|
||||
<string name="gaming_mode_dnd">Do not distrub</string>
|
||||
<string name="gaming_mode_disable_notification_alert_title">Disable notification alert</string>
|
||||
<string name="gaming_mode_disable_notification_alert_summary">Do not allow floating notification and conversation bubbles other than incoming calls and alarms</string>
|
||||
<string name="gaming_mode_disable_ringtone_title">No ringing</string>
|
||||
<string name="gaming_mode_disable_ringtone_summary">Turn off the ringing of incoming calls and notifications in gaming mode</string>
|
||||
<string name="gaming_mode_auto_answer_call_title">Answering calls automatically</string>
|
||||
<string name="gaming_mode_auto_answer_call_summary">Answer calls automatically in the game and hands free when no headphones connected</string>
|
||||
|
||||
<string name="gaming_mode_prevent_accidental_touch">prevent accidental touch</string>
|
||||
<string name="gaming_mode_disable_hw_keys_title">Disable hardware keys</string>
|
||||
<string name="gaming_mode_disable_gesture_title">Disable gestures</string>
|
||||
|
||||
<string name="gaming_mode_apps">Game list</string>
|
||||
<string name="gaming_mode_dynamic_add_title">Dynamic mode</string>
|
||||
<string name="gaming_mode_dynamic_add_summary">Try detecting and adding gaming apps automatically</string>
|
||||
|
||||
<string name="gaming_mode_show_danmaku_title">Show danmaku</string>
|
||||
<string name="gaming_mode_danmaku_dynamic_notification_filter_title">Dynamic filtering notification</string>
|
||||
<string name="gaming_mode_danmaku_dynamic_notification_filter_summary">Automatically filter notifications such as download progress</string>
|
||||
<string name="gaming_mode_danmaku_size_horizontal_title">Danmaku size (horizontal)</string>
|
||||
<string name="gaming_mode_danmaku_size_vertical_title">Danmaku size (vertical)</string>
|
||||
<string name="gaming_mode_danmaku_speed_horizontal_title">Danmaku speed (horizontal)</string>
|
||||
<string name="gaming_mode_danmaku_speed_vertical_title">Danmaku speed (vertical)</string>
|
||||
<string name="gaming_mode_danmaku_blacklist">Blacklist</string>
|
||||
|
||||
</resources>
|
||||
|
||||
124
res/xml/cherish_settings_gaming.xml
Normal file
124
res/xml/cherish_settings_gaming.xml
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:title="@string/gaming_title" >
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_enabled"
|
||||
android:title="@string/gaming_mode_enabled_title"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_dynamic_add"
|
||||
android:title="@string/gaming_mode_dynamic_add_title"
|
||||
android:summary="@string/gaming_mode_dynamic_add_summary"
|
||||
android:defaultValue="true"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_disable_auto_brightness"
|
||||
android:title="@string/gaming_mode_disable_auto_brightness_title"
|
||||
android:summary="@string/gaming_mode_disable_auto_brightness_summary"
|
||||
android:defaultValue="true"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
<Preference
|
||||
android:key="gaming_mode_notification_danmaku"
|
||||
android:title="@string/gaming_mode_notification_danmaku_title"
|
||||
android:summary="@string/gaming_mode_notification_danmaku_summary"
|
||||
android:fragment="com.cherish.settings.fragments.gaming.DanmakuSettings"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
<Preference
|
||||
android:key="gaming_mode_quick_start_apps"
|
||||
android:title="@string/gaming_mode_quick_start_apps_title"
|
||||
android:summary="@string/gaming_mode_quick_start_apps_summary"
|
||||
android:fragment="com.cherish.settings.fragments.gaming.QuickStartAppSettings"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/gaming_mode_performance">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_use_game_driver"
|
||||
android:title="@string/gaming_mode_use_game_driver_title"
|
||||
android:summary="@string/gaming_mode_use_game_driver_summary"
|
||||
android:defaultValue="true"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_change_performance_level"
|
||||
android:title="@string/gaming_mode_change_performance_title"
|
||||
android:summary="@string/gaming_mode_change_performance_summary"
|
||||
android:defaultValue="true"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="gaming_mode_performance_level"
|
||||
android:title="@string/gaming_mode_performance_title"
|
||||
android:defaultValue="5"
|
||||
android:max="6"
|
||||
settings:min="0"
|
||||
settings:units=""
|
||||
android:dependency="gaming_mode_change_performance_level" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/gaming_mode_dnd">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_disable_notification_alert"
|
||||
android:title="@string/gaming_mode_disable_notification_alert_title"
|
||||
android:summary="@string/gaming_mode_disable_notification_alert_summary"
|
||||
android:defaultValue="true"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_disable_ringtone"
|
||||
android:title="@string/gaming_mode_disable_ringtone_title"
|
||||
android:summary="@string/gaming_mode_disable_ringtone_summary"
|
||||
android:defaultValue="false"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_auto_answer_call"
|
||||
android:title="@string/gaming_mode_auto_answer_call_title"
|
||||
android:summary="@string/gaming_mode_auto_answer_call_summary"
|
||||
android:defaultValue="false"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/gaming_mode_prevent_accidental_touch">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_disable_gesture"
|
||||
android:title="@string/gaming_mode_disable_gesture_title"
|
||||
android:defaultValue="false"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<com.cherish.settings.preferences.PackageListPreference
|
||||
android:key="gaming_mode_app_list"
|
||||
android:title="@string/gaming_mode_apps"
|
||||
android:dependency="gaming_mode_enabled" />
|
||||
|
||||
</PreferenceScreen>
|
||||
75
res/xml/cherish_settings_gaming_danmaku.xml
Normal file
75
res/xml/cherish_settings_gaming_danmaku.xml
Normal file
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
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_notification_danmaku_title" >
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_show_danmaku"
|
||||
android:title="@string/gaming_mode_show_danmaku_title"
|
||||
android:defaultValue="true" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="gaming_mode_danmaku_dynamic_notification_filter"
|
||||
android:title="@string/gaming_mode_danmaku_dynamic_notification_filter_title"
|
||||
android:summary="@string/gaming_mode_danmaku_dynamic_notification_filter_summary"
|
||||
android:defaultValue="true"
|
||||
android:dependency="gaming_mode_show_danmaku" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="gaming_mode_danmaku_size_horizontal"
|
||||
android:title="@string/gaming_mode_danmaku_size_horizontal_title"
|
||||
android:defaultValue="36"
|
||||
android:max="64"
|
||||
settings:min="12"
|
||||
settings:units="px"
|
||||
android:dependency="gaming_mode_show_danmaku" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="gaming_mode_danmaku_size_vertical"
|
||||
android:title="@string/gaming_mode_danmaku_size_vertical_title"
|
||||
android:defaultValue="36"
|
||||
android:max="64"
|
||||
settings:min="12"
|
||||
settings:units="px"
|
||||
android:dependency="gaming_mode_show_danmaku" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="gaming_mode_danmaku_speed_horizontal"
|
||||
android:title="@string/gaming_mode_danmaku_speed_horizontal_title"
|
||||
android:defaultValue="300"
|
||||
android:max="1000"
|
||||
settings:min="100"
|
||||
settings:units="px/s"
|
||||
android:dependency="gaming_mode_show_danmaku" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||
android:key="gaming_mode_danmaku_speed_vertical"
|
||||
android:title="@string/gaming_mode_danmaku_speed_vertical_title"
|
||||
android:defaultValue="300"
|
||||
android:max="1000"
|
||||
settings:min="100"
|
||||
settings:units="px/s"
|
||||
android:dependency="gaming_mode_show_danmaku" />
|
||||
|
||||
<com.cherish.settings.preferences.PackageListPreference
|
||||
android:title="@string/gaming_mode_danmaku_blacklist"
|
||||
android:key="gaming_mode_danmaku_app_blacklist"
|
||||
android:dependency="gaming_mode_show_danmaku" />
|
||||
</PreferenceScreen>
|
||||
26
res/xml/cherish_settings_gaming_qs_app.xml
Normal file
26
res/xml/cherish_settings_gaming_qs_app.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
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_quick_start_apps_title" >
|
||||
|
||||
<com.cherish.settings.preferences.PackageListPreference
|
||||
android:key="gaming_mode_qs_app_list" />
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -44,6 +44,13 @@
|
||||
android:persistent="false" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<!-- Gaming mode -->
|
||||
<Preference
|
||||
android:key="gaming_category"
|
||||
android:title="@string/gaming_title"
|
||||
android:fragment="com.cherish.settings.fragments.GamingModeSettings"
|
||||
android:icon="@drawable/ic_gaming_image"/>
|
||||
|
||||
|
||||
<com.cherish.settings.preferences.GlobalSettingSwitchPreference
|
||||
|
||||
55
src/com/cherish/settings/fragments/GamingModeSettings.java
Normal file
55
src/com/cherish/settings/fragments/GamingModeSettings.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
|
||||
import com.cherish.settings.preferences.PackageListPreference;
|
||||
|
||||
public class GamingModeSettings extends SettingsPreferenceFragment {
|
||||
|
||||
private PackageListPreference mGamingPrefList;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings_gaming);
|
||||
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
|
||||
mGamingPrefList = (PackageListPreference) findPreference("gaming_mode_app_list");
|
||||
mGamingPrefList.setRemovedListKey(Settings.System.GAMING_MODE_REMOVED_APP_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
206
src/com/cherish/settings/preferences/PackageListPreference.java
Normal file
206
src/com/cherish/settings/preferences/PackageListPreference.java
Normal file
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user