App & channel notification settings updates
- change 'block all' to an on/off switch bar - update channel list summary text when notifications are toggled on/off on app settings page - Add 'off state' text - change style of foot items - change 'importance' from a dropdown to its own page Bug: 37538972 Bug: 37479730 Fixes: 37541624 Fixes: 37549732 Test: manual Change-Id: I0e5cc66ba539ce2b76b4ad6541bf6bfb5b58c373
This commit is contained in:
@@ -24,6 +24,7 @@ import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
||||
import android.app.Activity;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@@ -33,17 +34,22 @@ import android.support.v7.preference.PreferenceCategory;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.AppHeader;
|
||||
import com.android.settings.DimmableIconPreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.AppHeaderController;
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.notification.NotificationBackend.AppRow;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.FooterPreference;
|
||||
import com.android.settings.widget.MasterSwitchPreference;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import java.text.Collator;
|
||||
@@ -57,12 +63,14 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
private static final String TAG = "AppNotificationSettings";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private static final String KEY_BLOCK = "block";
|
||||
private static final String KEY_IMPORTANCE = "allow_sound";
|
||||
|
||||
private List<NotificationChannelGroup> mChannelGroupList;
|
||||
private List<PreferenceCategory> mChannelGroups = new ArrayList();
|
||||
private RestrictedSwitchPreference mImportanceToggle;
|
||||
private LayoutPreference mBlockBar;
|
||||
private FooterPreference mDeletedChannels;
|
||||
private SwitchBar mSwitchBar;
|
||||
|
||||
private boolean mShowLegacyChannelConfig = false;
|
||||
|
||||
@@ -88,8 +96,8 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
addPreferencesFromResource(R.xml.app_notification_settings);
|
||||
getPreferenceScreen().setOrderingAsAdded(true);
|
||||
|
||||
mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
|
||||
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
|
||||
mBlockedDesc = (FooterPreference) getPreferenceScreen().findPreference(KEY_BLOCKED_DESC);
|
||||
|
||||
setupBlock();
|
||||
setupBadge();
|
||||
@@ -127,11 +135,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
.done(activity, getPrefContext());
|
||||
getPreferenceScreen().addPreference(pref);
|
||||
|
||||
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
|
||||
Log.w(TAG, "Missing package or uid or packageinfo");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
updateDependents(mAppRow.banned);
|
||||
}
|
||||
|
||||
private void populateChannelList() {
|
||||
@@ -187,12 +191,12 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
|
||||
int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
|
||||
if (deletedChannelCount > 0) {
|
||||
DimmableIconPreference deletedPref = new DimmableIconPreference(getPrefContext());
|
||||
deletedPref.setSelectable(false);
|
||||
deletedPref.setTitle(getResources().getQuantityString(
|
||||
mDeletedChannels = new FooterPreference(getPrefContext());
|
||||
mDeletedChannels.setSelectable(false);
|
||||
mDeletedChannels.setTitle(getResources().getQuantityString(
|
||||
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
|
||||
deletedPref.setIcon(R.drawable.ic_info);
|
||||
getPreferenceScreen().addPreference(deletedPref);
|
||||
mDeletedChannels.setEnabled(false);
|
||||
getPreferenceScreen().addPreference(mDeletedChannels);
|
||||
}
|
||||
}
|
||||
updateDependents(mAppRow.banned);
|
||||
@@ -214,7 +218,8 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
|
||||
Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
|
||||
ChannelNotificationSettings.class.getName(),
|
||||
channelArgs, null, 0, null, false, getMetricsCategory());
|
||||
channelArgs, null, R.string.notification_channel_title, null, false,
|
||||
getMetricsCategory());
|
||||
channelPref.setIntent(channelIntent);
|
||||
|
||||
channelPref.setOnPreferenceChangeListener(
|
||||
@@ -227,6 +232,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
channel.setImportance(importance);
|
||||
channel.lockFields(
|
||||
NotificationChannel.USER_LOCKED_IMPORTANCE);
|
||||
channelPref.setSummary(getImportanceSummary(channel.getImportance()));
|
||||
mBackend.updateChannel(mPkg, mUid, channel);
|
||||
|
||||
return true;
|
||||
@@ -237,8 +243,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
|
||||
private void populateDefaultChannelPrefs() {
|
||||
addPreferencesFromResource(R.xml.legacy_channel_notification_settings);
|
||||
mPriority =
|
||||
(RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
||||
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
|
||||
mVisibilityOverride =
|
||||
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
|
||||
mImportanceToggle = (RestrictedSwitchPreference) findPreference(KEY_IMPORTANCE);
|
||||
@@ -248,8 +253,11 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
setupVisOverridePref(mChannel.getLockscreenVisibility());
|
||||
setupImportanceToggle();
|
||||
}
|
||||
mSwitchBar.setChecked(!mAppRow.banned
|
||||
&& mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
|
||||
}
|
||||
|
||||
// 'allow sound'
|
||||
private void setupImportanceToggle() {
|
||||
mImportanceToggle.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mImportanceToggle.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT
|
||||
@@ -268,6 +276,40 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
});
|
||||
}
|
||||
|
||||
protected void setupBlock() {
|
||||
View switchBarContainer = LayoutInflater.from(
|
||||
getPrefContext()).inflate(R.layout.styled_switch_bar, null);
|
||||
mSwitchBar = switchBarContainer.findViewById(R.id.switch_bar);
|
||||
mSwitchBar.show();
|
||||
mSwitchBar.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mSwitchBar.setChecked(!mAppRow.banned);
|
||||
mSwitchBar.addOnSwitchChangeListener(new SwitchBar.OnSwitchChangeListener() {
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
if (mShowLegacyChannelConfig && mChannel != null) {
|
||||
final int importance = isChecked ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_NONE;
|
||||
mImportanceToggle.setChecked(importance == IMPORTANCE_UNSPECIFIED);
|
||||
mChannel.setImportance(importance);
|
||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
|
||||
mBackend.updateChannel(mPkg, mUid, mChannel);
|
||||
}
|
||||
mBackend.setNotificationsEnabledForPackage(mPkgInfo.packageName, mUid, isChecked);
|
||||
updateDependents(!isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
|
||||
mBlockBar.setOrder(-500);
|
||||
mBlockBar.setKey(KEY_BLOCK);
|
||||
getPreferenceScreen().addPreference(mBlockBar);
|
||||
|
||||
if (mAppRow.systemApp && !mAppRow.banned) {
|
||||
setVisible(mBlockBar, false);
|
||||
}
|
||||
|
||||
setupBlockDesc(R.string.app_notifications_off_desc);
|
||||
}
|
||||
|
||||
private void setupBadge() {
|
||||
mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mBadge.setChecked(mAppRow.showBadge);
|
||||
@@ -281,31 +323,14 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
});
|
||||
}
|
||||
|
||||
private void setupBlock() {
|
||||
if (mAppRow.systemApp && !mAppRow.banned) {
|
||||
setVisible(mBlock, false);
|
||||
} else {
|
||||
mBlock.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mBlock.setChecked(mAppRow.banned);
|
||||
mBlock.setOnPreferenceChangeListener(
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference,
|
||||
Object newValue) {
|
||||
final boolean blocked = (Boolean) newValue;
|
||||
mBackend.setNotificationsEnabledForPackage(mPkgInfo.packageName, mUid,
|
||||
!blocked);
|
||||
updateDependents(blocked);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDependents(boolean banned) {
|
||||
for (PreferenceCategory category : mChannelGroups) {
|
||||
setVisible(category, !banned);
|
||||
}
|
||||
if (mDeletedChannels != null) {
|
||||
setVisible(mDeletedChannels, !banned);
|
||||
}
|
||||
setVisible(mBlockedDesc, banned);
|
||||
setVisible(mBadge, !banned);
|
||||
if (mShowLegacyChannelConfig) {
|
||||
setVisible(mImportanceToggle, !banned);
|
||||
@@ -313,7 +338,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
setVisible(mVisibilityOverride, !banned);
|
||||
}
|
||||
if (mAppRow.systemApp && !mAppRow.banned) {
|
||||
setVisible(mBlock, false);
|
||||
setVisible(mBlockBar, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user