Clean up notification settings

- Reorganize settings
- Fix dividers
- Add icons
- Fix titles
- Fix colors
- Fix indentation
- Add summaries

Fixes: 190079590
Test: manual inspection, robotests

Change-Id: Ia03219575d3b0c78f9f9b088aa3cdaa29cfdf412
This commit is contained in:
Julia Reynolds
2021-06-17 16:31:35 -04:00
parent 0fcac8bf0d
commit 6a603e7f4b
21 changed files with 231 additions and 135 deletions

View File

@@ -15,9 +15,10 @@
limitations under the License.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:shape="rectangle">
<solid
android:color="@color/notification_importance_selection_bg" />
android:color="?androidprv:attr/colorSurface" />
<stroke
android:width="2dp"
android:color="?android:attr/colorAccent"/>

View File

@@ -16,6 +16,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="32dip" android:height="32dip" />
<size android:width="24dp" android:height="24dp" />
<solid android:color="@android:color/transparent" />
</shape>

View File

@@ -17,8 +17,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2021 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M22,6.98V16c0,1.1 -0.9,2 -2,2H6l-4,4V4c0,-1.1 0.9,-2 2,-2h10.1C14.04,2.32 14,2.66 14,3s0.04,0.68 0.1,1H4v12h16V7.9C20.74,7.75 21.42,7.42 22,6.98zM16,3c0,1.66 1.34,3 3,3s3,-1.34 3,-3s-1.34,-3 -3,-3S16,1.34 16,3z"/>
</vector>

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2021 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M6,19h12v2H6v-2z"/>
</vector>

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2021 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M17,1L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,3c0,-1.1 -0.9,-2 -2,-2zM17,21L7,21v-1h10v1zM17,18L7,18L7,6h10v12zM17,4L7,4L7,3h10v1zM8,7h8v2L8,9z"/>
</vector>

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2021 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M17,1.01L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,3c0,-1.1 -0.9,-1.99 -2,-1.99zM17,21L7,21v-1h10v1zM17,18L7,18L7,6h10v12zM7,4L7,3h10v1L7,4zM14.25,10.5v-0.66c0,-1.13 -1.03,-2.09 -2.25,-2.09s-2.25,0.96 -2.25,2.09v0.66L9,10.5L9,16h6v-5.5h-0.75zM12.75,10.5h-1.5v-0.66c0,-0.29 0.38,-0.59 0.75,-0.59s0.75,0.3 0.75,0.59v0.66z"/>
</vector>

View File

@@ -17,8 +17,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FFFFFF"

View File

@@ -22,7 +22,7 @@
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginEnd="16dp"
android:paddingTop="@dimen/notification_importance_toggle_marginTop"
android:paddingBottom="@dimen/notification_importance_toggle_marginTop"
android:orientation="vertical">

View File

@@ -21,7 +21,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/notification_importance_toggle_marginTop"
android:layout_marginStart="24dp"
android:layout_marginEnd="16dp"
android:paddingTop="@dimen/notification_importance_toggle_marginTop"
android:paddingBottom="@dimen/notification_importance_toggle_marginTop"
android:orientation="vertical">
<com.android.settings.notification.NotificationButtonRelativeLayout

View File

@@ -8797,11 +8797,14 @@
<string name="recent_notifications_see_all_title">See all from last 7 days</string>
<!-- notification header for general notification settings [CHAR LIMIT=80]-->
<string name="general_notification_header">General</string>
<string name="general_notification_header">Manage</string>
<!-- notification preference for app specific notification settings [CHAR LIMIT=80]-->
<string name="app_notification_field">App settings</string>
<!-- notification preference summary for app specific notification settings [CHAR LIMIT=120]-->
<string name="app_notification_field_summary">Control notifications from individual apps</string>
<!-- Configure Notifications: Advanced section header [CHAR LIMIT=30] -->
<string name="advanced_section_header">General</string>
@@ -9251,7 +9254,7 @@
<!-- Sound & notification > Advanced section: Title for managing notification listeners option. [CHAR LIMIT=60] -->
<string name="manage_notification_access_title">Device &amp; app notifications</string>
<string name="manage_notification_access_summary">Control which notifications show on your apps and devices</string>
<string name="manage_notification_access_summary">Control which apps and devices can read notifications</string>
<!-- Notification Access section: Indicates that the work profile admin doesn't allow this
notification listener to access work profile notifications [CHAR LIMIT=100] -->

View File

@@ -58,7 +58,16 @@
android:key="channels"
android:layout="@layout/empty_view"
settings:allowDividerAbove="true"
settings:allowDividerBelow="false" />
settings:allowDividerBelow="true" />
<!-- Show badge -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="badge"
android:title="@string/notification_badge_title"
settings:useAdditionalSummary="true"
android:order="1001"
settings:allowDividerAbove="true"
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
<!-- Importance toggle -->
<com.android.settingslib.RestrictedSwitchPreference
@@ -75,26 +84,14 @@
<com.android.settingslib.RestrictedSwitchPreference
android:key="bypass_dnd"
android:title="@string/app_notification_override_dnd_title"
android:summary="@string/app_notification_override_dnd_summary"
settings:useAdditionalSummary="true"/>
android:summary="@string/app_notification_override_dnd_summary"/>
<PreferenceCategory
android:key="app_advanced"
android:order="1000">
<!-- Show badge -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="badge"
android:title="@string/notification_badge_title"
settings:useAdditionalSummary="true"
android:order="1001"
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
<Preference
android:key="app_link"
android:order="1003"
android:icon="@drawable/ic_settings_24dp"
android:title="@string/app_settings_link" />
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference
android:key="desc"
android:order="5000" />

View File

@@ -34,26 +34,26 @@
android:key="allow_sound"
android:order="3"
android:title="@string/allow_interruption"
android:icon="@drawable/empty_icon"
android:summary="@string/allow_interruption_summary" />
<!-- Importance -->
<com.android.settings.notification.app.ImportancePreference
android:key="importance"
android:order="4"
android:title="@string/notification_importance_title"
settings:allowDividerBelow="true"/>
android:title="@string/notification_importance_title" />
<com.android.settingslib.RestrictedSwitchPreference
android:key="min_importance"
android:order="5"
settings:allowDividerAbove="true"
android:icon="@drawable/ic_notification_min"
android:title="@string/notification_importance_min_title"
android:summary="@string/notification_channel_summary_min"/>
<com.android.settingslib.RestrictedSwitchPreference
android:key="high_importance"
android:order="6"
settings:allowDividerAbove="true"
android:icon="@drawable/ic_notification_peek"
android:title="@string/notification_importance_high_title"
android:summary="@string/notification_channel_summary_high"/>
@@ -62,14 +62,14 @@
android:order="7"
android:icon="@drawable/ic_promote_conversation"
android:title="@string/promote_conversation_title"
android:summary="@string/promote_conversation_summary"
settings:allowDividerAbove="true"/>
android:summary="@string/promote_conversation_summary" />
<!-- Default ringtone -->
<com.android.settings.notification.app.NotificationSoundPreference
android:key="ringtone"
android:title="@string/notification_channel_sound_title"
android:dialogTitle="@string/notification_channel_sound_title"
android:icon="@drawable/ic_notifications"
android:order="11"
android:showSilent="true"
android:showDefault="true"/>
@@ -78,48 +78,46 @@
<com.android.settingslib.RestrictedSwitchPreference
android:key="vibrate"
android:order="12"
android:title="@string/notification_vibrate_title"
settings:useAdditionalSummary="true" />
android:icon="@drawable/ic_volume_ringer_vibrate"
android:title="@string/notification_vibrate_title" />
<!-- Visibility Override -->
<com.android.settings.RestrictedListPreference
android:key="visibility_override"
android:order="13"
android:icon="@drawable/ic_notification_vis_override"
android:title="@string/app_notification_visibility_override_title"/>
<!-- Lights -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="lights"
android:order="14"
android:title="@string/notification_show_lights_title"
settings:useAdditionalSummary="true"/>
android:icon="@drawable/ic_lightbulb_outline_24"
android:title="@string/notification_show_lights_title" />
<!-- Show badge -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="badge"
android:order="15"
android:title="@string/notification_channel_badge_title"
settings:useAdditionalSummary="true"
android:icon="@drawable/ic_notification_dot"
settings:restrictedSwitchSummary="@string/enabled_by_admin"/>
<!-- Bypass DND -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="bypass_dnd"
android:order="17"
android:icon="@drawable/ic_do_not_disturb_on_24dp"
android:title="@string/app_notification_override_dnd_title"
android:summary="@string/app_notification_override_dnd_summary"
settings:useAdditionalSummary="true"/>
android:summary="@string/app_notification_override_dnd_summary" />
<Preference
android:key="app_link"
android:order="18"
android:title="@string/app_settings_link"
android:icon="@drawable/ic_settings_24dp"
settings:allowDividerAbove="true"/>
<com.android.settingslib.widget.FooterPreference
android:key="desc"
android:order="100"/>
<com.android.settingslib.widget.FooterPreference
android:key="block_desc"
android:order="110"

View File

@@ -26,6 +26,7 @@
android:key="all_notifications"
android:order="10"
android:title="@string/app_notification_field"
android:summary="@string/app_notification_field_summary"
android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
settings:searchable="false">
<extra
@@ -42,13 +43,6 @@
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.notification.history.NotificationHistoryActivity" />
</Preference>
<Preference
android:key="notification_access"
android:order="12"
android:title="@string/manage_notification_access_title"
android:summary="@string/manage_notification_access_summary"
android:fragment="com.android.settings.notification.NotificationAccessSettings"
settings:controller="com.android.settings.applications.specialaccess.notificationaccess.NotificationAccessController" />
</PreferenceCategory>
<PreferenceCategory
@@ -75,6 +69,13 @@
<PreferenceCategory
android:key="configure_notifications_lock"
android:title="@string/lock_screen_notifications_title">
<Preference
android:key="notification_access"
android:order="12"
android:title="@string/manage_notification_access_title"
android:summary="@string/manage_notification_access_summary"
android:fragment="com.android.settings.notification.NotificationAccessSettings"
settings:controller="com.android.settings.applications.specialaccess.notificationaccess.NotificationAccessController" />
<!-- When device is locked -->
<com.android.settings.RestrictedListPreference
android:key="lock_screen_notifications"

View File

@@ -32,41 +32,23 @@
settings:allowDividerAbove="true"
settings:allowDividerBelow="true"/>
<PreferenceCategory
android:key="bubbles"
android:title="@string/notification_bubbles_title">
<!-- bubbles -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="bubble_pref"
android:title="@string/bubbles_conversation_toggle_title"
android:summary="@string/bubbles_conversation_toggle_summary"
android:icon="@drawable/ic_create_bubble"
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
<Preference
android:key="notification_bubbles"
android:title="@string/bubbles_conversation_app_link"
/>
</PreferenceCategory>
<!-- demote -->
<Preference
android:key="demote"
android:icon="@drawable/ic_demote_conversation"
android:title="@string/demote_conversation_title"
android:summary="@string/demote_conversation_summary"
settings:allowDividerAbove="true"/>
<!-- bubbles -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="bubble_pref"
android:title="@string/bubbles_conversation_toggle_title"
android:summary="@string/bubbles_conversation_toggle_summary"
android:icon="@drawable/ic_create_bubble"
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
<com.android.settingslib.widget.FooterPreference
android:key="block_desc"
settings:allowDividerAbove="false"/>
<!-- peeking -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="high_importance"
android:title="@string/notification_importance_high_title"
android:icon="@drawable/ic_notification_peek"
android:summary="@string/notification_channel_summary_high"/>
<!-- ringtone -->
@@ -81,27 +63,34 @@
<!-- Visibility Override -->
<com.android.settings.RestrictedListPreference
android:key="visibility_override"
android:icon="@drawable/ic_lock_closed"
android:icon="@drawable/ic_notification_vis_override"
android:title="@string/app_notification_visibility_override_title"/>
<!-- Show badge -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="badge"
android:title="@string/notification_channel_badge_title"
settings:useAdditionalSummary="true"
android:icon="@drawable/ic_notification_dot"
settings:restrictedSwitchSummary="@string/enabled_by_admin"/>
<!-- Lights -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="lights"
android:title="@string/notification_show_lights_title"
settings:useAdditionalSummary="true"/>
android:icon="@drawable/ic_lightbulb_outline_24"
android:title="@string/notification_show_lights_title"/>
<!-- Vibration -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="vibrate"
android:icon="@drawable/ic_volume_ringer_vibrate"
android:title="@string/notification_vibrate_title"
settings:useAdditionalSummary="true" />
android:title="@string/notification_vibrate_title" />
<!-- demote -->
<Preference
android:key="demote"
android:icon="@drawable/ic_demote_conversation"
android:title="@string/demote_conversation_title"
android:summary="@string/demote_conversation_summary"
settings:allowDividerAbove="true"/>
</PreferenceScreen>

View File

@@ -25,9 +25,11 @@ import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
@@ -38,35 +40,11 @@ public class AppNotificationSettings extends NotificationSettings {
private static final String TAG = "AppNotificationSettings";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private static String KEY_ADVANCED_CATEGORY = "app_advanced";
private static String KEY_BADGE = "badge";
private static String KEY_APP_LINK = "app_link";
private static String[] LEGACY_NON_ADVANCED_KEYS = {KEY_BADGE, KEY_APP_LINK};
@Override
public int getMetricsCategory() {
return SettingsEnums.NOTIFICATION_APP_NOTIFICATION;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final PreferenceScreen screen = getPreferenceScreen();
if (mShowLegacyChannelConfig && screen != null) {
// if showing legacy settings, pull advanced settings out of the advanced category
PreferenceGroup advanced = (PreferenceGroup) findPreference(KEY_ADVANCED_CATEGORY);
removePreference(KEY_ADVANCED_CATEGORY);
if (advanced != null) {
for (String key : LEGACY_NON_ADVANCED_KEYS) {
Preference pref = advanced.findPreference(key);
advanced.removePreference(pref);
if (pref != null) {
screen.addPreference(pref);
}
}
}
}
}
@Override
public void onResume() {
@@ -78,6 +56,8 @@ public class AppNotificationSettings extends NotificationSettings {
return;
}
getActivity().setTitle(mAppRow.label);
for (NotificationPreferenceController controller : mControllers) {
controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin,
null);

View File

@@ -322,7 +322,7 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
if (channel.getImportance() > IMPORTANCE_LOW) {
channelPref.setIcon(getAlertingIcon());
} else {
channelPref.setIcon(null);
channelPref.setIcon(R.drawable.empty_icon);
}
channelPref.setIconSize(PrimarySwitchPreference.ICON_SIZE_SMALL);
channelPref.setTitle(channel.getName());
@@ -350,7 +350,7 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
channel.setImportance(importance);
channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
PrimarySwitchPreference channelPref1 = (PrimarySwitchPreference) preference;
channelPref1.setIcon(null);
channelPref1.setIcon(R.drawable.empty_icon);
if (channel.getImportance() > IMPORTANCE_LOW) {
channelPref1.setIcon(getAlertingIcon());
}

View File

@@ -66,8 +66,9 @@ public class ChannelNotificationSettings extends NotificationSettings {
return;
}
if (mChannel != null && !TextUtils.isEmpty(mChannel.getConversationId())
&& !mChannel.isDemoted()) {
getActivity().setTitle(mChannel.getName());
if (!TextUtils.isEmpty(mChannel.getConversationId()) && !mChannel.isDemoted()) {
Intent intent = new SubSettingLauncher(mContext)
.setDestination(ConversationNotificationSettings.class.getName())
.setArguments(getArguments())
@@ -128,7 +129,6 @@ public class ChannelNotificationSettings extends NotificationSettings {
mDependentFieldListener, mBackend));
mControllers.add(new VibrationPreferenceController(context, mBackend));
mControllers.add(new AppLinkPreferenceController(context));
mControllers.add(new DescriptionPreferenceController(context));
mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
mBackend));
mControllers.add(new LightsPreferenceController(context, mBackend));

View File

@@ -41,11 +41,13 @@ public class ConversationNotificationSettings extends NotificationSettings {
@Override
public void onResume() {
super.onResume();
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) {
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null
|| mConversationInfo == null) {
Log.w(TAG, "Missing package or uid or packageinfo or channel");
finish();
return;
}
getActivity().setTitle(mConversationInfo.getLabel());
for (NotificationPreferenceController controller : mControllers) {
controller.onResume(mAppRow, mChannel, mChannelGroup, mConversationDrawable,

View File

@@ -84,6 +84,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController
pref = mHeaderController.setIcon(mAppRow.icon)
.setLabel(getLabel())
.setSummary(getSummary())
.setSecondSummary(getSecondSummary())
.setPackageName(mAppRow.pkg)
.setUid(mAppRow.uid)
.setButtonActions(EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
@@ -96,25 +97,11 @@ public class HeaderPreferenceController extends NotificationPreferenceController
}
}
@Override
public CharSequence getSummary() {
public CharSequence getLabel() {
if (mChannel != null && !isDefaultChannel()) {
if (mChannelGroup != null
&& !TextUtils.isEmpty(mChannelGroup.getName())) {
final SpannableStringBuilder summary = new SpannableStringBuilder();
BidiFormatter bidi = BidiFormatter.getInstance();
summary.append(bidi.unicodeWrap(mAppRow.label.toString()));
summary.append(bidi.unicodeWrap(mContext.getText(
R.string.notification_header_divider_symbol_with_spaces)));
summary.append(bidi.unicodeWrap(mChannelGroup.getName().toString()));
return summary.toString();
} else {
return mAppRow.label.toString();
}
} else if (mChannelGroup != null) {
return mAppRow.label.toString();
return mChannel.getName();
} else {
return "";
return mAppRow.label;
}
}
@@ -123,11 +110,26 @@ public class HeaderPreferenceController extends NotificationPreferenceController
mStarted = true;
}
@VisibleForTesting
CharSequence getLabel() {
return (mChannel != null && !isDefaultChannel()) ? mChannel.getName()
: mChannelGroup != null
? mChannelGroup.getName()
: mAppRow.label;
@Override
public CharSequence getSummary() {
if (mChannel != null) {
if (mChannelGroup != null
&& !TextUtils.isEmpty(mChannelGroup.getName())) {
final SpannableStringBuilder summary = new SpannableStringBuilder();
BidiFormatter bidi = BidiFormatter.getInstance();
summary.append(bidi.unicodeWrap(mAppRow.label));
summary.append(bidi.unicodeWrap(mContext.getText(
R.string.notification_header_divider_symbol_with_spaces)));
summary.append(bidi.unicodeWrap(mChannelGroup.getName().toString()));
return summary.toString();
} else {
return mAppRow.label.toString();
}
}
return "";
}
public CharSequence getSecondSummary() {
return mChannel == null ? null : mChannel.getDescription();
}
}

View File

@@ -118,7 +118,7 @@ public class HeaderPreferenceControllerTest {
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
mController.onResume(appRow, null, group, null, null, null, null);
assertEquals(group.getName(), mController.getLabel());
assertEquals(appRow.label, mController.getLabel());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null, null, null, null);
@@ -155,4 +155,24 @@ public class HeaderPreferenceControllerTest {
mController.onResume(appRow, defaultChannel, null, null, null, null, null);
assertEquals("", mController.getSummary());
}
@Test
public void testGetSecondSummary() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "bananas";
mController.onResume(appRow, null, null, null, null, null, null);
assertEquals("", mController.getSecondSummary());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
mController.onResume(appRow, null, group, null, null, null, null);
assertEquals("", mController.getSecondSummary());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null, null, null, null);
assertEquals("", mController.getSecondSummary());
channel.setDescription("description");
mController.onResume(appRow, channel, group, null, null, null, null);
assertEquals("description", mController.getSecondSummary());
}
}