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.MediaChooseAudioActivity.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 w w . j a va 2 s .com*/ return; } /* * We have chosen a saved audio clip from somewhere, but we really want it * to be in: /sdcard/odk/instances/[current instance]/something.3gpp 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, selectedMedia, Audio.Media.DATA); File sourceMedia = new File(sourceMediaPath); String extension = sourceMediaPath.substring(sourceMediaPath.lastIndexOf(".")); File newMedia = ODKFileUtils.getRowpathFile(appName, tableId, instanceId, uriFragmentNewFileBase + extension); try { FileUtils.copyFile(sourceMedia, newMedia); } catch (IOException e) { WebLogger.getLogger(appName).e(t, "Failed to copy " + sourceMedia.getAbsolutePath()); Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show(); // keep the image as a captured image so user can choose it. setResult(Activity.RESULT_CANCELED); finish(); return; } WebLogger.getLogger(appName).i(t, "copied " + sourceMedia.getAbsolutePath() + " to " + newMedia.getAbsolutePath()); Uri mediaURI = null; if (newMedia.exists()) { // Add the new image to the Media content provider so that the // viewing is fast in Android 2.0+ ContentValues values = new ContentValues(6); values.put(Audio.Media.TITLE, newMedia.getName()); values.put(Audio.Media.DISPLAY_NAME, newMedia.getName()); values.put(Audio.Media.DATE_ADDED, System.currentTimeMillis()); values.put(Audio.Media.MIME_TYPE, MEDIA_CLASS + extension.substring(1)); values.put(Audio.Media.DATA, newMedia.getAbsolutePath()); mediaURI = getContentResolver().insert(Audio.Media.EXTERNAL_CONTENT_URI, values); WebLogger.getLogger(appName).i(t, "Insert " + MEDIA_CLASS + " returned uri = " + mediaURI.toString()); // if you are replacing an answer. delete the previous image using // the // content provider. String binarypath = MediaUtils.getPathFromUri(this, mediaURI, Audio.Media.DATA); File newMediaFromCP = new File(binarypath); WebLogger.getLogger(appName).i(t, "Return mediaFile: " + newMediaFromCP.getAbsolutePath()); Intent i = new Intent(); i.putExtra(IntentConsts.INTENT_KEY_URI_FRAGMENT, ODKFileUtils.asRowpathUri(appName, tableId, instanceId, newMediaFromCP)); String name = newMediaFromCP.getName(); i.putExtra(IntentConsts.INTENT_KEY_CONTENT_TYPE, MEDIA_CLASS + name.substring(name.lastIndexOf(".") + 1)); setResult(Activity.RESULT_OK, i); finish(); } else { WebLogger.getLogger(appName).e(t, "No " + MEDIA_CLASS + " exists at: " + newMedia.getAbsolutePath()); Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show(); setResult(Activity.RESULT_CANCELED); finish(); } }
From source file:org.opendatakit.survey.activities.MediaChooseVideoActivity.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();/* ww w. java 2 s.c o m*/ return; } /* * We have chosen a saved audio clip from somewhere, but we really want it * to be in: /sdcard/odk/instances/[current instance]/something.3gpp 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, selectedMedia, Video.Media.DATA); File sourceMedia = new File(sourceMediaPath); String extension = sourceMediaPath.substring(sourceMediaPath.lastIndexOf(".")); File newMedia = ODKFileUtils.getRowpathFile(appName, tableId, instanceId, uriFragmentNewFileBase + extension); try { FileUtils.copyFile(sourceMedia, newMedia); } catch (IOException e) { WebLogger.getLogger(appName).e(t, "Failed to copy " + sourceMedia.getAbsolutePath()); Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show(); // keep the image as a captured image so user can choose it. setResult(Activity.RESULT_CANCELED); finish(); return; } WebLogger.getLogger(appName).i(t, "copied " + sourceMedia.getAbsolutePath() + " to " + newMedia.getAbsolutePath()); Uri mediaURI = null; if (newMedia.exists()) { // Add the new image to the Media content provider so that the // viewing is fast in Android 2.0+ ContentValues values = new ContentValues(6); values.put(Video.Media.TITLE, newMedia.getName()); values.put(Video.Media.DISPLAY_NAME, newMedia.getName()); values.put(Video.Media.DATE_ADDED, System.currentTimeMillis()); values.put(Video.Media.MIME_TYPE, MEDIA_CLASS + extension.substring(1)); values.put(Video.Media.DATA, newMedia.getAbsolutePath()); mediaURI = getContentResolver().insert(Video.Media.EXTERNAL_CONTENT_URI, values); WebLogger.getLogger(appName).i(t, "Insert " + MEDIA_CLASS + " returned uri = " + mediaURI.toString()); // if you are replacing an answer. delete the previous image using // the // content provider. String binarypath = MediaUtils.getPathFromUri(this, mediaURI, Video.Media.DATA); File newMediaFromCP = new File(binarypath); WebLogger.getLogger(appName).i(t, "Return mediaFile: " + newMediaFromCP.getAbsolutePath()); Intent i = new Intent(); i.putExtra(IntentConsts.INTENT_KEY_URI_FRAGMENT, ODKFileUtils.asRowpathUri(appName, tableId, instanceId, newMediaFromCP)); String name = newMediaFromCP.getName(); i.putExtra(IntentConsts.INTENT_KEY_CONTENT_TYPE, MEDIA_CLASS + name.substring(name.lastIndexOf(".") + 1)); setResult(Activity.RESULT_OK, i); finish(); } else { WebLogger.getLogger(appName).e(t, "No " + MEDIA_CLASS + " exists at: " + newMedia.getAbsolutePath()); Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show(); setResult(Activity.RESULT_CANCELED); finish(); } }
From source file:org.opendatakit.survey.activities.MediaChooseImageActivity.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 . jav a 2s . c om*/ return; } /* * 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, selectedMedia, Images.Media.DATA); File sourceMedia = new File(sourceMediaPath); String extension = sourceMediaPath.substring(sourceMediaPath.lastIndexOf(".")); File newMedia = ODKFileUtils.getRowpathFile(appName, tableId, instanceId, uriFragmentNewFileBase + extension); try { FileUtils.copyFile(sourceMedia, newMedia); } catch (IOException e) { WebLogger.getLogger(appName).e(t, "Failed to copy " + sourceMedia.getAbsolutePath()); Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show(); // keep the image as a captured image so user can choose it. setResult(Activity.RESULT_CANCELED); finish(); return; } WebLogger.getLogger(appName).i(t, "copied " + sourceMedia.getAbsolutePath() + " to " + newMedia.getAbsolutePath()); Uri mediaURI = null; if (newMedia.exists()) { // Add the new image to the Media content provider so that the // viewing is fast in Android 2.0+ ContentValues values = new ContentValues(6); values.put(Images.Media.TITLE, newMedia.getName()); values.put(Images.Media.DISPLAY_NAME, newMedia.getName()); values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis()); values.put(Images.Media.MIME_TYPE, MEDIA_CLASS + extension.substring(1)); values.put(Images.Media.DATA, newMedia.getAbsolutePath()); mediaURI = getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values); WebLogger.getLogger(appName).i(t, "Insert " + MEDIA_CLASS + " returned uri = " + mediaURI.toString()); // if you are replacing an answer. delete the previous image using // the // content provider. String binarypath = MediaUtils.getPathFromUri(this, mediaURI, Images.Media.DATA); File newMediaFromCP = new File(binarypath); WebLogger.getLogger(appName).i(t, "Return mediaFile: " + newMediaFromCP.getAbsolutePath()); Intent i = new Intent(); i.putExtra(IntentConsts.INTENT_KEY_URI_FRAGMENT, ODKFileUtils.asRowpathUri(appName, tableId, instanceId, newMediaFromCP)); String name = newMediaFromCP.getName(); i.putExtra(IntentConsts.INTENT_KEY_CONTENT_TYPE, MEDIA_CLASS + name.substring(name.lastIndexOf(".") + 1)); setResult(Activity.RESULT_OK, i); finish(); } else { WebLogger.getLogger(appName).e(t, "No " + MEDIA_CLASS + " exists at: " + newMedia.getAbsolutePath()); Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show(); setResult(Activity.RESULT_CANCELED); finish(); } }
From source file:jahirfiquitiva.iconshowcase.adapters.IconsAdapter.java
private void iconClick(int position) { int resId = iconsList.get(position).getResId(); String name = iconsList.get(position).getName().toLowerCase(Locale.getDefault()); if (ShowcaseActivity.iconsPicker) { Intent intent = new Intent(); Bitmap bitmap = null;//from w ww. ja v a2 s . c o m try { bitmap = BitmapFactory.decodeResource(context.getResources(), resId); } catch (Exception e) { if (ShowcaseActivity.DEBUGGING) Utils.showLog(context, "Icons Picker error: " + Log.getStackTraceString(e)); } if (bitmap != null) { intent.putExtra("icon", bitmap); intent.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", resId); String bmUri = "android.resource://" + context.getPackageName() + "/" + String.valueOf(resId); intent.setData(Uri.parse(bmUri)); context.setResult(Activity.RESULT_OK, intent); } else { context.setResult(Activity.RESULT_CANCELED, intent); } context.finish(); } else { if (!inChangelog) { Drawable iconDrawable = ContextCompat.getDrawable(context, resId); MaterialDialog dialog = new MaterialDialog.Builder(context).customView(R.layout.dialog_icon, false) .title(Utils.makeTextReadable(name)).positiveText(R.string.close) .positiveColor(ColorExtractor.getPreferredColor(iconDrawable, context, true, true)).show(); if (dialog.getCustomView() != null) { ImageView dialogIcon = (ImageView) dialog.getCustomView().findViewById(R.id.dialogicon); dialogIcon.setImageResource(resId); } } } }
From source file:eu.funceptionapps.convertitall.ui.SettingsInterface.java
@SuppressWarnings("deprecation") @Override/*from w ww. ja va 2s .c om*/ public void onCreate(Bundle savedInstanceState) { InitView.setTheme(prefs, this); super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); PreferenceScreen prefSet = getPreferenceScreen(); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getActionBar().setDisplayHomeAsUpEnabled(true); } mSelectedCurrencies = prefSet.findPreference(SELECTED_CURRENCIES_PREF); mSelectedLengths = prefSet.findPreference(SELECTED_LENGTHS_PREF); mSelectedTemperatures = prefSet.findPreference(SELECTED_TEMPERATURES_PREF); mSelectedBytes = prefSet.findPreference(SELECTED_BYTES_PREF); mSelectedNumSys = prefSet.findPreference(SELECTED_NUMSYS_PREF); mSelectedForces = prefSet.findPreference(SELECTED_FORCES_PREF); mThemeSetting = (ListPreference) prefSet.findPreference(THEME_SETTING_PREF); mChangelog = prefSet.findPreference(CHANGELOG_PREF); mVersionPreference = prefSet.findPreference(VERSION_PREF); //mXDAThread = prefSet.findPreference(XDA_THREAD_PREF); mThemeSetting.setSummary(themeSum); mThemeSetting.setValueIndex(Integer.valueOf(prefs.getString(THEME_SETTING_PREF, "0"))); mThemeSetting.setOnPreferenceChangeListener(this); try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); mVersionPreference.setSummary(pInfo.versionName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } setResult(Activity.RESULT_CANCELED); }
From source file:com.waz.zclient.pages.main.conversation.AssetIntentsManager.java
public boolean onActivityResult(int requestCode, int resultCode, Intent data) { if (callback == null) { throw new IllegalStateException("A callback must be set!"); }/*from w w w . j ava2 s . com*/ IntentType type = IntentType.get(requestCode); if (type == IntentType.UNKOWN) { return false; } if (resultCode == Activity.RESULT_CANCELED) { callback.onCanceled(type); return true; } if (resultCode != Activity.RESULT_OK) { callback.onFailed(type); return true; } File possibleFile = null; if (pendingFileUri != null) { possibleFile = new File(pendingFileUri.getPath()); } if ((type == IntentType.CAMERA || type == IntentType.VIDEO || type == IntentType.VIDEO_CURSOR_BUTTON) && possibleFile != null && possibleFile.exists() && possibleFile.length() > 0) { callback.onDataReceived(type, pendingFileUri); pendingFileUri = null; } else if (data != null) { Uri uri; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { uri = Uri.parse(data.getDataString()); } else { uri = data.getData(); } if (uri == null) { callback.onFailed(type); } else { callback.onDataReceived(type, uri); } } else { callback.onFailed(type); } return true; }
From source file:io.flutter.plugins.imagepicker.ImagePickerPlugin.java
@Override public boolean onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_PICK) { if (resultCode == Activity.RESULT_OK && data != null) { String path = FileUtils.getPathFromUri(registrar.activity(), data.getData()); handleResult(path);/* w w w . j a v a2s . c om*/ return true; } else if (resultCode != Activity.RESULT_CANCELED) { pendingResult.error("PICK_ERROR", "Error picking image", null); } pendingResult = null; methodCall = null; return true; } if (requestCode == REQUEST_CODE_CAMERA) { if (resultCode == Activity.RESULT_OK) { cameraModule.getImage(registrar.context(), data, new OnImageReadyListener() { @Override public void onImageReady(List<Image> images) { handleResult(images.get(0).getPath()); } }); return true; } else if (resultCode != Activity.RESULT_CANCELED) { pendingResult.error("PICK_ERROR", "Error taking photo", null); } pendingResult = null; methodCall = null; return true; } return false; }
From source file:me.vijayjaybhay.galleryview.GalleryViewActivity.java
/** * Sets handlers/* w w w . j a v a 2 s . c o m*/ */ private void setHandlers() { mCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent resIntent = new Intent(); setResult(Activity.RESULT_CANCELED, resIntent); finish(); } }); mDone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent resIntent = new Intent(); resIntent.putExtra(KEY_SELECTED_IMAGE_INDEX, mSelectedImageIndex); setResult(Activity.RESULT_OK, resIntent); finish(); } }); mImageContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { loadBackgroundImage(position); } }); }
From source file:org.opendatakit.survey.android.activities.MediaCaptureAudioActivity.java
@Override protected void onResume() { super.onResume(); if (afterResult) { // this occurs if we re-orient the phone during the save-recording // action returnResult();/* w w w . j ava 2 s.com*/ } else if (!hasLaunched && !afterResult) { Intent i = new Intent(Audio.Media.RECORD_SOUND_ACTION); // to make the name unique... File f = ODKFileUtils.getAsFile(appName, (uriFragmentToMedia == null ? uriFragmentNewFileBase : uriFragmentToMedia)); int idx = f.getName().lastIndexOf('.'); if (idx == -1) { i.putExtra(Audio.Media.DISPLAY_NAME, f.getName()); } else { i.putExtra(Audio.Media.DISPLAY_NAME, f.getName().substring(0, idx)); } try { hasLaunched = true; startActivityForResult(i, ACTION_CODE); } catch (ActivityNotFoundException e) { String err = getString(R.string.activity_not_found, Audio.Media.RECORD_SOUND_ACTION); WebLogger.getLogger(appName).e(t, err); Toast.makeText(this, err, Toast.LENGTH_SHORT).show(); setResult(Activity.RESULT_CANCELED); finish(); } } }
From source file:com.google.android.gms.samples.wallet.PromoAddressLookupFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CODE_RESOLVE_ERR: // call connect regardless of success or failure // if the result was success, the connect should succeed // if the result was not success, this should get a new connection result mGoogleApiClient.connect();//ww w .j a v a 2 s .c o m break; case REQUEST_CODE_RESOLVE_ADDRESS_LOOKUP: dismissProgressDialog(); mPromoWasSelected = false; switch (resultCode) { case Activity.RESULT_OK: ((BikestoreApplication) getActivity().getApplication()).setAddressValidForPromo(true); UserAddress userAddress = UserAddress.fromIntent(data); Toast.makeText(getActivity(), getString(R.string.promo_eligible, formatUsAddress(userAddress)), Toast.LENGTH_LONG).show(); break; case Activity.RESULT_CANCELED: break; default: Toast.makeText(getActivity(), getString(R.string.no_address), Toast.LENGTH_LONG).show(); break; } break; default: super.onActivityResult(requestCode, resultCode, data); dismissProgressDialog(); break; } }