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.squareup.plugin.square.Square.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.w(LOGTAG, "onActivityResult");
    if (this.requestCode == requestCode) {

        // Handle the rare situation where the Square Register app was uninstalled during the request.
        if (data == null) {
            return;
        }// w  ww  .  ja  v  a 2 s  . co  m

        if (this.requestCallback == null) {
            return;
        }

        try {
            JSONObject parameter = new JSONObject();
            if (resultCode == Activity.RESULT_OK) {
                ChargeRequest.Success success = registerClient.parseChargeSuccess(data);

                // Retrieve the transaction's client-generated and server-generated IDs.
                // Descriptions of these fields are available in the SDK's javadoc.
                parameter.putOpt("clientTransactionId", success.clientTransactionId);
                parameter.putOpt("serverTransactionId", success.serverTransactionId);

                // This matches the value you provided for requestMetadata in your
                // original request.
                parameter.putOpt("metadata", success.requestMetadata);

                // Persist and use the transaction IDs however you choose
                requestCallback.success(parameter);
            } else {
                ChargeRequest.Error error = registerClient.parseChargeError(data);

                // Get the type of error that occurred
                parameter.putOpt("errorCode", error.code.toString());

                // Get the debug string that describes the error
                parameter.putOpt("errorDescription", error.debugDescription);

                parameter.putOpt("metadata", error.requestMetadata);

                // Use the error code and description to debug the error.
                requestCallback.error(parameter);
            }
        } catch (JSONException e) {
            Log.w(LOGTAG, String.format("Caught JSON Exception: %s", e.getMessage()));
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateDisease.java

/**
 * Informs user whether disease creation was successful or not.
 *
 * @param disease returned disease info if any
 *//*from  ww w  .j  a  v  a  2s .co  m*/
@Override
protected void onPostExecute(Disease disease) {
    if (disease != null) {
        Intent resultIntent = new Intent();
        resultIntent.putExtra(Values.ADD_DISEASE_KEY, disease);
        Toast.makeText(activity, R.string.creation_ok, Toast.LENGTH_SHORT).show();
        activity.setResult(Activity.RESULT_OK, resultIntent);
        activity.finish();
    } else {
        Toast.makeText(activity, R.string.creation_failed, Toast.LENGTH_SHORT).show();
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreatePerson.java

/**
 * Informs user whether person creation was successful or not.
 *
 * @param person returned user info if any
 *///  w ww.ja va  2 s. c o m
@Override
protected void onPostExecute(Person person) {
    if (person != null) {
        Intent resultIntent = new Intent();
        resultIntent.putExtra(Values.ADD_PERSON_KEY, person);
        Toast.makeText(activity, R.string.creation_ok, Toast.LENGTH_SHORT).show();
        activity.setResult(Activity.RESULT_OK, resultIntent);
        activity.finish();
    } else {
        Toast.makeText(activity, R.string.creation_failed, Toast.LENGTH_SHORT).show();
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateArtifact.java

/**
 * Informs user whether artifact creation was successful or not.
 *
 * @param artifact returned artifact info if any
 *///from  w w  w . j a v a2 s.co  m
@Override
protected void onPostExecute(Artifact artifact) {
    if (artifact != null) {
        Intent resultIntent = new Intent();
        resultIntent.putExtra(Values.ADD_ARTIFACT_KEY, artifact);
        Toast.makeText(activity, R.string.creation_ok, Toast.LENGTH_SHORT).show();
        activity.setResult(Activity.RESULT_OK, resultIntent);
        activity.finish();
    } else {
        Toast.makeText(activity, R.string.creation_failed, Toast.LENGTH_SHORT).show();
    }
}

From source file:cc.mintcoin.wallet.ui.SendingAddressesFragment.java

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

        new StringInputParser(input) {
            @Override/*ww  w. j ava2 s .co m*/
            protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
                // workaround for "IllegalStateException: Can not perform this action after onSaveInstanceState"
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (paymentIntent.hasAddress())
                            EditAddressBookEntryFragment.edit(getFragmentManager(),
                                    paymentIntent.getAddress().toString());
                        else
                            dialog(activity, null, R.string.address_book_options_scan_title,
                                    R.string.address_book_options_scan_invalid);
                    }
                }, 500);
            }

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

            @Override
            protected void error(final int messageResId, final Object... messageArgs) {
                dialog(activity, null, R.string.address_book_options_scan_title, messageResId, messageArgs);
            }
        }.parse();
    }
}

From source file:com.cloudstudio.BarcodeScanner.java

/**
 * Called when the barcode scanner intent completes.
 *
 * @param requestCode The request code originally supplied to startActivityForResult(),
 *                       allowing you to identify who this result came from.
 * @param resultCode  The integer result code returned by the child activity through its setResult().
 * @param intent      An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 *///from   w w w  . ja  v a 2s .com
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, intent.getStringExtra("SCAN_RESULT"));
                obj.put(FORMAT, intent.getStringExtra("SCAN_RESULT_FORMAT"));
                obj.put(CANCELLED, false);
            } catch (JSONException e) {
                Log.d(LOG_TAG, "This should never happen");
            }
            //this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
            this.callbackContext.success(obj);
        } else if (resultCode == Activity.RESULT_CANCELED) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, "");
                obj.put(FORMAT, "");
                obj.put(CANCELLED, true);
            } catch (JSONException e) {
                Log.d(LOG_TAG, "This should never happen");
            }
            //this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
            this.callbackContext.success(obj);
        } else {
            //this.error(new PluginResult(PluginResult.Status.ERROR), this.callback);
            this.callbackContext.error("Unexpected error");
        }
    }
}

From source file:ca.rmen.android.networkmonitor.app.prefs.FilterColumnActivity.java

public void onOk(@SuppressWarnings("UnusedParameters") View v) {
    Log.v(TAG, "onOk");
    // Update the preference for values to filter, for this particular column.

    // Build a list of all the values the user selected.
    SparseBooleanArray checkedPositions = mListView.getCheckedItemPositions();
    final List<String> selectedValues = new ArrayList<>(mListView.getCount());
    for (int i = 0; i < mListView.getCount(); i++) {
        if (checkedPositions.get(i))
            selectedValues.add(((FilterListItem) mListView.getAdapter().getItem(i)).value);
    }//from   ww  w.j a  v  a2s  . c o  m
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            // Update the filter preference for this column.
            String columnName = getIntent().getExtras().getString(EXTRA_COLUMN_NAME);
            NetMonPreferences.getInstance(FilterColumnActivity.this).setColumnFilterValues(columnName,
                    selectedValues);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            setResult(Activity.RESULT_OK);
            finish();
        }
    }.execute();
}

From source file:com.corumgaz.mobilsayac.VoiceRecognizer.VoiceRecognizer.java

/**
 * Handle the results from the recognition activity.
 *//*from  w w  w.  j av  a 2 s . co  m*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        // Fill the list view with the strings the recognizer thought it could have heard
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

        returnSpeechResults(matches);
    } else {
        // Failure - Let the caller know
        this.callbackContext.error(Integer.toString(resultCode));
    }

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

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateElectrodeFix.java

/**
 * Informs user whether ElectrodeFix creation was successful or not.
 *
 * @param fix returned electrode fix info if any
 *///  w w w . java 2 s .  c  o m
@Override
protected void onPostExecute(ElectrodeFix fix) {
    if (fix != null) {
        Intent resultIntent = new Intent();
        resultIntent.putExtra(Values.ADD_ELECTRODE_FIX_KEY, fix);
        Toast.makeText(activity, R.string.creation_ok, Toast.LENGTH_SHORT).show();
        activity.setResult(Activity.RESULT_OK, resultIntent);
        activity.finish();
    } else {
        Toast.makeText(activity, R.string.creation_failed, Toast.LENGTH_SHORT).show();
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateExperiment.java

/**
 * Informs user whether experiment creation was successful or not.
 *
 * @param experiment returned experiment info if any
 *///from  w w  w  .  ja v a 2s .  c  o m
@Override
protected void onPostExecute(Experiment experiment) {
    if (experiment != null) {
        Intent resultIntent = new Intent();
        resultIntent.putExtra(Values.ADD_EXPERIMENT_KEY, experiment);
        Toast.makeText(activity, R.string.creation_experiment_ok, Toast.LENGTH_SHORT).show();
        activity.setResult(Activity.RESULT_OK, resultIntent);
        activity.finish();
    } else {
        Toast.makeText(activity, R.string.creation_failed, Toast.LENGTH_SHORT).show();
    }
}