android.graphics.drawable.Drawable#setState()源码实例Demo

下面列出了android.graphics.drawable.Drawable#setState() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private Drawable applySupportCompoundDrawableTint(int position) {
    Drawable originDrawable = mView.getCompoundDrawables()[position];
    Drawable compoundDrawable = originDrawable;
    TintInfo tintInfo = mCompoundDrawableTintInfos[position];
    if (compoundDrawable != null && tintInfo != null && tintInfo.mHasTintList) {
        compoundDrawable = DrawableCompat.wrap(compoundDrawable);
        compoundDrawable.mutate();
        if (tintInfo.mHasTintList) {
            DrawableCompat.setTintList(compoundDrawable, tintInfo.mTintList);
        }
        if (tintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(compoundDrawable, tintInfo.mTintMode);
        }
        if (compoundDrawable.isStateful()) {
            compoundDrawable.setState(originDrawable.getState());
        }
        return compoundDrawable;
    }
    return originDrawable;
}
 
public void setForeground(Drawable drawable) {
  if (foreground != drawable) {
    if (foreground != null) {
      foreground.setCallback(null);
      unscheduleDrawable(foreground);
    }

    foreground = drawable;

    if (drawable != null) {
      setWillNotDraw(false);
      drawable.setCallback(this);
      if (drawable.isStateful()) {
        drawable.setState(getDrawableState());
      }
    } else {
      setWillNotDraw(true);
    }
    requestLayout();
    invalidate();
  }
}
 
源代码3 项目: timecat   文件: AppCompatSwitchHelper.java
private boolean applySupportDrawableTint() {
    Drawable drawable = mDrawableCallback.getDrawable();
    if (drawable != null && mTintInfo != null && mTintInfo.mHasTintList) {
        Drawable tintDrawable = drawable.mutate();
        tintDrawable = DrawableCompat.wrap(tintDrawable);
        if (mTintInfo.mHasTintList) {
            DrawableCompat.setTintList(tintDrawable, mTintInfo.mTintList);
        }
        if (mTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(tintDrawable, mTintInfo.mTintMode);
        }
        if (tintDrawable.isStateful()) {
            tintDrawable.setState(mSwitchCompat.getDrawableState());
        }
        setDrawable(tintDrawable);
        if (drawable == tintDrawable) {
            tintDrawable.invalidateSelf();
        }
        return true;
    }
    return false;
}
 
源代码4 项目: simple-keyboard   文件: Key.java
/**
 * Returns the background drawable for the key, based on the current state and type of the key.
 * @return the background drawable of the key.
 * @see android.graphics.drawable.StateListDrawable#setState(int[])
 */
public final Drawable selectBackgroundDrawable(final Drawable keyBackground,
        final Drawable functionalKeyBackground,
        final Drawable spacebarBackground) {
    final Drawable background;
    if (mBackgroundType == BACKGROUND_TYPE_FUNCTIONAL) {
        background = functionalKeyBackground;
    } else if (mBackgroundType == BACKGROUND_TYPE_SPACEBAR) {
        background = spacebarBackground;
    } else {
        background = keyBackground;
    }
    final int[] state = KeyBackgroundState.STATES[mBackgroundType].getState(mPressed);
    background.setState(state);
    return background;
}
 
源代码5 项目: timecat   文件: AppCompatCompoundButtonHelper.java
public boolean applySupportButtonDrawableTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable((CompoundButton) mView);
    if (buttonDrawable != null && mCompoundButtonTintInfo != null && mCompoundButtonTintInfo.mHasTintList) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable);
        buttonDrawable = buttonDrawable.mutate();
        if (mCompoundButtonTintInfo.mHasTintList) {
            DrawableCompat.setTintList(buttonDrawable, mCompoundButtonTintInfo.mTintList);
        }
        if (mCompoundButtonTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(buttonDrawable, mCompoundButtonTintInfo.mTintMode);
        }
        // The drawable (or one of its children) may not have been
        // stateful before applying the tint, so let's try again.
        if (buttonDrawable.isStateful()) {
            buttonDrawable.setState(mView.getDrawableState());
        }
        setButtonDrawable(buttonDrawable);
        return true;
    }
    return false;
}
 
源代码6 项目: MagicaSakura   文件: AppCompatImageHelper.java
private boolean applySupportImageTint() {
    Drawable image = mView.getDrawable();
    if (image != null && mImageTintInfo != null && mImageTintInfo.mHasTintList) {
        Drawable tintDrawable = image.mutate();
        tintDrawable = DrawableCompat.wrap(tintDrawable);
        if (mImageTintInfo.mHasTintList) {
            DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList);
        }
        if (mImageTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode);
        }
        if (tintDrawable.isStateful()) {
            tintDrawable.setState(mView.getDrawableState());
        }
        setImageDrawable(tintDrawable);
        if (image == tintDrawable) {
            tintDrawable.invalidateSelf();
        }
        return true;
    }
    return false;
}
 
源代码7 项目: android_9.0.0_r45   文件: AbsSeekBar.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();

    final Drawable progressDrawable = getProgressDrawable();
    if (progressDrawable != null && mDisabledAlpha < 1.0f) {
        progressDrawable.setAlpha(isEnabled() ? NO_ALPHA : (int) (NO_ALPHA * mDisabledAlpha));
    }

    final Drawable thumb = mThumb;
    if (thumb != null && thumb.isStateful()
            && thumb.setState(getDrawableState())) {
        invalidateDrawable(thumb);
    }

    final Drawable tickMark = mTickMark;
    if (tickMark != null && tickMark.isStateful()
            && tickMark.setState(getDrawableState())) {
        invalidateDrawable(tickMark);
    }
}
 
源代码8 项目: MiBandDecompiled   文件: VerticalViewPager.java
protected void drawableStateChanged()
{
    super.drawableStateChanged();
    Drawable drawable = s;
    if (drawable != null && drawable.isStateful())
    {
        drawable.setState(getDrawableState());
    }
}
 
源代码9 项目: adt-leanback-support   文件: ViewPager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码10 项目: openboard   文件: KeyPreviewView.java
public void setPreviewBackground(final boolean hasMoreKeys, final int position) {
    final Drawable background = getBackground();
    if (background == null) {
        return;
    }
    final int hasMoreKeysState = hasMoreKeys ? STATE_HAS_MOREKEYS : STATE_NORMAL;
    background.setState(KEY_PREVIEW_BACKGROUND_STATE_TABLE[position][hasMoreKeysState]);
}
 
源代码11 项目: DoubleViewPager   文件: HorizontalViewPager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码12 项目: likeJDGoodsDetails   文件: VerViewPager.java
@Override
protected void drawableStateChanged() {
	super.drawableStateChanged();
	final Drawable d = mMarginDrawable;
	if (d != null && d.isStateful()) {
		d.setState(getDrawableState());
	}
}
 
源代码13 项目: BookReader   文件: DirectionalViewpager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码14 项目: VideoOS-Android-SDK   文件: ForegroundDelegate.java
/**
 * Supply a Drawable that is to be rendered on top of all of the child
 * views in the frame layout.  Any padding in the Drawable will be taken
 * into account by ensuring that the children are inset to be placed
 * inside of the padding area.
 *
 * @param drawable The Drawable to be drawn on top of the children.
 */
public void setForeground(View view, Drawable drawable) {
    if (view != null) {
        if (mForeground != drawable) {
            if (mForeground != null) {
                mForeground.setCallback(null);
                view.unscheduleDrawable(mForeground);
            }

            mForeground = drawable;

            if (drawable != null) {
                view.setWillNotDraw(false);
                drawable.setCallback(view);
                if (drawable.isStateful()) {
                    drawable.setState(view.getDrawableState());
                }
                if (mForegroundGravity == Gravity.FILL) {
                    Rect padding = new Rect();
                    drawable.getPadding(padding);
                }

                //update bounds
                updateBounds(view, drawable);//added by song
            } else {
                view.setWillNotDraw(true);
            }
            view.requestLayout();
            view.invalidate();
        }
    }
}
 
源代码15 项目: Android-SDK-Demo   文件: SdkCenteredViewPager.java
@Override
protected void drawableStateChanged()
{
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if ( d != null && d.isStateful() )
    {
        d.setState( getDrawableState() );
    }
}
 
源代码16 项目: MagicaSakura   文件: AppCompatProgressBarHelper.java
private void applySupportProgressTint() {
    if (mProgressTintInfo != null
            && (mProgressTintInfo.mHasTintList || mProgressTintInfo.mHasTintMode)) {
        final Drawable target = getTintTarget(android.R.id.progress, true);
        if (target != null) {
            TintManager.tintViewDrawable(mView, target, mProgressTintInfo);
            // The drawable (or one of its children) may not have been
            // stateful before applying the tint, so let's try again.
            if (target.isStateful()) {
                target.setState(mView.getDrawableState());
            }
        }
    }
}
 
源代码17 项目: VerticalViewPager   文件: VerticalViewPager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码18 项目: android_9.0.0_r45   文件: ImageView.java
private void updateDrawable(Drawable d) {
    if (d != mRecycleableBitmapDrawable && mRecycleableBitmapDrawable != null) {
        mRecycleableBitmapDrawable.setBitmap(null);
    }

    boolean sameDrawable = false;

    if (mDrawable != null) {
        sameDrawable = mDrawable == d;
        mDrawable.setCallback(null);
        unscheduleDrawable(mDrawable);
        if (!sCompatDrawableVisibilityDispatch && !sameDrawable && isAttachedToWindow()) {
            mDrawable.setVisible(false, false);
        }
    }

    mDrawable = d;

    if (d != null) {
        d.setCallback(this);
        d.setLayoutDirection(getLayoutDirection());
        if (d.isStateful()) {
            d.setState(getDrawableState());
        }
        if (!sameDrawable || sCompatDrawableVisibilityDispatch) {
            final boolean visible = sCompatDrawableVisibilityDispatch
                    ? getVisibility() == VISIBLE
                    : isAttachedToWindow() && getWindowVisibility() == VISIBLE && isShown();
            d.setVisible(visible, true);
        }
        d.setLevel(mLevel);
        mDrawableWidth = d.getIntrinsicWidth();
        mDrawableHeight = d.getIntrinsicHeight();
        applyImageTint();
        applyColorMod();

        configureBounds();
    } else {
        mDrawableWidth = mDrawableHeight = -1;
    }
}
 
源代码19 项目: RangeSeekBar   文件: RangeSeekBar.java
protected void setDrawableState(final Drawable drawable, final int[] drawableState) {
    if (null != drawable && drawable.isStateful() && drawable.setState(drawableState)) {
        invalidateDrawable(drawable);
    }
}
 
源代码20 项目: android_9.0.0_r45   文件: TabWidget.java
@Override
public void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    // Do nothing if there are no tabs.
    if (getTabCount() == 0) return;

    // If the user specified a custom view for the tab indicators, then
    // do not draw the bottom strips.
    if (!mDrawBottomStrips) {
        // Skip drawing the bottom strips.
        return;
    }

    final View selectedChild = getChildTabViewAt(mSelectedTab);

    final Drawable leftStrip = mLeftStrip;
    final Drawable rightStrip = mRightStrip;

    if (leftStrip != null) {
        leftStrip.setState(selectedChild.getDrawableState());
    }
    if (rightStrip != null) {
        rightStrip.setState(selectedChild.getDrawableState());
    }

    if (mStripMoved) {
        final Rect bounds = mBounds;
        bounds.left = selectedChild.getLeft();
        bounds.right = selectedChild.getRight();
        final int myHeight = getHeight();
        if (leftStrip != null) {
            leftStrip.setBounds(Math.min(0, bounds.left - leftStrip.getIntrinsicWidth()),
                    myHeight - leftStrip.getIntrinsicHeight(), bounds.left, myHeight);
        }
        if (rightStrip != null) {
            rightStrip.setBounds(bounds.right, myHeight - rightStrip.getIntrinsicHeight(),
                    Math.max(getWidth(), bounds.right + rightStrip.getIntrinsicWidth()),
                    myHeight);
        }
        mStripMoved = false;
    }

    if (leftStrip != null) {
        leftStrip.draw(canvas);
    }
    if (rightStrip != null) {
        rightStrip.draw(canvas);
    }
}