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:cc.mintcoin.wallet.ui.SendCoinsFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (requestCode == REQUEST_CODE_SCAN) {
        if (resultCode == Activity.RESULT_OK) {
            final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);

            new StringInputParser(input) {
                @Override//from   w w  w  .j  a v a  2  s.c om
                protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
                    updateStateFrom(paymentIntent);
                }

                @Override
                protected void handleDirectTransaction(final Transaction transaction) {
                    cannotClassify(input);
                }

                @Override
                protected void error(final int messageResId, final Object... messageArgs) {
                    dialog(activity, null, R.string.button_scan, messageResId, messageArgs);
                }
            }.parse();
        }
    } else if (requestCode == REQUEST_CODE_ENABLE_BLUETOOTH) {
        if (paymentIntent.isBluetoothPaymentUrl())
            directPaymentEnableView.setChecked(resultCode == Activity.RESULT_OK);
    }
}

From source file:com.mohamnag.inappbilling.InAppBillingPlugin.java

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

    if (pendingPurchaseCallbacks.containsKey(requestCode)) {
        jsLog("Got response of a purchase");

        // going to handle response of a purchase
        CallbackContext callbackContext = pendingPurchaseCallbacks.get(requestCode);
        int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
        String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
        String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");

        if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) {
            if (purchaseData == null || dataSignature == null) {
                callbackContext/*from   w w w  .  j a  v  a2s  .  com*/
                        .error(new Error(ERR_PURCHASE_FAILED, "Empty purchase data or empty signature returned")
                                .toJavaScriptJSON());
            } else {

                try {
                    Purchase purchase = new Purchase(purchaseData, dataSignature);

                    if (base64EncodedPublicKey != null
                            && !Security.verifyPurchase(base64EncodedPublicKey, purchaseData, dataSignature)) {

                        callbackContext.error(new Error(ERR_PAYMENT_INVALID, "Signature verification failed")
                                .toJavaScriptJSON());
                    } else {
                        jsLog("Purchase successful.");

                        // add the purchase to the inventory
                        myInventory.addPurchase(purchase);

                        callbackContext.success(purchase.toJavaScriptJson());
                    }
                } catch (JSONException e) {
                    callbackContext
                            .error(new Error(ERR_JSON_CONVERSION_FAILED, e.getMessage()).toJavaScriptJSON());
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            callbackContext
                    .error(new Error(ERR_PAYMENT_CANCELLED, "Purchase cancelled by user.").toJavaScriptJSON());
        } else {
            // unknown result, interpret as error
            callbackContext
                    .error(new Error(ERR_PURCHASE_FAILED, "Unknown result code from activity. ResultCode: "
                            + resultCode + " ResponseCode: " + responseCode).toJavaScriptJSON());
        }
    }
}

From source file:com.felkertech.n.ActivityUtils.java

public static void onActivityResult(final Activity mActivity, GoogleApiClient gapi, final int requestCode,
        final int resultCode, final Intent data) {
    SettingsManager sm = new SettingsManager(mActivity);
    if (gapi == null)
        gapi = GoogleDrive.gapi;/*w  w  w . j  a v a 2 s. c  om*/
    switch (requestCode) {
    case RESOLVE_CONNECTION_REQUEST_CODE:
        if (resultCode == Activity.RESULT_OK) {
            if (DEBUG) {
                Log.d(TAG, "App connect +1");
            }
            gapi.connect();
        } else {
            if (DEBUG) {
                Log.d(TAG, "App cannot connect");
            }
            final GoogleApiClient finalGapi = gapi;
            new MaterialDialog.Builder(mActivity).title(R.string.connection_issue_title)
                    .content(R.string.connection_issue_description).positiveText(R.string.ok)
                    .negativeText(R.string.try_again).callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);
                            finalGapi.connect();
                        }
                    }).show();
        }
        break;
    case REQUEST_CODE_CREATOR:
        if (data == null || !gapi.isConnected()) {
            // If op was canceled
            return;
        }
        DriveId driveId = data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
        if (DEBUG) {
            Log.d(TAG, driveId.encodeToString() + ", " + driveId.getResourceId() + ", "
                    + driveId.toInvariantString());
        }
        sm.setString(R.string.sm_google_drive_id, driveId.encodeToString());

        DriveFile file = Drive.DriveApi.getFile(gapi, DriveId.decodeFromString(driveId.encodeToString()));
        //Write initial data
        ActivityUtils.writeDriveData(mActivity, gapi);
        break;
    case ActivityUtils.REQUEST_CODE_OPENER:
        if (data == null) //If op was canceled
            return;
        driveId = data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
        if (DEBUG) {
            Log.d(TAG, driveId.encodeToString() + ", " + driveId.getResourceId() + ", "
                    + driveId.toInvariantString());
        }
        sm.setString(R.string.sm_google_drive_id, driveId.encodeToString());
        final GoogleApiClient finalGapi1 = gapi;
        new MaterialDialog.Builder(mActivity).title(R.string.sync_initial)
                .positiveText(R.string.sync_cloud_local).negativeText(R.string.sync_local_cloud)
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        super.onPositive(dialog);
                        ActivityUtils.readDriveData(mActivity, finalGapi1);
                    }

                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        super.onNegative(dialog);
                        ActivityUtils.writeDriveData(mActivity, finalGapi1);
                    }
                }).show();
    }
}

From source file:com.odoo.addons.sale.SalesDetail.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_ADD_ITEMS && resultCode == Activity.RESULT_OK) {
        lineValues.clear();//from w  w w.ja va  2s .  co m
        for (String key : data.getExtras().keySet()) {
            if (data.getExtras().getFloat(key) > 0)
                lineValues.put(key, data.getExtras().getFloat(key));
        }
        OnProductChange onProductChange = new OnProductChange();
        onProductChange.execute(lineValues);
    }
}

From source file:com.markupartist.sthlmtraveling.PlannerFragment.java

/**
 * Setup a search short cut./*from w w w  . ja  va 2 s  .  c o m*/
 * 
 * @param startPoint
 *            the start point
 * @param endPoint
 *            the end point
 */
protected void onCreateShortCut(Site startPoint, Site endPoint, String name) {
    Uri routesUri = RoutesActivity.createRoutesUri(startPoint, endPoint, null, true);
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, routesUri, getActivity(), RoutesActivity.class);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // Then, set up the container intent (the response to the caller)
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.shortcut);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Now, return the result to the launcher
    getActivity().setResult(Activity.RESULT_OK, intent);
    getActivity().finish();
}

From source file:com.smartmobilesoftware.util.IabHelper.java

/**
 * Handles an activity result that's part of the purchase flow in in-app billing. If you
 * are calling {@link #launchPurchaseFlow}, then you must call this method from your
 * Activity's {@link android.app.Activity@onActivityResult} method. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param requestCode The requestCode as you received it.
 * @param resultCode The resultCode as you received it.
 * @param data The data (Intent) as you received it.
 * @return Returns true if the result was related to a purchase flow and was handled;
 *     false if the result was not related to a purchase, in which case you should
 *     handle it normally./*  www .  ja va 2s . c o m*/
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != mRequestCode)
        return false;

    checkNotDisposed();
    checkSetupDone("handleActivityResult");

    // end of async purchase operation that started on launchPurchaseFlow
    flagEndAsync();

    if (data == null) {
        logError("Null data in IAB activity result.");
        result = new IabResult(ERR_BAD_RESPONSE, "Null data in IAB result");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
        return true;
    }

    int responseCode = getResponseCodeFromIntent(data);
    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

    if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) {
        logDebug("Successful resultcode from purchase activity.");
        logDebug("Purchase data: " + purchaseData);
        logDebug("Data signature: " + dataSignature);
        logDebug("Extras: " + data.getExtras());
        logDebug("Expected item type: " + mPurchasingItemType);

        if (purchaseData == null || dataSignature == null) {
            logError("BUG: either purchaseData or dataSignature is null.");
            logDebug("Extras: " + data.getExtras().toString());
            result = new IabResult(ERR_UNKNOWN, "IAB returned null purchaseData or dataSignature");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        Purchase purchase = null;
        try {
            purchase = new Purchase(mPurchasingItemType, purchaseData, dataSignature);
            String sku = purchase.getSku();

            // Verify signature
            if (!Security.verifyPurchase(mSignatureBase64, purchaseData, dataSignature)) {
                logError("Purchase signature verification FAILED for sku " + sku);
                result = new IabResult(ERR_VERIFICATION_FAILED, "Signature verification failed for sku " + sku);
                if (mPurchaseListener != null)
                    mPurchaseListener.onIabPurchaseFinished(result, purchase);
                return true;
            }
            logDebug("Purchase signature successfully verified.");
        } catch (JSONException e) {
            logError("Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(ERR_BAD_RESPONSE, "Failed to parse purchase data.");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        if (mPurchaseListener != null) {
            mPurchaseListener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Success"),
                    purchase);
        }
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode));
        if (mPurchaseListener != null) {
            result = new IabResult(responseCode, "Problem purchashing item.");
            mPurchaseListener.onIabPurchaseFinished(result, null);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(ERR_CANCELLED, "User canceled.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    } else {
        logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: "
                + getResponseDesc(responseCode));
        result = new IabResult(ERR_UNKNOWN, "Unknown purchase response.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    return true;
}

From source file:com.google.example.eightbitartist.DrawingActivity.java

@Override
public void onActivityResult(int request, int response, Intent data) {
    super.onActivityResult(request, response, data);
    Log.i(TAG, "onActivityResult: code = " + request + ", response = " + response);

    // Coming back from resolving a sign-in request
    if (request == RC_SIGN_IN) {
        mSignInClicked = false;//www  .  j  a  v a 2  s  . co  m
        mResolvingConnectionFailure = false;
        if (response == RESULT_OK) {
            mGoogleApiClient.connect();
        } else {
            BaseGameUtils.showActivityResultError(this, request, response, R.string.sign_in_failed);
        }
    }

    // Coming back from a RealTime Multiplayer waiting room
    if (request == RC_WAITING_ROOM) {
        dismissSpinner();

        Room room = data.getParcelableExtra(Multiplayer.EXTRA_ROOM);
        if (response == RESULT_OK) {
            Log.d(TAG, "Waiting Room: Success");
            mRoom = room;
            startMatch();
        } else if (response == RESULT_CANCELED) {
            Log.d(TAG, "Waiting Room: Canceled");
            leaveRoom();
        } else if (response == GamesActivityResultCodes.RESULT_LEFT_ROOM) {
            Log.d(TAG, "Waiting Room: Left Room");
            leaveRoom();
        } else if (response == GamesActivityResultCodes.RESULT_INVALID_ROOM) {
            Log.d(TAG, "Waiting Room: Invalid Room");
            leaveRoom();
        }
    }

    // We are coming back from the player selection UI, in preparation to start a match.
    if (request == RC_SELECT_PLAYERS) {
        if (response != Activity.RESULT_OK) {
            // user canceled
            Log.d(TAG, "onActivityResult: user canceled player selection.");
            return;
        }

        // Create a basic room configuration
        RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(this).setMessageReceivedListener(this)
                .setRoomStatusUpdateListener(this);

        // Set the auto match criteria
        int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
        int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
        if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) {
            Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers,
                    maxAutoMatchPlayers, 0);
            roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
        }

        // Set the invitees
        final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
        if (invitees != null && invitees.size() > 0) {
            roomConfigBuilder.addPlayersToInvite(invitees);
        }

        // Build the room and start the match
        showSpinner();
        Games.RealTimeMultiplayer.create(mGoogleApiClient, roomConfigBuilder.build());
    }
}

From source file:net.reichholf.dreamdroid.fragment.TimerEditFragment.java

@Override
public void onSimpleResult(boolean success, ExtendedHashMap result) {
    if (mProgress != null) {
        mProgress.dismiss();/*from   w ww.  j  av  a2s  .c o  m*/
        mProgress = null;
    }
    super.onSimpleResult(success, result);

    if (Python.TRUE.equals(result.getString(SimpleResult.KEY_STATE))) {
        finish(Activity.RESULT_OK);
    }
}

From source file:com.nit.vicky.multimediacard.activity.MultimediaCardEditorActivity.java

private void save() {
    mEditorNote.setmData(mNote.getField(0).getName());
    Themes.showThemedToast(MultimediaCardEditorActivity.this, mEditorNote.getmData() + " saved", false);
    NoteService.saveMedia((MultimediaEditableNote) mNote, getApplicationContext());
    NoteService.updateJsonNoteFromMultimediaNote(mNote, mEditorNote);

    TaskListener listener = new TaskListener() {

        @Override//from  w ww. ja v a 2 s . c  om
        public void onProgressUpdate(TaskData... values) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPreExecute() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPostExecute(TaskData result) {
            // TODO Auto-generated method stub

        }
    };

    if (mAddNote) {

        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ADD_FACT, listener, new DeckTask.TaskData(mEditorNote));
    } else {

        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, listener,
                new DeckTask.TaskData(mCol.getSched(), mCard, false));
    }

    setResult(Activity.RESULT_OK);
    finish();
    animateRight();
}

From source file:com.hichinaschool.flashcards.anki.multimediacard.activity.MultimediaCardEditorActivity.java

private void save() {
    NoteService.saveMedia((MultimediaEditableNote) mNote);
    NoteService.updateJsonNoteFromMultimediaNote(mNote, mEditorNote);

    TaskListener listener = new TaskListener() {

        @Override// w w  w .ja  v  a 2 s. co m
        public void onProgressUpdate(TaskData... values) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPreExecute() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPostExecute(TaskData result) {
            // TODO Auto-generated method stub

        }
    };

    if (mAddNote) {

        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ADD_FACT, listener, new DeckTask.TaskData(mEditorNote));
    } else {

        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, listener,
                new DeckTask.TaskData(mCol.getSched(), mCard, false));
    }

    setResult(Activity.RESULT_OK);
    finish();
    animateRight();
}