Search in sources :

Example 1 with StopMotionVectorDrawable

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");
    }
}
Also used : StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) Resources(android.content.res.Resources) Paint(android.graphics.Paint) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 2 with StopMotionVectorDrawable

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");
    }
}
Also used : StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) Resources(android.content.res.Resources) Paint(android.graphics.Paint) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 3 with StopMotionVectorDrawable

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);
}
Also used : StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) Paint(android.graphics.Paint)

Example 4 with StopMotionVectorDrawable

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());
    }
}
Also used : StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)4 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 Drawable (android.graphics.drawable.Drawable)4 LayerDrawable (android.graphics.drawable.LayerDrawable)4 StopMotionVectorDrawable (org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable)4 Resources (android.content.res.Resources)2