Java Code Examples for android.graphics.drawable.Drawable#isStateful()
The following examples show how to use
android.graphics.drawable.Drawable#isStateful() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Switch.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@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(); } }
Example 2
Source File: ImageView.java From Carbon with Apache License 2.0 | 6 votes |
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()); }
Example 3
Source File: AppCompatBackgroundHelper.java From timecat with Apache License 2.0 | 6 votes |
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; }
Example 4
Source File: CompoundButton.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * 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(); } } }
Example 5
Source File: AppCompatCompoundButtonHelper.java From MagicaSakura with Apache License 2.0 | 6 votes |
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; }
Example 6
Source File: ForegroundLinearLayout.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
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(); } }
Example 7
Source File: AppCompatSwitchHelper.java From MagicaSakura with Apache License 2.0 | 6 votes |
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; }
Example 8
Source File: YViewPager.java From YViewPagerDemo with Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable d = mMarginDrawable; if (d != null && d.isStateful()) { d.setState(getDrawableState()); } }
Example 9
Source File: VerticalViewPager.java From VerticalViewPager with Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable d = mMarginDrawable; if (d != null && d.isStateful()) { d.setState(getDrawableState()); } }
Example 10
Source File: VerticalViewPager.java From TLint with Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable d = mMarginDrawable; if (d != null && d.isStateful()) { d.setState(getDrawableState()); } }
Example 11
Source File: ForegroundDelegate.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
/** * 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(); } } }
Example 12
Source File: WheelView.java From X-Alarm with GNU Affero General Public License v3.0 | 5 votes |
/** * 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(); } }
Example 13
Source File: DirectionalViewpager.java From BookReader with Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable d = mMarginDrawable; if (d != null && d.isStateful()) { d.setState(getDrawableState()); } }
Example 14
Source File: RangeProgressBar.java From RangeSeekBar with MIT License | 5 votes |
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); } }
Example 15
Source File: ViewPagerEx.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable d = mMarginDrawable; if (d != null && d.isStateful()) { d.setState(getDrawableState()); } }
Example 16
Source File: VerticalViewPager.java From DKVideoPlayer with Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable d = mMarginDrawable; if (d != null && d.isStateful()) { d.setState(getDrawableState()); } }
Example 17
Source File: CompoundButton.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable buttonDrawable = mButtonDrawable; if (buttonDrawable != null && buttonDrawable.isStateful() && buttonDrawable.setState(getDrawableState())) { invalidateDrawable(buttonDrawable); } }
Example 18
Source File: CoolViewPager.java From CoolViewPager with Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable d = mMarginDrawable; if (d != null && d.isStateful()) { d.setState(getDrawableState()); } }
Example 19
Source File: CustomViewPager.java From youqu_master with Apache License 2.0 | 5 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); final Drawable d = mMarginDrawable; if (d != null && d.isStateful()) { d.setState(getDrawableState()); } }
Example 20
Source File: RangeSeekBar.java From RangeSeekBar with MIT License | 4 votes |
protected void setDrawableState(final Drawable drawable, final int[] drawableState) { if (null != drawable && drawable.isStateful() && drawable.setState(drawableState)) { invalidateDrawable(drawable); } }