use of android.graphics.drawable.ClipDrawable in project AndroidTraining by mixi-inc.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Handler handler = new Handler();
final Timer timer = new Timer();
// 5秒ごとにレベルを変更するタスク
final Drawable levelListDrawable = findViewById(R.id.LevelListButton).getBackground();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
final int level = levelListDrawable.getLevel();
handler.post(new Runnable() {
@Override
public void run() {
if (level == 0) {
levelListDrawable.setLevel(1);
} else {
levelListDrawable.setLevel(0);
}
}
});
}
}, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
// クロスフェードを開始する
final TransitionDrawable transition = (TransitionDrawable) findViewById(R.id.TransitionView).getBackground();
transition.startTransition(TRANSITION_DURATION);
// 5秒ごとにレベルを変更し、クリップの範囲を変化させるタスク
final ClipDrawable clipDrawable = (ClipDrawable) findViewById(R.id.ClipView).getBackground();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
clipDrawable.setLevel(clipDrawable.getLevel() + 1000);
}
});
}
}, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
// スケールのレベルを変更する
ScaleDrawable scale = (ScaleDrawable) findViewById(R.id.ScaleView).getBackground();
scale.setLevel(1);
}
use of android.graphics.drawable.ClipDrawable in project PaletteImageView by DingMouRen.
the class PaletteImageView method dispatchDraw.
@Override
protected void dispatchDraw(Canvas canvas) {
View view = getChildAt(0);
if (null == view) {
return;
}
canvas.save();
mShadowRadiusSize = view.getHeight() / 12 > MAX_SHADOW_RADIUS_SIZE ? MAX_SHADOW_RADIUS_SIZE : view.getHeight() / 12;
mShadowDepth = view.getHeight() / 16 > MAX_SHADOW_DEPTH ? MAX_SHADOW_DEPTH : view.getHeight() / 16;
if (((ImageView) view).getDrawable() instanceof ClipDrawable) {
mShadowRGB = Color.parseColor(DEFAULT_SHADOW_COLOR);
mPaintShadow.setShadowLayer(mShadowRadiusSize, 0, mShadowDepth, getDarkerColor(mShadowRGB));
} else if (((ImageView) view).getDrawable() instanceof ColorDrawable) {
mShadowRGB = ((ColorDrawable) ((ImageView) view).getDrawable()).getColor();
mPaintShadow.setShadowLayer(MAX_SHADOW_RADIUS_SIZE, 0, MAX_SHADOW_DEPTH, getDarkerColor(mShadowRGB));
} else {
mBitmap = ((BitmapDrawable) ((ImageView) view).getDrawable()).getBitmap();
mSwatch = Palette.from(mBitmap).generate().getDominantSwatch();
if (null != mSwatch) {
mShadowRGB = mSwatch.getRgb();
} else {
mShadowRGB = Color.parseColor(DEFAULT_SHADOW_COLOR);
}
mPaintShadow.setShadowLayer(mShadowRadiusSize, 0, mShadowDepth, getDarkerColor(mShadowRGB));
mBitmapTemp = Bitmap.createBitmap(mBitmap, 0, mBitmap.getHeight() / 4 * 3, mBitmap.getWidth(), mBitmap.getHeight() / 4);
if (null != Palette.from(mBitmapTemp).generate().getDominantSwatch()) {
mShadowRGB = Palette.from(mBitmapTemp).generate().getDominantSwatch().getRgb();
mPaintShadow.setShadowLayer(mShadowRadiusSize, 0, mShadowDepth, mShadowRGB);
}
}
mRectF = new RectF(view.getX() + (view.getWidth() / 20), view.getY(), view.getX() + view.getWidth() - (view.getWidth() / 20), view.getY() + view.getHeight());
canvas.drawRoundRect(mRectF, mCornerRadius, mCornerRadius, mPaintShadow);
canvas.restore();
((CustomImageView) view).setCornerRadius(mCornerRadius);
super.dispatchDraw(canvas);
}
use of android.graphics.drawable.ClipDrawable in project android_frameworks_base by crdroidandroid.
the class ProgressBar method tileifyIndeterminate.
/**
* Convert a AnimationDrawable for use as a barberpole animation.
* Each frame of the animation is wrapped in a ClipDrawable and
* given a tiling BitmapShader.
*/
private Drawable tileifyIndeterminate(Drawable drawable) {
if (drawable instanceof AnimationDrawable) {
AnimationDrawable background = (AnimationDrawable) drawable;
final int N = background.getNumberOfFrames();
AnimationDrawable newBg = new AnimationDrawable();
newBg.setOneShot(background.isOneShot());
for (int i = 0; i < N; i++) {
Drawable frame = tileify(background.getFrame(i), true);
frame.setLevel(10000);
newBg.addFrame(frame, background.getDuration(i));
}
newBg.setLevel(10000);
drawable = newBg;
}
return drawable;
}
use of android.graphics.drawable.ClipDrawable in project android_frameworks_base by crdroidandroid.
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;
}
use of android.graphics.drawable.ClipDrawable in project little-bear-dictionary by daimajia.
the class ProgressBar method tileify.
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i), id == R.id.progress || id == R.id.secondaryProgress);
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = ReflectHelper.invoke(in, "getStateCount", int.class);
for (int i = 0; i < numStates; i++) {
out.addState(ReflectHelper.invoke(in, "getStateSet", int[].class, i), tileify(ReflectHelper.invoke(in, "getStateDrawable", Drawable.class, i), clip));
}
return out;
} else if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return clip ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
}
Aggregations