List of usage examples for android.os Bundle getStringArray
@Nullable
public String[] getStringArray(@Nullable String key)
From source file:net.potterpcs.recipebook.DirectionsEditor.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { activity = (RecipeEditor) getActivity(); long rid = activity.getRecipeId(); directions = new ArrayList<String>(); photoUris = new ArrayList<String>(); currentDirection = -1;/* w ww.j a v a2 s.c o m*/ currentPhoto = null; if (savedInstanceState != null) { // Load from the saved state if possible String[] savedDirections = savedInstanceState.getStringArray(STATE_DIRS); String[] savedUris = savedInstanceState.getStringArray(STATE_PHOTOS); if (savedDirections != null) { directions.addAll(Arrays.asList(savedDirections)); } if (savedUris != null) { photoUris.addAll(Arrays.asList(savedUris)); } } else { // There's no saved state, so we can load a recipe from the database // if needed, or start a new one. if (rid > 0) { // Load an existing recipe for editing RecipeBook app = (RecipeBook) activity.getApplication(); Cursor c = app.getData().getRecipeDirections(rid); c.moveToFirst(); while (!c.isAfterLast()) { String value = c.getString(c.getColumnIndex(RecipeData.DT_STEP)); directions.add(value); String photo = c.getString(c.getColumnIndex(RecipeData.DT_PHOTO)); photoUris.add(photo); c.moveToNext(); } c.close(); } else { // Start a new recipe (this requires no extra setup) } } adapter = new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1, directions); return inflater.inflate(R.layout.directionsedit, container, false); }
From source file:org.opendatakit.scan.services.ProcessFormsService.java
@Override public void onHandleIntent(Intent intent) { Log.i(LOG_TAG, "Handling Intent to process form"); // Retrieve input parameters final Bundle extras = intent.getExtras(); if (extras == null) { Log.e(LOG_TAG, this.getString(R.string.error_background_exception)); Log.e(LOG_TAG, this.getString(R.string.error_missing_intent)); return;// w ww . j a va 2s. c o m } final String[] templatePaths = extras.getStringArray("templatePaths"); if (templatePaths == null) { Log.e(LOG_TAG, this.getString(R.string.error_background_exception)); Log.e(LOG_TAG, this.getString(R.string.error_missing_template_paths)); return; } String photoName = extras.getString("photoName", null); if (photoName == null) { Log.e(LOG_TAG, this.getString(R.string.error_missing_photo_name)); } final int requestCode = extras.getInt("opCode", -1); if (requestCode == -1) { Log.e(LOG_TAG, this.getString(R.string.error_background_exception)); Log.e(LOG_TAG, this.getString(R.string.error_missing_op_code)); return; } String uriString = extras.getString("uri", null); Uri uri = null; if (uriString == null) { Log.d(LOG_TAG, this.getString(R.string.error_missing_uri)); } else { uri = Uri.parse(uriString); } final boolean isRecursive = extras.getBoolean("isRecursive", false); // Switch on the types of form processing requests. No matter which is chosen we will create // our JSONConfig and run the processForm() method JSONObject configJSON; File destFile; try { switch (requestCode) { case R.integer.new_image: Log.i(LOG_TAG, this.getString(R.string.acquired_from_camera)); if (photoName == null) { Log.e(LOG_TAG, this.getString(R.string.error_photo_name_not_found)); return; } // Verify that the new picture exists destFile = new File(ScanUtils.getPhotoPath(photoName)); if (!destFile.exists()) { Log.e(LOG_TAG, this.getString(R.string.error_file_creation)); return; } extras.putString("photoName", photoName); try { configJSON = prepareConfig(templatePaths, photoName); } catch (Exception e) { Log.e(LOG_TAG, this.getString(R.string.error_failed_create_config)); return; } processForm(extras, configJSON); break; case R.integer.existing_image: Log.d(LOG_TAG, this.getString(R.string.acquired_from_file_picker)); if (uri == null) { Log.e(LOG_TAG, this.getString(R.string.error_uri_not_found)); return; } // Verify that the new file exists and is an image Log.d(LOG_TAG, "File Uri Selected: " + uri.toString()); File sourceFile = new File(uri.getPath()); if (!sourceFile.exists() || !ScanUtils.imageFilter.accept(sourceFile, uri.toString())) { Log.d(LOG_TAG, this.getString(R.string.error_finding_file)); return; } photoName = ScanUtils.setPhotoName(templatePaths); ScanUtils.prepareOutputDir(photoName); extras.putString("photoName", photoName); // Copy the new file into the Scan file system destFile = new File(ScanUtils.getPhotoPath(photoName)); FileUtils.copyFile(sourceFile, destFile); try { configJSON = prepareConfig(templatePaths, photoName); } catch (Exception e) { Log.e(LOG_TAG, this.getString(R.string.error_failed_create_config)); return; } processForm(extras, configJSON); break; case R.integer.image_directory: Log.d(LOG_TAG, this.getString(R.string.acquired_from_folder_picker)); if (uri == null) { Log.e(LOG_TAG, this.getString(R.string.error_uri_not_found)); return; } // Validate the directory File dir = new File(uri.getPath()); if (!dir.exists() || !dir.isDirectory()) { Log.e(LOG_TAG, this.getString(R.string.error_finding_dir)); return; } processImagesInFolder(dir, isRecursive, templatePaths, extras); break; default: Log.e(LOG_TAG, this.getString(R.string.error_acquire_bad_return)); return; } } catch (Exception e) { Log.e(LOG_TAG, e.toString()); return; } }
From source file:com.bydavy.card.receipts.activities.ReceiptPagerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_receipt_pager); mLoadingView = findViewById(R.id.loading_container); mContentView = findViewById(R.id.content_container); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mReceiptPagerFragment = (ReceiptPagerFragment) getSupportFragmentManager() .findFragmentById(FRAGMENT_PAGER_FRAGMENT_ID); if (mReceiptPagerFragment == null) { final Bundle bundle = getIntent().getExtras(); if (bundle == null) { LogHelper.e(ErrorID.EXTRA_IS_NULL, "Attempt to open " + ReceiptPagerActivity.class.getName() + " without extras in intent", null);/*www .j av a 2 s . c o m*/ finish(); return; } // Load data from the intent final int index = bundle.getInt(INTENT_BUNDLE_INDEX); final String selection = bundle.getString(INTENT_BUNDLE_CURSOR_SELECTION); final String[] selectionArgs = bundle.getStringArray(INTENT_BUNDLE_CURSOR_SELECTION_ARGS); final String sortOrder = bundle.getString(INTENT_BUNDLE_CURSOR_SORT_ORDER); // Create the fragment mReceiptPagerFragment = ReceiptPagerFragment.newInstance(index, selection, selectionArgs, sortOrder); // Publish the fragment final FragmentTransaction fm = getSupportFragmentManager().beginTransaction(); fm.add(FRAGMENT_PAGER_FRAGMENT_ID, mReceiptPagerFragment); fm.commit(); } mReceiptPagerFragment.setStateListener(this, true); // If Landscape && screen lize >= Large, finish the activity if ((getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) && AndroidUtils.isScreenSizeBiggerOrEqual(getResources(), Configuration.SCREENLAYOUT_SIZE_LARGE)) { setActivityResult(); finish(); } }
From source file:com.s16.picker.colorpicker.ColorPickerDialog.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mTitleResId = getArguments().getInt(KEY_TITLE_ID); mColumns = getArguments().getInt(KEY_COLUMNS); mSize = getArguments().getInt(KEY_SIZE); }/*w w w .j ava 2 s .co m*/ if (savedInstanceState != null) { mColors = savedInstanceState.getIntArray(KEY_COLORS); mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR); mColorContentDescriptions = savedInstanceState.getStringArray(KEY_COLOR_CONTENT_DESCRIPTIONS); } }
From source file:net.xpece.android.colorpicker.ColorPickerDialog.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mTitleResId = getArguments().getInt(KEY_TITLE_ID); mColumns = getArguments().getInt(KEY_COLUMNS); //noinspection WrongConstant mSize = getArguments().getInt(KEY_SIZE); }//from w w w . ja v a 2 s . co m if (savedInstanceState != null) { mColors = savedInstanceState.getIntArray(KEY_COLORS); mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR); mColorContentDescriptions = savedInstanceState.getStringArray(KEY_COLOR_CONTENT_DESCRIPTIONS); } }
From source file:de.unipassau.isl.evs.ssh.app.activity.EditUserDeviceFragment.java
/** * Creates and shows a dialogs that gives the user the option to edit a group. *//*ww w. jav a 2 s. c o m*/ private void showEditUserDeviceDialog(Bundle bundle) { final UserDevice userDevice = (UserDevice) bundle.getSerializable(EDIT_USERDEVICE_DIALOG); if (userDevice == null) { Log.i(TAG, "No device found."); return; } final String[] groupNames = bundle.getStringArray(ALL_GROUPS_DIALOG); if (groupNames == null) { Log.i(TAG, "Empty bundle"); return; } final AppUserConfigurationHandler handler = getComponent(AppUserConfigurationHandler.KEY); if (handler == null) { Log.i(TAG, "Container not yet connected!"); return; } final LayoutInflater inflater = getActivity().getLayoutInflater(); final View dialogView = inflater.inflate(R.layout.dialog_edituserdevice, null); final TextView title = (TextView) dialogView.findViewById(R.id.editdevicedialog_title); title.setText(String.format(getResources().getString(R.string.edit_user_device), userDevice.getName())); final EditText userDeviceName = (EditText) dialogView.findViewById(R.id.editdevicedialog_username); userDeviceName.setText(userDevice.getName()); final ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, groupNames); final Spinner groupName = ((Spinner) dialogView.findViewById(R.id.editdevicedialog_spinner)); groupName.setAdapter(adapter); groupName.setSelection(adapter.getPosition(userDevice.getInGroup())); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final Resources res = getResources(); final AlertDialog editDialog = builder.setView(dialogView).setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.edit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { final AppMainActivity activity = (AppMainActivity) getActivity(); if (activity.hasPermission(Permission.CHANGE_USER_NAME) && activity.hasPermission(Permission.CHANGE_USER_GROUP)) { String name = userDeviceName.getText().toString(); String group = ((String) groupName.getSelectedItem()); DeviceID userDeviceID = userDevice.getUserDeviceID(); // no permission check as method only gets called when user can edit user name / user group handler.setUserName(userDeviceID, name); handler.setUserGroup(userDeviceID, group); } else { showToast(R.string.you_can_not_edit_user_devices); } } }).setNeutralButton(R.string.remove, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (((AppMainActivity) getActivity()).hasPermission(Permission.DELETE_USER)) { handler.removeUserDevice(userDevice.getUserDeviceID()); String toastText = String.format(res.getString(R.string.device_removed), userDevice.getName()); Toast.makeText(getActivity(), toastText, Toast.LENGTH_SHORT).show(); } else { showToast(R.string.you_can_not_remove_users); } } }).create(); // open the soft keyboard when dialog gets focused userDeviceName.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { editDialog.getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); editDialog.show(); userDeviceName.requestFocus(); }
From source file:org.lol.reddit.fragments.CommentListingFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { // TODO load position/etc? super.onCreate(savedInstanceState); setHasOptionsMenu(true);//from ww w .jav a 2 s. c o m final Bundle arguments = getArguments(); final String[] urls = arguments.getStringArray("urls"); mAllUrls = new ArrayList<RedditURLParser.RedditURL>(urls.length); for (final String url : urls) { final RedditURLParser.RedditURL redditURL = RedditURLParser.parseProbableCommentListing(Uri.parse(url)); if (redditURL != null) { mAllUrls.add(redditURL); } } mUrlsToDownload = new LinkedList<RedditURLParser.RedditURL>(mAllUrls); if (arguments.containsKey("session")) { session = UUID.fromString(arguments.getString("session")); } downloadType = CacheRequest.DownloadType.valueOf(arguments.getString("downloadType")); mUser = RedditAccountManager.getInstance(getSupportActivity()).getDefaultAccount(); getSupportActivity().invalidateOptionsMenu(); }
From source file:android.support.content.ContentPager.java
/** * @return true if the cursor extras contains all of the signs of being paged. * Technically we could also check SDK version since facilities for paging * were added in SDK 26, but if it looks like a duck and talks like a duck * itsa duck (especially if it helps with testing). *//*ww w . j a v a 2s . c o m*/ @WorkerThread private boolean isProviderPaged(Cursor cursor) { Bundle extras = cursor.getExtras(); extras = extras != null ? extras : Bundle.EMPTY; String[] honoredArgs = extras.getStringArray(EXTRA_HONORED_ARGS); return (extras.containsKey(EXTRA_TOTAL_COUNT) && honoredArgs != null && contains(honoredArgs, QUERY_ARG_OFFSET) && contains(honoredArgs, QUERY_ARG_LIMIT)); }
From source file:org.xdty.preference.colorpicker.ColorPickerDialog.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mTitleResId = getArguments().getInt(KEY_TITLE_ID); mColumns = getArguments().getInt(KEY_COLUMNS); mSize = getArguments().getInt(KEY_SIZE); key = getArguments().getString("key"); }/*from ww w .ja va 2 s. co m*/ if (savedInstanceState != null) { mColors = savedInstanceState.getIntArray(KEY_COLORS); mSelectedColor = savedInstanceState.getInt(KEY_SELECTED_COLOR); mColorContentDescriptions = savedInstanceState.getStringArray(KEY_COLOR_CONTENT_DESCRIPTIONS); key = savedInstanceState.getString("key"); } }
From source file:com.ultramegasoft.flavordex2.dialog.FileSelectorDialog.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = getContext(); if (context == null) { return;// www. j a v a 2 s .c om } final Bundle args = getArguments(); if (args != null) { mPath = args.getString(ARG_PATH); mRootPath = args.getString(ARG_ROOT_PATH); mAllowDirectories = args.getBoolean(ARG_ALLOW_DIRECTORIES, false); mNameFilter = args.getStringArray(ARG_NAME_FILTER); if (mNameFilter != null) { for (int i = 0; i < mNameFilter.length; i++) { mNameFilter[i] = mNameFilter[i].toLowerCase(); } } } if (savedInstanceState != null) { mPath = savedInstanceState.getString(STATE_PATH, mPath); } if (mRootPath == null) { mRootPath = Environment.getExternalStorageDirectory().getPath(); } if (mPath == null) { mPath = mRootPath; } if (!new File(mPath).canRead()) { Toast.makeText(context, R.string.error_read_dir, Toast.LENGTH_LONG).show(); dismiss(); return; } mAdapter = new FileListAdapter(context); }