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.marshalchen.common.demoofui.pagerSlidingTabStrip.PagerSlidingTabStripActivity.java

private void changeColor(int newColor) {

    tabs.setBackgroundColor(newColor);/*  w  w  w. j a  v  a 2s  . co m*/
    mTintManager.setTintColor(newColor);
    // change ActionBar color just if an ActionBar is available

    Drawable colorDrawable = new ColorDrawable(newColor);
    Drawable bottomDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent));
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

    if (oldBackground == null) {
        getSupportActionBar().setBackgroundDrawable(ld);
    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        getSupportActionBar().setBackgroundDrawable(td);
        td.startTransition(200);
    }

    oldBackground = ld;
    currentColor = newColor;

}

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

@Override
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);
    }/*from w  w  w . j  a  v a2  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.getResources(), mContentBackground,
            mShadowViewDelegate.getRadius(), mElevation, mElevation + mPressedTranslationZ);
    mShadowDrawable.setAddPaddingForCorners(false);
    mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable);
}

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

@Override
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);
    }/*from  w  w  w.j a v  a 2 s. c om*/

    // 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.collcloud.frame.viewpager.main.PagerTabMainActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//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.drawable.tab_pagertab_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:com.eccyan.widget.sample.MainActivity.java

private void changeColor(int newColor) {
    tabs.setBackgroundColor(newColor);/*  w ww. ja  v a2 s  .co m*/
    mTintManager.setTintColor(newColor);
    // change ActionBar color just if an ActionBar is available
    Drawable colorDrawable = new ColorDrawable(newColor);
    Drawable bottomDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent));
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });
    if (oldBackground == null) {
        getSupportActionBar().setBackgroundDrawable(ld);
    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        getSupportActionBar().setBackgroundDrawable(td);
        td.startTransition(200);
    }

    oldBackground = ld;
    currentColor = newColor;
}

From source file:com.mymusic.cocomusic.MainActivity.java

private void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);//from w w w.jav  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.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:com.aujur.ebookreader.reading.options.ReadingOptionsFragment.java

private void changeColor(int newColor) {

    // tabs.setIndicatorColor(newColor);
    tabs.setIndicatorColor(getResources().getColor(R.color.green_tab_indicator));
    // tabs.setIndicatorColor(2131034133);

    // 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 {
                getActivity().getActionBar().setBackgroundDrawable(ld);
            }//from   w  w  w  .  j  a va  2 s. c o m

        } 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 {
                getActivity().getActionBar().setBackgroundDrawable(td);
            }

            td.startTransition(200);

        }

        oldBackground = ld;

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

    }

    currentColor = newColor;

}

From source file:com.ouyang.musicplayer.MainActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);/*from ww  w. j a v  a  2 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 });

            // 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:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.FloatingActionButtonEclairMr1.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, using
    // an InsetDrawable if we have a border width
    mShapeDrawable = DrawableCompat.wrap(originalBackground.mutate());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }/*from w  ww  . j  a va2 s . com*/

    // Now we created a mask Drawable which will be used for touch feedback.
    // As we don't know the actual outline of mShapeDrawable, we'll just guess that it's a
    // circle
    GradientDrawable touchFeedbackShape = new GradientDrawable();
    touchFeedbackShape.setShape(GradientDrawable.OVAL);
    touchFeedbackShape.setColor(Color.WHITE);
    touchFeedbackShape.setCornerRadius(mShadowViewDelegate.getRadius());

    // 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));
    DrawableCompat.setTintMode(mRippleDrawable, PorterDuff.Mode.MULTIPLY);

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

    mShadowDrawable = new ShadowDrawableWrapper(mView.getResources(), new LayerDrawable(layers),
            mShadowViewDelegate.getRadius(), mElevation, mElevation + mPressedTranslationZ);
    mShadowDrawable.setAddPaddingForCorners(false);

    mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable);

    updatePadding();
}

From source file:com.lesikapk.opengelplus.settings.SettingsActivity.java

public void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//from w w w. j a  va 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.drawable.background_tab);
        LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

        // This is actually unnecessary because the actionbar is hidden anyways, however I will leave this because of the transition.
        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;

}