Example usage for android.app Activity RESULT_CANCELED

List of usage examples for android.app Activity RESULT_CANCELED

Introduction

In this page you can find the example usage for android.app Activity RESULT_CANCELED.

Prototype

int RESULT_CANCELED

To view the source code for android.app Activity RESULT_CANCELED.

Click Source Link

Document

Standard activity result: operation canceled.

Usage

From source file:com.zion.htf.ui.DonateActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (Activity.RESULT_OK == resultCode) {
        PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
        if (null != confirm) {
            try {
                if (BuildConfig.DEBUG)
                    Log.i(DonateActivity.TAG, confirm.toJSONObject().toString(4));

                // TODO: send 'confirm' to your server for verification.
                // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                // for more details.
            } catch (JSONException e) {
                Log.e(DonateActivity.TAG, "an extremely unlikely failure occurred: ", e);
            }//from   w w  w  .  j av  a  2s .c om
        }
    } else if (Activity.RESULT_CANCELED == resultCode) {
        if (BuildConfig.DEBUG)
            Log.i(DonateActivity.TAG, "The user canceled.");
    } else if (PaymentActivity.RESULT_PAYMENT_INVALID == resultCode) {
        Log.e(DonateActivity.TAG, "An invalid payment was submitted. Please see the docs.");
    }
}

From source file:org.fdroid.fdroid.installer.DefaultInstallerActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_INSTALL:
        /**/*  www. j  a  v a 2s. c o  m*/
         * resultCode is always 0 on Android < 4.0. See
         * com.android.packageinstaller.PackageInstallerActivity: setResult is
         * never executed on Androids < 4.0
         */
        if (Build.VERSION.SDK_INT < 14) {
            installer.sendBroadcastInstall(downloadUri, Installer.ACTION_INSTALL_COMPLETE);
            break;
        }

        switch (resultCode) {
        case Activity.RESULT_OK:
            installer.sendBroadcastInstall(downloadUri, Installer.ACTION_INSTALL_COMPLETE);
            break;
        case Activity.RESULT_CANCELED:
            installer.sendBroadcastInstall(downloadUri, Installer.ACTION_INSTALL_INTERRUPTED);
            break;
        case Activity.RESULT_FIRST_USER:
        default:
            // AOSP returns Activity.RESULT_FIRST_USER on error
            installer.sendBroadcastInstall(downloadUri, Installer.ACTION_INSTALL_INTERRUPTED,
                    getString(R.string.install_error_unknown));
            break;
        }

        break;
    case REQUEST_CODE_UNINSTALL:
        // resultCode is always 0 on Android < 4.0.
        if (Build.VERSION.SDK_INT < 14) {
            installer.sendBroadcastUninstall(uninstallPackageName, Installer.ACTION_UNINSTALL_COMPLETE);
            break;
        }

        switch (resultCode) {
        case Activity.RESULT_OK:
            installer.sendBroadcastUninstall(uninstallPackageName, Installer.ACTION_UNINSTALL_COMPLETE);
            break;
        case Activity.RESULT_CANCELED:
            installer.sendBroadcastUninstall(uninstallPackageName, Installer.ACTION_UNINSTALL_INTERRUPTED);
            break;
        case Activity.RESULT_FIRST_USER:
        default:
            // AOSP UninstallAppProgress returns RESULT_FIRST_USER on error
            installer.sendBroadcastUninstall(uninstallPackageName, Installer.ACTION_UNINSTALL_INTERRUPTED,
                    getString(R.string.uninstall_error_unknown));
            break;
        }

        break;
    default:
        throw new RuntimeException("Invalid request code!");
    }

    // after doing the broadcasts, finish this transparent wrapper activity
    finish();
}

From source file:org.opendatakit.survey.activities.MediaCaptureAudioActivity.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 a2 s .c  om
        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 RECORD_SOUND_ACTION!");
        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, Audio.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(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(Audio.Media.EXTERNAL_CONTENT_URI,
                values);
        WebLogger.getLogger(appName).i(t, "Inserting AUDIO returned uri = " + MediaURI.toString());
        uriFragmentToMedia = ODKFileUtils.asRowpathUri(appName, tableId, instanceId, sourceMedia);
        WebLogger.getLogger(appName).i(t, "Setting current answer to " + sourceMedia.getAbsolutePath());

        int 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 Audio file FAILED");
    }

    /*
     * We saved the audio to the instance directory. Verify that it is there...
     */
    returnResult();
    return;
}

From source file:org.linphone.setup.SetupActivity.java

@Override
public void onBackPressed() {
    if (currentFragment == firstFragment) {
        LinphonePreferences.instance().firstLaunchSuccessful();
        if (getResources().getBoolean(R.bool.setup_cancel_move_to_back)) {
            moveTaskToBack(true);/*from  w  ww. ja  va  2s  . co  m*/
        } else {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    }
    if (currentFragment == SetupFragmentsEnum.MENU) {
        WelcomeFragment fragment = new WelcomeFragment();
        changeFragment(fragment);
        currentFragment = SetupFragmentsEnum.WELCOME;

        next.setVisibility(View.VISIBLE);
        back.setVisibility(View.GONE);
    } else if (currentFragment == SetupFragmentsEnum.GENERIC_LOGIN
            || currentFragment == SetupFragmentsEnum.LINPHONE_LOGIN
            || currentFragment == SetupFragmentsEnum.WIZARD
            || currentFragment == SetupFragmentsEnum.REMOTE_PROVISIONING) {
        MenuFragment fragment = new MenuFragment();
        changeFragment(fragment);
        currentFragment = SetupFragmentsEnum.MENU;
    } else if (currentFragment == SetupFragmentsEnum.WELCOME) {
        finish();
    }
}

From source file:com.whamads.nativecamera.NativeCameraLauncher.java

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    // If image available
    if (resultCode == Activity.RESULT_OK) {
        int rotate = 0;
        try {//from   w  w w . ja v a 2  s  . c  o  m
            // Check if the image was written to
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            Bitmap bitmap = BitmapFactory.decodeFile(this.imageUri.getPath(), options);
            if (options.outWidth == -1 || options.outHeight == -1) {
                this.failPicture("Error decoding image.");
                return;
            }

            ExifHelper exif = new ExifHelper();
            exif.createInFile(this.imageUri.getPath());
            exif.readExifData();
            rotate = exif.getOrientation();
            Log.i(LOG_TAG, "Uncompressed image rotation value: " + rotate);

            exif.resetOrientation();
            exif.createOutFile(this.imageUri.getPath());
            exif.writeExifData();

            JSONObject returnObject = new JSONObject();
            returnObject.put("url", this.imageUri.toString());
            returnObject.put("rotation", rotate);

            Log.i(LOG_TAG, "Return data: " + returnObject.toString());

            PluginResult result = new PluginResult(PluginResult.Status.OK, returnObject);

            // Log.i(LOG_TAG, "Final Exif orientation value: " + exif.getOrientation());

            // Send Uri back to JavaScript for viewing image
            this.callbackContext.sendPluginResult(result);

        } catch (IOException e) {
            e.printStackTrace();
            this.failPicture("Error capturing image.");
        } catch (JSONException e) {
            e.printStackTrace();
            this.failPicture("Error capturing image.");
        }
    }

    // If browse gallery clicked
    else if (resultCode == CameraActivity.BROWSE_GALLERY) {
        this.failPicture("BROWSE_GALLERY");
    }

    // If cancelled
    else if (resultCode == Activity.RESULT_CANCELED) {
        this.failPicture("Camera cancelled.");
    }

    // If something else
    else {
        this.failPicture("Did not complete!");
    }
}

From source file:io.plaidapp.ui.DesignerNewsLogin.java

public void dismiss(View view) {
    isDismissing = true;
    setResult(Activity.RESULT_CANCELED);
    finishAfterTransition();
}

From source file:com.android.gallery3d.gadget.WidgetConfigure.java

private void setChoosenPhoto(final Intent data) {
    AsyncTask.execute(new Runnable() {
        @Override//from  w  ww.  j av a  2s.  c  o m
        public void run() {
            Resources res = getResources();

            float width = res.getDimension(R.dimen.appwidget_width);
            float height = res.getDimension(R.dimen.appwidget_height);

            // We try to crop a larger image (by scale factor), but there is still
            // a bound on the binder limit.
            float scale = Math.min(WIDGET_SCALE_FACTOR, MAX_WIDGET_SIDE / Math.max(width, height));

            int widgetWidth = Math.round(width * scale);
            int widgetHeight = Math.round(height * scale);

            File cropSrc = new File(getCacheDir(), "crop_source.png");
            File cropDst = new File(getCacheDir(), "crop_dest.png");
            mPickedItem = data.getData();
            if (!copyUriToFile(mPickedItem, cropSrc)) {
                setResult(Activity.RESULT_CANCELED);
                finish();
                return;
            }

            mCropSrc = FileProvider.getUriForFile(WidgetConfigure.this, "com.android.gallery3d.fileprovider",
                    new File(cropSrc.getAbsolutePath()));
            mCropDst = FileProvider.getUriForFile(WidgetConfigure.this, "com.android.gallery3d.fileprovider",
                    new File(cropDst.getAbsolutePath()));

            Intent request = new Intent(CropActivity.CROP_ACTION).putExtra(CropExtras.KEY_OUTPUT_X, widgetWidth)
                    .putExtra(CropExtras.KEY_OUTPUT_Y, widgetHeight)
                    .putExtra(CropExtras.KEY_ASPECT_X, widgetWidth)
                    .putExtra(CropExtras.KEY_ASPECT_Y, widgetHeight)
                    .putExtra(CropExtras.KEY_SCALE_UP_IF_NEEDED, true).putExtra(CropExtras.KEY_SCALE, true)
                    .putExtra(CropExtras.KEY_RETURN_DATA, false).setDataAndType(mCropSrc, "image/*")
                    .addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            request.putExtra(MediaStore.EXTRA_OUTPUT, mCropDst);
            request.setClipData(ClipData.newRawUri(MediaStore.EXTRA_OUTPUT, mCropDst));
            startActivityForResult(request, REQUEST_CROP_IMAGE);
        }
    });
}

From source file:org.mifos.androidclient.main.CustomerDetailsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case ApplyCustomerChargeActivity.REQUEST_CODE:
        switch (resultCode) {
        case Activity.RESULT_OK:
            runCustomerDetailsTask();/*from w ww  .  j a  v a 2s .c  o  m*/
            break;
        case Activity.RESULT_CANCELED:
            break;
        default:
            break;
        }
        break;
    default:
        break;
    }
}

From source file:com.paymaya.sdk.android.checkout.PayMayaCheckoutActivity.java

private void finishCanceled() {
    Intent intent = new Intent();
    setResult(Activity.RESULT_CANCELED, intent);
    finish();
}

From source file:org.apache.cordova.contacts.ContactManager.java

/**
 * Called when user picks contact./*from  w w w . jav a  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").
 * @throws JSONException
 */
public void onActivityResult(int requestCode, int resultCode, final Intent intent) {
    if (requestCode == 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));
    }
}