Search in sources :

Example 6 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project Libraries-for-Android-Developers by eoecn.

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 7 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by ParanoidAndroid.

the class ProgressBar 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);
            if (progressDrawable != null && canResolveLayoutDirection()) {
                progressDrawable.setLayoutDirection(getLayoutDirection());
            }
        }
        final int level = (int) (scale * MAX_LEVEL);
        (progressDrawable != null ? progressDrawable : d).setLevel(level);
    } else {
        invalidate();
    }
    if (callBackToApp && id == 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) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 8 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by ParanoidAndroid.

the class ToggleButton method updateReferenceToIndicatorDrawable.

private void updateReferenceToIndicatorDrawable(Drawable backgroundDrawable) {
    if (backgroundDrawable instanceof LayerDrawable) {
        LayerDrawable layerDrawable = (LayerDrawable) backgroundDrawable;
        mIndicatorDrawable = layerDrawable.findDrawableByLayerId(com.android.internal.R.id.toggle);
    } else {
        mIndicatorDrawable = null;
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable)

Example 9 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by ParanoidAndroid.

the class TabletStatusBar method workAroundBadLayerDrawableOpacity.

@Override
protected void workAroundBadLayerDrawableOpacity(View v) {
    Drawable bgd = v.getBackground();
    if (!(bgd instanceof LayerDrawable))
        return;
    LayerDrawable d = (LayerDrawable) bgd;
    v.setBackground(null);
    d.setOpacity(PixelFormat.TRANSLUCENT);
    v.setBackground(d);
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) LayerDrawable(android.graphics.drawable.LayerDrawable)

Example 10 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project HoloEverywhere by Prototik.

the class ProgressBar method tileify.

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 if (drawable instanceof StateListDrawable) {
        StateListDrawable in = (StateListDrawable) drawable;
        StateListDrawable out = new StateListDrawable();
        int numStates = ReflectHelper.invoke(in, "getStateCount", int.class);
        for (int i = 0; i < numStates; i++) {
            out.addState(ReflectHelper.invoke(in, "getStateSet", int[].class, i), tileify(ReflectHelper.invoke(in, "getStateDrawable", Drawable.class, i), clip));
        }
        return out;
    } else 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) StateListDrawable(android.graphics.drawable.StateListDrawable) 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) StateListDrawable(android.graphics.drawable.StateListDrawable) BitmapShader(android.graphics.BitmapShader) SuppressLint(android.annotation.SuppressLint) ClipDrawable(android.graphics.drawable.ClipDrawable)

Aggregations

LayerDrawable (android.graphics.drawable.LayerDrawable)127 Drawable (android.graphics.drawable.Drawable)87 BitmapDrawable (android.graphics.drawable.BitmapDrawable)60 StateListDrawable (android.graphics.drawable.StateListDrawable)44 AnimationDrawable (android.graphics.drawable.AnimationDrawable)42 ClipDrawable (android.graphics.drawable.ClipDrawable)42 ShapeDrawable (android.graphics.drawable.ShapeDrawable)38 Paint (android.graphics.Paint)23 SuppressLint (android.annotation.SuppressLint)19 GradientDrawable (android.graphics.drawable.GradientDrawable)16 Bitmap (android.graphics.Bitmap)14 BitmapShader (android.graphics.BitmapShader)13 ColorDrawable (android.graphics.drawable.ColorDrawable)12 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)8 OvalShape (android.graphics.drawable.shapes.OvalShape)7 Nullable (android.annotation.Nullable)5 Resources (android.content.res.Resources)5 TypedArray (android.content.res.TypedArray)5 InsetDrawable (android.graphics.drawable.InsetDrawable)5 TransitionDrawable (android.graphics.drawable.TransitionDrawable)5