Example usage for android.graphics.drawable TransitionDrawable startTransition

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

Introduction

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

Prototype

public void startTransition(int durationMillis) 

Source Link

Document

Begin the second layer on top of the first layer.

Usage

From source file:com.marshalchen.common.demoofui.pagerSlidingTabStrip.PagerSlidingTabStripActivity.java

private void changeColor(int newColor) {

    tabs.setBackgroundColor(newColor);//w w  w . j av a 2 s.  c  o  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:org.lucasr.smoothie.samples.gallery.GalleryLoader.java

@Override
public void displayItem(View itemView, Bitmap result, boolean fromMemory) {
    if (result == null) {
        return;/*from www. jav  a2s  .co  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.medhdj.pagergallery.PagerGalleryContainer.java

@Override
public void onPageSelected(int position) {
    if (position == mPreviousSelectedPosition) {
        return;/*w w  w .j a  va 2 s. co  m*/
    }
    View v = mPager.getChildAt(position);
    if (v != null) {
        if (v.getBackground() instanceof TransitionDrawable) {
            TransitionDrawable transition = (TransitionDrawable) v.getBackground();
            if (transition != null) {
                transition.startTransition(700);
            }

        }
    }

    View mprev = mPager.getChildAt(mPreviousSelectedPosition);
    if (mprev != null) {
        if (mprev.getBackground() instanceof TransitionDrawable) {
            TransitionDrawable transition = (TransitionDrawable) mprev.getBackground();
            if (transition != null) {
                transition.reverseTransition(700);
                transition.resetTransition();
            }

        }
    }

    if (mOnItemChangedListener != null) {
        mOnItemChangedListener.onItemSelected(v, position);
        mOnItemChangedListener.onItemUnSelected(mprev, mPreviousSelectedPosition);
    }

    mPreviousSelectedPosition = position;
}

From source file:com.haoxue.zixueplayer.MainActivity.java

private void changeColor(int newColor) {

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

            getActionBar().setBackgroundDrawable(ld);

        } else {

            TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });

            getActionBar().setBackgroundDrawable(td);

            td.startTransition(200);

        }

        oldBackground = ld;

        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);

    }

}

From source file:jahirfiquitiva.iconshowcase.adapters.WallpapersAdapter.java

@Override
public void onBindViewHolder(final WallsHolder holder, int position) {
    final WallpaperItem wallItem = wallsList.get(position);

    ViewCompat.setTransitionName(holder.wall, "transition" + position);

    holder.name.setText(wallItem.getWallName());
    holder.authorName.setText(wallItem.getWallAuthor());

    final String wallUrl = wallItem.getWallURL();
    String wallThumb = wallItem.getWallThumbUrl();

    BitmapImageViewTarget target = new BitmapImageViewTarget(holder.wall) {
        @Override/*from w  w  w  .  java2s .c o m*/
        protected void setResource(Bitmap resource) {
            Palette.Swatch wallSwatch = ColorExtractor.getProminentSwatch(resource, false);
            boolean animsEnabled = mPrefs.getAnimationsEnabled();

            if (animsEnabled) {
                TransitionDrawable td = new TransitionDrawable(
                        new Drawable[] { new ColorDrawable(Color.TRANSPARENT),
                                new BitmapDrawable(context.getResources(), resource) });
                holder.wall.setImageDrawable(td);
                td.startTransition(250);
            } else {
                holder.wall.setImageBitmap(resource);
            }

            if (wallSwatch != null) {
                if (animsEnabled) {
                    TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                            holder.titleBg.getBackground(), new ColorDrawable(wallSwatch.getRgb()) });
                    holder.titleBg.setBackground(td);
                    td.startTransition(250);
                } else {
                    holder.titleBg.setBackgroundColor(wallSwatch.getRgb());
                }
                holder.name.setTextColor(wallSwatch.getBodyTextColor());
                holder.authorName.setTextColor(wallSwatch.getTitleTextColor());
            }
        }
    };

    if (!(wallThumb.equals("null"))) {
        Glide.with(context).load(wallUrl).asBitmap()
                .thumbnail(Glide.with(context).load(wallThumb).asBitmap().thumbnail(0.3f)).into(target);
    } else {
        Glide.with(context).load(wallUrl).asBitmap().thumbnail(0.4f).into(target);
    }
}

From source file:com.jia.blossom.viewpageindicator.MainActivity.java

private void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);/*from   w w w  . j a v a2 s  .  com*/
    if (Build.VERSION.SDK_INT >= 11) {
        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 < 17) {
                Log.e("lintest", Build.VERSION.SDK_INT + " < 17");
                ld.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(ld);
            }
        } else {
            // TransitionDrawableDrawable?drawable?
            TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
            if (Build.VERSION.SDK_INT < 17) {
                td.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(td);
            }
            td.startTransition(3000);
        }
        oldBackground = ld;
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);
    }
    currentColor = newColor;
}

From source file:com.android.volley.ui.NetworkImageView.java

@SuppressLint("NewApi")
private void setAnimateImageBitmap(final Bitmap bitmap, boolean fadeIn) {

    // If we're fading in and on HC MR1+
    if (fadeIn && Utils.hasHoneycombMR1()) {
        // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the
        // ImageView
        animate().scaleY(0.95f).scaleX(0.95f).alpha(0f)
                .setDuration(getDrawable() == null ? 0 : HALF_FADE_IN_TIME)
                .setListener(new AnimatorListenerAdapter() {
                    @Override/*from  www . ja v  a 2  s .c o m*/
                    public void onAnimationEnd(Animator animation) {
                        setImageBitmap(bitmap);
                        animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME)
                                .setListener(null);
                    }
                });
    } else if (fadeIn) {
        // Otherwise use a TransitionDrawable to fade in
        Drawable initialDrawable;
        if (getDrawable() != null) {
            initialDrawable = getDrawable();
        } else {
            initialDrawable = transparentDrawable;
        }

        BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
        // Use TransitionDrawable to fade in
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { initialDrawable, bitmapDrawable });
        setImageDrawable(td);
        td.startTransition(Utils.ANIMATION_FADE_IN_TIME);
    } else {
        // No fade in, just set bitmap directly
        setImageBitmap(bitmap);
    }
}

From source file:cn.psvmc.demo.MainActivity.java

private void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);//from  w  w  w  .ja va  2 s  .c o  m
    ActionBar actionbar = getActionBar();
    if (actionbar == null) {
        return;
    }
    // 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: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 {/*from  w  w w  .j  a  va 2s .  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.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 {// www  . jav  a 2 s .  c  om
        //noinspection deprecation
        t.first.setBackgroundDrawable(transitionDrawable);
    }
    transitionDrawable.startTransition(target.targetCrossfadeSpeed);
}