summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-11-30 23:32:06 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-11-30 23:32:06 +0000
commit8b819c0a03340b8a27795c2444fbf8caa1834f94 (patch)
treeda0da126c8653d57df76b82845387e925d8422dc /core/java
parent77ac1a413a7e857cf782d7eec15f1a576a96b7d0 (diff)
parentb00728fd4a127db43242593477e91c7fa3ac634b (diff)
Merge "Show largeIcon on the left when grouped."
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/Notification.java102
1 files changed, 66 insertions, 36 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index a886beddf64c..d5572bf130c1 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -30,6 +30,7 @@ import android.annotation.IdRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.Px;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
@@ -5105,33 +5106,29 @@ public class Notification implements Parcelable
if (result == null) {
result = new TemplateBindResult();
}
- boolean largeIconShown = bindLargeIcon(contentView, p);
+ final boolean largeIconShown = bindLargeIcon(contentView, p);
calculateLargeIconMarginEnd(largeIconShown, result);
if (p.mHeaderless) {
// views in the headerless (collapsed) state
- contentView.setViewLayoutMarginEnd(R.id.notification_standard_view_column,
- result.getHeadingExtraMarginEnd());
+ result.mHeadingExtraMarginSet.applyToView(contentView,
+ R.id.notification_headerless_view_column);
} else {
// views in states with a header (big states)
- contentView.setInt(R.id.notification_header, "setTopLineExtraMarginEnd",
- result.getHeadingExtraMarginEnd());
- contentView.setViewLayoutMarginEnd(R.id.line1, result.getTitleMarginEnd());
+ result.mHeadingExtraMarginSet.applyToView(contentView, R.id.notification_header);
+ result.mTitleMarginSet.applyToView(contentView, R.id.line1);
}
}
private void calculateLargeIconMarginEnd(boolean largeIconShown,
@NonNull TemplateBindResult result) {
- int contentMargin = mContext.getResources().getDimensionPixelSize(
+ final Resources resources = mContext.getResources();
+ final int contentMargin = resources.getDimensionPixelOffset(
R.dimen.notification_content_margin_end);
- int expanderSize = mContext.getResources().getDimensionPixelSize(
+ final int expanderSize = resources.getDimensionPixelSize(
R.dimen.notification_header_expand_icon_size) - contentMargin;
- int extraMarginEnd = 0;
- if (largeIconShown) {
- int iconSize = mContext.getResources().getDimensionPixelSize(
- R.dimen.notification_right_icon_size);
- extraMarginEnd = iconSize + contentMargin;
- }
- result.setRightIconState(largeIconShown, extraMarginEnd, expanderSize);
+ final int extraMarginEndIfVisible = resources.getDimensionPixelSize(
+ R.dimen.notification_right_icon_size) + contentMargin;
+ result.setRightIconState(largeIconShown, extraMarginEndIfVisible, expanderSize);
}
/**
@@ -7759,8 +7756,10 @@ public class Notification implements Parcelable
addExtras(mBuilder.mN.extras);
if (!isConversationLayout) {
// also update the end margin if there is an image
+ // NOTE: This template doesn't support moving this icon to the left, so we don't
+ // need to fully apply the MarginSet
contentView.setViewLayoutMarginEnd(R.id.notification_messaging,
- bindResult.getHeadingExtraMarginEnd());
+ bindResult.mHeadingExtraMarginSet.getValue());
}
contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor",
mBuilder.isColorized(p)
@@ -8757,9 +8756,8 @@ public class Notification implements Parcelable
if (!headerless) {
// also update the end margin to account for the large icon or expander
Resources resources = mBuilder.mContext.getResources();
- int endMargin = resources.getDimensionPixelSize(
- R.dimen.notification_content_margin_end) + result.getTitleMarginEnd();
- remoteViews.setViewLayoutMarginEnd(R.id.notification_main_column, endMargin);
+ result.mTitleMarginSet.applyToView(remoteViews, R.id.notification_main_column,
+ resources.getDimensionPixelOffset(R.dimen.notification_content_margin_end));
}
}
@@ -10997,42 +10995,74 @@ public class Notification implements Parcelable
*/
private static class TemplateBindResult {
boolean mRightIconVisible;
- int mRightIconMarginEnd;
- int mExpanderSize;
/**
- * @return the margin end that needs to be added to the heading so that it won't overlap
+ * The margin end that needs to be added to the heading so that it won't overlap
* with the large icon. This value includes the space required to accommodate the large
* icon, but should be added to the space needed to accommodate the expander. This does
* not include the 16dp content margin that all notification views must have.
*/
- public int getHeadingExtraMarginEnd() {
- return mRightIconMarginEnd;
- }
+ public final MarginSet mHeadingExtraMarginSet = new MarginSet();
/**
- * @return the margin end that needs to be added to the heading so that it won't overlap
+ * The margin end that needs to be added to the heading so that it won't overlap
* with the large icon. This value includes the space required to accommodate the large
* icon as well as the expander. This does not include the 16dp content margin that all
* notification views must have.
*/
- public int getHeadingFullMarginEnd() {
- return mRightIconMarginEnd + mExpanderSize;
- }
+ public final MarginSet mHeadingFullMarginSet = new MarginSet();
/**
- * @return the margin end that needs to be added to the title text of the big state
+ * The margin end that needs to be added to the title text of the big state
* so that it won't overlap with the large icon, but assuming the text can run under
* the expander when that icon is not visible.
*/
- public int getTitleMarginEnd() {
- return mRightIconVisible ? getHeadingFullMarginEnd() : 0;
- }
+ public final MarginSet mTitleMarginSet = new MarginSet();
- public void setRightIconState(boolean visible, int marginEnd, int expanderSize) {
+ public void setRightIconState(boolean visible, int marginEndIfVisible, int expanderSize) {
mRightIconVisible = visible;
- mRightIconMarginEnd = marginEnd;
- mExpanderSize = expanderSize;
+ mHeadingExtraMarginSet.setValues(0, marginEndIfVisible);
+ mHeadingFullMarginSet.setValues(expanderSize, marginEndIfVisible + expanderSize);
+ mTitleMarginSet.setValues(0, marginEndIfVisible + expanderSize);
+ }
+
+ /**
+ * This contains the end margins for a view when the right icon is visible or not. These
+ * values are both needed so that NotificationGroupingUtil can 'move' the right_icon to the
+ * left_icon and adjust the margins, and to undo that change as well.
+ */
+ private class MarginSet {
+ private int mValueIfGone;
+ private int mValueIfVisible;
+
+ public void setValues(int valueIfGone, int valueIfVisible) {
+ mValueIfGone = valueIfGone;
+ mValueIfVisible = valueIfVisible;
+ }
+
+ public void applyToView(@NonNull RemoteViews views, @IdRes int viewId) {
+ applyToView(views, viewId, 0);
+ }
+
+ public void applyToView(@NonNull RemoteViews views, @IdRes int viewId,
+ @Px int extraMargin) {
+ final int marginEnd = getValue() + extraMargin;
+ if (viewId == R.id.notification_header) {
+ views.setInt(R.id.notification_header, "setTopLineExtraMarginEnd", marginEnd);
+ } else {
+ views.setViewLayoutMarginEnd(viewId, marginEnd);
+ }
+ if (mRightIconVisible) {
+ views.setIntTag(viewId, R.id.tag_margin_end_when_icon_visible,
+ mValueIfVisible + extraMargin);
+ views.setIntTag(viewId, R.id.tag_margin_end_when_icon_gone,
+ mValueIfGone + extraMargin);
+ }
+ }
+
+ public int getValue() {
+ return mRightIconVisible ? mValueIfVisible : mValueIfGone;
+ }
}
}