use of android.graphics.drawable.ClipDrawable in project Klyph by jonathangerbaud.
the class DefaultHeaderTransformer method applyProgressBarSettings.
private void applyProgressBarSettings() {
if (mHeaderProgressBar != null) {
final int strokeWidth = mHeaderProgressBar.getResources().getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width);
mHeaderProgressBar.setIndeterminateDrawable(new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext()).color(mProgressDrawableColor).width(strokeWidth).build());
ShapeDrawable shape = new ShapeDrawable();
shape.setShape(new RectShape());
shape.getPaint().setColor(mProgressDrawableColor);
ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);
mHeaderProgressBar.setProgressDrawable(clipDrawable);
}
}
use of android.graphics.drawable.ClipDrawable in project HoloEverywhere by Prototik.
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 == android.R.id.progress || id == android.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;
}
use of android.graphics.drawable.ClipDrawable in project Bitocle by mthli.
the class DefaultHeaderTransformer method applyProgressBarSettings.
private void applyProgressBarSettings() {
if (mHeaderProgressBar != null) {
ShapeDrawable shape = new ShapeDrawable();
shape.setShape(new RectShape());
shape.getPaint().setColor(mProgressDrawableColor);
ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);
mHeaderProgressBar.setProgressDrawable(clipDrawable);
}
}
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 ActionBarSherlock by JakeWharton.
the class IcsProgressBar 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) {
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 == android.R.id.progress || id == android.R.id.secondaryProgress));
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else /* else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = in.getStateCount();
for (int i = 0; i < numStates; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
}*/
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