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:de.ub0r.android.websms.WebSMS.java

/**
 * Send a command as broadcast./*w ww . j ava2s.  co  m*/
 *
 * @param context   Current context
 * @param connector {@link ConnectorSpec}
 * @param command   {@link ConnectorCommand}
 */
static void runCommand(final Context context, final ConnectorSpec connector, final ConnectorCommand command) {
    connector.setErrorMessage((String) null);
    final Intent intent = command.setToIntent(null);
    short t = command.getType();
    boolean sendOrdered = false;
    switch (t) {
    case ConnectorCommand.TYPE_BOOTSTRAP:
        sendOrdered = true;
        intent.setAction(connector.getPackage() + Connector.ACTION_RUN_BOOTSTRAP);
        connector.addStatus(ConnectorSpec.STATUS_BOOTSTRAPPING);
        break;
    case ConnectorCommand.TYPE_SEND:
        sendOrdered = true;
        intent.setAction(connector.getPackage() + Connector.ACTION_RUN_SEND);
        connector.setToIntent(intent);
        connector.addStatus(ConnectorSpec.STATUS_SENDING);
        if (command.getResendCount() == 0) {
            WebSMSReceiver.saveMessage(me, connector, command, WebSMSReceiver.MESSAGE_TYPE_DRAFT);
        }
        break;
    case ConnectorCommand.TYPE_UPDATE:
        intent.setAction(connector.getPackage() + Connector.ACTION_RUN_UPDATE);
        connector.addStatus(ConnectorSpec.STATUS_UPDATING);
        break;
    default:
        break;
    }
    updateProgressBar();
    intent.setFlags(intent.getFlags() | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    Log.d(TAG, "send broadcast: " + intent.getAction());
    if (sendOrdered) {
        context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() {
            @Override
            public void onReceive(final Context context, final Intent intent) {
                if (this.getResultCode() != Activity.RESULT_OK) {
                    ConnectorCommand command = new ConnectorCommand(intent);
                    ConnectorSpec specs = new ConnectorSpec(intent);
                    specs.setErrorMessage(// TODO: localize
                            "Connector did not react on message");
                    WebSMSReceiver.handleSendCommand(context, specs, command);
                }
            }
        }, null, Activity.RESULT_CANCELED, null, null);
    } else {
        context.sendBroadcast(intent);
    }
}

From source file:com.ichi2.anki2.StudyOptionsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    Log.i(AnkiDroidApp.TAG, "StudyOptionsFragment: onActivityResult");

    if (resultCode == DeckPicker.RESULT_DB_ERROR) {
        closeStudyOptions(DeckPicker.RESULT_DB_ERROR);
    }//from  w ww.  j a  va2 s  .  c  o m

    if (resultCode == AnkiDroidApp.RESULT_TO_HOME) {
        closeStudyOptions();
        return;
    }

    // TODO: proper integration of big widget
    if (resultCode == DeckPicker.RESULT_MEDIA_EJECTED) {
        closeStudyOptions(DeckPicker.RESULT_MEDIA_EJECTED);
    } else {
        if (!AnkiDroidApp.colIsOpen()) {
            reloadCollection();
            mDontSaveOnStop = false;
            return;
        }
        if (requestCode == DECK_OPTIONS) {
            if (mCramInitialConfig != null) {
                mCramInitialConfig = null;
                try {
                    JSONObject deck = AnkiDroidApp.getCol().getDecks().current();
                    if (deck.getInt("dyn") != 0 && deck.has("empty")) {
                        deck.remove("empty");
                    }
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
                rebuildCramDeck();
            } else {
                resetAndUpdateValuesFromDeck();
            }
        } else if (requestCode == ADD_NOTE && resultCode != Activity.RESULT_CANCELED) {
            resetAndUpdateValuesFromDeck();
        } else if (requestCode == REQUEST_REVIEW) {
            Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
            // TODO: Return to standard scheduler
            // TODO: handle big widget
            switch (resultCode) {
            default:
                // do not reload counts, if activity is created anew because it has been before destroyed by android
                resetAndUpdateValuesFromDeck();
                break;
            case Reviewer.RESULT_NO_MORE_CARDS:
                prepareCongratsView();
                setFragmentContentView(mCongratsView);
                break;
            }
            mDontSaveOnStop = false;
        } else if (requestCode == BROWSE_CARDS
                && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
            mDontSaveOnStop = false;
            resetAndUpdateValuesFromDeck();
        } else if (requestCode == STATISTICS && mCurrentContentView == CONTENT_CONGRATS) {
            resetAndUpdateValuesFromDeck();
            mCurrentContentView = CONTENT_STUDY_OPTIONS;
            setFragmentContentView(mStudyOptionsView);
        }
    }
}

From source file:com.facebook.Session.java

private void handleAuthorizationResult(int resultCode, AuthorizationClient.Result result) {
    AccessToken newToken = null;/* www  .j av a 2  s  . c  o  m*/
    Exception exception = null;
    if (resultCode == Activity.RESULT_OK) {
        if (result.code == AuthorizationClient.Result.Code.SUCCESS) {
            newToken = result.token;
        } else {
            exception = new FacebookAuthorizationException(result.errorMessage);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        exception = new FacebookOperationCanceledException(result.errorMessage);
    }

    logAuthorizationComplete(result.code, result.loggingExtras, exception);

    authorizationClient = null;
    finishAuthOrReauth(newToken, exception);
}

From source file:com.hichinaschool.flashcards.anki.StudyOptionsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    // Log.i(AnkiDroidApp.TAG, "StudyOptionsFragment: onActivityResult");

    if (resultCode == DeckPicker.RESULT_DB_ERROR) {
        closeStudyOptions(DeckPicker.RESULT_DB_ERROR);
    }//from   ww  w .  ja  va 2 s  . c o  m

    if (resultCode == AnkiDroidApp.RESULT_TO_HOME) {
        closeStudyOptions();
        return;
    }

    // TODO: proper integration of big widget
    if (resultCode == DeckPicker.RESULT_MEDIA_EJECTED) {
        closeStudyOptions(DeckPicker.RESULT_MEDIA_EJECTED);
    } else {
        if (!AnkiDroidApp.colIsOpen()) {
            reloadCollection();
            mDontSaveOnStop = false;
            return;
        }
        if (requestCode == DECK_OPTIONS) {
            if (mCramInitialConfig != null) {
                mCramInitialConfig = null;
                try {
                    JSONObject deck = AnkiDroidApp.getCol().getDecks().current();
                    if (deck.getInt("dyn") != 0 && deck.has("empty")) {
                        deck.remove("empty");
                    }
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
                rebuildCramDeck();
            } else {
                resetAndUpdateValuesFromDeck();
            }
        } else if (requestCode == ADD_NOTE && resultCode != Activity.RESULT_CANCELED) {
            resetAndUpdateValuesFromDeck();
        } else if (requestCode == REQUEST_REVIEW) {
            // Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
            // TODO: Return to standard scheduler
            // TODO: handle big widget
            switch (resultCode) {
            default:
                // do not reload counts, if activity is created anew because it has been before destroyed by android
                resetAndUpdateValuesFromDeck();
                break;
            case Reviewer.RESULT_NO_MORE_CARDS:
                prepareCongratsView();
                setFragmentContentView(mCongratsView);
                break;
            }
            mDontSaveOnStop = false;
        } else if (requestCode == BROWSE_CARDS
                && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
            mDontSaveOnStop = false;
            resetAndUpdateValuesFromDeck();
        } else if (requestCode == STATISTICS && mCurrentContentView == CONTENT_CONGRATS) {
            resetAndUpdateValuesFromDeck();
            mCurrentContentView = CONTENT_STUDY_OPTIONS;
            setFragmentContentView(mStudyOptionsView);
        }
    }
}

From source file:com.TagFu.facebook.Session.java

private void tryLegacyAuth(final AuthorizationRequest request) {

    this.authorizationClient = new AuthorizationClient();
    this.authorizationClient.setOnCompletedListener(new AuthorizationClient.OnCompletedListener() {

        @Override/* w ww  .  ja v  a 2  s  . c  om*/
        public void onCompleted(final AuthorizationClient.Result result) {

            int activityResult;
            if (result.code == AuthorizationClient.Result.Code.CANCEL) {
                activityResult = Activity.RESULT_CANCELED;
            } else {
                activityResult = Activity.RESULT_OK;
            }
            Session.this.handleAuthorizationResult(activityResult, result);
        }
    });
    this.authorizationClient.setContext(getStaticContext());
    this.authorizationClient.startOrContinueAuth(request.getAuthorizationClientRequest());
}

From source file:com.facebook.Session.java

private void tryLegacyAuth(final AuthorizationRequest request) {
    authorizationClient = new AuthorizationClient();
    authorizationClient.setOnCompletedListener(new AuthorizationClient.OnCompletedListener() {
        @Override//from  w  w w .  j  av  a  2 s  .  c om
        public void onCompleted(AuthorizationClient.Result result) {
            int activityResult;
            if (result.code == AuthorizationClient.Result.Code.CANCEL) {
                activityResult = Activity.RESULT_CANCELED;
            } else {
                activityResult = Activity.RESULT_OK;
            }
            handleAuthorizationResult(activityResult, result);
        }
    });
    authorizationClient.setContext(getStaticContext());
    authorizationClient.startOrContinueAuth(request.getAuthorizationClientRequest());
}

From source file:no.barentswatch.fiskinfo.BaseActivity.java

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

    if (resultCode == Activity.RESULT_OK) {
        String filePath = data.getStringExtra(FileDialog.RESULT_PATH) + "/";
        setFilePathForExternalStorage(filePath);
        Toast mToast = Toast.makeText(getContext(), "SELECTED FILEPATH AT: " + filePath, Toast.LENGTH_LONG);
        writeFilePathToDisk(filePath);//from  w w  w. java  2s .  c om
        mToast.show();

    } else if (resultCode == Activity.RESULT_CANCELED) {

    }

}

From source file:com.TagFu.facebook.Session.java

void handleAuthorizationResult(final int resultCode, final AuthorizationClient.Result result) {

    AccessToken newToken = null;//from  ww w.  j  ava  2 s .  co  m
    Exception exception = null;
    if (resultCode == Activity.RESULT_OK) {
        if (result.code == AuthorizationClient.Result.Code.SUCCESS) {
            newToken = result.token;
        } else {
            exception = new FacebookAuthorizationException(result.errorMessage);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        exception = new FacebookOperationCanceledException(result.errorMessage);
    }

    this.logAuthorizationComplete(result.code, result.loggingExtras, exception);

    this.authorizationClient = null;
    this.finishAuthOrReauth(newToken, exception);
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

@Override
public void onIntroResultListener(Bundle data) {
    int resultCode = data.getInt(extra.RESULT_CODE);
    DraftData d = DraftData.INSTANCE;/*from   w ww. j a  v a  2  s .  c o  m*/

    switch (resultCode) {
    case IntroductionFragment.RESULT_RECIPSEL1:
        // user wants to pick a recipient
        showRecipientSelect(VIEW_RECIPSEL1);
        break;
    case IntroductionFragment.RESULT_RECIPSEL2:
        // user wants to pick a recipient
        showRecipientSelect(VIEW_RECIPSEL2);
        break;

    case IntroductionFragment.RESULT_SLINGKEYS:
        setTab(Tabs.SLINGKEYS);
        refreshView();
        break;
    case IntroductionFragment.RESULT_SEND:
        if (data != null) {
            long groupSentTime = System.currentTimeMillis();

            // TODO: place in AsyncTask with progress for slower devices

            MessageData sendMsg1 = new MessageData();
            MessageData sendMsg2 = new MessageData();
            // set sent time closest to UI command
            sendMsg1.setDateSent(groupSentTime);
            sendMsg2.setDateSent(groupSentTime);

            RecipientRow recip1 = null;
            RecipientRow recip2 = null;

            RecipientDbAdapter dbRecipient = RecipientDbAdapter.openInstance(getApplicationContext());
            // update
            long rowIdRecipient1 = data.getLong(extra.RECIPIENT_ROW_ID1, -1);
            if (rowIdRecipient1 > -1) {
                Cursor c = dbRecipient.fetchRecipient(rowIdRecipient1);
                if (c != null) {
                    try {
                        if (c.moveToFirst()) {
                            recip1 = new RecipientRow(c);
                        } else {
                            showNote(R.string.error_InvalidRecipient);
                            break;
                        }
                    } finally {
                        c.close();
                    }
                }
            }

            long rowIdRecipient2 = data.getLong(extra.RECIPIENT_ROW_ID2, -1);
            if (rowIdRecipient2 > -1) {
                Cursor c = dbRecipient.fetchRecipient(rowIdRecipient2);
                if (c != null) {
                    try {
                        if (c.moveToFirst()) {
                            recip2 = new RecipientRow(c);
                        } else {
                            showNote(R.string.error_InvalidRecipient);
                            break;
                        }
                    } finally {
                        c.close();
                    }
                }
            }

            // user wants to post the file and notify recipient
            if (recip1 == null || recip2 == null) {
                showNote(R.string.error_InvalidRecipient);
                refreshView();
                break;
            }
            if (recip1.getNotify() == SafeSlingerConfig.NOTIFY_NOPUSH
                    || recip2.getNotify() == SafeSlingerConfig.NOTIFY_NOPUSH) {
                showNote(R.string.error_InvalidRecipient);
                refreshView();
                break;
            }

            if (recip1.isDeprecated() || recip2.isDeprecated()) {
                showNote(R.string.error_AllMembersMustUpgradeBadKeyFormat);
                refreshView();
                break;
            }

            String text1 = data.getString(extra.TEXT_MESSAGE1);
            if (!TextUtils.isEmpty(text1))
                sendMsg1.setText(text1);

            String text2 = data.getString(extra.TEXT_MESSAGE2);
            if (!TextUtils.isEmpty(text2))
                sendMsg2.setText(text2);

            // create vcard data
            String vCard1 = null;
            String vCard2 = null;
            try {
                vCard1 = SSUtil.generateRecipientVCard(recip1);
                vCard2 = SSUtil.generateRecipientVCard(recip2);
            } catch (VCardException e) {
                showNote(e.getLocalizedMessage());
                refreshView();
                break;
            }

            if (TextUtils.isEmpty(vCard1) || TextUtils.isEmpty(vCard2)) {
                showNote(R.string.error_VcardParseFailure);
                refreshView();
                break;
            }

            // ensure push token and pub key in vCard
            StringBuilder errors = new StringBuilder();
            if (!vCard1.contains(SafeSlingerConfig.APP_KEY_PUSHTOKEN)) {
                errors.append(recip1.getName() + " Push is missing").append("\n");
            }
            if (!vCard1.contains(SafeSlingerConfig.APP_KEY_PUBKEY)) {
                errors.append(recip1.getName() + " PubKey is missing").append("\n");
            }
            if (!vCard2.contains(SafeSlingerConfig.APP_KEY_PUSHTOKEN)) {
                errors.append(recip2.getName() + " Push is missing").append("\n");
            }
            if (!vCard2.contains(SafeSlingerConfig.APP_KEY_PUBKEY)) {
                errors.append(recip2.getName() + " PubKey is missing").append("\n");
            }
            if (errors.length() > 0) {
                showNote(errors.toString());
                refreshView();
                break;
            }

            byte[] bVC1 = vCard1.getBytes();
            byte[] bVC2 = vCard2.getBytes();

            sendMsg1.setFileData(bVC2);
            sendMsg1.setFileSize(bVC2.length);
            sendMsg1.setFileName(SafeSlingerConfig.INTRODUCTION_VCF);
            sendMsg1.setFileType(
                    SafeSlingerConfig.MIMETYPE_CLASS + "/" + SafeSlingerConfig.MIMETYPE_FUNC_SECINTRO);

            sendMsg2.setFileData(bVC1);
            sendMsg2.setFileSize(bVC1.length);
            sendMsg2.setFileName(SafeSlingerConfig.INTRODUCTION_VCF);
            sendMsg2.setFileType(
                    SafeSlingerConfig.MIMETYPE_CLASS + "/" + SafeSlingerConfig.MIMETYPE_FUNC_SECINTRO);

            // automatic, do not keep introduction tab drafts
            doSendMessageStart(new MessageTransport[] { new MessageTransport(recip1, sendMsg1, false),
                    new MessageTransport(recip2, sendMsg2, false) });

            // reset after complete, little slow, better than nothing
            d.clearRecip1();
            d.clearRecip2();
        }
        break;
    case Activity.RESULT_CANCELED:
        // nothing to change...
        break;
    }
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * Finishes this activity./*from   w w  w  . ja v a 2  s  .co m*/
 * 
 * @param files
 *            list of {@link Uri}.
 */
private void finish(ArrayList<Uri> files) {
    if (files == null || files.isEmpty()) {
        getActivity().setResult(Activity.RESULT_CANCELED);
        getActivity().finish();
        return;
    }

    Intent intent = new Intent();
    if (files.size() == 1) {
        intent.setData(files.get(0));
    }
    intent.putParcelableArrayListExtra(FileChooserActivity.EXTRA_RESULTS, files);

    getActivity().setResult(FileChooserActivity.RESULT_OK, intent);

    if (DisplayPrefs.isRememberLastLocation(getActivity()) && getCurrentLocation() != null)
        DisplayPrefs.setLastLocation(getActivity(), getCurrentLocation().toString());
    else
        DisplayPrefs.setLastLocation(getActivity(), null);

    getActivity().finish();
}