android.util.StateSet Java Examples

The following examples show how to use android.util.StateSet. 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 Project: android_9.0.0_r45   Author: lulululbj   File: StateListAnimator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Called by View
 * @hide
 */
public void setState(int[] state) {
    Tuple match = null;
    final int count = mTuples.size();
    for (int i = 0; i < count; i++) {
        final Tuple tuple = mTuples.get(i);
        if (StateSet.stateSetMatches(tuple.mSpecs, state)) {
            match = tuple;
            break;
        }
    }
    if (match == mLastMatch) {
        return;
    }
    if (mLastMatch != null) {
        cancel();
    }
    mLastMatch = match;
    if (match != null) {
        start(match);
    }
}
 
Example #2
Source Project: TelePlus-Android   Author: TelePlusDev   File: AndroidUtilities.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static void clearDrawableAnimation(View view)
{
    if (Build.VERSION.SDK_INT < 21 || view == null)
    {
        return;
    }
    Drawable drawable;
    if (view instanceof ListView)
    {
        drawable = ((ListView) view).getSelector();
        if (drawable != null)
        {
            drawable.setState(StateSet.NOTHING);
        }
    }
    else
    {
        drawable = view.getBackground();
        if (drawable != null)
        {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}
 
Example #3
Source Project: TelePlus-Android   Author: TelePlusDev   File: RecyclerListView.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void updateSelectorState()
{
    if (selectorDrawable != null && selectorDrawable.isStateful())
    {
        if (currentChildView != null)
        {
            if (selectorDrawable.setState(getDrawableStateForSelector()))
            {
                invalidateDrawable(selectorDrawable);
            }
        }
        else
        {
            selectorDrawable.setState(StateSet.NOTHING);
        }
    }
}
 
Example #4
Source Project: timecat   Author: triline3   File: CircularProgressButton.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }

    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());
}
 
Example #5
Source Project: timecat   Author: triline3   File: DrawableUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Extracts state_ attributes from an attribute set.
 *
 * @param attrs The attribute set.
 *
 * @return An array of state_ attributes.
 */
static int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        if (stateResId == 0) {
            break;
        } else if (stateResId == android.R.attr.drawable || stateResId == android.R.attr.id || stateResId == R.attr.drawableTint || stateResId == R.attr.drawableTintMode) {
            // Ignore attributes from StateListDrawableItem and
            // AnimatedStateListDrawableItem.
            continue;
        } else {
            states[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId;
        }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
}
 
Example #6
Source Project: timecat   Author: triline3   File: ColorStateListUtils.java    License: Apache License 2.0 6 votes vote down vote up
protected static int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        switch (stateResId) {
            case 0:
                break;
            case android.R.attr.color:
            case android.R.attr.alpha:
                // Ignore attributes from StateListDrawableItem and
                // AnimatedStateListDrawableItem.
                continue;
            default:
                states[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId;
        }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
}
 
Example #7
Source Project: TelePlus-Android   Author: TelePlusDev   File: AndroidUtilities.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static void clearDrawableAnimation(View view)
{
    if (Build.VERSION.SDK_INT < 21 || view == null)
    {
        return;
    }
    Drawable drawable;
    if (view instanceof ListView)
    {
        drawable = ((ListView) view).getSelector();
        if (drawable != null)
        {
            drawable.setState(StateSet.NOTHING);
        }
    }
    else
    {
        drawable = view.getBackground();
        if (drawable != null)
        {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}
 
Example #8
Source Project: TelePlus-Android   Author: TelePlusDev   File: RecyclerListView.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void updateSelectorState()
{
    if (selectorDrawable != null && selectorDrawable.isStateful())
    {
        if (currentChildView != null)
        {
            if (selectorDrawable.setState(getDrawableStateForSelector()))
            {
                invalidateDrawable(selectorDrawable);
            }
        }
        else
        {
            selectorDrawable.setState(StateSet.NOTHING);
        }
    }
}
 
Example #9
Source Project: SSForms   Author: StarkSoftware   File: DirectoryFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static void clearDrawableAnimation(View view) {
    if (view == null) {
        return;
    }
    Drawable drawable = null;
    if (view instanceof ListView) {
        drawable = ((ListView) view).getSelector();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
        }
    } else {
        drawable = view.getBackground();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}
 
Example #10
Source Project: android-paypal-example   Author: OmarAliSaid   File: BadgeDrawableBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public StateListDrawable build(Context ctx) {
    StateListDrawable stateListDrawable = new StateListDrawable();

    GradientDrawable normal = (GradientDrawable) ContextCompat.getDrawable(ctx, R.drawable.action_item_badge);
    GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();

    normal.setColor(mColor);
    selected.setColor(mColorPressed);

    if (mStroke > -1) {
        normal.setStroke(mStroke, mStrokeColor);
        selected.setStroke(mStroke, mStrokeColor);
    }

    if (mCorners > -1) {
        normal.setCornerRadius(mCorners);
        selected.setCornerRadius(mCorners);
    }

    stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected);
    stateListDrawable.addState(StateSet.WILD_CARD, normal);

    return stateListDrawable;
}
 
Example #11
Source Project: letv   Author: JackChan1999   File: ResourceManager.java    License: Apache License 2.0 6 votes vote down vote up
public static StateListDrawable createStateListDrawable(Context context, String normalPicName, String pressedPicName) {
    Drawable normalDrawable;
    Drawable pressedDrawable;
    if (normalPicName.indexOf(".9") > -1) {
        normalDrawable = getNinePatchDrawable(context, normalPicName);
    } else {
        normalDrawable = getDrawable(context, normalPicName);
    }
    if (pressedPicName.indexOf(".9") > -1) {
        pressedDrawable = getNinePatchDrawable(context, pressedPicName);
    } else {
        pressedDrawable = getDrawable(context, pressedPicName);
    }
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{16842919}, pressedDrawable);
    drawable.addState(new int[]{16842913}, pressedDrawable);
    drawable.addState(new int[]{16842908}, pressedDrawable);
    drawable.addState(StateSet.WILD_CARD, normalDrawable);
    return drawable;
}
 
Example #12
Source Project: KrGallery   Author: chengzichen   File: AndroidUtilities.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static void clearDrawableAnimation(View view) {
    if (Build.VERSION.SDK_INT < 21 || view == null) {
        return;
    }
    Drawable drawable;
    if (view instanceof ListView) {
        drawable = ((ListView) view).getSelector();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
        }
    } else {
        drawable = view.getBackground();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}
 
Example #13
Source Project: ChromeLikeTabSwitcher   Author: michael-rapp   File: TabletTabRecyclerAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
protected final View onInflateTabView(@NonNull final LayoutInflater inflater,
                                      @Nullable final ViewGroup parent,
                                      @NonNull final AbstractTabViewHolder viewHolder) {
    View view = inflater.inflate(R.layout.tablet_tab, parent, false);
    StateListDrawable backgroundDrawable = new StateListDrawable();
    Drawable defaultDrawable = ContextCompat
            .getDrawable(getModel().getContext(), R.drawable.tablet_tab_background);
    Drawable selectedDrawable = ContextCompat
            .getDrawable(getModel().getContext(), R.drawable.tablet_tab_background_selected);
    backgroundDrawable.addState(new int[]{android.R.attr.state_selected}, selectedDrawable);
    backgroundDrawable.addState(StateSet.WILD_CARD, defaultDrawable);
    ViewUtil.setBackground(view, backgroundDrawable);
    return view;
}
 
Example #14
Source Project: ShareBox   Author: Kerr1Gan   File: CircularProgressButton.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }

    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());
}
 
Example #15
Source Project: SmartOrnament   Author: fergus825   File: CircularProgressButton.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }

    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());
}
 
Example #16
Source Project: ProgressButton   Author: nihasKalam07   File: CircularProgressButton.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }

    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());
}
 
Example #17
Source Project: MagicaSakura   Author: bilibili   File: DrawableUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Extracts state_ attributes from an attribute set.
 *
 * @param attrs The attribute set.
 * @return An array of state_ attributes.
 */
static int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        if (stateResId == 0) {
            break;
        } else if (stateResId == android.R.attr.drawable
                || stateResId == android.R.attr.id
                || stateResId == R.attr.drawableTint
                || stateResId == R.attr.drawableTintMode) {
            // Ignore attributes from StateListDrawableItem and
            // AnimatedStateListDrawableItem.
            continue;
        } else {
            states[j++] = attrs.getAttributeBooleanValue(i, false)
                    ? stateResId : -stateResId;
        }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
}
 
Example #18
Source Project: MagicaSakura   Author: bilibili   File: ColorStateListUtils.java    License: Apache License 2.0 6 votes vote down vote up
protected static int[] extractStateSet(AttributeSet attrs) {
    int j = 0;
    final int numAttrs = attrs.getAttributeCount();
    int[] states = new int[numAttrs];
    for (int i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        switch (stateResId) {
            case 0:
                break;
            case android.R.attr.color:
            case android.R.attr.alpha:
                // Ignore attributes from StateListDrawableItem and
                // AnimatedStateListDrawableItem.
                continue;
            default:
                states[j++] = attrs.getAttributeBooleanValue(i, false)
                        ? stateResId : -stateResId;
        }
    }
    states = StateSet.trimStateSet(states, j);
    return states;
}
 
Example #19
Source Project: material-components-android   Author: material-components   File: StateListAnimator.java    License: Apache License 2.0 6 votes vote down vote up
/** Called by View */
public void setState(int[] state) {
  Tuple match = null;
  final int count = tuples.size();
  for (int i = 0; i < count; i++) {
    final Tuple tuple = tuples.get(i);
    if (StateSet.stateSetMatches(tuple.specs, state)) {
      match = tuple;
      break;
    }
  }
  if (match == lastMatch) {
    return;
  }
  if (lastMatch != null) {
    cancel();
  }

  lastMatch = match;

  if (match != null) {
    start(match);
  }
}
 
Example #20
Source Project: Carbon   Author: ZieIony   File: AnimatedColorStateList.java    License: Apache License 2.0 6 votes vote down vote up
public void setState(int[] newState) {
    synchronized (AnimatedColorStateList.this) {
        if (Arrays.equals(newState, currentState))
            return;

        colorAnimation.end();

        if (currentState.length != 0) {
            for (final int[] state : states) {
                if (StateSet.stateSetMatches(state, newState)) {
                    int firstColor = getColorForState(currentState, getDefaultColor());
                    int secondColor = super.getColorForState(newState, getDefaultColor());
                    colorAnimation.setIntValues(firstColor, secondColor);
                    currentState = newState;
                    animatedColor = firstColor;
                    colorAnimation.start();
                    return;
                }
            }
        }

        currentState = newState;
    }
}
 
Example #21
Source Project: Carbon   Author: ZieIony   File: StateAnimator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Called by View
 */
public void setState(int[] state) {
    Tuple match = null;
    final int count = mTuples.size();
    for (int i = 0; i < count; i++) {
        final Tuple tuple = mTuples.get(i);
        if (StateSet.stateSetMatches(tuple.mSpecs, state)) {
            match = tuple;
            break;
        }
    }
    if (match == lastMatch) {
        return;
    }
    if (lastMatch != null) {
        cancel();
    }

    lastMatch = match;

    View view = (View) viewRef.get();
    if (match != null && view != null && view.getVisibility() == View.VISIBLE) {
        start(match);
    }
}
 
Example #22
Source Project: indeterminate-checkbox   Author: sevar83   File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
private static ColorStateList createIndeterminateColorStateList(Context context) {

        final int[][] states = new int[][]{
                new int[]{-android.R.attr.state_enabled},
                new int[]{R.attr.state_indeterminate},
                new int[]{android.R.attr.state_checked},
                StateSet.WILD_CARD
        };

        final int normal = resolveColor(context, R.attr.colorControlNormal, Color.DKGRAY);
        final int activated = resolveColor(context, R.attr.colorControlActivated, Color.CYAN);
        final int intermediate = resolveColor(context, R.attr.colorControlIndeterminate, activated);
        final float disabledAlpha = resolveFloat(context, android.R.attr.disabledAlpha, 0.25f);
        final int[] colors = new int[]{
                Utils.applyAlpha(normal, disabledAlpha),
                intermediate,
                activated,
                normal
        };

        return new ColorStateList(states, colors);
    }
 
Example #23
Source Project: actor-platform   Author: actorapp   File: ComposeFabFragment.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View res = inflater.inflate(R.layout.fragment_fab, container, false);
    FloatingActionButton fabRoot = (FloatingActionButton) res.findViewById(R.id.fab);
    fabRoot.setImageResource(R.drawable.ic_edit_white_24dp);
    fabRoot.setBackgroundTintList(new ColorStateList(new int[][]{
            new int[]{android.R.attr.state_pressed},
            StateSet.WILD_CARD,

    }, new int[]{
            ActorSDK.sharedActor().style.getFabPressedColor(),
            ActorSDK.sharedActor().style.getFabColor(),
    }));
    fabRoot.setRippleColor(ActorSDK.sharedActor().style.getFabPressedColor());
    fabRoot.setOnClickListener(v -> startActivity(new Intent(getActivity(), ComposeActivity.class)));
    return res;
}
 
Example #24
Source Project: MaterialDrawer-Xamarin   Author: amatkivskiy   File: BadgeDrawableBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public StateListDrawable build(Context ctx) {
    StateListDrawable stateListDrawable = new StateListDrawable();

    GradientDrawable normal = (GradientDrawable) UIUtils.getCompatDrawable(ctx, mStyle.getGradientDrawable());
    GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();

    ColorHolder.applyToOrTransparent(mStyle.getColor(), ctx, normal);
    if (mStyle.getColorPressed() == null) {
        ColorHolder.applyToOrTransparent(mStyle.getColor(), ctx, selected);
    } else {
        ColorHolder.applyToOrTransparent(mStyle.getColorPressed(), ctx, selected);
    }

    if (mStyle.getCorners() != null) {
        normal.setCornerRadius(mStyle.getCorners().asPixel(ctx));
        selected.setCornerRadius(mStyle.getCorners().asPixel(ctx));
    }

    stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected);
    stateListDrawable.addState(StateSet.WILD_CARD, normal);

    return stateListDrawable;
}
 
Example #25
Source Project: edx-app-android   Author: edx   File: IconDrawable.java    License: Apache License 2.0 6 votes vote down vote up
private IconDrawable(Context context, @NonNull IconState state) {
    iconState = state;
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    // We have already confirmed that a typeface exists for this icon during
    // validation, so we can ignore the null pointer warning.
    //noinspection ConstantConditions
    paint.setTypeface(Iconify.findTypefaceOf(state.icon).getTypeface(context));
    paint.setStyle(state.style);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setUnderlineText(false);
    color = state.colorStateList.getColorForState(StateSet.WILD_CARD, DEFAULT_COLOR);
    paint.setColor(color);
    updateTintFilter();
    setModulatedAlpha();
    paint.setDither(iconState.dither);
    text = String.valueOf(iconState.icon.character());
    if (SDK_INT < LOLLIPOP && iconState.bounds != null) {
        setBounds(iconState.bounds);
    }
}
 
Example #26
Source Project: commcare-android   Author: dimagi   File: LoginActivityUIController.java    License: Apache License 2.0 6 votes vote down vote up
private void setupLoginButton() {
    ColorDrawable colorDrawable = new ColorDrawable(getResources().getColor(R.color.cc_brand_color));
    ColorDrawable disabledColor = new ColorDrawable(getResources().getColor(R.color.grey));

    StateListDrawable sld = new StateListDrawable();

    sld.addState(new int[]{-android.R.attr.state_enabled}, disabledColor);
    sld.addState(StateSet.WILD_CARD, colorDrawable);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        loginButton.setBackground(sld);
    } else {
        loginButton.setBackgroundDrawable(sld);
    }

    loginButton.setTextColor(getResources().getColor(R.color.cc_neutral_bg));
}
 
Example #27
Source Project: UltimateAndroid   Author: cymcsg   File: CircularProgressButton.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }

    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());
}
 
Example #28
Source Project: UltimateAndroid   Author: cymcsg   File: CircularProgressButton.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }

    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());
}
 
Example #29
Source Project: simpletask-android   Author: mpcjanssen   File: Utils.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static ColorStateList createIndetermColorStateList(Context context) {

        final int[][] states = new int[][]{
                new int[]{-android.R.attr.state_enabled},
                new int[]{R.attr.state_indeterminate},
                new int[]{android.R.attr.state_checked},
                StateSet.WILD_CARD
        };

        final int normal = resolveColor(context, R.attr.colorControlNormal, Color.DKGRAY);
        final int activated = resolveColor(context, R.attr.colorControlActivated, Color.CYAN);
        final float disabledAlpha = resolveFloat(context, android.R.attr.disabledAlpha, 0.25f);
        final int[] colors = new int[]{
                Utils.applyAlpha(normal, disabledAlpha),
                normal,
                activated,
                normal
        };

        return new ColorStateList(states, colors);
    }
 
Example #30
Source Project: Telegram-FOSS   Author: Telegram-FOSS-Team   File: AndroidUtilities.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static void clearDrawableAnimation(View view) {
    if (Build.VERSION.SDK_INT < 21 || view == null) {
        return;
    }
    Drawable drawable;
    if (view instanceof ListView) {
        drawable = ((ListView) view).getSelector();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
        }
    } else {
        drawable = view.getBackground();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}