Fix NPE in notification settings.
Show/hide the apps category safely every time. Default apps category to hidden to avoid startup blip. Change-Id: I4c18c57754e5d0a6a73e7271844ff71c0a66ad8d
This commit is contained in:
@@ -70,6 +70,7 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private static final int MSG_UPDATE_SOUND_SUMMARY = 2;
|
private static final int MSG_UPDATE_SOUND_SUMMARY = 2;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private PackageManager mPM;
|
private PackageManager mPM;
|
||||||
|
|
||||||
private Preference mNotificationSoundPreference;
|
private Preference mNotificationSoundPreference;
|
||||||
@@ -77,13 +78,14 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
|
|||||||
private CheckBoxPreference mLockscreenNotifications;
|
private CheckBoxPreference mLockscreenNotifications;
|
||||||
private CheckBoxPreference mHeadsUp;
|
private CheckBoxPreference mHeadsUp;
|
||||||
private CheckBoxPreference mNotificationPulse;
|
private CheckBoxPreference mNotificationPulse;
|
||||||
|
private PreferenceGroup mAppsPreference;
|
||||||
|
|
||||||
private final Runnable mRingtoneLookupRunnable = new Runnable() {
|
private final Runnable mRingtoneLookupRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mNotificationSoundPreference != null) {
|
if (mNotificationSoundPreference != null) {
|
||||||
final CharSequence summary = SoundSettings.updateRingtoneName(
|
final CharSequence summary = SoundSettings.updateRingtoneName(
|
||||||
getActivity(), RingtoneManager.TYPE_NOTIFICATION);
|
mContext, RingtoneManager.TYPE_NOTIFICATION);
|
||||||
if (summary != null) {
|
if (summary != null) {
|
||||||
mHandler.sendMessage(
|
mHandler.sendMessage(
|
||||||
mHandler.obtainMessage(MSG_UPDATE_SOUND_SUMMARY, summary));
|
mHandler.obtainMessage(MSG_UPDATE_SOUND_SUMMARY, summary));
|
||||||
@@ -154,27 +156,23 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
|
|||||||
private final Runnable mRefreshAppsListRunnable = new Runnable() {
|
private final Runnable mRefreshAppsListRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final PreferenceScreen root = getPreferenceScreen();
|
|
||||||
final PreferenceGroup appsCategory = (PreferenceGroup)
|
|
||||||
root.findPreference(KEY_APPS_CATEGORY);
|
|
||||||
|
|
||||||
appsCategory.removeAll();
|
|
||||||
|
|
||||||
synchronized (mAppNotificationInfo) {
|
synchronized (mAppNotificationInfo) {
|
||||||
if (mAppNotificationInfo.size() == 0) {
|
mAppsPreference.removeAll();
|
||||||
root.removePreference(appsCategory);
|
Preference p = getPreferenceScreen().findPreference(mAppsPreference.getKey());
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int N = mAppNotificationInfo.size();
|
final int N = mAppNotificationInfo.size();
|
||||||
|
if (N == 0 && p != null) {
|
||||||
|
getPreferenceScreen().removePreference(p);
|
||||||
|
} else if (N > 0 && p == null) {
|
||||||
|
getPreferenceScreen().addPreference(mAppsPreference);
|
||||||
|
}
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
final AppNotificationInfo info = mAppNotificationInfo.get(i);
|
final AppNotificationInfo info = mAppNotificationInfo.get(i);
|
||||||
Preference pref = new AppNotificationPreference(root.getContext());
|
Preference pref = new AppNotificationPreference(mContext);
|
||||||
pref.setTitle(info.label);
|
pref.setTitle(info.label);
|
||||||
pref.setIcon(info.icon);
|
pref.setIcon(info.icon);
|
||||||
pref.setIntent(new Intent(Intent.ACTION_MAIN)
|
pref.setIntent(new Intent(Intent.ACTION_MAIN)
|
||||||
.setClassName(info.pkg, info.name));
|
.setClassName(info.pkg, info.name));
|
||||||
appsCategory.addPreference(pref);
|
mAppsPreference.addPreference(pref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,9 +182,10 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
final ContentResolver resolver = getActivity().getContentResolver();
|
mContext = getActivity();
|
||||||
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
|
|
||||||
mPM = getActivity().getPackageManager();
|
mPM = mContext.getPackageManager();
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.notification_settings);
|
addPreferencesFromResource(R.xml.notification_settings);
|
||||||
|
|
||||||
@@ -248,6 +247,8 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
|
|||||||
Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found");
|
Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mAppsPreference = (PreferenceGroup) root.findPreference(KEY_APPS_CATEGORY);
|
||||||
|
root.removePreference(mAppsPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user