Drawable setState - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Drawable setState method.

This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setBounds, setState
	@Override 
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
 
		if (image != null) {
			image.setState(getDrawableState());
 
			// scale image to fit inside button 
 
			int imgHeight = image.getIntrinsicHeight();
			int imgWidth = image.getIntrinsicWidth();
			int btnWidth = getWidth();
			int btnHeight = getHeight();
			float scale;
 
			if (imgWidth <= btnWidth && imgHeight <= btnHeight) {
                scale = 1.0f;
            } else { 
                scale = Math.min((float) btnWidth / (float) imgWidth,
                        (float) btnHeight / (float) imgHeight);

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, setCallback, setState, setVisible
This code example shows how to use the following methods:isStateful, setState
    } 
 
    @Override 
    protected void drawableStateChanged() { 
        Drawable d = mBackground;
        if (d != null && d.isStateful()) {
            d.setState(getDrawableState());
        } 
        super.drawableStateChanged(); 
    } 
 
    @Override 
    public void draw(Canvas canvas) {
        final Drawable background = mBackground;
        if (background != null) {
            if (mBackgroundSizeChanged) {
                mBackgroundSizeChanged = false;
                Rect chld = mTmp0;
                Rect bkg = mTmp1;
                mBackground.getPadding(bkg);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, setState
    @Override 
    public void draw(Canvas canvas) {
        super.draw(canvas);
        final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
        canvas.translate(0, off);
        mHandleBar.setState(mHandleView.getDrawableState());
        mHandleBar.draw(canvas);
        canvas.translate(0, -off);
    } 
 
    @Override 
    public boolean onTouchEvent(MotionEvent event) {
        if (DEBUG_GESTURES) {
            if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
                EventLog.writeEvent(EventLogTags.SYSUI_NOTIFICATIONPANEL_TOUCH,
                       event.getActionMasked(), (int) event.getX(), (int) event.getY());
            } 
        } 
        if (PhoneStatusBar.SETTINGS_DRAG_SHORTCUT && mStatusBar.mHasFlipSettings) {
            switch (event.getActionMasked()) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, isStateful, setBounds, setCallback
 
            mDotDrawable = dotDrawable;
 
            if (dotDrawable != null) {
 
                if (dotDrawable.getIntrinsicHeight() == -1 || dotDrawable.getIntrinsicWidth() == -1) {
                    // Do not accept Drawable with no intrinsic dimensions. 
                    return; 
                } 
 
                dotDrawable.setBounds(0, 0, dotDrawable.getIntrinsicWidth(), dotDrawable.getIntrinsicHeight());
                dotDrawable.setCallback(this);
                if (dotDrawable.isStateful()) {
                    dotDrawable.setState(getDrawableState());
                } 
            } 
 
            requestLayout(); 
            invalidate(); 
        } 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, setState
    @Override 
    public void draw(Canvas canvas) {
        super.draw(canvas);
        final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
        canvas.translate(0, off);
        mHandleBar.setState(mHandleView.getDrawableState());
        mHandleBar.draw(canvas);
        canvas.translate(0, -off);
    } 
 
    @Override 
    public boolean onTouchEvent(MotionEvent event) {
        if (DEBUG_GESTURES) {
            if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
                EventLog.writeEvent(EventLogTags.SYSUI_QUICKPANEL_TOUCH,
                       event.getActionMasked(), (int) event.getX(), (int) event.getY());
            } 
        } 
        return super.onTouchEvent(event);
    } 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setState
		if (background != null) {
//			Log.e("TiBackground", "background="+background.getClass().getSimpleName()+",state.len="+stateSet.length); 
//			for (int i = 0; i < stateSet.length; i++) { 
//				Log.e("TiBackground", "    state[" + i + "]=" + stateSet[i]); 
//			} 
			drawableChanged = background.setState(stateSet);
			if (drawableChanged) {
				invalidateSelf(); 
			} 
		} 
 
		return changed || drawableChanged;
	} 
 
	@Override 
	public void addState(int[] stateSet, Drawable drawable) {
		if (background instanceof StateListDrawable) {
			((StateListDrawable)background).addState(stateSet, drawable);
		} 
	} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isStateful, setState
            mBackground.setState(getDrawableState());
        } 
        if (mStackedBackground != null && mStackedBackground.isStateful()) {
            mStackedBackground.setState(getDrawableState());
        } 
        if (mSplitBackground != null && mSplitBackground.isStateful()) {
            mSplitBackground.setState(getDrawableState());
        } 
    } 
 
    @Override 
    public void jumpDrawablesToCurrentState() { 
        super.jumpDrawablesToCurrentState(); 
        if (mBackground != null) {
            mBackground.jumpToCurrentState();
        } 
        if (mStackedBackground != null) {
            mStackedBackground.jumpToCurrentState();
        } 
        if (mSplitBackground != null) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setBounds, setState
     @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
 
            if (buttonDrawable != null) {
                buttonDrawable.setState(getDrawableState());
                final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
                final int height = buttonDrawable.getIntrinsicHeight();
                int y = 0;
 
                switch (verticalGravity) {
                    case Gravity.BOTTOM:
                        y = getHeight() - height ;
                        break; 
                    case Gravity.CENTER_VERTICAL:
                        y = (getHeight() - height) / 2;
                        break; 
                } 
 
            int buttonWidth = buttonDrawable.getIntrinsicWidth();

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setBounds, setState
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Drawable setState Questions & Answers:

setState Method Overview
Specify a set of states for the drawable.
See Code Examples for other Android Drawable Methods: