Merge "Add support for colors in PageIndicator"

This commit is contained in:
TreeHugger Robot
2020-07-20 21:08:59 +00:00
committed by Android (Google) Code Review
3 changed files with 48 additions and 12 deletions

View File

@@ -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)
}

View File

@@ -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,

View File

@@ -508,7 +508,6 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
mPageListener.onPageChanged(isLayoutRtl() ? position == mPages.size() - 1
: position == 0);
}
}
@Override