Cherish:HeadsUp blacklists (2/2)
@xyyx: delete app with one tap and some diff in code) Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -508,7 +508,9 @@
|
||||
<string name="summary_heads_up_disabled">Pop-up notifications are disabled</string>
|
||||
<string name="add_heads_up_package">Add app</string>
|
||||
<string name="add_heads_up_stoplist_summary">Disable heads up notifications in these applications</string>
|
||||
<string name="heads_up_stoplist_title">Applist</string>
|
||||
<string name="add_heads_up_blacklist_summary">Disable heads up from these applications</string>
|
||||
<string name="heads_up_stoplist_title">Stoplist</string>
|
||||
<string name="heads_up_blacklist_title">Blacklist</string>
|
||||
<string name="profile_choose_app">Choose app</string>
|
||||
<string name="dialog_delete_title">Delete</string>
|
||||
<string name="dialog_delete_message">Remove selected item?</string>
|
||||
|
||||
@@ -1,47 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
<!-- Copyright (C) 2014 The CyanogenMod 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"
|
||||
android:title="@string/notifications_title"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
|
||||
|
||||
<!-- Heads up -->
|
||||
<Preference
|
||||
android:key="heads_up_notifications"
|
||||
android:title="@string/heads_up_notifications"
|
||||
android:summary="@string/heads_up_summary"
|
||||
android:fragment="com.cherish.settings.fragments.HeadsUpSettings" />
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<Preference
|
||||
android:key="notification_light"
|
||||
android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
|
||||
android:title="@string/notification_light_settings" >
|
||||
<extra
|
||||
android:name="classname"
|
||||
android:value="com.android.settings.Settings$NotificationAppListActivity" />
|
||||
</Preference>
|
||||
<PreferenceCategory
|
||||
android:title="@string/heads_up_notifications" >
|
||||
|
||||
<Preference
|
||||
android:key="charging_light"
|
||||
android:icon="@drawable/ic_battery_almostfull"
|
||||
android:fragment="com.cherish.settings.fragments.BatteryLightSettings"
|
||||
android:title="@string/battery_light_settings" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="notification_sound_vib_screen_on"
|
||||
android:icon="@drawable/ic_notification"
|
||||
android:title="@string/notification_sound_vib_screen_on_title"
|
||||
android:summary="@string/notification_sound_vib_screen_on_summary"
|
||||
<com.cherish.settings.preferences.GlobalSettingSwitchPreference
|
||||
android:key="heads_up_notifications_enabled"
|
||||
android:title="@string/heads_up_notifications"
|
||||
android:summaryOn="@string/summary_heads_up_enabled"
|
||||
android:summaryOff="@string/summary_heads_up_disabled"
|
||||
android:defaultValue="true" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/heads_up_stoplist_title"
|
||||
android:key="stoplist_applications"
|
||||
android:dependency="heads_up_notifications_enabled" >
|
||||
<Preference
|
||||
android:key="add_stoplist_packages"
|
||||
android:icon="@drawable/ic_menu_add_activated_tint"
|
||||
android:title="@string/add_heads_up_package"
|
||||
android:summary="@string/add_heads_up_stoplist_summary" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/heads_up_blacklist_title"
|
||||
android:key="blacklist_applications"
|
||||
android:dependency="heads_up_notifications_enabled" >
|
||||
<Preference
|
||||
android:key="add_blacklist_packages"
|
||||
android:icon="@drawable/ic_menu_add_activated_tint"
|
||||
android:title="@string/add_heads_up_package"
|
||||
android:summary="@string/add_heads_up_blacklist_summary" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -51,14 +51,19 @@ 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) {
|
||||
@@ -71,11 +76,17 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
|
||||
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
|
||||
@@ -91,7 +102,7 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
|
||||
|
||||
@Override
|
||||
public int getDialogMetricsCategory(int dialogId) {
|
||||
if (dialogId == DIALOG_STOPLIST_APPS) {
|
||||
if (dialogId == DIALOG_STOPLIST_APPS || dialogId == DIALOG_BLACKLIST_APPS ) {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
return 0;
|
||||
@@ -104,27 +115,35 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
|
||||
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:
|
||||
final ListView list = new ListView(getActivity());
|
||||
list.setAdapter(mPackageAdapter);
|
||||
|
||||
builder.setTitle(R.string.profile_choose_app);
|
||||
builder.setView(list);
|
||||
dialog = builder.create();
|
||||
|
||||
list.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
// Add empty application definition, the user will be able to edit it later
|
||||
PackageItem info = (PackageItem) parent.getItemAtPosition(position);
|
||||
addCustomApplicationPref(info.packageName);
|
||||
addCustomApplicationPref(info.packageName, mStoplistPackages);
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
dialog = null;
|
||||
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;
|
||||
}
|
||||
@@ -169,8 +188,9 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
// Add the Application Preferences
|
||||
if (mStoplistPrefList != null) {
|
||||
if (mStoplistPrefList != null && mBlacklistPrefList != null) {
|
||||
mStoplistPrefList.removeAll();
|
||||
mBlacklistPrefList.removeAll();
|
||||
|
||||
for (Package pkg : mStoplistPackages.values()) {
|
||||
try {
|
||||
@@ -180,27 +200,44 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
|
||||
// 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())
|
||||
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) {
|
||||
removeCustomApplicationPref(preference.getKey());
|
||||
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);
|
||||
@@ -210,12 +247,12 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addCustomApplicationPref(String packageName) {
|
||||
Package pkg = mStoplistPackages.get(packageName);
|
||||
private void addCustomApplicationPref(String packageName, Map<String,Package> map) {
|
||||
Package pkg = map.get(packageName);
|
||||
if (pkg == null) {
|
||||
pkg = new Package(packageName);
|
||||
mStoplistPackages.put(packageName, pkg);
|
||||
savePackageList(false);
|
||||
map.put(packageName, pkg);
|
||||
savePackageList(false, map);
|
||||
refreshCustomApplicationPrefs();
|
||||
}
|
||||
}
|
||||
@@ -235,51 +272,73 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
|
||||
return pref;
|
||||
}
|
||||
|
||||
private void removeCustomApplicationPref(String packageName) {
|
||||
if (mStoplistPackages.remove(packageName) != null) {
|
||||
savePackageList(false);
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
if (!TextUtils.equals(mStoplistPackageList, stoplistString)) {
|
||||
mStoplistPackageList = stoplistString;
|
||||
mStoplistPackages.clear();
|
||||
|
||||
if (stoplistString != null) {
|
||||
final String[] array = TextUtils.split(stoplistString, "\\|");
|
||||
for (String item : array) {
|
||||
if (TextUtils.isEmpty(item)) {
|
||||
continue;
|
||||
}
|
||||
Package pkg = Package.fromString(item);
|
||||
if (pkg != null) {
|
||||
mStoplistPackages.put(pkg.name, pkg);
|
||||
}
|
||||
}
|
||||
parseAndAddToMap(stoplistString, mStoplistPackages);
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
if (!TextUtils.equals(mBlacklistPackageList, blacklistString)) {
|
||||
mBlacklistPackageList = blacklistString;
|
||||
mBlacklistPackages.clear();
|
||||
parseAndAddToMap(blacklistString, mBlacklistPackages);
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
private void savePackageList(boolean preferencesUpdated) {
|
||||
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 : mStoplistPackages.values()) {
|
||||
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(),
|
||||
Settings.System.HEADS_UP_STOPLIST_VALUES, value);
|
||||
setting, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user