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:Main.java

public static LayerDrawable getBorderLayerDrawable(int color, int backgroundColor, int padding, int radius) {
    Drawable[] layers = new Drawable[2];
    layers[0] = getShapeDrawable(color, radius);
    layers[0].setState(new int[] { android.R.attr.state_enabled });
    layers[1] = getShapeDrawable(backgroundColor, radius);
    layers[1].setState(new int[] { android.R.attr.state_enabled });
    LayerDrawable layerDrawable = new LayerDrawable(layers);
    layerDrawable.setLayerInset(1, padding, padding, padding, padding);
    return layerDrawable;
}

From source file:net.xpece.android.colorpicker.ColorStateDrawable.java

public static Drawable create(Drawable[] layers, int color, int pressed) {
    if (Build.VERSION.SDK_INT >= 21) {
        LayerDrawable ld = new LayerDrawable(layers);
        ld.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        RippleDrawable rd = new RippleDrawable(ColorStateList.valueOf(pressed), ld, null);
        return rd;
    } else {/* www  .  jav  a  2  s.c  o m*/
        return new ColorStateDrawable(layers, color, pressed);
    }
}

From source file:com.facebook.react.views.view.ReactViewBackgroundManager.java

private ReactViewBackgroundDrawable getOrCreateReactViewBackground() {
    if (mReactBackgroundDrawable == null) {
        mReactBackgroundDrawable = new ReactViewBackgroundDrawable(mView.getContext());
        Drawable backgroundDrawable = mView.getBackground();
        ViewCompat.setBackground(mView, null); // required so that drawable callback is cleared before we add the
        // drawable back as a part of LayerDrawable
        if (backgroundDrawable == null) {
            ViewCompat.setBackground(mView, mReactBackgroundDrawable);
        } else {//from   www. j  a v a  2s. c om
            LayerDrawable layerDrawable = new LayerDrawable(
                    new Drawable[] { mReactBackgroundDrawable, backgroundDrawable });
            ViewCompat.setBackground(mView, layerDrawable);
        }
    }
    return mReactBackgroundDrawable;
}

From source file:com.sysdata.widget.accordion.ExpandedViewHolder.java

protected ExpandedViewHolder(View itemView) {
    super(itemView);

    final Context context = itemView.getContext();
    itemView.setBackground(new LayerDrawable(
            new Drawable[] { ContextCompat.getDrawable(context, R.drawable.alarm_background_expanded),
                    ThemeUtils.resolveDrawable(context, R.attr.selectableItemBackground) }));

    // Collapse handler
    itemView.setOnClickListener(new View.OnClickListener() {
        @Override//from  w ww  . j  av  a2  s  . c  o  m
        public void onClick(View v) {
            getItemHolder().collapse();
            notifyItemClicked(ItemAdapter.OnItemClickedListener.ACTION_ID_EXPANDED_VIEW);
        }
    });

    if (arrow != null) {
        arrow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getItemHolder().collapse();
                notifyItemClicked(ItemAdapter.OnItemClickedListener.ACTION_ID_EXPANDED_VIEW);
            }
        });

        // Override arrow drawable if running Lollipop
        if (SystemUtils.isLMR1OrLater()) {
            arrow.setImageDrawable(
                    ContextCompat.getDrawable(itemView.getContext(), R.drawable.ic_caret_up_animation));
        }
    }

    itemView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
}

From source file:org.aminb.mathtools.app.activity.BaseActivity.java

private void changeColor(int newColor) {
    // change ActionBar color just if an ActionBar is available
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        Drawable colorDrawable = new ColorDrawable(getResources().getColor(newColor));
        Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
        LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ld.setCallback(drawableCallback);
        } else {//from ww  w  .j ava 2s .  c  o m
            mActionBar.setBackgroundDrawable(ld);
        }

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

    }
}

From source file:android.support.design.widget.FloatingActionButtonLollipop.java

@Override
void setBackgroundDrawable(ColorStateList backgroundTint, PorterDuff.Mode backgroundTintMode, int rippleColor,
        int borderWidth) {
    // Now we need to tint the shape background with the tint
    mShapeDrawable = DrawableCompat.wrap(createShapeDrawable());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }/* ww  w  .  j a  v a2 s . co  m*/

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

    mRippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor), rippleContent, null);

    mContentBackground = mRippleDrawable;

    mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
}

From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.FloatingActionButtonLollipop.java

@Override
void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint,
        PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) {
    // Now we need to tint the original background with the tint
    mShapeDrawable = DrawableCompat.wrap(originalBackground.mutate());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }/*from   w  ww.j  a  v  a 2  s.  c o m*/

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

    mRippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor), rippleContent, null);

    mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
    mShadowViewDelegate.setShadowPadding(0, 0, 0, 0);
}

From source file:com.carinsurance.pagerslidingtabstrip.pagerslidingtabstripMainActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);/*  w  w w.  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 {
                //               Log.v("aaa","getActionBar=="+getActionBar());
                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:com.example.demo.frame.pageslidingtabstrip.PagerSlidingTabStripActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//from w  w w .j a  v a  2s.  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.mipmap.ic_launcher);
        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:com.doctoror.fuckoffmusicplayer.presentation.queue.QueueItemViewHolder.java

@NonNull
private Drawable getSelectedBackground(@NonNull final Context context) {
    if (mSelectedBackground != null) {
        return mSelectedBackground;
    }//from ww  w.  j a v a  2s .  c  o  m

    mSelectedBackground = new LayerDrawable(new Drawable[] {
            new ColorDrawable(ThemeUtils.getColor(context.getTheme(), android.R.attr.windowBackground)),
            new ColorDrawable(ContextCompat.getColor(context, R.color.dividerBackground)) });

    return mSelectedBackground;
}