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.tomeokin.lspush.ui.widget.dialog.BaseDialogFragment.java

@Override
public void onCancel(DialogInterface dialog) {
    super.onCancel(dialog);
    if (hasCancelListener) {
        OnDialogCancelListener listener = getDialogListener(OnDialogCancelListener.class);
        if (listener != null) {
            listener.onDialogCancel(dialog, requestCode);
        } else {/*from   w  ww . j  a  va2  s  . com*/
            setResult(requestCode, Activity.RESULT_CANCELED, null);
        }
    }
}

From source file:com.jigarmjoshi.ReportFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TAKE_PHOTO_CODE && resultCode == Activity.RESULT_OK) {
        // Bitmap photo = (Bitmap) data.getExtras().get("data");
        // reportImageView.setImageBitmap(photo);
        reportImageView.setImageBitmap(BitmapFactory.decodeFile(lastImagePath));
    } else if (resultCode == Activity.RESULT_CANCELED) {
        Toast.makeText(rootView.getContext(), "Picture was not taken ", Toast.LENGTH_SHORT).show();
    } else {/*from   w  w  w  .ja  v a  2 s.  c  om*/
        Toast.makeText(rootView.getContext(), "Picture was not taken ", Toast.LENGTH_SHORT).show();
    }
}

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

/**
 * first time/* w  w  w .  jav  a 2  s .c o m*/
 */
private void firstTime() {
    // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    String message = getString(R.string.system_install_first_time_message) + "<br/><br/>"
            + InstallIntoSystem.create(getApplicationContext()).getWarningInfo();

    AlertDialog.Builder builder = new AlertDialog.Builder(theme).setMessage(Html.fromHtml(message))
            .setPositiveButton(R.string.system_permission_install_via_root,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            installTask.execute();
                        }
                    })
            .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED);
                    InstallIntoSystemDialogActivity.this.finish();
                }
            });
    builder.create().show();
}

From source file:com.ducnd.recordvideo_sample.CaptureDemoFragment.java

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

    if (resultCode == Activity.RESULT_OK) {
        filename = data.getStringExtra(VideoCaptureActivity.EXTRA_OUTPUT_FILENAME);
        statusMessage = String.format(getString(R.string.status_capturesuccess), filename);
    } else if (resultCode == Activity.RESULT_CANCELED) {
        filename = null;/*from   w  w  w  . j a  va2 s .  c  o m*/
        statusMessage = getString(R.string.status_capturecancelled);
    } else if (resultCode == VideoCaptureActivity.RESULT_ERROR) {
        filename = null;
        statusMessage = getString(R.string.status_capturefailed);
    }
    updateStatusAndThumbnail();

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.nextgis.maplibui.SelectNGWResourceDialog.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADDACCOUNT_CODE) {
        if (resultCode != Activity.RESULT_CANCELED) {
            //search new account and add it
            final AccountManager accountManager = AccountManager.get(getActivity());
            Connections connections = mListAdapter.getConnections();
            for (Account account : accountManager.getAccountsByType(NGW_ACCOUNT_TYPE)) {
                boolean find = false;
                for (int i = 0; i < connections.getChildrenCount(); i++) {
                    Connection connection = (Connection) connections.getChild(i);
                    if (null != connection && connection.getName().equals(account.name)) {
                        find = true;/*from  w w  w.ja  v  a2  s . c  o  m*/
                        break;
                    }
                }

                if (!find) {
                    String url = accountManager.getUserData(account, "url");
                    String password = accountManager.getPassword(account);
                    String login = accountManager.getUserData(account, "login");
                    connections.add(new Connection(account.name, login, password, url));
                    mListAdapter.notifyDataSetChanged();
                    break;
                }
            }
        }
    } else
        super.onActivityResult(requestCode, resultCode, data);
}

From source file:org.opendatakit.survey.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();/*  ww w  .  j  av a 2 s.  c o  m*/
    } else if (!hasLaunched && !afterResult) {
        Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        // to make the name unique...
        File f = ODKFileUtils.getRowpathFile(appName, tableId, instanceId,
                (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:com.brandroidtools.filemanager.activities.PickerActivity.java

/**
 * Method that displays a dialog with a {@link NavigationFragment} to select the
 * proposed file/* www . j  a  va2s .  c o m*/
 */
private void init() {
    final boolean pickingDirectory;
    final Intent intent = getIntent();

    if (isFilePickIntent(intent)) {
        // ok
        Log.d(TAG, "PickerActivity: got file pick intent: " + String.valueOf(intent)); //$NON-NLS-1$
        pickingDirectory = false;
    } else if (isDirectoryPickIntent(getIntent())) {
        // ok
        Log.d(TAG, "PickerActivity: got folder pick intent: " + String.valueOf(intent)); //$NON-NLS-1$
        pickingDirectory = true;
    } else {
        Log.d(TAG, "PickerActivity got unrecognized intent: " + String.valueOf(intent)); //$NON-NLS-1$
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }

    // Display restrictions
    Map<DisplayRestrictions, Object> restrictions = new HashMap<DisplayRestrictions, Object>();
    //- Mime/Type restriction
    String mimeType = getIntent().getType();
    if (mimeType != null) {
        if (!MimeTypeHelper.isMimeTypeKnown(this, mimeType)) {
            Log.i(TAG, String.format("Mime type %s unknown, falling back to wildcard.", //$NON-NLS-1$
                    mimeType));
            mimeType = MimeTypeHelper.ALL_MIME_TYPES;
        }
        restrictions.put(DisplayRestrictions.MIME_TYPE_RESTRICTION, mimeType);
    }
    // Other restrictions
    Bundle extras = getIntent().getExtras();
    Log.d(TAG, "PickerActivity. extras: " + String.valueOf(extras)); //$NON-NLS-1$
    if (extras != null) {
        //-- File size
        if (extras.containsKey(android.provider.MediaStore.Audio.Media.EXTRA_MAX_BYTES)) {
            long size = extras.getLong(android.provider.MediaStore.Audio.Media.EXTRA_MAX_BYTES);
            restrictions.put(DisplayRestrictions.SIZE_RESTRICTION, Long.valueOf(size));
        }
        //-- Local filesystems only
        if (extras.containsKey(Intent.EXTRA_LOCAL_ONLY)) {
            boolean localOnly = extras.getBoolean(Intent.EXTRA_LOCAL_ONLY);
            restrictions.put(DisplayRestrictions.LOCAL_FILESYSTEM_ONLY_RESTRICTION, Boolean.valueOf(localOnly));
        }
    }
    if (pickingDirectory) {
        restrictions.put(DisplayRestrictions.DIRECTORY_ONLY_RESTRICTION, Boolean.TRUE);
    }

    // Create or use the console
    if (!initializeConsole()) {
        // Something when wrong. Display a message and exit
        DialogHelper.showToast(this, R.string.msgs_cant_create_console, Toast.LENGTH_SHORT);
        cancel();
        return;
    }

    // Create the root file
    this.mRootView = getLayoutInflater().inflate(R.layout.picker, null, false);
    this.mRootView.post(new Runnable() {
        @Override
        public void run() {
            measureHeight();
        }
    });

    // Breadcrumb
    Breadcrumb breadcrumb = (Breadcrumb) this.mRootView.findViewById(R.id.breadcrumb_view);
    // Set the free disk space warning level of the breadcrumb widget
    String fds = Preferences.getSharedPreferences().getString(
            FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getId(),
            (String) FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getDefaultValue());
    breadcrumb.setFreeDiskSpaceWarningLevel(Integer.parseInt(fds));

    // Navigation view
    this.mNavigationFragment = (NavigationFragment) getSupportFragmentManager()
            .findFragmentById(R.id.navigation_fragment);
    this.mNavigationFragment.setRestrictions(restrictions);
    this.mNavigationFragment.setOnFilePickedListener(this);
    this.mNavigationFragment.setOnDirectoryChangedListener(this);
    this.mNavigationFragment.setBreadcrumb(breadcrumb);

    // Apply the current theme
    applyTheme();

    // Create the dialog
    this.mDialog = DialogHelper.createDialog(this, R.drawable.ic_launcher,
            pickingDirectory ? R.string.directory_picker_title : R.string.picker_title, this.mRootView);

    this.mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dlg, int which) {
                    dlg.cancel();
                }
            });
    if (pickingDirectory) {
        this.mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.select),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dlg, int which) {
                        PickerActivity.this.mFso = PickerActivity.this.mCurrentDirectory;
                        dlg.dismiss();
                    }
                });
    }
    this.mDialog.setCancelable(true);
    this.mDialog.setOnCancelListener(this);
    this.mDialog.setOnDismissListener(this);
    DialogHelper.delegateDialogShow(this, this.mDialog);

    // Set content description of storage volume button
    ButtonItem fs = (ButtonItem) this.mRootView.findViewById(R.id.ab_filesystem_info);
    fs.setContentDescription(getString(R.string.actionbar_button_storage_cd));

    final File initialDir = getInitialDirectoryFromIntent(getIntent());
    final String rootDirectory;

    if (initialDir != null) {
        rootDirectory = initialDir.getAbsolutePath();
    } else {
        rootDirectory = FileHelper.ROOT_DIRECTORY;
    }

    this.mHandler = new Handler();
    this.mHandler.post(new Runnable() {
        @Override
        public void run() {
            // Navigate to. The navigation view will redirect to the appropriate directory
            PickerActivity.this.mNavigationFragment.changeCurrentDir(rootDirectory);
        }
    });

}

From source file:org.opendatakit.survey.android.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  w w  .  j  ava 2 s. 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.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(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.asUriFragment(appName, 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:most.voip.example.remote_config.MainActivity.java

public void ignoreConfig(View view) {
    Intent resultIntent = new Intent();
    Log.d(TAG, "Configuration refused");
    setResult(Activity.RESULT_CANCELED, resultIntent);
    finish();/*from  www  .  j av a 2 s. c o  m*/
}

From source file:org.opendatakit.survey.android.activities.MediaCaptureImageActivity.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 w w  . j a  va 2  s.c  o m*/
        return;
    }

    if (uriFragmentToMedia == null) {
        // we are in trouble
        WebLogger.getLogger(appName).e(t, "Unexpectedly null uriFragmentToMedia!");
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }

    if (uriFragmentNewFileBase == null) {
        // we are in trouble
        WebLogger.getLogger(appName).e(t, "Unexpectedly null newFileBase!");
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }

    File f = ODKFileUtils.getAsFile(appName, uriFragmentToMedia);
    Uri mediaUri = Uri.fromFile(f);
    // we never have to deal with deleting, as the Camera is overwriting
    // this...

    // get the file path and create a copy in the instance folder
    String binaryPath = MediaUtils.getPathFromUri(this, (Uri) mediaUri, Images.Media.DATA);
    String extension = binaryPath.substring(binaryPath.lastIndexOf("."));

    File source = new File(binaryPath);
    File sourceMedia = ODKFileUtils.getAsFile(appName, uriFragmentNewFileBase + extension);
    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();
        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(Images.Media.EXTERNAL_CONTENT_URI,
                values);
        WebLogger.getLogger(appName).i(t, "Inserting IMAGE returned uri = " + MediaURI.toString());

        if (uriFragmentToMedia != null) {
            deleteMedia();
        }
        uriFragmentToMedia = ODKFileUtils.asUriFragment(appName, sourceMedia);
        WebLogger.getLogger(appName).i(t, "Setting current answer to " + sourceMedia.getAbsolutePath());
    } else {
        if (uriFragmentToMedia != null) {
            deleteMedia();
        }
        uriFragmentToMedia = null;
        WebLogger.getLogger(appName).e(t, "Inserting Image file FAILED");
    }

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