Search in sources :

Example 11 with FetchBitmapTask

use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project Shuttle by timusus.

the class VideoCastControllerFragment method showImage.

/*
     * Gets the image at the given url and populates the image view with that. It tries to cache the
     * image to avoid unnecessary network calls.
     */
private void showImage(final Uri uri) {
    if (uri == null) {
        mCastController.setImage(BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.album_art_placeholder_large));
        return;
    }
    if (mUrlAndBitmap != null && mUrlAndBitmap.isMatch(uri)) {
        // we can reuse mBitmap
        mCastController.setImage(mUrlAndBitmap.mBitmap);
        return;
    }
    mUrlAndBitmap = null;
    if (mImageAsyncTask != null) {
        mImageAsyncTask.cancel(true);
    }
    Point screenSize = Utils.getDisplaySize(getActivity());
    mImageAsyncTask = new FetchBitmapTask(screenSize.x, screenSize.y, false) {

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            if (bitmap != null) {
                mUrlAndBitmap = new UrlAndBitmap();
                mUrlAndBitmap.mBitmap = bitmap;
                mUrlAndBitmap.mUrl = uri;
                if (!isCancelled()) {
                    mCastController.setImage(bitmap);
                }
            }
            if (this == mImageAsyncTask) {
                mImageAsyncTask = null;
            }
        }
    };
    mImageAsyncTask.execute(uri);
}
Also used : Bitmap(android.graphics.Bitmap) Point(android.graphics.Point) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)

Example 12 with FetchBitmapTask

use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project zype-android by zype.

the class VideoMediaRouteControllerDialog method setIcon.

public void setIcon(Uri uri) {
    if (mIconUri != null && mIconUri.equals(uri)) {
        return;
    }
    mIconUri = uri;
    if (uri == null) {
        Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder);
        mIcon.setImageBitmap(bm);
        return;
    }
    if (mFetchBitmap != null) {
        mFetchBitmap.cancel(true);
    }
    mFetchBitmap = new FetchBitmapTask() {

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            mIcon.setImageBitmap(bitmap);
            if (this == mFetchBitmap) {
                mFetchBitmap = null;
            }
        }
    };
    mFetchBitmap.execute(mIconUri);
}
Also used : Bitmap(android.graphics.Bitmap) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)

Example 13 with FetchBitmapTask

use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project zype-android by zype.

the class MiniController method setIcon.

@Override
public void setIcon(Uri uri) {
    if (mIconUri != null && mIconUri.equals(uri)) {
        return;
    }
    mIconUri = uri;
    if (mFetchBitmapTask != null) {
        mFetchBitmapTask.cancel(true);
    }
    mFetchBitmapTask = new FetchBitmapTask() {

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            if (bitmap == null) {
                bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.album_art_placeholder);
            }
            setIcon(bitmap);
            if (this == mFetchBitmapTask) {
                mFetchBitmapTask = null;
            }
        }
    };
    mFetchBitmapTask.execute(uri);
}
Also used : Bitmap(android.graphics.Bitmap) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)

Example 14 with FetchBitmapTask

use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project zype-android by zype.

the class VideoCastControllerFragment method showImage.

/*
     * Gets the image at the given url and populates the image view with that. It tries to cache the
     * image to avoid unnecessary network calls.
     */
private void showImage(final Uri uri) {
    if (mImageAsyncTask != null) {
        mImageAsyncTask.cancel(true);
    }
    if (uri == null) {
        mCastController.setImage(BitmapFactory.decodeResource(getActivity().getResources(), com.google.android.libraries.cast.companionlibrary.R.drawable.album_art_placeholder_large));
        return;
    }
    if (mUrlAndBitmap != null && mUrlAndBitmap.isMatch(uri)) {
        // we can reuse mBitmap
        mCastController.setImage(mUrlAndBitmap.mBitmap);
        return;
    }
    mUrlAndBitmap = null;
    mImageAsyncTask = new FetchBitmapTask() {

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            if (bitmap != null) {
                mUrlAndBitmap = new UrlAndBitmap();
                mUrlAndBitmap.mBitmap = bitmap;
                mUrlAndBitmap.mUrl = uri;
                mCastController.setImage(bitmap);
            }
            if (this == mImageAsyncTask) {
                mImageAsyncTask = null;
            }
        }
    };
    mImageAsyncTask.execute(uri);
}
Also used : Bitmap(android.graphics.Bitmap) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)

Aggregations

Bitmap (android.graphics.Bitmap)14 FetchBitmapTask (com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)14 Uri (android.net.Uri)5 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)3 Builder (com.google.android.gms.cast.Cast.CastOptions.Builder)3 Point (android.graphics.Point)2 WebImage (com.google.android.gms.common.images.WebImage)2 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)2 NotFoundException (android.content.res.Resources.NotFoundException)1 MediaInfo (com.google.android.gms.cast.MediaInfo)1 MediaMetadata (com.google.android.gms.cast.MediaMetadata)1 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)1 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)1