Example usage for android.graphics.drawable BitmapDrawable BitmapDrawable

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

Introduction

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

Prototype

private BitmapDrawable(BitmapState state, Resources res) 

Source Link

Usage

From source file:com.example.com.jglx.android.app.util.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView.//from   ww  w .j  a  v a2s.c  om
 * 
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final
        // drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.example.image.ImageWorker.java

protected Drawable getLoadingDrawable() {
    byte[] chunk = mLoadingBitmap.getNinePatchChunk();
    if (NinePatch.isNinePatchChunk(chunk)) {
        return new NinePatchDrawable(mResources, mLoadingBitmap, chunk, new Rect(), null);
    } else {//from   www  .j  av  a 2  s. c o  m
        return new BitmapDrawable(mResources, mLoadingBitmap);
    }
}

From source file:com.github.programmerr47.vkgroups.imageloading.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView./*w  w w. java2  s .com*/
 */
private void setImageDrawable(ImageView imageView, BitmapDrawable drawable, LoadBitmapParams loadingParams) {
    Drawable finalDrawable = postProcessDrawable(drawable, loadingParams);

    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(imageView.getResources().getColor(android.R.color.transparent)),
                finalDrawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(finalDrawable);
    }
}

From source file:com.swater.meimeng.activity.oomimg.ImageCache.java

/**
 * A blocking call to get an image. If it's in the cache, it'll return the drawable immediately.
 * Otherwise it will download, scale, and cache the image before returning it. For non-blocking
 * use, see {@link #loadImage(int, android.net.Uri, int, int)}
 *
 * @param uri/*from w w  w . ja v a  2s . c  o  m*/
 * @param width
 * @param height
 * @return
 * @throws org.apache.http.client.ClientProtocolException
 * @throws java.io.IOException
 * @throws ImageCacheException
 */
public Drawable getImage(Uri uri, int width, int height)
        throws ClientProtocolException, IOException, ImageCacheException {

    final String scaledKey = getKey(uri, width, height);

    mDownloading.lock(scaledKey);

    try {
        Drawable d = getDrawable(scaledKey);
        if (d != null) {
            return d;
        }

        Bitmap bmp = get(scaledKey);

        if (bmp == null) {
            if ("file".equals(uri.getScheme())) {
                bmp = scaleLocalImage(new File(uri.getPath()), width, height);
            } else {
                final String sourceKey = getKey(uri);

                mDownloading.lock(sourceKey);

                try {
                    if (!contains(sourceKey)) {
                        downloadImage(sourceKey, uri);
                    }
                } finally {
                    mDownloading.unlock(sourceKey);
                }

                bmp = scaleLocalImage(getFile(sourceKey), width, height);
                if (bmp == null) {
                    clear(sourceKey);
                }
            }
            put(scaledKey, bmp);

        }
        if (bmp == null) {
            throw new ImageCacheException("got null bitmap from request to scale");

        }
        d = new BitmapDrawable(mRes, bmp);
        putDrawable(scaledKey, d);

        return d;

    } finally {
        mDownloading.unlock(scaledKey);
    }
}

From source file:com.crazyapk.util.bitmap.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//w  w  w  .  j av a 2 s .  co m
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap 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
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {

        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.nf2m.util.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView.//  w w  w  .  j a  v a 2s. c om
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(@NonNull ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with UriObserver transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(ContextCompat.getColor(mContext, android.R.color.transparent)), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
    if (ImageDetailFragment.mProgress != null) {
        ImageDetailFragment.mProgress.setVisibility(View.GONE);
    }
}

From source file:baselyous.com.copticsmedia.mediaTasks.tasks.ebsalmodiaTask.util.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView./*from  www. j  a v  a2s .c o  m*/
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(mResources.getColor(android.R.color.transparent)), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:air.com.snagfilms.utils.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView./*  www  .j a  v a2 s . c o m*/
 * 
 * @param imageView
 * @param drawable
 */
@SuppressWarnings("deprecation")
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final
        // drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.baseproject.image.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView./* w  w  w  .  ja  v  a2s . c o m*/
 * 
 * @param imageView
 * @param bitmap
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        if (imageView.getTag() instanceof String && "no_animation".equals(String.valueOf(imageView.getTag()))) {
            imageView.setImageBitmap(bitmap);
        } else {
            // Transition drawable with a transparent drwabale and the final
            // bitmap
            TransitionDrawable td = new TransitionDrawable(
                    new Drawable[] { new ColorDrawable(android.R.color.transparent),
                            new BitmapDrawable(mContext.getResources(), bitmap) });
            final WeakReference<TransitionDrawable> tdReference = new WeakReference<TransitionDrawable>(td);
            td = null;
            // Set background to loading bitmap
            final BitmapDrawable bd = new BitmapDrawable(mContext.getResources(), mLoadingBitmap);
            if (Build.VERSION.SDK_INT >= 16) {
                imageView.setBackground(bd);
            } else {
                imageView.setBackgroundDrawable(bd);

            }
            if (null != tdReference.get()) {
                imageView.setImageDrawable(tdReference.get());
                tdReference.get().startTransition(FADE_IN_TIME);
            }
        }
    } else {
        imageView.setImageBitmap(bitmap);
    }

}

From source file:com.alex.develop.cache.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView.//from  w  ww.ja  v a 2 s.  c  o  m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {

                // Edit by alex
                // before
                new ColorDrawable(android.R.color.transparent),
                // after
                //                            new ColorDrawable(Color.parseColor("#00000000")),
                // end

                drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}