Example usage for android.graphics.drawable StateListDrawable StateListDrawable

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

Introduction

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

Prototype

public StateListDrawable() 

Source Link

Usage

From source file:net.yanzm.mth.MaterialTabHost.java

/**
 * add new tab with specified view//  w  ww.j  av  a 2s .  c om
 *
 * @param view tab view
 */
public void addTab(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple);

    } else {
        // create background using colorControlActivated
        StateListDrawable d = new StateListDrawable();
        d.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(colorControlActivated));
        d.setAlpha(180);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackground(d);
        } else {
            view.setBackgroundDrawable(d);
        }
    }

    int tabId = tabWidget.getTabCount();

    addTab(newTabSpec(String.valueOf(tabId)).setIndicator(view).setContent(android.R.id.tabcontent));
}

From source file:com.esri.android.ecologicalmarineunitexplorer.bottomsheet.BottomSheetFragment.java

/**
 * Build a stateful drawable for a given EMU
 * @param emuName String representing name
 * @return StateListDrawable responsive to selected, pressed, and enabled states
 *///from w w  w  .  j  ava  2  s .  c o m
private static StateListDrawable buildStateList(final int emuName) {
    final StateListDrawable stateListDrawable = new StateListDrawable();

    final GradientDrawable defaultShape = new GradientDrawable();
    final int color = Color.parseColor(EmuHelper.getColorForEMUCluster(emuName));
    defaultShape.setColor(color);

    final GradientDrawable selectedPressShape = new GradientDrawable();
    selectedPressShape.setColor(color);
    selectedPressShape.setStroke(5, Color.parseColor("#f4f442"));

    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, defaultShape);

    return stateListDrawable;
}

From source file:com.filemanager.free.ui.views.FastScroller.java

public void setPressedHandleColor(int i) {
    handle.setColorFilter(i);//from  w  ww  . j  a  v a  2 s  .  com
    StateListDrawable stateListDrawable = new StateListDrawable();
    Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.fastscroller_handle_normal);
    Drawable drawable1 = ContextCompat.getDrawable(getContext(), R.drawable.fastscroller_handle_pressed);
    stateListDrawable.addState(View.PRESSED_ENABLED_STATE_SET, new InsetDrawable(drawable1,
            getResources().getDimensionPixelSize(R.dimen.fastscroller_track_padding), 0, 0, 0));
    stateListDrawable.addState(View.EMPTY_STATE_SET, new InsetDrawable(drawable,
            getResources().getDimensionPixelSize(R.dimen.fastscroller_track_padding), 0, 0, 0));
    this.handle.setImageDrawable(stateListDrawable);
}

From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java

private void initCancelStateDrawable() {
    int colorPressed = getPressedColor(mCancelColorState);

    StrokeGradientDrawable drawablePressed = createDrawable(colorPressed);
    mCancelStateDrawable = new StateListDrawable();

    mCancelStateDrawable.addState(new int[] { android.R.attr.state_pressed },
            drawablePressed.getGradientDrawable());
    mCancelStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}

From source file:com.kkbox.toolkit.app.KKTabFragment.java

protected void initView(View view, int[] buttonTextResourcetId, boolean showSubFragmentAnimation,
        int currentIndex) {
    fixStateForNestedFragment();//from   w w  w.java 2  s.c  om
    initView(view);
    if (this.currentIndex == -1) {
        this.currentIndex = currentIndex;
    }
    this.showSubFragmentAnimation = showSubFragmentAnimation;
    radioGroup = (RadioGroup) view.findViewById(R.id.button_radiogroup);

    TypedValue typedValue = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.KKTabFragmentStyle, typedValue, true);
    TypedArray array = getActivity().obtainStyledAttributes(typedValue.resourceId,
            new int[] { R.attr.KKTabButtonBackgroundLeft, R.attr.KKTabButtonBackgroundMiddle,
                    R.attr.KKTabButtonBackgroundRight });
    int tabButtonBackgroundLeftResourceId = array.getResourceId(0, -1);
    int tabButtonBackgroundMiddleResourceId = array.getResourceId(1, -1);
    int tabButtonBackgroundRightResourceId = array.getResourceId(2, -1);
    array.recycle();
    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { R.attr.KKTabBackground });
    int backgroundResourceId = array.getResourceId(0, -1);
    FrameLayout layoutRadioBar = (FrameLayout) view.findViewById(R.id.layout_radio_bar);
    if (backgroundResourceId != -1) {
        layoutRadioBar.setBackgroundResource(backgroundResourceId);
    }
    array.recycle();

    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { R.attr.KKTabOverlay });
    int overlayResourceId = array.getResourceId(0, -1);
    ImageView viewOverlay = (ImageView) view.findViewById(R.id.view_overlay);
    if (overlayResourceId != -1) {
        viewOverlay.setBackgroundResource(overlayResourceId);
    }
    array.recycle();

    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.textSize });
    int textSize = array.getDimensionPixelSize(0, -1);
    array.recycle();
    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.textColor });
    ColorStateList textColor = array.getColorStateList(0);
    array.recycle();
    array = getActivity().obtainStyledAttributes(typedValue.resourceId, new int[] { android.R.attr.height });
    int height = array.getDimensionPixelSize(0, -1);
    array.recycle();
    for (int i = 0; i < buttonTextResourcetId.length; i++) {
        RadioButton radioButton = new RadioButton(getActivity());
        if (i == 0 && tabButtonBackgroundLeftResourceId != -1) {
            radioButton.setBackgroundResource(tabButtonBackgroundLeftResourceId);
        } else if (i == buttonTextResourcetId.length - 1 && tabButtonBackgroundRightResourceId != -1) {
            radioButton.setBackgroundResource(tabButtonBackgroundRightResourceId);
        } else if (tabButtonBackgroundMiddleResourceId != -1) {
            radioButton.setBackgroundResource(tabButtonBackgroundMiddleResourceId);
        }
        radioButton.setText(buttonTextResourcetId[i]);
        radioButton.setButtonDrawable(new StateListDrawable());
        radioButton.setGravity(Gravity.CENTER);
        radioButton.setTextColor(textColor);
        radioButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        radioButton.setLayoutParams(new RadioGroup.LayoutParams(0, height, 1));
        radioButton.setOnClickListener(buttonClickListener);
        radioGroup.addView(radioButton);
    }
    currentFragment = null;
    radioGroup.getChildAt(this.currentIndex).performClick();

}

From source file:com.tr4android.support.extension.internal.AccountAdapter.java

private static void setupCheckBox(CheckBox checkBox) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        checkBox.setButtonDrawable(R.drawable.btn_checkbox_circle);
        checkBox.setBackgroundResource(R.drawable.btn_checkbox_circle_background);
    } else {/*ww w  .j  a v  a 2 s  .c om*/
        Context context = checkBox.getContext();
        AppCompatDrawableManager dm = AppCompatDrawableManager.get();

        StateListDrawable button = new StateListDrawable();
        button.addState(new int[] { android.R.attr.state_checked },
                dm.getDrawable(context, R.drawable.ic_checkbox_circle_checked));
        button.addState(new int[] {}, dm.getDrawable(context, R.drawable.ic_checkbox_circle_unchecked));
        ColorStateList buttonTint = new ColorStateList(new int[][] { // states
                new int[] { android.R.attr.state_checked }, new int[] {} // state_default
        }, new int[] { // colors
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated),
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlNormal) });
        Drawable buttonCompat = DrawableCompat.wrap(button);
        DrawableCompat.setTintList(buttonCompat, buttonTint);
        checkBox.setButtonDrawable(buttonCompat);

        ShapeDrawable background = new ShapeDrawable(new OvalShape());
        int backgroundTint = ThemeUtils.getThemeAttrColor(context, android.R.attr.colorBackground);
        Drawable backgroundCompat = DrawableCompat.wrap(background);
        DrawableCompat.setTint(backgroundCompat, backgroundTint);
        ViewCompatUtils.setBackground(checkBox, backgroundCompat);
    }
}

From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java

private static StateListDrawable getStateListDrawable(@ColorInt int normalColor, @ColorInt int pressedColor) {
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_activated }, getColorDrawable(pressedColor));
    states.addState(new int[] {}, getColorDrawable(normalColor));
    // Animating across states.
    // It seems item background is lost on scrolling out of the screen, 21 <= API <= 23
    if (!Utils.hasLollipop() || Utils.hasNougat()) {
        int duration = 200; //android.R.integer.config_shortAnimTime
        states.setEnterFadeDuration(duration);
        states.setExitFadeDuration(duration);
    }/*  w w  w.j a v  a 2  s.c  o  m*/
    return states;
}

From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java

private void initIdleStateDrawable() {
    int colorNormal = getNormalColor(mIdleColorState);
    int colorPressed = getPressedColor(mIdleColorState);
    int colorFocused = getFocusedColor(mIdleColorState);
    int colorDisabled = getDisabledColor(mIdleColorState);
    if (background == null) {
        background = createDrawable(colorNormal);
    }//from   ww  w  .  j av a2  s  . c o  m

    StrokeGradientDrawable drawableDisabled = createDrawable(colorDisabled);
    StrokeGradientDrawable drawableFocused = createDrawable(colorFocused);
    StrokeGradientDrawable drawablePressed = createDrawable(colorPressed);
    mIdleStateDrawable = new StateListDrawable();

    mIdleStateDrawable.addState(new int[] { android.R.attr.state_pressed },
            drawablePressed.getGradientDrawable());
    mIdleStateDrawable.addState(new int[] { android.R.attr.state_focused },
            drawableFocused.getGradientDrawable());
    mIdleStateDrawable.addState(new int[] { -android.R.attr.state_enabled },
            drawableDisabled.getGradientDrawable());
    mIdleStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}

From source file:arun.com.chromer.util.ColorUtil.java

@NonNull
public static Drawable getRippleDrawableCompat(final @ColorInt int color) {
    if (Utils.isLollipopAbove()) {
        return new RippleDrawable(ColorStateList.valueOf(color), null, null);
    }/*from   ww w. jav  a 2s .  c om*/
    int translucentColor = ColorUtils.setAlphaComponent(color, 0x44);
    StateListDrawable stateListDrawable = new StateListDrawable();
    int[] states = new int[] { android.R.attr.state_pressed };
    stateListDrawable.addState(states, new ColorDrawable(translucentColor));
    return stateListDrawable;
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

private static Drawable createImageViewNormalBg(int colorControlHighlight) {
    StateListDrawable sld = new StateListDrawable();
    sld.addState(new int[] { android.R.attr.state_pressed }, createImageViewShape(colorControlHighlight));
    sld.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT));
    return sld;/*ww  w  . j  a  v  a 2s. co  m*/
}