Example usage for android.support.v4.app TaskStackBuilder getIntentCount

List of usage examples for android.support.v4.app TaskStackBuilder getIntentCount

Introduction

In this page you can find the example usage for android.support.v4.app TaskStackBuilder getIntentCount.

Prototype

public int getIntentCount() 

Source Link

Usage

From source file:com.flowzr.budget.holo.activity.EntityListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_close:
    case android.R.id.home: {
        TaskStackBuilder tsb = TaskStackBuilder.create(this);
        final int intentCount = tsb.getIntentCount();
        if (intentCount > 0) {
            Intent upIntent = tsb.getIntents()[intentCount - 1];
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is not part of the application's task, so create a new task with a synthesized back stack.
                tsb.startActivities();//  w w  w.  java2  s . c  om
                finish();
            } else {
                // This activity is part of the application's task, so simply navigate up to the hierarchical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
        } else {
            onBackPressed();
        }
        return true;
    }

    }
    return super.onOptionsItemSelected(item);
}

From source file:com.flowzr.activity.AboutActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        TaskStackBuilder tsb = TaskStackBuilder.create(this);
        final int intentCount = tsb.getIntentCount();
        if (intentCount > 0) {
            Intent upIntent = tsb.getIntents()[intentCount - 1];
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is not part of the application's task, so create a new task with a synthesized back stack.
                tsb.startActivities();/*from   w  ww.  j a  v a  2 s  .  com*/
                finish();
            } else {
                // This activity is part of the application's task, so simply navigate up to the hierarchical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
        } else {
            onBackPressed();
        }
        return true;
    }

    }
    return super.onOptionsItemSelected(item);
}

From source file:com.flowzr.activity.DateFilterActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_done:
        Intent data = new Intent();
        PeriodType period = periods[spinnerPeriodType.getSelectedItemPosition()];
        data.putExtra(EXTRA_FILTER_PERIOD_TYPE, period.name());
        data.putExtra(EXTRA_FILTER_PERIOD_FROM, cFrom.getTimeInMillis());
        data.putExtra(EXTRA_FILTER_PERIOD_TO, cTo.getTimeInMillis());
        setResult(RESULT_OK, data);/*  ww w. ja va  2s .co m*/
        finish();
        return true;
    case R.id.action_cancel:
        setResult(RESULT_CANCELED);
        finish();
        return true;
    case android.R.id.home: {
        TaskStackBuilder tsb = TaskStackBuilder.create(this);
        final int intentCount = tsb.getIntentCount();
        if (intentCount > 0) {
            Intent upIntent = tsb.getIntents()[intentCount - 1];
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is not part of the application's task, so create a new task with a synthesized back stack.
                tsb.startActivities();
                finish();
            } else {
                // This activity is part of the application's task, so simply navigate up to the hierarchical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
        } else {
            onBackPressed();
        }
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:androidx.navigation.NavDeepLinkBuilder.java

/**
 * Construct the full {@link TaskStackBuilder task stack} needed to deep link to the given
 * destination./*from w  w w  .ja  va  2 s. c o m*/
 * <p>
 * You must have {@link #setGraph set a NavGraph} and {@link #setDestination set a destination}
 * before calling this method.
 * </p>
 *
 * @return a {@link TaskStackBuilder} which can be used to
 * {@link TaskStackBuilder#startActivities() send the deep link} or
 * {@link TaskStackBuilder#getPendingIntent(int, int) create a PendingIntent} to deep link to
 * the given destination.
 */
@NonNull
public TaskStackBuilder createTaskStackBuilder() {
    if (mIntent.getIntArrayExtra(NavController.KEY_DEEP_LINK_IDS) == null) {
        if (mGraph == null) {
            throw new IllegalStateException("You must call setGraph() " + "before constructing the deep link");
        } else {
            throw new IllegalStateException(
                    "You must call setDestination() " + "before constructing the deep link");
        }
    }
    // We create a copy of the Intent to ensure the Intent does not have itself
    // as an extra. This also prevents developers from modifying the internal Intent
    // via taskStackBuilder.editIntentAt()
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(mContext)
            .addNextIntentWithParentStack(new Intent(mIntent));
    for (int index = 0; index < taskStackBuilder.getIntentCount(); index++) {
        // Attach the original Intent to each Activity so that they can know
        // they were constructed in response to a deep link
        taskStackBuilder.editIntentAt(index).putExtra(NavController.KEY_DEEP_LINK_INTENT, mIntent);
    }
    return taskStackBuilder;
}

From source file:com.flowzr.activity.BackupListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings:
        startActivity(new Intent(getApplicationContext(), BackupPreferencesActivity.class));
        return true;
    case android.R.id.home: {
        TaskStackBuilder tsb = TaskStackBuilder.create(this);
        final int intentCount = tsb.getIntentCount();
        if (intentCount > 0) {
            Intent upIntent = tsb.getIntents()[intentCount - 1];
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is not part of the application's task, so create a new task with a synthesized back stack.
                tsb.startActivities();/*from  w w  w . j ava 2  s  .  co m*/
                finish();
            } else {
                // This activity is part of the application's task, so simply navigate up to the hierarchical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
        } else {
            onBackPressed();
        }
        return true;
    }

    }
    return super.onOptionsItemSelected(item);
}

From source file:com.flowzr.activity.RecurActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_done:
        RecurInterval interval = getRecurInterval(sInterval.getSelectedItem());
        RecurPeriod period = periods[sPeriod.getSelectedItemPosition()];
        Recur r = RecurUtils.createRecur(interval);
        r.startDate = startDate.getTimeInMillis();
        r.period = period;//from   w  w w  . ja  va 2 s .c o m
        if (updateInterval(r) && updatePeriod(r)) {
            Intent data = new Intent();
            data.putExtra(EXTRA_RECUR, r.toString());
            setResult(RESULT_OK, data);
            finish();
        }
        return true;
    case R.id.action_cancel:
        setResult(RESULT_CANCELED, null);
        finish();
        return true;
    case android.R.id.home: {
        TaskStackBuilder tsb = TaskStackBuilder.create(this);
        final int intentCount = tsb.getIntentCount();
        if (intentCount > 0) {
            Intent upIntent = tsb.getIntents()[intentCount - 1];
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is not part of the application's task, so create a new task with a synthesized back stack.
                tsb.startActivities();
                finish();
            } else {
                // This activity is part of the application's task, so simply navigate up to the hierarchical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
        } else {
            onBackPressed();
        }
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.firefly.sample.castcompanionlibrary.notification.VideoCastNotificationService.java

private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying, Class<?> targetActivity)
        throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
    Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = null;//www  . ja v a  2 s . co m
    if (null == mTargetActivity) {
        mTargetActivity = VideoCastControllerActivity.class;
    }
    contentIntent = new Intent(this, mTargetActivity);

    contentIntent.putExtra("media", mediaWrapper);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(mTargetActivity);

    stackBuilder.addNextIntent(contentIntent);
    if (stackBuilder.getIntentCount() > 1) {
        stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
    }

    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID,
            PendingIntent.FLAG_UPDATE_CURRENT);

    MediaMetadata mm = info.getMetadata();

    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification);
    if (mIsIcsOrAbove) {
        addPendingIntents(rv, isPlaying, info);
    }
    if (null != bitmap) {
        rv.setImageViewBitmap(R.id.iconView, bitmap);
    }
    rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE));
    String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName());
    rv.setTextViewText(R.id.subTitleView, castingTo);
    mNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification)
            .setContentIntent(resultPendingIntent).setContent(rv).setAutoCancel(false).setOngoing(true).build();

    // to get around a bug in GB version, we add the following line
    // see https://code.google.com/p/android/issues/detail?id=30495
    mNotification.contentView = rv;

    return rv;
}

From source file:air.com.snagfilms.cast.chromecast.notifications.VideoCastNotificationService.java

private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying, Class<?> targetActivity)
        throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
    Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = null;//from ww w.j  a  v a2  s .  c  o m
    if (null == mTargetActivity) {
        mTargetActivity = VideoPlayerActivity.class;
    }
    contentIntent = new Intent(this, mTargetActivity);

    contentIntent.putExtra("media", mediaWrapper);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(mTargetActivity);

    stackBuilder.addNextIntent(contentIntent);
    if (stackBuilder.getIntentCount() > 1) {
        stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
    }

    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID,
            PendingIntent.FLAG_UPDATE_CURRENT);

    MediaMetadata mm = info.getMetadata();

    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification);
    if (mIsIcsOrAbove) {
        addPendingIntents(rv, isPlaying, info);
    }
    if (null != bitmap) {
        rv.setImageViewBitmap(R.id.iconView, bitmap);
    }
    rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE));
    String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName());
    rv.setTextViewText(R.id.subTitleView, castingTo);
    mNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification)
            .setContentIntent(resultPendingIntent).setContent(rv).setAutoCancel(false).setOngoing(true).build();

    // to get around a bug in GB version, we add the following line
    // see https://code.google.com/p/android/issues/detail?id=30495
    mNotification.contentView = rv;

    return rv;
}

From source file:com.google.sample.castcompanionlibrary.notification.VideoCastNotificationService.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void buildForLollipopAndAbove(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.fromMediaInfo(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = new Intent(this, mTargetActivity);
    contentIntent.putExtra("media", mediaWrapper);

    // Media metadata
    MediaMetadata mm = info.getMetadata();
    String castingTo = getResources().getString(R.string.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);
    }/*from w ww. j av a2 s. c o  m*/
    PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mNotification = new Notification.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification)
            .setContentTitle(mm.getString(MediaMetadata.KEY_TITLE)).setContentText(castingTo)
            .setContentIntent(contentPendingIntent).setLargeIcon(bitmap)
            .addAction(isPlaying ? R.drawable.ic_pause_white_48dp : R.drawable.ic_play_arrow_white_48dp,
                    getString(R.string.pause), playbackPendingIntent)
            .addAction(R.drawable.ic_clear_white_24dp, getString(R.string.disconnect), stopPendingIntent)
            .setStyle(new Notification.MediaStyle().setShowActionsInCompactView(new int[] { 0, 1 }))
            .setOngoing(true).setShowWhen(false).setVisibility(Notification.VISIBILITY_PUBLIC).build();

}

From source file:com.google.sample.castcompanionlibrary.notification.VideoCastNotificationService.java

private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying)
        throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
    if (mIsLollipopOrAbove) {
        buildForLollipopAndAbove(info, bitmap, isPlaying);
        return null;
    }/*  www  . j  a v a2  s  . co  m*/
    Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = new Intent(this, mTargetActivity);

    contentIntent.putExtra("media", mediaWrapper);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(mTargetActivity);

    stackBuilder.addNextIntent(contentIntent);
    if (stackBuilder.getIntentCount() > 1) {
        stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
    }

    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID,
            PendingIntent.FLAG_UPDATE_CURRENT);

    MediaMetadata mm = info.getMetadata();

    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification);
    if (mIsIcsOrAbove) {
        addPendingIntents(rv, isPlaying, info);
    }
    if (null != bitmap) {
        rv.setImageViewBitmap(R.id.iconView, bitmap);
    } else {
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_album_art);
        rv.setImageViewBitmap(R.id.iconView, bitmap);
    }
    rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE));
    String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName());
    rv.setTextViewText(R.id.subTitleView, castingTo);
    mNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification)
            .setContentIntent(resultPendingIntent).setContent(rv).setAutoCancel(false).setOngoing(true).build();

    // to get around a bug in GB version, we add the following line
    // see https://code.google.com/p/android/issues/detail?id=30495
    mNotification.contentView = rv;

    return rv;
}