Search in sources :

Example 56 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project FlycoDialog_Master by H07000223.

the class CornerUtils method listItemSelector.

/**
     * set ListView item selector with corner drawable for the first and the last position
     * (ListView的item点击效果,第一项和最后一项圆角处理)
     */
public static StateListDrawable listItemSelector(float radius, int normalColor, int pressColor, int itemTotalSize, int itemPosition) {
    StateListDrawable bg = new StateListDrawable();
    Drawable normal = null;
    Drawable pressed = null;
    if (itemPosition == 0 && itemPosition == itemTotalSize - 1) {
        // 只有一项
        normal = cornerDrawable(normalColor, new float[] { radius, radius, radius, radius, radius, radius, radius, radius });
        pressed = cornerDrawable(pressColor, new float[] { radius, radius, radius, radius, radius, radius, radius, radius });
    } else if (itemPosition == 0) {
        normal = cornerDrawable(normalColor, new float[] { radius, radius, radius, radius, 0, 0, 0, 0 });
        pressed = cornerDrawable(pressColor, new float[] { radius, radius, radius, radius, 0, 0, 0, 0 });
    } else if (itemPosition == itemTotalSize - 1) {
        normal = cornerDrawable(normalColor, new float[] { 0, 0, 0, 0, radius, radius, radius, radius });
        pressed = cornerDrawable(pressColor, new float[] { 0, 0, 0, 0, radius, radius, radius, radius });
    } else {
        normal = new ColorDrawable(normalColor);
        pressed = new ColorDrawable(pressColor);
    }
    bg.addState(new int[] { -android.R.attr.state_pressed }, normal);
    bg.addState(new int[] { android.R.attr.state_pressed }, pressed);
    return bg;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 57 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project UltimateAndroid by cymcsg.

the class MaskImageView method createStateDrawable.

public StateListDrawable createStateDrawable(Context context, Drawable normal) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(View.PRESSED_ENABLED_STATE_SET, createPressDrawable(normal));
    drawable.addState(View.ENABLED_STATE_SET, normal);
    drawable.addState(View.EMPTY_STATE_SET, normal);
    return drawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 58 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project UltimateAndroid by cymcsg.

the class CircularProgressButton method initCompleteStateDrawable.

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());
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) SuppressLint(android.annotation.SuppressLint)

Example 59 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project android_frameworks_base by DirtyUnicorns.

the class ProgressBar method needsTileify.

/**
     * Returns {@code true} if the target drawable needs to be tileified.
     *
     * @param dr the drawable to check
     * @return {@code true} if the target drawable needs to be tileified,
     *         {@code false} otherwise
     */
private static boolean needsTileify(Drawable dr) {
    if (dr instanceof LayerDrawable) {
        final LayerDrawable orig = (LayerDrawable) dr;
        final int N = orig.getNumberOfLayers();
        for (int i = 0; i < N; i++) {
            if (needsTileify(orig.getDrawable(i))) {
                return true;
            }
        }
        return false;
    }
    if (dr instanceof StateListDrawable) {
        final StateListDrawable in = (StateListDrawable) dr;
        final int N = in.getStateCount();
        for (int i = 0; i < N; i++) {
            if (needsTileify(in.getStateDrawable(i))) {
                return true;
            }
        }
        return false;
    }
    // ScaleDrawable, we'll need to wrap it and apply tiling.
    if (dr instanceof BitmapDrawable) {
        return true;
    }
    return false;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 60 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project android_frameworks_base by DirtyUnicorns.

the class ProgressBar method tileify.

/**
     * Converts a drawable to a tiled version of itself. It will recursively
     * traverse layer and state list drawables.
     */
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof LayerDrawable) {
        final LayerDrawable orig = (LayerDrawable) drawable;
        final int N = orig.getNumberOfLayers();
        final Drawable[] outDrawables = new Drawable[N];
        for (int i = 0; i < N; i++) {
            final int id = orig.getId(i);
            outDrawables[i] = tileify(orig.getDrawable(i), (id == R.id.progress || id == R.id.secondaryProgress));
        }
        final LayerDrawable clone = new LayerDrawable(outDrawables);
        for (int i = 0; i < N; i++) {
            clone.setId(i, orig.getId(i));
            clone.setLayerGravity(i, orig.getLayerGravity(i));
            clone.setLayerWidth(i, orig.getLayerWidth(i));
            clone.setLayerHeight(i, orig.getLayerHeight(i));
            clone.setLayerInsetLeft(i, orig.getLayerInsetLeft(i));
            clone.setLayerInsetRight(i, orig.getLayerInsetRight(i));
            clone.setLayerInsetTop(i, orig.getLayerInsetTop(i));
            clone.setLayerInsetBottom(i, orig.getLayerInsetBottom(i));
            clone.setLayerInsetStart(i, orig.getLayerInsetStart(i));
            clone.setLayerInsetEnd(i, orig.getLayerInsetEnd(i));
        }
        return clone;
    }
    if (drawable instanceof StateListDrawable) {
        final StateListDrawable in = (StateListDrawable) drawable;
        final StateListDrawable out = new StateListDrawable();
        final int N = in.getStateCount();
        for (int i = 0; i < N; i++) {
            out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
        }
        return out;
    }
    if (drawable instanceof BitmapDrawable) {
        final Drawable.ConstantState cs = drawable.getConstantState();
        final BitmapDrawable clone = (BitmapDrawable) cs.newDrawable(getResources());
        clone.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        if (mSampleWidth <= 0) {
            mSampleWidth = clone.getIntrinsicWidth();
        }
        if (clip) {
            return new ClipDrawable(clone, Gravity.LEFT, ClipDrawable.HORIZONTAL);
        } else {
            return clone;
        }
    }
    return drawable;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable)

Aggregations

StateListDrawable (android.graphics.drawable.StateListDrawable)166 Drawable (android.graphics.drawable.Drawable)43 LayerDrawable (android.graphics.drawable.LayerDrawable)24 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 GradientDrawable (android.graphics.drawable.GradientDrawable)21 ColorDrawable (android.graphics.drawable.ColorDrawable)17 Bitmap (android.graphics.Bitmap)13 TextView (android.widget.TextView)12 ShapeDrawable (android.graphics.drawable.ShapeDrawable)11 View (android.view.View)11 AnimationDrawable (android.graphics.drawable.AnimationDrawable)9 ClipDrawable (android.graphics.drawable.ClipDrawable)9 SuppressLint (android.annotation.SuppressLint)8 ColorStateList (android.content.res.ColorStateList)8 Paint (android.graphics.Paint)8 RippleDrawable (android.graphics.drawable.RippleDrawable)7 TargetApi (android.annotation.TargetApi)6 TypedArray (android.content.res.TypedArray)6 TextPaint (android.text.TextPaint)5 Button (android.widget.Button)5