List of usage examples for android.graphics.drawable TransitionDrawable TransitionDrawable
public TransitionDrawable(Drawable[] layers)
From source file:com.channelsoft.common.bitmapUtil.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView/*w ww .jav a 2 s .co m*/ * @param bitmap */ private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if ("0".equals(imageView.getTag())) { // ?? bitmap = toGrayscale(bitmap); } if (mFadeInBitmap) { // Transition drawable with a transparent drwabale and the final bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); // Set background to loading bitmap //TODO: miaolikui delete 20121229 // imageView.setBackgroundDrawable( // new BitmapDrawable(mResources, mLoadingBitmap)); Log.d(TAG, tagStr + ":imageView.setImageDrawable:" + System.currentTimeMillis()); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { Log.d(TAG, tagStr + ":imageView.setImageBitmap:" + System.currentTimeMillis()); imageView.setImageBitmap(bitmap); } }
From source file:com.android.systemui.statusbar.phone.NavigationBarView.java
private void updateColor(boolean defaults) { Bitmap bm = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); Canvas cnv = new Canvas(bm); if (defaults) { cnv.drawColor(0xFF000000);/* w w w . j a v a 2 s .c om*/ setBackground(new BitmapDrawable(bm)); return; } String setting = Settings.System.getString(mContext.getContentResolver(), Settings.System.NAV_BAR_COLOR); String[] colors = (setting == null || setting.equals("") ? ExtendedPropertiesUtils.PARANOID_COLORS_DEFAULTS[ExtendedPropertiesUtils.PARANOID_COLORS_NAVBAR] : setting).split(ExtendedPropertiesUtils.PARANOID_STRING_DELIMITER); String currentColor = colors[Integer.parseInt(colors[2])]; cnv.drawColor(new BigInteger(currentColor, 16).intValue()); TransitionDrawable transition = new TransitionDrawable( new Drawable[] { getBackground(), new BitmapDrawable(bm) }); transition.setCrossFadeEnabled(true); setBackground(transition); transition.startTransition(1000); }
From source file:com.silentcircle.contacts.ContactPhotoManagerNew.java
/** * Checks if the photo is present in cache. If so, sets the photo on the view. * * @return false if the photo needs to be (re)loaded from the provider. *//*from ww w.j av a2 s .c o m*/ private boolean loadCachedPhoto(ImageView view, Request request, boolean fadeIn) { BitmapHolder holder = mBitmapHolderCache.get(request.getKey()); if (holder == null) { // The bitmap has not been loaded ==> show default avatar request.applyDefaultImage(view, request.mIsCircular); return false; } if (holder.bytes == null) { request.applyDefaultImage(view, request.mIsCircular); return holder.fresh; } Bitmap cachedBitmap = holder.bitmapRef == null ? null : holder.bitmapRef.get(); if (cachedBitmap == null) { if (holder.bytes.length < 8 * 1024) { // Small thumbnails are usually quick to inflate. Let's do that on the UI thread inflateBitmap(holder, request.getRequestedExtent()); cachedBitmap = holder.bitmap; if (cachedBitmap == null) return false; } else { // This is bigger data. Let's send that back to the Loader so that we can // inflate this in the background request.applyDefaultImage(view, request.mIsCircular); return false; } } final Drawable previousDrawable = view.getDrawable(); if (fadeIn && previousDrawable != null) { final Drawable[] layers = new Drawable[2]; // Prevent cascade of TransitionDrawables. if (previousDrawable instanceof TransitionDrawable) { final TransitionDrawable previousTransitionDrawable = (TransitionDrawable) previousDrawable; layers[0] = previousTransitionDrawable .getDrawable(previousTransitionDrawable.getNumberOfLayers() - 1); } else { layers[0] = previousDrawable; } layers[1] = getDrawableForBitmap(mContext.getResources(), cachedBitmap, request); TransitionDrawable drawable = new TransitionDrawable(layers); view.setImageDrawable(drawable); drawable.startTransition(FADE_TRANSITION_DURATION); } else { view.setImageDrawable(getDrawableForBitmap(mContext.getResources(), cachedBitmap, request)); } // Put the bitmap in the LRU cache. But only do this for images that are small enough // (we require that at least six of those can be cached at the same time) if (cachedBitmap.getByteCount() < mBitmapCache.maxSize() / 6) { mBitmapCache.put(request.getKey(), cachedBitmap); } // hack: Don't allow resources from external requests to expire easily Uri uri = request.getUri(); if (uri != null) { final String scheme = uri.getScheme(); if (scheme.equals("http") || scheme.equals("https")) { holder.fresh = true; } } // Soften the reference holder.bitmap = null; return holder.fresh; }
From source file:com.android.contacts.common.ContactPhotoManager.java
/** * Checks if the photo is present in cache. If so, sets the photo on the view. * * @return false if the photo needs to be (re)loaded from the provider. *///from w w w .j a va 2s . c om private boolean loadCachedPhoto(ImageView view, Request request, boolean fadeIn) { BitmapHolder holder = mBitmapHolderCache.get(request.getKey()); if (holder == null) { // The bitmap has not been loaded ==> show default avatar request.applyDefaultImage(view, request.mIsCircular); return false; } if (holder.bytes == null) { request.applyDefaultImage(view, request.mIsCircular); return holder.fresh; } Bitmap cachedBitmap = holder.bitmapRef == null ? null : holder.bitmapRef.get(); if (cachedBitmap == null) { if (holder.bytes.length < 8 * 1024) { // Small thumbnails are usually quick to inflate. Let's do that on the UI thread inflateBitmap(holder, request.getRequestedExtent()); cachedBitmap = holder.bitmap; if (cachedBitmap == null) return false; } else { // This is bigger data. Let's send that back to the Loader so that we can // inflate this in the background request.applyDefaultImage(view, request.mIsCircular); return false; } } final Drawable previousDrawable = view.getDrawable(); if (fadeIn && previousDrawable != null) { final Drawable[] layers = new Drawable[2]; // Prevent cascade of TransitionDrawables. if (previousDrawable instanceof TransitionDrawable) { final TransitionDrawable previousTransitionDrawable = (TransitionDrawable) previousDrawable; layers[0] = previousTransitionDrawable .getDrawable(previousTransitionDrawable.getNumberOfLayers() - 1); } else { layers[0] = previousDrawable; } layers[1] = getDrawableForBitmap(mContext.getResources(), cachedBitmap, request); TransitionDrawable drawable = new TransitionDrawable(layers); view.setImageDrawable(drawable); drawable.startTransition(FADE_TRANSITION_DURATION); } else { view.setImageDrawable(getDrawableForBitmap(mContext.getResources(), cachedBitmap, request)); } // Put the bitmap in the LRU cache. But only do this for images that are small enough // (we require that at least six of those can be cached at the same time) if (cachedBitmap.getByteCount() < mBitmapCache.maxSize() / 6) { mBitmapCache.put(request.getKey(), cachedBitmap); } // Soften the reference holder.bitmap = null; return holder.fresh; }
From source file:com.android.contacts.ContactPhotoManager.java
/** * Checks if the photo is present in cache. If so, sets the photo on the view. * * @return false if the photo needs to be (re)loaded from the provider. *//*from w w w.j a v a 2 s . c om*/ private boolean loadCachedPhoto(ImageView view, Request request, boolean fadeIn) { BitmapHolder holder = mBitmapHolderCache.get(request.getKey()); if (holder == null) { // The bitmap has not been loaded ==> show default avatar request.applyDefaultImage(view, request.mIsCircular); return false; } if (holder.bytes == null || holder.bytes.length == 0) { request.applyDefaultImage(view, request.mIsCircular); return holder.fresh; } Bitmap cachedBitmap = holder.bitmapRef == null ? null : holder.bitmapRef.get(); if (cachedBitmap == null) { if (holder.bytes.length < 8 * 1024) { // Small thumbnails are usually quick to inflate. Let's do that on the UI thread inflateBitmap(holder, request.getRequestedExtent()); cachedBitmap = holder.bitmap; if (cachedBitmap == null) return false; } else { // This is bigger data. Let's send that back to the Loader so that we can // inflate this in the background request.applyDefaultImage(view, request.mIsCircular); return false; } } final Drawable previousDrawable = view.getDrawable(); if (fadeIn && previousDrawable != null) { final Drawable[] layers = new Drawable[2]; // Prevent cascade of TransitionDrawables. if (previousDrawable instanceof TransitionDrawable) { final TransitionDrawable previousTransitionDrawable = (TransitionDrawable) previousDrawable; layers[0] = previousTransitionDrawable .getDrawable(previousTransitionDrawable.getNumberOfLayers() - 1); } else { layers[0] = previousDrawable; } layers[1] = getDrawableForBitmap(mContext.getResources(), cachedBitmap, request); TransitionDrawable drawable = new TransitionDrawable(layers); view.setImageDrawable(drawable); drawable.startTransition(FADE_TRANSITION_DURATION); } else { view.setImageDrawable(getDrawableForBitmap(mContext.getResources(), cachedBitmap, request)); } // Put the bitmap in the LRU cache. But only do this for images that are small enough // (we require that at least six of those can be cached at the same time) if (cachedBitmap.getByteCount() < mBitmapCache.maxSize() / 6) { mBitmapCache.put(request.getKey(), cachedBitmap); } // Soften the reference holder.bitmap = null; return holder.fresh; }