From 4a824be44c3878f22469cf45c2ef8b7e92724e92 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Thu, 19 Apr 2012 01:47:45 -0400 Subject: [PATCH] Add notification shutoff switch to app details page. Requires change Ieccac574. Bug: 5547401 Change-Id: I9856658cc638723414a5c2c3c6807241c3ce6166 --- res/layout/installed_app_details.xml | 48 +++++++++++++++---- res/values/strings.xml | 7 +++ res/values/styles.xml | 4 ++ .../applications/InstalledAppDetails.java | 30 +++++++++++- 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/res/layout/installed_app_details.xml b/res/layout/installed_app_details.xml index afec51771e3..5c6867cf791 100644 --- a/res/layout/installed_app_details.xml +++ b/res/layout/installed_app_details.xml @@ -39,15 +39,47 @@ android:paddingTop="5dip" android:paddingBottom="5dip" > - - + + + + + + + + + + + + - - Remove user? Are you sure you want to remove the user and all associated data from the device? + + + Notifications + + Enabled + + Disabled diff --git a/res/values/styles.xml b/res/values/styles.xml index 32e0a48091d..6ee99b372fd 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -191,4 +191,8 @@ 2.0 #B0000000 + + diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java index faa531a7ac3..8b5ff0b0ab6 100644 --- a/src/com/android/settings/applications/InstalledAppDetails.java +++ b/src/com/android/settings/applications/InstalledAppDetails.java @@ -25,6 +25,8 @@ import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.app.Fragment; +import android.app.INotificationManager; +import android.app.NotificationManager; import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; import android.content.Context; @@ -65,6 +67,7 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.Switch; import android.widget.TextView; /** @@ -115,7 +118,8 @@ public class InstalledAppDetails extends Fragment private Button mForceStopButton; private Button mClearDataButton; private Button mMoveAppButton; - + private Switch mNotificationSwitch; + private PackageMoveObserver mPackageMoveObserver; private boolean mHaveSizes = false; @@ -319,6 +323,19 @@ public class InstalledAppDetails extends Fragment } } + private void initNotificationButton() { + INotificationManager nm = INotificationManager.Stub.asInterface( + ServiceManager.getService(Context.NOTIFICATION_SERVICE)); + boolean enabled = true; // default on + try { + enabled = nm.areNotificationsEnabledForPackage(mAppEntry.info.packageName); + } catch (android.os.RemoteException ex) { + // this does not bode well + } + mNotificationSwitch.setChecked(enabled); + mNotificationSwitch.setOnCheckedChangeListener(this); + } + /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { @@ -368,6 +385,8 @@ public class InstalledAppDetails extends Fragment mScreenCompatSection = view.findViewById(R.id.screen_compatibility_section); mAskCompatibilityCB = (CheckBox)view.findViewById(R.id.ask_compatibility_cb); mEnableCompatibilityCB = (CheckBox)view.findViewById(R.id.enable_compatibility_cb); + + mNotificationSwitch = (Switch) view.findViewById(R.id.notification_switch); return view; } @@ -614,6 +633,7 @@ public class InstalledAppDetails extends Fragment initUninstallButtons(); initDataButtons(); initMoveButton(); + initNotificationButton(); } else { mMoveAppButton.setText(R.string.moving); mMoveAppButton.setEnabled(false); @@ -925,6 +945,14 @@ public class InstalledAppDetails extends Fragment } else if (buttonView == mEnableCompatibilityCB) { am.setPackageScreenCompatMode(packageName, isChecked ? ActivityManager.COMPAT_MODE_ENABLED : ActivityManager.COMPAT_MODE_DISABLED); + } else if (buttonView == mNotificationSwitch) { + INotificationManager nm = INotificationManager.Stub.asInterface( + ServiceManager.getService(Context.NOTIFICATION_SERVICE)); + try { + nm.setNotificationsEnabledForPackage(packageName, isChecked); + } catch (android.os.RemoteException ex) { + mNotificationSwitch.setChecked(!isChecked); // revert + } } } }