Cherish: HeadsUp blacklists (2/2)
Change-Id: Ie86a3d43fdb14f96131e48c14ebb9f2818a222a3
This commit is contained in:
17
res/drawable/ic_blacklist.xml
Normal file
17
res/drawable/ic_blacklist.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<vector android:height="24dp" android:viewportHeight="256"
|
||||
android:viewportWidth="256" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#ebe7f2" android:pathData="m62.524,205.75v14.049h42.226c0,-5.279 1.759,-10.146 4.723,-14.049z"/>
|
||||
<path android:fillColor="#ebe7f2" android:pathData="m146.527,205.75c2.964,3.902 4.723,8.77 4.723,14.049h42.226v-14.049z"/>
|
||||
<path android:fillColor="#ebe7f2" android:pathData="m96.665,61.136h62.671v12.605h-62.671z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m90.535,106.5 l4.42,-4.42c0.977,-0.977 0.977,-2.559 0,-3.535 -0.977,-0.977 -2.559,-0.977 -3.535,0l-4.42,4.42 -4.42,-4.42c-0.977,-0.977 -2.559,-0.977 -3.535,0 -0.977,0.977 -0.977,2.559 0,3.535l4.42,4.42 -4.42,4.42c-0.977,0.977 -0.977,2.559 0,3.535 0.488,0.488 1.128,0.732 1.768,0.732s1.279,-0.244 1.768,-0.732l4.42,-4.42 4.42,4.42c0.488,0.488 1.128,0.732 1.768,0.732s1.279,-0.244 1.768,-0.732c0.977,-0.977 0.977,-2.559 0,-3.535z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m90.535,139 l4.42,-4.42c0.977,-0.977 0.977,-2.559 0,-3.535 -0.977,-0.977 -2.559,-0.977 -3.535,0l-4.42,4.42 -4.42,-4.42c-0.977,-0.977 -2.559,-0.977 -3.535,0 -0.977,0.977 -0.977,2.559 0,3.535l4.42,4.42 -4.42,4.42c-0.977,0.977 -0.977,2.559 0,3.535 0.488,0.488 1.128,0.732 1.768,0.732s1.279,-0.244 1.768,-0.732l4.42,-4.42 4.42,4.42c0.488,0.488 1.128,0.732 1.768,0.732s1.279,-0.244 1.768,-0.732c0.977,-0.977 0.977,-2.559 0,-3.535z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m90.535,171.5 l4.42,-4.42c0.977,-0.977 0.977,-2.559 0,-3.535 -0.977,-0.977 -2.559,-0.977 -3.535,0l-4.42,4.42 -4.42,-4.42c-0.977,-0.977 -2.559,-0.977 -3.535,0 -0.977,0.977 -0.977,2.559 0,3.535l4.42,4.42 -4.42,4.42c-0.977,0.977 -0.977,2.559 0,3.535 0.488,0.488 1.128,0.732 1.768,0.732s1.279,-0.244 1.768,-0.732l4.42,-4.42 4.42,4.42c0.488,0.488 1.128,0.732 1.768,0.732s1.279,-0.244 1.768,-0.732c0.977,-0.977 0.977,-2.559 0,-3.535z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m94.833,217.299h-29.81v-153.663h20.581c1.381,0 2.5,-1.119 2.5,-2.5s-1.119,-2.5 -2.5,-2.5h-23.081c-1.381,0 -2.5,1.119 -2.5,2.5v158.663c0,1.381 1.119,2.5 2.5,2.5h32.31c1.381,0 2.5,-1.119 2.5,-2.5s-1.119,-2.5 -2.5,-2.5z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m193.477,58.636h-23.081c-1.381,0 -2.5,1.119 -2.5,2.5s1.119,2.5 2.5,2.5h20.581v153.663h-28.644c-1.381,0 -2.5,1.119 -2.5,2.5s1.119,2.5 2.5,2.5h31.144c1.381,0 2.5,-1.119 2.5,-2.5v-158.663c0,-1.381 -1.12,-2.5 -2.5,-2.5z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m96.665,76.241h62.671c1.381,0 2.5,-1.119 2.5,-2.5v-25.21c0,-1.381 -1.119,-2.5 -2.5,-2.5h-17.316c0.548,-1.563 0.83,-3.217 0.83,-4.916 0,-8.188 -6.661,-14.851 -14.85,-14.851s-14.85,6.662 -14.85,14.851c0,1.699 0.282,3.354 0.83,4.916h-17.315c-1.381,0 -2.5,1.119 -2.5,2.5v25.21c0,1.381 1.119,2.5 2.5,2.5zM99.165,51.031h18.96c0.947,0 1.813,-0.536 2.237,-1.384 0.423,-0.848 0.33,-1.862 -0.24,-2.619 -1.29,-1.715 -1.972,-3.759 -1.972,-5.913 0,-5.432 4.419,-9.851 9.85,-9.851s9.85,4.419 9.85,9.851c0,2.154 -0.682,4.198 -1.972,5.913 -0.57,0.757 -0.663,1.771 -0.24,2.619 0.424,0.848 1.29,1.384 2.237,1.384h18.961v20.21h-57.671z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m172,104h-65.335c-1.381,0 -2.5,1.119 -2.5,2.5s1.119,2.5 2.5,2.5h65.335c1.381,0 2.5,-1.119 2.5,-2.5s-1.119,-2.5 -2.5,-2.5z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m172,136.5h-65.335c-1.381,0 -2.5,1.119 -2.5,2.5s1.119,2.5 2.5,2.5h65.335c1.381,0 2.5,-1.119 2.5,-2.5s-1.119,-2.5 -2.5,-2.5z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m172,169h-65.335c-1.381,0 -2.5,1.119 -2.5,2.5s1.119,2.5 2.5,2.5h65.335c1.381,0 2.5,-1.119 2.5,-2.5s-1.119,-2.5 -2.5,-2.5z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m128,194.049c-14.198,0 -25.75,11.552 -25.75,25.75s11.552,25.75 25.75,25.75 25.75,-11.552 25.75,-25.75 -11.552,-25.75 -25.75,-25.75zM128,240.549c-11.441,0 -20.75,-9.309 -20.75,-20.75s9.309,-20.75 20.75,-20.75 20.75,9.309 20.75,20.75 -9.309,20.75 -20.75,20.75z"/>
|
||||
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="m131.535,219.799 l8.232,-8.232c0.977,-0.977 0.977,-2.559 0,-3.535 -0.977,-0.977 -2.559,-0.977 -3.535,0l-8.232,8.232 -8.232,-8.232c-0.977,-0.977 -2.559,-0.977 -3.535,0 -0.977,0.977 -0.977,2.559 0,3.535l8.232,8.232 -8.232,8.232c-0.977,0.977 -0.977,2.559 0,3.535 0.488,0.488 1.128,0.732 1.768,0.732s1.279,-0.244 1.768,-0.732l8.232,-8.232 8.232,8.232c0.488,0.488 1.128,0.732 1.768,0.732s1.279,-0.244 1.768,-0.732c0.977,-0.977 0.977,-2.559 0,-3.535z"/>
|
||||
</vector>
|
||||
@@ -424,4 +424,15 @@
|
||||
<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>
|
||||
<!-- Heads up -->
|
||||
<string name="heads_up_notifications">Đứng đầu</string>
|
||||
<string name="heads_up_notifications_summary">Bật lên thông báo trên thanh trạng thái</string>
|
||||
<string name="add_heads_up_package">Thêm ứng dụng</string>
|
||||
<string name="heads_up_stoplist_title">Danh sách dừng</string>
|
||||
<string name="add_heads_up_stoplist_summary">Vô hiệu hóa heads up trong các ứng dụng này</string>
|
||||
<string name="heads_up_blacklist_title">Danh sách đen</string>
|
||||
<string name="add_heads_up_blacklist_summary">Vô hiệu hóa các ứng dụng này</string>
|
||||
<string name="profile_choose_app">Chọn ứng dụng</string>
|
||||
<string name="dialog_delete_title">Xóa</string>
|
||||
<string name="dialog_delete_message">Xóa mục đã chọn?</string>
|
||||
</resources>
|
||||
|
||||
@@ -476,4 +476,16 @@
|
||||
<string name="gaming_mode_dynamic_title">Dynamic mode</string>
|
||||
<string name="gaming_mode_dynamic_summary">Try detecting and adding gaming apps automatically</string>
|
||||
|
||||
<!-- Heads up -->
|
||||
<string name="heads_up_notifications">Heads Up</string>
|
||||
<string name="heads_up_notifications_summary">Pop up statusbar notifications</string>
|
||||
<string name="add_heads_up_package">Add app</string>
|
||||
<string name="heads_up_stoplist_title">Stoplist</string>
|
||||
<string name="add_heads_up_stoplist_summary">Disable heads up in these applications</string>
|
||||
<string name="heads_up_blacklist_title">Blacklist</string>
|
||||
<string name="add_heads_up_blacklist_summary">Disable heads up for these applications</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>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -63,6 +63,20 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="notification_stat"
|
||||
android:title="@string/notification_stat">
|
||||
|
||||
<com.cherish.settings.preferences.GlobalSettingMasterSwitchPreference
|
||||
android:key="heads_up_notifications_enabled"
|
||||
android:icon="@drawable/ic_blacklist"
|
||||
android:fragment="com.cherish.settings.fragments.HeadsUp"
|
||||
android:title="@string/heads_up_notifications"
|
||||
android:summary="@string/heads_up_notifications_summary"
|
||||
android:defaultValue="true" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/qs_title">
|
||||
|
||||
|
||||
39
res/xml/heads_up_settings.xml
Normal file
39
res/xml/heads_up_settings.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/heads_up_notifications">
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/heads_up_stoplist_title"
|
||||
android:key="stoplist_applications" >
|
||||
<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
|
||||
android:title="@string/heads_up_blacklist_title"
|
||||
android:key="blacklist_applications" >
|
||||
<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>
|
||||
343
src/com/cherish/settings/fragments/HeadsUp.java
Normal file
343
src/com/cherish/settings/fragments/HeadsUp.java
Normal file
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* 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.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 java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HeadsUp 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user