Java Code Examples for android.graphics.drawable.StateListDrawable#setState()

The following examples show how to use android.graphics.drawable.StateListDrawable#setState() . 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: CreateEDSLocationFragmentBase.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onPrepareOptionsMenu (Menu menu)
{
    super.onPrepareOptionsMenu(menu);
    MenuItem mi = menu.findItem(R.id.confirm);
    mi.setVisible(_state.containsKey(ARG_ADD_EXISTING_LOCATION));
    mi.setTitle(_state.getBoolean(ARG_ADD_EXISTING_LOCATION) ? R.string.add_container : R.string.create_new_container);
    boolean enabled = checkParams();
    mi.setEnabled(enabled);
    @SuppressWarnings("deprecation") StateListDrawable sld = (StateListDrawable) getActivity().getResources().getDrawable(R.drawable.ic_menu_done);
    if(sld!=null)
    {
        sld.setState(enabled ? new int[]{android.R.attr.state_enabled} : new int[0]);
        mi.setIcon(sld.getCurrent());
    }
}
 
Example 2
Source File: Label.java    From FloatingActionButton with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    void onActionDown() {
        if (mUsingStyle) {
            mBackgroundDrawable = getBackground();
        }

        if (mBackgroundDrawable instanceof StateListDrawable) {
            StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
            drawable.setState(new int[]{android.R.attr.state_pressed});
        } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
            RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
            ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
            ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
            ripple.setVisible(true, true);
        }
//        setPressed(true);
    }
 
Example 3
Source File: Label.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mUsingStyle) {
        mBackgroundDrawable = getBackground();
    }

    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{});
    } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{});
        ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        ripple.setVisible(true, true);
    }
    setPressed(false);
}
 
Example 4
Source File: Label.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mUsingStyle) {
        mBackgroundDrawable = getBackground();
    }

    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_pressed});
    } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
        ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        ripple.setVisible(true, true);
    }
    setPressed(true);
}
 
Example 5
Source File: Label.java    From FloatingActionButton with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    void onActionUp() {
        if (mUsingStyle) {
            mBackgroundDrawable = getBackground();
        }

        if (mBackgroundDrawable instanceof StateListDrawable) {
            StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
            drawable.setState(new int[]{});
        } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
            RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
            ripple.setState(new int[]{});
            ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
            ripple.setVisible(true, true);
        }
//        setPressed(false);
    }
 
Example 6
Source File: Label.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    void onActionUp() {
        if (mUsingStyle) {
            mBackgroundDrawable = getBackground();
        }

        if (mBackgroundDrawable instanceof StateListDrawable) {
            StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
            drawable.setState(new int[]{});
        } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
            RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
            ripple.setState(new int[]{});
            ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
            ripple.setVisible(true, true);
        }
//        setPressed(false);
    }
 
Example 7
Source File: Label.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
    void onActionDown() {
        if (mUsingStyle) {
            mBackgroundDrawable = getBackground();
        }

        if (mBackgroundDrawable instanceof StateListDrawable) {
            StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
            drawable.setState(new int[]{android.R.attr.state_pressed});
        } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
            RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
            ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
            ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
            ripple.setVisible(true, true);
        }
//        setPressed(true);
    }
 
Example 8
Source File: FloatingActionButton.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_enabled});
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled});
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
 
Example 9
Source File: FloatingActionButton.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
 
Example 10
Source File: FloatingActionButton.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_enabled});
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled});
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
 
Example 11
Source File: FloatingActionButton.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
 
Example 12
Source File: BookPageFragment.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
private void setBookMarkIcon(@NonNull MenuItem item) {
    TypedValue typedvalueattr = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.menuBookmarkIcon, typedvalueattr, true);
    StateListDrawable stateListDrawable = (StateListDrawable) getResources().getDrawable(typedvalueattr.resourceId);
    int[] state = {item.isChecked() ? android.R.attr.state_checked : -android.R.attr.state_checked};
    stateListDrawable.setState(state);
    item.setIcon(stateListDrawable.getCurrent());
    item.setTitle(item.isChecked() ? R.string.action_remove_book_mark : R.string.action_add_book_mark);
}
 
Example 13
Source File: HolographicLinearLayout.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();

    if (mImageView != null) {
        Drawable d = mImageView.getDrawable();
        if (d instanceof StateListDrawable) {
            StateListDrawable sld = (StateListDrawable) d;
            sld.setState(getDrawableState());
            sld.invalidateSelf();
        }
    }
}
 
Example 14
Source File: HolographicImageView.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();

    Drawable d = getDrawable();
    if (d instanceof StateListDrawable) {
        StateListDrawable sld = (StateListDrawable) d;
        sld.setState(getDrawableState());
        sld.invalidateSelf();
    }
}
 
Example 15
Source File: FloatingActionButton.java    From FloatingActionButton with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed});
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
 
Example 16
Source File: FloatingActionButton.java    From FloatingActionButton with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionUp() {
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[]{android.R.attr.state_enabled});
    } else if (Util.hasLollipop()) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[]{android.R.attr.state_enabled});
        ripple.setHotspot(calculateCenterX(), calculateCenterY());
        ripple.setVisible(true, true);
    }
}
 
Example 17
Source File: PhasedSeekBar.java    From android-phased-seek-bar with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mFirstDraw) configure();
    if (mBackgroundDrawable != null) mBackgroundDrawable.draw(canvas);
    if (isInEditMode()) return;

    Drawable itemOff;
    Drawable itemOn;
    StateListDrawable stateListDrawable;
    int count = getCount();

    if (!mUpdateFromPosition) {
        int distance;
        int minIndex = 0;
        int minDistance = Integer.MAX_VALUE;
        for (int i = 0; i < count; i++) {
            distance = Math.abs(mModeIsHorizontal ? mAnchors[i][0] - mCurrentX : mAnchors[i][1] - mCurrentY);
            if (minDistance > distance) {
                minIndex = i;
                minDistance = distance;
            }
        }

        setCurrentItem(minIndex);
        stateListDrawable = mAdapter.getItem(minIndex);
    } else {
        mUpdateFromPosition = false;
        mCurrentX = mAnchors[mCurrentItem][0];
        mCurrentY = mAnchors[mCurrentItem][1];
        stateListDrawable = mAdapter.getItem(mCurrentItem);
    }
    stateListDrawable.setState(mState);
    itemOn = stateListDrawable.getCurrent();

    for (int i = 0; i < count; i++) {
        if (!mDrawOnOff && i == mCurrentItem) continue;
        stateListDrawable = mAdapter.getItem(i);
        stateListDrawable.setState(STATE_NORMAL);
        itemOff = stateListDrawable.getCurrent();
        itemOff.setBounds(
                mAnchors[i][0] - mItemHalfWidth,
                mAnchors[i][1] - mItemHalfHeight,
                mAnchors[i][0] + mItemHalfWidth,
                mAnchors[i][1] + mItemHalfHeight);
        itemOff.draw(canvas);
    }

    itemOn.setBounds(
            mCurrentX - mItemHalfWidth,
            mCurrentY - mItemHalfHeight,
            mCurrentX + mItemHalfWidth,
            mCurrentY + mItemHalfHeight);
    itemOn.draw(canvas);

    setFirstDraw(false);
}
 
Example 18
Source File: GBSlideBar.java    From GBSlideBar with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (mFirstDraw) drawBackground();
        if (mBackgroundDrawable != null) mBackgroundDrawable.draw(canvas);
        if (isInEditMode()) return;

        Drawable itemDefault, itemSlide;
        StateListDrawable stateListDrawable;

        if (!mSlide) {
            int distance, minIndex = 0, minDistance = Integer.MAX_VALUE;
            for (int i = 0; i < getCount(); i++) {
                distance = Math.abs(mModIsHorizontal ? mAnchor[i][0] - mCurrentX : mAnchor[i][1] - mCurrentY);
                if (minDistance > distance) {
                    minIndex = i;
                    minDistance = distance;
                }
            }

            setCurrentItem(minIndex);
            stateListDrawable = mAdapter.getItem(minIndex);


        } else {
            mSlide = false;
            mCurrentX = mAnchor[mCurrentItem][0];
            mCurrentY = mAnchor[mCurrentItem][1];
            if (mFirstDraw) {
                mSlideX = mLastX = mCurrentX;
            }
            stateListDrawable = mAdapter.getItem(mCurrentItem);

            mIsFirstSelect = true;


        }
        stateListDrawable.setState(mState);
        itemDefault = stateListDrawable.getCurrent();


        for (int i = 0; i < getCount(); i++) {
            if (i == mCurrentItem) {
//                continue; //
                mPaint.setColor(mAdapter.getTextColor(mCurrentItem));
                canvas.drawText(mAdapter.getText(i), mAnchor[i][0], mAnchor[i][1] + mAnchorHeight * 3 / 2 + mTextMargin, mPaint);
            }else {
                mPaint.setColor(mTextColor);
                canvas.drawText(mAdapter.getText(i), mAnchor[i][0], mAnchor[i][1] + mAnchorHeight * 3 / 2 + mTextMargin, mPaint);
            }
            stateListDrawable = mAdapter.getItem(i);
            stateListDrawable.setState(STATE_NORMAL);
            itemSlide = stateListDrawable.getCurrent();
            itemSlide.setBounds(
                    mAnchor[i][0] - mPlaceHolderWidth,
                    mAnchor[i][1] - mPlaceHolderHeight,
                    mAnchor[i][0] + mPlaceHolderWidth,
                    mAnchor[i][1] + mPlaceHolderHeight
            );
            itemSlide.draw(canvas);

        }


        itemDefault.setBounds(
                mSlideX - mAnchorWidth,
                mPivotY + mAbsoluteY / 2 - mAnchorHeight,
                mSlideX + mAnchorWidth,
                mPivotY + mAbsoluteY / 2 + mAnchorHeight
        );

        itemDefault.draw(canvas);

        setFirstDraw(false);

    }
 
Example 19
Source File: TargetDrawable.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
public void setState(int [] state) {
    if (mDrawable instanceof StateListDrawable) {
        StateListDrawable d = (StateListDrawable) mDrawable;
        d.setState(state);
    }
}