Example usage for android.widget RemoteViews setImageViewBitmap

List of usage examples for android.widget RemoteViews setImageViewBitmap

Introduction

In this page you can find the example usage for android.widget RemoteViews setImageViewBitmap.

Prototype

public void setImageViewBitmap(int viewId, Bitmap bitmap) 

Source Link

Document

Equivalent to calling ImageView#setImageBitmap(Bitmap)

Usage

From source file:net.sourceforge.servestream.service.MediaPlaybackService.java

private void setupContentView(RemoteViews rv, boolean updateNotification) {
    String contentText;/*from  w  w  w  .  j a va 2s  .c  o  m*/

    String trackName = getTrackName();
    if (trackName == null || trackName.equals(Media.UNKNOWN_STRING)) {
        trackName = getMediaUri();
    }

    String artist = getArtistName();
    if (artist == null || artist.equals(Media.UNKNOWN_STRING)) {
        artist = getString(R.string.unknown_artist_name);
    }

    String album = getAlbumName();
    if (album == null || album.equals(Media.UNKNOWN_STRING)) {
        contentText = getString(R.string.notification_alt_info, artist);
    } else {
        contentText = getString(R.string.notification_artist_album, artist, album);
    }

    if (updateNotification) {
        if (isPlaying()) {
            rv.setImageViewResource(R.id.play_pause, android.R.drawable.ic_media_pause);
        } else {
            rv.setImageViewResource(R.id.play_pause, android.R.drawable.ic_media_play);
        }
    } else {
        rv.setImageViewResource(R.id.play_pause, android.R.drawable.ic_media_pause);
    }

    int trackId = getTrackId();
    if (mPreferences.getBoolean(PreferenceConstants.RETRIEVE_ALBUM_ART, false) && trackId != -1) {
        Bitmap bitmap = getAlbumArt(true);
        if (bitmap != null) {
            rv.setImageViewBitmap(R.id.coverart, bitmap);
        }
    }

    // set the text for the notifications
    rv.setTextViewText(R.id.title, trackName);
    rv.setTextViewText(R.id.subtitle, contentText);

    rv.setOnClickPendingIntent(R.id.play_pause, createPendingIntent(2, CMDTOGGLEPAUSE));
    rv.setOnClickPendingIntent(R.id.next, createPendingIntent(3, CMDNEXT));
    rv.setOnClickPendingIntent(R.id.close, createPendingIntent(4, CMDSTOP));
}

From source file:org.xbmc.kore.service.NotificationObserver.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void buildNotification(PlayerType.GetActivePlayersReturnType getActivePlayerResult,
        PlayerType.PropertyValue getPropertiesResult, ListType.ItemsAll getItemResult) {
    final String title, underTitle, poster;
    int smallIcon, playPauseIcon, rewindIcon, ffIcon;

    boolean isVideo = ((getItemResult.type.equals(ListType.ItemsAll.TYPE_MOVIE))
            || (getItemResult.type.equals(ListType.ItemsAll.TYPE_EPISODE)));

    switch (getItemResult.type) {
    case ListType.ItemsAll.TYPE_MOVIE:
        title = getItemResult.title;//from  www .  jav a2 s. c o  m
        underTitle = getItemResult.tagline;
        poster = getItemResult.thumbnail;
        smallIcon = R.drawable.ic_movie_white_24dp;
        break;
    case ListType.ItemsAll.TYPE_EPISODE:
        title = getItemResult.title;
        String seasonEpisode = String.format(mContext.getString(R.string.season_episode_abbrev),
                getItemResult.season, getItemResult.episode);
        underTitle = String.format("%s | %s", getItemResult.showtitle, seasonEpisode);
        poster = getItemResult.art.poster;
        smallIcon = R.drawable.ic_tv_white_24dp;
        break;
    case ListType.ItemsAll.TYPE_SONG:
        title = getItemResult.title;
        underTitle = getItemResult.displayartist + " | " + getItemResult.album;
        poster = getItemResult.thumbnail;
        smallIcon = R.drawable.ic_headset_white_24dp;
        break;
    case ListType.ItemsAll.TYPE_MUSIC_VIDEO:
        title = getItemResult.title;
        underTitle = Utils.listStringConcat(getItemResult.artist, ", ") + " | " + getItemResult.album;
        poster = getItemResult.thumbnail;
        smallIcon = R.drawable.ic_headset_white_24dp;
        break;
    default:
        // We don't know what this is, forget it
        return;
    }

    switch (getPropertiesResult.speed) {
    case 1:
        playPauseIcon = R.drawable.ic_pause_white_24dp;
        break;
    default:
        playPauseIcon = R.drawable.ic_play_arrow_white_24dp;
        break;
    }

    // Create the actions, depending on the type of media
    PendingIntent rewindPendingItent, ffPendingItent, playPausePendingIntent;
    playPausePendingIntent = buildActionPendingIntent(getActivePlayerResult.playerid,
            IntentActionsService.ACTION_PLAY_PAUSE);
    if (getItemResult.type.equals(ListType.ItemsAll.TYPE_SONG)) {
        rewindPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_PREVIOUS);
        rewindIcon = R.drawable.ic_skip_previous_white_24dp;
        ffPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_NEXT);
        ffIcon = R.drawable.ic_skip_next_white_24dp;
    } else {
        rewindPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_REWIND);
        rewindIcon = R.drawable.ic_fast_rewind_white_24dp;
        ffPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_FAST_FORWARD);
        ffIcon = R.drawable.ic_fast_forward_white_24dp;
    }

    // Setup the collpased and expanded notifications
    final RemoteViews collapsedRV = new RemoteViews(mContext.getPackageName(), R.layout.notification_colapsed);
    collapsedRV.setImageViewResource(R.id.rewind, rewindIcon);
    collapsedRV.setOnClickPendingIntent(R.id.rewind, rewindPendingItent);
    collapsedRV.setImageViewResource(R.id.play, playPauseIcon);
    collapsedRV.setOnClickPendingIntent(R.id.play, playPausePendingIntent);
    collapsedRV.setImageViewResource(R.id.fast_forward, ffIcon);
    collapsedRV.setOnClickPendingIntent(R.id.fast_forward, ffPendingItent);
    collapsedRV.setTextViewText(R.id.title, title);
    collapsedRV.setTextViewText(R.id.text2, underTitle);

    final RemoteViews expandedRV = new RemoteViews(mContext.getPackageName(), R.layout.notification_expanded);
    expandedRV.setImageViewResource(R.id.rewind, rewindIcon);
    expandedRV.setOnClickPendingIntent(R.id.rewind, rewindPendingItent);
    expandedRV.setImageViewResource(R.id.play, playPauseIcon);
    expandedRV.setOnClickPendingIntent(R.id.play, playPausePendingIntent);
    expandedRV.setImageViewResource(R.id.fast_forward, ffIcon);
    expandedRV.setOnClickPendingIntent(R.id.fast_forward, ffPendingItent);
    expandedRV.setTextViewText(R.id.title, title);
    expandedRV.setTextViewText(R.id.text2, underTitle);
    final int expandedIconResId;
    if (isVideo) {
        expandedIconResId = R.id.icon_slim;
        expandedRV.setViewVisibility(R.id.icon_slim, View.VISIBLE);
        expandedRV.setViewVisibility(R.id.icon_square, View.GONE);
    } else {
        expandedIconResId = R.id.icon_square;
        expandedRV.setViewVisibility(R.id.icon_slim, View.GONE);
        expandedRV.setViewVisibility(R.id.icon_square, View.VISIBLE);
    }

    // Build the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    final Notification notification = builder.setSmallIcon(smallIcon).setShowWhen(false).setOngoing(true)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setCategory(NotificationCompat.CATEGORY_TRANSPORT).setContentIntent(mRemoteStartPendingIntent)
            .setContent(collapsedRV).build();

    // This is a convoluted way of loading the image and showing the
    // notification, but it's what works with Picasso and is efficient.
    // Here's what's going on:
    //
    // 1. The image is loaded asynchronously into a Target, and only after
    // it is loaded is the notification shown. Using targets is a lot more
    // efficient than letting Picasso load it directly into the
    // notification imageview, which causes a lot of flickering
    //
    // 2. The target needs to be static, because Picasso only keeps a weak
    // reference to it, so we need to keed a strong reference and reset it
    // to null when we're done. We also need to check if it is not null in
    // case a previous request hasn't finished yet.
    //
    // 3. We can only show the notification after the bitmap is loaded into
    // the target, so it is done in the callback
    //
    // 4. We specifically resize the image to the same dimensions used in
    // the remote, so that Picasso reuses it in the remote and here from the cache
    Resources resources = mContext.getResources();
    final int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width);
    final int posterHeight = isVideo ? resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height)
            : posterWidth;
    if (picassoTarget == null) {
        picassoTarget = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                showNotification(bitmap);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
                CharacterDrawable avatarDrawable = UIUtils.getCharacterAvatar(mContext, title);
                showNotification(Utils.drawableToBitmap(avatarDrawable, posterWidth, posterHeight));
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            }

            private void showNotification(Bitmap bitmap) {
                collapsedRV.setImageViewBitmap(R.id.icon, bitmap);
                if (Utils.isJellybeanOrLater()) {
                    notification.bigContentView = expandedRV;
                    expandedRV.setImageViewBitmap(expandedIconResId, bitmap);
                }

                NotificationManager notificationManager = (NotificationManager) mContext
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.notify(NOTIFICATION_ID, notification);
                picassoTarget = null;
            }
        };

        // Load the image
        HostManager hostManager = HostManager.getInstance(mContext);
        hostManager.getPicasso().load(hostManager.getHostInfo().getImageUrl(poster))
                .resize(posterWidth, posterHeight).into(picassoTarget);
    }
}

From source file:com.massivcode.androidmusicplayer.services.MusicService.java

private void showNotificationUnderLollipop() {
    Notification.Builder builder = new Notification.Builder(this);
    RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification);

    // ? ? ?   /*from ww  w  .  j  ava2 s.  c o  m*/
    // =========================================================================================

    Intent musicPreviousIntent = new Intent(getApplicationContext(), MusicService.class);
    musicPreviousIntent.setAction(ACTION_PLAY_PREVIOUS);
    musicPreviousIntent.putExtra("position", getPositionAtPreviousOrNext(ACTION_PLAY_PREVIOUS));

    PendingIntent musicPreviousPendingIntent = PendingIntent.getService(getApplicationContext(), 0,
            musicPreviousIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.noti_previous_ib, musicPreviousPendingIntent);
    // =========================================================================================

    // ? ? ?   
    // =========================================================================================
    Intent musicStopIntent = new Intent(getApplicationContext(), MusicService.class);
    musicStopIntent.setAction(ACTION_PAUSE);

    PendingIntent musicStopPendingIntent = PendingIntent.getService(getApplicationContext(), 1, musicStopIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.noti_play_ib, musicStopPendingIntent);
    // =========================================================================================

    // ? ? ?   
    // =========================================================================================
    Intent musicNextIntent = new Intent(getApplicationContext(), MusicService.class);
    musicNextIntent.setAction(ACTION_PLAY_NEXT);
    musicNextIntent.putExtra("position", getPositionAtPreviousOrNext(ACTION_PLAY_NEXT));

    PendingIntent musicNextPendingIntent = PendingIntent.getService(getApplicationContext(), 2, musicNextIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.noti_next_ib, musicNextPendingIntent);
    // =========================================================================================

    //  ? ?   
    // =========================================================================================
    Intent closeIntent = new Intent(getApplicationContext(), MusicService.class);
    closeIntent.setAction(ACTION_FINISH);

    PendingIntent closePendingIntent = PendingIntent.getService(getApplicationContext(), 3, closeIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.noti_close_ib, closePendingIntent);
    // =========================================================================================

    // Notification  ?   PendingIntent 
    // =========================================================================================
    Intent activityStartIntent = new Intent(MainActivity.ACTION_NAME);
    activityStartIntent.putExtra("restore", getCurrentInfo());
    PendingIntent activityStartPendingIntent = PendingIntent.getActivity(getApplicationContext(), 1,
            activityStartIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(activityStartPendingIntent);
    // =========================================================================================

    Bitmap bitmap = null;
    if (mCurrentMusicInfo != null) {
        if (mCurrentMusicInfo.getUri() != null) {
            bitmap = MusicInfoLoadUtil.getBitmap(getApplicationContext(), mCurrentMusicInfo.getUri(), 4);
        }
    }
    if (bitmap == null) {
        bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_no_image);
    }

    remoteViews.setImageViewBitmap(R.id.noti_album_art_iv, bitmap);
    if (mCurrentMusicInfo != null) {
        remoteViews.setTextViewText(R.id.noti_artist_tv, mCurrentMusicInfo.getArtist());
        remoteViews.setTextViewText(R.id.noti_title_tv, mCurrentMusicInfo.getTitle());
    }

    builder.setContent(remoteViews);
    builder.setLargeIcon(bitmap);
    builder.setSmallIcon(R.mipmap.ic_no_image);

    if (mMediaPlayer.isPlaying()) {
        remoteViews.setImageViewResource(R.id.noti_play_ib, android.R.drawable.ic_media_pause);
    } else {
        remoteViews.setImageViewResource(R.id.noti_play_ib, android.R.drawable.ic_media_play);
    }

    builder.setAutoCancel(false);

    Notification notification = builder.build();

    startForeground(1, notification);
}

From source file:com.syncedsynapse.kore2.service.NotificationService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void buildNotification(PlayerType.GetActivePlayersReturnType getActivePlayerResult,
        PlayerType.PropertyValue getPropertiesResult, ListType.ItemsAll getItemResult) {
    final String title, underTitle, poster;
    int smallIcon, playPauseIcon, rewindIcon, ffIcon;

    boolean isVideo = ((getItemResult.type.equals(ListType.ItemsAll.TYPE_MOVIE))
            || (getItemResult.type.equals(ListType.ItemsAll.TYPE_EPISODE)));

    switch (getItemResult.type) {
    case ListType.ItemsAll.TYPE_MOVIE:
        title = getItemResult.title;// w  w  w  .  j  av  a2  s. co m
        underTitle = getItemResult.tagline;
        poster = getItemResult.thumbnail;
        smallIcon = R.drawable.ic_movie_white_24dp;
        break;
    case ListType.ItemsAll.TYPE_EPISODE:
        title = getItemResult.title;
        String seasonEpisode = String.format(getString(R.string.season_episode_abbrev), getItemResult.season,
                getItemResult.episode);
        underTitle = String.format("%s | %s", getItemResult.showtitle, seasonEpisode);
        poster = getItemResult.art.poster;
        smallIcon = R.drawable.ic_tv_white_24dp;
        break;
    case ListType.ItemsAll.TYPE_SONG:
        title = getItemResult.title;
        underTitle = getItemResult.displayartist + " | " + getItemResult.album;
        poster = getItemResult.thumbnail;
        smallIcon = R.drawable.ic_headset_white_24dp;
        break;
    case ListType.ItemsAll.TYPE_MUSIC_VIDEO:
        title = getItemResult.title;
        underTitle = Utils.listStringConcat(getItemResult.artist, ", ") + " | " + getItemResult.album;
        poster = getItemResult.thumbnail;
        smallIcon = R.drawable.ic_headset_white_24dp;
        break;
    default:
        // We don't know what this is, forget it
        return;
    }

    switch (getPropertiesResult.speed) {
    case 1:
        playPauseIcon = R.drawable.ic_pause_white_24dp;
        break;
    default:
        playPauseIcon = R.drawable.ic_play_arrow_white_24dp;
        break;
    }

    // Create the actions, depending on the type of media
    PendingIntent rewindPendingItent, ffPendingItent, playPausePendingIntent;
    playPausePendingIntent = buildActionPendingIntent(getActivePlayerResult.playerid,
            IntentActionsService.ACTION_PLAY_PAUSE);
    if (getItemResult.type.equals(ListType.ItemsAll.TYPE_SONG)) {
        rewindPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_PREVIOUS);
        rewindIcon = R.drawable.ic_skip_previous_white_24dp;
        ffPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_NEXT);
        ffIcon = R.drawable.ic_skip_next_white_24dp;
    } else {
        rewindPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_REWIND);
        rewindIcon = R.drawable.ic_fast_rewind_white_24dp;
        ffPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_FAST_FORWARD);
        ffIcon = R.drawable.ic_fast_forward_white_24dp;
    }

    // Setup the collpased and expanded notifications
    final RemoteViews collapsedRV = new RemoteViews(this.getPackageName(), R.layout.notification_colapsed);
    collapsedRV.setImageViewResource(R.id.rewind, rewindIcon);
    collapsedRV.setOnClickPendingIntent(R.id.rewind, rewindPendingItent);
    collapsedRV.setImageViewResource(R.id.play, playPauseIcon);
    collapsedRV.setOnClickPendingIntent(R.id.play, playPausePendingIntent);
    collapsedRV.setImageViewResource(R.id.fast_forward, ffIcon);
    collapsedRV.setOnClickPendingIntent(R.id.fast_forward, ffPendingItent);
    collapsedRV.setTextViewText(R.id.title, title);
    collapsedRV.setTextViewText(R.id.text2, underTitle);

    final RemoteViews expandedRV = new RemoteViews(this.getPackageName(), R.layout.notification_expanded);
    expandedRV.setImageViewResource(R.id.rewind, rewindIcon);
    expandedRV.setOnClickPendingIntent(R.id.rewind, rewindPendingItent);
    expandedRV.setImageViewResource(R.id.play, playPauseIcon);
    expandedRV.setOnClickPendingIntent(R.id.play, playPausePendingIntent);
    expandedRV.setImageViewResource(R.id.fast_forward, ffIcon);
    expandedRV.setOnClickPendingIntent(R.id.fast_forward, ffPendingItent);
    expandedRV.setTextViewText(R.id.title, title);
    expandedRV.setTextViewText(R.id.text2, underTitle);
    final int expandedIconResId;
    if (isVideo) {
        expandedIconResId = R.id.icon_slim;
        expandedRV.setViewVisibility(R.id.icon_slim, View.VISIBLE);
        expandedRV.setViewVisibility(R.id.icon_square, View.GONE);
    } else {
        expandedIconResId = R.id.icon_square;
        expandedRV.setViewVisibility(R.id.icon_slim, View.GONE);
        expandedRV.setViewVisibility(R.id.icon_square, View.VISIBLE);
    }

    // Build the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    final Notification notification = builder.setSmallIcon(smallIcon).setShowWhen(false).setOngoing(true)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setCategory(NotificationCompat.CATEGORY_TRANSPORT).setContentIntent(mRemoteStartPendingIntent)
            .setContent(collapsedRV).build();

    // This is a convoluted way of loading the image and showing the
    // notification, but it's what works with Picasso and is efficient.
    // Here's what's going on:
    //
    // 1. The image is loaded asynchronously into a Target, and only after
    // it is loaded is the notification shown. Using targets is a lot more
    // efficient than letting Picasso load it directly into the
    // notification imageview, which causes a lot of flickering
    //
    // 2. The target needs to be static, because Picasso only keeps a weak
    // reference to it, so we need to keed a strong reference and reset it
    // to null when we're done. We also need to check if it is not null in
    // case a previous request hasn't finished yet.
    //
    // 3. We can only show the notification after the bitmap is loaded into
    // the target, so it is done in the callback
    //
    // 4. We specifically resize the image to the same dimensions used in
    // the remote, so that Picasso reuses it in the remote and here from the cache
    Resources resources = this.getResources();
    final int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width);
    final int posterHeight = isVideo ? resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height)
            : posterWidth;
    if (picassoTarget == null) {
        picassoTarget = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                showNotification(bitmap);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
                CharacterDrawable avatarDrawable = UIUtils.getCharacterAvatar(NotificationService.this, title);
                showNotification(Utils.drawableToBitmap(avatarDrawable, posterWidth, posterHeight));
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            }

            private void showNotification(Bitmap bitmap) {
                collapsedRV.setImageViewBitmap(R.id.icon, bitmap);
                if (Utils.isJellybeanOrLater()) {
                    notification.bigContentView = expandedRV;
                    expandedRV.setImageViewBitmap(expandedIconResId, bitmap);
                }

                NotificationManager notificationManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                notificationManager.notify(NOTIFICATION_ID, notification);
                picassoTarget = null;
            }
        };

        // Load the image
        HostManager hostManager = HostManager.getInstance(this);
        hostManager.getPicasso().load(hostManager.getHostInfo().getImageUrl(poster))
                .resize(posterWidth, posterHeight).into(picassoTarget);
    }
}

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

private Notification getNotification() {
    RemoteViews remoteViews;
    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;//from   w ww  .j a  v  a 2s. co m

    } 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.wm.remusic.service.MediaService.java

private Notification getNotification() {
    RemoteViews remoteViews;
    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.wm.remusic.LAUNCH_NOW_PLAYING_ACTION");
    nowPlayingIntent/*w w w .  j  ava  2s . co m*/
            .setComponent(new ComponentName("com.wm.remusic", "com.wm.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.av.remusic.service.MediaService.java

private Notification getNotification() {
    RemoteViews remoteViews;
    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/*w w  w. j  av a2 s  . co  m*/
            .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:au.com.wallaceit.reddinator.Rservice.java

@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row;
    if (position > data.length()) {
        return null; //  prevent errornous views
    }//from ww  w  .  j  ava 2 s .  com
    // check if its the last view and return loading view instead of normal row
    if (position == data.length()) {
        // build load more item
        //System.out.println("load more getViewAt("+position+") firing");
        RemoteViews loadmorerow = new RemoteViews(mContext.getPackageName(), R.layout.listrowloadmore);
        if (endOfFeed) {
            loadmorerow.setTextViewText(R.id.loadmoretxt, "There's nothing more here");
        } else {
            loadmorerow.setTextViewText(R.id.loadmoretxt, "Load more...");
        }
        loadmorerow.setTextColor(R.id.loadmoretxt, themeColors[0]);
        Intent i = new Intent();
        Bundle extras = new Bundle();
        extras.putString(WidgetProvider.ITEM_ID, "0"); // zero will be an indicator in the onreceive function of widget provider if its not present it forces a reload
        i.putExtras(extras);
        loadmorerow.setOnClickFillInIntent(R.id.listrowloadmore, i);
        return loadmorerow;
    } else {
        // build normal item
        String title = "";
        String url = "";
        String permalink = "";
        String thumbnail = "";
        String domain = "";
        String id = "";
        int score = 0;
        int numcomments = 0;
        boolean nsfw = false;
        try {
            JSONObject tempobj = data.getJSONObject(position).getJSONObject("data");
            title = tempobj.getString("title");
            //userlikes = tempobj.getString("likes");
            domain = tempobj.getString("domain");
            id = tempobj.getString("name");
            url = tempobj.getString("url");
            permalink = tempobj.getString("permalink");
            thumbnail = (String) tempobj.get("thumbnail"); // we have to call get and cast cause its not in quotes
            score = tempobj.getInt("score");
            numcomments = tempobj.getInt("num_comments");
            nsfw = tempobj.getBoolean("over_18");
        } catch (JSONException e) {
            e.printStackTrace();
            // return null; // The view is invalid;
        }
        // create remote view from specified layout
        if (bigThumbs) {
            row = new RemoteViews(mContext.getPackageName(), R.layout.listrowbigthumb);
        } else {
            row = new RemoteViews(mContext.getPackageName(), R.layout.listrow);
        }
        // build view
        row.setTextViewText(R.id.listheading, Html.fromHtml(title).toString());
        row.setFloat(R.id.listheading, "setTextSize", Integer.valueOf(titleFontSize)); // use for compatibility setTextViewTextSize only introduced in API 16
        row.setTextColor(R.id.listheading, themeColors[0]);
        row.setTextViewText(R.id.sourcetxt, domain);
        row.setTextColor(R.id.sourcetxt, themeColors[3]);
        row.setTextColor(R.id.votestxt, themeColors[4]);
        row.setTextColor(R.id.commentstxt, themeColors[4]);
        row.setTextViewText(R.id.votestxt, String.valueOf(score));
        row.setTextViewText(R.id.commentstxt, String.valueOf(numcomments));
        row.setInt(R.id.listdivider, "setBackgroundColor", themeColors[2]);
        row.setViewVisibility(R.id.nsfwflag, nsfw ? TextView.VISIBLE : TextView.GONE);
        // add extras and set click intent
        Intent i = new Intent();
        Bundle extras = new Bundle();
        extras.putString(WidgetProvider.ITEM_ID, id);
        extras.putInt("itemposition", position);
        extras.putString(WidgetProvider.ITEM_URL, url);
        extras.putString(WidgetProvider.ITEM_PERMALINK, permalink);
        i.putExtras(extras);
        row.setOnClickFillInIntent(R.id.listrow, i);
        // load thumbnail if they are enabled for this widget
        if (loadThumbnails) {
            // load big image if preference is set
            if (!thumbnail.equals("")) { // check for thumbnail; self is used to display the thinking logo on the reddit site, we'll just show nothing for now
                if (thumbnail.equals("nsfw") || thumbnail.equals("self") || thumbnail.equals("default")) {
                    int resource = 0;
                    switch (thumbnail) {
                    case "nsfw":
                        resource = R.drawable.nsfw;
                        break;
                    case "default":
                    case "self":
                        resource = R.drawable.self_default;
                        break;
                    }
                    row.setImageViewResource(R.id.thumbnail, resource);
                    row.setViewVisibility(R.id.thumbnail, View.VISIBLE);
                    //System.out.println("Loading default image: "+thumbnail);
                } else {
                    Bitmap bitmap;
                    String fileurl = mContext.getCacheDir() + "/thumbcache-" + appWidgetId + "/" + id + ".png";
                    // check if the image is in cache
                    if (new File(fileurl).exists()) {
                        bitmap = BitmapFactory.decodeFile(fileurl);
                        saveImageToStorage(bitmap, id);
                    } else {
                        // download the image
                        bitmap = loadImage(thumbnail);
                    }
                    if (bitmap != null) {
                        row.setImageViewBitmap(R.id.thumbnail, bitmap);
                        row.setViewVisibility(R.id.thumbnail, View.VISIBLE);
                    } else {
                        // row.setImageViewResource(R.id.thumbnail, android.R.drawable.stat_notify_error); for later
                        row.setViewVisibility(R.id.thumbnail, View.GONE);
                    }
                }
            } else {
                row.setViewVisibility(R.id.thumbnail, View.GONE);
            }
        } else {
            row.setViewVisibility(R.id.thumbnail, View.GONE);
        }
        // hide info bar if options set
        if (hideInf) {
            row.setViewVisibility(R.id.infbox, View.GONE);
        } else {
            row.setViewVisibility(R.id.infbox, View.VISIBLE);
        }
    }
    //System.out.println("getViewAt("+position+");");
    return row;
}

From source file:com.adityarathi.muo.services.AudioPlaybackService.java

/**
 * Builds and returns a fully constructed Notification for devices 
 * on Ice Cream Sandwich (APIs 14 & 15).
 *//*from   w w w  .  j  av  a  2s.c  om*/
private Notification buildICSNotification(SongHelper songHelper) {
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setOngoing(true);
    mNotificationBuilder.setAutoCancel(false);
    mNotificationBuilder.setSmallIcon(R.mipmap.ic_launcher);

    //Open up the player screen when the user taps on the notification.
    Intent launchNowPlayingIntent = new Intent();
    launchNowPlayingIntent.setAction(AudioPlaybackService.LAUNCH_NOW_PLAYING_ACTION);
    PendingIntent launchNowPlayingPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(),
            0, launchNowPlayingIntent, 0);
    mNotificationBuilder.setContentIntent(launchNowPlayingPendingIntent);

    //Grab the notification layout.
    RemoteViews notificationView = new RemoteViews(mContext.getPackageName(),
            R.layout.notification_custom_layout);

    //Initialize the notification layout buttons.
    Intent previousTrackIntent = new Intent();
    previousTrackIntent.setAction(AudioPlaybackService.PREVIOUS_ACTION);
    PendingIntent previousTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            previousTrackIntent, 0);

    Intent playPauseTrackIntent = new Intent();
    playPauseTrackIntent.setAction(AudioPlaybackService.PLAY_PAUSE_ACTION);
    PendingIntent playPauseTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            playPauseTrackIntent, 0);

    Intent nextTrackIntent = new Intent();
    nextTrackIntent.setAction(AudioPlaybackService.NEXT_ACTION);
    PendingIntent nextTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            nextTrackIntent, 0);

    Intent stopServiceIntent = new Intent();
    stopServiceIntent.setAction(AudioPlaybackService.STOP_SERVICE);
    PendingIntent stopServicePendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            stopServiceIntent, 0);

    //Check if audio is playing and set the appropriate play/pause button.
    if (mApp.getService().isPlayingMusic()) {
        notificationView.setImageViewResource(R.id.notification_base_play, R.mipmap.ic_launcher);
    } else {
        notificationView.setImageViewResource(R.id.notification_base_play, R.mipmap.ic_launcher);
    }

    //Set the notification content.    
    notificationView.setTextViewText(R.id.notification_base_line_one, songHelper.getTitle());
    notificationView.setTextViewText(R.id.notification_base_line_two, songHelper.getArtist());

    //Set the states of the next/previous buttons and their pending intents.
    if (mApp.getService().isOnlySongInQueue()) {
        //This is the only song in the queue, so disable the previous/next buttons.
        notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);

    } else if (mApp.getService().isFirstSongInQueue()) {
        //This is the the first song in the queue, so disable the previous button. 
        notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);

    } else if (mApp.getService().isLastSongInQueue()) {
        //This is the last song in the cursor, so disable the next button.    
        notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);

    } else {
        //We're smack dab in the middle of the queue, so keep the previous and next buttons enabled.       
        notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_previous, previousTrackPendingIntent);

    }

    //Set the "Stop Service" pending intent.
    notificationView.setOnClickPendingIntent(R.id.notification_base_collapse, stopServicePendingIntent);

    //Set the album art.
    notificationView.setImageViewBitmap(R.id.notification_base_image, songHelper.getAlbumArt());

    //Attach the shrunken layout to the notification.
    mNotificationBuilder.setContent(notificationView);

    //Build the notification object and set its flags.
    Notification notification = mNotificationBuilder.build();
    notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR
            | Notification.FLAG_ONGOING_EVENT;

    return notification;
}