Search in sources :

Example 46 with LayerDrawable

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

the class ProgressBar method needsTileify.

/**
     * Returns {@code true} if the target drawable needs to be tileified.
     *
     * @param dr the drawable to check
     * @return {@code true} if the target drawable needs to be tileified,
     *         {@code false} otherwise
     */
private static boolean needsTileify(Drawable dr) {
    if (dr instanceof LayerDrawable) {
        final LayerDrawable orig = (LayerDrawable) dr;
        final int N = orig.getNumberOfLayers();
        for (int i = 0; i < N; i++) {
            if (needsTileify(orig.getDrawable(i))) {
                return true;
            }
        }
        return false;
    }
    if (dr instanceof StateListDrawable) {
        final StateListDrawable in = (StateListDrawable) dr;
        final int N = in.getStateCount();
        for (int i = 0; i < N; i++) {
            if (needsTileify(in.getStateDrawable(i))) {
                return true;
            }
        }
        return false;
    }
    // ScaleDrawable, we'll need to wrap it and apply tiling.
    if (dr instanceof BitmapDrawable) {
        return true;
    }
    return false;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 47 with LayerDrawable

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

the class ProgressBar 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) {
        final LayerDrawable orig = (LayerDrawable) drawable;
        final int N = orig.getNumberOfLayers();
        final Drawable[] outDrawables = new Drawable[N];
        for (int i = 0; i < N; i++) {
            final int id = orig.getId(i);
            outDrawables[i] = tileify(orig.getDrawable(i), (id == R.id.progress || id == R.id.secondaryProgress));
        }
        final LayerDrawable clone = new LayerDrawable(outDrawables);
        for (int i = 0; i < N; i++) {
            clone.setId(i, orig.getId(i));
            clone.setLayerGravity(i, orig.getLayerGravity(i));
            clone.setLayerWidth(i, orig.getLayerWidth(i));
            clone.setLayerHeight(i, orig.getLayerHeight(i));
            clone.setLayerInsetLeft(i, orig.getLayerInsetLeft(i));
            clone.setLayerInsetRight(i, orig.getLayerInsetRight(i));
            clone.setLayerInsetTop(i, orig.getLayerInsetTop(i));
            clone.setLayerInsetBottom(i, orig.getLayerInsetBottom(i));
            clone.setLayerInsetStart(i, orig.getLayerInsetStart(i));
            clone.setLayerInsetEnd(i, orig.getLayerInsetEnd(i));
        }
        return clone;
    }
    if (drawable instanceof StateListDrawable) {
        final StateListDrawable in = (StateListDrawable) drawable;
        final StateListDrawable out = new StateListDrawable();
        final int N = in.getStateCount();
        for (int i = 0; i < N; i++) {
            out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
        }
        return out;
    }
    if (drawable instanceof BitmapDrawable) {
        final Drawable.ConstantState cs = drawable.getConstantState();
        final BitmapDrawable clone = (BitmapDrawable) cs.newDrawable(getResources());
        clone.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        if (mSampleWidth <= 0) {
            mSampleWidth = clone.getIntrinsicWidth();
        }
        if (clip) {
            return new ClipDrawable(clone, Gravity.LEFT, ClipDrawable.HORIZONTAL);
        } else {
            return clone;
        }
    }
    return drawable;
}
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) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 48 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project weex-example by KalicyZhou.

the class WXComponent method getOrCreateBorder.

protected BorderDrawable getOrCreateBorder() {
    if (mBackgroundDrawable == null) {
        Drawable backgroundDrawable = mHost.getBackground();
        WXViewUtils.setBackGround(mHost, null);
        mBackgroundDrawable = new BorderDrawable();
        if (backgroundDrawable == null) {
            WXViewUtils.setBackGround(mHost, mBackgroundDrawable);
        } else {
            //TODO Not strictly clip according to background-clip:border-box
            WXViewUtils.setBackGround(mHost, new LayerDrawable(new Drawable[] { mBackgroundDrawable, backgroundDrawable }));
        }
    }
    return mBackgroundDrawable;
}
Also used : BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable)

Example 49 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 50 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)

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