List of usage examples for android.os Bundle putStringArray
public void putStringArray(@Nullable String key, @Nullable String[] value)
From source file:org.odk.collect.android.activities.GoogleDriveActivity.java
@Override protected void onSaveInstanceState(Bundle outState) { outState.putBoolean(MY_DRIVE_KEY, myDrive); ArrayList<DriveListItem> dl = new ArrayList<DriveListItem>(); for (int i = 0; i < listView.getCount(); i++) { dl.add((DriveListItem) listView.getItemAtPosition(i)); }//www . j av a 2 s .c om outState.putParcelableArrayList(DRIVE_ITEMS_KEY, dl); outState.putStringArray(PATH_KEY, currentPath.toArray(new String[currentPath.size()])); outState.putString(PARENT_KEY, parentId); outState.putBoolean(ALERT_SHOWING_KEY, alertShowing); outState.putString(ALERT_MSG_KEY, alertMsg); super.onSaveInstanceState(outState); }
From source file:com.github.chenxiaolong.dualbootpatcher.switcher.InAppFlashingFragment.java
@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelableArrayList(EXTRA_PENDING_ACTIONS, mPendingActions); outState.putParcelable(EXTRA_SELECTED_URI, mSelectedUri); outState.putString(EXTRA_SELECTED_URI_FILE_NAME, mSelectedUriFileName); outState.putParcelable(EXTRA_SELECTED_BACKUP_DIR_URI, mSelectedBackupDirUri); outState.putString(EXTRA_SELECTED_BACKUP_NAME, mSelectedBackupName); outState.putStringArray(EXTRA_SELECTED_BACKUP_TARGETS, mSelectedBackupTargets); outState.putString(EXTRA_SELECTED_ROM_ID, mSelectedRomId); outState.putString(EXTRA_ZIP_ROM_ID, mZipRomId); outState.putSerializable(EXTRA_ADD_TYPE, mAddType); outState.putInt(EXTRA_TASK_ID_VERIFY_ZIP, mTaskIdVerifyZip); outState.putBoolean(EXTRA_QUERYING_METADATA, mQueryingMetadata); }
From source file:eu.alefzero.owncloud.ui.activity.FileDisplayActivity.java
@Override protected void onSaveInstanceState(Bundle outState) { // responsability of restore is prefered in onCreate() before than in onRestoreInstanceState when there are Fragments involved Log.i(getClass().toString(), "onSaveInstanceState() start"); super.onSaveInstanceState(outState); if (mDirectories != null && mDirectories.getCount() != 0) { mDirs = new String[mDirectories.getCount() - 1]; for (int j = mDirectories.getCount() - 2, i = 0; j >= 0; --j, ++i) { mDirs[i] = mDirectories.getItem(j); }/*from w ww .ja va2 s . c om*/ } outState.putStringArray(KEY_DIR_ARRAY, mDirs); outState.putParcelable(FileDetailFragment.EXTRA_FILE, mCurrentDir); Log.i(getClass().toString(), "onSaveInstanceState() end"); }
From source file:org.envirocar.app.activity.ListTracksFragment.java
/** * Change one item//w ww. j ava 2s .co m */ @Override public boolean onContextItemSelected(MenuItem item) { final Track track; synchronized (this) { track = tracksList.get(itemSelect); } switch (item.getItemId()) { // Edit the trackname case R.id.editName: if (track.isLocalTrack()) { logger.info("editing track: " + itemSelect); final EditText input = new EditText(getActivity()); new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.editTrack)) .setMessage(getString(R.string.enterTrackName)).setView(input) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); logger.info("New name: " + value.toString()); track.setName(value); dbAdapter.updateTrack(track); tracksList.get(itemSelect).setName(value); updateTrackListView(); Crouton.showText(getActivity(), getString(R.string.nameChanged), Style.INFO); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } else { Crouton.showText(getActivity(), R.string.not_possible_for_remote, Style.INFO); } return true; // Edit the track description case R.id.editDescription: if (track.isLocalTrack()) { logger.info("editing track: " + itemSelect); final EditText input2 = new EditText(getActivity()); new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.editTrack)) .setMessage(getString(R.string.enterTrackDescription)).setView(input2) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input2.getText().toString(); logger.info("New description: " + value.toString()); track.setDescription(value); dbAdapter.updateTrack(track); trackListView.collapseGroup(itemSelect); updateTrackListView(); trackListAdapter.updateTrackChildView(track); Crouton.showText(getActivity(), getString(R.string.descriptionChanged), Style.INFO); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } else { Crouton.showText(getActivity(), R.string.not_possible_for_remote, Style.INFO); } return true; // Show that track in the map case R.id.startMap: logger.info("Show in Map"); logger.info(Environment.getExternalStorageDirectory().toString()); File f = new File(Environment.getExternalStorageDirectory() + "/Android"); if (f.isDirectory()) { // if (track.isLazyLoadingMeasurements()) { // dbAdapter.loadMeasurements(track); // } List<Measurement> measurements = track.getMeasurements(); logger.info("Count of measurements in the track: " + String.valueOf(measurements.size())); String[] trackCoordinates = extractCoordinates(measurements); if (trackCoordinates.length != 0) { logger.info(String.valueOf(trackCoordinates.length)); Intent intent = new Intent(getActivity().getApplicationContext(), org.envirocar.app.activity.Map.class); Bundle bundle = new Bundle(); bundle.putStringArray("coordinates", trackCoordinates); intent.putExtras(bundle); startActivity(intent); } else { Crouton.showText(getActivity(), getString(R.string.trackContainsNoCoordinates), Style.INFO); } } else { Crouton.showText(getActivity(), getString(R.string.noSdCard), Style.INFO); } return true; // Delete only selected track case R.id.deleteTrack: /* * we need to check the database if the track might have * transisted to a remote track due to uploading */ Track dbRefTrack = dbAdapter.getTrack(track.getTrackId(), true); if (dbRefTrack.isLocalTrack()) { logger.info("deleting item: " + itemSelect); dbAdapter.deleteTrack(track.getTrackId()); Crouton.showText(getActivity(), getString(R.string.trackDeleted), Style.INFO); tracksList.remove(itemSelect); updateTrackListView(); } else { createRemoteDeleteDialog(track, (RemoteTrack) dbRefTrack); } return true; // Share track case R.id.shareTrack: try { // if (track.isLazyLoadingMeasurements()) { // dbAdapter.loadMeasurements(track); // } Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("application/json"); Uri shareBody = Uri.fromFile(Util.saveTrackAndReturnFile(track, isObfuscationEnabled()).getFile()); sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "EnviroCar Track " + track.getName()); sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, shareBody); startActivity(Intent.createChooser(sharingIntent, "Share via")); } catch (JSONException e) { logger.warn(e.getMessage(), e); Crouton.showText(getActivity(), R.string.error_json, Style.ALERT); } catch (IOException e) { logger.warn(e.getMessage(), e); Crouton.showText(getActivity(), R.string.error_io, Style.ALERT); } catch (TrackWithoutMeasurementsException e) { logger.warn(e.getMessage(), e); if (isObfuscationEnabled()) { Crouton.showText(getActivity(), R.string.uploading_track_no_measurements_after_obfuscation_long, Style.ALERT); } else { Crouton.showText(getActivity(), R.string.uploading_track_no_measurements_after_obfuscation_long, Style.ALERT); } } return true; // Upload track case R.id.uploadTrack: if (UserManager.instance().isLoggedIn()) { // if (track.isLazyLoadingMeasurements()) { // dbAdapter.loadMeasurements(track); // } startTrackUpload(false, track); } else { Crouton.showText(getActivity(), R.string.hint_login_first, Style.INFO); } return true; default: return super.onContextItemSelected(item); } }
From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java
/** * Called before placing the activity in a background state, such as * - when a new Activity opens up on top of it * - when a Runtime Change occurs (e.g. screen orientation change). * The resulting Bundle is then passed to onCreate(Bundle) when the Activity gets back into focus. * * The bundle is used to save the _non-persistent_ application state, persistent state should be saved * in onPause()./*from w ww . j av a 2s . c o m*/ */ @Override public void onSaveInstanceState(Bundle outState) { // Save non-persistent state: // When trying to use "getString(R.string.nonPersistentState_panelCount)" as key, the value is // just NOT retrieved. The same if the key is too long, e.g. "nonPersistentState_panelCount". outState.putBoolean("nps_fullscreenMode", fullscreenMode); outState.putStringArray("nps_drawerBookButtonText", drawerBookButtonText); // In case it is ever needed, this is the best place to remove panels FragmentManager // (i.e. remove them from view) before the activity gets destroyed and recreated. // Just test for isFinishing() to see if it will get recreated. // This is *not* possible to move to onDestroy, because FragmentManager refuses to do // anything after onSaveInstanceState, since it might cause potential problems when recreating // the Activity from the saved state. super.onSaveInstanceState(outState); }
From source file:org.onebusaway.android.ui.ArrivalsListFragment.java
private void showRoutesFilterDialog() { ObaArrivalInfoResponse response = getArrivalsLoader().getLastGoodResponse(); final List<ObaRoute> routes = response.getRoutes(mStop.getRouteIds()); final int len = routes.size(); final ArrayList<String> filter = mRoutesFilter; // mRouteIds = new ArrayList<String>(len); String[] items = new String[len]; boolean[] checks = new boolean[len]; // Go through all the stops, add them to the Ids and Names // For each stop, if it is in the enabled list, mark it as checked. for (int i = 0; i < len; ++i) { final ObaRoute route = routes.get(i); // final String id = route.getId(); // mRouteIds.add(i, id); items[i] = UIUtils.getRouteDisplayName(route); if (filter.contains(route.getId())) { checks[i] = true;/* www .java2 s . co m*/ } } // Arguments Bundle args = new Bundle(); args.putStringArray(RoutesFilterDialog.ITEMS, items); args.putBooleanArray(RoutesFilterDialog.CHECKS, checks); RoutesFilterDialog frag = new RoutesFilterDialog(); frag.setArguments(args); frag.show(getActivity().getSupportFragmentManager(), ".RoutesFilterDialog"); }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.DisplayStopDataFragment.java
/** * {@inheritDoc}//w w w. j ava2 s . c o m */ @Override public void onSaveInstanceState(final Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(STATE_KEY_AUTOREFRESH, autoRefresh); outState.putLong(STATE_KEY_LAST_REFRESH, lastRefresh); populateExpandedItemsList(); if (!expandedServices.isEmpty()) { final String[] items = new String[expandedServices.size()]; outState.putStringArray(STATE_KEY_EXPANDED_ITEMS, expandedServices.toArray(items)); } }
From source file:org.opendatakit.common.android.utilities.AndroidUtils.java
public static Bundle convertToBundle(JSONObject valueMap, final MacroStringExpander expander) throws JSONException { Bundle b = new Bundle(); @SuppressWarnings("unchecked") Iterator<String> cur = valueMap.keys(); while (cur.hasNext()) { String key = cur.next();/*from w w w .jav a 2 s .com*/ if (!valueMap.isNull(key)) { Object o = valueMap.get(key); if (o instanceof JSONObject) { Bundle be = convertToBundle((JSONObject) o, expander); b.putBundle(key, be); } else if (o instanceof JSONArray) { JSONArray a = (JSONArray) o; // only non-empty arrays are written into the Bundle // first non-null element defines data type // for the array Object oe = null; for (int j = 0; j < a.length(); ++j) { if (!a.isNull(j)) { oe = a.get(j); break; } } if (oe != null) { if (oe instanceof JSONObject) { Bundle[] va = new Bundle[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = null; } else { va[j] = convertToBundle((JSONObject) a.getJSONObject(j), expander); } } b.putParcelableArray(key, va); } else if (oe instanceof JSONArray) { throw new JSONException("Unable to convert nested arrays"); } else if (oe instanceof String) { String[] va = new String[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = null; } else { va[j] = a.getString(j); } } b.putStringArray(key, va); } else if (oe instanceof Boolean) { boolean[] va = new boolean[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = false; } else { va[j] = a.getBoolean(j); } } b.putBooleanArray(key, va); } else if (oe instanceof Integer) { int[] va = new int[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = 0; } else { va[j] = a.getInt(j); } } b.putIntArray(key, va); } else if (oe instanceof Long) { long[] va = new long[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = 0; } else { va[j] = a.getLong(j); } } b.putLongArray(key, va); } else if (oe instanceof Double) { double[] va = new double[a.length()]; for (int j = 0; j < a.length(); ++j) { if (a.isNull(j)) { va[j] = Double.NaN; } else { va[j] = a.getDouble(j); } } b.putDoubleArray(key, va); } } } else if (o instanceof String) { String v = valueMap.getString(key); if (expander != null) { v = expander.expandString(v); } b.putString(key, v); } else if (o instanceof Boolean) { b.putBoolean(key, valueMap.getBoolean(key)); } else if (o instanceof Integer) { b.putInt(key, valueMap.getInt(key)); } else if (o instanceof Long) { b.putLong(key, valueMap.getLong(key)); } else if (o instanceof Double) { b.putDouble(key, valueMap.getDouble(key)); } } } return b; }
From source file:org.mariotaku.twidere.fragment.BaseStatusesListFragment.java
@Override public final boolean onMenuItemClick(final MenuItem item) { final ParcelableStatus status = mSelectedStatus; if (status == null) return false; switch (item.getItemId()) { case MENU_VIEW: { openStatus(getActivity(), status); break;/*w ww. j a v a 2 s . c o m*/ } case MENU_SHARE: { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "@" + status.screen_name + ": " + status.text_plain); startActivity(Intent.createChooser(intent, getString(R.string.share))); break; } case MENU_COPY: { final CharSequence text = Html.fromHtml(status.text_html); if (ClipboardUtils.setText(getActivity(), text)) { Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show(); } break; } case R.id.direct_retweet: case MENU_RETWEET: { if (isMyRetweet(status)) { cancelRetweet(mTwitterWrapper, status); } else { final long id_to_retweet = mSelectedStatus.is_retweet && mSelectedStatus.retweet_id > 0 ? mSelectedStatus.retweet_id : mSelectedStatus.status_id; mTwitterWrapper.retweetStatus(status.account_id, id_to_retweet); } break; } case R.id.direct_quote: case MENU_QUOTE: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id); bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id); bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name); bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name); bundle.putBoolean(INTENT_KEY_IS_QUOTE, true); bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.text_plain)); intent.putExtras(bundle); startActivity(intent); break; } case MENU_REPLY: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); final List<String> mentions = new Extractor().extractMentionedScreennames(status.text_plain); mentions.remove(status.screen_name); mentions.add(0, status.screen_name); bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()])); bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id); bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id); bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name); bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name); intent.putExtras(bundle); startActivity(intent); break; } case MENU_FAVORITE: { if (mSelectedStatus.is_favorite) { mTwitterWrapper.destroyFavorite(status.account_id, status.status_id); } else { mTwitterWrapper.createFavoriteAsync(status.account_id, status.status_id); } break; } case MENU_DELETE: { mTwitterWrapper.destroyStatus(status.account_id, status.status_id); break; } case MENU_LOAD_FROM_POSITION: { getStatuses(new long[] { status.account_id }, new long[] { status.status_id }, null); break; } case MENU_MULTI_SELECT: { if (!mApplication.isMultiSelectActive()) { mApplication.startMultiSelect(); } final NoDuplicatesLinkedList<Object> list = mApplication.getSelectedItems(); if (!list.contains(status)) { list.add(status); } break; } default: { if (item.getIntent() != null) { try { startActivity(item.getIntent()); } catch (final ActivityNotFoundException e) { Log.w(LOGTAG, e); return false; } } break; } } return true; }
From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java
@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); try {/*w w w .ja v a2 s .c o m*/ outState.putString("Title", Title.getText().toString()); outState.putString("Component", Component.getText().toString()); outState.putString("EventClass", EventClass.getText().toString()); outState.putString("Summary", Summary.getText().toString()); outState.putString("FirstTime", FirstTime.getText().toString()); outState.putString("LastTime", LastTime.getText().toString()); outState.putString("EventCount", EventCount.getText().toString()); outState.putString("agent", agent.getText().toString()); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventFragmentUpdate", "onSaveInstanceState", e); } outState.putStringArray("LogEntries", LogEntries); try { if (isAcknowledged) { outState.putBoolean("eventStateAcknowledged", true); } else { outState.putBoolean("eventStateAcknowledged", false); } } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "onsaveinstance", e); } try { if (img.getDrawable() instanceof android.graphics.drawable.BitmapDrawable) { outState.putParcelable("img", ((BitmapDrawable) img.getDrawable()).getBitmap()); } } catch (ClassCastException cce) { //Don't care } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "onsaveinstance", e); } }