diff options
| author | 2022-06-22 13:45:53 +0000 | |
|---|---|---|
| committer | 2022-06-22 13:45:53 +0000 | |
| commit | 625ea9336c0b7358602f8106ffec70d1dffc140f (patch) | |
| tree | 00097e7cc7104db63fdd7c08afea8d42f40bc73b | |
| parent | 313d927ad22c296cacb2cf88982dd1051f35904b (diff) | |
| parent | 12f23952edf45b6956671f389642c627f6211915 (diff) | |
Merge "Code cleanup and visual polish for hybrid views" into tm-qpr-dev am: 12f23952ed
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18922156
Change-Id: Ice21a81cba9a0156b9d1e7a33feb8bc1cf6c2b49
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
7 files changed, 84 insertions, 78 deletions
diff --git a/packages/SystemUI/res/layout/hybrid_conversation_notification.xml b/packages/SystemUI/res/layout/hybrid_conversation_notification.xml index 43b16618d615..a313833e2a66 100644 --- a/packages/SystemUI/res/layout/hybrid_conversation_notification.xml +++ b/packages/SystemUI/res/layout/hybrid_conversation_notification.xml @@ -57,7 +57,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" - style="?attr/hybridNotificationTextStyle" + android:paddingEnd="4dp" + style="@*android:style/Widget.DeviceDefault.Notification.Text" /> <TextView @@ -65,6 +66,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" - style="?attr/hybridNotificationTextStyle" + android:paddingEnd="4dp" + style="@*android:style/Widget.DeviceDefault.Notification.Text" /> </com.android.systemui.statusbar.notification.row.HybridConversationNotificationView> diff --git a/packages/SystemUI/res/layout/hybrid_notification.xml b/packages/SystemUI/res/layout/hybrid_notification.xml index e8d77511e53c..9ea7be50adec 100644 --- a/packages/SystemUI/res/layout/hybrid_notification.xml +++ b/packages/SystemUI/res/layout/hybrid_notification.xml @@ -20,19 +20,22 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="bottom|start" - style="?attr/hybridNotificationStyle"> + android:paddingStart="@*android:dimen/notification_content_margin_start" + android:paddingEnd="12dp"> <TextView android:id="@+id/notification_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" - style="?attr/hybridNotificationTitleStyle" + android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Notification.Title" + android:paddingEnd="4dp" /> <TextView android:id="@+id/notification_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" - style="?attr/hybridNotificationTextStyle" + android:paddingEnd="4dp" + style="@*android:style/Widget.DeviceDefault.Notification.Text" /> </com.android.systemui.statusbar.notification.row.HybridNotificationView>
\ No newline at end of file diff --git a/packages/SystemUI/res/values/attrs.xml b/packages/SystemUI/res/values/attrs.xml index 70a72ad23d7e..9a71995383ac 100644 --- a/packages/SystemUI/res/values/attrs.xml +++ b/packages/SystemUI/res/values/attrs.xml @@ -108,12 +108,6 @@ <attr name="android:layout" /> </declare-styleable> - <declare-styleable name="HybridNotificationTheme"> - <attr name="hybridNotificationStyle" format="reference" /> - <attr name="hybridNotificationTitleStyle" format="reference" /> - <attr name="hybridNotificationTextStyle" format="reference" /> - </declare-styleable> - <declare-styleable name="PluginInflateContainer"> <attr name="viewType" format="string" /> </declare-styleable> diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml index 8b2481cff2a9..f954bc9bf17c 100644 --- a/packages/SystemUI/res/values/styles.xml +++ b/packages/SystemUI/res/values/styles.xml @@ -17,30 +17,6 @@ <resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"> - <!-- HybridNotification themes and styles --> - - <style name="HybridNotification"> - <item name="hybridNotificationStyle">@style/hybrid_notification</item> - <item name="hybridNotificationTitleStyle">@style/hybrid_notification_title</item> - <item name="hybridNotificationTextStyle">@style/hybrid_notification_text</item> - </style> - - <style name="hybrid_notification"> - <item name="android:paddingStart">@*android:dimen/notification_content_margin_start</item> - <item name="android:paddingEnd">12dp</item> - </style> - - <style name="hybrid_notification_title"> - <item name="android:paddingEnd">4dp</item> - <item name="android:textAppearance">@*android:style/TextAppearance.DeviceDefault.Notification.Title</item> - </style> - - <style name="hybrid_notification_text" - parent="@*android:style/Widget.DeviceDefault.Notification.Text"> - <item name="android:paddingEnd">4dp</item> - </style> - - <style name="TextAppearance.StatusBar.Clock" parent="@*android:style/TextAppearance.StatusBar.Icon"> <item name="android:textSize">@dimen/status_bar_clock_size</item> <item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridConversationNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridConversationNotificationView.java index c66140822d92..99a24cb3e9ca 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridConversationNotificationView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridConversationNotificationView.java @@ -67,6 +67,7 @@ public class HybridConversationNotificationView extends HybridNotificationView { mConversationIconView = requireViewById(com.android.internal.R.id.conversation_icon); mConversationFacePile = requireViewById(com.android.internal.R.id.conversation_face_pile); mConversationSenderName = requireViewById(R.id.conversation_notification_sender); + applyTextColor(mConversationSenderName, mSecondaryTextColor); mFacePileSize = getResources() .getDimensionPixelSize(R.dimen.conversation_single_line_face_pile_size); mFacePileAvatarSize = getResources() @@ -75,6 +76,9 @@ public class HybridConversationNotificationView extends HybridNotificationView { .getDimensionPixelSize(R.dimen.conversation_single_line_avatar_size); mFacePileProtectionWidth = getResources().getDimensionPixelSize( R.dimen.conversation_single_line_face_pile_protection_width); + mTransformationHelper.setCustomTransformation( + new FadeOutAndDownWithTitleTransformation(mConversationSenderName), + mConversationSenderName.getId()); mTransformationHelper.addViewTransformingToSimilar(mConversationIconView); mTransformationHelper.addTransformedView(mConversationSenderName); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridGroupManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridGroupManager.java index 40a44ffd7fe3..77fd05186090 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridGroupManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridGroupManager.java @@ -24,7 +24,6 @@ import android.content.Context; import android.content.res.Resources; import android.service.notification.StatusBarNotification; import android.util.TypedValue; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -57,10 +56,8 @@ public class HybridGroupManager { mOverflowNumberPadding = res.getDimensionPixelSize(R.dimen.group_overflow_number_padding); } - private HybridNotificationView inflateHybridViewWithStyle(int style, - View contentView, ViewGroup parent) { - LayoutInflater inflater = new ContextThemeWrapper(mContext, style) - .getSystemService(LayoutInflater.class); + private HybridNotificationView inflateHybridView(View contentView, ViewGroup parent) { + LayoutInflater inflater = LayoutInflater.from(mContext); int layout = contentView instanceof ConversationLayout ? R.layout.hybrid_conversation_notification : R.layout.hybrid_notification; @@ -93,16 +90,8 @@ public class HybridGroupManager { public HybridNotificationView bindFromNotification(HybridNotificationView reusableView, View contentView, StatusBarNotification notification, ViewGroup parent) { - return bindFromNotificationWithStyle(reusableView, contentView, notification, - R.style.HybridNotification, parent); - } - - private HybridNotificationView bindFromNotificationWithStyle( - HybridNotificationView reusableView, View contentView, - StatusBarNotification notification, - int style, ViewGroup parent) { if (reusableView == null) { - reusableView = inflateHybridViewWithStyle(style, contentView, parent); + reusableView = inflateHybridView(contentView, parent); } CharSequence titleText = resolveTitle(notification.getNotification()); CharSequence contentText = resolveText(notification.getNotification()); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridNotificationView.java index c0d85a6a16ef..fc9d9e8b736c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridNotificationView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/HybridNotificationView.java @@ -16,13 +16,18 @@ package com.android.systemui.statusbar.notification.row; +import static android.app.Notification.COLOR_INVALID; + import android.annotation.Nullable; import android.content.Context; +import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.TextView; +import androidx.annotation.ColorInt; + import com.android.keyguard.AlphaOptimizedLinearLayout; import com.android.systemui.R; import com.android.systemui.statusbar.CrossFadeHelper; @@ -40,6 +45,8 @@ public class HybridNotificationView extends AlphaOptimizedLinearLayout protected final ViewTransformationHelper mTransformationHelper = new ViewTransformationHelper(); protected TextView mTitleView; protected TextView mTextView; + protected int mPrimaryTextColor = COLOR_INVALID; + protected int mSecondaryTextColor = COLOR_INVALID; public HybridNotificationView(Context context) { this(context, null); @@ -69,42 +76,37 @@ public class HybridNotificationView extends AlphaOptimizedLinearLayout @Override protected void onFinishInflate() { super.onFinishInflate(); + resolveThemeTextColors(); mTitleView = findViewById(R.id.notification_title); mTextView = findViewById(R.id.notification_text); + applyTextColor(mTitleView, mPrimaryTextColor); + applyTextColor(mTextView, mSecondaryTextColor); mTransformationHelper.setCustomTransformation( - new ViewTransformationHelper.CustomTransformation() { - @Override - public boolean transformTo(TransformState ownState, TransformableView notification, - float transformationAmount) { - // We want to transform to the same y location as the title - TransformState otherState = notification.getCurrentState( - TRANSFORMING_VIEW_TITLE); - CrossFadeHelper.fadeOut(mTextView, transformationAmount); - if (otherState != null) { - ownState.transformViewVerticalTo(otherState, transformationAmount); - otherState.recycle(); - } - return true; - } - - @Override - public boolean transformFrom(TransformState ownState, - TransformableView notification, float transformationAmount) { - // We want to transform from the same y location as the title - TransformState otherState = notification.getCurrentState( - TRANSFORMING_VIEW_TITLE); - CrossFadeHelper.fadeIn(mTextView, transformationAmount, true /* remap */); - if (otherState != null) { - ownState.transformViewVerticalFrom(otherState, transformationAmount); - otherState.recycle(); - } - return true; - } - }, TRANSFORMING_VIEW_TEXT); + new FadeOutAndDownWithTitleTransformation(mTextView), + TRANSFORMING_VIEW_TEXT); mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView); mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView); } + protected void applyTextColor(TextView textView, @ColorInt int textColor) { + if (textColor != COLOR_INVALID) { + textView.setTextColor(textColor); + } + } + + private void resolveThemeTextColors() { + try (TypedArray ta = mContext.getTheme().obtainStyledAttributes( + android.R.style.Theme_DeviceDefault_DayNight, new int[]{ + android.R.attr.textColorPrimary, + android.R.attr.textColorSecondary + })) { + if (ta != null) { + mPrimaryTextColor = ta.getColor(0, mPrimaryTextColor); + mSecondaryTextColor = ta.getColor(1, mSecondaryTextColor); + } + } + } + public void bind(@Nullable CharSequence title, @Nullable CharSequence text, @Nullable View contentView) { mTitleView.setText(title); @@ -152,4 +154,40 @@ public class HybridNotificationView extends AlphaOptimizedLinearLayout @Override public void setNotificationFaded(boolean faded) {} + + protected static class FadeOutAndDownWithTitleTransformation extends + ViewTransformationHelper.CustomTransformation { + + private final View mView; + + public FadeOutAndDownWithTitleTransformation(View view) { + mView = view; + } + + @Override + public boolean transformTo(TransformState ownState, TransformableView notification, + float transformationAmount) { + // We want to transform to the same y location as the title + TransformState otherState = notification.getCurrentState(TRANSFORMING_VIEW_TITLE); + CrossFadeHelper.fadeOut(mView, transformationAmount); + if (otherState != null) { + ownState.transformViewVerticalTo(otherState, transformationAmount); + otherState.recycle(); + } + return true; + } + + @Override + public boolean transformFrom(TransformState ownState, + TransformableView notification, float transformationAmount) { + // We want to transform from the same y location as the title + TransformState otherState = notification.getCurrentState(TRANSFORMING_VIEW_TITLE); + CrossFadeHelper.fadeIn(mView, transformationAmount, true /* remap */); + if (otherState != null) { + ownState.transformViewVerticalFrom(otherState, transformationAmount); + otherState.recycle(); + } + return true; + } + } } |