diff options
author | Tony Wickham <twickham@google.com> | 2017-02-24 15:08:13 -0800 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2017-03-02 11:27:16 -0800 |
commit | 9407d4ab57a0c3500647f1f5f9a9a44b51d222b4 (patch) | |
tree | f71d04a0f8abead00df1762ad83abe8b4e61148c /src/com/android/launcher3/notification/NotificationFooterLayout.java | |
parent | f2db25398a029b6f13afccbec331e35c8007dde6 (diff) | |
download | android_packages_apps_Trebuchet-9407d4ab57a0c3500647f1f5f9a9a44b51d222b4.tar.gz android_packages_apps_Trebuchet-9407d4ab57a0c3500647f1f5f9a9a44b51d222b4.tar.bz2 android_packages_apps_Trebuchet-9407d4ab57a0c3500647f1f5f9a9a44b51d222b4.zip |
Update notification visuals (part 2)
- Background is now white, and color beneath and divider color
updated accordingly (not from color extraction)
- Removed overflow text ("+6") and added it to a header
("6 Notifications"). Use "..." instead if there is an overflow.
- Even spaced out icons in notification footer between the
far right icon and the ellipsis
- Remove code to change arrow tint, since it is always white
now. This also fixes the issue where it was drawn as a rect.
Bug: 35766387
Change-Id: I03bfda4ff029f23dd8b3dd1b72f534ea0e2c0816
Diffstat (limited to 'src/com/android/launcher3/notification/NotificationFooterLayout.java')
-rw-r--r-- | src/com/android/launcher3/notification/NotificationFooterLayout.java | 127 |
1 files changed, 51 insertions, 76 deletions
diff --git a/src/com/android/launcher3/notification/NotificationFooterLayout.java b/src/com/android/launcher3/notification/NotificationFooterLayout.java index 62126ef83..2e803417d 100644 --- a/src/com/android/launcher3/notification/NotificationFooterLayout.java +++ b/src/com/android/launcher3/notification/NotificationFooterLayout.java @@ -21,14 +21,15 @@ import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.content.Context; +import android.content.res.Resources; import android.graphics.Rect; import android.graphics.drawable.ColorDrawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.LinearLayout; -import android.widget.TextView; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAnimUtils; @@ -36,7 +37,6 @@ import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.anim.PropertyListBuilder; import com.android.launcher3.anim.PropertyResetListener; -import com.android.launcher3.graphics.IconPalette; import com.android.launcher3.popup.PopupContainerWithArrow; import java.util.ArrayList; @@ -44,16 +44,16 @@ import java.util.Iterator; import java.util.List; /** - * A {@link LinearLayout} that contains only icons of notifications. - * If there are more than {@link #MAX_FOOTER_NOTIFICATIONS} icons, we add a "+x" overflow. + * A {@link FrameLayout} that contains only icons of notifications. + * If there are more than {@link #MAX_FOOTER_NOTIFICATIONS} icons, we add a "..." overflow. */ -public class NotificationFooterLayout extends LinearLayout { +public class NotificationFooterLayout extends FrameLayout { public interface IconAnimationEndListener { void onIconAnimationEnd(NotificationInfo animatedNotification); } - private static final int MAX_FOOTER_NOTIFICATIONS = 4; + private static final int MAX_FOOTER_NOTIFICATIONS = 5; private static final Rect sTempRect = new Rect(); @@ -61,11 +61,10 @@ public class NotificationFooterLayout extends LinearLayout { private final List<NotificationInfo> mOverflowNotifications = new ArrayList<>(); private final boolean mRtl; - LinearLayout.LayoutParams mIconLayoutParams; + FrameLayout.LayoutParams mIconLayoutParams; + private View mOverflowEllipsis; private LinearLayout mIconRow; - private final ColorDrawable mBackgroundColor; - private int mTextColor; - private TextView mOverflowView; + private int mBackgroundColor; public NotificationFooterLayout(Context context) { this(context, null, 0); @@ -78,33 +77,29 @@ public class NotificationFooterLayout extends LinearLayout { public NotificationFooterLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - mRtl = Utilities.isRtl(getResources()); + Resources res = getResources(); + mRtl = Utilities.isRtl(res); - int size = getResources().getDimensionPixelSize( - R.dimen.notification_footer_icon_size); - int padding = getResources().getDimensionPixelSize(R.dimen.notification_padding); - mIconLayoutParams = new LayoutParams(size, size); - mIconLayoutParams.setMarginEnd(padding); + int iconSize = res.getDimensionPixelSize(R.dimen.notification_footer_icon_size); + mIconLayoutParams = new LayoutParams(iconSize, iconSize); mIconLayoutParams.gravity = Gravity.CENTER_VERTICAL; - - mBackgroundColor = new ColorDrawable(); - setBackground(mBackgroundColor); + // Compute margin start for each icon such that the icons between the first one + // and the ellipsis are evenly spaced out. + int paddingEnd = res.getDimensionPixelSize(R.dimen.notification_footer_icon_row_padding); + int ellipsisSpace = res.getDimensionPixelSize(R.dimen.horizontal_ellipsis_offset) + + res.getDimensionPixelSize(R.dimen.horizontal_ellipsis_size); + int footerWidth = res.getDimensionPixelSize(R.dimen.bg_popup_item_width); + int availableIconRowSpace = footerWidth - paddingEnd - ellipsisSpace + - iconSize * MAX_FOOTER_NOTIFICATIONS; + mIconLayoutParams.setMarginStart(availableIconRowSpace / MAX_FOOTER_NOTIFICATIONS); } @Override protected void onFinishInflate() { super.onFinishInflate(); + mOverflowEllipsis = findViewById(R.id.overflow); mIconRow = (LinearLayout) findViewById(R.id.icon_row); - } - - public void applyColors(IconPalette iconPalette) { - mBackgroundColor.setColor(iconPalette.backgroundColor); - findViewById(R.id.divider).setBackgroundColor(iconPalette.secondaryColor); - mTextColor = iconPalette.textColor; - } - - public int getBackgroundColor() { - return mBackgroundColor.getColor(); + mBackgroundColor = ((ColorDrawable) getBackground()).getColor(); } /** @@ -128,35 +123,26 @@ public class NotificationFooterLayout extends LinearLayout { for (int i = 0; i < mNotifications.size(); i++) { NotificationInfo info = mNotifications.get(i); - addNotificationIconForInfo(info, false /* fromOverflow */); + addNotificationIconForInfo(info); } + updateOverflowEllipsisVisibility(); + } - if (!mOverflowNotifications.isEmpty()) { - mOverflowView = new TextView(getContext()); - mOverflowView.setTextColor(mTextColor); - updateOverflowText(); - mIconRow.addView(mOverflowView, 0, mIconLayoutParams); - } + private void updateOverflowEllipsisVisibility() { + mOverflowEllipsis.setVisibility(mOverflowNotifications.isEmpty() ? GONE : VISIBLE); } - private void addNotificationIconForInfo(NotificationInfo info, boolean fromOverflow) { + /** + * Creates an icon for the given NotificationInfo, and adds it to the icon row. + * @return the icon view that was added + */ + private View addNotificationIconForInfo(NotificationInfo info) { View icon = new View(getContext()); - icon.setBackground(info.getIconForBackground(getContext(), getBackgroundColor())); + icon.setBackground(info.getIconForBackground(getContext(), mBackgroundColor)); icon.setOnClickListener(info); - int addIndex = 0; - if (fromOverflow) { - // Add the notification before the overflow view. - addIndex = 1; - icon.setAlpha(0); - icon.animate().alpha(1); - } icon.setTag(info); - mIconRow.addView(icon, addIndex, mIconLayoutParams); - } - - private void updateOverflowText() { - mOverflowView.setText(getResources().getString(R.string.deep_notifications_overflow, - mOverflowNotifications.size())); + mIconRow.addView(icon, 0, mIconLayoutParams); + return icon; } public void animateFirstNotificationTo(Rect toBounds, @@ -180,16 +166,22 @@ public class NotificationFooterLayout extends LinearLayout { animation.play(moveAndScaleIcon); // Shift all notifications (not the overflow) over to fill the gap. - int gapWidth = mIconLayoutParams.width + mIconLayoutParams.getMarginEnd(); + int gapWidth = mIconLayoutParams.width + mIconLayoutParams.getMarginStart(); if (mRtl) { gapWidth = -gapWidth; } - int numIcons = mIconRow.getChildCount() - 1; - // We have to set the translation X to 0 when the new main notification + if (!mOverflowNotifications.isEmpty()) { + NotificationInfo notification = mOverflowNotifications.remove(0); + mNotifications.add(notification); + View iconFromOverflow = addNotificationIconForInfo(notification); + animation.play(ObjectAnimator.ofFloat(iconFromOverflow, ALPHA, 0, 1)); + } + int numIcons = mIconRow.getChildCount() - 1; // All children besides the one leaving. + // We have to reset the translation X to 0 when the new main notification // is removed from the footer. PropertyResetListener<View, Float> propertyResetListener = new PropertyResetListener<>(TRANSLATION_X, 0f); - for (int i = mOverflowNotifications.isEmpty() ? 0 : 1; i < numIcons; i++) { + for (int i = 0; i < numIcons; i++) { final View child = mIconRow.getChildAt(i); Animator shiftChild = ObjectAnimator.ofFloat(child, TRANSLATION_X, gapWidth); shiftChild.addListener(propertyResetListener); @@ -201,19 +193,7 @@ public class NotificationFooterLayout extends LinearLayout { private void removeViewFromIconRow(View child) { mIconRow.removeView(child); mNotifications.remove((NotificationInfo) child.getTag()); - if (!mOverflowNotifications.isEmpty()) { - NotificationInfo notification = mOverflowNotifications.remove(0); - mNotifications.add(notification); - addNotificationIconForInfo(notification, true /* fromOverflow */); - } - if (mOverflowView != null) { - if (mOverflowNotifications.isEmpty()) { - mIconRow.removeView(mOverflowView); - mOverflowView = null; - } else { - updateOverflowText(); - } - } + updateOverflowEllipsisVisibility(); if (mIconRow.getChildCount() == 0) { // There are no more icons in the footer, so hide it. PopupContainerWithArrow popup = PopupContainerWithArrow.getOpen( @@ -240,16 +220,11 @@ public class NotificationFooterLayout extends LinearLayout { overflowIterator.remove(); } } - TextView overflowView = null; for (int i = mIconRow.getChildCount() - 1; i >= 0; i--) { View child = mIconRow.getChildAt(i); - if (child instanceof TextView) { - overflowView = (TextView) child; - } else { - NotificationInfo childInfo = (NotificationInfo) child.getTag(); - if (!notifications.contains(childInfo.notificationKey)) { - removeViewFromIconRow(child); - } + NotificationInfo childInfo = (NotificationInfo) child.getTag(); + if (!notifications.contains(childInfo.notificationKey)) { + removeViewFromIconRow(child); } } } |