Search in sources :

Example 26 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project platform_frameworks_base by android.

the class ProgressBar method setVisualProgress.

/**
     * Sets the visual state of a progress indicator.
     *
     * @param id the identifier of the progress indicator
     * @param progress the visual progress in the range [0...1]
     */
private void setVisualProgress(int id, float progress) {
    mVisualProgress = progress;
    Drawable d = mCurrentDrawable;
    if (d instanceof LayerDrawable) {
        d = ((LayerDrawable) d).findDrawableByLayerId(id);
        if (d == null) {
            // If we can't find the requested layer, fall back to setting
            // the level of the entire drawable. This will break if
            // progress is set on multiple elements, but the theme-default
            // drawable will always have all layer IDs present.
            d = mCurrentDrawable;
        }
    }
    if (d != null) {
        final int level = (int) (progress * MAX_LEVEL);
        d.setLevel(level);
    } else {
        invalidate();
    }
    onVisualProgressChanged(id, progress);
}
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)

Example 27 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project platform_frameworks_base by android.

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

use of android.graphics.drawable.LayerDrawable in project Shuttle by timusus.

the class ThemeUtils method themeContextualActionBar.

public static void themeContextualActionBar(Activity activity) {
    if (activity != null) {
        View v = activity.findViewById(R.id.action_mode_bar);
        if (v != null) {
            Drawable bottom = CompatUtils.getDrawableCompat(activity, R.drawable.abc_cab_background_top_mtrl_alpha);
            if (bottom != null) {
                bottom.setColorFilter(ColorUtils.getAccentColor(), PorterDuff.Mode.SRC_ATOP);
            }
            Drawable background = new ColorDrawable(ColorUtils.getPrimaryColorDark(activity));
            LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, bottom });
            v.setBackgroundDrawable(layerDrawable);
        }
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) HmsView(com.doomonafireball.betterpickers.hmspicker.HmsView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView)

Example 29 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project Shuttle by timusus.

the class ThemeUtils method themeSeekBar.

public static void themeSeekBar(Context context, SizableSeekBar seekBar, boolean noBackground) {
    int accentColor = ColorUtils.getAccentColor();
    if (noBackground) {
        if (accentColor == ColorUtils.getPrimaryColor()) {
            accentColor = android.graphics.Color.WHITE;
        }
    }
    seekBar.setThumb(DrawableUtils.getColoredDrawable(seekBar.getThumb(), accentColor));
    LayerDrawable progressDrawable = (LayerDrawable) seekBar.getProgressDrawable();
    progressDrawable.setDrawableByLayerId(android.R.id.progress, DrawableUtils.getColoredDrawable(progressDrawable.findDrawableByLayerId(android.R.id.progress), accentColor));
    if (!noBackground) {
        int color;
        int themeType = getThemeType(context);
        if (themeType == ThemeType.TYPE_DARK || themeType == ThemeType.TYPE_SOLID_DARK || themeType == ThemeType.TYPE_BLACK || themeType == ThemeType.TYPE_SOLID_BLACK) {
            color = android.graphics.Color.parseColor("#5a5a5a");
        } else {
            color = android.graphics.Color.parseColor("#bfbfbf");
        }
        progressDrawable.setDrawableByLayerId(android.R.id.background, DrawableUtils.getColoredDrawable(progressDrawable.findDrawableByLayerId(android.R.id.background), color));
    } else {
        progressDrawable.setDrawableByLayerId(android.R.id.background, new ColorDrawable(context.getResources().getColor(android.R.color.transparent)));
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) SuppressLint(android.annotation.SuppressLint)

Example 30 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project PagerSlidingTabStrip by astuetz.

the class MainActivity method changeColor.

private void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);
    // change ActionBar color just if an ActionBar is available
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Drawable colorDrawable = new ColorDrawable(newColor);
        Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
        LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });
        if (oldBackground == null) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                ld.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(ld);
            }
        } else {
            TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
            // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                td.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(td);
            }
            td.startTransition(200);
        }
        oldBackground = ld;
        // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);
    }
    currentColor = newColor;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) 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) TransitionDrawable(android.graphics.drawable.TransitionDrawable)

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