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

@SuppressWarnings("ResourceType")
public static TransitionDrawable drawable2TransitionDrawable(Drawable drawable) {
    TransitionDrawable mBitmapDrawable = null;
    try {//from  ww  w  .  j  a  va 2 s.  co m
        if (drawable == null) {
            return null;
        }
        mBitmapDrawable = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mBitmapDrawable;
}

From source file:Main.java

@SuppressWarnings("ResourceType")
public static TransitionDrawable bitmap2TransitionDrawable(Bitmap bitmap) {
    TransitionDrawable mBitmapDrawable = null;
    try {//from   w ww  .  j a v  a  2 s  . c  o  m
        if (bitmap == null) {
            return null;
        }
        mBitmapDrawable = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(null, bitmap) });
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mBitmapDrawable;
}

From source file:Main.java

public static TransitionDrawable drawableToTransitionDrawable(Drawable drawable) {
    TransitionDrawable mBitmapDrawable = null;
    try {/*  ww w  .ja  va 2 s .c  o m*/
        if (drawable == null) {
            return null;
        }
        mBitmapDrawable = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mBitmapDrawable;
}

From source file:Main.java

public static TransitionDrawable drawableToTransitionDrawable(Drawable drawable) {
    TransitionDrawable mBitmapDrawable = null;
    try {//ww w.ja va 2s. c o m
        if (drawable == null) {
            return null;
        }
        mBitmapDrawable = new TransitionDrawable(new Drawable[] { new ColorDrawable(transparent), drawable });
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mBitmapDrawable;
}

From source file:Main.java

public static TransitionDrawable bitmapToTransitionDrawable(Bitmap bitmap) {
    TransitionDrawable mBitmapDrawable = null;
    try {/* www . j a  v  a 2s .  co  m*/
        if (bitmap == null) {
            return null;
        }
        mBitmapDrawable = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(bitmap) });
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mBitmapDrawable;
}

From source file:Main.java

public static TransitionDrawable bitmapToTransitionDrawable(Bitmap bitmap) {
    TransitionDrawable mBitmapDrawable = null;
    try {/*  w  w w .  j  a  va 2 s. c  o  m*/
        if (bitmap == null) {
            return null;
        }
        mBitmapDrawable = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(transparent), new BitmapDrawable(bitmap) });
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mBitmapDrawable;
}

From source file:Main.java

/**
 * @see "http://blog.peterkuterna.net/2011/09/simple-crossfade-on-imageview.html"
 * with modifications by Thomas Suarez.//from  www.ja  v  a 2 s.c om
 */
public static void setImageDrawableWithFade(final Activity context, final ImageView imageView,
        final String drawableName, final int durationMillis) {
    int resId = getDrawableId(context, drawableName); // get new drawable resource
    Drawable drawable;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        drawable = context.getResources().getDrawable(resId, context.getTheme());
    } else {
        drawable = context.getResources().getDrawable(resId); // this is deprecated starting in Android 5.0 Lollipop
    }

    final Drawable currentDrawable = imageView.getDrawable();
    final Drawable newDrawable = drawable;

    Runnable r = new Runnable() {
        @Override
        public void run() {
            if (currentDrawable != null) {
                Drawable[] arrayDrawable = new Drawable[2];
                arrayDrawable[0] = currentDrawable;
                arrayDrawable[1] = newDrawable;
                TransitionDrawable transitionDrawable = new TransitionDrawable(arrayDrawable);
                transitionDrawable.setCrossFadeEnabled(true);
                imageView.setImageDrawable(transitionDrawable);
                transitionDrawable.startTransition(durationMillis);
            } else {
                imageView.setImageDrawable(newDrawable);
            }
        }
    };
    context.runOnUiThread(r);
}

From source file:dev.vision.shopping.center.Splash.java

void Init() {
    overrideFonts(this, findViewById(android.R.id.content));

    final ImageView im = null;//(ImageView) findViewById(R.id.ImageView01);

    td = (TransitionDrawable) im.getDrawable();
    td.setCrossFadeEnabled(true);/*from   ww w .j a  va  2 s .c  o m*/
    td.startTransition(3000);
    final Random rnd = new Random();

    new Handler().postDelayed(new Runnable() {

        @SuppressLint("NewApi")
        @Override
        public void run() {
            int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
            td = new TransitionDrawable(new Drawable[] { td.getDrawable(1), new ColorDrawable(color) });
            im.setImageDrawable(td);
            td.setCrossFadeEnabled(true);
            td.startTransition(3000);

            new Handler().postDelayed(this, 3000);
        }
    }, 3000);
}

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 a2s  .  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.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.carinsurance.pagerslidingtabstrip.pagerslidingtabstripMainActivity.java

private void changeColor(int newColor) {

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

}