Example usage for android.graphics.drawable LayerDrawable LayerDrawable

List of usage examples for android.graphics.drawable LayerDrawable LayerDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable LayerDrawable LayerDrawable.

Prototype

public LayerDrawable(@NonNull Drawable[] layers) 

Source Link

Document

Creates a new layer drawable with the list of specified layers.

Usage

From source file:com.lx.minimusic.MainActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//  w  w w .j ava2 s.c  o  m

    // 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 });

            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;

}

From source file:com.desmond.ripple.view.RippleCompat.java

private static void adaptBackground(RippleCompatDrawable rippleDrawable, View v, RippleConfig config) {
    Drawable background;/*  www .ja va 2 s  .c o m*/

    if (v instanceof ImageView) {
        ImageView.ScaleType scaleType = ((ImageView) v).getScaleType();
        background = ((ImageView) v).getDrawable();
        rippleDrawable.setBackgroundDrawable(background).setScaleType(scaleType).setPadding(v.getPaddingLeft(),
                v.getPaddingTop(), v.getPaddingRight(), v.getPaddingBottom());
        ((ImageView) v).setImageDrawable(null);
        setBackground(v, rippleDrawable);
    } else {
        if (config.getBackgroundDrawable() != null) {
            rippleDrawable.setBackgroundDrawable(config.getBackgroundDrawable());
            rippleDrawable.setScaleType(config.getScaleType());
        }

        background = v.getBackground();

        if (background != null) {
            setBackground(v, new LayerDrawable(new Drawable[] { background, rippleDrawable }));
        } else {
            setBackground(v, rippleDrawable);
        }
    }
}

From source file:io.romain.passport.utils.glide.CityItemTarget.java

@SuppressWarnings("RedundantCast")
@Override//from w w  w  .  jav  a2 s  . co m
@TargetApi(21)
public void onGenerated(Palette palette) {
    sUrlPaletteCache.put(mCity.picture(), palette);
    Context context = getView().getContext();
    ((FourThreeImageView) getView()).setForeground(new LayerDrawable(new Drawable[] {
            ViewUtils.createRipple(palette, 0.25f, 0.5f, ContextCompat.getColor(context, R.color.mid_grey),
                    true),
            ScrimUtil.makeCubicGradientScrimDrawable(ContextCompat.getColor(context, R.color.scrim), 5,
                    Gravity.BOTTOM) }));

    int color;
    switch (ColorUtils.isDark(palette)) {
    default:
    case ColorUtils.LIGHTNESS_UNKNOWN:
    case ColorUtils.IS_DARK:
        color = getColor(context, android.R.color.white);
        mViewHolder.name.setTextColor(getColor(context, R.color.text_primary_light));
        break;
    case ColorUtils.IS_LIGHT:
        color = getColor(context, android.R.color.black);
        mViewHolder.name.setTextColor(getColor(context, R.color.text_primary_dark));
        break;
    }

    mViewHolder.favorite.setImageTintList(ColorStateList.valueOf(color));
    mViewHolder.remove.setImageTintList(ColorStateList.valueOf(color));
}

From source file:com.ibuildapp.ZopimChatPlugin.ZopimChat.java

public void setNavbarBackgroundColor(final int color, View view) {
    float density = getResources().getDisplayMetrics().density;

    Drawable background = new LayerDrawable(new Drawable[] { new ColorDrawable(color), new ColorDrawable(
            color == Color.WHITE ? Color.parseColor("#33000000") : Color.parseColor("#66FFFFFF")) });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        view.setBackground(background);/*from w  ww. jav a 2 s . c o m*/
    else
        view.setBackgroundDrawable(background);

    view.setPadding((int) (density * 10), (int) (density * 10), (int) (density * 10), (int) (density * 10));
}

From source file:br.ufrgs.ufrgsmapas.views.BuildingClusterRenderer.java

private LayerDrawable makeClusterBackground() {
    this.mColoredCircleBackground = new ShapeDrawable(new OvalShape());
    ShapeDrawable outline = new ShapeDrawable(new OvalShape());
    outline.getPaint().setColor(-2130706433);
    LayerDrawable background = new LayerDrawable(new Drawable[] { outline, this.mColoredCircleBackground });
    int strokeWidth = (int) (this.mDensity * 3.0F);
    background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
    return background;
}

From source file:cn.finalteam.galleryfinal.widget.FloatingActionButton.java

void updateBackground() {
    float circleLeft = mShadowRadius;
    float circleTop = mShadowRadius - mShadowOffset;

    final RectF circleRect = new RectF(circleLeft, circleTop, circleLeft + mCircleSize,
            circleTop + mCircleSize);/*from  www .  j  av  a  2  s. co m*/

    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { new BitmapDrawable(getResources()),
            createFillDrawable(circleRect), new BitmapDrawable(getResources()), getIconDrawable() });

    float iconOffset = (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2f;

    int iconInsetHorizontal = (int) (mShadowRadius + iconOffset);
    int iconInsetTop = (int) (circleTop + iconOffset);
    int iconInsetBottom = (int) (mShadowRadius + mShadowOffset + iconOffset);

    layerDrawable.setLayerInset(3, iconInsetHorizontal, iconInsetTop, iconInsetHorizontal, iconInsetBottom);

    setBackgroundCompat(layerDrawable);
}

From source file:com.ksharkapps.musicnow.ui.activities.HomeActivity.java

public void changeActionBarColor(int newColor) {

    int color = newColor != 0 ? newColor : SettingsActivity.getActionBarColor(this);
    Drawable colorDrawable = new ColorDrawable(color);
    Drawable bottomDrawable = getResources().getDrawable(R.drawable.transparent_overlay);
    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 {//from w  w  w. j av a  2 s  .  c  o m
            actBar.setBackgroundDrawable(colorDrawable);
        }

    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        // workaround for broken ActionBarContainer drawable handling on
        // pre-API 17 builds
        // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            td.setCallback(drawableCallback);
        } else {
            actBar.setBackgroundDrawable(td);
        }
        td.startTransition(200);
    }

    oldBackground = ld;

    ScrollableTabView mScrollingTabs = (ScrollableTabView) findViewById(R.id.fragment_home_phone_pager_titles);
    mScrollingTabs.setBackgroundColor(color);

    // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
    actBar.setDisplayShowTitleEnabled(false);
    actBar.setDisplayShowTitleEnabled(true);

    if (Utils.hasKitKat()) {
        if (SettingsActivity.getTranslucentMode(this)) {
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintColor(color);

        }

    }

}

From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButtonImpl.java

void setBackgroundDrawable(ColorStateList backgroundTint, PorterDuff.Mode backgroundTintMode, int rippleColor,
        int borderWidth) {
    // Now we need to tint the original background with the tint, using
    // an InsetDrawable if we have a border width
    mShapeDrawable = DrawableCompat.wrap(createShapeDrawable());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }//  w w w .  ja  v  a 2  s . c o m

    // Now we created a mask Drawable which will be used for touch feedback.
    GradientDrawable touchFeedbackShape = createShapeDrawable();

    // We'll now wrap that touch feedback mask drawable with a ColorStateList. We do not need
    // to inset for any border here as LayerDrawable will nest the padding for us
    mRippleDrawable = DrawableCompat.wrap(touchFeedbackShape);
    DrawableCompat.setTintList(mRippleDrawable, createColorStateList(rippleColor));

    final Drawable[] layers;
    if (borderWidth > 0) {
        mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
        layers = new Drawable[] { mBorderDrawable, mShapeDrawable, mRippleDrawable };
    } else {
        mBorderDrawable = null;
        layers = new Drawable[] { mShapeDrawable, mRippleDrawable };
    }

    mContentBackground = new LayerDrawable(layers);

    mShadowDrawable = new ShadowDrawableWrapper(mView.getContext(), mContentBackground,
            mShadowViewDelegate.getRadius(), mElevation, mElevation + mPressedTranslationZ);
    mShadowDrawable.setAddPaddingForCorners(false);
    mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable);
}

From source file:com.lulu.admin.kuyimusic.MainActivity.java

public void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);/*from  w  ww  .j a  v a  2s  .  c om*/

    // 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 });

            // workaround for broken ActionBarContainer drawable handling on
            // pre-API 17 builds
            // 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;

}

From source file:org.opensilk.common.ui.widget.FloatingActionButton.java

/**
 * <= api 19// w  w  w .  j ava2s  . c  o m
 */
protected Drawable createSelectableDrawable() {

    ShapeDrawable drawableNormal = new ShapeDrawable(new OvalShape());
    drawableNormal.getPaint().setColor(mColorNormal);

    StateListDrawable stateDrawable = new StateListDrawable();

    ShapeDrawable drawableHighlight = new ShapeDrawable(new OvalShape());
    drawableHighlight.getPaint().setColor(mColorPressed);

    stateDrawable.addState(new int[] { android.R.attr.state_pressed }, drawableHighlight);
    stateDrawable.addState(new int[0], null);

    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { drawableNormal, stateDrawable });

    return layerDrawable;
}