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:
Julia Reynolds
2017-04-21 08:27:06 -04:00
parent 8da8951b4b
commit 38c16a9417
12 changed files with 489 additions and 140 deletions

View File

@@ -16,9 +16,7 @@
package com.android.settings.notification;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import android.app.Activity;
@@ -27,25 +25,31 @@ import android.app.NotificationManager;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.support.v7.preference.Preference;
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.internal.widget.LockPatternUtils;
import com.android.settings.DimmableIconPreference;
import com.android.settings.AppHeader;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
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.overlay.FeatureFactory;
import com.android.settings.widget.FooterPreference;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.RestrictedSwitchPreference;
import java.util.ArrayList;
import java.util.List;
public class ChannelNotificationSettings extends NotificationSettingsBase {
private static final String TAG = "ChannelSettings";
@@ -53,10 +57,13 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
protected static final String KEY_VIBRATE = "vibrate";
protected static final String KEY_RINGTONE = "ringtone";
protected Preference mImportance;
protected RestrictedSwitchPreference mLights;
protected RestrictedSwitchPreference mVibrate;
protected NotificationSoundPreference mRingtone;
protected LayoutPreference mBlockBar;
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_TOPIC_NOTIFICATION;
@@ -75,33 +82,33 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
getPreferenceScreen().removeAll();
}
addPreferencesFromResource(R.xml.channel_notification_settings);
getPreferenceScreen().setOrderingAsAdded(true);
// load settings intent
ArrayMap<String, NotificationBackend.AppRow> rows = new ArrayMap<String, NotificationBackend.AppRow>();
rows.put(mAppRow.pkg, mAppRow);
collectConfigActivities(rows);
mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
mBlockedDesc = (FooterPreference) getPreferenceScreen().findPreference(KEY_BLOCKED_DESC);
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
mImportance = (RestrictedDropDownPreference) findPreference(KEY_IMPORTANCE);
mPriority =
(RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
mImportance = findPreference(KEY_IMPORTANCE);
mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
mVisibilityOverride =
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
mLights = (RestrictedSwitchPreference) findPreference(KEY_LIGHTS);
mVibrate = (RestrictedSwitchPreference) findPreference(KEY_VIBRATE);
mRingtone = (NotificationSoundPreference) findPreference(KEY_RINGTONE);
if (mPkgInfo != null && mChannel != null) {
setupPriorityPref(mChannel.canBypassDnd());
setupVisOverridePref(mChannel.getLockscreenVisibility());
setupLights();
setupVibrate();
setupRingtone();
setupBlockAndImportance();
updateDependents();
}
setupPriorityPref(mChannel.canBypassDnd());
setupVisOverridePref(mChannel.getLockscreenVisibility());
setupLights();
setupVibrate();
setupRingtone();
setupBadge();
setupBlock();
setupImportance();
updateDependents();
final Activity activity = getActivity();
final Preference pref = FeatureFactory.getFactory(activity)
.getApplicationFeatureProvider(activity)
@@ -124,12 +131,13 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
}
if (!TextUtils.isEmpty(mChannel.getDescription())) {
DimmableIconPreference descPref = new DimmableIconPreference(getPrefContext());
FooterPreference descPref = new FooterPreference(getPrefContext());
descPref.setSelectable(false);
descPref.setSummary(mChannel.getDescription());
descPref.setIcon(R.drawable.ic_info);
descPref.setEnabled(false);
getPreferenceScreen().addPreference(descPref);
}
}
private void setupLights() {
@@ -175,27 +183,38 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
});
}
protected void setupBlockAndImportance() {
protected void setupBlock() {
View switchBarContainer = LayoutInflater.from(
getPrefContext()).inflate(R.layout.styled_switch_bar, null);
SwitchBar switchBar = switchBarContainer.findViewById(R.id.switch_bar);
switchBar.show();
switchBar.setDisabledByAdmin(mSuspendedAppsAdmin);
switchBar.setChecked(mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
switchBar.addOnSwitchChangeListener(new SwitchBar.OnSwitchChangeListener() {
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
int importance = isChecked ? IMPORTANCE_LOW : IMPORTANCE_NONE;
mImportance.setSummary(getImportanceSummary(importance));
mChannel.setImportance(importance);
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
mBackend.updateChannel(mPkg, mUid, mChannel);
updateDependents();
}
});
mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
mBlockBar.setOrder(-500);
mBlockBar.setKey(KEY_BLOCK);
getPreferenceScreen().addPreference(mBlockBar);
if (mAppRow.systemApp && mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE) {
setVisible(mBlock, false);
} else {
mBlock.setEnabled(mAppRow.systemApp);
mBlock.setDisabledByAdmin(mSuspendedAppsAdmin);
mBlock.setChecked(mChannel.getImportance() == NotificationManager.IMPORTANCE_NONE);
mBlock.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean value = (Boolean) newValue;
int importance = value ? IMPORTANCE_NONE : IMPORTANCE_LOW;
mImportance.setValue(String.valueOf(importance));
mChannel.setImportance(importance);
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
mBackend.updateChannel(mPkg, mUid, mChannel);
updateDependents();
return true;
}
});
setVisible(mBlockBar, false);
}
setupBlockDesc(R.string.channel_notifications_off_desc);
}
protected void setupBadge() {
mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
mBadge.setEnabled(mAppRow.showBadge);
mBadge.setChecked(mChannel.canShowBadge());
@@ -209,41 +228,21 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
return true;
}
});
}
mImportance.setDisabledByAdmin(mSuspendedAppsAdmin);
final int numImportances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1;
List<String> summaries = new ArrayList<>();
List<String> values = new ArrayList<>();
for (int i = 0; i < numImportances; i++) {
int importance = i + 1;
summaries.add(getImportanceSummary(importance));
values.add(String.valueOf(importance));
}
if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
// Add option to reset to letting the app decide
summaries.add(getImportanceSummary(NotificationManager.IMPORTANCE_UNSPECIFIED));
values.add(String.valueOf(NotificationManager.IMPORTANCE_UNSPECIFIED));
}
mImportance.setEntryValues(values.toArray(new String[0]));
mImportance.setEntries(summaries.toArray(new String[0]));
mImportance.setValue(String.valueOf(mChannel.getImportance()));
protected void setupImportance() {
Bundle channelArgs = new Bundle();
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
channelArgs.putString(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
ChannelImportanceSettings.class.getName(),
channelArgs, null, R.string.notification_importance_title, null,
false, getMetricsCategory());
mImportance.setIntent(channelIntent);
mImportance.setEnabled(mSuspendedAppsAdmin == null);
mImportance.setSummary(getImportanceSummary(mChannel.getImportance()));
if (mAppRow.lockedImportance) {
mImportance.setEnabled(false);
} else {
mImportance.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int importance = Integer.parseInt((String) newValue);
mChannel.setImportance(importance);
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
mBackend.updateChannel(mPkg, mUid, mChannel);
updateDependents();
return true;
}
});
}
}
private boolean isLockScreenSecure() {
@@ -292,6 +291,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
}
private void updateDependents() {
setVisible(mBlockedDesc, mChannel.getImportance() == IMPORTANCE_NONE);
setVisible(mBadge, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
setVisible(mImportance, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
setVisible(mLights, checkCanBeVisible(