use of org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable in project android_frameworks_base by ResurrectionRemix.
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);
// 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 org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable 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 org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable in project android_frameworks_base by ResurrectionRemix.
the class BatteryMeterDrawable method loadBatteryDrawables.
private void loadBatteryDrawables(Resources res, int style) {
if (isThemeApplied()) {
try {
checkBatteryMeterDrawableValid(res, style);
} catch (BatteryMeterDrawableException e) {
Log.w(TAG, "Invalid themed battery meter drawable, falling back to system", e);
/* Disable until the theme engine is brought up
PackageManager pm = mContext.getPackageManager();
try {
res = pm.getThemedResourcesForApplication(mContext.getPackageName(),
ThemeConfig.SYSTEM_DEFAULT);
} catch (PackageManager.NameNotFoundException nnfe) {
// Ignore; this should not happen
}
*/
}
}
final int drawableResId = getBatteryDrawableResourceForStyle(style);
mBatteryDrawable = (LayerDrawable) res.getDrawable(drawableResId, null);
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 org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable in project android_frameworks_base by crdroidandroid.
the class BatteryMeterDrawable method loadBatteryDrawables.
private void loadBatteryDrawables(Resources res, int style) {
if (isThemeApplied()) {
try {
checkBatteryMeterDrawableValid(res, style);
} catch (BatteryMeterDrawableException e) {
Log.w(TAG, "Invalid themed battery meter drawable, falling back to system", e);
/* Disable until the theme engine is brought up
PackageManager pm = mContext.getPackageManager();
try {
res = pm.getThemedResourcesForApplication(mContext.getPackageName(),
ThemeConfig.SYSTEM_DEFAULT);
} catch (PackageManager.NameNotFoundException nnfe) {
// Ignore; this should not happen
}
*/
}
}
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);
if (mBoltDrawable != null) {
mBoltDrawable.setTint(getBoltColor());
}
}
Aggregations