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

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

源代码1 项目: android_9.0.0_r45   文件: Switch.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();

    final int[] state = getDrawableState();
    boolean changed = false;

    final Drawable thumbDrawable = mThumbDrawable;
    if (thumbDrawable != null && thumbDrawable.isStateful()) {
        changed |= thumbDrawable.setState(state);
    }

    final Drawable trackDrawable = mTrackDrawable;
    if (trackDrawable != null && trackDrawable.isStateful()) {
        changed |= trackDrawable.setState(state);
    }

    if (changed) {
        invalidate();
    }
}
 
源代码2 项目: Carbon   文件: ImageView.java
protected void applyTint() {
    Drawable drawable = getDrawable();
    if (drawable == null)
        return;

    if (tint != null && tintMode != null) {
        Carbon.setTintListMode(drawable, tint, tintMode);
    } else {
        Carbon.clearTint(drawable);
    }

    if (drawable.isStateful())
        drawable.setState(getDrawableState());
    if (tint != null && tint instanceof AnimatedColorStateList)
        ((AnimatedColorStateList) tint).setState(getDrawableState());
}
 
源代码3 项目: android_9.0.0_r45   文件: CompoundButton.java
/**
 * Sets a drawable as the compound button image.
 *
 * @param drawable the drawable to set
 * @attr ref android.R.styleable#CompoundButton_button
 */
public void setButtonDrawable(@Nullable Drawable drawable) {
    if (mButtonDrawable != drawable) {
        if (mButtonDrawable != null) {
            mButtonDrawable.setCallback(null);
            unscheduleDrawable(mButtonDrawable);
        }

        mButtonDrawable = drawable;

        if (drawable != null) {
            drawable.setCallback(this);
            drawable.setLayoutDirection(getLayoutDirection());
            if (drawable.isStateful()) {
                drawable.setState(getDrawableState());
            }
            drawable.setVisible(getVisibility() == VISIBLE, false);
            setMinHeight(drawable.getIntrinsicHeight());
            applyButtonTint();
        }
    }
}
 
public void setForeground(Drawable drawable) {
	if (foregroundSelector != drawable) {
		if (foregroundSelector != null) {
			foregroundSelector.setCallback(null);
			unscheduleDrawable(foregroundSelector);
		}

		foregroundSelector = drawable;

		if (drawable != null) {
			setWillNotDraw(false);
			drawable.setCallback(this);
			if (drawable.isStateful()) {
				drawable.setState(getDrawableState());
			}
		} else {
			setWillNotDraw(true);
		}
		requestLayout();
		invalidate();
	}
}
 
源代码5 项目: MagicaSakura   文件: 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;
}
 
public boolean applySupportButtonDrawableTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(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;
}
 
源代码7 项目: timecat   文件: AppCompatBackgroundHelper.java
private boolean applySupportBackgroundTint() {
    Drawable backgroundDrawable = mView.getBackground();
    if (backgroundDrawable != null && mBackgroundTintInfo != null && mBackgroundTintInfo.mHasTintList) {
        backgroundDrawable = DrawableCompat.wrap(backgroundDrawable);
        backgroundDrawable = backgroundDrawable.mutate();
        if (mBackgroundTintInfo.mHasTintList) {
            DrawableCompat.setTintList(backgroundDrawable, mBackgroundTintInfo.mTintList);
        }
        if (mBackgroundTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(backgroundDrawable, mBackgroundTintInfo.mTintMode);
        }
        if (backgroundDrawable.isStateful()) {
            backgroundDrawable.setState(mView.getDrawableState());
        }
        setBackgroundDrawable(backgroundDrawable);
        return true;
    }
    return false;
}
 
源代码8 项目: VerticalViewPager   文件: VerticalViewPager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码9 项目: youqu_master   文件: CustomViewPager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码10 项目: CoolViewPager   文件: CoolViewPager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码11 项目: android_9.0.0_r45   文件: CompoundButton.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();

    final Drawable buttonDrawable = mButtonDrawable;
    if (buttonDrawable != null && buttonDrawable.isStateful()
            && buttonDrawable.setState(getDrawableState())) {
        invalidateDrawable(buttonDrawable);
    }
}
 
源代码12 项目: DKVideoPlayer   文件: VerticalViewPager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码13 项目: UltimateAndroid   文件: ViewPagerEx.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码14 项目: RangeSeekBar   文件: RangeProgressBar.java
public void setProgressDrawable(Drawable d) {
    if (mProgressDrawable != d) {
        if (mProgressDrawable != null) {
            mProgressDrawable.setCallback(null);
            unscheduleDrawable(mProgressDrawable);
        }

        mProgressDrawable = d;

        if (d != null) {
            d.setCallback(this);
            DrawableCompat.setLayoutDirection(d, getLayoutDirection());
            if (d.isStateful()) {
                d.setState(getDrawableState());
            }

            // Make sure the ProgressBar is always tall enough
            int drawableHeight = d.getMinimumHeight();
            if (mMaxHeight < drawableHeight) {
                mMaxHeight = drawableHeight;
                requestLayout();
            }

            applyProgressTints();
        }

        swapCurrentDrawable(d);
        postInvalidate();

        updateDrawableBounds(getWidth(), getHeight());
        updateDrawableState();

        doRefreshProgress(android.R.id.progress, mStartProgress, mEndProgress, false, false, false);
    }
}
 
源代码15 项目: BookReader   文件: DirectionalViewpager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码16 项目: X-Alarm   文件: WheelView.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(Drawable drawable) {
    if (mWheelForeground != drawable) {
        if (mWheelForeground != null) {
            mWheelForeground.setCallback(null);
            unscheduleDrawable(mWheelForeground);
        }

        mWheelForeground = drawable;

        if (drawable != null) {
            setWillNotDraw(false);
            drawable.setCallback(this);
            if (drawable.isStateful()) {
                drawable.setState(getDrawableState());
            }
            if (mForegroundGravity == Gravity.FILL) {
                Rect padding = new Rect();
                drawable.getPadding(padding);
            }
        }  else {
            setWillNotDraw(true);
        }
        requestLayout();
        invalidate();
    }
}
 
源代码17 项目: 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();
        }
    }
}
 
源代码18 项目: TLint   文件: VerticalViewPager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码19 项目: YViewPagerDemo   文件: YViewPager.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mMarginDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }
}
 
源代码20 项目: RangeSeekBar   文件: RangeSeekBar.java
protected void setDrawableState(final Drawable drawable, final int[] drawableState) {
    if (null != drawable && drawable.isStateful() && drawable.setState(drawableState)) {
        invalidateDrawable(drawable);
    }
}