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.survey.activities.MediaCaptureVideoActivity.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();// w ww .ja va2s .c o m return; } Uri mediaUri = intent.getData(); // it is unclear whether getData() always returns a value or if // getDataString() does... String str = intent.getDataString(); if (mediaUri == null && str != null) { WebLogger.getLogger(appName).w(t, "Attempting to work around null mediaUri"); mediaUri = Uri.parse(str); } if (mediaUri == null) { // we are in trouble WebLogger.getLogger(appName).e(t, "No uri returned from ACTION_CAPTURE_VIDEO!"); setResult(Activity.RESULT_CANCELED); finish(); return; } // Remove the current media. deleteMedia(); // get the file path and create a copy in the instance folder String binaryPath = MediaUtils.getPathFromUri(this, (Uri) mediaUri, Video.Media.DATA); File source = new File(binaryPath); String extension = binaryPath.substring(binaryPath.lastIndexOf(".")); if (uriFragmentToMedia == null) { // use the newFileBase as a starting point... uriFragmentToMedia = uriFragmentNewFileBase + extension; } // adjust the mediaPath (destination) to have the same extension // and delete any existing file. File f = ODKFileUtils.getRowpathFile(appName, tableId, instanceId, uriFragmentToMedia); File sourceMedia = new File(f.getParentFile(), f.getName().substring(0, f.getName().lastIndexOf('.')) + extension); uriFragmentToMedia = ODKFileUtils.asRowpathUri(appName, tableId, instanceId, sourceMedia); deleteMedia(); 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(); deleteMedia(); setResult(Activity.RESULT_CANCELED); finish(); return; } if (sourceMedia.exists()) { // Add the copy to the content provier ContentValues values = new ContentValues(6); values.put(Video.Media.TITLE, sourceMedia.getName()); values.put(Video.Media.DISPLAY_NAME, sourceMedia.getName()); values.put(Video.Media.DATE_ADDED, System.currentTimeMillis()); values.put(Video.Media.DATA, sourceMedia.getAbsolutePath()); Uri MediaURI = getApplicationContext().getContentResolver().insert(Video.Media.EXTERNAL_CONTENT_URI, values); WebLogger.getLogger(appName).i(t, "Inserting VIDEO returned uri = " + MediaURI.toString()); uriFragmentToMedia = ODKFileUtils.asRowpathUri(appName, tableId, instanceId, sourceMedia); WebLogger.getLogger(appName).i(t, "Setting current answer to " + sourceMedia.getAbsolutePath()); // Need to have this ugly code to account for // a bug in the Nexus 7 on 4.3 not returning the mediaUri in the data // of the intent - uri in this case is a file int delCount = 0; if (NEXUS7.equals(android.os.Build.MODEL) && Build.VERSION.SDK_INT == 18) { File fileToDelete = new File(mediaUri.getPath()); delCount = fileToDelete.delete() ? 1 : 0; } else { delCount = getApplicationContext().getContentResolver().delete(mediaUri, null, null); } WebLogger.getLogger(appName).i(t, "Deleting original capture of file: " + mediaUri.toString() + " count: " + delCount); } else { WebLogger.getLogger(appName).e(t, "Inserting Video file FAILED"); } /* * We saved the audio to the instance directory. Verify that it is there... */ returnResult(); return; }
From source file:com.coloreight.plugin.socialAuth.SocialAuth.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); fbCallbackManager.onActivityResult(requestCode, resultCode, intent); if (requestCode == SocialAuth.TWITTER_OAUTH_REQUEST) { if (resultCode == Activity.RESULT_OK) { Log.v(TAG, "On activity result with authtoken: " + intent.getExtras().keySet()); for (String key : intent.getExtras().keySet()) { Object value = intent.getExtras().get(key); try { String valueStr = value.toString(); Log.v("AUTH", String.format("%s %s (%s)", key, valueStr, value.getClass().getName())); } catch (NullPointerException e) { Log.v(TAG, e.getMessage()); }// ww w.ja v a 2 s . c om } this.getTwitterSystemAccount(this.requestedTwitterAccountName, callbackContext); } else if (resultCode == Activity.RESULT_CANCELED) { callbackContext.error("Twitter auth activity canceled"); } } }
From source file:com.groundupworks.wings.gcp.GoogleCloudPrintSettingsActivity.java
@Override public void onAccountSelectionCanceled() { setResult(Activity.RESULT_CANCELED); finish(); }
From source file:org.chromium.chrome.browser.firstrun.FirstRunActivity.java
@Override public void abortFirstRunExperience() { Intent intent = new Intent(); if (mFreProperties != null) intent.putExtras(mFreProperties); intent.putExtra(RESULT_CLOSE_APP, true); finishAllFREActivities(Activity.RESULT_CANCELED, intent); }
From source file:org.cloudsky.cordovaPlugins.BarcodeminCDV.java
/** * Called when the barcode scanner intent completes. * * @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"). *///from w w w. j av a 2 s. c o m @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { String res = ""; if (requestCode == REQUEST_CODE && this.callbackContext != null) { if (resultCode == Activity.RESULT_OK) { JSONObject obj = new JSONObject(); try { obj.put(TEXT, intent.getStringExtra("SCAN_RESULT")); obj.put(FORMAT, intent.getStringExtra("SCAN_RESULT_FORMAT")); obj.put(CANCELLED, false); res = intent.getStringExtra("SCAN_RESULT"); } catch (JSONException e) { Log.d(LOG_TAG, "This should never happen"); } //this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback); this.callbackContext.success(res); } else if (resultCode == Activity.RESULT_CANCELED) { JSONObject obj = new JSONObject(); try { obj.put(TEXT, ""); obj.put(FORMAT, ""); obj.put(CANCELLED, true); } catch (JSONException e) { Log.d(LOG_TAG, "This should never happen"); } //this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback); this.callbackContext.success(res); } else { //this.error(new PluginResult(PluginResult.Status.ERROR), this.callback); this.callbackContext.error("Unexpected error"); } } }
From source file:com.armtimes.activities.SingleArticlePreviewActivity.java
@Override public void onSingleArticleDownloadCompleted(final ArticleInfo articleInfo) { if (progressDialog != null) { progressDialog.dismissAllowingStateLoss(); progressDialog = null;/*from ww w. ja va 2s. com*/ } // Finish current activity if Description or Title // are missing, missing of image is not a case to // finish activity. if (articleInfo == null) { Toast.makeText(getApplicationContext(), R.string.cant_show_news_data_missing, Toast.LENGTH_LONG).show(); setResult(Activity.RESULT_CANCELED); finish(); return; } // Title comes from the Database and it should be there // as it is downloaded at first phase from RSS. String title = getIntent().getStringExtra(EXTRA_TITLE); if (title == null || title.isEmpty()) { Toast.makeText(getApplicationContext(), R.string.cant_show_news_data_missing, Toast.LENGTH_LONG).show(); setResult(Activity.RESULT_CANCELED); finish(); return; } String description = articleInfo.getDescription(); if (description == null || description.isEmpty()) { Toast.makeText(getApplicationContext(), R.string.cant_show_news_data_missing, Toast.LENGTH_LONG).show(); setResult(Activity.RESULT_CANCELED); finish(); return; } // If news article information was successfully downloaded, // and shown to the user - update database by setting given // news item read state to TRUE. try { // Get current table name, in which information for given // article must be updated. final String table = getIntent().getStringExtra(EXTRA_CATEGORY).toUpperCase(); // Create Database helper object. NewsDatabaseHelper helper = new NewsDatabaseHelper(getApplicationContext()); SQLiteDatabase database = helper.getWritableDatabase(); // Create data which must be updated. ContentValues cv = new ContentValues(); cv.put(NewsContract.COL_NAME_NEWS_IS_READ, 1); // Update appropriate field in database. database.update(table, cv, String.format("%s=\"%s\"", NewsContract.COL_NAME_NEWS_URL, articleInfo.url), null); // Close database database.close(); helper.close(); } catch (Exception ex) { Logger.e(TAG, "Exception occurs while trying to Update database!"); } // Set layout Visible. layoutMain.setVisibility(View.VISIBLE); textTitle.setText(title.trim()); textDescription.setText(Html.fromHtml(articleInfo.getDescription())); // Try to set image if it exists. InputStream is = null; try { is = new FileInputStream(new File(articleInfo.getMainImagePath())); imageBanner.setImageBitmap(BitmapFactory.decodeStream(is)); imageBanner.setScaleType(ImageView.ScaleType.CENTER_CROP); } catch (IOException ex) { imageBanner.setScaleType(ImageView.ScaleType.CENTER); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { Logger.e(TAG, "Error occurs while trying to close Banner Image Stream."); } } } setResult(Activity.RESULT_OK); }
From source file:com.fastbootmobile.encore.app.tv.TvSearchFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (DEBUG)//from w w w. ja v a2s. c o m Log.v(TAG, "onActivityResult requestCode=" + requestCode + " resultCode=" + resultCode + " data=" + data); switch (requestCode) { case REQUEST_SPEECH: switch (resultCode) { case Activity.RESULT_OK: setSearchQuery(data, true); break; case Activity.RESULT_CANCELED: // Once recognizer canceled, user expects the current activity to process // the same BACK press as user doesn't know about overlay activity. // However, you may not want this behaviour as it makes harder to // fall back to keyboard input. if (FINISH_ON_RECOGNIZER_CANCELED) { if (!hasResults()) { if (DEBUG) Log.v(TAG, "Delegating BACK press from recognizer"); getActivity().onBackPressed(); } } break; // the rest includes various recognizer errors, see {@link RecognizerIntent} } break; } }
From source file:com.groundupworks.wings.gcp.GoogleCloudPrintSettingsActivity.java
@Override public void onAuthenticationError(final Throwable throwable) { Toast.makeText(getApplicationContext(), R.string.wings_gcp__settings__error_authenticate, Toast.LENGTH_SHORT).show();// w w w .j a v a 2s.c o m setResult(Activity.RESULT_CANCELED); finish(); }
From source file:net.mutina.uclimb.ForegroundCameraLauncher.java
/** * Called when the camera view exits. //from ww w . j ava 2s .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"). */ 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(ctx.getContext()) + "/Pic.jpg"); exif.readExifData(); // Read in bitmap of captured image Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri); } catch (FileNotFoundException e) { Uri uri = intent.getData(); android.content.ContentResolver resolver = this.ctx.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.ctx.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.ctx.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.ctx.getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file exif.createOutFile(getRealPathFromURI(uri, this.ctx)); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); 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.sourceallies.android.zonebeacon.activity.TransferActivityTest.java
@Test public void test_onActivityResult_cancelled() { activity.setResolvingError(true);//from w ww . j a v a2 s . c om activity.onActivityResult(1, Activity.RESULT_CANCELED, null); assertFalse(activity.isResolvingError()); assertTrue(activity.isFinishing()); }