Example usage for android.graphics.drawable StateListDrawable getStateDrawable

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

Introduction

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

Prototype

public Drawable getStateDrawable(int index) 

Source Link

Document

Gets the drawable at an index.

Usage

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

private void refreshApplyButton() {
    //Default/*from   ww w . ja  v  a 2s  .  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 ww  w.j a va 2 s  .c  o  m*/
        if (base != null) {
            base.setTint(color);
        }
    }
}