summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fabian Kozynski <kozynski@google.com> 2020-07-20 15:48:59 -0400
committer Fabian Kozynski <kozynski@google.com> 2020-07-20 15:50:37 -0400
commit06df1f5e98fbfc06cfdd97037d13899cb805ad77 (patch)
treef9c18036c8aeb87dd65de03168cc19b90ca28a0d
parentdc91aaab2d3e8f162fead05d2ee56d6553db57cd (diff)
Add support for colors in PageIndicator
Adds proper support for colors in PageIndicator (via android:tint attribute). By default, it will use the accent color. Test: manual Fixes: 157767613 Change-Id: I41288e182938d31c41b82f4a95ce3ac6b50c65e3
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java57
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java1
3 files changed, 48 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt
index e12b7dd259a5..075318b3f1f7 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt
@@ -306,7 +306,7 @@ class MediaCarouselController @Inject constructor(
private fun updatePageIndicator() {
val numPages = mediaContent.getChildCount()
- pageIndicator.setNumPages(numPages, Color.WHITE)
+ pageIndicator.setNumPages(numPages)
if (numPages == 1) {
pageIndicator.setLocation(0f)
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java b/packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java
index 2c76d70fb3cc..f8655cc44d2a 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/PageIndicator.java
@@ -10,10 +10,18 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
+import androidx.annotation.NonNull;
+
+import com.android.settingslib.Utils;
import com.android.systemui.R;
import java.util.ArrayList;
+/**
+ * Page indicator for using with pageable layouts
+ *
+ * Supports {@code android.R.attr.tint}. If missing, it will use the current accent color.
+ */
public class PageIndicator extends ViewGroup {
private static final String TAG = "PageIndicator";
@@ -31,12 +39,22 @@ public class PageIndicator extends ViewGroup {
private final int mPageIndicatorWidth;
private final int mPageIndicatorHeight;
private final int mPageDotWidth;
+ private @NonNull ColorStateList mTint;
private int mPosition = -1;
private boolean mAnimating;
public PageIndicator(Context context, AttributeSet attrs) {
super(context, attrs);
+
+ TypedArray array = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.tint});
+ if (array.hasValue(0)) {
+ mTint = array.getColorStateList(0);
+ } else {
+ mTint = Utils.getColorAccent(context);
+ }
+ array.recycle();
+
mPageIndicatorWidth =
(int) mContext.getResources().getDimension(R.dimen.qs_page_indicator_width);
mPageIndicatorHeight =
@@ -45,15 +63,6 @@ public class PageIndicator extends ViewGroup {
}
public void setNumPages(int numPages) {
- TypedArray array = getContext().obtainStyledAttributes(
- new int[]{android.R.attr.colorControlActivated});
- int color = array.getColor(0, 0);
- array.recycle();
- setNumPages(numPages, color);
- }
-
- /** Overload of setNumPages that allows the indicator color to be specified.*/
- public void setNumPages(int numPages, int color) {
setVisibility(numPages > 1 ? View.VISIBLE : View.GONE);
if (numPages == getChildCount()) {
return;
@@ -67,13 +76,41 @@ public class PageIndicator extends ViewGroup {
while (numPages > getChildCount()) {
ImageView v = new ImageView(mContext);
v.setImageResource(R.drawable.minor_a_b);
- v.setImageTintList(ColorStateList.valueOf(color));
+ v.setImageTintList(mTint);
addView(v, new LayoutParams(mPageIndicatorWidth, mPageIndicatorHeight));
}
// Refresh state.
setIndex(mPosition >> 1);
}
+ /**
+ * @return the current tint list for this view.
+ */
+ @NonNull
+ public ColorStateList getTintList() {
+ return mTint;
+ }
+
+ /**
+ * Set the color for this view.
+ * <br>
+ * Calling this will change the color of the current view and any new dots that are added to it.
+ * @param color the new color
+ */
+ public void setTintList(@NonNull ColorStateList color) {
+ if (color.equals(mTint)) {
+ return;
+ }
+ mTint = color;
+ final int N = getChildCount();
+ for (int i = 0; i < N; i++) {
+ View v = getChildAt(i);
+ if (v instanceof ImageView) {
+ ((ImageView) v).setImageTintList(mTint);
+ }
+ }
+ }
+
public void setLocation(float location) {
int index = (int) location;
setContentDescription(getContext().getString(R.string.accessibility_quick_settings_page,
diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
index 3eed8ad89075..560998b5d1d8 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
@@ -508,7 +508,6 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
mPageListener.onPageChanged(isLayoutRtl() ? position == mPages.size() - 1
: position == 0);
}
-
}
@Override