Search in sources :

Example 61 with LayerDrawable

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);
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 62 with LayerDrawable

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");
    }
}
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 63 with LayerDrawable

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;
}
Also used : Bitmap(android.graphics.Bitmap) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapShader(android.graphics.BitmapShader) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 64 with LayerDrawable

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

Example 65 with LayerDrawable

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);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) NonNull(android.support.annotation.NonNull)

Aggregations

LayerDrawable (android.graphics.drawable.LayerDrawable)133 Drawable (android.graphics.drawable.Drawable)91 BitmapDrawable (android.graphics.drawable.BitmapDrawable)61 StateListDrawable (android.graphics.drawable.StateListDrawable)45 AnimationDrawable (android.graphics.drawable.AnimationDrawable)42 ClipDrawable (android.graphics.drawable.ClipDrawable)42 ShapeDrawable (android.graphics.drawable.ShapeDrawable)39 Paint (android.graphics.Paint)25 SuppressLint (android.annotation.SuppressLint)21 GradientDrawable (android.graphics.drawable.GradientDrawable)19 Bitmap (android.graphics.Bitmap)14 ColorDrawable (android.graphics.drawable.ColorDrawable)14 BitmapShader (android.graphics.BitmapShader)13 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)8 OvalShape (android.graphics.drawable.shapes.OvalShape)8 TypedArray (android.content.res.TypedArray)7 Nullable (android.annotation.Nullable)5 Resources (android.content.res.Resources)5 InsetDrawable (android.graphics.drawable.InsetDrawable)5 TransitionDrawable (android.graphics.drawable.TransitionDrawable)5