use of android.graphics.drawable.StopMotionVectorDrawable in project android_frameworks_base by DirtyUnicorns.
the class BatteryMeterDrawable method checkBatteryMeterDrawableValid.
private void checkBatteryMeterDrawableValid(Resources res, int style) {
final int resId = getBatteryDrawableResourceForStyle(style);
final Drawable batteryDrawable;
try {
batteryDrawable = res.getDrawable(resId, null);
} 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);
final Drawable bolt = layerDrawable.findDrawableByLayerId(R.id.battery_charge_indicator);
final Drawable plus = layerDrawable.findDrawableByLayerId(R.id.battery_powersave_indicator);
// Now, check that the required layers exist and are of the correct type
if (frame == null) {
throw new BatteryMeterDrawableException("Missing battery_frame drawble");
}
if (bolt == null) {
throw new BatteryMeterDrawableException("Missing battery_charge_indicator drawable");
}
if (plus == null) {
throw new BatteryMeterDrawableException("Missing battery_powersave_indicator drawable");
}
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.StopMotionVectorDrawable in project android_frameworks_base by DirtyUnicorns.
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) res.getDrawable(drawableResId, null);
mFrameDrawable = mBatteryDrawable.findDrawableByLayerId(R.id.battery_frame);
mFrameDrawable.setTint((mCurrentBackgroundColor != 0 && !mIsBatteryTile) ? mCurrentBackgroundColor : (!mIsBatteryTile ? res.getColor(R.color.batterymeter_frame_color) : res.getColor(R.color.batterymeter_frame_color_tile)));
// 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);
mBoltDrawable.setTint(getBoltColor());
mPlusDrawable = mBatteryDrawable.findDrawableByLayerId(R.id.battery_powersave_indicator);
mPlusDrawable.setTint(getPlusColor());
}
Aggregations