From 216812e98150abfe30a34c35b95c8ac8b0c76864 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Fri, 1 Feb 2019 13:49:00 -0500 Subject: [PATCH] Change Chip between QS and QQS Chip animates via fade out and fade in. No redlines for margins and padding. Test: manual Change-Id: I10f024eb06f88b6493687febdbb0d5ccbba450b8 --- .../SystemUI/res/drawable/privacy_chip_bg.xml | 3 +- .../res/layout/ongoing_privacy_chip.xml | 19 +++++++--- packages/SystemUI/res/values/dimens.xml | 10 +++--- packages/SystemUI/res/values/strings.xml | 3 ++ .../systemui/privacy/OngoingPrivacyChip.kt | 35 ++++++++++++++----- .../systemui/qs/QuickStatusBarHeader.java | 16 +++++++-- 6 files changed, 66 insertions(+), 20 deletions(-) diff --git a/packages/SystemUI/res/drawable/privacy_chip_bg.xml b/packages/SystemUI/res/drawable/privacy_chip_bg.xml index 36d06591460b3..f1158ef11ccc2 100644 --- a/packages/SystemUI/res/drawable/privacy_chip_bg.xml +++ b/packages/SystemUI/res/drawable/privacy_chip_bg.xml @@ -17,6 +17,7 @@ - + \ No newline at end of file diff --git a/packages/SystemUI/res/layout/ongoing_privacy_chip.xml b/packages/SystemUI/res/layout/ongoing_privacy_chip.xml index cbdd51b243887..58fe811097315 100644 --- a/packages/SystemUI/res/layout/ongoing_privacy_chip.xml +++ b/packages/SystemUI/res/layout/ongoing_privacy_chip.xml @@ -29,14 +29,25 @@ android:orientation="horizontal" android:paddingStart="@dimen/ongoing_appops_chip_side_padding" android:paddingEnd="@dimen/ongoing_appops_chip_side_padding" - android:background="@drawable/privacy_chip_bg" android:focusable="true"> + + @@ -51,7 +62,7 @@ android:gravity="center_vertical" android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:textColor="@color/status_bar_clock_color" - android:layout_marginStart="@dimen/ongoing_appops_chip_icon_margin" - android:layout_marginEnd="@dimen/ongoing_appops_chip_icon_margin" + android:layout_marginStart="@dimen/ongoing_appops_chip_icon_margin_collapsed" + android:layout_marginEnd="@dimen/ongoing_appops_chip_icon_margin_collapsed" /> \ No newline at end of file diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 03445352e3305..1e1245fe0d86e 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -967,7 +967,7 @@ 24dp - 8dp + 12dp 32dp @@ -988,12 +988,14 @@ 6dp 0dp - - 4dp + + 0dp + + 8dp 18dp - 12dp + 4dp 20sp diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index db4a6cc1d7049..89c6c8a66231d 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -2301,6 +2301,9 @@ Applications are using your %s. + + In use: + %1$d application is using your %2$s. diff --git a/packages/SystemUI/src/com/android/systemui/privacy/OngoingPrivacyChip.kt b/packages/SystemUI/src/com/android/systemui/privacy/OngoingPrivacyChip.kt index 65ed889f34e1e..ecbf0246a8bab 100644 --- a/packages/SystemUI/src/com/android/systemui/privacy/OngoingPrivacyChip.kt +++ b/packages/SystemUI/src/com/android/systemui/privacy/OngoingPrivacyChip.kt @@ -16,6 +16,7 @@ package com.android.systemui.privacy import android.content.Context import android.util.AttributeSet +import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.LinearLayout @@ -29,14 +30,25 @@ class OngoingPrivacyChip @JvmOverloads constructor( defStyleRes: Int = 0 ) : LinearLayout(context, attrs, defStyleAttrs, defStyleRes) { - private val iconMargin = - context.resources.getDimensionPixelSize(R.dimen.ongoing_appops_chip_icon_margin) + private val iconMarginExpanded = context.resources.getDimensionPixelSize( + R.dimen.ongoing_appops_chip_icon_margin_expanded) + private val iconMarginCollapsed = context.resources.getDimensionPixelSize( + R.dimen.ongoing_appops_chip_icon_margin_collapsed) private val iconSize = context.resources.getDimensionPixelSize(R.dimen.ongoing_appops_chip_icon_size) - val iconColor = context.resources.getColor( + private val iconColor = context.resources.getColor( R.color.status_bar_clock_color, context.theme) + private val backgroundDrawable = context.getDrawable(R.drawable.privacy_chip_bg) private lateinit var text: TextView private lateinit var iconsContainer: LinearLayout + private lateinit var inUseText: TextView + var expanded = false + set(value) { + if (value != field) { + field = value + updateView() + } + } var builder = PrivacyDialogBuilder(context, emptyList()) var privacyList = emptyList() set(value) { @@ -48,15 +60,18 @@ class OngoingPrivacyChip @JvmOverloads constructor( override fun onFinishInflate() { super.onFinishInflate() + inUseText = findViewById(R.id.in_use_text) text = findViewById(R.id.text_container) iconsContainer = findViewById(R.id.icons_container) } // Should only be called if the builder icons or app changed private fun updateView() { + inUseText.visibility = if (expanded) View.GONE else View.VISIBLE + background = if (expanded) backgroundDrawable else null fun setIcons(dialogBuilder: PrivacyDialogBuilder, iconsContainer: ViewGroup) { iconsContainer.removeAllViews() - dialogBuilder.generateIcons().forEach { + dialogBuilder.generateIcons().forEachIndexed { i, it -> it.mutate() it.setTint(iconColor) val image = ImageView(context).apply { @@ -64,17 +79,19 @@ class OngoingPrivacyChip @JvmOverloads constructor( scaleType = ImageView.ScaleType.CENTER_INSIDE } iconsContainer.addView(image, iconSize, iconSize) - val lp = image.layoutParams as MarginLayoutParams - lp.marginStart = iconMargin - image.layoutParams = lp + if (i != 0) { + val lp = image.layoutParams as MarginLayoutParams + lp.marginStart = if (expanded) iconMarginExpanded else iconMarginCollapsed + image.layoutParams = lp + } } } if (!privacyList.isEmpty()) { generateContentDescription() setIcons(builder, iconsContainer) - text.visibility = if (builder.types.size == 1) VISIBLE else GONE - if (builder.types.size == 1) { + text.visibility = if (builder.types.size == 1 && expanded) VISIBLE else GONE + if (builder.types.size == 1 && expanded) { if (builder.app != null) { text.setText(builder.app?.applicationName) } else { diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java index 74e82b270aa06..ee9255c54a62d 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java @@ -124,6 +124,7 @@ public class QuickStatusBarHeader extends RelativeLayout implements private TintedIconManager mIconManager; private TouchAnimator mStatusIconsAlphaAnimator; private TouchAnimator mHeaderTextContainerAlphaAnimator; + private TouchAnimator mPrivacyChipAlphaAnimator; private View mSystemIconsView; private View mQuickQsStatusIcons; @@ -212,6 +213,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements mNextAlarmTextView = findViewById(R.id.next_alarm_text); mRingerModeIcon = findViewById(R.id.ringer_mode_icon); mRingerModeTextView = findViewById(R.id.ringer_mode_text); + mPrivacyChip = findViewById(R.id.privacy_chip); + mPrivacyChip.setOnClickListener(this); updateResources(); @@ -230,8 +233,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements mClockView = findViewById(R.id.clock); mClockView.setOnClickListener(this); mDateView = findViewById(R.id.date); - mPrivacyChip = findViewById(R.id.privacy_chip); - mPrivacyChip.setOnClickListener(this); mSpace = findViewById(R.id.space); // Tint for the battery icons are handled in setupHost() @@ -383,6 +384,7 @@ public class QuickStatusBarHeader extends RelativeLayout implements updateStatusIconAlphaAnimator(); updateHeaderTextContainerAlphaAnimator(); + updatePrivacyChipAlphaAnimator(); } private void updateStatusIconAlphaAnimator() { @@ -398,6 +400,12 @@ public class QuickStatusBarHeader extends RelativeLayout implements .build(); } + private void updatePrivacyChipAlphaAnimator() { + mPrivacyChipAlphaAnimator = new TouchAnimator.Builder() + .addFloat(mPrivacyChip, "alpha", 1, 0, 1) + .build(); + } + public void setExpanded(boolean expanded) { if (mExpanded == expanded) return; mExpanded = expanded; @@ -431,6 +439,10 @@ public class QuickStatusBarHeader extends RelativeLayout implements if (mHeaderTextContainerAlphaAnimator != null) { mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction); } + if (mPrivacyChipAlphaAnimator != null) { + mPrivacyChip.setExpanded(expansionFraction > 0.5); + mPrivacyChipAlphaAnimator.setPosition(keyguardExpansionFraction); + } // Check the original expansion fraction - we don't want to show the tooltip until the // panel is pulled all the way out.