List of usage examples for android.app Activity RESULT_CANCELED
int RESULT_CANCELED
To view the source code for android.app Activity RESULT_CANCELED.
Click Source Link
From source file:org.opendatakit.services.preferences.fragments.DeviceSettingsFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == Activity.RESULT_CANCELED) { // request was canceled, so do nothing return;//w w w.jav a 2s.com } PropertiesSingleton props = ((IOdkAppPropertiesActivity) this.getActivity()).getProps(); String appName = props.getAppName(); switch (requestCode) { case AppPropertiesActivity.SPLASH_IMAGE_CHOOSER: //////////////////// /* * We have chosen a saved image from somewhere, but we really want it to be * in: /sdcard/odk/instances/[current instance]/something.jpg so we copy it * there and insert that copy into the content provider. */ // get gp of chosen file Uri selectedMedia = intent.getData(); String sourceMediaPath = MediaUtils.getPathFromUri(this.getActivity(), selectedMedia, MediaStore.Images.Media.DATA); File sourceMedia = new File(sourceMediaPath); String extension = sourceMediaPath.substring(sourceMediaPath.lastIndexOf(".")); File newMedia; if (!ODKFileUtils.isPathUnderAppName(appName, sourceMedia)) { newMedia = ODKFileUtils.asConfigFile(appName, "splash" + extension); try { FileUtils.copyFile(sourceMedia, newMedia); } catch (IOException e) { WebLogger.getLogger(appName).e(t, "Failed to copy " + sourceMedia.getAbsolutePath()); Toast.makeText(this.getActivity(), R.string.splash_media_save_failed, Toast.LENGTH_SHORT) .show(); // keep the image as a captured image so user can choose it. return; } WebLogger.getLogger(appName).i(t, "copied " + sourceMedia.getAbsolutePath() + " to " + newMedia.getAbsolutePath()); } else { newMedia = sourceMedia; } if (newMedia.exists()) { String appRelativePath = ODKFileUtils.asRelativePath(props.getAppName(), newMedia); props.setProperty(CommonToolProperties.KEY_SPLASH_PATH, appRelativePath); mSplashPathPreference.setSummary(appRelativePath); } } }
From source file:org.fdroid.fdroid.privileged.install.InstallExtensionDialogActivity.java
private void askBeforeInstall() { // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId()); // not support on Android >= 5.1 if (android.os.Build.VERSION.SDK_INT >= 22) { AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme); alertBuilder.setMessage(R.string.system_install_not_supported); alertBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override/*from w ww .j a v a 2 s . c o m*/ public void onClick(DialogInterface dialog, int which) { InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED); InstallExtensionDialogActivity.this.finish(); } }); alertBuilder.create().show(); return; } AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme); alertBuilder.setTitle(R.string.system_install_question); String message = InstallExtension.create(getApplicationContext()).getWarningString(); alertBuilder.setMessage(Html.fromHtml(message)); alertBuilder.setPositiveButton(R.string.system_install_button_install, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { checkRootTask.execute(); } }); alertBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED); InstallExtensionDialogActivity.this.finish(); } }); alertBuilder.create().show(); }
From source file:org.disrupted.rumble.userinterface.fragments.FragmentNetworkDrawer.java
public void manageBTCode(int requestCode, int resultCode, Intent data) { if (!mBound)/* www . ja v a 2s .co m*/ return; if ((requestCode == BluetoothUtil.REQUEST_ENABLE_BT) && (resultCode == Activity.RESULT_OK)) { if (!BluetoothUtil.isDiscoverable()) BluetoothUtil.discoverableBT(getActivity(), 3600); refreshBluetoothController(); return; } if ((requestCode == BluetoothUtil.REQUEST_ENABLE_BT) && (resultCode == Activity.RESULT_CANCELED)) { refreshBluetoothController(); return; } if (requestCode == BluetoothUtil.REQUEST_ENABLE_DISCOVERABLE) { // the resultCode carries the discoverability timeout, // 1 means that we are disabling the discoverability if (resultCode != 1) bluetoothController.setSelected(2); else bluetoothController.setSelected(1); return; } }
From source file:com.foregroundcameraplugin.ForegroundCameraLauncher.java
/** * Called when the camera view exits./*from w ww .j a va2s. c om*/ * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost // during compression ExifHelper exif = new ExifHelper(); exif.createInFile( getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg"); exif.readExifData(); // Read in bitmap of captured image Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri); } catch (FileNotFoundException e) { Uri uri = intent.getData(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } bitmap = scaleBitmap(bitmap); // Create entry in media store for image // (Don't use insertImage() because it uses default compression // setting of 50 - no way to change it) ContentValues values = new ContentValues(); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri = null; try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.failPicture("Error capturing image - no media storage found."); return; } } // Add compressed version of captured image to returned media // store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file exif.createOutFile(getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.callbackContext.success(getRealPathFromURI(uri, this.cordova)); bitmap.recycle(); bitmap = null; System.gc(); checkForDuplicateImage(); } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } }
From source file:com.parse.hangout.MapActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CHECK_SETTINGS: // the case for location change switch (resultCode) { case Activity.RESULT_OK: // All required changes were successfully made Log.i(TAG, "User agreed to make required location settings changes."); break; case Activity.RESULT_CANCELED: // The user was asked to change settings, but chose not to Log.i(TAG, "User chose not to make required location settings changes."); break; default://www .java2 s. c o m break; } break; } }
From source file:fragments.ShowTicket.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case COLOR_PICKER: if (resultCode == Activity.RESULT_OK) { Bundle bundle = data.getExtras(); String color = bundle.getString("color", ""); ticketColor.setText(color);//from www.jav a2 s . co m } else if (resultCode == Activity.RESULT_CANCELED) { ticketColor.setText(""); } break; case SAVE_PICKER: if (resultCode == Activity.RESULT_OK) { Bundle bundle = data.getExtras(); String color = bundle.getString("color", ""); ticketColor.setText(color); } else if (resultCode == Activity.RESULT_CANCELED) { ticketColor.setText(""); } break; } }
From source file:com.remobile.contacts.ContactManager.java
/** * Called when user picks contact./*from w w w.j a v a2 s . com*/ * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). * @throws JSONException */ public void onActivityResult(int requestCode, int resultCode, final Intent intent) { if (requestCode == cordova.CONTACT_PICKER_RESULT) { if (resultCode == Activity.RESULT_OK) { String contactId = intent.getData().getLastPathSegment(); // to populate contact data we require Raw Contact ID // so we do look up for contact raw id first Cursor c = this.cordova.getActivity().getContentResolver().query(RawContacts.CONTENT_URI, new String[] { RawContacts._ID }, RawContacts.CONTACT_ID + " = " + contactId, null, null); if (!c.moveToFirst()) { this.callbackContext.error("Error occured while retrieving contact raw id"); return; } String id = c.getString(c.getColumnIndex(RawContacts._ID)); c.close(); try { JSONObject contact = contactAccessor.getContactById(id); this.callbackContext.success(contact); return; } catch (JSONException e) { Log.e(LOG_TAG, "JSON fail.", e); } } else if (resultCode == Activity.RESULT_CANCELED) { this.callbackContext .sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT, UNKNOWN_ERROR)); return; } this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR)); } }
From source file:info.guardianproject.iocipher.camera.VideoCameraActivity.java
@Override public void onPictureTaken(final byte[] data, Camera camera) { File fileSecurePicture;//from www .j a v a 2 s. c o m try { overlayView.setBackgroundResource(R.color.flash); long mTime = System.currentTimeMillis(); fileSecurePicture = new File(mFileBasePath, "secure_image_" + mTime + ".jpg"); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileSecurePicture)); out.write(data); out.flush(); out.close(); mResultList.add(fileSecurePicture.getAbsolutePath()); Intent intent = new Intent("new-media"); // You can also include some extra data. intent.putExtra("media", fileSecurePicture.getAbsolutePath()); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); Intent intentResult = new Intent().putExtra(MediaStore.EXTRA_OUTPUT, mResultList.toArray(new String[mResultList.size()])); setResult(Activity.RESULT_OK, intentResult); view.postDelayed(new Runnable() { @Override public void run() { overlayView.setBackgroundColor(Color.TRANSPARENT); resumePreview(); } }, 100); } catch (Exception e) { e.printStackTrace(); setResult(Activity.RESULT_CANCELED); } }
From source file:com.groundupworks.wings.gcp.GoogleCloudPrintSettingsActivity.java
@Override public void onRetryAuthentication() { Toast.makeText(getApplicationContext(), R.string.wings_gcp__settings__error_authenticate, Toast.LENGTH_SHORT).show();//from ww w.ja v a2 s .co m setResult(Activity.RESULT_CANCELED); finish(); }
From source file:org.opendatakit.survey.activities.MediaCaptureImageActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (resultCode == Activity.RESULT_CANCELED) { // request was canceled -- propagate setResult(Activity.RESULT_CANCELED); finish();/*from w ww .j av a 2s.c o m*/ return; } if (uriFragmentToMedia == null) { // we are in trouble WebLogger.getLogger(appName).e(t, "Unexpectedly null uriFragmentToMedia!"); setResult(Activity.RESULT_CANCELED); finish(); return; } if (uriFragmentNewFileBase == null) { // we are in trouble WebLogger.getLogger(appName).e(t, "Unexpectedly null newFileBase!"); setResult(Activity.RESULT_CANCELED); finish(); return; } File f = ODKFileUtils.getRowpathFile(appName, tableId, instanceId, uriFragmentToMedia); Uri mediaUri = Uri.fromFile(f); // we never have to deal with deleting, as the Camera is overwriting // this... // get the file path and create a copy in the instance folder String binaryPath = MediaUtils.getPathFromUri(this, (Uri) mediaUri, Images.Media.DATA); String extension = binaryPath.substring(binaryPath.lastIndexOf(".")); File source = new File(binaryPath); File sourceMedia = ODKFileUtils.getRowpathFile(appName, tableId, instanceId, uriFragmentNewFileBase + extension); try { FileUtils.copyFile(source, sourceMedia); } catch (IOException e) { WebLogger.getLogger(appName).e(t, ERROR_COPY_FILE + sourceMedia.getAbsolutePath()); Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show(); setResult(Activity.RESULT_CANCELED); finish(); return; } if (sourceMedia.exists()) { // Add the copy to the content provier ContentValues values = new ContentValues(6); values.put(Audio.Media.TITLE, sourceMedia.getName()); values.put(Audio.Media.DISPLAY_NAME, sourceMedia.getName()); values.put(Audio.Media.DATE_ADDED, System.currentTimeMillis()); values.put(Audio.Media.DATA, sourceMedia.getAbsolutePath()); Uri MediaURI = getApplicationContext().getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values); WebLogger.getLogger(appName).i(t, "Inserting IMAGE returned uri = " + MediaURI.toString()); if (uriFragmentToMedia != null) { deleteMedia(); } uriFragmentToMedia = ODKFileUtils.asRowpathUri(appName, tableId, instanceId, sourceMedia); WebLogger.getLogger(appName).i(t, "Setting current answer to " + sourceMedia.getAbsolutePath()); } else { if (uriFragmentToMedia != null) { deleteMedia(); } uriFragmentToMedia = null; WebLogger.getLogger(appName).e(t, "Inserting Image file FAILED"); } /* * We saved the image to the instance directory. Verify that it is there... */ returnResult(); return; }