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.if3games.chessonline.DroidFish.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case RESULT_SETTINGS:
        handlePrefsChange();//from w  w w .j  a  va  2 s .  c  o m
        break;
    case RESULT_EDITBOARD:
        if (resultCode == RESULT_OK) {
            try {
                String fen = data.getAction();
                ctrl.setFENOrPGN(fen);
                setBoardFlip(false);
            } catch (ChessParseError e) {
            }
        }
        break;
    case RESULT_LOAD_PGN:
        if (resultCode == RESULT_OK) {
            try {
                String pgn = data.getAction();
                int modeNr = ctrl.getGameMode().getModeNr();
                if ((modeNr != GameMode.ANALYSIS) && (modeNr != GameMode.EDIT_GAME))
                    newGameMode(GameMode.EDIT_GAME);
                ctrl.setFENOrPGN(pgn);
                setBoardFlip(true);
            } catch (ChessParseError e) {
                Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show();
            }
        }
        break;
    case RESULT_SELECT_SCID:
        if (resultCode == RESULT_OK) {
            String pathName = data.getAction();
            if (pathName != null) {
                Editor editor = settings.edit();
                editor.putString("currentScidFile", pathName);
                editor.putInt("currFT", FT_SCID);
                editor.commit();
                Intent i = new Intent(DroidFish.this, LoadScid.class);
                i.setAction("com.if3games.chessonline.loadScid");
                i.putExtra("com.if3games.chessonline.pathname", pathName);
                startActivityForResult(i, RESULT_LOAD_PGN);
            }
        }
        break;
    case RESULT_OI_PGN_LOAD:
        if (resultCode == RESULT_OK) {
            String pathName = getFilePathFromUri(data.getData());
            if (pathName != null)
                loadPGNFromFile(pathName);
        }
        break;
    case RESULT_OI_PGN_SAVE:
        if (resultCode == RESULT_OK) {
            String pathName = getFilePathFromUri(data.getData());
            if (pathName != null) {
                if ((pathName.length() > 0) && !pathName.contains("."))
                    pathName += ".pgn";
                savePGNToFile(pathName, false);
            }
        }
        break;
    case RESULT_OI_FEN_LOAD:
        if (resultCode == RESULT_OK) {
            String pathName = getFilePathFromUri(data.getData());
            if (pathName != null)
                loadFENFromFile(pathName);
        }
        break;
    case RESULT_GET_FEN:
        if (resultCode == RESULT_OK) {
            String fen = data.getStringExtra(Intent.EXTRA_TEXT);
            if (fen == null) {
                String pathName = getFilePathFromUri(data.getData());
                loadFENFromFile(pathName);
            }
            setFenHelper(fen);
        }
        break;
    case RESULT_LOAD_FEN:
        if (resultCode == RESULT_OK) {
            String fen = data.getAction();
            setFenHelper(fen);
        }
        break;
    // GMS
    case RC_SELECT_PLAYERS:
        // we got the result from the "select players" UI -- ready to create the room
        handleSelectPlayersResult(resultCode, data, gmsGameVariantNumber);
        break;
    case RC_INVITATION_INBOX:
        // we got the result from the "select invitation" UI (invitation inbox). We're
        // ready to accept the selected invitation:
        handleInvitationInboxResult(resultCode, data);
        break;
    case RC_WAITING_ROOM:
        // we got the result from the "waiting room" UI.
        if (resultCode == Activity.RESULT_OK) {
            // ready to start playing
            //Log.d(TAG, "Starting game (waiting room returned OK).");
            //if(!imNotFirst)
            //sendImFirstLevelNumberForStart();
            if (gmsGameVariantNumber != -1)
                startGame(true, gmsGameVariantNumber);
        } else if (resultCode == GamesActivityResultCodes.RESULT_LEFT_ROOM) {
            // player indicated that they want to leave the room
            leaveRoom();
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // Dialog was cancelled (user pressed back key, for instance). In our game,
            // this means leaving the room too. In more elaborate games, this could mean
            // something else (like minimizing the waiting room UI).
            leaveRoom();
        }
        break;
    }
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Finishes this activity.//from   www  .  jav a  2s .  c o  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();
    intent.putParcelableArrayListExtra(FileChooserActivity.EXTRA_RESULTS, files);
    getActivity().setResult(FileChooserActivity.RESULT_OK, intent);

    saveSettingsAndFinish();
}

From source file:com.android.gallery3d.app.PhotoPage.java

@Override
protected void onStateResult(int requestCode, int resultCode, Intent data) {
    /// M: [BUG.ADD] mark we are not starting video player, to re-enable toggleBars() @{
    mIsStartingVideoPlayer = false;// w  w w  .ja va  2s .com
    /// @}
    /// M: [FEATURE.ADD] @{
    if (mExtActivityResultListener != null) {
        mExtActivityResultListener.onActivityResult(requestCode, resultCode, data);
        mExtActivityResultListener = null;
    }
    /// @}
    /// M: [BUG.MODIFY] @{
    /*if (resultCode == Activity.RESULT_CANCELED) {*/
    if (resultCode == Activity.RESULT_CANCELED && requestCode != REQUEST_PLAY_VIDEO) {
        /// @}
        // This is a reset, not a canceled
        return;
    }
    mRecenterCameraOnResume = false;
    switch (requestCode) {
    case REQUEST_EDIT:
        setCurrentPhotoByIntentEx(data);
        break;
    /// M: [FEATURE.ADD] SlideVideo @{
    case REQUEST_TRIM:
        if (data != null) {
            redirectCurrentMedia(data.getData(), false);
        }
        break;
    /// @}
    case REQUEST_CROP:
        if (resultCode == Activity.RESULT_OK) {
            setCurrentPhotoByIntentEx(data);
        }
        break;
    case REQUEST_CROP_PICASA: {
        if (resultCode == Activity.RESULT_OK) {
            Context context = mActivity.getAndroidContext();
            String message = context.getString(R.string.crop_saved,
                    context.getString(R.string.folder_edited_online_photos));
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        }
        break;
    }
    case REQUEST_SLIDESHOW: {
        if (data == null)
            break;
        String path = data.getStringExtra(SlideshowPage.KEY_ITEM_PATH);
        int index = data.getIntExtra(SlideshowPage.KEY_PHOTO_INDEX, 0);
        if (path != null) {
            mModel.setCurrentPhoto(Path.fromString(path), index);
        }
        break;
    }
    /// M: [FEATURE.ADD] added for Stereo feature.@{
    case BottomControlLayer.REQUEST_REFOCUS:
    case BottomControlLayer.REQUEST_FANCY_COLOR:
    case BottomControlLayer.REQUEST_BACKGROUND:
    case BottomControlLayer.REQUEST_COPY_PAST:
        if (resultCode == Activity.RESULT_OK) {
            setRefocusCurrentPhotoByIntent(data);
        }
        break;
    /// @}
    }
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragment.java

/**
 * Catch the result of a scanned barcode
 * @param requestCode a code to identity from whom we received the result
 * @param resultCode the type of result//from   w w w .j a va2  s  .c  o m
 * @param data the data received with the result
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    // check if from whom we received a callback
    if (requestCode == IntentIntegrator.REQUEST_CODE) {
        // from the zxing barcode scanner activity:

        // parse the result in a intentresult object
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);

        if (result != null) {
            if (result.getContents() == null) {
                mToast = Utility.showToast(getActivity(), mToast,
                        getString(R.string.notice_scan_barcode_cancelled));
            } else {

                // get the scanned code
                String barcode = result.getContents();

                // find the koopman by querying for scanned barcode (=erkenningsnummer)
                Cursor koopman = getContext().getContentResolver().query(MakkelijkeMarktProvider.mUriKoopman,
                        new String[] { MakkelijkeMarktProvider.Koopman.COL_ID },
                        MakkelijkeMarktProvider.Koopman.COL_ERKENNINGSNUMMER + " = ? ",
                        new String[] { barcode }, null);

                // set the koopman
                if (koopman != null && koopman.moveToFirst()) {
                    mKoopmanFragment.selectKoopman(
                            koopman.getInt(koopman.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_ID)),
                            DagvergunningFragmentKoopman.KOOPMAN_SELECTION_METHOD_SCAN_BARCODE);
                    mKoopmanFragment.mDagvergunningId = mId;
                    mKoopmanFragment.mErkenningsnummerEditText.setText(barcode);
                    mKoopmanFragment.mErkenningsnummerEditText.dismissDropDown();
                } else {
                    mToast = Utility.showToast(getActivity(), mToast,
                            getString(R.string.notice_koopman_not_found));
                }

                // close the cursor
                if (koopman != null) {
                    koopman.close();
                }
            }
        }
    } else if (requestCode == NFC_SCAN_REQUEST_CODE) {
        // from the nfc scan activity:

        if (resultCode == Activity.RESULT_OK) {

            String uid = data.getStringExtra(getString(R.string.scan_nfc_result_uid));
            if (uid != null) {

                // uppercase the scanned uid
                uid = uid.toUpperCase();

                // find the koopman by querying for scanned nfc tag uid
                Cursor koopman = getContext().getContentResolver().query(MakkelijkeMarktProvider.mUriKoopman,
                        new String[] { MakkelijkeMarktProvider.Koopman.COL_ID,
                                MakkelijkeMarktProvider.Koopman.COL_ERKENNINGSNUMMER },
                        MakkelijkeMarktProvider.Koopman.COL_PAS_UID + " = ? ", new String[] { uid }, null);

                // set the koopman
                if (koopman != null && koopman.moveToFirst()) {
                    mKoopmanFragment.selectKoopman(
                            koopman.getInt(koopman.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_ID)),
                            DagvergunningFragmentKoopman.KOOPMAN_SELECTION_METHOD_SCAN_NFC);
                    mKoopmanFragment.mDagvergunningId = mId;
                    mKoopmanFragment.mErkenningsnummerEditText.setText(koopman.getString(
                            koopman.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_ERKENNINGSNUMMER)));
                    mKoopmanFragment.mErkenningsnummerEditText.dismissDropDown();
                } else {

                    // show the progressbar
                    mProgressbar.setVisibility(View.VISIBLE);

                    // query api for koopman by pas uid
                    ApiGetKoopmanByPasUid getKoopman = new ApiGetKoopmanByPasUid(getContext());
                    getKoopman.setPasUid(uid);
                    getKoopman.enqueue();
                }

                // close the cursor
                if (koopman != null) {
                    koopman.close();
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            mToast = Utility.showToast(getContext(), mToast, getString(R.string.notice_scan_nfc_cancelled));
        }
    }
}

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    DraftData d = DraftData.INSTANCE;//www  .ja va  2  s.c  o m

    switch (requestCode) {

    case VIEW_FINDCONTACT_ID:
    case VIEW_PASSPHRASE_CHANGE_ID:
    case VIEW_PASSPHRASE_ID:
        SafeSlinger.setPassphraseOpen(false);
        switch (resultCode) {
        case RESULT_OK:
            if (data != null) {
                if (requestCode == VIEW_FINDCONTACT_ID) {
                    String passNew = data.getStringExtra(extra.PASS_PHRASE_NEW);
                    boolean preExistingKey = doPassEntryCheck(passNew, null, false);
                    if (!preExistingKey) {
                        CreateKeyTask createKey = new CreateKeyTask();
                        createKey.execute(passNew);
                        break;
                    }
                } else if (requestCode == VIEW_PASSPHRASE_CHANGE_ID) {
                    String passOld = data.getStringExtra(extra.PASS_PHRASE_OLD);
                    String passNew = data.getStringExtra(extra.PASS_PHRASE_NEW);
                    doPassEntryCheck(passNew, passOld, true);
                } else { // login
                    String passOld = data.getStringExtra(extra.PASS_PHRASE_OLD);
                    doPassEntryCheck(passOld, null, false);
                }

                if (loadCurrentPassPhrase()) {
                    processIntent(getIntent());
                }

                // if requested, and logged in, try to decrypt
                // messages
                String passCached = SafeSlinger.getCachedPassPhrase(SafeSlingerPrefs.getKeyIdString());
                if (SafeSlingerPrefs.getAutoDecrypt() && !TextUtils.isEmpty(passCached)) {
                    DecryptPendingTask decryptPending = new DecryptPendingTask();
                    decryptPending.execute(passCached);
                }
            }
            isSetupCheckComplete();
            break;
        case PassPhraseActivity.RESULT_CLOSEANDCONTINUE:
            isSetupCheckComplete();
            break;
        case RESULT_CANCELED:
            if (requestCode == VIEW_FINDCONTACT_ID) {
                // if cancel setting up new profile, save nothing
                // and push user selection back one
                int user = SafeSlingerPrefs.getUser();
                if (user > 0) {
                    SafeSlingerPrefs.setUser(user - 1);
                    deleteUser(user);
                }
            }
            // this separate task is now finished
            showExit(RESULT_CANCELED);
            break;
        case PassPhraseActivity.RESULT_BACKPRESSED:
            // this separate task is now finished
            showExit(RESULT_CANCELED);
            break;
        }
        break;

    case REQUEST_QRECEIVE_MGS:
        switch (resultCode) {
        case RESULT_OK:
            doGetPushRegistration();
            break;
        case RESULT_CANCELED:
            SafeSlingerPrefs.setPushRegistrationIdWriteOnlyC2dm(SafeSlingerConfig.NOTIFY_NOPUSH_TOKENDATA);
            isSetupCheckComplete();
            break;
        }
        break;

    case VIEW_RECIPSEL_ID:
        switch (resultCode) {
        case PickRecipientsActivity.RESULT_SLINGKEYS:
            setTab(Tabs.SLINGKEYS);
            refreshView();
            break;
        case PickRecipientsActivity.RESULT_RECIPSEL:
            RecipientDbAdapter dbRecipient = RecipientDbAdapter.openInstance(getApplicationContext());
            long rowIdRecipient = data.getLongExtra(extra.RECIPIENT_ROW_ID, -1L);
            Cursor c = dbRecipient.fetchRecipient(rowIdRecipient);
            if (c != null) {
                try {
                    if (c.moveToFirst()) {
                        d.setRecip(new RecipientRow(c));

                        CheckRegistrationStateTask task = new CheckRegistrationStateTask();
                        task.execute(d.getRecip());

                        setTab(Tabs.COMPOSE);
                        refreshView();
                    } else {
                        showNote(R.string.error_InvalidRecipient);
                        setTab(Tabs.COMPOSE);
                        refreshView();
                        break;
                    }
                } finally {
                    c.close();
                }
            }
            break;
        case Activity.RESULT_CANCELED:
            // clear the selection
            d.clearRecip();
            setTab(Tabs.COMPOSE);
            refreshView();
            break;
        }
        break;

    case VIEW_RECIPSEL1:
        switch (resultCode) {
        case PickRecipientsActivity.RESULT_SLINGKEYS:
            setTab(Tabs.SLINGKEYS);
            refreshView();
            break;
        case PickRecipientsActivity.RESULT_RECIPSEL:
            long rowIdRecipient1 = data.getLongExtra(extra.RECIPIENT_ROW_ID, -1);

            if (d.existsRecip2() && rowIdRecipient1 == d.getRecip2RowId()) {
                showNote(R.string.error_InvalidRecipient);
                break;
            }

            RecipientDbAdapter dbRecipient = RecipientDbAdapter.openInstance(getApplicationContext());
            Cursor c = dbRecipient.fetchRecipient(rowIdRecipient1);
            if (c != null) {
                try {
                    if (c.moveToFirst()) {
                        d.setRecip1(new RecipientRow(c));
                        refreshView();
                    } else {
                        showNote(R.string.error_InvalidRecipient);
                        break;
                    }
                } finally {
                    c.close();
                }
            }
            break;
        case Activity.RESULT_CANCELED:
            // clear the selection
            d.clearRecip1();
            setTab(Tabs.INTRO);
            refreshView();
            break;
        }
        break;

    case VIEW_RECIPSEL2:
        switch (resultCode) {
        case PickRecipientsActivity.RESULT_SLINGKEYS:
            setTab(Tabs.SLINGKEYS);
            refreshView();
            break;
        case PickRecipientsActivity.RESULT_RECIPSEL:
            long rowIdRecipient2 = data.getLongExtra(extra.RECIPIENT_ROW_ID, -1);

            if (d.existsRecip1() && rowIdRecipient2 == d.getRecip1RowId()) {
                showNote(R.string.error_InvalidRecipient);
                break;
            }

            RecipientDbAdapter dbRecipient = RecipientDbAdapter.openInstance(getApplicationContext());
            Cursor c = dbRecipient.fetchRecipient(rowIdRecipient2);
            if (c != null) {
                try {
                    if (c.moveToFirst()) {
                        d.setRecip2(new RecipientRow(c));
                        refreshView();
                    } else {
                        showNote(R.string.error_InvalidRecipient);
                        break;
                    }
                } finally {
                    c.close();
                }
            }
            break;
        case Activity.RESULT_CANCELED:
            // clear the selection
            d.clearRecip2();
            setTab(Tabs.INTRO);
            refreshView();
            break;
        }
        break;

    case VIEW_SETTINGS_ID:
        // handle potential language change
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            recreate();
        } else {
            // TODO: find better update for <= 2.3
            // startActivity(getIntent());
            // finish();
        }

        switch (resultCode) {
        case SettingsActivity.RESULT_NEW_PASSPHRASE:
            // remove cached pass
            SafeSlinger.removeCachedPassPhrase(SafeSlingerPrefs.getKeyIdString());
            SafeSlinger.startCacheService(HomeActivity.this);
            showPassPhrase(false, true);
            break;
        case SettingsActivity.RESULT_LOGOUT:
            doManualLogout();
            break;
        case SettingsActivity.RESULT_DELETE_KEYS:
            // allow deletion of newer keys only
            showManagePassphrases(getMoreRecentKeys());
            break;
        case SettingsActivity.RESULT_CHANGE_PASSTTL:
            // update timer since ttl has changed
            updatePassCacheTimer();
            break;
        case Activity.RESULT_CANCELED:
            // nothing to change...
            break;
        }
        break;

    case VIEW_FILESAVE_ID:
        switch (resultCode) {
        case RESULT_OK:
            try {
                String chosenFile = data.getStringExtra(extra.FNAME);
                String chosenPath = data.getStringExtra(extra.FPATH);
                MessageData recvMsg = new MessageData();
                recvMsg.setFileName(chosenFile);
                doSaveDownloadedFile(new File(chosenPath, chosenFile), recvMsg);
            } catch (OutOfMemoryError e) {
                showNote(R.string.error_OutOfMemoryError);
                refreshView();
                break;
            }
            break;
        case RESULT_CANCELED:
            refreshView();
            break;
        }
        break;

    case VIEW_EXCHANGE_ID:
        switch (resultCode) {
        case ExchangeActivity.RESULT_EXCHANGE_OK:
            showSave(data.getExtras());
            break;
        case ExchangeActivity.RESULT_EXCHANGE_CANCELED:
            refreshView();
            break;
        }
        break;

    case VIEW_SAVE_ID:
        switch (resultCode) {
        case SaveActivity.RESULT_SAVE:
            SafeSlingerPrefs.setFirstExchangeComplete(true);
            // locally store trusted exchanged items
            Bundle args = data.getExtras();
            args.putInt(extra.RECIP_SOURCE, RecipientDbAdapter.RECIP_SOURCE_EXCHANGE);
            ImportFromExchangeTask importFromExchange = new ImportFromExchangeTask();
            importFromExchange.execute(args);
            break;
        case SaveActivity.RESULT_SELNONE:
            SafeSlingerPrefs.setFirstExchangeComplete(true);
            int exchanged = data.getExtras().getInt(extra.EXCHANGED_TOTAL);
            showNote(String.format(getString(R.string.state_SomeContactsImported), "0/" + exchanged));
            break;
        case RESULT_CANCELED:
            showNote(String.format(getString(R.string.state_SomeContactsImported), "0"));
            break;
        default:
            showNote(String.format(getString(R.string.state_SomeContactsImported), "?"));
            break;
        }
        break;

    case RESULT_PICK_CONTACT_SENDER:
        // parse newly selected sender contact
        switch (resultCode) {
        case RESULT_OK:
            Uri contactData = data.getData();
            Cursor c = getContentResolver().query(contactData, null, null, null, null);
            if (c != null) {
                try {
                    if (c.moveToFirst()) {
                        String contactLookupKey = c
                                .getString(c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
                        String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

                        // save these for lookup and display
                        // purposes
                        SafeSlingerPrefs.setContactLookupKey(contactLookupKey);
                        SafeSlingerPrefs.setContactName(name);
                    }
                } finally {
                    c.close();
                }
            }
            refreshView();
            break;
        case RESULT_CANCELED:
            refreshView();
            break;
        default:
            break;
        }
        break;

    case VIEW_FILEATTACH_ID:
        // file should be assigned for real now
        switch (resultCode) {
        case RESULT_OK:
            try {
                String path = null;
                if (data == null) {
                    // capture camera data from 1st non-standard
                    // return from hardware
                    path = SafeSlinger.getTempCameraFileUri().getPath();
                    doLoadAttachment(path);
                } else {
                    String chosenFile = data.getStringExtra(extra.FNAME);
                    String chosenPath = data.getStringExtra(extra.FPATH);

                    if (chosenFile != null || chosenPath != null) {
                        // from our own File Manager
                        path = chosenPath + File.separator + chosenFile;
                        doLoadAttachment(path);
                    } else if (data.getData() != null) {
                        // String action = data.getAction();
                        // act=null
                        // act=android.intent.action.GET_CONTENT
                        long filesize = getOutStreamSizeAndData(data.getData(), null);
                        if (filesize <= 0) {
                            showNote(R.string.error_CannotSendEmptyFile);
                            refreshView();
                            break;
                        }
                    } else {
                        // capture camera data from 2nd non-standard
                        // return from hardware
                        path = SafeSlinger.getTempCameraFileUri().getPath();
                        doLoadAttachment(path);
                    }
                }
            } catch (OutOfMemoryError e) {
                showNote(R.string.error_OutOfMemoryError);
                refreshView();
                break;
            } catch (FileNotFoundException e) {
                showNote(e);
                refreshView();
                break;
            } catch (IOException e) {
                showNote(e);
                refreshView();
                break;
            }

            setTab(Tabs.COMPOSE);
            refreshView();
            break;
        case RESULT_CANCELED:
            d.removeFile();
            setTab(Tabs.COMPOSE);
            refreshView();
            break;
        default:
            break;
        }
        break;

    case RESULT_PICK_MSGAPP:
        setTab(Tabs.COMPOSE);
        refreshView();
        break;

    case RESULT_ERROR:
        showExit(RESULT_CANCELED);
        break;

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

From source file:com.cognizant.trumobi.PersonaLauncher.java

@SuppressWarnings("unused")
void addAppWidget(final Intent data) {
    // TODO: catch bad widget exception when sent
    int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);

    String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET);
    /*/*from  w w w  . j  a  va2s . co  m*/
     * if (SEARCH_WIDGET.equals(customWidget)) { // We don't need this any
     * more, since this isn't a real app widget.
     * mAppWidgetHost.deleteAppWidgetId(appWidgetId); // add the search
     * widget addSearch(); } else {
     */
    AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);

    try {
        Bundle metadata = getPackageManager().getReceiverInfo(appWidget.provider,
                PackageManager.GET_META_DATA).metaData;
        if (metadata != null) {
            if (metadata.containsKey(PersonaLauncherMetadata.Requirements.APIVersion)) {
                int requiredApiVersion = metadata.getInt(PersonaLauncherMetadata.Requirements.APIVersion);
                if (requiredApiVersion > PersonaLauncherMetadata.CurrentAPIVersion) {
                    onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_CANCELED, data);
                    // Show a nice toast here to tell the user why the
                    // widget is rejected.
                    new AlertDialog.Builder(this).setTitle(R.string.adw_version).setCancelable(true)
                            .setIcon(R.drawable.pr_app_icon)
                            .setPositiveButton(getString(android.R.string.ok), null)
                            .setMessage(getString(R.string.scrollable_api_required)).create().show();
                    return;
                }
            }
        }
    } catch (PackageManager.NameNotFoundException expt) {
        // No Metadata available... then it is all OK...
    }
    configureOrAddAppWidget(data);
}

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

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

    mDontSaveOnStop = false;//from ww w  . j  a va2s  . co m
    if (resultCode == RESULT_MEDIA_EJECTED) {
        showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
        return;
    } else if (resultCode == RESULT_DB_ERROR) {
        handleDbError();
        return;
    }
    if (requestCode == SHOW_STUDYOPTIONS && resultCode == RESULT_OK) {
        loadCounts();
    } else if (requestCode == ADD_NOTE && resultCode != RESULT_CANCELED) {
        loadCounts();
    } else if (requestCode == BROWSE_CARDS
            && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
        loadCounts();
    } else if (requestCode == ADD_CRAM_DECK) {
        // TODO: check, if ok has been clicked
        loadCounts();
    } else if (requestCode == REPORT_ERROR) {
        showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 4);
    } else if (requestCode == SHOW_INFO_UPGRADE_DECKS) {
        if (intent != null && intent.hasExtra(Info.TYPE_UPGRADE_STAGE)) {
            int type = intent.getIntExtra(Info.TYPE_UPGRADE_STAGE, Info.UPGRADE_SCREEN_BASIC1);
            if (type == Info.UPGRADE_CONTINUE) {
                showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 3);
            } else {
                showUpgradeScreen(true, type, !intent.hasExtra(Info.TYPE_ANIMATION_RIGHT));
            }
        } else {
            if (resultCode == RESULT_OK) {
                if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) {
                    mOpenCollectionDialog.dismiss();
                }
                if (AnkiDroidApp.colIsOpen()) {
                    AnkiDroidApp.closeCollection(true);
                }
                AnkiDroidApp.openCollection(AnkiDroidApp.getCollectionPath());
                loadCounts();
            } else {
                finishWithAnimation();
            }
        }
    } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) {
        if (resultCode == RESULT_OK) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()),
                    requestCode == SHOW_INFO_WELCOME ? 1 : 2);
        } else {
            finishWithAnimation();
        }
    } else if (requestCode == PREFERENCES_UPDATE) {
        String oldPath = mPrefDeckPath;
        SharedPreferences pref = restorePreferences();
        String newLanguage = pref.getString("language", "");
        if (!AnkiDroidApp.getLanguage().equals(newLanguage)) {
            AnkiDroidApp.setLanguage(newLanguage);
            mInvalidateMenu = true;
        }
        if (mNotMountedDialog != null && mNotMountedDialog.isShowing()
                && pref.getBoolean("internalMemory", false)) {
            showStartupScreensAndDialogs(pref, 0);
        } else if (!mPrefDeckPath.equals(oldPath)) {
            loadCollection();
        }
        // if (resultCode == StudyOptions.RESULT_RESTART) {
        // setResult(StudyOptions.RESULT_RESTART);
        // finishWithAnimation();
        // } else {
        // SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext());
        // BackupManager.initBackup();
        // if (!mPrefDeckPath.equals(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())) ||
        // mPrefDeckOrder != Integer.parseInt(preferences.getString("deckOrder", "0"))) {
        // // populateDeckList(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory()));
        // }
        // }
    } else if (requestCode == REPORT_FEEDBACK && resultCode == RESULT_OK) {
    } else if (requestCode == LOG_IN_FOR_SYNC && resultCode == RESULT_OK) {
        sync();
    } else if (requestCode == LOG_IN_FOR_SHARED_DECK && resultCode == RESULT_OK) {
        addSharedDeck();
    } else if (requestCode == ADD_SHARED_DECKS) {
        if (intent != null) {
            mImportPath = intent.getStringExtra("importPath");
        }
        if (AnkiDroidApp.colIsOpen() && mImportPath != null) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                    new TaskData(AnkiDroidApp.getCol(), mImportPath, true));
            mImportPath = null;
        }
    } else if (requestCode == REQUEST_REVIEW) {
        Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
        switch (resultCode) {
        default:
            // do not reload counts, if activity is created anew because it has been before destroyed by android
            loadCounts();
            break;
        case Reviewer.RESULT_NO_MORE_CARDS:
            mDontSaveOnStop = true;
            Intent i = new Intent();
            i.setClass(this, StudyOptionsActivity.class);
            i.putExtra("onlyFnsMsg", true);
            startActivityForResult(i, SHOW_STUDYOPTIONS);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
            }
            break;
        }

    }

    // workaround for hidden dialog on return
    BroadcastMessages.showDialog();
}

From source file:com.nit.vicky.DeckPicker.java

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

    mDontSaveOnStop = false;/* w  w  w.ja  v a 2 s .c  om*/
    if (resultCode == RESULT_MEDIA_EJECTED) {
        showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
        return;
    } else if (resultCode == RESULT_DB_ERROR) {
        handleDbError();
        return;
    }
    if (requestCode == SHOW_STUDYOPTIONS && resultCode == RESULT_OK) {
        loadCounts();
    } else if (requestCode == ADD_NOTE && resultCode != RESULT_CANCELED) {
        loadCounts();
        addNote();
    } else if (requestCode == BROWSE_CARDS
            && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
        loadCounts();
    } else if (requestCode == ADD_CRAM_DECK) {
        // TODO: check, if ok has been clicked
        loadCounts();
    } else if (requestCode == REPORT_ERROR) {
        showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 4);
    } else if (requestCode == SHOW_INFO_UPGRADE_DECKS) {
        if (intent != null && intent.hasExtra(Info.TYPE_UPGRADE_STAGE)) {
            int type = intent.getIntExtra(Info.TYPE_UPGRADE_STAGE, Info.UPGRADE_SCREEN_BASIC1);
            if (type == Info.UPGRADE_CONTINUE) {
                showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 3);
            } else {
                showUpgradeScreen(true, type, !intent.hasExtra(Info.TYPE_ANIMATION_RIGHT));
            }
        } else {
            if (resultCode == RESULT_OK) {
                if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) {
                    mOpenCollectionDialog.dismiss();
                }
                if (AnkiDroidApp.colIsOpen()) {
                    AnkiDroidApp.closeCollection(true);
                }
                AnkiDroidApp.openCollection(AnkiDroidApp.getCollectionPath());
                loadCounts();
            } else {
                finishWithAnimation();
            }
        }
    } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) {
        if (resultCode == RESULT_OK) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()),
                    requestCode == SHOW_INFO_WELCOME ? 1 : 2);
        } else {
            finishWithAnimation();
        }
    } else if (requestCode == PREFERENCES_UPDATE) {
        String oldPath = mPrefDeckPath;
        SharedPreferences pref = restorePreferences();
        String newLanguage = pref.getString("language", "");
        if (AnkiDroidApp.setLanguage(newLanguage)) {
            mInvalidateMenu = true;
        }
        if (mNotMountedDialog != null && mNotMountedDialog.isShowing()
                && pref.getBoolean("internalMemory", false)) {
            showStartupScreensAndDialogs(pref, 0);
        } else if (!mPrefDeckPath.equals(oldPath)) {
            loadCollection();
        }
        // if (resultCode == StudyOptions.RESULT_RESTART) {
        // setResult(StudyOptions.RESULT_RESTART);
        // finishWithAnimation();
        // } else {
        // SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext());
        // BackupManager.initBackup();
        // if (!mPrefDeckPath.equals(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())) ||
        // mPrefDeckOrder != Integer.parseInt(preferences.getString("deckOrder", "0"))) {
        // // populateDeckList(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory()));
        // }
        // }
    } else if (requestCode == REPORT_FEEDBACK && resultCode == RESULT_OK) {
    } else if (requestCode == LOG_IN_FOR_SYNC && resultCode == RESULT_OK) {
        sync();
    } else if (requestCode == LOG_IN_FOR_SHARED_DECK && resultCode == RESULT_OK) {
        addSharedDeck();
    } else if (requestCode == ADD_SHARED_DECKS) {
        if (intent != null) {
            mImportPath = intent.getStringExtra("importPath");
        }
        if (AnkiDroidApp.colIsOpen() && mImportPath != null) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                    new TaskData(AnkiDroidApp.getCol(), mImportPath, true));
            mImportPath = null;
        }
    } else if (requestCode == REQUEST_REVIEW) {
        // Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
        switch (resultCode) {
        default:
            // do not reload counts, if activity is created anew because it has been before destroyed by android
            loadCounts();
            break;
        case Reviewer.RESULT_NO_MORE_CARDS:
            mDontSaveOnStop = true;
            Intent i = new Intent();
            i.setClass(this, StudyOptionsActivity.class);
            i.putExtra("onlyFnsMsg", true);
            startActivityForResult(i, SHOW_STUDYOPTIONS);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
            }
            break;
        }

    }

    // workaround for hidden dialog on return
    BroadcastMessages.showDialog();
}

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

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

    mDontSaveOnStop = false;// w  w  w  .j  a va 2  s  .  co  m
    if (resultCode == RESULT_MEDIA_EJECTED) {
        showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
        return;
    } else if (resultCode == RESULT_DB_ERROR) {
        handleDbError();
        return;
    }
    if (requestCode == SHOW_STUDYOPTIONS && resultCode == RESULT_OK) {
        loadCounts();
    } else if (requestCode == ADD_NOTE && resultCode != RESULT_CANCELED) {
        loadCounts();
    } else if (requestCode == BROWSE_CARDS
            && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
        loadCounts();
    } else if (requestCode == ADD_CRAM_DECK) {
        // TODO: check, if ok has been clicked
        loadCounts();
    } else if (requestCode == REPORT_ERROR) {
        showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 4);
    } else if (requestCode == SHOW_INFO_UPGRADE_DECKS) {
        if (intent != null && intent.hasExtra(Info.TYPE_UPGRADE_STAGE)) {
            int type = intent.getIntExtra(Info.TYPE_UPGRADE_STAGE, Info.UPGRADE_SCREEN_BASIC1);
            if (type == Info.UPGRADE_CONTINUE) {
                showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 3);
            } else {
                showUpgradeScreen(true, type, !intent.hasExtra(Info.TYPE_ANIMATION_RIGHT));
            }
        } else {
            if (resultCode == RESULT_OK) {
                if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) {
                    mOpenCollectionDialog.dismiss();
                }
                if (AnkiDroidApp.colIsOpen()) {
                    AnkiDroidApp.closeCollection(true);
                }
                AnkiDroidApp.openCollection(AnkiDroidApp.getCollectionPath());
                loadCounts();
            } else {
                finishWithAnimation();
            }
        }
    } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) {
        if (resultCode == RESULT_OK) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()),
                    requestCode == SHOW_INFO_WELCOME ? 1 : 2);
        } else {
            finishWithAnimation();
        }
    } else if (requestCode == PREFERENCES_UPDATE) {
        String oldPath = mPrefDeckPath;
        SharedPreferences pref = restorePreferences();
        String newLanguage = pref.getString("language", "");
        if (AnkiDroidApp.setLanguage(newLanguage)) {
            mInvalidateMenu = true;
        }
        if (mNotMountedDialog != null && mNotMountedDialog.isShowing()
                && pref.getBoolean("internalMemory", false)) {
            showStartupScreensAndDialogs(pref, 0);
        } else if (!mPrefDeckPath.equals(oldPath)) {
            loadCollection();
        }
        // if (resultCode == StudyOptions.RESULT_RESTART) {
        // setResult(StudyOptions.RESULT_RESTART);
        // finishWithAnimation();
        // } else {
        // SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext());
        // BackupManager.initBackup();
        // if (!mPrefDeckPath.equals(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())) ||
        // mPrefDeckOrder != Integer.parseInt(preferences.getString("deckOrder", "0"))) {
        // // populateDeckList(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory()));
        // }
        // }
    } else if (requestCode == REPORT_FEEDBACK && resultCode == RESULT_OK) {
    } else if (requestCode == LOG_IN_FOR_SYNC && resultCode == RESULT_OK) {
        sync();
    } else if (requestCode == LOG_IN_FOR_SHARED_DECK && resultCode == RESULT_OK) {
        addSharedDeck();
    } else if (requestCode == ADD_SHARED_DECKS) {
        if (intent != null) {
            mImportPath = intent.getStringExtra("importPath");
        }
        if (AnkiDroidApp.colIsOpen() && mImportPath != null) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                    new TaskData(AnkiDroidApp.getCol(), mImportPath, true));
            mImportPath = null;
        }
    } else if (requestCode == REQUEST_REVIEW) {
        // Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
        switch (resultCode) {
        default:
            // do not reload counts, if activity is created anew because it has been before destroyed by android
            loadCounts();
            break;
        case Reviewer.RESULT_NO_MORE_CARDS:
            mDontSaveOnStop = true;
            Intent i = new Intent();
            i.setClass(this, StudyOptionsActivity.class);
            i.putExtra("onlyFnsMsg", true);
            startActivityForResult(i, SHOW_STUDYOPTIONS);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
            }
            break;
        }

    }

    // workaround for hidden dialog on return
    BroadcastMessages.showDialog();
}