Search in sources :

Example 11 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project cube-sdk by liaohuqiu.

the class DefaultImageLoadHandler method onLoadFinish.

@Override
public void onLoadFinish(ImageTask imageTask, CubeImageView imageView, BitmapDrawable drawable) {
    if (imageView == null) {
        return;
    }
    Drawable d = drawable;
    if (drawable != null) {
        if (mResizeImageViewAfterLoad) {
            int w = drawable.getBitmap().getWidth();
            int h = drawable.getBitmap().getHeight();
            if (w > 0 && h > 0) {
                ViewGroup.LayoutParams lyp = imageView.getLayoutParams();
                if (lyp != null) {
                    lyp.width = w;
                    lyp.height = h;
                    imageView.setLayoutParams(lyp);
                }
            }
        }
        // RoundedDrawable will not recycle automatically when API level is lower than 11
        if ((mDisplayTag & DISPLAY_ROUNDED) == DISPLAY_ROUNDED && Version.hasHoneycomb()) {
            d = new RoundedDrawable(drawable.getBitmap(), mCornerRadius);
        }
        if ((mDisplayTag & DISPLAY_FADE_IN) == DISPLAY_FADE_IN) {
            int loadingColor = android.R.color.transparent;
            if (mLoadingColor != -1 && (mDisplayTag & DISPLAY_ROUNDED) != DISPLAY_ROUNDED) {
                loadingColor = mLoadingColor;
            }
            final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(loadingColor), d });
            imageView.setImageDrawable(td);
            td.startTransition(200);
        } else {
            if (DEBUG) {
                Drawable oldDrawable = imageView.getDrawable();
                int w = 0, h = 0;
                if (oldDrawable != null) {
                    w = oldDrawable.getIntrinsicWidth();
                    h = oldDrawable.getIntrinsicHeight();
                }
                CLog.d(LOG_TAG, MSG_LOAD_FINISH, imageTask, imageView, w, h, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            }
            imageView.setImageDrawable(drawable);
        }
    }
}
Also used : RoundedDrawable(in.srain.cube.image.drawable.RoundedDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) RoundedDrawable(in.srain.cube.image.drawable.RoundedDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 12 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project NotificationPeekPort by lzanita09.

the class AppearanceSettingsFragment method initPreviewBackgroundDrawable.

/**
     * Create a new {@link android.graphics.drawable.TransitionDrawable} object with correct order
     * of Drawables based on user selection.
     *
     * @return TransitionDrawable object created.
     */
private TransitionDrawable initPreviewBackgroundDrawable() {
    boolean isWallpaperSelected = WallpaperFactory.isWallpaperThemeSelected(getActivity());
    Drawable black = new ColorDrawable(Color.BLACK);
    Drawable wallpaper = mUseLiveWallpaper ? new ColorDrawable(Color.TRANSPARENT) : new BitmapDrawable(getResources(), mWallpaperFactory.getPrefSystemWallpaper());
    mChangeDrawables = !isWallpaperSelected ? new Drawable[] { black, wallpaper } : new Drawable[] { wallpaper, black };
    mBlackDrawableIndex = !isWallpaperSelected ? 0 : 1;
    return new TransitionDrawable(mChangeDrawables);
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 13 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project 9GAG by stormzhang.

the class ImageCacheManager method getImageListener.

public static ImageLoader.ImageListener getImageListener(final ImageView view, final Drawable defaultImageDrawable, final Drawable errorImageDrawable) {
    return new ImageLoader.ImageListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageDrawable != null) {
                view.setImageDrawable(errorImageDrawable);
            }
        }

        @Override
        public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                if (!isImmediate && defaultImageDrawable != null) {
                    TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { defaultImageDrawable, new BitmapDrawable(App.getContext().getResources(), response.getBitmap()) });
                    transitionDrawable.setCrossFadeEnabled(true);
                    view.setImageDrawable(transitionDrawable);
                    transitionDrawable.startTransition(100);
                } else {
                    view.setImageBitmap(response.getBitmap());
                }
            } else if (defaultImageDrawable != null) {
                view.setImageDrawable(defaultImageDrawable);
            }
        }
    };
}
Also used : VolleyError(com.android.volley.VolleyError) TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 14 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project glide by bumptech.

the class DrawableCrossFadeTransition method transition.

/**
   * Animates from the previous drawable to the current drawable in one of two ways.
   *
   * <ol> <li>Using the default animation provided in the constructor if the previous drawable is
   * null</li> <li>Using the cross fade animation with the duration provided in the constructor if
   * the previous drawable is non null</li> </ol>
   *
   * @param current {@inheritDoc}
   * @param adapter {@inheritDoc}
   * @return {@inheritDoc}
   */
@Override
public boolean transition(Drawable current, ViewAdapter adapter) {
    Drawable previous = adapter.getCurrentDrawable();
    if (previous != null) {
        TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { previous, current });
        transitionDrawable.setCrossFadeEnabled(isCrossFadeEnabled);
        transitionDrawable.startTransition(duration);
        adapter.setDrawable(transitionDrawable);
        return true;
    } else {
        defaultAnimation.transition(current, adapter);
        return false;
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Drawable(android.graphics.drawable.Drawable)

Example 15 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project coursera-android by aporter.

the class TransitionDrawableActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TransitionDrawable transition = (TransitionDrawable) getResources().getDrawable(R.drawable.shape_transition);
    transition.setCrossFadeEnabled(true);
    ((ImageView) findViewById(R.id.image_view)).setImageDrawable(transition);
    transition.startTransition(5000);
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ImageView(android.widget.ImageView)

Aggregations

TransitionDrawable (android.graphics.drawable.TransitionDrawable)61 Drawable (android.graphics.drawable.Drawable)45 View (android.view.View)23 ColorDrawable (android.graphics.drawable.ColorDrawable)22 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 VelocityTracker (android.view.VelocityTracker)10 Rect (android.graphics.Rect)9 Handler (android.os.Handler)8 LayerDrawable (android.graphics.drawable.LayerDrawable)5 RippleDrawable (android.graphics.drawable.RippleDrawable)3 Animation (android.view.animation.Animation)3 ImageView (android.widget.ImageView)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 ColorStateList (android.content.res.ColorStateList)2 ContentObserver (android.database.ContentObserver)2 Bitmap (android.graphics.Bitmap)2 Canvas (android.graphics.Canvas)2 GradientDrawable (android.graphics.drawable.GradientDrawable)2 StateListDrawable (android.graphics.drawable.StateListDrawable)2