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:org.safegees.safegees.gui.view.MainActivity.java

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

    if (requestCode == 1) {
        if (resultCode == Activity.RESULT_OK) {
            shareDataWithServer();/*from   w  w  w  .  ja  va2  s  .c  o m*/
        }
        if (resultCode == Activity.RESULT_CANCELED) {
            //Write your code if there's no result
            start();
        }
    }
}

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

/**
 * 3. Verify that install worked//w ww .j  a  va 2s .c om
 */
private void postInstall() {
    // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    final boolean success = Installer.hasSystemPermissions(this, this.getPackageManager());

    // enable system installer on installation success
    Preferences.get().setSystemInstallerEnabled(success);

    AlertDialog.Builder builder = new AlertDialog.Builder(theme)
            .setTitle(success ? R.string.system_install_post_success : R.string.system_install_post_fail)
            .setMessage(success ? R.string.system_install_post_success_message
                    : R.string.system_install_post_fail_message)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    InstallIntoSystemDialogActivity.this
                            .setResult(success ? Activity.RESULT_OK : Activity.RESULT_CANCELED);
                    InstallIntoSystemDialogActivity.this.finish();
                    startActivity(new Intent(InstallIntoSystemDialogActivity.this, FDroid.class));
                }
            }).setCancelable(false);
    builder.create().show();
}

From source file:org.mozilla.gecko.AwesomeBar.java

private void cancelAndFinish() {
    setResult(Activity.RESULT_CANCELED);
    finish();
    overridePendingTransition(0, 0);
}

From source file:org.fdroid.fdroid.FDroidApp.java

public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
    if (resultCode == Activity.RESULT_CANCELED) {
        return;/*  ww w  .j  a va  2 s  .c o  m*/
    }
    String bluetoothPackageName = null;
    String className = null;
    boolean found = false;
    Intent sendBt = null;
    try {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        sendBt = new Intent(Intent.ACTION_SEND);
        // The APK type is blocked by stock Android, so use zip
        // sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir));
        // not all devices have the same Bluetooth Activities, so
        // let's find it
        for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) {
            bluetoothPackageName = info.activityInfo.packageName;
            if ("com.android.bluetooth".equals(bluetoothPackageName)
                    || "com.mediatek.bluetooth".equals(bluetoothPackageName)) {
                className = info.activityInfo.name;
                found = true;
                break;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not get application info to send via bluetooth", e);
        found = false;
    }
    if (sendBt != null) {
        if (found) {
            sendBt.setClassName(bluetoothPackageName, className);
            activity.startActivity(sendBt);
        } else {
            Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show();
            activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send)));
        }
    }
}

From source file:com.jtechme.apphub.FDroidApp.java

public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
    if (resultCode == Activity.RESULT_CANCELED)
        return;/*  w  w w  . j ava2  s  .co m*/
    String bluetoothPackageName = null;
    String className = null;
    boolean found = false;
    Intent sendBt = null;
    try {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        sendBt = new Intent(Intent.ACTION_SEND);
        // The APK type is blocked by stock Android, so use zip
        // sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir));
        // not all devices have the same Bluetooth Activities, so
        // let's find it
        for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) {
            bluetoothPackageName = info.activityInfo.packageName;
            if ("com.android.bluetooth".equals(bluetoothPackageName)
                    || "com.mediatek.bluetooth".equals(bluetoothPackageName)) {
                className = info.activityInfo.name;
                found = true;
                break;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not get application info to send via bluetooth", e);
        found = false;
    }
    if (sendBt != null) {
        if (found) {
            sendBt.setClassName(bluetoothPackageName, className);
            activity.startActivity(sendBt);
        } else {
            Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show();
            activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send)));
        }
    }
}

From source file:io.romain.passport.ui.AddCityActivity.java

@OnClick({ R.id.add_city_cancel })
// R.id.dialog_outer_frame,
void dismiss() {
    dismiss(Activity.RESULT_CANCELED, null);
}

From source file:cx.ring.fragments.CallFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    SipCall transfer;/*  ww w .  ja  v  a  2  s  . c o m*/
    if (requestCode == REQUEST_TRANSFER) {
        switch (resultCode) {
        case TransferDFragment.RESULT_TRANSFER_CONF:
            Conference c = data.getParcelableExtra("target");
            transfer = data.getParcelableExtra("transfer");
            try {

                mCallbacks.getRemoteService().attendedTransfer(transfer.getCallId(),
                        c.getParticipants().get(0).getCallId());

            } catch (RemoteException e) {
                e.printStackTrace();
            }
            break;

        case TransferDFragment.RESULT_TRANSFER_NUMBER:
            String to = data.getStringExtra("to_number");
            transfer = data.getParcelableExtra("transfer");
            try {
                mCallbacks.getRemoteService().transfer(transfer.getCallId(), to);
                mCallbacks.getRemoteService().hangUp(transfer.getCallId());
            } catch (RemoteException e) {
                e.printStackTrace();
            }
            break;
        case Activity.RESULT_CANCELED:
        default:
            initNormalStateDisplay();
            break;
        }
    }
}

From source file:com.yoval.community.chatapp.DistanceActivity.java

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

    switch (requestCode) {
    // Check for the integer request code originally supplied to startResolutionForResult().
    case REQUEST_CHECK_SETTINGS:
        switch (resultCode) {
        case Activity.RESULT_OK:
            //User agreed to make required location settings changes.

            break;
        case Activity.RESULT_CANCELED:
            //User chose not to make required location settings changes
            // Close the app
            finish();/*from   w  w  w. j a v  a  2  s.co  m*/
            break;
        }
        break;

    case SIGN_IN_REQUEST_CODE:
        if (resultCode == RESULT_OK) {
            Toast.makeText(this, "Successfully signed in. Welcome!", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "We couldn't sign you in. Please try again later.", Toast.LENGTH_LONG).show();

            // Close the app
            finish();
        }
        break;
    }

}

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

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

    if (requestCode == REAUTH_ACTIVITY_CODE) {
        // This ensures a session state change is recorded so that the tokenUpdated() callback is triggered
        // to attempt a post if the write permissions have been granted
        Log.i(FriendSmashApplication.TAG, "Reauthorized with publish permissions.");
        Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data);
    } else if (resultCode == Activity.RESULT_OK && data != null) {
        // Finished a game
        Bundle bundle = data.getExtras();
        application.setScore(bundle.getInt("score"));
        updateYouScoredTextView();// w w w .ja  v a  2s  . c o  m
        updateButtonVisibility();
        completeGameOver(1500);
    } else if (resultCode == Activity.RESULT_FIRST_USER && data != null) {
        // Came from the ScoreboardFragment, so start a game with the specific user who has been clicked
        Intent i = new Intent(getActivity(), GameActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("user_id", data.getStringExtra("user_id"));
        i.putExtras(bundle);
        startActivityForResult(i, 0);
    } else if (resultCode == Activity.RESULT_CANCELED && data != null) {
        Bundle bundle = data.getExtras();
        ((HomeActivity) getActivity()).showError(bundle.getString("error"), false);
    } else if (resultCode == Activity.RESULT_CANCELED
            && ((FriendSmashApplication) getActivity().getApplication())
                    .getGameFragmentFBRequestError() != null) {
        ((HomeActivity) getActivity()).handleError(
                ((FriendSmashApplication) getActivity().getApplication()).getGameFragmentFBRequestError(),
                false);
        ((FriendSmashApplication) getActivity().getApplication()).setGameFragmentFBRequestError(null);
    }
}

From source file:de.schildbach.wallet.ui.backup.BackupWalletDialogFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (requestCode == REQUEST_CODE_CREATE_DOCUMENT) {
        if (resultCode == Activity.RESULT_OK) {
            final Uri targetUri = intent.getData();
            final String password = passwordView.getText().toString().trim();
            checkState(!password.isEmpty());
            wipePasswords();//from   w  w w.  java  2 s  .c  o m
            dismiss();

            final Wallet wallet = viewModel.wallet.getValue();
            final Protos.Wallet walletProto = new WalletProtobufSerializer().walletToProto(wallet);

            try (final Writer cipherOut = new OutputStreamWriter(
                    activity.getContentResolver().openOutputStream(targetUri), StandardCharsets.UTF_8)) {
                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                walletProto.writeTo(baos);
                baos.close();
                final byte[] plainBytes = baos.toByteArray();

                cipherOut.write(Crypto.encrypt(plainBytes, password.toCharArray()));
                cipherOut.flush();
                application.getConfiguration().disarmBackupReminder();

                final String target = uriToTarget(targetUri);
                log.info("backed up wallet to: '" + targetUri + "'"
                        + (target != null ? " (" + target + ")" : ""));
                SuccessDialogFragment.showDialog(getFragmentManager(),
                        target != null ? target : targetUri.toString());
            } catch (final IOException x) {
                log.error("problem backing up wallet", x);
                ErrorDialogFragment.showDialog(getFragmentManager(), x.toString());
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            log.info("cancelled backing up wallet");
            passwordView.setEnabled(true);
            passwordAgainView.setEnabled(true);
        }
    } else {
        super.onActivityResult(requestCode, resultCode, intent);
    }
}