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.jtechme.apphub.privileged.install.InstallExtensionDialogActivity.java

public 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());

    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/*from  w  ww . jav  a  2 s  . c  o  m*/
                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:com.brq.wallet.activity.ScanActivity.java

public static void toastScanError(int resultCode, Intent intent, Activity activity) {
    if (intent == null) {
        return; // no result, user pressed back
    }/*  w  w w  .j  a va2  s  .co m*/
    if (resultCode == Activity.RESULT_CANCELED) {
        String error = intent.getStringExtra(StringHandlerActivity.RESULT_ERROR);
        if (error != null) {
            new Toaster(activity).toast(error, false);
        }
    }
}

From source file:com.sandklef.coachapp.activities.TopActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(LOG_TAG, "Video callback: " + requestCode + " " + resultCode + " " + data);
    if (requestCode == TrainingPhasesFragment.VIDEO_CAPTURE) {
        Log.d(LOG_TAG, "instructional video found....");
    } else if (requestCode == VideoCapture.VIDEO_CAPTURE) {
        if (resultCode == Activity.RESULT_OK) {
            Log.d(LOG_TAG, "Video saved to: " + data.getData());
            Log.d(LOG_TAG, "Saving media object...");
            saveMedia(data.getData());/*w  w  w .  j av  a 2s .  c  om*/
        } else if (resultCode == Activity.RESULT_CANCELED) {
            Log.d(LOG_TAG, "Video recording cancelled.");
        } else {
            Log.d(LOG_TAG, "Failed to record video");
        }
    }
}

From source file:com.phonegap.CameraLauncher.java

/**
 * Called when the camera view exits. /*  w  w  w .j a v  a  2 s.  c o m*/
 * 
 * @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) {

    // Get src and dest types from request code
    int srcType = (requestCode / 16) - 1;
    int destType = (requestCode % 16) - 1;

    // If CAMERA
    if (srcType == CAMERA) {

        // If image available
        if (resultCode == Activity.RESULT_OK) {
            try {
                // Read in bitmap of captured image
                Bitmap bitmap = android.provider.MediaStore.Images.Media
                        .getBitmap(this.ctx.getContentResolver(), imageUri);

                // If sending base64 image back
                if (destType == DATA_URL) {
                    this.processPicture(bitmap);
                }

                // If sending filename back
                else if (destType == FILE_URI) {
                    // 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) {
                        System.out.println("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) {
                            System.out.println("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();

                    // 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();
            } 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!");
        }
    }

    // If retrieving photo from library
    else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
        if (resultCode == Activity.RESULT_OK) {
            Uri uri = intent.getData();
            android.content.ContentResolver resolver = this.ctx.getContentResolver();
            // If sending base64 image back
            if (destType == DATA_URL) {
                try {
                    Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
                    this.processPicture(bitmap);
                    bitmap.recycle();
                    bitmap = null;
                    System.gc();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                    this.failPicture("Error retrieving image.");
                }
            }

            // If sending filename back
            else if (destType == FILE_URI) {
                this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            this.failPicture("Selection cancelled.");
        } else {
            this.failPicture("Selection did not complete!");
        }
    }
}

From source file:org.akvo.caddisfly.ui.ExternalActionActivity.java

/**
 * Alert message for calibration incomplete or invalid.
 *//*from ww  w .j  a v a 2 s. c  o  m*/
private void alertCalibrationIncomplete() {

    final Activity activity = this;

    String message = getString(R.string.errorCalibrationIncomplete,
            CaddisflyApp.getApp().getCurrentTestInfo().getName());
    message = String.format(MESSAGE_TWO_LINE_FORMAT, message, getString(R.string.doYouWantToCalibrate));

    AlertUtil.showAlert(this, R.string.cannotStartTest, message, R.string.calibrate,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    final Intent intent = new Intent(getBaseContext(), CalibrateListActivity.class);
                    startActivity(intent);

                    activity.setResult(Activity.RESULT_CANCELED);
                    dialogInterface.dismiss();
                    finish();
                }
            }, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    activity.setResult(Activity.RESULT_CANCELED);
                    dialogInterface.dismiss();
                    finish();
                }
            }, new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    activity.setResult(Activity.RESULT_CANCELED);
                    dialogInterface.dismiss();
                    finish();
                }
            });
}

From source file:co.mwater.foregroundcameraplugin.ForegroundCameraLauncher.java

/**
 * Called when the camera view exits./*  ww  w. j a va 2s  . co  m*/
 * 
 * @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.sendPluginResult(new PluginResult(PluginResult.Status.OK, uri.toString()));
            //                  getRealPathFromURI(uri, this.cordova))); WRONG. Needs URI

            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:org.gnucash.android.ui.BaseDrawerActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_CANCELED) {
        return;/*from   w w  w .  ja v  a 2s  .  co  m*/
    }

    switch (requestCode) {
    case AccountsActivity.REQUEST_PICK_ACCOUNTS_FILE:
        try {
            GncXmlExporter.createBackup();
            InputStream accountInputStream = getContentResolver().openInputStream(data.getData());
            new ImportAsyncTask(this).execute(accountInputStream);
        } catch (FileNotFoundException e) {
            Crashlytics.logException(e);
            Toast.makeText(this, R.string.toast_error_importing_accounts, Toast.LENGTH_SHORT).show();
        }
        break;
    }
}

From source file:com.meetingninja.csse.meetings.MeetingsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 2) {
        if (resultCode == Activity.RESULT_OK) {
            if (data != null) {
                int listPosition = data.getIntExtra("listPosition", -1);
                Meeting created = data.getParcelableExtra(Keys.Meeting.PARCEL);

                if (data.getStringExtra("method").equals("update")) {
                    Log.d(TAG, "Updating Meeting");
                    if (listPosition != -1)
                        updateMeeting(listPosition, created);
                    else
                        updateMeeting(created);
                } else if (data.getStringExtra("method").equals("insert")) {
                    Log.d(TAG, "Inserting Meeting");
                    // created = mySQLiteAdapter.insertMeeting(created);
                    fetchMeetings();// ww w. j  a v a 2 s  . c  o m
                }
            }
        } else {
            if (resultCode == Activity.RESULT_CANCELED) {
                // nothing to do here
            }
        }
    }
}

From source file:net.wespot.pim.view.PimInquiriesFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case DIALOG_FRAGMENT:

        if (resultCode == Activity.RESULT_OK) {
            // After Ok code.
            Log.e(TAG, "OK code");
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // After Cancel code.
            Log.e(TAG, "cancel code");
        }/*w ww  . ja v a  2 s  . c  om*/
        break;
    }
}

From source file:app.com.vaipo.ContactsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == 1) {
        if (resultCode == Activity.RESULT_OK) {
            int action = data.getIntExtra("action", InCallActivityDialog.ACTION_NONE);
            int option = data.getIntExtra("option", InCallActivityDialog.OPTION_NONE);

            switch (action) {
            case InCallActivityDialog.ACTION_END:
                Utils.endVaipoCall(getActivity());
                break;
            case InCallActivityDialog.ACTION_MUTE:
                break;
            case InCallActivityDialog.ACTION_SPKR:
                break;
            case InCallActivityDialog.ACTION_SWAP:
                break;
            }//from   w  w w .  j a va 2  s  .  c o  m

        }
        if (resultCode == Activity.RESULT_CANCELED) {
            //Write your code if there's no result
        }
    }
}