Java Code Examples for android.util.StateSet

The following are top voted examples for showing how to use android.util.StateSet. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RoundButton   File: RoundButton.java   Source Code and License 6 votes vote down vote up
private void update() {
    StateListDrawable background = new StateListDrawable();
    background.addState(new int[]{android.R.attr.state_pressed}, createDrawable(backgroundColorPressed, cornerColorPressed, cornerWidth, cornerRadius));
    background.addState(new int[]{-android.R.attr.state_enabled}, createDrawable(backgroundColorDisabled, cornerColorDisabled, cornerWidth, cornerRadius));
    background.addState(StateSet.WILD_CARD, createDrawable(backgroundColor, cornerColor, cornerWidth, cornerRadius));
    setBackground(background);

    setTextColor(new ColorStateList(
            new int[][]{
                    new int[]{android.R.attr.state_pressed},
                    new int[]{-android.R.attr.state_enabled},
                    new int[]{}
            },
            new int[]{
                    textColorPressed,
                    textColorDisabled,
                    textColor
            }
    ));
}
 
Example 2
Project: EasyEmoji   File: CommonUtil.java   Source Code and License 6 votes vote down vote up
/**
 * 清除View(etc:ListView) 拉至顶部或底部的橡皮筋效果
 */
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
Project: airgram   File: AndroidUtilities.java   Source Code and License 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 4
Project: android-paypal-example   File: BadgeDrawableBuilder.java   Source Code and License 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 5
Project: Mix   File: DrawableUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Extracts state_ attributes from an attribute set.
 *
 * @param attrs The attribute set.
 * @return An array of state_ attributes.
 */
protected 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
Project: Mix   File: ColorStateListUtils.java   Source Code and License 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
Project: letv   File: ResourceManager.java   Source Code and License 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 8
Project: KrGallery   File: AndroidUtilities.java   Source Code and License 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 9
Project: cwac-crossport   File: StateListAnimator.java   Source Code and License 6 votes vote down vote up
/**
   * Called by View
   */
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 10
Project: ChromeLikeTabSwitcher   File: TabletTabRecyclerAdapter.java   Source Code and License 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 11
Project: PlusGram   File: AndroidUtilities.java   Source Code and License 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 12
Project: boohee_v5.6   File: StateListAnimator.java   Source Code and License 6 votes vote down vote up
void setState(int[] state) {
    Tuple match = null;
    int count = this.mTuples.size();
    for (int i = 0; i < count; i++) {
        Tuple tuple = (Tuple) this.mTuples.get(i);
        if (StateSet.stateSetMatches(tuple.mSpecs, state)) {
            match = tuple;
            break;
        }
    }
    if (match != this.mLastMatch) {
        if (this.mLastMatch != null) {
            cancel();
        }
        this.mLastMatch = match;
        View view = (View) this.mViewRef.get();
        if (match != null && view != null && view.getVisibility() == 0) {
            start(match);
        }
    }
}
 
Example 13
Project: SmartOrnament   File: CircularProgressButton.java   Source Code and License 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 14
Project: OpenEyesReading-android   File: Util.java   Source Code and License 6 votes vote down vote up
public void setCircleButtonStateListDrawable(View circleButton, int radius,int color) {
    WeakReference<Bitmap> imageNormal = new WeakReference<>(Bitmap.createBitmap(2 * radius, 2 * radius, Bitmap.Config.ARGB_8888));
    Canvas canvasNormal = new Canvas(imageNormal.get());
    Paint paintNormal = new Paint();
    paintNormal.setAntiAlias(true);
    paintNormal.setColor(color);
    canvasNormal.drawCircle(radius, radius, radius, paintNormal);
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(StateSet.WILD_CARD, new BitmapDrawable(circleButton.getContext().getResources(), imageNormal.get()));
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        circleButton.setBackground(stateListDrawable);
    } else {
        circleButton.setBackgroundDrawable(stateListDrawable);
    }

}
 
Example 15
Project: MagicaSakura   File: DrawableUtils.java   Source Code and License 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 16
Project: MagicaSakura   File: ColorStateListUtils.java   Source Code and License 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 17
Project: Hyber-SDK-Android   File: AndroidUtilities.java   Source Code and License 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 18
Project: permissionsModule   File: StateListAnimator.java   Source Code and License 6 votes vote down vote up
/**
 * Called by View
 */
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;

    View view = mViewRef.get();
    if (match != null && view != null && view.getVisibility() == View.VISIBLE ) {
        start(match);
    }
}
 
Example 19
Project: ProgressButton   File: CircularProgressButton.java   Source Code and License 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 20
Project: AndroidActionItemBadge   File: BadgeDrawableBuilder.java   Source Code and License 6 votes vote down vote up
public StateListDrawable build(Context ctx) {
    StateListDrawable stateListDrawable = new StateListDrawable();

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

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

    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 21
Project: material-components-android   File: StateListAnimator.java   Source Code and License 6 votes vote down vote up
/** Called by View */
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 22
Project: CircularProgressButton   File: CircularProgressButton.java   Source Code and License 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 23
Project: MaterialDrawer   File: BadgeDrawableBuilder.java   Source Code and License 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 24
Project: YouJoin-Android   File: BadgeDrawableBuilder.java   Source Code and License 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
Project: hill-lists   File: FolderPicker.java   Source Code and License 6 votes vote down vote up
@Override
		protected boolean onStateChange(int[] state) {
			boolean active = StateSet.stateSetMatches(STATE_SELECTED, state) | StateSet.stateSetMatches(STATE_PRESSED, state);
			if (active != mActive) {
				mActive = active;
//				Log.d("FolderTransitionDrawable", "onStateChange " + StateSet.dump(state) + " " + active);
				if (!active) {
					unscheduleSelf(this);
					if (mAlpha != 255) {
						startTransition(false);
					}
				} else {
					scheduleSelf(this, SystemClock.uptimeMillis() + 500);
				}
				return true;
			}
			return false;
		}
 
Example 26
Project: FMTech   File: ToolButton.java   Source Code and License 6 votes vote down vote up
@Deprecated
public final void a(int paramInt1, int paramInt2, int paramInt3)
{
  if (paramInt1 == 0) {
    return;
  }
  Resources localResources = getResources();
  StateListDrawable localStateListDrawable = new StateListDrawable();
  if (paramInt2 != 0)
  {
    Drawable localDrawable2 = localResources.getDrawable(paramInt2);
    localStateListDrawable.addState(new int[] { 16842910, 16842913 }, localDrawable2);
  }
  Drawable localDrawable1 = localResources.getDrawable(paramInt1);
  if (paramInt3 == 0) {}
  for (Object localObject = a(localDrawable1);; localObject = localResources.getDrawable(paramInt3))
  {
    localStateListDrawable.addState(new int[] { -16842910 }, (Drawable)localObject);
    localStateListDrawable.addState(new int[] { -16842910, 16842913 }, (Drawable)localObject);
    localStateListDrawable.addState(StateSet.WILD_CARD, localDrawable1);
    this.a.setImageDrawable(localStateListDrawable);
    return;
  }
}
 
Example 27
Project: Carbon   File: AnimatedColorStateList.java   Source Code and License 6 votes vote down vote up
public void setState(int[] newState) {
    if (Arrays.equals(newState, currentState))
        return;
    if (currentState != null)
        cancel();

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

    currentState = newState;
}
 
Example 28
Project: Carbon   File: StateAnimator.java   Source Code and License 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 29
Project: alternate-java-bridge-library   File: TabForm.java   Source Code and License 6 votes vote down vote up
/**
 * Use this method to add a Tab to the tabForm. Each tab is it's own
 * Form.
 * 
 * @param title The title of the tab
 * @param selected - The selected drawable image ( use something like "image42" ) of the tab icon
 * @param notselected - The not selected drawable image of the tab icon
 * @param formtoopen - The Form to open in this tab's space
 */
public void addTab(String title, String selected, String notselected, Class<?> formtoopen) {
	
	int[] temp = new int[2];
	temp[0] = getResources().getIdentifier(selected, "drawable", getPackageName());
	temp[1] = getResources().getIdentifier(notselected, "drawable", getPackageName());
	StateListDrawable draw = new StateListDrawable();
	BitmapDrawable draw1 = (BitmapDrawable) getResources().getDrawable(temp[0]);
	BitmapDrawable draw2 = (BitmapDrawable) getResources().getDrawable(temp[1]);
	draw.addState(new int[] {android.R.attr.state_selected}, draw1);
	draw.addState(StateSet.WILD_CARD , draw2);
	Intent intent = new Intent().setClass(this, formtoopen);
	TabHost.TabSpec spec;
	spec = tabHost.newTabSpec(title.toLowerCase()).setIndicator(title, draw).setContent(intent);		
	tabHost.addTab(spec);		
}
 
Example 30
Project: alternate-java-bridge-library   File: TabForm.java   Source Code and License 6 votes vote down vote up
/**
 * Use this method to add a Tab to the tabForm. Each tab is it's own
 * Form.
 * 
 * @param title The title of the tab
 * @param selected - The resourceId of the selected tab icon
 * @param notselected - The resourceId of the not selected tab icon
 * @param formtoopen - The Form to open in this tab's space
 */	
public void addTab(String title, int selectedresId, int notselectedresId, Class<?> formtoopen) {
	
	int[] temp = new int[2];
	temp[0] = selectedresId;
	temp[1] = notselectedresId;
	StateListDrawable draw = new StateListDrawable();
	BitmapDrawable draw1 = (BitmapDrawable) getResources().getDrawable(temp[0]);
	BitmapDrawable draw2 = (BitmapDrawable) getResources().getDrawable(temp[1]);
	draw.addState(new int[] {android.R.attr.state_selected}, draw1);
	draw.addState(StateSet.WILD_CARD , draw2);
	Intent intent = new Intent().setClass(this, formtoopen);
	TabHost.TabSpec spec;
	spec = tabHost.newTabSpec(title.toLowerCase()).setIndicator(title, draw).setContent(intent);		
	tabHost.addTab(spec);		
}
 
Example 31
Project: digits-android   File: ButtonThemer.java   Source Code and License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
void setBackgroundAccentColor(View view, int accentColor) {
    final StateListDrawable background = new StateListDrawable();
    final float radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5,
            resources.getDisplayMetrics());

    // pressed or in focus
    GradientDrawable tmp = new GradientDrawable();
    tmp.setCornerRadius(radius);
    tmp.setColor(getPressedColor(accentColor));
    for (int[]state: focussedOrPressedButEnabled) {
        background.addState(state, tmp);
    }

    // default
    tmp = new GradientDrawable();
    tmp.setColor(accentColor);
    tmp.setCornerRadius(radius);
    background.addState(StateSet.WILD_CARD, tmp);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(background);
    } else {
        view.setBackgroundDrawable(background);
    }
}
 
Example 32
Project: digits-android   File: ButtonThemer.java   Source Code and License 6 votes vote down vote up
void setTextAccentColorInverse(TextView view, int accentColor) {
    final int pressedColor = getPressedColor(accentColor);
    final int disabledColor = getDisabledColor(accentColor);

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

    final int[] colors = new int[]{pressedColor, pressedColor, disabledColor, accentColor};

    final ColorStateList stateList = new ColorStateList(states, colors);

    view.setTextColor(stateList);
}
 
Example 33
Project: DenleyBihari   File: DrawerListItem.java   Source Code and License 6 votes vote down vote up
/**
 * Sets up the background drawable for this list item.
 *
 * This must be done programatically, to use the theme-dependent background attribute
 * as a fallback for the "pressed" and "normal" states.
 */
private void setupBackground(final Context context){
    // Load the "normal" state, a theme attribute
    final TypedArray backgroundArray = context.obtainStyledAttributes(
            new int[]{R.attr.selectableItemBackground});
    final Drawable normalPressedBackground = backgroundArray.getDrawable(0);
    backgroundArray.recycle();

    // Load the "selected" state
    final Drawable selectedBackground = new ColorDrawable(
            context.getResources().getColor(R.color.selected_item_background));

    // Set up the state-list drawable
    final StateListDrawable background = new StateListDrawable();
    background.addState(new int[]{android.R.attr.state_selected}, selectedBackground);
    background.addState(StateSet.WILD_CARD, normalPressedBackground);

    setBackgroundDrawable(background);
}
 
Example 34
Project: multi-seek-bar   File: AbsMultiSeekBar.java   Source Code and License 6 votes vote down vote up
public static ColorStateList generateDefaultTrackColorStateListFromTheme(Context context) {
	int[][] states = new int[][] {
		SELECTED_STATE_SET,
		ENABLED_STATE_SET,
		StateSet.WILD_CARD
	};

	// This is an approximation of the track colors derived from Lollipop resources
	boolean isLightTheme = Utils.isLightTheme(context);
	int enabled = isLightTheme ? 0x28181818 : 0x85ffffff;

	int[] colors = new int[] {
		Utils.getThemeColor(context, android.R.attr.colorControlActivated),
		enabled,
		0x14181818 //TODO: get this from a theme attr?
	};

	return new ColorStateList(states, colors);
}
 
Example 35
Project: yelo-android   File: AndroidUtilities.java   Source Code and License 6 votes vote down vote up
public static void clearDrawableAnimation(View view) {
    if (Build.VERSION.SDK_INT < 21 || 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 36
Project: indeterminate-checkbox   File: Utils.java   Source Code and License 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 37
Project: actor-platform   File: ComposeFabFragment.java   Source Code and License 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 38
Project: gBike   File: CircularProgressButton.java   Source Code and License 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 39
Project: MaterialDrawer-Xamarin   File: BadgeDrawableBuilder.java   Source Code and License 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 40
Project: CircularProgressButton   File: CircularProgressButton.java   Source Code and License 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 41
Project: edx-app-android   File: IconDrawable.java   Source Code and License 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 42
Project: iosched   File: StateListAnimator.java   Source Code and License 6 votes vote down vote up
/** Called by View */
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 43
Project: commcare-android   File: LoginActivityUIController.java   Source Code and License 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 44
Project: UltimateAndroid   File: CircularProgressButton.java   Source Code and License 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 45
Project: UltimateAndroid   File: CircularProgressButton.java   Source Code and License 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 46
Project: circular-progress-button   File: CircularProgressButton.java   Source Code and License 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 47
Project: CEFCommon   File: MSDrawable.java   Source Code and License 6 votes vote down vote up
public static StateListDrawable createFromDrawables(@NonNull Drawable normal,
                                                    @Nullable Drawable pressed,
                                                    @Nullable Drawable selected,
                                                    @Nullable Drawable disabled) {
    StateListDrawable stateListDrawable = new StateListDrawable();

    if (disabled == null) {
        if (selected != null) {
            stateListDrawable.addState(new int[]{state_selected}, selected);
            stateListDrawable.addState(new int[]{state_checked}, selected);
        }
        if (pressed != null) stateListDrawable.addState(new int[]{state_pressed}, pressed);
        stateListDrawable.addState(StateSet.WILD_CARD, normal);
    } else {
        if (selected != null) {
            stateListDrawable.addState(new int[]{state_selected, state_enabled}, selected);
            stateListDrawable.addState(new int[]{state_checked, state_enabled}, selected);
        }
        if (pressed != null) {
            stateListDrawable.addState(new int[]{state_pressed, state_enabled}, pressed);
        }
        stateListDrawable.addState(new int[]{state_enabled}, normal);
        stateListDrawable.addState(StateSet.WILD_CARD, disabled);
    }
    return stateListDrawable;
}
 
Example 48
Project: Telegram   File: AndroidUtilities.java   Source Code and License 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 49
Project: Telegram   File: Theme.java   Source Code and License 6 votes vote down vote up
public static Drawable createSimpleSelectorCircleDrawable(int size, int defaultColor, int pressedColor) {
    OvalShape ovalShape = new OvalShape();
    ovalShape.resize(size, size);
    ShapeDrawable defaultDrawable = new ShapeDrawable(ovalShape);
    defaultDrawable.getPaint().setColor(defaultColor);
    ShapeDrawable pressedDrawable = new ShapeDrawable(ovalShape);
    if (Build.VERSION.SDK_INT >= 21) {
        pressedDrawable.getPaint().setColor(0xffffffff);
        ColorStateList colorStateList = new ColorStateList(
                new int[][]{StateSet.WILD_CARD},
                new int[]{pressedColor}
        );
        return new RippleDrawable(colorStateList, defaultDrawable, pressedDrawable);
    } else {
        pressedDrawable.getPaint().setColor(pressedColor);
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, pressedDrawable);
        stateListDrawable.addState(new int[]{android.R.attr.state_focused}, pressedDrawable);
        stateListDrawable.addState(StateSet.WILD_CARD, defaultDrawable);
        return stateListDrawable;
    }
}
 
Example 50
Project: Telegram   File: Theme.java   Source Code and License 6 votes vote down vote up
public static Drawable getRoundRectSelectorDrawable() {
    if (Build.VERSION.SDK_INT >= 21) {
        Drawable maskDrawable = createRoundRectDrawable(AndroidUtilities.dp(3), 0xffffffff);
        ColorStateList colorStateList = new ColorStateList(
                new int[][]{StateSet.WILD_CARD},
                new int[]{getColor(key_dialogButtonSelector)}
        );
        return new RippleDrawable(colorStateList, null, maskDrawable);
    } else {
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, createRoundRectDrawable(AndroidUtilities.dp(3), getColor(key_dialogButtonSelector)));
        stateListDrawable.addState(new int[]{android.R.attr.state_selected}, createRoundRectDrawable(AndroidUtilities.dp(3), getColor(key_dialogButtonSelector)));
        stateListDrawable.addState(StateSet.WILD_CARD, new ColorDrawable(0x00000000));
        return stateListDrawable;
    }
}
 
Example 51
Project: Telegram   File: Theme.java   Source Code and License 6 votes vote down vote up
public static Drawable getSelectorDrawable(boolean whiteBackground) {
    if (whiteBackground) {
        if (Build.VERSION.SDK_INT >= 21) {
            Drawable maskDrawable = new ColorDrawable(0xffffffff);
            ColorStateList colorStateList = new ColorStateList(
                    new int[][]{StateSet.WILD_CARD},
                    new int[]{getColor(key_listSelector)}
            );
            return new RippleDrawable(colorStateList, new ColorDrawable(getColor(key_windowBackgroundWhite)), maskDrawable);
        } else {
            int color = getColor(key_listSelector);
            StateListDrawable stateListDrawable = new StateListDrawable();
            stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, new ColorDrawable(color));
            stateListDrawable.addState(new int[]{android.R.attr.state_selected}, new ColorDrawable(color));
            stateListDrawable.addState(StateSet.WILD_CARD, new ColorDrawable(getColor(key_windowBackgroundWhite)));
            return stateListDrawable;
        }
    } else {
        return createSelectorDrawable(getColor(key_listSelector), 2);
    }
}
 
Example 52
Project: LuaViewPlayground   File: UDButton.java   Source Code and License 5 votes vote down vote up
/**
 * 设置按钮的图片
 *
 * @param normalImage
 * @param pressedImage
 * @return
 */
public UDButton setImage(final String normalImage, final String pressedImage) {
    this.mNormalImage = normalImage;
    this.mPressedImage = pressedImage;
    final Button btn = getView();
    if (btn != null && getContext() != null) {
        ImageUtil.fetch(getContext(), getLuaResourceFinder(), new String[]{normalImage, pressedImage}, new ImageUtil.LoadCallback() {
            @Override
            public void onLoadResult(Map<String, Drawable> drawables) {
                if (drawables != null) {
                    final StateListDrawable stateListDrawable = new StateListDrawable();
                    if (drawables.containsKey(pressedImage)) {
                        stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, drawables.get(pressedImage));
                    }
                    if (drawables.containsKey(normalImage)) {
                        stateListDrawable.addState(StateSet.WILD_CARD, drawables.get(normalImage));
                    }
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        btn.setBackground(stateListDrawable);
                    } else {
                        btn.setBackgroundDrawable(stateListDrawable);
                    }
                }
            }
        });
    }
    return this;
}
 
Example 53
Project: LauncherTV   File: ApplicationView.java   Source Code and License 5 votes vote down vote up
private void setBackgroundStateDrawable(float transparency) {
	StateListDrawable stateListDrawable = new StateListDrawable();

	Drawable drawableEnabled = createTileShape(
			Color.argb(getTransparency(transparency, 0.0F), 0xF0, 0xF0, 0xF0),
			Color.argb(0xFF, 0x90, 0x90, 0x90)
	);
	Drawable drawableFocused = createTileShape(
			Color.argb(getTransparency(transparency, 0.4F), 0xE0, 0xE0, 0xFF),
			Color.argb(0xFF, 0x90, 0x90, 0x90)
	);
	Drawable drawablePressed = createTileShape(
			Color.argb(getTransparency(transparency, 0.8F), 0xE0, 0xE0, 0xFF),
			Color.argb(0xFF, 0x00, 0x00, 0x00)
	);

	stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, drawablePressed);
	stateListDrawable.addState(new int[]{android.R.attr.state_focused}, drawableFocused);
	stateListDrawable.addState(new int[]{android.R.attr.state_hovered}, drawableFocused);
	stateListDrawable.addState(StateSet.WILD_CARD, drawableEnabled);

	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		setBackground(stateListDrawable);
	} else {
		//noinspection deprecation
		setBackgroundDrawable(stateListDrawable);
	}
}
 
Example 54
Project: Mix   File: ThemeUtils.java   Source Code and License 5 votes vote down vote up
public static ColorStateList getThemeColorStateList(Context context, ColorStateList origin) {
    if (origin == null) return null;

    if (origin.isStateful()) {
        TintInfo tintInfo = parseColorStateList(origin);
        if (tintInfo == null || tintInfo.isInvalid()) {
            return origin;
        }

        int[] newColors;
        int[][] newStates;
        int index = 0;
        boolean hasDisableColor = StateSet.stateSetMatches(tintInfo.mTintStates[0], DISABLED_STATE_SET);
        if (!hasDisableColor) {
            newStates = new int[tintInfo.mTintStates.length + 1][];
            newColors = new int[tintInfo.mTintStates.length + 1];
            newStates[index] = DISABLED_STATE_SET;
            newColors[index] = getDisabledThemeAttrColor(context, R.attr.themeColorSecondary);
            index++;
        } else {
            newStates = new int[tintInfo.mTintStates.length][];
            newColors = new int[tintInfo.mTintStates.length];
        }

        for (int i = 0; i < tintInfo.mTintStates.length; i++) {
            newStates[index] = tintInfo.mTintStates[i];
            newColors[index] = replaceColor(context, tintInfo.mTintColors[i]);
            index++;
        }
        return new ColorStateList(newStates, newColors);
    }
    return ColorStateList.valueOf(replaceColor(context, origin.getDefaultColor()));
}
 
Example 55
Project: letv   File: ResourceManager.java   Source Code and License 5 votes vote down vote up
public static ColorStateList createColorStateList(int normal, int pressed) {
    int[] colors = new int[]{pressed, pressed, pressed, normal};
    int[][] states = new int[4][];
    states[0] = new int[]{16842919};
    states[1] = new int[]{16842913};
    states[2] = new int[]{16842908};
    states[3] = StateSet.WILD_CARD;
    return new ColorStateList(states, colors);
}
 
Example 56
Project: letv   File: ResourceManager.java   Source Code and License 5 votes vote down vote up
public static StateListDrawable createStateListDrawable(Context context, String normalPicName, String pressedPicName, String enabledPicName) {
    Drawable normalDrawable;
    Drawable enableDrawable;
    Drawable pressedDrawable;
    if (normalPicName.indexOf(".9") > -1) {
        normalDrawable = getNinePatchDrawable(context, normalPicName);
    } else {
        normalDrawable = getDrawable(context, normalPicName);
    }
    if (enabledPicName.indexOf(".9") > -1) {
        enableDrawable = getNinePatchDrawable(context, enabledPicName);
    } else {
        enableDrawable = getDrawable(context, enabledPicName);
    }
    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(new int[]{16842766}, enableDrawable);
    drawable.addState(StateSet.WILD_CARD, normalDrawable);
    return drawable;
}
 
Example 57
Project: MaterialAbout   File: RippleUtil.java   Source Code and License 5 votes vote down vote up
private static StateListDrawable getStateListDrawable(
        int normalColor, int pressedColor) {
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[]{android.R.attr.state_pressed},
            new ColorDrawable(pressedColor));
    states.addState(new int[]{android.R.attr.state_focused},
            new ColorDrawable(pressedColor));
    states.addState(new int[]{android.R.attr.state_activated},
            new ColorDrawable(pressedColor));
    states.addState(new int[]{}, new ColorDrawable(normalColor));
    states.addState(StateSet.WILD_CARD, new ColorDrawable(normalColor));
    return states;
}
 
Example 58
Project: SmartOrnament   File: CircularProgressButton.java   Source Code and License 5 votes vote down vote up
private void initErrorStateDrawable() {
    int colorPressed = getPressedColor(mErrorColorState);

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

    mErrorStateDrawable.addState(new int[]{android.R.attr.state_pressed}, drawablePressed.getGradientDrawable());
    mErrorStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}
 
Example 59
Project: SmartOrnament   File: CircularProgressButton.java   Source Code and License 5 votes vote down vote up
private void initCompleteStateDrawable() {
    int colorPressed = getPressedColor(mCompleteColorState);

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

    mCompleteStateDrawable.addState(new int[]{android.R.attr.state_pressed}, drawablePressed.getGradientDrawable());
    mCompleteStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}
 
Example 60
Project: MagicaSakura   File: ThemeUtils.java   Source Code and License 5 votes vote down vote up
public static ColorStateList getThemeColorStateList(Context context, ColorStateList origin) {
    if (origin == null) return null;

    if (origin.isStateful()) {
        TintInfo tintInfo = parseColorStateList(origin);
        if (tintInfo == null || tintInfo.isInvalid()) {
            return origin;
        }

        int[] newColors;
        int[][] newStates;
        int index = 0;
        boolean hasDisableColor = StateSet.stateSetMatches(tintInfo.mTintStates[0], DISABLED_STATE_SET);
        if (!hasDisableColor) {
            newStates = new int[tintInfo.mTintStates.length + 1][];
            newColors = new int[tintInfo.mTintStates.length + 1];
            newStates[index] = DISABLED_STATE_SET;
            newColors[index] = getDisabledThemeAttrColor(context, R.attr.themeColorSecondary);
            index++;
        } else {
            newStates = new int[tintInfo.mTintStates.length][];
            newColors = new int[tintInfo.mTintStates.length];
        }

        for (int i = 0; i < tintInfo.mTintStates.length; i++) {
            newStates[index] = tintInfo.mTintStates[i];
            newColors[index] = replaceColor(context, tintInfo.mTintColors[i]);
            index++;
        }
        return new ColorStateList(newStates, newColors);
    }
    return ColorStateList.valueOf(replaceColor(context, origin.getDefaultColor()));
}