Search in sources :

Example 41 with TaskStackBuilder

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();
}
Also used : Bundle(android.os.Bundle) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) MediaMetadata(com.google.android.gms.cast.MediaMetadata) NotificationCompat(android.support.v7.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder)

Example 42 with TaskStackBuilder

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);
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder)

Aggregations

Intent (android.content.Intent)40 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)40 PendingIntent (android.app.PendingIntent)35 NotificationCompat (android.support.v4.app.NotificationCompat)21 NotificationManager (android.app.NotificationManager)14 Bitmap (android.graphics.Bitmap)13 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 URL (java.net.URL)8 Notification (android.app.Notification)7 Context (android.content.Context)5 Uri (android.net.Uri)5 SharedPreferences (android.content.SharedPreferences)3 Resources (android.content.res.Resources)3 Cursor (android.database.Cursor)3 Bundle (android.os.Bundle)3 RemoteViews (android.widget.RemoteViews)3 TaskStackBuilder (android.app.TaskStackBuilder)2 ContentResolver (android.content.ContentResolver)2 NonNull (android.support.annotation.NonNull)2