Search in sources :

Example 61 with StateListDrawable

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

the class IconUtilities method createIconDrawable.

public Drawable createIconDrawable(Drawable src) {
    Bitmap scaled = createIconBitmap(src);
    StateListDrawable result = new StateListDrawable();
    result.addState(new int[] { android.R.attr.state_focused }, new BitmapDrawable(createSelectedBitmap(scaled, false)));
    result.addState(new int[] { android.R.attr.state_pressed }, new BitmapDrawable(createSelectedBitmap(scaled, true)));
    result.addState(new int[0], new BitmapDrawable(scaled));
    result.setBounds(0, 0, mIconTextureWidth, mIconTextureHeight);
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 62 with StateListDrawable

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

the class RenderDrawable method render.

public Result render() {
    checkLock();
    // get the drawable resource value
    DrawableParams params = getParams();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ResourceValue drawableResource = params.getDrawable();
    // resolve it
    BridgeContext context = getContext();
    drawableResource = context.getRenderResources().resolveResValue(drawableResource);
    if (drawableResource == null) {
        return Status.ERROR_NOT_A_DRAWABLE.createResult();
    }
    ResourceType resourceType = drawableResource.getResourceType();
    if (resourceType != ResourceType.DRAWABLE && resourceType != ResourceType.MIPMAP) {
        return Status.ERROR_NOT_A_DRAWABLE.createResult();
    }
    Drawable d = ResourceHelper.getDrawable(drawableResource, context);
    final Boolean allStates = params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
    if (allStates == Boolean.TRUE) {
        final List<BufferedImage> result;
        if (d instanceof StateListDrawable) {
            result = new ArrayList<BufferedImage>();
            final StateListDrawable stateList = (StateListDrawable) d;
            for (int i = 0; i < stateList.getStateCount(); i++) {
                final Drawable stateDrawable = stateList.getStateDrawable(i);
                result.add(renderImage(hardwareConfig, stateDrawable, context));
            }
        } else {
            result = Collections.singletonList(renderImage(hardwareConfig, d, context));
        }
        return Status.SUCCESS.createResult(result);
    } else {
        BufferedImage image = renderImage(hardwareConfig, d, context);
        return Status.SUCCESS.createResult(image);
    }
}
Also used : HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceType(com.android.resources.ResourceType) StateListDrawable(android.graphics.drawable.StateListDrawable) BufferedImage(java.awt.image.BufferedImage) DrawableParams(com.android.ide.common.rendering.api.DrawableParams)

Example 63 with StateListDrawable

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

the class SizeAdaptiveLayout method initialize.

private void initialize() {
    mModestyPanel = new View(getContext());
    // If the SizeAdaptiveLayout has a solid background, use it as a transition hint.
    Drawable background = getBackground();
    if (background instanceof StateListDrawable) {
        StateListDrawable sld = (StateListDrawable) background;
        sld.setState(StateSet.WILD_CARD);
        background = sld.getCurrent();
    }
    if (background instanceof ColorDrawable) {
        mModestyPanel.setBackgroundDrawable(background);
    } else {
        mModestyPanel.setBackgroundColor(Color.BLACK);
    }
    SizeAdaptiveLayout.LayoutParams layout = new SizeAdaptiveLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mModestyPanel.setLayoutParams(layout);
    addView(mModestyPanel);
    mFadePanel = ObjectAnimator.ofFloat(mModestyPanel, "alpha", 0f);
    mFadeView = ObjectAnimator.ofFloat(null, "alpha", 0f);
    mAnimatorListener = new BringToFrontOnEnd();
    mTransitionAnimation = new AnimatorSet();
    mTransitionAnimation.play(mFadeView).with(mFadePanel);
    mTransitionAnimation.setDuration(CROSSFADE_TIME);
    mTransitionAnimation.addListener(mAnimatorListener);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) AnimatorSet(android.animation.AnimatorSet) StateListDrawable(android.graphics.drawable.StateListDrawable) RemoteView(android.widget.RemoteViews.RemoteView) View(android.view.View)

Example 64 with StateListDrawable

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

the class TargetDrawable method isActive.

/**
     * Returns true if the drawable is a StateListDrawable and is in the focused state.
     *
     * @return
     */
public boolean isActive() {
    if (mDrawable instanceof StateListDrawable) {
        StateListDrawable d = (StateListDrawable) mDrawable;
        int[] states = d.getState();
        for (int i = 0; i < states.length; i++) {
            if (states[i] == android.R.attr.state_focused) {
                return true;
            }
        }
    }
    return false;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 65 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project android_frameworks_base by AOSPA.

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)

Aggregations

StateListDrawable (android.graphics.drawable.StateListDrawable)166 Drawable (android.graphics.drawable.Drawable)43 LayerDrawable (android.graphics.drawable.LayerDrawable)24 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 GradientDrawable (android.graphics.drawable.GradientDrawable)21 ColorDrawable (android.graphics.drawable.ColorDrawable)17 Bitmap (android.graphics.Bitmap)13 TextView (android.widget.TextView)12 ShapeDrawable (android.graphics.drawable.ShapeDrawable)11 View (android.view.View)11 AnimationDrawable (android.graphics.drawable.AnimationDrawable)9 ClipDrawable (android.graphics.drawable.ClipDrawable)9 SuppressLint (android.annotation.SuppressLint)8 ColorStateList (android.content.res.ColorStateList)8 Paint (android.graphics.Paint)8 RippleDrawable (android.graphics.drawable.RippleDrawable)7 TargetApi (android.annotation.TargetApi)6 TypedArray (android.content.res.TypedArray)6 TextPaint (android.text.TextPaint)5 Button (android.widget.Button)5