Example usage for android.app Activity RESULT_OK

List of usage examples for android.app Activity RESULT_OK

Introduction

In this page you can find the example usage for android.app Activity RESULT_OK.

Prototype

int RESULT_OK

To view the source code for android.app Activity RESULT_OK.

Click Source Link

Document

Standard activity result: operation succeeded.

Usage

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 ww w .j  a v a 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.facebook.Session.java

private void handleAuthorizationResult(int resultCode, AuthorizationClient.Result result) {
    AccessToken newToken = null;//from w ww .j  av a2  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);
    }

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

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

From source file:it.feio.android.omninotes.DetailFragment.java

@SuppressLint("NewApi")
@Override/*from  w ww .j av  a 2 s  .c o m*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    // Fetch uri from activities, store into adapter and refresh adapter
    Attachment attachment;
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case TAKE_PHOTO:
            attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_IMAGE);
            addAttachment(attachment);
            mAttachmentAdapter.notifyDataSetChanged();
            mGridView.autoresize();
            break;
        case TAKE_VIDEO:
            // Gingerbread doesn't allow custom folder so data are retrieved from intent
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
                attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_VIDEO);
            } else {
                attachment = new Attachment(intent.getData(), Constants.MIME_TYPE_VIDEO);
            }
            addAttachment(attachment);
            mAttachmentAdapter.notifyDataSetChanged();
            mGridView.autoresize();
            break;
        case FILES:
            onActivityResultManageReceivedFiles(intent);
            break;
        case SET_PASSWORD:
            noteTmp.setPasswordChecked(true);
            lockUnlock();
            break;
        case SKETCH:
            attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_SKETCH);
            addAttachment(attachment);
            mAttachmentAdapter.notifyDataSetChanged();
            mGridView.autoresize();
            break;
        case CATEGORY:
            mainActivity.showMessage(R.string.category_saved, ONStyle.CONFIRM);
            Category category = intent.getParcelableExtra("category");
            noteTmp.setCategory(category);
            setTagMarkerColor(category);
            break;
        case DETAIL:
            mainActivity.showMessage(R.string.note_updated, ONStyle.CONFIRM);
            break;
        }
    }
}

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 . java2  s  .c om*/

    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.dycody.android.idealnote.DetailFragment.java

@SuppressLint("NewApi")
@Override/*  ww w  .  j a  va 2  s .  com*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    // Fetch uri from activities, store into adapter and refresh adapter
    Attachment attachment;
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case TAKE_PHOTO:
            attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_IMAGE);
            addAttachment(attachment);
            mAttachmentAdapter.notifyDataSetChanged();
            mGridView.autoresize();
            break;
        case TAKE_VIDEO:
            // Gingerbread doesn't allow custom folder so data are retrieved from intent
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
                attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_VIDEO);
            } else {
                attachment = new Attachment(intent.getData(), Constants.MIME_TYPE_VIDEO);
            }
            addAttachment(attachment);
            mAttachmentAdapter.notifyDataSetChanged();
            mGridView.autoresize();
            break;
        case FILES:
            onActivityResultManageReceivedFiles(intent);
            break;
        case SET_PASSWORD:
            noteTmp.setPasswordChecked(true);
            lockUnlock();
            break;
        case SKETCH:
            attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_SKETCH);
            addAttachment(attachment);
            mAttachmentAdapter.notifyDataSetChanged();
            mGridView.autoresize();
            break;
        case CATEGORY:
            Toast.makeText(getActivity(), R.string.category_saved, Toast.LENGTH_SHORT).show();
            //mainActivity.showMessage(R.string.category_saved, ONStyle.CONFIRM);
            Category category = intent.getParcelableExtra("category");
            noteTmp.setCategory(category);
            setTagMarkerColor(category);
            break;
        case DETAIL:
            Toast.makeText(getActivity(), R.string.note_updated, Toast.LENGTH_SHORT).show();
            //mainActivity.showMessage(R.string.note_updated, ONStyle.CONFIRM);
            break;
        default:
            Log.e(Constants.TAG, "Wrong element choosen: " + requestCode);
        }
    }
}

From source file:com.chaqianma.jd.fragment.PersonalAssetsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case REQUEST_SDK_IMGS:
            if (data != null && data.getData() != null) {
                Uri imgUri = data.getData();
                ContentResolver resolver = getActivity().getContentResolver();
                String[] pojo = { MediaStore.Images.Media.DATA };
                Cursor cursor = null;
                try {
                    cursor = resolver.query(imgUri, pojo, null, null, null);
                    if (cursor != null && cursor.getCount() > 0) {
                        int colunm_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                        cursor.moveToFirst();
                        new Thread(new BaseFragment.ImgRunable(cursor.getString(colunm_index), fileType,
                                selIdxTag, new UpdateUIHandler())).start();
                        //mHandler.post(new ImgRunable(cursor.getString(colunm_index)));
                    } else {
                        JDToast.showLongText(getActivity(), "");
                    }/*from  w w  w.  j av  a  2s .  c o  m*/
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                    if (cursor != null) {
                        cursor.close();
                    }
                }
            }
            break;
        case REQUEST_TAKE_PHOTO:
            // mHandler.post(mRunnable);
            new Thread(
                    new BaseFragment.ImgRunable(Constants.TEMPPATH, fileType, selIdxTag, new UpdateUIHandler()))
                            .start();
            break;
        default:
            break;
        }
    }
}

From source file:com.facebook.Session.java

private void tryLegacyAuth(final AuthorizationRequest request) {
    authorizationClient = new AuthorizationClient();
    authorizationClient.setOnCompletedListener(new AuthorizationClient.OnCompletedListener() {
        @Override/*  w  w  w. jav  a  2s  .c  o  m*/
        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:com.updetector.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    // Choose what to do based on the request code
    Log.e(LOG_TAG, requestCode + "  " + requestCode);
    switch (requestCode) {
    case Constants.SENSOR_GPS:
        checkBluetoothEnabled();//from  w ww.j  av a2  s. c  o  m
        break;
    case Constants.SENSOR_BLUETOOTH:
        if (mBluetoothAdapter.isEnabled()) {//only if the user enables the bluetooth
            checkBluetoothEnabled();
        }
        break;
    // If the request code matches the code sent in onConnectionFailed
    case Constants.CONNECTION_FAILURE_RESOLUTION_REQUEST:
        switch (resultCode) {
        // If Google Play services resolved the problem
        case Activity.RESULT_OK:
            // If the request was to start activity recognition updates
            if (Constants.REQUEST_TYPE.ADD == mRequestType) {
                // Restart the process of requesting activity recognition
                // updates
                mGoogleActivityDetectionRequester.requestUpdates();
                // If the request was to remove activity recognition updates
            } else if (Constants.REQUEST_TYPE.REMOVE == mRequestType) {
                /*
                 * Restart the removal of all activity recognition updates
                 * for the PendingIntent.
                 */
                mGoogleActivityDetectionRemover
                        .removeUpdates(mGoogleActivityDetectionRequester.getRequestPendingIntent());

            }
            break;

        // If any other result was returned by Google Play services
        default:
            // Report that Google Play services was unable to resolve the
            // problem.
            Log.d(Constants.APP_NAME, getString(R.string.no_resolution));
        }
        // If any other request code was received
    default:
        // Report that this Activity received an unknown requestCode
        Log.d(Constants.APP_NAME, getString(R.string.unknown_activity_request_code, requestCode));
        break;
    }
}

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   ww w.  j av  a 2  s .c  om*/
        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;
    }
}