Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f681448 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Add attributes and accessors for tinting View drawables"

parents 6170cca0 91174365
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -320,6 +320,8 @@ package android {
    field public static final int backgroundDimEnabled = 16843295; // 0x101021f
    field public static final int backgroundSplit = 16843659; // 0x101038b
    field public static final int backgroundStacked = 16843658; // 0x101038a
    field public static final int backgroundTint = 16843885; // 0x101046d
    field public static final int backgroundTintMode = 16843886; // 0x101046e
    field public static final int backupAgent = 16843391; // 0x101027f
    field public static final int banner = 16843762; // 0x10103f2
    field public static final int baseline = 16843548; // 0x101031c
@@ -344,6 +346,8 @@ package android {
    field public static final int buttonStyleInset = 16842826; // 0x101004a
    field public static final int buttonStyleSmall = 16842825; // 0x1010049
    field public static final int buttonStyleToggle = 16842827; // 0x101004b
    field public static final int buttonTint = 16843889; // 0x1010471
    field public static final int buttonTintMode = 16843890; // 0x1010472
    field public static final int cacheColorHint = 16843009; // 0x1010101
    field public static final int calendarViewShown = 16843596; // 0x101034c
    field public static final int calendarViewStyle = 16843613; // 0x101035d
@@ -554,6 +558,8 @@ package android {
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
    field public static final int foreground = 16843017; // 0x1010109
    field public static final int foregroundGravity = 16843264; // 0x1010200
    field public static final int foregroundTint = 16843887; // 0x101046f
    field public static final int foregroundTintMode = 16843888; // 0x1010470
    field public static final int format = 16843013; // 0x1010105
    field public static final int format12Hour = 16843722; // 0x10103ca
    field public static final int format24Hour = 16843723; // 0x10103cb
@@ -636,6 +642,8 @@ package android {
    field public static final int indeterminateDuration = 16843069; // 0x101013d
    field public static final int indeterminateOnly = 16843066; // 0x101013a
    field public static final int indeterminateProgressStyle = 16843544; // 0x1010318
    field public static final int indeterminateTint = 16843883; // 0x101046b
    field public static final int indeterminateTintMode = 16843884; // 0x101046c
    field public static final int indicatorEnd = 16843730; // 0x10103d2
    field public static final int indicatorLeft = 16843021; // 0x101010d
    field public static final int indicatorRight = 16843022; // 0x101010e
@@ -911,6 +919,8 @@ package android {
    field public static final int privateImeOptions = 16843299; // 0x1010223
    field public static final int process = 16842769; // 0x1010011
    field public static final int progress = 16843063; // 0x1010137
    field public static final int progressBackgroundTint = 16843879; // 0x1010467
    field public static final int progressBackgroundTintMode = 16843880; // 0x1010468
    field public static final int progressBarPadding = 16843545; // 0x1010319
    field public static final int progressBarStyle = 16842871; // 0x1010077
    field public static final int progressBarStyleHorizontal = 16842872; // 0x1010078
@@ -921,6 +931,8 @@ package android {
    field public static final int progressBarStyleSmallInverse = 16843400; // 0x1010288
    field public static final int progressBarStyleSmallTitle = 16843279; // 0x101020f
    field public static final int progressDrawable = 16843068; // 0x101013c
    field public static final int progressTint = 16843877; // 0x1010465
    field public static final int progressTintMode = 16843878; // 0x1010466
    field public static final int prompt = 16843131; // 0x101017b
    field public static final int propertyName = 16843489; // 0x10102e1
    field public static final int protectionLevel = 16842761; // 0x1010009
@@ -1013,6 +1025,8 @@ package android {
    field public static final int searchSuggestSelection = 16843224; // 0x10101d8
    field public static final int searchSuggestThreshold = 16843373; // 0x101026d
    field public static final int secondaryProgress = 16843064; // 0x1010138
    field public static final int secondaryProgressTint = 16843881; // 0x1010469
    field public static final int secondaryProgressTintMode = 16843882; // 0x101046a
    field public static final int seekBarStyle = 16842875; // 0x101007b
    field public static final int segmentedButtonStyle = 16843568; // 0x1010330
    field public static final int selectAllOnFocus = 16843102; // 0x101015e
@@ -1216,6 +1230,8 @@ package android {
    field public static final int thumb = 16843074; // 0x1010142
    field public static final int thumbOffset = 16843075; // 0x1010143
    field public static final int thumbTextPadding = 16843634; // 0x1010372
    field public static final int thumbTint = 16843891; // 0x1010473
    field public static final int thumbTintMode = 16843892; // 0x1010474
    field public static final int thumbnail = 16843429; // 0x10102a5
    field public static final int tileMode = 16843265; // 0x1010201
    field public static final int timeZone = 16843724; // 0x10103cc
@@ -32548,6 +32564,8 @@ package android.view {
    method public android.view.animation.Animation getAnimation();
    method public android.os.IBinder getApplicationWindowToken();
    method public android.graphics.drawable.Drawable getBackground();
    method public android.content.res.ColorStateList getBackgroundTint();
    method public android.graphics.PorterDuff.Mode getBackgroundTintMode();
    method public int getBaseline();
    method public final int getBottom();
    method protected float getBottomFadingEdgeStrength();
@@ -32825,6 +32843,8 @@ package android.view {
    method public void setBackgroundColor(int);
    method public deprecated void setBackgroundDrawable(android.graphics.drawable.Drawable);
    method public void setBackgroundResource(int);
    method public void setBackgroundTint(android.content.res.ColorStateList);
    method public void setBackgroundTintMode(android.graphics.PorterDuff.Mode);
    method public final void setBottom(int);
    method public void setCameraDistance(float);
    method public void setClickable(boolean);
@@ -35791,10 +35811,14 @@ package android.widget {
    method public boolean getSplitTrack();
    method public android.graphics.drawable.Drawable getThumb();
    method public int getThumbOffset();
    method public android.content.res.ColorStateList getThumbTint();
    method public android.graphics.PorterDuff.Mode getThumbTintMode();
    method public void setKeyProgressIncrement(int);
    method public void setSplitTrack(boolean);
    method public void setThumb(android.graphics.drawable.Drawable);
    method public void setThumbOffset(int);
    method public void setThumbTint(android.content.res.ColorStateList);
    method public void setThumbTintMode(android.graphics.PorterDuff.Mode);
  }
  public abstract class AbsSpinner extends android.widget.AdapterView {
@@ -36209,9 +36233,13 @@ package android.widget {
    ctor public CompoundButton(android.content.Context, android.util.AttributeSet);
    ctor public CompoundButton(android.content.Context, android.util.AttributeSet, int);
    ctor public CompoundButton(android.content.Context, android.util.AttributeSet, int, int);
    method public android.content.res.ColorStateList getButtonTint();
    method public android.graphics.PorterDuff.Mode getButtonTintMode();
    method public boolean isChecked();
    method public void setButtonDrawable(int);
    method public void setButtonDrawable(android.graphics.drawable.Drawable);
    method public void setButtonTint(android.content.res.ColorStateList);
    method public void setButtonTintMode(android.graphics.PorterDuff.Mode);
    method public void setChecked(boolean);
    method public void setOnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener);
    method public void toggle();
@@ -36472,10 +36500,14 @@ package android.widget {
    method public deprecated boolean getConsiderGoneChildrenWhenMeasuring();
    method public android.graphics.drawable.Drawable getForeground();
    method public int getForegroundGravity();
    method public android.content.res.ColorStateList getForegroundTint();
    method public android.graphics.PorterDuff.Mode getForegroundTintMode();
    method public boolean getMeasureAllChildren();
    method protected void onLayout(boolean, int, int, int, int);
    method public void setForeground(android.graphics.drawable.Drawable);
    method public void setForegroundGravity(int);
    method public void setForegroundTint(android.content.res.ColorStateList);
    method public void setForegroundTintMode(android.graphics.PorterDuff.Mode);
    method public void setMeasureAllChildren(boolean);
  }
@@ -36684,6 +36716,8 @@ package android.widget {
    method public int getMaxHeight();
    method public int getMaxWidth();
    method public android.widget.ImageView.ScaleType getScaleType();
    method public android.content.res.ColorStateList getTint();
    method public android.graphics.PorterDuff.Mode getTintMode();
    method public int[] onCreateDrawableState(int);
    method public void setAdjustViewBounds(boolean);
    method public deprecated void setAlpha(int);
@@ -36705,6 +36739,8 @@ package android.widget {
    method public void setMaxHeight(int);
    method public void setMaxWidth(int);
    method public void setScaleType(android.widget.ImageView.ScaleType);
    method public void setTint(android.content.res.ColorStateList);
    method public void setTintMode(android.graphics.PorterDuff.Mode);
  }
  public static final class ImageView.ScaleType extends java.lang.Enum {
@@ -37077,11 +37113,19 @@ package android.widget {
    ctor public ProgressBar(android.content.Context, android.util.AttributeSet, int);
    ctor public ProgressBar(android.content.Context, android.util.AttributeSet, int, int);
    method public android.graphics.drawable.Drawable getIndeterminateDrawable();
    method public android.content.res.ColorStateList getIndeterminateTint();
    method public android.graphics.PorterDuff.Mode getIndeterminateTintMode();
    method public android.view.animation.Interpolator getInterpolator();
    method public synchronized int getMax();
    method public synchronized int getProgress();
    method public android.content.res.ColorStateList getProgressBackgroundTint();
    method public android.graphics.PorterDuff.Mode getProgressBackgroundTintMode();
    method public android.graphics.drawable.Drawable getProgressDrawable();
    method public android.content.res.ColorStateList getProgressTint();
    method public android.graphics.PorterDuff.Mode getProgressTintMode();
    method public synchronized int getSecondaryProgress();
    method public android.content.res.ColorStateList getSecondaryProgressTint();
    method public android.graphics.PorterDuff.Mode getSecondaryProgressTintMode();
    method public final synchronized void incrementProgressBy(int);
    method public final synchronized void incrementSecondaryProgressBy(int);
    method public synchronized boolean isIndeterminate();
@@ -37090,13 +37134,21 @@ package android.widget {
    method public synchronized void setIndeterminate(boolean);
    method public void setIndeterminateDrawable(android.graphics.drawable.Drawable);
    method public void setIndeterminateDrawableTiled(android.graphics.drawable.Drawable);
    method public void setIndeterminateTint(android.content.res.ColorStateList);
    method public void setIndeterminateTintMode(android.graphics.PorterDuff.Mode);
    method public void setInterpolator(android.content.Context, int);
    method public void setInterpolator(android.view.animation.Interpolator);
    method public synchronized void setMax(int);
    method public synchronized void setProgress(int);
    method public void setProgressBackgroundTint(android.content.res.ColorStateList);
    method public void setProgressBackgroundTintMode(android.graphics.PorterDuff.Mode);
    method public void setProgressDrawable(android.graphics.drawable.Drawable);
    method public void setProgressDrawableTiled(android.graphics.drawable.Drawable);
    method public void setProgressTint(android.content.res.ColorStateList);
    method public void setProgressTintMode(android.graphics.PorterDuff.Mode);
    method public synchronized void setSecondaryProgress(int);
    method public void setSecondaryProgressTint(android.content.res.ColorStateList);
    method public void setSecondaryProgressTintMode(android.graphics.PorterDuff.Mode);
  }
  public class QuickContactBadge extends android.widget.ImageView implements android.view.View.OnClickListener {
+103 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ClipData;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -44,6 +45,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.Shader;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManagerGlobal;
@@ -3187,6 +3189,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_")
    private Drawable mBackground;
    private ColorStateList mBackgroundTint = null;
    private PorterDuff.Mode mBackgroundTintMode = PorterDuff.Mode.SRC_ATOP;
    private boolean mHasBackgroundTint = false;
    /**
     * Display list used for backgrounds.
@@ -4022,6 +4027,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                    setStateListAnimator(AnimatorInflater.loadStateListAnimator(context,
                            a.getResourceId(attr, 0)));
                    break;
                case R.styleable.View_backgroundTint:
                    // This will get applied later during setBackground().
                    mBackgroundTint = a.getColorStateList(R.styleable.View_backgroundTint);
                    mHasBackgroundTint = true;
                    break;
                case R.styleable.View_backgroundTintMode:
                    // This will get applied later during setBackground().
                    mBackgroundTintMode = Drawable.parseTintMode(a.getInt(
                            R.styleable.View_backgroundTintMode, -1), mBackgroundTintMode);
                    break;
            }
        }
@@ -15774,8 +15789,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            // Compare the minimum sizes of the old Drawable and the new.  If there isn't an old or
            // if it has a different minimum size, we should layout again
            if (mBackground == null || mBackground.getMinimumHeight() != background.getMinimumHeight() ||
                    mBackground.getMinimumWidth() != background.getMinimumWidth()) {
            if (mBackground == null
                    || mBackground.getMinimumHeight() != background.getMinimumHeight()
                    || mBackground.getMinimumWidth() != background.getMinimumWidth()) {
                requestLayout = true;
            }
@@ -15786,6 +15802,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            background.setVisible(getVisibility() == VISIBLE, false);
            mBackground = background;
            applyBackgroundTint();
            if ((mPrivateFlags & PFLAG_SKIP_DRAW) != 0) {
                mPrivateFlags &= ~PFLAG_SKIP_DRAW;
                mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND;
@@ -15840,6 +15858,88 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return mBackground;
    }
    /**
     * Applies a tint to the background drawable.
     * <p>
     * Subsequent calls to {@link #setBackground(Drawable)} will automatically
     * mutate the drawable and apply the specified tint and tint mode using
     * {@link Drawable#setTint(ColorStateList, PorterDuff.Mode)}.
     *
     * @param tint the tint to apply, may be {@code null} to clear tint
     * @param tintMode the blending mode used to apply the tint, may be
     *                 {@code null} to clear tint
     *
     * @attr ref android.R.styleable#View_backgroundTint
     * @attr ref android.R.styleable#View_backgroundTintMode
     * @see Drawable#setTint(ColorStateList, PorterDuff.Mode)
     */
    private void setBackgroundTint(@Nullable ColorStateList tint,
            @Nullable PorterDuff.Mode tintMode) {
        mBackgroundTint = tint;
        mBackgroundTintMode = tintMode;
        mHasBackgroundTint = true;
        applyBackgroundTint();
    }
    /**
     * Applies a tint to the background drawable. Does not modify the current tint
     * mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
     * <p>
     * Subsequent calls to {@link #setBackground(Drawable)} will automatically
     * mutate the drawable and apply the specified tint and tint mode using
     * {@link Drawable#setTint(ColorStateList, PorterDuff.Mode)}.
     *
     * @param tint the tint to apply, may be {@code null} to clear tint
     *
     * @attr ref android.R.styleable#View_backgroundTint
     * @see #setBackgroundTint(ColorStateList, PorterDuff.Mode)
     */
    public void setBackgroundTint(@Nullable ColorStateList tint) {
        setBackgroundTint(tint, mBackgroundTintMode);
    }
    /**
     * @return the tint applied to the background drawable
     * @attr ref android.R.styleable#View_backgroundTint
     * @see #setBackgroundTint(ColorStateList, PorterDuff.Mode)
     */
    @Nullable
    public ColorStateList getBackgroundTint() {
        return mBackgroundTint;
    }
    /**
     * Specifies the blending mode used to apply the tint specified by
     * {@link #setBackgroundTint(ColorStateList)}} to the background drawable.
     * The default mode is {@link PorterDuff.Mode#SRC_ATOP}.
     *
     * @param tintMode the blending mode used to apply the tint, may be
     *                 {@code null} to clear tint
     * @attr ref android.R.styleable#View_backgroundTintMode
     * @see #setBackgroundTint(ColorStateList)
     */
    public void setBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) {
        setBackgroundTint(mBackgroundTint, tintMode);
    }
    /**
     * @return the blending mode used to apply the tint to the background drawable
     * @attr ref android.R.styleable#View_backgroundTintMode
     * @see #setBackgroundTint(ColorStateList, PorterDuff.Mode)
     */
    @Nullable
    public PorterDuff.Mode getBackgroundTintMode() {
        return mBackgroundTintMode;
    }
    private void applyBackgroundTint() {
        if (mBackground != null && mHasBackgroundTint) {
            mBackground = mBackground.mutate();
            mBackground.setTint(mBackgroundTint, mBackgroundTintMode);
        }
    }
    /**
     * Sets the padding. The view may add on the space required to display
     * the scrollbars, depending on the style and visibility of the scrollbars.
+107 −1
Original line number Diff line number Diff line
@@ -16,11 +16,15 @@

package android.widget;

import android.annotation.Nullable;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Insets;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.PorterDuff.Mode;
import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -31,10 +35,16 @@ import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;

import com.android.internal.R;

public abstract class AbsSeekBar extends ProgressBar {
    private final Rect mTempRect = new Rect();

    private Drawable mThumb;
    private ColorStateList mThumbTint = null;
    private PorterDuff.Mode mThumbTintMode = PorterDuff.Mode.SRC_ATOP;
    private boolean mHasThumbTint = false;

    private int mThumbOffset;
    private boolean mSplitTrack;

@@ -83,6 +93,15 @@ public abstract class AbsSeekBar extends ProgressBar {
        final Drawable thumb = a.getDrawable(com.android.internal.R.styleable.SeekBar_thumb);
        setThumb(thumb);

        if (a.hasValue(R.styleable.SeekBar_thumbTint)) {
            mThumbTint = a.getColorStateList(R.styleable.SeekBar_thumbTint);
            mThumbTintMode = Drawable.parseTintMode(a.getInt(
                    R.styleable.SeekBar_thumbTintMode, -1), mThumbTintMode);
            mHasThumbTint = true;

            applyThumbTint();
        }

        // Guess thumb offset if thumb != null, but allow layout to override.
        final int thumbOffset = a.getDimensionPixelOffset(
                com.android.internal.R.styleable.SeekBar_thumbOffset, getThumbOffset());
@@ -108,7 +127,7 @@ public abstract class AbsSeekBar extends ProgressBar {
     * @param thumb Drawable representing the thumb
     */
    public void setThumb(Drawable thumb) {
        boolean needUpdate;
        final boolean needUpdate;
        // This way, calling setThumb again with the same bitmap will result in
        // it recalcuating mThumbOffset (if for example it the bounds of the
        // drawable changed)
@@ -118,6 +137,7 @@ public abstract class AbsSeekBar extends ProgressBar {
        } else {
            needUpdate = false;
        }

        if (thumb != null) {
            thumb.setCallback(this);
            if (canResolveLayoutDirection()) {
@@ -136,8 +156,12 @@ public abstract class AbsSeekBar extends ProgressBar {
                requestLayout();
            }
        }

        mThumb = thumb;

        applyThumbTint();
        invalidate();

        if (needUpdate) {
            updateThumbAndTrackPos(getWidth(), getHeight());
            if (thumb != null && thumb.isStateful()) {
@@ -159,6 +183,88 @@ public abstract class AbsSeekBar extends ProgressBar {
        return mThumb;
    }

    /**
     * Applies a tint to the thumb drawable.
     * <p>
     * Subsequent calls to {@link #setThumb(Drawable)} will automatically
     * mutate the drawable and apply the specified tint and tint mode using
     * {@link Drawable#setTint(ColorStateList, PorterDuff.Mode)}.
     *
     * @param tint the tint to apply, may be {@code null} to clear tint
     * @param tintMode the blending mode used to apply the tint, may be
     *                 {@code null} to clear tint
     *
     * @attr ref android.R.styleable#SeekBar_thumbTint
     * @attr ref android.R.styleable#SeekBar_thumbTintMode
     * @see Drawable#setTint(ColorStateList, PorterDuff.Mode)
     */
    private void setThumbTint(@Nullable ColorStateList tint,
            @Nullable PorterDuff.Mode tintMode) {
        mThumbTint = tint;
        mThumbTintMode = tintMode;
        mHasThumbTint = true;

        applyThumbTint();
    }

    /**
     * Applies a tint to the thumb drawable. Does not modify the current tint
     * mode, which is {@link PorterDuff.Mode#SRC_ATOP} by default.
     * <p>
     * Subsequent calls to {@link #setThumb(Drawable)} will automatically
     * mutate the drawable and apply the specified tint and tint mode using
     * {@link Drawable#setTint(ColorStateList, PorterDuff.Mode)}.
     *
     * @param tint the tint to apply, may be {@code null} to clear tint
     *
     * @attr ref android.R.styleable#SeekBar_thumbTint
     * @see #setThumbTint(ColorStateList, PorterDuff.Mode)
     */
    public void setThumbTint(@Nullable ColorStateList tint) {
        setThumbTint(tint, mThumbTintMode);
    }

    /**
     * @return the tint applied to the thumb drawable
     * @attr ref android.R.styleable#SeekBar_thumbTint
     * @see #setThumbTint(ColorStateList, PorterDuff.Mode)
     */
    @Nullable
    public ColorStateList getThumbTint() {
        return mThumbTint;
    }

    /**
     * Specifies the blending mode used to apply the tint specified by
     * {@link #setThumbTint(ColorStateList)}} to the thumb drawable. The
     * default mode is {@link PorterDuff.Mode#SRC_ATOP}.
     *
     * @param tintMode the blending mode used to apply the tint, may be
     *                 {@code null} to clear tint
     * @attr ref android.R.styleable#SeekBar_thumbTintMode
     * @see #setThumbTint(ColorStateList)
     */
    public void setThumbTintMode(@Nullable PorterDuff.Mode tintMode) {
        setThumbTint(mThumbTint, tintMode);
    }

    /**
     * @return the blending mode used to apply the tint to the thumb drawable
     * @attr ref android.R.styleable#SeekBar_thumbTintMode
     * @see #setThumbTint(ColorStateList, PorterDuff.Mode)
     */
    @Nullable
    public PorterDuff.Mode getThumbTintMode() {
        return mThumbTintMode;
    }

    private void applyThumbTint() {
        if (mThumb != null && mHasThumbTint) {
            mThumb = mThumb.mutate();
            mThumb.setTint(mThumbTint, mThumbTintMode);
        }
    }

    /**
     * @see #setThumbOffset(int)
     */
+123 −12

File changed.

Preview size limit exceeded, changes collapsed.

+112 −9

File changed.

Preview size limit exceeded, changes collapsed.

Loading