Example usage for android.os Bundle getBundle

List of usage examples for android.os Bundle getBundle

Introduction

In this page you can find the example usage for android.os Bundle getBundle.

Prototype

@Nullable
public Bundle getBundle(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:androidx.navigation.NavController.java

/**
 * Checks the given Intent for a Navigation deep link and navigates to the deep link if present.
 * This is called automatically for you the first time you set the graph if you've passed in an
 * {@link Activity} as the context when constructing this NavController, but should be manually
 * called if your Activity receives new Intents in {@link Activity#onNewIntent(Intent)}.
 * <p>/*from www .j  a  v  a2s . co m*/
 * The types of Intents that are supported include:
 * <ul>
 *     <ol>Intents created by {@link NavDeepLinkBuilder} or
 *     {@link #createDeepLink()}. This assumes that the current graph shares
 *     the same hierarchy to get to the deep linked destination as when the deep link was
 *     constructed.</ol>
 *     <ol>Intents that include a {@link Intent#getData() data Uri}. This Uri will be checked
 *     against the Uri patterns added via {@link NavDestination#addDeepLink(String)}.</ol>
 * </ul>
 * <p>The {@link #getGraph() navigation graph} should be set before calling this method.</p>
 * @param intent The Intent that may contain a valid deep link
 * @return True if the navigation controller found a valid deep link and navigated to it.
 * @see NavDestination#addDeepLink(String)
 */
public boolean onHandleDeepLink(@Nullable Intent intent) {
    if (intent == null) {
        return false;
    }
    Bundle extras = intent.getExtras();
    int[] deepLink = extras != null ? extras.getIntArray(KEY_DEEP_LINK_IDS) : null;
    Bundle bundle = new Bundle();
    Bundle deepLinkExtras = extras != null ? extras.getBundle(KEY_DEEP_LINK_EXTRAS) : null;
    if (deepLinkExtras != null) {
        bundle.putAll(deepLinkExtras);
    }
    if ((deepLink == null || deepLink.length == 0) && intent.getData() != null) {
        Pair<NavDestination, Bundle> matchingDeepLink = mGraph.matchDeepLink(intent.getData());
        if (matchingDeepLink != null) {
            deepLink = matchingDeepLink.first.buildDeepLinkIds();
            bundle.putAll(matchingDeepLink.second);
        }
    }
    if (deepLink == null || deepLink.length == 0) {
        return false;
    }
    bundle.putParcelable(KEY_DEEP_LINK_INTENT, intent);
    int flags = intent.getFlags();
    if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) == 0) {
        // Someone called us with NEW_TASK, but we don't know what state our whole
        // task stack is in, so we need to manually restart the whole stack to
        // ensure we're in a predictably good state.
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(mContext)
                .addNextIntentWithParentStack(intent);
        taskStackBuilder.startActivities();
        if (mActivity != null) {
            mActivity.finish();
        }
        return true;
    }
    if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
        // Start with a cleared task starting at our root when we're on our own task
        if (!mBackStack.isEmpty()) {
            navigate(mGraph.getStartDestination(), bundle, new NavOptions.Builder()
                    .setPopUpTo(mGraph.getId(), true).setEnterAnim(0).setExitAnim(0).build());
        }
        int index = 0;
        while (index < deepLink.length) {
            int destinationId = deepLink[index++];
            NavDestination node = findDestination(destinationId);
            if (node == null) {
                throw new IllegalStateException("unknown destination during deep link: "
                        + NavDestination.getDisplayName(mContext, destinationId));
            }
            node.navigate(bundle, new NavOptions.Builder().setEnterAnim(0).setExitAnim(0).build());
        }
        return true;
    }
    // Assume we're on another apps' task and only start the final destination
    NavGraph graph = mGraph;
    for (int i = 0; i < deepLink.length; i++) {
        int destinationId = deepLink[i];
        NavDestination node = i == 0 ? mGraph : graph.findNode(destinationId);
        if (node == null) {
            throw new IllegalStateException("unknown destination during deep link: "
                    + NavDestination.getDisplayName(mContext, destinationId));
        }
        if (i != deepLink.length - 1) {
            // We're not at the final NavDestination yet, so keep going through the chain
            graph = (NavGraph) node;
        } else {
            // Navigate to the last NavDestination, clearing any existing destinations
            node.navigate(bundle, new NavOptions.Builder().setPopUpTo(mGraph.getId(), true).setEnterAnim(0)
                    .setExitAnim(0).build());
        }
    }
    return true;
}

From source file:com.cyanogenmod.account.ui.SetupWizardActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.setup_main);
    ((CMAccount) AppGlobals.getInitialApplication()).disableStatusBar();
    mSharedPreferences = getSharedPreferences(CMAccount.SETTINGS_PREFERENCES, Context.MODE_PRIVATE);
    mSetupData = (AbstractSetupData) getLastNonConfigurationInstance();
    if (mSetupData == null) {
        mSetupData = new CMSetupWizardData(this);
    }//from  w  w w . j  a v  a  2 s .  com

    if (savedInstanceState != null) {
        mSetupData.load(savedInstanceState.getBundle("data"));
    } else {
        mSharedPreferences.edit().putBoolean(KEY_SIM_MISSING_SHOWN, false).commit();
    }
    mSetupData.registerListener(this);
    mPagerAdapter = new CMPagerAdapter(getFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setPageTransformer(true, new DepthPageTransformer());
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            if (position < mPageList.size()) {
                onPageLoaded(mPageList.get(position));
            }
        }
    });
    onPageTreeChanged();
    removeUnNeededPages();
}

From source file:com.google.android.libraries.cast.companionlibrary.cast.player.VideoCastControllerFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setImmersive();/*from   ww  w .  j  a v a 2 s  . c  o  m*/
    mCastConsumer = new MyCastConsumer();
    Bundle bundle = getArguments();
    if (bundle == null) {
        return;
    }
    Bundle extras = bundle.getBundle(EXTRAS);
    Bundle mediaWrapper = extras.getBundle(VideoCastManager.EXTRA_MEDIA);

    // Retain this fragment across configuration changes.
    setRetainInstance(true);
    mCastManager.addTracksSelectedListener(this);
    boolean explicitStartActivity = mCastManager.getPreferenceAccessor()
            .getBooleanFromPreference(VideoCastManager.PREFS_KEY_START_ACTIVITY, false);
    if (explicitStartActivity) {
        mIsFresh = true;
    }
    mCastManager.getPreferenceAccessor().saveBooleanToPreference(VideoCastManager.PREFS_KEY_START_ACTIVITY,
            false);
    if (extras.getBoolean(VideoCastManager.EXTRA_HAS_AUTH)) {
        if (mIsFresh) {
            mOverallState = OverallState.AUTHORIZING;
            mMediaAuthService = mCastManager.getMediaAuthService();
            handleMediaAuthTask(mMediaAuthService);
            showImage(Utils.getImageUri(mMediaAuthService.getMediaInfo(), 1));
        }
    } else if (mediaWrapper != null) {
        mOverallState = OverallState.PLAYBACK;
        boolean shouldStartPlayback = extras.getBoolean(VideoCastManager.EXTRA_SHOULD_START);
        String customDataStr = extras.getString(VideoCastManager.EXTRA_CUSTOM_DATA);
        int nextPreviousVisibilityPolicy = extras.getInt(VideoCastManager.EXTRA_NEXT_PREVIOUS_VISIBILITY_POLICY,
                VideoCastController.NEXT_PREV_VISIBILITY_POLICY_DISABLED);
        mCastController.setNextPreviousVisibilityPolicy(nextPreviousVisibilityPolicy);
        JSONObject customData = null;
        if (!TextUtils.isEmpty(customDataStr)) {
            try {
                customData = new JSONObject(customDataStr);
            } catch (JSONException e) {
                LOGE(TAG, "Failed to unmarshalize custom data string: customData=" + customDataStr, e);
            }
        }
        MediaInfo info = Utils.bundleToMediaInfo(mediaWrapper);
        int startPoint = extras.getInt(VideoCastManager.EXTRA_START_POINT, 0);
        onReady(info, shouldStartPlayback && explicitStartActivity, startPoint, customData);
    }
}

From source file:com.android.screenspeak.eventprocessor.ProcessorEventQueue.java

/**
 * Provides feedback for the specified utterance.
 *
 * @param queueMode The queueMode of the Utterance.
 * @param utterance The utterance to provide feedback for.
 *///ww  w .  jav  a 2 s  .c o m
private void provideFeedbackForUtterance(int queueMode, Utterance utterance) {
    final Bundle metadata = utterance.getMetadata();
    final float earconRate = metadata.getFloat(Utterance.KEY_METADATA_EARCON_RATE, 1.0f);
    final float earconVolume = metadata.getFloat(Utterance.KEY_METADATA_EARCON_VOLUME, 1.0f);
    final Bundle nonSpeechMetadata = new Bundle();
    nonSpeechMetadata.putFloat(Utterance.KEY_METADATA_EARCON_RATE, earconRate);
    nonSpeechMetadata.putFloat(Utterance.KEY_METADATA_EARCON_VOLUME, earconVolume);

    // Retrieve and play all spoken text.
    final CharSequence textToSpeak = StringBuilderUtils.getAggregateText(utterance.getSpoken());
    final int flags = metadata.getInt(Utterance.KEY_METADATA_SPEECH_FLAGS, 0);
    final Bundle speechMetadata = metadata.getBundle(Utterance.KEY_METADATA_SPEECH_PARAMS);

    final int utteranceGroup = utterance.getMetadata().getInt(Utterance.KEY_UTTERANCE_GROUP,
            SpeechController.UTTERANCE_GROUP_DEFAULT);

    mSpeechController.speak(textToSpeak, utterance.getAuditory(), utterance.getHaptic(), queueMode, flags,
            utteranceGroup, speechMetadata, nonSpeechMetadata);
}

From source file:com.example.android.snake.Snake.java

/**
 * Called when Activity is first created. Turns off the title bar, sets up
 * the content views, and fires up the SnakeView.
 *
 *//*from w  w w  .j a  v a2 s. c  om*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.snake_layout);

    mSnakeView = (SnakeView) findViewById(R.id.snake);
    mSnakeView.setTextView((TextView) findViewById(R.id.text));
    mSnakeView.setImageView((ImageView) findViewById(R.id.image));
    mSnakeView.setBackgroundView((ImageView) findViewById(R.id.background));
    //mBackground = (ImageView) findViewById(R.id.background);

    //mSnakeView.displayNewPortion();

    //Bitmap cropped = Bitmap.createBitmap(mSourceBitmap, 10, 15, 10, 15, null, false);
    //mBackground.setImageBitmap(cropped);

    if (savedInstanceState == null) {
        // We were just launched -- set up a new game
        mSnakeView.setMode(SnakeView.READY);
    } else {
        // We are being restored
        Bundle map = savedInstanceState.getBundle(ICICLE_KEY);
        if (map != null) {
            mSnakeView.restoreState(map);
        } else {
            mSnakeView.setMode(SnakeView.PAUSE);
        }
    }
}

From source file:com.google.samples.apps.iosched.map.MapActivity.java

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    if (mDetachedMode) {
        final Toolbar toolbar = getToolbar();
        toolbar.setNavigationIcon(R.drawable.ic_up);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override//from w w w . j  a  v  a 2s  .  c  o  m
            public void onClick(View view) {
                finish();
            }
        });
    }

    if (mMapFragment == null) {
        // Either restore the state of the map or read it from the Intent extras.
        if (savedInstanceState != null) {
            // Restore state from existing bundle
            Bundle previousState = savedInstanceState.getBundle(BUNDLE_STATE_MAPVIEW);
            mMapFragment = MapFragment.newInstance(previousState);
        } else {
            // Get highlight room id (if specified in intent extras)
            final String highlightRoomId = getIntent().hasExtra(EXTRA_ROOM)
                    ? getIntent().getExtras().getString(EXTRA_ROOM)
                    : null;
            mMapFragment = MapFragment.newInstance(highlightRoomId);
        }
        getFragmentManager().beginTransaction().add(R.id.fragment_container_map, mMapFragment, "map").commit();
    }

    if (mInfoFragment == null) {
        mInfoFragment = MapInfoFragment.newInstace(this);
        getFragmentManager().beginTransaction().add(R.id.fragment_container_map_info, mInfoFragment, "mapsheet")
                .commit();
    }

    mDetachedMode = getIntent().getBooleanExtra(EXTRA_DETACHED_MODE, false);

    attemptEnableMyLocation();
}

From source file:mobi.cangol.mobile.base.BaseDialogFragment.java

public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (this.mShowsDialog) {
        View view = this.getView();
        if (view != null) {
            if (view.getParent() != null) {
                throw new IllegalStateException("DialogFragment can not be attached to a container view");
            }//w w w.  j av  a 2s . co  m
            this.mDialog.setContentView(view);
        }

        this.mDialog.setOwnerActivity(this.getActivity());
        this.mDialog.setCancelable(this.mCancelable);
        this.mDialog.setOnCancelListener(this);
        this.mDialog.setOnDismissListener(this);
        if (savedInstanceState != null) {
            Bundle dialogState = savedInstanceState.getBundle("android:savedDialogState");
            if (dialogState != null) {
                this.mDialog.onRestoreInstanceState(dialogState);
            }
        }

    }
}

From source file:android.support.mediacompat.service.ServiceBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    if (ACTION_CALL_MEDIA_BROWSER_SERVICE_METHOD.equals(intent.getAction()) && extras != null) {
        StubMediaBrowserServiceCompat service = StubMediaBrowserServiceCompat.sInstance;
        int method = extras.getInt(KEY_METHOD_ID, 0);

        switch (method) {
        case NOTIFY_CHILDREN_CHANGED:
            service.notifyChildrenChanged(extras.getString(KEY_ARGUMENT));
            break;
        case SEND_DELAYED_NOTIFY_CHILDREN_CHANGED:
            service.sendDelayedNotifyChildrenChanged();
            break;
        case SEND_DELAYED_ITEM_LOADED:
            service.sendDelayedItemLoaded();
            break;
        case CUSTOM_ACTION_SEND_PROGRESS_UPDATE:
            service.mCustomActionResult.sendProgressUpdate(extras.getBundle(KEY_ARGUMENT));
            break;
        case CUSTOM_ACTION_SEND_ERROR:
            service.mCustomActionResult.sendError(extras.getBundle(KEY_ARGUMENT));
            break;
        case CUSTOM_ACTION_SEND_RESULT:
            service.mCustomActionResult.sendResult(extras.getBundle(KEY_ARGUMENT));
            break;
        case SET_SESSION_TOKEN:
            StubMediaBrowserServiceCompatWithDelayedMediaSession.sInstance.callSetSessionToken();
            break;
        }//from  w  w  w  .j  ava  2 s  .c  o m
    } else if (ACTION_CALL_MEDIA_SESSION_METHOD.equals(intent.getAction()) && extras != null) {
        MediaSessionCompat session = StubMediaBrowserServiceCompat.sSession;
        int method = extras.getInt(KEY_METHOD_ID, 0);

        switch (method) {
        case SET_EXTRAS:
            session.setExtras(extras.getBundle(KEY_ARGUMENT));
            break;
        case SET_FLAGS:
            session.setFlags(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_METADATA:
            session.setMetadata((MediaMetadataCompat) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_PLAYBACK_STATE:
            session.setPlaybackState((PlaybackStateCompat) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_QUEUE:
            List<QueueItem> items = extras.getParcelableArrayList(KEY_ARGUMENT);
            session.setQueue(items);
            break;
        case SET_QUEUE_TITLE:
            session.setQueueTitle(extras.getCharSequence(KEY_ARGUMENT));
            break;
        case SET_SESSION_ACTIVITY:
            session.setSessionActivity((PendingIntent) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_CAPTIONING_ENABLED:
            session.setCaptioningEnabled(extras.getBoolean(KEY_ARGUMENT));
            break;
        case SET_REPEAT_MODE:
            session.setRepeatMode(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_SHUFFLE_MODE:
            session.setShuffleMode(extras.getInt(KEY_ARGUMENT));
            break;
        case SEND_SESSION_EVENT:
            Bundle arguments = extras.getBundle(KEY_ARGUMENT);
            session.sendSessionEvent(arguments.getString("event"), arguments.getBundle("extras"));
            break;
        case SET_ACTIVE:
            session.setActive(extras.getBoolean(KEY_ARGUMENT));
            break;
        case RELEASE:
            session.release();
            break;
        case SET_PLAYBACK_TO_LOCAL:
            session.setPlaybackToLocal(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_PLAYBACK_TO_REMOTE:
            ParcelableVolumeInfo volumeInfo = extras.getParcelable(KEY_ARGUMENT);
            session.setPlaybackToRemote(new VolumeProviderCompat(volumeInfo.controlType, volumeInfo.maxVolume,
                    volumeInfo.currentVolume) {
            });
            break;
        case SET_RATING_TYPE:
            session.setRatingType(RatingCompat.RATING_5_STARS);
            break;
        }
    }
}

From source file:sg.fxl.topekaport.QuizFragment.java

private void restoreQuizState(final Bundle savedInstanceState) {
    if (null == savedInstanceState) {
        return;/*  w  w w .ja  v  a 2 s.c  om*/
    }
    quizView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            quizView.removeOnLayoutChangeListener(this);
            View currentChild = quizView.getChildAt(0);
            if (currentChild instanceof ViewGroup) {
                final View potentialQuizView = ((ViewGroup) currentChild).getChildAt(0);
                if (potentialQuizView instanceof AbsQuizView) {
                    ((AbsQuizView) potentialQuizView)
                            .setUserInput(savedInstanceState.getBundle(KEY_USER_INPUT));
                }
            }
        }
    });

}

From source file:br.org.funcate.dynamicforms.FragmentDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // don't permit rotation
    int currentOrientation = getResources().getConfiguration().orientation;
    if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {/* w w  w .  j ava 2 s .co m*/
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    String tags = "";
    String defaultSectionName = FormUtilities.DEFAULT_SESSION_NAME;

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    String geojsonTags = "";
    if (extras != null) {
        pointId = extras.getLong(LibraryConstants.SELECTED_POINT_ID);
        formName = extras.getString(FormUtilities.ATTR_FORMNAME);
        tags = extras.getString(FormUtilities.ATTR_JSON_TAGS);

        if (extras.containsKey(FormUtilities.ATTR_GEOJSON_TAGS)) {
            geojsonTags = extras.getString(FormUtilities.ATTR_GEOJSON_TAGS);
        }
        // here are the attribute values from feature to populate form in edit operation
        if (extras.containsKey(FormUtilities.ATTR_DATA_VALUES)) {
            existingFeatureData = extras.getBundle(FormUtilities.ATTR_DATA_VALUES);
        }
        workingDirectory = extras.getString(FormUtilities.MAIN_APP_WORKING_DIRECTORY);
    }

    try {
        sectionObject = TagsManager.getInstance(tags).getSectionByName(defaultSectionName);

        if (sectionObject == null) {
            Toast.makeText(getApplicationContext(), "Failure on get form session.", Toast.LENGTH_LONG).show();
            System.out.println("Failure on load JSON form from database.");
            this.finish();
        }

        JSONObject geojson = new JSONObject(geojsonTags);
        sectionObject.put(FormUtilities.ATTR_GEOJSON_TAGS, geojson);

    } catch (JSONException e) {
        Toast.makeText(getApplicationContext(), "Incorrect form configuration.", Toast.LENGTH_LONG).show();
        System.out.println("Failure on load JSON form from database.");
        e.printStackTrace();
        this.finish();
    }

    setContentView(R.layout.details_activity_layout);
}