use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project zype-android by zype.
the class VideoCastNotificationService method setUpNotification.
private void setUpNotification(final MediaInfo info) throws TransientNetworkDisconnectionException, NoConnectionException {
if (info == null) {
return;
}
if (mBitmapDecoderTask != null) {
mBitmapDecoderTask.cancel(false);
}
Uri imgUri = null;
try {
if (!info.getMetadata().hasImages()) {
build(info, null, mIsPlaying);
return;
} else {
imgUri = info.getMetadata().getImages().get(0).getUrl();
}
} catch (CastException e) {
LOGE(TAG, "Failed to build notification", e);
}
mBitmapDecoderTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
try {
mVideoArtBitmap = Utils.scaleAndCenterCropBitmap(bitmap, mDimensionInPixels, mDimensionInPixels);
build(info, mVideoArtBitmap, mIsPlaying);
} catch (CastException | NoConnectionException | TransientNetworkDisconnectionException e) {
LOGE(TAG, "Failed to set notification for " + info.toString(), e);
}
if (mVisible && (mNotification != null)) {
startForeground(NOTIFICATION_ID, mNotification);
}
if (this == mBitmapDecoderTask) {
mBitmapDecoderTask = null;
}
}
};
mBitmapDecoderTask.execute(imgUri);
}
use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project zype-android by zype.
the class MiniController method setUpcomingIcon.
private void setUpcomingIcon(Uri uri) {
if (mUpcomingIconUri != null && mUpcomingIconUri.equals(uri)) {
return;
}
mUpcomingIconUri = uri;
if (mFetchUpcomingBitmapTask != null) {
mFetchUpcomingBitmapTask.cancel(true);
}
mFetchUpcomingBitmapTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap == null) {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.album_art_placeholder);
}
setUpcomingIcon(bitmap);
if (this == mFetchUpcomingBitmapTask) {
mFetchUpcomingBitmapTask = null;
}
}
};
mFetchUpcomingBitmapTask.execute(uri);
}
use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project Shuttle by timusus.
the class VideoCastManager method setBitmapForLockScreen.
/*
* Sets the appropriate {@link Bitmap} for the right size image for lock screen. In ICS and
* JB, the image shown on the lock screen is a small size bitmap but for KitKat, the image is a
* full-screen image so we need to separately handle these two cases.
*/
private void setBitmapForLockScreen(MediaInfo video) {
if (video == null || mMediaSessionCompat == null) {
return;
}
Uri imgUrl = null;
Bitmap bm = null;
List<WebImage> images = video.getMetadata().getImages();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (images.size() > 1) {
imgUrl = images.get(1).getUrl();
} else if (images.size() == 1) {
imgUrl = images.get(0).getUrl();
} else if (mContext != null) {
// we don't have a url for image so get a placeholder image from resources
bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder_large);
}
} else if (!images.isEmpty()) {
imgUrl = images.get(0).getUrl();
} else {
// we don't have a url for image so get a placeholder image from resources
bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder);
}
if (bm != null) {
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bm).build());
} else {
if (mLockScreenFetchTask != null) {
mLockScreenFetchTask.cancel(true);
}
Point screenSize = Utils.getDisplaySize(mContext);
mLockScreenFetchTask = new FetchBitmapTask(screenSize.x, screenSize.y, false) {
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null && mMediaSessionCompat != null) {
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap).build());
}
mLockScreenFetchTask = null;
}
};
mLockScreenFetchTask.execute(imgUrl);
}
}
use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project Shuttle by timusus.
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);
}
use of com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask in project Shuttle by timusus.
the class VideoCastNotificationService method setUpNotification.
private void setUpNotification(final MediaInfo info) throws TransientNetworkDisconnectionException, NoConnectionException {
if (info == null) {
return;
}
if (mBitmapDecoderTask != null) {
mBitmapDecoderTask.cancel(false);
}
Uri imgUri = null;
try {
if (!info.getMetadata().hasImages()) {
build(info, null, mIsPlaying);
return;
} else {
imgUri = info.getMetadata().getImages().get(0).getUrl();
}
} catch (CastException e) {
LOGE(TAG, "Failed to build notification", e);
}
mBitmapDecoderTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
try {
mVideoArtBitmap = Utils.scaleAndCenterCropBitmap(bitmap, mDimensionInPixels, mDimensionInPixels);
build(info, mVideoArtBitmap, mIsPlaying);
} catch (CastException | NoConnectionException | TransientNetworkDisconnectionException e) {
LOGE(TAG, "Failed to set notification for " + info.toString(), e);
}
if (mVisible && (mNotification != null)) {
startForeground(NOTIFICATION_ID, mNotification);
}
if (this == mBitmapDecoderTask) {
mBitmapDecoderTask = null;
}
}
};
mBitmapDecoderTask.execute(imgUri);
}
Aggregations