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.ultramegasoft.flavordex2.dialog.CatListDialog.java

@Override
public void onCancel(DialogInterface dialog) {
    super.onCancel(dialog);
    final Fragment target = getTargetFragment();
    if (target != null) {
        target.onActivityResult(getTargetRequestCode(), Activity.RESULT_CANCELED, null);
    }//from ww  w.j a  v  a 2 s . c  o m
}

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

private void setPhotoWidget() {
    AsyncTask.execute(new Runnable() {
        @Override/*  w ww . j  a v  a2  s  .c om*/
        public void run() {
            Bitmap bitmap = null;
            InputStream stream = null;
            try {
                stream = WidgetConfigure.this.getContentResolver().openInputStream(mCropDst);
                if (stream != null) {
                    bitmap = BitmapFactory.decodeStream(stream);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } finally {
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                getContentResolver().delete(mCropSrc, null, null);
                getContentResolver().delete(mCropDst, null, null);
            }
            if (bitmap == null) {
                setResult(Activity.RESULT_CANCELED);
                finish();
                return;
            }
            WidgetDatabaseHelper helper = new WidgetDatabaseHelper(WidgetConfigure.this);
            try {
                helper.setPhoto(mAppWidgetId, mPickedItem, bitmap);
                updateWidgetAndFinish(helper.getEntry(mAppWidgetId));
            } finally {
                helper.close();
            }
        }
    });
}

From source file:com.tuxpan.foregroundvideocapture.CaptureFG.java

/**
 * Called when the video view exits.//w  w  w  . j ava 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").
 * @throws JSONException
 */
public void onActivityResult(int requestCode, int resultCode, final Intent intent) {

    // Result received okay
    if (resultCode == Activity.RESULT_OK) {
        // An audio clip was requested

        final CaptureFG that = this;
        Runnable captureVideo = new Runnable() {

            @Override
            public void run() {

                Uri data = null;

                if (intent != null) {
                    // Get the uri of the video clip
                    data = intent.getData();
                }

                if (data == null) {
                    File movie = new File(getTempDirectoryPath(), "video.3gp");
                    data = Uri.fromFile(movie);
                }

                // create a file object from the uri
                if (data == null) {
                    that.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
                } else {
                    results.put(createMediaFile(data));
                    // Send Uri back to JavaScript for viewing video
                    that.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                }
            }
        };
        this.cordova.getThreadPool().execute(captureVideo);
    }
    // If canceled
    else if (resultCode == Activity.RESULT_CANCELED) {
        // If we have partial results send them back to the user
        if (results.length() > 0) {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
        }
        // user canceled the action
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Canceled."));
        }
    }
    // If something else
    else {
        // If we have partial results send them back to the user
        if (results.length() > 0) {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
        }
        // something bad happened
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Did not complete!"));
        }
    }
}

From source file:org.opendatakit.survey.android.activities.MediaCaptureVideoActivity.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.java 2s  .  com
    } else if (!hasLaunched && !afterResult) {
        Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        // to make the name unique...
        File f = ODKFileUtils.getAsFile(appName,
                (uriFragmentToMedia == null ? uriFragmentNewFileBase : uriFragmentToMedia));
        int idx = f.getName().lastIndexOf('.');
        if (idx == -1) {
            i.putExtra(Video.Media.DISPLAY_NAME, f.getName());
        } else {
            i.putExtra(Video.Media.DISPLAY_NAME, f.getName().substring(0, idx));
        }

        // 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 - using the MediaStore.EXTRA_OUTPUT to get the data
        // Have it saving to an intermediate location instead of final destination
        // to allow the current location to catch issues with the intermediate file
        WebLogger.getLogger(appName).i(t, "The build of this device is " + android.os.Build.MODEL);
        if (NEXUS7.equals(android.os.Build.MODEL) && Build.VERSION.SDK_INT == 18) {
            nexus7Uri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
            i.putExtra(MediaStore.EXTRA_OUTPUT, nexus7Uri);
        }

        try {
            hasLaunched = true;
            startActivityForResult(i, ACTION_CODE);
        } catch (ActivityNotFoundException e) {
            String err = getString(R.string.activity_not_found, MediaStore.ACTION_VIDEO_CAPTURE);
            WebLogger.getLogger(appName).e(t, err);
            Toast.makeText(this, err, Toast.LENGTH_SHORT).show();
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    }
}

From source file:org.opendatakit.survey.android.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();//  w  ww . j ava  2 s  .  co 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 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.getAsFile(appName, uriFragmentToMedia);
    File sourceMedia = new File(f.getParentFile(),
            f.getName().substring(0, f.getName().lastIndexOf('.')) + extension);
    uriFragmentToMedia = ODKFileUtils.asUriFragment(appName, 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.asUriFragment(appName, 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 onClick(View v) {
    int id = v.getId();

    if (id == R.id.setup_cancel) {
        LinphonePreferences.instance().firstLaunchSuccessful();
        if (getResources().getBoolean(R.bool.setup_cancel_move_to_back)) {
            moveTaskToBack(true);/* w  ww.  j  ava 2  s  . com*/
        } else {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    } else if (id == R.id.setup_next) {
        if (firstFragment == SetupFragmentsEnum.LINPHONE_LOGIN) {
            LinphoneLoginFragment linphoneFragment = (LinphoneLoginFragment) fragment;
            linphoneFragment.linphoneLogIn();
        } else {
            if (currentFragment == SetupFragmentsEnum.WELCOME) {
                MenuFragment fragment = new MenuFragment();
                changeFragment(fragment);
                currentFragment = SetupFragmentsEnum.MENU;

                next.setVisibility(View.GONE);
                back.setVisibility(View.VISIBLE);
            } else if (currentFragment == SetupFragmentsEnum.WIZARD_CONFIRM) {
                finish();
            }
        }
    } else if (id == R.id.setup_back) {
        onBackPressed();
    }
}

From source file:com.github.baoti.pioneer.ui.common.image.chooser.ImageChooserFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CAPTURE_IMAGE:
        if (imageCapture != null && resultCode != Activity.RESULT_CANCELED) {
            Uri image = imageCapture.capturedImage(resultCode, data);
            verbose("Captured: %s", image);
            onImageChose(requestCode, image);
        } else {/*from   ww  w  . ja  v a2 s . c om*/
            verbose("Capture cancelled");
            onImageCancelled(requestCode);
        }
        break;
    case REQUEST_PICK_IMAGE:
        if (resultCode != Activity.RESULT_CANCELED) {
            Uri image = ImageActions.pickedImage(resultCode, data);
            verbose("Picked: %s", image);
            onImageChose(requestCode, image);
        } else {
            verbose("Pick cancelled");
            onImageCancelled(requestCode);
        }
        break;
    case REQUEST_CROP_IMAGE:
        if (imageCrop != null && resultCode != Activity.RESULT_CANCELED) {
            Uri image = imageCrop.croppedImage(resultCode, data);
            verbose("Cropped: %s", image);
            onImageChose(requestCode, image);
        } else {
            verbose("Crop cancelled");
            onImageCancelled(requestCode);
        }
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:freed.viewer.dngconvert.DngConvertingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    appSettingsManager = new AppSettingsManager(
            PreferenceManager.getDefaultSharedPreferences(getActivity().getBaseContext()), getResources());
    if (appSettingsManager.getDevice() == null)
        appSettingsManager.SetDevice(new DeviceUtils().getDevice(getResources()));
    handler = new Handler();
    view = inflater.inflate(R.layout.dngconvertingfragment, container, false);
    editTextwidth = (EditText) view.findViewById(id.editText_width);
    editTextheight = (EditText) view.findViewById(id.editText_height);
    editTextblacklvl = (EditText) view.findViewById(id.editText_blacklevel);
    spinnerMatrixProfile = (Spinner) view.findViewById(id.spinner_MatrixProfile);
    matrixChooserParameter = new MatrixChooserParameter(appSettingsManager.getMatrixesMap());
    String[] items = matrixChooserParameter.GetValues();
    ArrayAdapter<String> matrixadapter = new ArrayAdapter<>(getContext(), layout.simple_spinner_item, items);
    //ArrayAdapter<CharSequence> matrixadapter = ArrayAdapter.createFromResource(getContext(),R.array.matrixes, android.R.layout.simple_spinner_item);
    matrixadapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
    spinnerMatrixProfile.setAdapter(matrixadapter);

    buttonconvertToDng = (Button) view.findViewById(id.button_convertDng);
    buttonconvertToDng.setOnClickListener(convertToDngClick);

    spinnerColorPattern = (Spinner) view.findViewById(id.spinner_ColorPattern);
    ArrayAdapter<CharSequence> coloradapter = ArrayAdapter.createFromResource(getContext(), array.color_pattern,
            layout.simple_spinner_item);
    coloradapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
    spinnerColorPattern.setAdapter(coloradapter);

    spinnerrawFormat = (Spinner) view.findViewById(id.spinner_rawFormat);
    ArrayAdapter<CharSequence> rawadapter = ArrayAdapter.createFromResource(getContext(), array.raw_format,
            layout.simple_spinner_item);
    rawadapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
    spinnerrawFormat.setAdapter(rawadapter);
    closeButton = (Button) view.findViewById(id.button_goback_from_conv);
    closeButton.setOnClickListener(new OnClickListener() {
        @Override// w ww.  ja v a  2  s.c o  m
        public void onClick(View v) {
            Intent returnIntent = new Intent();
            getActivity().setResult(Activity.RESULT_CANCELED, returnIntent);
            getActivity().finish();
        }
    });
    imageView = (TouchImageView) view.findViewById(id.dngconvert_imageview);
    fakeGPS = (CheckBox) view.findViewById(id.checkBox_fakeGPS);
    return view;
}

From source file:at.alladin.rmbt.android.terms.RMBTCheckFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    if (!(getActivity() instanceof RMBTMainActivity))
        firstTime = false;/*from w  ww  . ja v a  2s  .  c o m*/

    final View v = inflater.inflate(R.layout.ndt_check, container, false);

    if (!firstTime)
        v.findViewById(R.id.termsNdtButtonBack).setVisibility(View.GONE);

    final TextView textTitle = (TextView) v.findViewById(R.id.check_fragment_title);
    textTitle.setText(checkType.getTitleId());

    checkBox = (CheckBox) v.findViewById(R.id.ndtCheckBox);
    checkBox.setText(checkType.getTextId());

    if (savedInstanceState != null) {
        checkBox.setChecked(savedInstanceState.getBoolean("isChecked"));
    } else {
        checkBox.setChecked(checkType.isDefaultIsChecked());
    }

    final Button buttonAccept = (Button) v.findViewById(R.id.termsNdtAcceptButton);

    if (!firstTime) {
        checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                buttonAccept.setEnabled(isChecked);
            }
        });
    }

    final WebView wv = (WebView) v.findViewById(R.id.ndtInfoWebView);
    wv.loadUrl(checkType.getTemplateFile());

    buttonAccept.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            final FragmentActivity activity = getActivity();

            switch (checkType) {
            case NDT:
                ConfigHelper.setNDT(activity, checkBox.isChecked());
                ConfigHelper.setNDTDecisionMade(activity, true);
                break;
            case LOOP_MODE:
                ConfigHelper.setLoopMode(activity, checkBox.isChecked());
                break;
            }

            activity.getSupportFragmentManager().popBackStack(checkType.getFragmentTag(),
                    FragmentManager.POP_BACK_STACK_INCLUSIVE);

            if (firstTime && CheckType.NDT.equals(checkType)) {
                ((RMBTMainActivity) activity).initApp(false);
            } else {
                getActivity().setResult(checkBox.isChecked() ? Activity.RESULT_OK : Activity.RESULT_CANCELED);
                getActivity().finish();
            }
        }
    });

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            buttonAccept.setEnabled(firstTime || checkBox.isChecked());
        }
    }, 500);

    final Button buttonBack = (Button) v.findViewById(R.id.termsNdtBackButton);
    buttonBack.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            getActivity().getSupportFragmentManager().popBackStack();
        }
    });

    return v;
}

From source file:com.samuelcastro.cordova.InstagramSharePlugin.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Log.v("Instagram", "shared ok");
        this.cbContext.success();
    } else if (resultCode == Activity.RESULT_CANCELED) {
        Log.v("Instagram", "share cancelled");
        this.cbContext.error("Share Cancelled");
    }/*from w w w.j a  v a 2s  .  c om*/
}