use of android.graphics.drawable.LayerDrawable in project little-bear-dictionary by daimajia.
the class IcsProgressBar method doRefreshProgress.
private synchronized void doRefreshProgress(int id, int progress, boolean fromUser, boolean callBackToApp) {
float scale = mMax > 0 ? (float) progress / (float) mMax : 0;
final Drawable d = mCurrentDrawable;
if (d != null) {
Drawable progressDrawable = null;
if (d instanceof LayerDrawable) {
progressDrawable = ((LayerDrawable) d).findDrawableByLayerId(id);
}
final int level = (int) (scale * MAX_LEVEL);
(progressDrawable != null ? progressDrawable : d).setLevel(level);
} else {
invalidate();
}
if (callBackToApp && id == android.R.id.progress) {
onProgressRefresh(scale, fromUser);
}
}
use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by crdroidandroid.
the class BatteryMeterDrawable method checkBatteryMeterDrawableValid.
private void checkBatteryMeterDrawableValid(Resources res, int style) {
final int resId = getBatteryDrawableResourceForStyle(style);
final Drawable batteryDrawable;
try {
batteryDrawable = mContext.getDrawable(resId);
} catch (Resources.NotFoundException e) {
throw new BatteryMeterDrawableException(res.getResourceName(resId) + " is an " + "invalid drawable", e);
}
// Check that the drawable is a LayerDrawable
if (!(batteryDrawable instanceof LayerDrawable)) {
throw new BatteryMeterDrawableException("Expected a LayerDrawable but received a " + batteryDrawable.getClass().getSimpleName());
}
final LayerDrawable layerDrawable = (LayerDrawable) batteryDrawable;
final Drawable frame = layerDrawable.findDrawableByLayerId(R.id.battery_frame);
final Drawable level = layerDrawable.findDrawableByLayerId(R.id.battery_fill);
// Now, check that the required layers exist and are of the correct type
if (frame == null) {
throw new BatteryMeterDrawableException("Missing battery_frame drawble");
}
if (level != null) {
// Check that the level drawable is an AnimatedVectorDrawable
if (!(level instanceof AnimatedVectorDrawable)) {
throw new BatteryMeterDrawableException("Expected a AnimatedVectorDrawable " + "but received a " + level.getClass().getSimpleName());
}
// Make sure we can stop-motion animate the level drawable
try {
StopMotionVectorDrawable smvd = new StopMotionVectorDrawable(level);
smvd.setCurrentFraction(0.5f);
} catch (Exception e) {
throw new BatteryMeterDrawableException("Unable to perform stop motion on " + "battery_fill drawable", e);
}
} else {
throw new BatteryMeterDrawableException("Missing battery_fill drawable");
}
}
use of android.graphics.drawable.LayerDrawable in project little-bear-dictionary by daimajia.
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;
}
use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by AOSPA.
the class BatteryMeterDrawable method loadBatteryDrawables.
private void loadBatteryDrawables(Resources res, int style) {
try {
checkBatteryMeterDrawableValid(res, style);
} catch (BatteryMeterDrawableException e) {
Log.w(TAG, "Invalid themed battery meter drawable, falling back to system", e);
}
final int drawableResId = getBatteryDrawableResourceForStyle(style);
mBatteryDrawable = (LayerDrawable) mContext.getDrawable(drawableResId);
mFrameDrawable = mBatteryDrawable.findDrawableByLayerId(R.id.battery_frame);
mFrameDrawable.setTint(mCurrentBackgroundColor != 0 ? mCurrentBackgroundColor : res.getColor(R.color.batterymeter_frame_color));
// Set the animated vector drawable we will be stop-animating
final Drawable levelDrawable = mBatteryDrawable.findDrawableByLayerId(R.id.battery_fill);
mLevelDrawable = new StopMotionVectorDrawable(levelDrawable);
mBoltDrawable = mBatteryDrawable.findDrawableByLayerId(R.id.battery_charge_indicator);
}
use of android.graphics.drawable.LayerDrawable in project xabber-android by redsolution.
the class AvatarManager method getDefaultAccountAvatar.
@NonNull
public Drawable getDefaultAccountAvatar(AccountJid account) {
Drawable[] layers = new Drawable[2];
layers[0] = new ColorDrawable(ColorManager.getInstance().getAccountPainter().getAccountMainColor(account));
layers[1] = application.getResources().getDrawable(R.drawable.ic_avatar_1);
return new LayerDrawable(layers);
}
Aggregations