Example usage for android.graphics BitmapFactory decodeResource

List of usage examples for android.graphics BitmapFactory decodeResource

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeResource.

Prototype

public static Bitmap decodeResource(Resources res, int id) 

Source Link

Document

Synonym for #decodeResource(Resources,int,android.graphics.BitmapFactory.Options) with null Options.

Usage

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static void sendTestNotification(Context context) {

    if (!TEST_NOTIFICATION) {
        return;//  w w  w.j  av  a2  s . c  o m
    }

    AppSettings settings = AppSettings.getInstance(context);

    SharedPreferences sharedPrefs = context.getSharedPreferences(
            "com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    Intent markRead = new Intent(context, MarkReadService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    String shortText = "Test Talon";
    String longText = "Here is a test for Talon's notifications";

    Intent resultIntent = new Intent(context, RedirectToMentions.class);

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    NotificationCompat.Builder mBuilder;

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    mBuilder = new NotificationCompat.Builder(context).setContentTitle(shortText).setContentText(longText)
            .setSmallIcon(R.drawable.ic_stat_icon)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            .setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(shortText)
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    // Pebble notification
    if (sharedPrefs.getBoolean("pebble_notification", false)) {
        sendAlertToPebble(context, shortText, shortText);
    }

    // Light Flow notification
    sendToLightFlow(context, shortText, shortText);

    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            e.printStackTrace();
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

    Intent reply = new Intent(context, NotificationCompose.class);
    MentionsDataSource data = MentionsDataSource.getInstance(context);
    PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + "lukeklinker" + " ")
            .build();

    // Create the notification action
    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply),
            replyPending).addRemoteInput(remoteInput).build();

    NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
            R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending);

    mBuilder.addAction(replyAction);
    mBuilder.addAction(action.build());

    // Build the notification and issues it with notification manager.
    notificationManager.notify(1, mBuilder.build());

    // if we want to wake the screen on a new message
    if (settings.wakeScreen) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
        wakeLock.acquire(5000);
    }
}

From source file:com.av.remusic.service.MediaService.java

private Notification getNotification() {
    RemoteViews remoteViews;/*w w  w  .  ja  va 2 s. c  o  m*/
    final int PAUSE_FLAG = 0x1;
    final int NEXT_FLAG = 0x2;
    final int STOP_FLAG = 0x3;
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();

    remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification);
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;
    remoteViews.setTextViewText(R.id.title, getTrackName());
    remoteViews.setTextViewText(R.id.text, text);

    //action?  ?flag??
    Intent pauseIntent = new Intent(TOGGLEPAUSE_ACTION);
    pauseIntent.putExtra("FLAG", PAUSE_FLAG);
    PendingIntent pausePIntent = PendingIntent.getBroadcast(this, 0, pauseIntent, 0);
    remoteViews.setImageViewResource(R.id.iv_pause,
            isPlaying ? R.drawable.note_btn_pause : R.drawable.note_btn_play);
    remoteViews.setOnClickPendingIntent(R.id.iv_pause, pausePIntent);

    Intent nextIntent = new Intent(NEXT_ACTION);
    nextIntent.putExtra("FLAG", NEXT_FLAG);
    PendingIntent nextPIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.iv_next, nextPIntent);

    Intent preIntent = new Intent(STOP_ACTION);
    preIntent.putExtra("FLAG", STOP_FLAG);
    PendingIntent prePIntent = PendingIntent.getBroadcast(this, 0, preIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.iv_stop, prePIntent);

    //        PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0,
    //                new Intent(this.getApplicationContext(), PlayingActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    final Intent nowPlayingIntent = new Intent();
    //nowPlayingIntent.setAction("com.av.remusic.LAUNCH_NOW_PLAYING_ACTION");
    nowPlayingIntent
            .setComponent(new ComponentName("com.av.remusic", "com.av.remusic.activity.PlayingActivity"));
    nowPlayingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent clickIntent = PendingIntent.getBroadcast(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent click = PendingIntent.getActivity(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Bitmap bitmap = ImageUtils.getArtworkQuick(this, getAlbumId(), 160, 160);
    if (bitmap != null) {
        remoteViews.setImageViewBitmap(R.id.image, bitmap);
        // remoteViews.setImageViewUri(R.id.image, MusicUtils.getAlbumUri(this, getAudioId()));
        mNoBit = null;

    } else if (!isTrackLocal()) {
        if (mNoBit != null) {
            remoteViews.setImageViewBitmap(R.id.image, mNoBit);
            mNoBit = null;

        } else {
            Uri uri = null;
            if (getAlbumPath() != null) {
                try {
                    uri = Uri.parse(getAlbumPath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (getAlbumPath() == null || uri == null) {
                mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
                updateNotification();
            } else {
                ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri)
                        .setProgressiveRenderingEnabled(true).build();
                ImagePipeline imagePipeline = Fresco.getImagePipeline();
                DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline
                        .fetchDecodedImage(imageRequest, MediaService.this);

                dataSource.subscribe(new BaseBitmapDataSubscriber() {

                    @Override
                    public void onNewResultImpl(@Nullable Bitmap bitmap) {
                        // You can use the bitmap in only limited ways
                        // No need to do any cleanup.
                        if (bitmap != null) {
                            mNoBit = bitmap;
                        }
                        updateNotification();
                    }

                    @Override
                    public void onFailureImpl(DataSource dataSource) {
                        // No cleanup required here.
                        mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
                        updateNotification();
                    }
                }, CallerThreadExecutor.getInstance());
            }
        }

    } else {
        remoteViews.setImageViewResource(R.id.image, R.drawable.placeholder_disk_210);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }
    if (mNotification == null) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(remoteViews)
                .setSmallIcon(R.drawable.ic_notification).setContentIntent(click)
                .setWhen(mNotificationPostTime);
        if (CommonUtils.isJellyBeanMR1()) {
            builder.setShowWhen(false);
        }
        mNotification = builder.build();
    } else {
        mNotification.contentView = remoteViews;
    }

    return mNotification;
}

From source file:com.cloud9.netmusic.service.MediaService.java

private Notification getNotification() {
    RemoteViews remoteViews;/*from  ww w .j a va  2  s  .  c om*/
    final int PAUSE_FLAG = 0x1;
    final int NEXT_FLAG = 0x2;
    final int STOP_FLAG = 0x3;
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();

    remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification);
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;
    remoteViews.setTextViewText(R.id.title, getTrackName());
    remoteViews.setTextViewText(R.id.text, text);

    //action?  ?flag??
    Intent pauseIntent = new Intent(TOGGLEPAUSE_ACTION);
    pauseIntent.putExtra("FLAG", PAUSE_FLAG);
    PendingIntent pausePIntent = PendingIntent.getBroadcast(this, 0, pauseIntent, 0);
    remoteViews.setImageViewResource(R.id.iv_pause,
            isPlaying ? R.drawable.note_btn_pause : R.drawable.note_btn_play);
    remoteViews.setOnClickPendingIntent(R.id.iv_pause, pausePIntent);

    Intent nextIntent = new Intent(NEXT_ACTION);
    nextIntent.putExtra("FLAG", NEXT_FLAG);
    PendingIntent nextPIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.iv_next, nextPIntent);

    Intent preIntent = new Intent(STOP_ACTION);
    preIntent.putExtra("FLAG", STOP_FLAG);
    PendingIntent prePIntent = PendingIntent.getBroadcast(this, 0, preIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.iv_stop, prePIntent);

    //        PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0,
    //                new Intent(this.getApplicationContext(), PlayingActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    final Intent nowPlayingIntent = new Intent();
    //nowPlayingIntent.setAction("com.cloud9.netmusic.LAUNCH_NOW_PLAYING_ACTION");
    nowPlayingIntent.setComponent(new ComponentName("com.wm.remusic", "PlayingActivity"));
    nowPlayingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent clickIntent = PendingIntent.getBroadcast(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent click = PendingIntent.getActivity(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Bitmap bitmap = ImageUtils.getArtworkQuick(this, getAlbumId(), 160, 160);
    if (bitmap != null) {
        remoteViews.setImageViewBitmap(R.id.image, bitmap);
        // remoteViews.setImageViewUri(R.id.image, MusicUtils.getAlbumUri(this, getAudioId()));
        mNoBit = null;

    } else if (!isTrackLocal()) {
        if (mNoBit != null) {
            remoteViews.setImageViewBitmap(R.id.image, mNoBit);
            mNoBit = null;

        } else {
            Uri uri = null;
            if (getAlbumPath() != null) {
                try {
                    uri = Uri.parse(getAlbumPath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (getAlbumPath() == null || uri == null) {
                mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
                updateNotification();
            } else {
                ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri)
                        .setProgressiveRenderingEnabled(true).build();
                ImagePipeline imagePipeline = Fresco.getImagePipeline();
                DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline
                        .fetchDecodedImage(imageRequest, MediaService.this);

                dataSource.subscribe(new BaseBitmapDataSubscriber() {

                    @Override
                    public void onNewResultImpl(@Nullable Bitmap bitmap) {
                        // You can use the bitmap in only limited ways
                        // No need to do any cleanup.
                        if (bitmap != null) {
                            mNoBit = bitmap;
                        }
                        updateNotification();
                    }

                    @Override
                    public void onFailureImpl(DataSource dataSource) {
                        // No cleanup required here.
                        mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
                        updateNotification();
                    }
                }, CallerThreadExecutor.getInstance());
            }
        }

    } else {
        remoteViews.setImageViewResource(R.id.image, R.drawable.placeholder_disk_210);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }
    if (mNotification == null) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(remoteViews)
                .setSmallIcon(R.drawable.ic_notification).setContentIntent(click)
                .setWhen(mNotificationPostTime);
        if (CommonUtils.isJellyBeanMR1()) {
            builder.setShowWhen(false);
        }
        mNotification = builder.build();
    } else {
        mNotification.contentView = remoteViews;
    }

    return mNotification;
}

From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java

private Bitmap makeSnapshot() {

    contentRelative.setDrawingCacheEnabled(true);
    contentRelative.buildDrawingCache();
    Bitmap bm = contentRelative.getDrawingCache();

    int width = bm.getWidth();
    int height = bm.getHeight();

    Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.histogram_bg);
    Bitmap logo = BitmapFactory.decodeResource(getResources(), R.drawable.manhoodlogo);

    Bitmap cs = null;/*  w w w. j a v a 2  s. co  m*/

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas comboImage = new Canvas(cs);

    Rect src = new Rect(0, 0, background.getWidth() - 1, background.getHeight() - 1);
    Rect dest = new Rect(0, 0, width - 1, height - 1);
    comboImage.drawBitmap(background, src, dest, null);
    comboImage.drawBitmap(bm, 0f, 0f, null);
    comboImage.drawBitmap(logo, 7.0f, height - logo.getHeight() - 4.0f, null);

    return cs;
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
  * Reuse of bitmaps in tiled backgrounds is a known cause of problems:
  *      http://stackoverflow.com/questions/4077487/background-image-not-repeating-in-android-layout
 * So we avoid reusing them.// ww w.  java2 s  .  co m
 * 
 * This seems to have become further messed up in 4.1 so now, we just created them manually. No references,
 * but the old cleanup method (see below for cleanupTiledBackground()) no longer works. Since it effectively
 * un-cached the background, we just create it here.
 * 
 * The main problem with this approach is that the style is defined in code rather than XML.
 *
 * @param a         Activity context
 * @param bright   Flag indicating if background should be 'bright'
 * 
 * @return         Background Drawable
 */
public static Drawable makeTiledBackground(boolean bright) {
    // Storage for the layers
    Drawable[] drawables = new Drawable[2];
    // Get the BG image, put in tiled drawable
    Bitmap b = BitmapFactory.decodeResource(BookCatalogueApp.context.getResources(), R.drawable.books_bg);
    BitmapDrawable bmD = new BitmapDrawable(BookCatalogueApp.context.getResources(), b);
    bmD.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
    // Add to layers
    drawables[0] = bmD;

    // Set up the gradient colours based on 'bright' setting
    int[] colours = new int[3];
    if (bright) {
        colours[0] = Color.argb(224, 0, 0, 0);
        colours[1] = Color.argb(208, 0, 0, 0);
        colours[2] = Color.argb(48, 0, 0, 0);
    } else {
        colours[0] = Color.argb(255, 0, 0, 0);
        colours[1] = Color.argb(208, 0, 0, 0);
        colours[2] = Color.argb(160, 0, 0, 0);
    }

    // Create a gradient and add to layers
    GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colours);
    drawables[1] = gd;

    // Make the layers and we are done.
    LayerDrawable ll = new LayerDrawable(drawables);
    ll.setDither(true);

    return ll;
}

From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuService.java

/**
 * Creates or updates the notification in the Notification Manager. Sends broadcast with given progress or error state to the activity.
 * /*from   ww  w  . ja  va2 s .co  m*/
 * @param progress
 *            the current progress state or an error number, can be one of {@link #PROGRESS_CONNECTING}, {@link #PROGRESS_STARTING}, {@link #PROGRESS_VALIDATING}, {@link #PROGRESS_DISCONNECTING},
 *            {@link #PROGRESS_COMPLETED} or {@link #ERROR_FILE_CLOSED}, {@link #ERROR_FILE_INVALID} , etc
 */
private void updateProgressNotification(final int progress) {
    final String deviceAddress = mDeviceAddress;
    final String deviceName = mDeviceName != null ? mDeviceName : getString(R.string.dfu_unknown_name);

    final Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.stat_dfu);

    final Notification.Builder builder = new Notification.Builder(this)
            .setSmallIcon(android.R.drawable.stat_sys_upload).setOnlyAlertOnce(true).setLargeIcon(largeIcon);
    switch (progress) {
    case PROGRESS_CONNECTING:
        builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_connecting))
                .setContentText(getString(R.string.dfu_status_connecting_msg, deviceName))
                .setProgress(100, 0, true);
        break;
    case PROGRESS_STARTING:
        builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_starting))
                .setContentText(getString(R.string.dfu_status_starting_msg, deviceName))
                .setProgress(100, 0, true);
        break;
    case PROGRESS_VALIDATING:
        builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_validating))
                .setContentText(getString(R.string.dfu_status_validating_msg, deviceName))
                .setProgress(100, 0, true);
        break;
    case PROGRESS_DISCONNECTING:
        builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_disconnecting))
                .setContentText(getString(R.string.dfu_status_disconnecting_msg, deviceName))
                .setProgress(100, 0, true);
        break;
    case PROGRESS_COMPLETED:
        builder.setOngoing(false).setContentTitle(getString(R.string.dfu_status_completed))
                .setContentText(getString(R.string.dfu_status_completed_msg)).setAutoCancel(true);
        break;
    case PROGRESS_ABORTED:
        builder.setOngoing(false).setContentTitle(getString(R.string.dfu_status_abored))
                .setContentText(getString(R.string.dfu_status_aborted_msg)).setAutoCancel(true);
        break;
    default:
        if (progress >= ERROR_MASK) {
            // progress is an error number
            builder.setOngoing(false).setContentTitle(getString(R.string.dfu_status_error))
                    .setContentText(getString(R.string.dfu_status_error_msg)).setAutoCancel(true);
        } else {
            // progress is in percents
            builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_uploading))
                    .setContentText(getString(R.string.dfu_status_uploading_msg, deviceName))
                    .setProgress(100, progress, false);
        }
    }
    // send progress or error broadcast
    if (progress < ERROR_MASK)
        sendProgressBroadcast(progress);
    else
        sendErrorBroadcast(progress);

    // We cannot set two activities at once (using PendingIntent.getActivities(...)) because we have to start the BluetoothLeService first. Service is created in DeviceListActivity.
    // When creating activities the parent Activity is not created, it's just inserted to the history stack.
    final Intent intent = new Intent(this, NotificationActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(DfuActivity.EXTRA_DEVICE_ADDRESS, deviceAddress);
    intent.putExtra(DfuActivity.EXTRA_DEVICE_NAME, deviceName);
    intent.putExtra(DfuActivity.EXTRA_PROGRESS, progress); // this may contains ERROR_CONNECTION_MASK bit!
    if (mLogSession != null)
        intent.putExtra(DfuActivity.EXTRA_LOG_URI, mLogSession.getSessionUri());
    final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(NOTIFICATION_ID, builder.build());
}

From source file:com.firefly.sample.castcompanionlibrary.cast.VideoCastManager.java

private Bitmap getBitmapForLockScreen(MediaInfo video) {
    if (null == video) {
        return null;
    }//w w w.j  a  va2s  . c  o  m
    URL imgUrl = null;
    Bitmap bm = null;
    List<WebImage> images = video.getMetadata().getImages();
    try {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
            if (images.size() > 1) {
                imgUrl = new URL(images.get(1).getUrl().toString());
            } else if (images.size() == 1) {
                imgUrl = new URL(images.get(0).getUrl().toString());
            } else if (null != mContext) {
                // we don't have a url for image so get a placeholder image from resources
                bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.dummy_album_art_large);
            }
        } else if (!images.isEmpty()) {
            imgUrl = new URL(images.get(0).getUrl().toString());
        } else {
            // we don't have a url for image so get a placeholder image from resources
            bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.dummy_album_art_small);
        }
    } catch (MalformedURLException e) {
        LOGE(TAG, "Failed to get the url for images", e);
    }

    if (null != imgUrl) {
        try {
            bm = BitmapFactory.decodeStream(imgUrl.openStream());
        } catch (IOException e) {
            LOGE(TAG, "Failed to decoded a bitmap for url: " + imgUrl, e);
        }
    }

    return bm;
}

From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java

public void setonehourglass(final ImageView iv) {

    int resourceint = R.drawable.hourglassicon;
    Bitmap resourcebm = BitmapFactory.decodeResource(getResources(), resourceint);
    iv.setImageResource(resourceint);/*from ww w  .j  a  va  2 s. co  m*/
    iv.setClickable(false);
    iv.addOnLayoutChangeListener(hourglasslistener);

}

From source file:com.google.sample.castcompanionlibrary.cast.VideoCastManager.java

private void setBitmapForLockScreen(MediaInfo video) {
    if (null == video || mRemoteControlClientCompat == null) {
        return;/* w  w  w. j a  v a  2s .c om*/
    }
    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 (null != mContext) {
            // we don't have a url for image so get a placeholder image from resources
            bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.dummy_album_art_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.dummy_album_art_small);
    }
    if (null != bm) {
        mRemoteControlClientCompat.editMetadata(false)
                .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, bm).apply();
    } else {

        new FetchBitmapTask() {
            @Override
            protected void onPostExecute(Bitmap bitmap) {
                mRemoteControlClientCompat.editMetadata(false)
                        .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, bitmap)
                        .apply();
            }
        }.start(imgUrl);
    }
}

From source file:com.dycody.android.idealnote.DetailFragment.java

private void replacePlayingAudioBitmap(View v) {
    Drawable d = ((ImageView) v.findViewById(R.id.gridview_item_picture)).getDrawable();
    if (BitmapDrawable.class.isAssignableFrom(d.getClass())) {
        recordingBitmap = ((BitmapDrawable) d).getBitmap();
    } else {/*from w  ww  .  j av  a 2 s.  com*/
        recordingBitmap = ((GlideBitmapDrawable) d.getCurrent()).getBitmap();
    }
    ((ImageView) v.findViewById(R.id.gridview_item_picture)).setImageBitmap(ThumbnailUtils.extractThumbnail(
            BitmapFactory.decodeResource(mainActivity.getResources(), R.drawable.stop),
            Constants.THUMBNAIL_SIZE, Constants.THUMBNAIL_SIZE));
}