Add notification shutoff switch to app details page.
Requires change Ieccac574. Bug: 5547401 Change-Id: I9856658cc638723414a5c2c3c6807241c3ce6166
This commit is contained in:
committed by
Android (Google) Code Review
parent
d4260682b7
commit
4a824be44c
@@ -48,6 +48,38 @@
|
||||
<include
|
||||
layout="@layout/two_buttons_panel"
|
||||
android:id="@+id/control_buttons_panel"/>
|
||||
|
||||
<!-- Ban notifications for this package -->
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="48dp"
|
||||
android:paddingLeft="6dip"
|
||||
android:paddingTop="8dip"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingRight="14dip"
|
||||
android:text="@string/app_notifications_switch_label"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal" />
|
||||
<Switch android:id="@+id/notification_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:padding="8dip"
|
||||
android:switchTextAppearance="@style/TextAppearance.Switch"
|
||||
android:textOn="@string/app_notifications_switch_on"
|
||||
android:textOff="@string/app_notifications_switch_off"
|
||||
android:focusable="false"
|
||||
android:clickable="true" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
|
@@ -3934,4 +3934,11 @@
|
||||
<string name="user_confirm_remove_title">Remove user?</string>
|
||||
<!-- User removal confirmation message [CHAR LIMIT=none] -->
|
||||
<string name="user_confirm_remove_message">Are you sure you want to remove the user and all associated data from the device?</string>
|
||||
|
||||
<!-- Label for "notifications enabled" switch in app details [CHAR LIMIT=20] -->
|
||||
<string name="app_notifications_switch_label">Notifications</string>
|
||||
<!-- Label for enabled state of "notifications enabled" switch in app details [CHAR LIMIT=10] -->
|
||||
<string name="app_notifications_switch_on">Enabled</string>
|
||||
<!-- Label for disabled state "notifications enabled" switch in app details [CHAR LIMIT=10] -->
|
||||
<string name="app_notifications_switch_off">Disabled</string>
|
||||
</resources>
|
||||
|
@@ -191,4 +191,8 @@
|
||||
<item name="android:shadowRadius">2.0</item>
|
||||
<item name="android:shadowColor">#B0000000</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.Switch" parent="@*android:style/TextAppearance.Holo.Widget.Switch">
|
||||
<item name="android:textAllCaps">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
@@ -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,6 +118,7 @@ public class InstalledAppDetails extends Fragment
|
||||
private Button mForceStopButton;
|
||||
private Button mClearDataButton;
|
||||
private Button mMoveAppButton;
|
||||
private Switch mNotificationSwitch;
|
||||
|
||||
private PackageMoveObserver mPackageMoveObserver;
|
||||
|
||||
@@ -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) {
|
||||
@@ -369,6 +386,8 @@ public class InstalledAppDetails extends Fragment
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user