List of usage examples for android.os Bundle getBundle
@Nullable
public Bundle getBundle(@Nullable String key)
From source file:org.cobaltians.cobalt.activities.CobaltActivity.java
/*********************************************************************************************** * * MENU// w w w. jav a2 s . c o m * **********************************************************************************************/ @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); Bundle bundle = getIntent().getExtras(); if (bundle == null) { bundle = new Bundle(); } Bundle extras = bundle.getBundle(Cobalt.kExtras); if (extras == null) { extras = Cobalt.getInstance(getApplicationContext()).getConfigurationForController(getInitController()); } if (extras.containsKey(Cobalt.kBars)) { try { JSONObject actionBar = new JSONObject(extras.getString(Cobalt.kBars)); String color = actionBar.optString(Cobalt.kBarsColor, null); if (color == null) { color = getDefaultActionBarTextColor(); } JSONArray actions = actionBar.optJSONArray(Cobalt.kBarsActions); if (actions != null) setupOptionsMenu(menu, color, actions); } catch (JSONException exception) { if (Cobalt.DEBUG) { Log.e(Cobalt.TAG, TAG + " - onCreate: action bar configuration parsing failed. " + extras.getString(Cobalt.kBars)); } exception.printStackTrace(); } } return true; }
From source file:com.facebook.internal.BundleJSONConverterTest.java
@Test public void testSimpleValues() throws JSONException { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("1st"); arrayList.add("2nd"); arrayList.add("third"); Bundle innerBundle1 = new Bundle(); innerBundle1.putInt("inner", 1); Bundle innerBundle2 = new Bundle(); innerBundle2.putString("inner", "2"); innerBundle2.putStringArray("deep list", new String[] { "7", "8" }); innerBundle1.putBundle("nested bundle", innerBundle2); Bundle b = new Bundle(); b.putBoolean("boolValue", true); b.putInt("intValue", 7); b.putLong("longValue", 5000000000l); b.putDouble("doubleValue", 3.14); b.putString("stringValue", "hello world"); b.putStringArray("stringArrayValue", new String[] { "first", "second" }); b.putStringArrayList("stringArrayListValue", arrayList); b.putBundle("nested", innerBundle1); JSONObject json = BundleJSONConverter.convertToJSON(b); assertNotNull(json);/*from ww w . j a v a2 s. com*/ assertEquals(true, json.getBoolean("boolValue")); assertEquals(7, json.getInt("intValue")); assertEquals(5000000000l, json.getLong("longValue")); assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals("hello world", json.getString("stringValue")); JSONArray jsonArray = json.getJSONArray("stringArrayValue"); assertEquals(2, jsonArray.length()); assertEquals("first", jsonArray.getString(0)); assertEquals("second", jsonArray.getString(1)); jsonArray = json.getJSONArray("stringArrayListValue"); assertEquals(3, jsonArray.length()); assertEquals("1st", jsonArray.getString(0)); assertEquals("2nd", jsonArray.getString(1)); assertEquals("third", jsonArray.getString(2)); JSONObject innerJson = json.getJSONObject("nested"); assertEquals(1, innerJson.getInt("inner")); innerJson = innerJson.getJSONObject("nested bundle"); assertEquals("2", innerJson.getString("inner")); jsonArray = innerJson.getJSONArray("deep list"); assertEquals(2, jsonArray.length()); assertEquals("7", jsonArray.getString(0)); assertEquals("8", jsonArray.getString(1)); Bundle finalBundle = BundleJSONConverter.convertToBundle(json); assertNotNull(finalBundle); assertEquals(true, finalBundle.getBoolean("boolValue")); assertEquals(7, finalBundle.getInt("intValue")); assertEquals(5000000000l, finalBundle.getLong("longValue")); assertEquals(3.14, finalBundle.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals("hello world", finalBundle.getString("stringValue")); List<String> stringList = finalBundle.getStringArrayList("stringArrayValue"); assertEquals(2, stringList.size()); assertEquals("first", stringList.get(0)); assertEquals("second", stringList.get(1)); stringList = finalBundle.getStringArrayList("stringArrayListValue"); assertEquals(3, stringList.size()); assertEquals("1st", stringList.get(0)); assertEquals("2nd", stringList.get(1)); assertEquals("third", stringList.get(2)); Bundle finalInnerBundle = finalBundle.getBundle("nested"); assertEquals(1, finalInnerBundle.getInt("inner")); finalBundle = finalInnerBundle.getBundle("nested bundle"); assertEquals("2", finalBundle.getString("inner")); stringList = finalBundle.getStringArrayList("deep list"); assertEquals(2, stringList.size()); assertEquals("7", stringList.get(0)); assertEquals("8", stringList.get(1)); }
From source file:com.actionbarsherlock.plus.SherlockDialogPlusFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (!mShowsDialog) { return;// w w w. j a v a 2s . c o m } View view = getView(); if (view != null) { if (view.getParent() != null) { throw new IllegalStateException("DialogFragment can not be attached to a container view"); } mDialog.setContentView(view); } mDialog.setOwnerActivity(getActivity()); mDialog.setCancelable(mCancelable); mDialog.setOnDismissListener(this); if (savedInstanceState != null) { Bundle dialogState = savedInstanceState.getBundle(SAVED_DIALOG_STATE_TAG); if (dialogState != null) { mDialog.onRestoreInstanceState(dialogState); } } }
From source file:presentation.foundation.BaseFragmentActivity.java
private void configureFragment() { Bundle bundle = getIntent().getExtras(); if (bundle == null || bundle.getSerializable(Behaviour.FRAGMENT_CLASS_KEY) == null) { Log.w(BaseFragmentActivity.class.getSimpleName(), "When using " + BaseFragmentActivity.class.getSimpleName() + " you could supply" + " a fragment which extends from " + BasePresenterFragment.class.getSimpleName() + " by extra argument in the intent" + " as value and " + Behaviour.FRAGMENT_CLASS_KEY + " as key, but a <FrameLayout android:id=\"@id/fl_fragment\" .../>" + " will be mandatory in your activity layout."); return;/*from ww w . j av a 2 s. c o m*/ } Serializable serializable = bundle.getSerializable(Behaviour.FRAGMENT_CLASS_KEY); Class<BasePresenterFragment> clazz = (Class<BasePresenterFragment>) serializable; BasePresenterFragment basePresenterFragment = replaceFragment(clazz); Bundle bundleFragment = bundle.getBundle(Behaviour.BUNDLE_FOR_FRAGMENT); basePresenterFragment.setArguments(bundleFragment); }
From source file:org.anhonesteffort.flock.EditAutoRenewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.activity_edit_auto_renew); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setTitle(R.string.button_edit_payment_details); if (savedInstanceState != null && !savedInstanceState.isEmpty()) { if (!DavAccount.build(savedInstanceState.getBundle(KEY_DAV_ACCOUNT_BUNDLE)).isPresent()) { finish();//from www. ja va2 s.c o m return; } davAccount = DavAccount.build(savedInstanceState.getBundle(KEY_DAV_ACCOUNT_BUNDLE)).get(); flockAccount = FlockAccount.build(savedInstanceState.getBundle(KEY_FLOCK_ACCOUNT_BUNDLE)); cardInformation = FlockCardInformation.build(savedInstanceState.getBundle(KEY_CARD_INFORMATION_BUNDLE)); } else if (getIntent().getExtras() != null) { if (!DavAccount.build(getIntent().getExtras().getBundle(KEY_DAV_ACCOUNT_BUNDLE)).isPresent()) { finish(); return; } davAccount = DavAccount.build(getIntent().getExtras().getBundle(KEY_DAV_ACCOUNT_BUNDLE)).get(); flockAccount = FlockAccount.build(getIntent().getExtras().getBundle(KEY_FLOCK_ACCOUNT_BUNDLE)); cardInformation = FlockCardInformation .build(getIntent().getExtras().getBundle(KEY_CARD_INFORMATION_BUNDLE)); } initCostPerYear(); }
From source file:org.cobaltians.cobalt.activities.CobaltActivity.java
/*********************************************************************************************** * * LIFECYCLE//w w w.java2 s.c om * **********************************************************************************************/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayoutToInflate()); sActivitiesArrayList.add(this); Bundle bundle = getIntent().getExtras(); if (bundle == null) { bundle = new Bundle(); } Bundle extras = bundle.getBundle(Cobalt.kExtras); if (extras == null) { extras = Cobalt.getInstance(this.getApplicationContext()) .getConfigurationForController(getInitController()); extras.putString(Cobalt.kPage, getInitPage()); bundle.putBundle(Cobalt.kExtras, extras); } if (bundle.containsKey(Cobalt.kJSData)) { try { mDataNavigation = new JSONObject(bundle.getString(Cobalt.kJSData)); } catch (JSONException e) { if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + " - onCreate: data navigation parsing failed. " + extras.getString(Cobalt.kJSData)); e.printStackTrace(); } } if (extras.containsKey(Cobalt.kBars)) { try { JSONObject actionBar = new JSONObject(extras.getString(Cobalt.kBars)); setupBars(actionBar); } catch (JSONException exception) { setupBars(null); if (Cobalt.DEBUG) { Log.e(Cobalt.TAG, TAG + " - onCreate: bars configuration parsing failed. " + extras.getString(Cobalt.kBars)); } exception.printStackTrace(); } } else { setupBars(null); } if (savedInstanceState == null) { CobaltFragment fragment = getFragment(); if (fragment != null) { fragment.setArguments(extras); mAnimatedTransition = bundle.getBoolean(Cobalt.kJSAnimated, true); if (mAnimatedTransition) { mWasPushedAsModal = bundle.getBoolean(Cobalt.kPushAsModal, false); if (mWasPushedAsModal) { sWasPushedFromModal = true; overridePendingTransition(R.anim.modal_open_enter, android.R.anim.fade_out); } else if (bundle.getBoolean(Cobalt.kPopAsModal, false)) { sWasPushedFromModal = false; overridePendingTransition(android.R.anim.fade_in, R.anim.modal_close_exit); } else if (sWasPushedFromModal) overridePendingTransition(R.anim.modal_push_enter, R.anim.modal_push_exit); } else overridePendingTransition(0, 0); } if (findViewById(getFragmentContainerId()) != null) { getSupportFragmentManager().beginTransaction().replace(getFragmentContainerId(), fragment).commit(); } else if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + " - onCreate: fragment container not found"); } else if (Cobalt.DEBUG) Log.e(Cobalt.TAG, TAG + " - onCreate: getFragment() returned null"); }
From source file:com.eleybourn.bookcatalogue.BookEdit.java
/** * This function will populate the forms elements in three different ways 1. * If a valid rowId exists it will populate the fields from the database 2. * If fields have been passed from another activity (e.g. ISBNSearch) it * will populate the fields from the bundle 3. It will leave the fields * blank for new books.// ww w .ja v a 2s . c o m */ private void loadBookData(Long rowId, Bundle bestBundle) { if (bestBundle != null && bestBundle.containsKey("bookData")) { // If we have saved book data, use it mBookData = new BookData(rowId, bestBundle.getBundle("bookData")); } else { // Just load based on rowId mBookData = new BookData(rowId); } }
From source file:br.liveo.navigationliveo.NavigationLiveoAWizard.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.navigation_main); if (savedInstanceState != null) { setCurrentPosition(savedInstanceState.getInt(CURRENT_POSITION)); //FORM WIZARD mWizardModel.load(savedInstanceState.getBundle("model")); mDataChanged = savedInstanceState.getBoolean("dataChanged"); }/*ww w . j av a 2 s . co m*/ mList = (ListView) findViewById(R.id.list); mList.setOnItemClickListener(new DrawerItemClickListener()); mToolbar = (Toolbar) findViewById(R.id.toolbar); // mToolbar.inflateMenu(R.menu.menu); ALVIN TEST mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); mDrawerToggle = new ActionBarDrawerToggleCompat(this, mDrawerLayout, mToolbar); mDrawerLayout.setDrawerListener(mDrawerToggle); mTitleFooter = (TextView) this.findViewById(R.id.titleFooter); mIconFooter = (ImageView) this.findViewById(R.id.iconFooter); mFooterDrawer = (RelativeLayout) this.findViewById(R.id.footerDrawer); mFooterDrawer.setOnClickListener(onClickFooterDrawer); mRelativeDrawer = (FrameLayout) this.findViewById(R.id.relativeDrawer); //alvin temp comments this.setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setIcon(R.drawable.ic_launcher); getSupportActionBar().setTitle(""); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { Resources.Theme theme = this.getTheme(); TypedArray typedArray = theme.obtainStyledAttributes(new int[] { android.R.attr.colorPrimary }); mDrawerLayout.setStatusBarBackground(typedArray.getResourceId(0, 0)); } catch (Exception e) { e.getMessage(); } this.setElevationToolBar(15); } if (mList != null) { mountListNavigation(savedInstanceState); } if (savedInstanceState == null) { mNavigationListener.onItemClickNavigation(mCurrentPosition, R.id.container); } setCheckedItemNavigation(mCurrentPosition, true); }
From source file:com.hippo.ehviewer.ui.MainActivity.java
public void startSceneForCheckStep(int checkStep, Bundle args) { switch (checkStep) { case CHECK_STEP_WARNING: if (Settings.getAskAnalytics()) { startScene(new Announcer(AnalyticsScene.class).setArgs(args)); break; }/* w w w . j av a 2 s. c o m*/ case CHECK_STEP_ANALYTICS: if (Crash.hasCrashFile()) { startScene(new Announcer(CrashScene.class).setArgs(args)); break; } case CHECK_STEP_CRASH: if (!EhUtils.hasSignedIn(this)) { startScene(new Announcer(SignInScene.class).setArgs(args)); break; } case CHECK_STEP_SIGN_IN: String targetScene = null; Bundle targetArgs = null; if (null != args) { targetScene = args.getString(KEY_TARGET_SCENE); targetArgs = args.getBundle(KEY_TARGET_ARGS); } Class<?> clazz = null; if (targetScene != null) { try { clazz = Class.forName(targetScene); } catch (ClassNotFoundException e) { Log.e(TAG, "Can't find class with name: " + targetScene); } } if (clazz != null) { startScene(new Announcer(clazz).setArgs(targetArgs)); } else { Bundle newArgs = new Bundle(); newArgs.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE); startScene(new Announcer(GalleryListScene.class).setArgs(newArgs)); } break; } }
From source file:android.support.v7.media.RemotePlaybackClient.java
private void performItemAction(final Intent intent, final String sessionId, final String itemId, Bundle extras, final ItemActionCallback callback) { intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK); if (sessionId != null) { intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId); }//from w w w . j a va2s . c om if (itemId != null) { intent.putExtra(MediaControlIntent.EXTRA_ITEM_ID, itemId); } if (extras != null) { intent.putExtras(extras); } logRequest(intent); mRoute.sendControlRequest(intent, new MediaRouter.ControlRequestCallback() { @Override public void onResult(Bundle data) { if (data != null) { String sessionIdResult = inferMissingResult(sessionId, data.getString(MediaControlIntent.EXTRA_SESSION_ID)); MediaSessionStatus sessionStatus = MediaSessionStatus .fromBundle(data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS)); String itemIdResult = inferMissingResult(itemId, data.getString(MediaControlIntent.EXTRA_ITEM_ID)); MediaItemStatus itemStatus = MediaItemStatus .fromBundle(data.getBundle(MediaControlIntent.EXTRA_ITEM_STATUS)); adoptSession(sessionIdResult); if (sessionIdResult != null && itemIdResult != null && itemStatus != null) { if (DEBUG) { Log.d(TAG, "Received result from " + intent.getAction() + ": data=" + bundleToString(data) + ", sessionId=" + sessionIdResult + ", sessionStatus=" + sessionStatus + ", itemId=" + itemIdResult + ", itemStatus=" + itemStatus); } callback.onResult(data, sessionIdResult, sessionStatus, itemIdResult, itemStatus); return; } } handleInvalidResult(intent, callback, data); } @Override public void onError(String error, Bundle data) { handleError(intent, callback, error, data); } }); }