Add conversations image resource

- Conversations image resource is a compilation of the conversation
icons that are allowed to bypass DND
- Update category header text on DND > Display options for hidden notifications
page
- Update a11y bug in messages and calls pref pages that said images were
tappable

Test: manual
Bug: 151845457
Change-Id: I5387722abf0543b6e07378d498cc0085122c91b9
This commit is contained in:
Beverly
2020-03-31 16:25:37 -04:00
parent 93162ce9f4
commit 216bf3c320
9 changed files with 202 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 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.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/zen_mode_settings_senders_overlay_view"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
</RelativeLayout>

View File

@@ -89,6 +89,7 @@
<dimen name="zen_mode_button_padding_vertical">16dp</dimen>
<dimen name="zen_schedule_rule_checkbox_padding">7dp</dimen>
<dimen name="zen_schedule_day_margin">17dp</dimen>
<dimen name="zen_conversations_icon_size">56dp</dimen>
<dimen name="rect_button_radius">8dp</dimen>

View File

@@ -7809,6 +7809,8 @@
<!-- Do not disturb: restrict notifications settings title [CHAR LIMIT=80] -->
<string name="zen_mode_restrict_notifications_title">Display options for hidden notifications</string>
<!-- Do not disturb: Hide notifications screen category title [CHAR LIMIT=100] -->
<string name="zen_mode_restrict_notifications_category">When Do Not Disturb is on</string>
<!-- Do not disturb: Mute notifications option [CHAR LIMIT=60] -->
<string name="zen_mode_restrict_notifications_mute">No sound from notifications</string>
<!-- Do not disturb:Mute notifications summary [CHAR LIMIT=NONE] -->

View File

@@ -29,7 +29,8 @@
<!-- Senders image -->
<com.android.settingslib.widget.LayoutPreference
android:key="zen_mode_calls_image"
android:layout="@layout/zen_mode_senders_image" />
android:layout="@layout/zen_mode_senders_image"
android:selectable="false"/>
</PreferenceCategory>
<!-- Repeat callers -->

View File

@@ -21,6 +21,11 @@
<PreferenceCategory
android:key="zen_mode_conversations_radio_buttons"
android:title="@string/zen_mode_conversations_section_title">
<!-- TODO: add preference with chat images here (b/151845457) -->
<!-- Senders image -->
<com.android.settingslib.widget.LayoutPreference
android:key="zen_mode_conversations_image"
android:layout="@layout/zen_mode_senders_overlay_image"
android:selectable="false"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -27,7 +27,8 @@
<!-- Senders image -->
<com.android.settingslib.widget.LayoutPreference
android:key="zen_mode_messages_image"
android:layout="@layout/zen_mode_senders_image" />
android:layout="@layout/zen_mode_senders_image"
android:selectable="false"/>
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference/>

View File

@@ -22,7 +22,7 @@
<PreferenceCategory
android:key="restrict_category"
android:title="@string/zen_mode_settings_category">
android:title="@string/zen_mode_restrict_notifications_category">
<com.android.settings.notification.zen.ZenCustomRadioButtonPreference
android:key="zen_mute_notifications"
android:title="@string/zen_mode_restrict_notifications_mute"

View File

@@ -0,0 +1,161 @@
/*
* Copyright (C) 2020 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.zen;
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE;
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT;
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_NONE;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.service.notification.ConversationChannelWrapper;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.LayoutPreference;
import java.util.ArrayList;
import java.util.List;
/**
* Updates the DND Settings conversations image resource based on the conversations channels.
*/
public class ZenModeConversationsImagePreferenceController
extends AbstractZenModePreferenceController {
private static final int MAX_CONVERSATIONS_SHOWN = 5;
private final int mIconSizePx;
private final int mIconOffsetPx;
private final ArrayList<Drawable> mConversationDrawables = new ArrayList<>();
private final NotificationBackend mNotificationBackend;
private ViewGroup mViewGroup;
private LayoutPreference mPreference;
public ZenModeConversationsImagePreferenceController(Context context, String key,
Lifecycle lifecycle, NotificationBackend notificationBackend) {
super(context, key, lifecycle);
mNotificationBackend = notificationBackend;
mIconSizePx =
mContext.getResources().getDimensionPixelSize(R.dimen.zen_conversations_icon_size);
mIconOffsetPx = mIconSizePx * 3 / 4;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (LayoutPreference) screen.findPreference(KEY);
mViewGroup =
(ViewGroup) mPreference.findViewById(R.id.zen_mode_settings_senders_overlay_view);
loadConversations();
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public void updateState(Preference preference) {
loadConversations();
mViewGroup.removeAllViews();
final int conversationSenders = mBackend.getPriorityConversationSenders();
if (conversationSenders == CONVERSATION_SENDERS_ANYONE) {
mViewGroup.setContentDescription(
mContext.getResources().getString(R.string.zen_mode_from_all_conversations));
} else if (conversationSenders == CONVERSATION_SENDERS_IMPORTANT) {
mViewGroup.setContentDescription(
mContext.getResources().getString(
R.string.zen_mode_from_important_conversations));
} else {
mViewGroup.setContentDescription(null);
}
final int numDrawablesToShow = Math.min(MAX_CONVERSATIONS_SHOWN,
mConversationDrawables.size());
for (int i = 0; i < numDrawablesToShow; i++) {
ImageView iv = new ImageView(mContext);
iv.setImageDrawable(mConversationDrawables.get(i));
iv.setLayoutParams(new ViewGroup.LayoutParams(mIconSizePx, mIconSizePx));
FrameLayout fl = new FrameLayout(mContext);
fl.addView(iv);
fl.setPadding((numDrawablesToShow - i - 1) * mIconOffsetPx, 0, 0, 0);
mViewGroup.addView(fl);
}
}
private void loadConversations() {
// Load conversations
new AsyncTask<Void, Void, Void>() {
private List<Drawable> mDrawables = new ArrayList<>();
@Override
protected Void doInBackground(Void... unused) {
mDrawables.clear();
final int conversationSenders = mBackend.getPriorityConversationSenders();
if (conversationSenders == CONVERSATION_SENDERS_NONE) {
return null;
}
ParceledListSlice<ConversationChannelWrapper> conversations =
mNotificationBackend.getConversations(
conversationSenders == CONVERSATION_SENDERS_IMPORTANT);
if (conversations != null) {
for (ConversationChannelWrapper conversation : conversations.getList()) {
if (!conversation.getNotificationChannel().isDemoted()) {
Drawable drawable = mNotificationBackend.getConversationDrawable(
mContext,
conversation.getShortcutInfo(),
conversation.getPkg(),
conversation.getUid(),
conversation.getNotificationChannel()
.isImportantConversation());
if (drawable != null) {
mDrawables.add(drawable);
}
}
}
}
return null;
}
@Override
protected void onPostExecute(Void unused) {
if (mContext == null) {
return;
}
mConversationDrawables.clear();
mConversationDrawables.addAll(mDrawables);
updateState(mPreference);
}
}.execute();
}
}

View File

@@ -44,6 +44,8 @@ public class ZenModeConversationsSettings extends ZenModeSettingsBase {
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, NotificationBackend notificationBackend) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeConversationsImagePreferenceController(context,
"zen_mode_conversations_image", lifecycle, notificationBackend));
controllers.add(new ZenModePriorityConversationsPreferenceController(context,
"zen_mode_conversations_radio_buttons", lifecycle, notificationBackend));
return controllers;