Example usage for android.graphics.drawable StateListDrawable getStateDrawableIndex

List of usage examples for android.graphics.drawable StateListDrawable getStateDrawableIndex

Introduction

In this page you can find the example usage for android.graphics.drawable StateListDrawable getStateDrawableIndex.

Prototype

public int getStateDrawableIndex(int[] stateSet) 

Source Link

Document

Gets the index of the drawable with the provided state set.

Usage

From source file:org.cyanogenmod.theme.chooser.ChooserDetailFragment.java

private void refreshApplyButton() {
    //Default//w  ww.j  a  va  2  s.  c  om
    mApply.setText(R.string.apply);
    StateListDrawable d = (StateListDrawable) mApply.getBackground();
    LayerDrawable bg = (LayerDrawable) d
            .getStateDrawable(d.getStateDrawableIndex(new int[] { android.R.attr.state_enabled }));
    final ClipDrawable clip = (ClipDrawable) bg.findDrawableByLayerId(android.R.id.progress);
    clip.setLevel(0);

    //Determine whether the apply button should show "apply" or "update"
    if (mAppliedThemeCursor != null) {
        mAppliedThemeCursor.moveToPosition(-1);
        while (mAppliedThemeCursor.moveToNext()) {
            String component = mAppliedThemeCursor
                    .getString(mAppliedThemeCursor.getColumnIndex(MixnMatchColumns.COL_KEY));
            String pkg = mAppliedThemeCursor
                    .getString(mAppliedThemeCursor.getColumnIndex(MixnMatchColumns.COL_VALUE));

            // At least one component is set here for this theme
            if (pkg != null && mPkgName.equals(pkg)) {
                mApply.setText(R.string.update);
                break;
            }
        }
    }

    //Determine if the apply button's progress
    int progress = (mService == null) ? 0 : mService.getProgress();
    if (progress != 0) {
        clip.setLevel(progress * 100);
        mApply.setText(R.string.applying);
        mApply.setClickable(false);
    } else {
        mApply.setClickable(true);
    }
}

From source file:com.android.mms.ui.MessageListItem.java

private void tintBackground(Drawable background, int color) {
    if (background instanceof LayerDrawable) {
        Drawable base = ((LayerDrawable) background).findDrawableByLayerId(R.id.base_layer);
        if (base instanceof StateListDrawable) {
            StateListDrawable sld = (StateListDrawable) base;
            base = sld.getStateDrawable(sld.getStateDrawableIndex(null));

        }//from   w ww  .  j a v a2  s.  com
        if (base != null) {
            base.setTint(color);
        }
    }
}