Notification settings updates

- Footer preferences were too dim
- Fix text and target on recently sent apps
- Make 'behavior' a dialog
- reorder settings on apps page

Change-Id: Idf8056bc77ead89fe2025bbde3346861e23a3c8d
Fixes: 72652526
Fixes: 72651810
Fixes: 72652024
Bug: 72651953
Test: make RunSettingsRoboTests
This commit is contained in:
Julia Reynolds
2018-01-30 11:28:38 -05:00
parent 3b04494ac6
commit 4f3b556388
23 changed files with 147 additions and 461 deletions

View File

@@ -56,6 +56,7 @@ public class AllowSoundPreferenceController extends NotificationPreferenceContro
}
@Override
public void updateState(Preference preference) {
if (mChannel != null) {
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;

View File

@@ -120,7 +120,8 @@ public class AppNotificationSettings extends NotificationSettingsBase {
mControllers.add(new BadgePreferenceController(context, mBackend));
mControllers.add(new AllowSoundPreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new ImportancePreferenceController(context));
mControllers.add(new ImportancePreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new SoundPreferenceController(context, this,
mImportanceListener, mBackend));
mControllers.add(new LightsPreferenceController(context, mBackend));

View File

@@ -1,166 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE;
import static android.app.NotificationChannel.USER_LOCKED_SOUND;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MAX;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import android.content.Context;
import android.media.RingtoneManager;
import android.provider.SearchIndexableResource;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.widget.RadioButtonPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
public class ChannelImportanceSettings extends NotificationSettingsBase
implements RadioButtonPreference.OnClickListener, Indexable {
private static final String TAG = "NotiImportance";
private static final String KEY_IMPORTANCE_HIGH = "importance_high";
private static final String KEY_IMPORTANCE_DEFAULT = "importance_default";
private static final String KEY_IMPORTANCE_LOW = "importance_low";
private static final String KEY_IMPORTANCE_MIN = "importance_min";
List<RadioButtonPreference> mImportances = new ArrayList<>();
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_CHANNEL_IMPORTANCE;
}
@Override
public void onResume() {
super.onResume();
if (mAppRow == null || mChannel == null) {
Log.w(TAG, "Missing package or channel");
finish();
return;
}
createPreferenceHierarchy();
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.notification_importance;
}
@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
return null;
}
@Override
public void onPause() {
super.onPause();
}
private PreferenceScreen createPreferenceHierarchy() {
PreferenceScreen root = getPreferenceScreen();
for (int i = 0; i < root.getPreferenceCount(); i++) {
Preference pref = root.getPreference(i);
if (pref instanceof RadioButtonPreference) {
RadioButtonPreference radioPref = (RadioButtonPreference) pref;
radioPref.setOnClickListener(this);
mImportances.add(radioPref);
}
}
switch (mChannel.getImportance()) {
case IMPORTANCE_MIN:
updateRadioButtons(KEY_IMPORTANCE_MIN);
break;
case IMPORTANCE_LOW:
updateRadioButtons(KEY_IMPORTANCE_LOW);
break;
case IMPORTANCE_DEFAULT:
updateRadioButtons(KEY_IMPORTANCE_DEFAULT);
break;
case IMPORTANCE_HIGH:
case IMPORTANCE_MAX:
updateRadioButtons(KEY_IMPORTANCE_HIGH);
break;
}
return root;
}
private void updateRadioButtons(String selectionKey) {
for (RadioButtonPreference pref : mImportances) {
if (selectionKey.equals(pref.getKey())) {
pref.setChecked(true);
} else {
pref.setChecked(false);
}
}
}
@Override
public void onRadioButtonClicked(RadioButtonPreference clicked) {
int oldImportance = mChannel.getImportance();
switch (clicked.getKey()) {
case KEY_IMPORTANCE_HIGH:
mChannel.setImportance(IMPORTANCE_HIGH);
break;
case KEY_IMPORTANCE_DEFAULT:
mChannel.setImportance(IMPORTANCE_DEFAULT);
break;
case KEY_IMPORTANCE_LOW:
mChannel.setImportance(IMPORTANCE_LOW);
break;
case KEY_IMPORTANCE_MIN:
mChannel.setImportance(IMPORTANCE_MIN);
break;
}
updateRadioButtons(clicked.getKey());
// If you are moving from an importance level without sound to one with sound,
// but the sound you had selected was "Silence",
// then set sound for this channel to your default sound,
// because you probably intended to cause this channel to actually start making sound.
if (oldImportance < IMPORTANCE_DEFAULT
&& !SoundPreferenceController.hasValidSound(mChannel)
&& mChannel.getImportance() >= IMPORTANCE_DEFAULT) {
mChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),
mChannel.getAudioAttributes());
mChannel.lockFields(USER_LOCKED_SOUND);
}
mChannel.lockFields(USER_LOCKED_IMPORTANCE);
mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, mChannel);
}
}

View File

@@ -79,7 +79,8 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
mControllers = new ArrayList<>();
mControllers.add(new HeaderPreferenceController(context, this));
mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
mControllers.add(new ImportancePreferenceController(context));
mControllers.add(new ImportancePreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new AllowSoundPreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new SoundPreferenceController(context, this,

View File

@@ -30,9 +30,7 @@ import android.support.v7.preference.Preference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
import com.android.settings.applications.NotificationApps;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -153,15 +151,6 @@ public class ConfigureNotificationSettings extends DashboardFragment {
}
}
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
= new SummaryLoader.SummaryProviderFactory() {
@Override
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
SummaryLoader summaryLoader) {
return new NotificationApps.SummaryProvider(activity, summaryLoader);
}
};
/**
* For Search.
*/

View File

@@ -55,7 +55,6 @@ public class DeletedChannelsPreferenceController extends NotificationPreferenceC
preference.setTitle(mContext.getResources().getQuantityString(
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
}
preference.setEnabled(false);
preference.setSelectable(false);
}
}

View File

@@ -16,41 +16,39 @@
package com.android.settings.notification;
import static android.app.NotificationChannel.USER_LOCKED_SOUND;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.media.RingtoneManager;
import android.support.v7.preference.Preference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.RestrictedListPreference;
import com.android.settings.core.PreferenceControllerMixin;
public class ImportancePreferenceController extends NotificationPreferenceController
implements PreferenceControllerMixin {
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
private static final String KEY_IMPORTANCE = "importance";
private NotificationSettingsBase.ImportanceListener mImportanceListener;
// Ironically doesn't take an importance listener because the importance is not changed
// by this controller's preference but by the screen it links to.
public ImportancePreferenceController(Context context) {
super(context, null);
public ImportancePreferenceController(Context context,
NotificationSettingsBase.ImportanceListener importanceListener,
NotificationBackend backend) {
super(context, backend);
mImportanceListener = importanceListener;
}
@Override
public String getPreferenceKey() {
return KEY_IMPORTANCE;
}
private int getMetricsCategory() {
return MetricsProto.MetricsEvent.NOTIFICATION_TOPIC_NOTIFICATION;
}
@Override
public boolean isAvailable() {
@@ -63,51 +61,82 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
return !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
}
@Override
public void updateState(Preference preference) {
if (mAppRow!= null && mChannel != null) {
preference.setEnabled(mAdmin == null && isChannelConfigurable());
Bundle channelArgs = new Bundle();
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mAppRow.uid);
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mAppRow.pkg);
channelArgs.putString(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
if (preference.isEnabled()) {
Intent channelIntent = Utils.onBuildStartFragmentIntent(mContext,
ChannelImportanceSettings.class.getName(),
channelArgs, null,
R.string.notification_importance_title, null,
false, getMetricsCategory());
preference.setIntent(channelIntent);
preference.setSummary(getImportanceSummary(mContext, mChannel));
preference.setSummary(getImportanceSummary(mChannel));
int importances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1;
CharSequence[] entries = new CharSequence[importances];
CharSequence[] values = new CharSequence[importances];
int index = 0;
for (int i = IMPORTANCE_HIGH; i >= IMPORTANCE_MIN; i--) {
NotificationChannel channel = new NotificationChannel("", "", i);
entries[index] = getImportanceSummary(channel);
values[index] = String.valueOf(i);
index++;
}
RestrictedListPreference pref = (RestrictedListPreference) preference;
pref.setEntries(entries);
pref.setEntryValues(values);
pref.setValue(String.valueOf(mChannel.getImportance()));
}
}
protected static String getImportanceSummary(Context context, NotificationChannel channel) {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mChannel != null) {
final int importance = Integer.parseInt((String) newValue);
// If you are moving from an importance level without sound to one with sound,
// but the sound you had selected was "Silence",
// then set sound for this channel to your default sound,
// because you probably intended to cause this channel to actually start making sound.
if (mChannel.getImportance() < IMPORTANCE_DEFAULT
&& !SoundPreferenceController.hasValidSound(mChannel)
&& importance >= IMPORTANCE_DEFAULT) {
mChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),
mChannel.getAudioAttributes());
mChannel.lockFields(USER_LOCKED_SOUND);
}
mChannel.setImportance(importance);
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
saveChannel();
mImportanceListener.onImportanceChanged();
}
return true;
}
protected String getImportanceSummary(NotificationChannel channel) {
String summary = "";
int importance = channel.getImportance();
switch (importance) {
case IMPORTANCE_UNSPECIFIED:
summary = context.getString(R.string.notification_importance_unspecified);
summary = mContext.getString(R.string.notification_importance_unspecified);
break;
case NotificationManager.IMPORTANCE_MIN:
summary = context.getString(R.string.notification_importance_min);
summary = mContext.getString(R.string.notification_importance_min);
break;
case NotificationManager.IMPORTANCE_LOW:
summary = context.getString(R.string.notification_importance_low);
summary = mContext.getString(R.string.notification_importance_low);
break;
case NotificationManager.IMPORTANCE_DEFAULT:
if (SoundPreferenceController.hasValidSound(channel)) {
summary = context.getString(R.string.notification_importance_default);
summary = mContext.getString(R.string.notification_importance_default);
} else {
summary = context.getString(R.string.notification_importance_low);
summary = mContext.getString(R.string.notification_importance_low);
}
break;
case NotificationManager.IMPORTANCE_HIGH:
case NotificationManager.IMPORTANCE_MAX:
if (SoundPreferenceController.hasValidSound(channel)) {
summary = context.getString(R.string.notification_importance_high);
summary = mContext.getString(R.string.notification_importance_high);
} else {
summary = context.getString(R.string.notification_importance_high_silent);
summary = mContext.getString(R.string.notification_importance_high_silent);
}
break;
default:

View File

@@ -57,7 +57,6 @@ public class NotificationsOffPreferenceController extends NotificationPreference
preference.setTitle(R.string.app_notifications_off_desc);
}
}
preference.setEnabled(false);
preference.setSelectable(false);
}
}

View File

@@ -147,7 +147,8 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
@Override
protected void onCountComplete(int num) {
if (mHasRecentApps) {
mSeeAllPref.setTitle(mContext.getString(R.string.see_all_apps_title, num));
mSeeAllPref.setTitle(
mContext.getString(R.string.recent_notifications_see_all_title));
} else {
mSeeAllPref.setSummary(mContext.getString(R.string.apps_summary, num));
}