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.jefftharris.passwdsafe.sync.lib.AccountChooserDlg.java

/** Handle a selected account */
private void onAccountSelected(String accountName) {
    Bundle args = getArguments();/*from w  w w  .j av  a2 s. co m*/
    int requestCode = args.getInt("requestCode");

    int result;
    Intent intent = new Intent();
    if (accountName != null) {
        intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName);
        result = Activity.RESULT_OK;
    } else {
        result = Activity.RESULT_CANCELED;
    }

    PendingIntent pendIntent = getActivity().createPendingResult(requestCode, intent,
            PendingIntent.FLAG_ONE_SHOT);
    try {
        pendIntent.send(result);
    } catch (PendingIntent.CanceledException e) {
        Log.e(TAG, "intent send failed", e);
    }
}

From source file:circleplus.app.UserInfoFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_CANCELED || getActivity() == null) {
        mEmptyFrame.setVisibility(View.VISIBLE);
        mInfoFrame.setVisibility(View.GONE);
        return;// www .  j a v  a2 s  . c  om
    }
    if (requestCode == LOGIN_REQ_CODE) {
        mUser = UserUtils.getUserInfo(getActivity());
        refreshViewInfo();
    }
}

From source file:com.kaliturin.blacklist.fragments.AddOrEditContactFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    numbersViewList = (LinearLayout) view.findViewById(R.id.numbers_list);

    // snack bar/*  www .  j av a 2s  .  c  o m*/
    ButtonsBar snackBar = new ButtonsBar(view, R.id.three_buttons_bar);
    // "Cancel" button
    snackBar.setButton(R.id.button_left, getString(R.string.CANCEL), new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finishActivity(Activity.RESULT_CANCELED);
        }
    });
    // "Save" button
    snackBar.setButton(R.id.button_right, getString(R.string.SAVE), new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!Permissions.notifyIfNotGranted(getContext(), Permissions.WRITE_EXTERNAL_STORAGE)) {
                int result = (saveContact() ? Activity.RESULT_OK : Activity.RESULT_CANCELED);
                finishActivity(result);
            }
        }
    });
    snackBar.show();

    // 'add new row' button click listener
    View button = view.findViewById(R.id.button_add_another);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showAddContactsMenuDialog();
        }
    });

    if (savedInstanceState == null) {
        if (contactId < 0) {
            // add the first empty row to the numbers list
            addRowToNumbersList("", ContactNumber.TYPE_EQUALS);
        } else {
            // get contact by id
            DatabaseAccessHelper db = DatabaseAccessHelper.getInstance(getContext());
            if (db != null) {
                ContactCursorWrapper cursor = db.getContact(contactId);
                if (cursor != null) {
                    // add contact numbers to the list
                    addRowsToNumbersList(cursor.getContact());
                    cursor.close();
                } else {
                    finishActivity(Activity.RESULT_CANCELED);
                }
            }
        }
    }
}

From source file:org.opendatakit.survey.android.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();//from   w  w w  . j av a  2  s  .co 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, Audio.Media.DATA);
    File sourceMedia = new File(sourceMediaPath);
    String extension = sourceMediaPath.substring(sourceMediaPath.lastIndexOf("."));

    File newMedia = ODKFileUtils.getAsFile(appName, 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(URI_FRAGMENT, ODKFileUtils.asUriFragment(appName, newMediaFromCP));
        String name = newMediaFromCP.getName();
        i.putExtra(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.android.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();//from ww  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, Video.Media.DATA);
    File sourceMedia = new File(sourceMediaPath);
    String extension = sourceMediaPath.substring(sourceMediaPath.lastIndexOf("."));

    File newMedia = ODKFileUtils.getAsFile(appName, 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(URI_FRAGMENT, ODKFileUtils.asUriFragment(appName, newMediaFromCP));
        String name = newMediaFromCP.getName();
        i.putExtra(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.android.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();/*from www  .  j  a va2s  . co m*/
        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.getAsFile(appName, 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(URI_FRAGMENT, ODKFileUtils.asUriFragment(appName, newMediaFromCP));
        String name = newMediaFromCP.getName();
        i.putExtra(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:com.google.zxing.client.android.plugin.BarcodeScanner.java

/**
 * Called when the barcode scanner intent completes
 *
 * @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").
 *///from w w w  . j  a  v  a2  s .c  o m
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, intent.getStringExtra("result"));
                obj.put(FORMAT, intent.getStringExtra("format"));
                obj.put(CANCELLED, false);
            } catch (JSONException e) {
                //Log.d(LOG_TAG, "This should never happen");
            }

            this.cbContext.success(obj);

        } else if (resultCode == Activity.RESULT_CANCELED) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, "");
                obj.put(FORMAT, "");
                obj.put(CANCELLED, true);
            } catch (JSONException e) {
                //Log.d(LOG_TAG, "This should never happen");
            }

            this.cbContext.success(obj);

        } else {

            this.cbContext.error("Invalid Activity");

        }
    }
}

From source file:com.money.manager.ex.budget.BudgetListFragment.java

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

    if (resultCode == Activity.RESULT_CANCELED)
        return;/*ww w .j  a v a 2 s.com*/

    switch (requestCode) {
    case REQUEST_EDIT_BUDGET:
        // refresh budget list
        getLoaderManager().restartLoader(LOADER_BUDGETS, null, this);
        break;
    }
}

From source file:com.facebook.android.friendsmash.ScoreboardFragment.java

private void closeAndShowError(String error) {
    Bundle bundle = new Bundle();
    bundle.putString("error", error);

    Intent i = new Intent();
    i.putExtras(bundle);//  w  ww .ja va2  s.co  m

    getActivity().setResult(Activity.RESULT_CANCELED, i);
    getActivity().finish();
}

From source file:cn.tycoon.lighttrans.fileManager.AbstractFilePickerActivity.java

@Override
@SuppressWarnings("unchecked")
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_filepicker);

    Intent intent = getIntent();//from w w  w .j a  v  a2 s . c  o m
    if (intent != null) {
        startPath = intent.getStringExtra(EXTRA_START_PATH);
        mode = intent.getIntExtra(EXTRA_MODE, mode);
        allowCreateDir = intent.getBooleanExtra(EXTRA_ALLOW_CREATE_DIR, allowCreateDir);
        allowMultiple = intent.getBooleanExtra(EXTRA_ALLOW_MULTIPLE, allowMultiple);
    }

    FragmentManager fm = getSupportFragmentManager();
    AbstractFilePickerFragment<T> fragment = (AbstractFilePickerFragment<T>) fm.findFragmentByTag(TAG);

    if (fragment == null) {
        fragment = getFragment(startPath, mode, allowMultiple, allowCreateDir);
    }

    if (fragment != null) {
        fm.beginTransaction().replace(R.id.fragment, fragment, TAG).commit();
    }

    // Default to cancelled
    setResult(Activity.RESULT_CANCELED);
}