Example usage for android.graphics.drawable TransitionDrawable TransitionDrawable

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

Introduction

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

Prototype

public TransitionDrawable(Drawable[] layers) 

Source Link

Document

Create a new transition drawable with the specified list of layers.

Usage

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);
            }//ww  w.j  a v a 2s.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:augsburg.se.alltagsguide.utilities.ui.BaseActivity.java

protected void changeColor(@ColorInt int primaryColor) {
    ColorDrawable colorDrawableActivity = new ColorDrawable(primaryColor);
    ColorDrawable colorDrawableTabs = new ColorDrawable(primaryColor);
    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        if (oldBackgroundActivity == null) {
            ab.setBackgroundDrawable(colorDrawableActivity);
            changeTabColor(colorDrawableTabs, primaryColor);
        } else {/* w  w  w  .  j  av a 2 s  . c  o  m*/
            TransitionDrawable tdActivity = new TransitionDrawable(
                    new Drawable[] { oldBackgroundActivity, colorDrawableActivity });
            TransitionDrawable tdTabs = new TransitionDrawable(
                    new Drawable[] { oldBackgroundTabs, colorDrawableTabs });
            ab.setBackgroundDrawable(tdActivity);
            changeTabColor(tdTabs, primaryColor);
            tdActivity.startTransition(DURATION);
            tdTabs.startTransition(DURATION);
        }
    }
    oldBackgroundActivity = colorDrawableActivity;
    oldBackgroundTabs = colorDrawableTabs;
    mPrefUtilities.saveCurrentColor(primaryColor);
}

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

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//from   www.  ja v a  2 s .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.lucasr.smoothie.samples.gallery.GalleryLoader.java

@Override
public void displayItem(View itemView, Bitmap result, boolean fromMemory) {
    if (result == null) {
        return;//  w w  w .ja  va2  s  .c o  m
    }

    ViewHolder holder = (ViewHolder) itemView.getTag();

    BitmapDrawable imageDrawable = new BitmapDrawable(itemView.getResources(), result);

    if (fromMemory) {
        holder.image.setImageDrawable(imageDrawable);
    } else {
        BitmapDrawable emptyDrawable = new BitmapDrawable(itemView.getResources());

        TransitionDrawable fadeInDrawable = new TransitionDrawable(
                new Drawable[] { emptyDrawable, imageDrawable });

        holder.image.setImageDrawable(fadeInDrawable);
        fadeInDrawable.startTransition(200);
    }
}

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

public void changeColor(int newColor) {

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

}

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

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//from ww w.jav a2s  .  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.musenkishi.atelier.Atelier.java

private static void applyColorToView(final PaletteTarget target, int color, boolean fromCache) {
    if (target.getView() instanceof TextView) {
        applyColorToView((TextView) target.getView(), color, fromCache);
    } else if (target.getView() instanceof CardView) {
        applyColorToView((CardView) target.getView(), color, fromCache);
    } else if (target.getView() instanceof FloatingActionButton) {
        applyColorToView((FloatingActionButton) target.getView(), color, fromCache,
                target.shouldMaskDrawable());
    } else if (target.getView() instanceof ImageView) {
        applyColorToView((ImageView) target.getView(), color, fromCache, target.shouldMaskDrawable());
    } else {//from   www  . j  a  va 2  s  .c  om
        if (fromCache) {
            target.getView().setBackgroundColor(color);
        } else {
            Drawable preDrawable;

            if (target.getView().getBackground() == null) {
                preDrawable = new ColorDrawable(Color.TRANSPARENT);
            } else {
                preDrawable = target.getView().getBackground();
            }

            TransitionDrawable transitionDrawable = new TransitionDrawable(
                    new Drawable[] { preDrawable, new ColorDrawable(color) });
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                target.getView().setBackground(transitionDrawable);
            } else {
                target.getView().setBackgroundDrawable(transitionDrawable);
            }
            transitionDrawable.startTransition(300);
        }
    }
}

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 {//w  w  w.  j a v a 2s .  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.lulu.admin.kuyimusic.MainActivity.java

public void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);/*w w  w . j  av  a2  s  .com*/

    // 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.palette.BitmapPalette.java

private void crossfadeTargetBackground(PaletteTarget target, Pair<View, Integer> t, int newColor) {

    final Drawable oldColor = t.first.getBackground();
    final Drawable[] drawables = new Drawable[2];

    drawables[0] = oldColor != null ? oldColor : new ColorDrawable(t.first.getSolidColor());
    drawables[1] = new ColorDrawable(newColor);
    TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        t.first.setBackground(transitionDrawable);
    } else {//from w  w  w . j  av  a 2  s.  c  om
        //noinspection deprecation
        t.first.setBackgroundDrawable(transitionDrawable);
    }
    transitionDrawable.startTransition(target.targetCrossfadeSpeed);
}