use of android.support.v4.app.TaskStackBuilder in project zype-android by zype.
the class VideoCastNotificationService method build.
/*
* Build the RemoteViews for the notification. We also need to add the appropriate "back stack"
* so when user goes into the CastPlayerActivity, she can have a meaningful "back" experience.
*/
private void build(MediaInfo info, Bitmap bitmap, boolean isPlaying) throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
// Playback PendingIntent
Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK);
playbackIntent.setPackage(getPackageName());
PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0);
// Disconnect PendingIntent
Intent stopIntent = new Intent(ACTION_STOP);
stopIntent.setPackage(getPackageName());
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);
// Main Content PendingIntent
Bundle mediaWrapper = Utils.mediaInfoToBundle(mCastManager.getRemoteMediaInformation());
Intent contentIntent = new Intent(this, mTargetActivity);
contentIntent.putExtra("media", mediaWrapper);
// Media metadata
MediaMetadata metadata = info.getMetadata();
String castingTo = getResources().getString(R.string.ccl_casting_to_device, mCastManager.getDeviceName());
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(mTargetActivity);
stackBuilder.addNextIntent(contentIntent);
if (stackBuilder.getIntentCount() > 1) {
stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
}
PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT);
int pauseOrStopResourceId = 0;
if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) {
pauseOrStopResourceId = R.drawable.ic_notification_stop_48dp;
} else {
pauseOrStopResourceId = R.drawable.ic_notification_pause_48dp;
}
int pauseOrPlayTextResourceId = isPlaying ? R.string.ccl_pause : R.string.ccl_play;
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification).setContentTitle(metadata.getString(MediaMetadata.KEY_TITLE)).setContentText(castingTo).setContentIntent(contentPendingIntent).setLargeIcon(bitmap).addAction(isPlaying ? pauseOrStopResourceId : R.drawable.ic_notification_play_48dp, getString(pauseOrPlayTextResourceId), playbackPendingIntent).addAction(R.drawable.ic_notification_disconnect_24dp, getString(R.string.ccl_disconnect), stopPendingIntent).setStyle(new NotificationCompat.MediaStyle().setShowActionsInCompactView(0, 1).setMediaSession(mCastManager.getMediaSessionCompatToken())).setOngoing(true).setShowWhen(false).setVisibility(Notification.VISIBILITY_PUBLIC);
mNotification = builder.build();
}
use of android.support.v4.app.TaskStackBuilder in project Shuttle by timusus.
the class VideoCastNotificationService method getContentIntent.
/**
* Returns the {@link PendingIntent} for showing the full screen cast controller page. We also
* build an appropriate "back stack" so that when user is sent to that full screen controller,
* clicking on the Back button would allow navigation into the app.
*/
protected PendingIntent getContentIntent(MediaInfo mediaInfo) {
Bundle mediaWrapper = Utils.mediaInfoToBundle(mediaInfo);
Intent contentIntent = new Intent(this, mTargetActivity);
contentIntent.putExtra(VideoCastManager.EXTRA_MEDIA, mediaWrapper);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(mTargetActivity);
stackBuilder.addNextIntent(contentIntent);
if (stackBuilder.getIntentCount() > 1) {
stackBuilder.editIntentAt(1).putExtra(VideoCastManager.EXTRA_MEDIA, mediaWrapper);
}
return stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT);
}
Aggregations