Merge "Add tap targets to top 2 sections" into rvc-dev am: 9db658bfe0 am: 9d9504f951 am: 99ab33a0fa am: 4448e97222

Change-Id: I0dc36cad82a368a460fd0bb40fcfa37ff2a14026
This commit is contained in:
TreeHugger Robot
2020-03-30 18:10:23 +00:00
committed by Automerger Merge Worker
3 changed files with 46 additions and 6 deletions

View File

@@ -8093,6 +8093,9 @@
<!-- Notification history screen; content description describing what happens when you tap on a notification history entry [CHAR LIMIT=NONE] --> <!-- Notification history screen; content description describing what happens when you tap on a notification history entry [CHAR LIMIT=NONE] -->
<string name="notification_history_view_settings">view notification settings</string> <string name="notification_history_view_settings">view notification settings</string>
<!-- Notification history screen; content description describing what happens when you tap on a snoozed or recently dismissed notification [CHAR LIMIT=NONE] -->
<string name="notification_history_open_notification">open notification</string>
<!-- Configure Notifications: setting title, whether the snooze menu is shown on notifications [CHAR LIMIT=80] --> <!-- Configure Notifications: setting title, whether the snooze menu is shown on notifications [CHAR LIMIT=80] -->
<string name="snooze_options_title">Allow notification snoozing</string> <string name="snooze_options_title">Allow notification snoozing</string>

View File

@@ -20,7 +20,6 @@ import static android.app.Notification.COLOR_DEFAULT;
import static android.content.pm.PackageManager.MATCH_ANY_USER; import static android.content.pm.PackageManager.MATCH_ANY_USER;
import static android.content.pm.PackageManager.NameNotFoundException; import static android.content.pm.PackageManager.NameNotFoundException;
import static android.os.UserHandle.USER_ALL; import static android.os.UserHandle.USER_ALL;
import static android.os.UserHandle.USER_CURRENT;
import android.annotation.ColorInt; import android.annotation.ColorInt;
import android.annotation.UserIdInt; import android.annotation.UserIdInt;
@@ -48,7 +47,6 @@ import com.android.internal.util.ContrastColorUtil;
import com.android.settings.R; import com.android.settings.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Currency;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -92,7 +90,7 @@ public class NotificationSbnAdapter extends
final StatusBarNotification sbn = mValues.get(position); final StatusBarNotification sbn = mValues.get(position);
if (sbn != null) { if (sbn != null) {
holder.setIcon(loadIcon(sbn)); holder.setIcon(loadIcon(sbn));
holder.setPackageName(loadPackageName(sbn.getPackageName()).toString()); holder.setPackageLabel(loadPackageLabel(sbn.getPackageName()).toString());
holder.setTitle(getTitleString(sbn.getNotification())); holder.setTitle(getTitleString(sbn.getNotification()));
holder.setSummary(getTextString(mContext, sbn.getNotification())); holder.setSummary(getTextString(mContext, sbn.getNotification()));
holder.setPostedTime(sbn.getPostTime()); holder.setPostedTime(sbn.getPostTime());
@@ -103,6 +101,8 @@ public class NotificationSbnAdapter extends
mUserBadgeCache.put(userId, profile); mUserBadgeCache.put(userId, profile);
} }
holder.setProfileBadge(mUserBadgeCache.get(userId)); holder.setProfileBadge(mUserBadgeCache.get(userId));
holder.addOnClick(sbn.getPackageName(), sbn.getUserId(),
sbn.getNotification().contentIntent);
} else { } else {
Slog.w(TAG, "null entry in list at position " + position); Slog.w(TAG, "null entry in list at position " + position);
} }
@@ -133,7 +133,7 @@ public class NotificationSbnAdapter extends
notifyDataSetChanged(); notifyDataSetChanged();
} }
private @NonNull CharSequence loadPackageName(String pkg) { private @NonNull CharSequence loadPackageLabel(String pkg) {
try { try {
ApplicationInfo info = mPm.getApplicationInfo(pkg, ApplicationInfo info = mPm.getApplicationInfo(pkg,
MATCH_ANY_USER); MATCH_ANY_USER);

View File

@@ -16,19 +16,26 @@
package com.android.settings.notification.history; package com.android.settings.notification.history;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon; import android.os.UserHandle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Slog;
import android.view.View; import android.view.View;
import android.widget.DateTimeView; import android.widget.DateTimeView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.view.AccessibilityDelegateCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R; import com.android.settings.R;
public class NotificationSbnViewHolder extends RecyclerView.ViewHolder { public class NotificationSbnViewHolder extends RecyclerView.ViewHolder {
private static final String TAG = "SbnViewHolder";
private final TextView mPkgName; private final TextView mPkgName;
private final ImageView mIcon; private final ImageView mIcon;
@@ -63,7 +70,7 @@ public class NotificationSbnViewHolder extends RecyclerView.ViewHolder {
mIcon.setImageDrawable(icon); mIcon.setImageDrawable(icon);
} }
void setPackageName(String pkg) { void setPackageLabel(String pkg) {
mPkgName.setText(pkg); mPkgName.setText(pkg);
} }
@@ -74,4 +81,34 @@ public class NotificationSbnViewHolder extends RecyclerView.ViewHolder {
void setProfileBadge(Drawable badge) { void setProfileBadge(Drawable badge) {
mProfileBadge.setImageDrawable(badge); mProfileBadge.setImageDrawable(badge);
} }
void addOnClick(String pkg, int userId, PendingIntent pi) {
itemView.setOnClickListener(v -> {
if (pi != null) {
try {
pi.send();
} catch (PendingIntent.CanceledException e) {
Slog.e(TAG, "Could not launch", e);
}
} else {
Intent appIntent = new Intent(Intent.ACTION_MAIN)
.setPackage(pkg);
appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
itemView.getContext().startActivityAsUser(appIntent, UserHandle.of(userId));
}
});
ViewCompat.setAccessibilityDelegate(itemView, new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityNodeInfo(View host,
AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
CharSequence description = host.getResources().getText(
R.string.notification_history_open_notification);
AccessibilityNodeInfoCompat.AccessibilityActionCompat customClick =
new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_CLICK, description);
info.addAction(customClick);
}
});
}
} }