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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations