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

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

源代码1 项目: edslite   文件: CreateEDSLocationFragmentBase.java
@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());
    }
}
 
源代码2 项目: ShareBox   文件: Label.java
@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);
    }
 
源代码3 项目: ShareBox   文件: Label.java
@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);
    }
 
源代码4 项目: clear-todolist   文件: Label.java
@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);
}
 
源代码5 项目: clear-todolist   文件: Label.java
@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);
}
 
源代码6 项目: FloatingActionButton   文件: Label.java
@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);
    }
 
源代码7 项目: FloatingActionButton   文件: Label.java
@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);
    }
 
源代码8 项目: IslamicLibraryAndroid   文件: BookPageFragment.java
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);
}
 
源代码9 项目: ShareBox   文件: FloatingActionButton.java
@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);
    }
}
 
源代码10 项目: ShareBox   文件: FloatingActionButton.java
@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);
    }
}
 
源代码11 项目: clear-todolist   文件: FloatingActionButton.java
@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);
    }
}
 
源代码12 项目: clear-todolist   文件: FloatingActionButton.java
@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);
    }
}
 
源代码13 项目: TurboLauncher   文件: HolographicLinearLayout.java
@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();
        }
    }
}
 
源代码14 项目: TurboLauncher   文件: HolographicImageView.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();

    Drawable d = getDrawable();
    if (d instanceof StateListDrawable) {
        StateListDrawable sld = (StateListDrawable) d;
        sld.setState(getDrawableState());
        sld.invalidateSelf();
    }
}
 
@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);
    }
}
 
@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);
    }
}
 
源代码17 项目: CSipSimple   文件: TargetDrawable.java
public void setState(int [] state) {
    if (mDrawable instanceof StateListDrawable) {
        StateListDrawable d = (StateListDrawable) mDrawable;
        d.setState(state);
    }
}
 
源代码18 项目: GBSlideBar   文件: GBSlideBar.java
@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);

    }
 
源代码19 项目: android-phased-seek-bar   文件: PhasedSeekBar.java
@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);
}