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.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragmentKoopman.java

/**
 * Catch the selected koopman of vervanger from dialogactivity result
 * @param requestCode//from w w w.  ja  v  a 2 s .  co m
 * @param resultCode
 * @param data
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    // check for the vervanger dialog request code
    if (requestCode == VERVANGER_DIALOG_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {

            // get the id of the selected koopman from the intent
            int koopmanId = data.getIntExtra(VERVANGER_RETURN_INTENT_EXTRA_KOOPMAN_ID, 0);
            if (koopmanId != 0) {

                // set the koopman that was selected in the dialog
                mKoopmanId = koopmanId;

                // reset the default amount of products before loading the koopman
                String[] productParams = getResources().getStringArray(R.array.array_product_param);
                for (String product : productParams) {
                    mProducten.put(product, -1);
                }

                // update aanwezig status to vervanger_met_toestemming
                mAanwezigSelectedValue = getString(R.string.item_vervanger_met_toestemming_aanwezig);
                setAanwezig(getString(R.string.item_vervanger_met_toestemming_aanwezig));

                // inform the dagvergunningfragment that the koopman has changed, get the new values,
                // and populate our layout with the new koopman
                ((Callback) getActivity()).onKoopmanFragmentUpdated();
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {

            // clear the selection by restarting the activity
            Intent intent = getActivity().getIntent();
            getActivity().finish();
            startActivity(intent);
        }
    }
}

From source file:com.launcher.silverfish.HomeScreenFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // listen for widget manager response
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_PICK_APPWIDGET) {
            configureWidget(data);/*  w w  w  .  j  a  va2 s  .co  m*/
        } else if (requestCode == REQUEST_CREATE_APPWIDGET) {
            createWidget(data);
        } else if (requestCode == REQUEST_BIND_APPWIDGET) {
            createWidget(data);
        }
    } else if (resultCode == Activity.RESULT_CANCELED && data != null) {
        int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
        if (appWidgetId != -1) {
            mAppWidgetHost.deleteAppWidgetId(appWidgetId);
        }
    }
}

From source file:org.apache.cordova.plugin.BluetoothPlugin.java

/**
 * Receives activity results//from ww  w.java2  s . c  om
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == this.REQUEST_CODE_ENABLE) {
        if (resultCode == Activity.RESULT_OK)
            this.callback_enable.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
        else if (resultCode == Activity.RESULT_CANCELED)
            this.callback_enable.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
    } else if (requestCode == this.REQUEST_CODE_DISCOVERABLE) {
        if (resultCode == Activity.RESULT_CANCELED)
            this.callback_discoverable.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
        else
            this.callback_discoverable.sendPluginResult(new PluginResult(PluginResult.Status.OK, resultCode));
    }
}

From source file:org.onepf.oms.appstore.skubitUtils.SkubitIabHelper.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.//from w w  w  . j av a2  s .c o  m
 */
public boolean handleActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    IabResult result;
    if (requestCode != mRequestCode)
        return false;

    checkSetupDone("handleActivityResult");

    // end of async purchase operation
    flagEndAsync();

    if (data == null) {
        Logger.e("In-app billing error: Null data in IAB activity result.");
        result = new IabResult(IABHELPER_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 == RESULT_OK) {
        processPurchaseSuccess(data, purchaseData, dataSignature);
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        processPurchaseFail(responseCode);
    } else if (resultCode == Activity.RESULT_CANCELED) {
        Logger.d("Purchase canceled - Response: ", getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    } else {
        Logger.e("In-app billing error: Purchase failed. Result code: " + Integer.toString(resultCode)
                + ". Response: " + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    return true;
}

From source file:com.hexypixel.hexyplugin.IabHelper.java

public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;/* ww w.ja  v  a2s  .  c  o  m*/
    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(IABHELPER_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(IABHELPER_UNKNOWN_ERROR, "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(IABHELPER_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(IABHELPER_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(IABHELPER_USER_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(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    return true;
}

From source file:csh.cryptonite.Cryptonite.java

/** Called upon exit from other activities */
public synchronized void onActivityResult(final int requestCode, int resultCode, final Intent data) {

    switch (requestCode) {
    case SelectionMode.MODE_OPEN_ENCFS:
    case SelectionMode.MODE_OPEN_ENCFS_DB:
    case SelectionMode.MODE_OPEN_DEFAULT:
    case SelectionMode.MODE_OPEN_DEFAULT_DB:
    case SelectionMode.MODE_OPEN_UPLOAD_SOURCE:
    case SelectionMode.MODE_OPEN_CREATE:
        /* file dialog */
        if (resultCode == Activity.RESULT_OK && data != null) {
            currentReturnPath = data.getStringExtra(FileDialog.RESULT_EXPORT_PATHS);
            if (currentReturnPath != null) {
                switch (opMode) {
                case MOUNT_MODE:
                    opMode = prevMode;//from  w w  w .ja va 2s .co  m
                    if (localFragment != null) {
                        localFragment.updateMountButtons();
                    }
                    break;
                case SELECTLOCALENCFS_MODE:
                case SELECTDBENCFS_MODE:
                    /* TODO: This is now handle in FileDialog.java
                    if (requestCode != SelectionMode.MODE_OPEN_DEFAULT_DB) {
                    StorageManager.INSTANCE.setEncFSPath(currentReturnPath
                            .substring(currentDialogStartPath.length()));
                    } else {
                    StorageManager.INSTANCE.setEncFSPath(currentReturnPath
                            .substring(currentDialogRoot.length()));
                    }*/
                    updateDecryptDelayed = true;
                    break;
                case LOCALEXPORT_MODE:
                case DBEXPORT_MODE:
                case SELECTDBUPLOAD_MODE:
                case SELECTLOCALUPLOAD_MODE:
                    break;
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
        } else if (resultCode == RESULT_RETRY) {
            launchBuiltinFileBrowser();
        }
        break;
    case SelectionMode.MODE_OPEN_MULTISELECT:
    case SelectionMode.MODE_OPEN_MULTISELECT_DB:
        if (resultCode == Activity.RESULT_OK && data != null) {
            currentReturnPathList = data.getStringArrayExtra(FileDialog.RESULT_EXPORT_PATHS);
            if (currentReturnPathList != null && currentReturnPathList.length > 0) {
                /* Select destination directory for exported files */
                currentDialogLabel = Cryptonite.this.getString(R.string.select_exp);
                currentDialogButtonLabel = Cryptonite.this.getString(R.string.select_exp_short);
                currentDialogMode = SelectionMode.MODE_OPEN_EXPORT_TARGET;
                if (externalStorageIsWritable()) {
                    currentDialogStartPath = getDownloadDir().getPath();
                    File downloadDir = new File(currentDialogStartPath);
                    if (!downloadDir.exists()) {
                        downloadDir.mkdir();
                    }
                    if (!downloadDir.exists()) {
                        currentDialogStartPath = "/";
                    }
                } else {
                    currentDialogStartPath = "/";
                }
                currentDialogRoot = "/";
                currentDialogRootName = currentDialogRoot;
                if (StorageManager.INSTANCE.getEncFSStorage() != null) {
                    opMode = StorageManager.INSTANCE.getEncFSStorage().exportMode;
                } else {
                    return;
                }
                currentConfigFile = "";
                launchBuiltinFileBrowser();
            } else {
                currentOpenPath = data.getStringExtra(FileDialog.RESULT_OPEN_PATH);
                if (currentOpenPath != null && currentOpenPath.length() > 0) {
                    /* */
                } else {
                    currentUploadTargetPath = data.getStringExtra(FileDialog.RESULT_UPLOAD_PATH);
                    if (currentUploadTargetPath != null && currentUploadTargetPath.length() > 0) {
                        /* select file to upload */
                        currentDialogLabel = Cryptonite.this.getString(R.string.select_upload);
                        currentDialogButtonLabel = Cryptonite.this.getString(R.string.select_upload_short);
                        currentDialogMode = SelectionMode.MODE_OPEN_UPLOAD_SOURCE;
                        if (externalStorageIsWritable()) {
                            currentDialogStartPath = DirectorySettings.getGlobalExternalStorageDirectory()
                                    .getPath();
                        } else {
                            currentDialogStartPath = "/";
                        }
                        currentDialogRoot = "/";
                        currentDialogRootName = currentDialogRoot;
                        if (StorageManager.INSTANCE.getEncFSStorage() != null) {
                            opMode = StorageManager.INSTANCE.getEncFSStorage().uploadMode;
                        } else {
                            return;
                        }
                        currentConfigFile = "";
                        launchBuiltinFileBrowser();
                    }
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {

        } else if (resultCode == RESULT_ERROR) {
            Toast.makeText(this, R.string.decode_failure, Toast.LENGTH_LONG).show();
            jniResetVolume();
            StorageManager.INSTANCE.resetEncFSStorage();
            VirtualFileSystem.INSTANCE.clear();
        }
        break;
    case REQUEST_PREFS:
        SharedPreferences prefs = getBaseContext().getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
        Editor prefEdit = prefs.edit();

        setupReadDirs(prefs.getBoolean("cb_extcache", false));

        DirectorySettings.INSTANCE.mntDir = prefs.getString("txt_mntpoint", defaultMntDir());

        /* If app folder settings have changed, we'll have to log out the user
         * from his Dropbox and restart the authentication from scratch during
         * the next login:
         */
        if (prefs.getBoolean("cb_appfolder", false) != mUseAppFolder) {
            prefEdit.putBoolean("dbDecided", true);
            prefEdit.commit();
            /* enforce re-authentication */
            DropboxInterface.INSTANCE.setDBApi(null);
            if (mLoggedIn) {
                Toast.makeText(Cryptonite.this, R.string.dropbox_forced_logout, Toast.LENGTH_LONG).show();
                logOut();
            }
        }
        break;
    case REQUEST_CODE_PICK_FILE_OR_DIRECTORY:
        /* from external OI file browser */
        if (resultCode == RESULT_OK && data != null) {
            // obtain the filename
            Uri fileUri = data.getData();
            if (fileUri != null) {
                currentReturnPath = fileUri.getPath();
            }
        }
        break;
    case CreateEncFS.CREATE_DB:
    case CreateEncFS.CREATE_LOCAL:
        break;
    case TextPreview.REQUEST_PREVIEW:
        break;
    default:
        Log.e(TAG, "Unknown request code");
    }
}

From source file:org.benetech.secureapp.activities.MainActivity.java

private void displayMessages(int resultCode) {
    int messageId = R.string.message_export_all_records_successful;
    if (resultCode == Activity.RESULT_CANCELED) {
        messageId = R.string.message_export_all_records_unsuccessful;
    }/*from ww  w .java 2  s .c  o m*/

    Toast.makeText(this, getString(messageId), Toast.LENGTH_LONG).show();
}

From source file:com.rimbit.android_wallet.ui.SendCoinsFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.send_coins_fragment, container);

    payeeNameView = (TextView) view.findViewById(R.id.send_coins_payee_name);
    payeeOrganizationView = (TextView) view.findViewById(R.id.send_coins_payee_organization);
    payeeVerifiedByView = (TextView) view.findViewById(R.id.send_coins_payee_verified_by);

    receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address);
    receivingAddressView.setAdapter(new AutoCompleteAddressAdapter(activity, null));
    receivingAddressView.setOnFocusChangeListener(receivingAddressListener);
    receivingAddressView.addTextChangedListener(receivingAddressListener);

    receivingStaticView = view.findViewById(R.id.send_coins_receiving_static);
    receivingStaticAddressView = (TextView) view.findViewById(R.id.send_coins_receiving_static_address);
    receivingStaticLabelView = (TextView) view.findViewById(R.id.send_coins_receiving_static_label);

    receivingStaticView.setOnFocusChangeListener(new OnFocusChangeListener() {
        private ActionMode actionMode;

        @Override//from w ww. j a v a2 s.  c  om
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus) {
                final Address address = paymentIntent.hasAddress() ? paymentIntent.getAddress()
                        : (validatedAddress != null ? validatedAddress.address : null);
                if (address != null)
                    actionMode = activity.startActionMode(new ReceivingAddressActionMode(address));
            } else {
                actionMode.finish();
            }
        }
    });

    final CurrencyAmountView RBTAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount_rbt);
    RBTAmountView.setCurrencySymbol(config.getRBTPrefix());
    RBTAmountView.setInputPrecision(config.getRBTMaxPrecision());
    RBTAmountView.setHintPrecision(config.getRBTPrecision());
    RBTAmountView.setShift(config.getRBTShift());

    final CurrencyAmountView localAmountView = (CurrencyAmountView) view
            .findViewById(R.id.send_coins_amount_local);
    localAmountView.setInputPrecision(Constants.LOCAL_PRECISION);
    localAmountView.setHintPrecision(Constants.LOCAL_PRECISION);
    amountCalculatorLink = new CurrencyCalculatorLink(RBTAmountView, localAmountView);
    amountCalculatorLink.setExchangeDirection(config.getLastExchangeDirection());

    directPaymentEnableView = (CheckBox) view.findViewById(R.id.send_coins_direct_payment_enable);
    directPaymentEnableView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (paymentIntent.isBluetoothPaymentUrl() && isChecked && !bluetoothAdapter.isEnabled()) {
                // ask for permission to enable bluetooth
                startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                        REQUEST_CODE_ENABLE_BLUETOOTH_FOR_DIRECT_PAYMENT);
            }
        }
    });

    directPaymentMessageView = (TextView) view.findViewById(R.id.send_coins_direct_payment_message);

    sentTransactionView = (ListView) view.findViewById(R.id.send_coins_sent_transaction);
    sentTransactionListAdapter = new TransactionsListAdapter(activity, wallet, application.maxConnectedPeers(),
            false);
    sentTransactionView.setAdapter(sentTransactionListAdapter);

    viewGo = (Button) view.findViewById(R.id.send_coins_go);
    viewGo.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            validateReceivingAddress(true);
            isAmountValid();

            if (everythingValid())
                handleGo();
            else
                requestFocusFirst();
        }
    });

    amountCalculatorLink.setNextFocusId(viewGo.getId());

    viewCancel = (Button) view.findViewById(R.id.send_coins_cancel);
    viewCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (state == State.INPUT)
                activity.setResult(Activity.RESULT_CANCELED);

            activity.finish();
        }
    });

    popupMessageView = (TextView) inflater.inflate(R.layout.send_coins_popup_message, container);

    return view;
}

From source file:de.langerhans.wallet.ui.SendCoinsFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.send_coins_fragment, container);

    payeeNameView = (TextView) view.findViewById(R.id.send_coins_payee_name);
    payeeVerifiedByView = (TextView) view.findViewById(R.id.send_coins_payee_verified_by);

    receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address);
    receivingAddressView.setAdapter(new AutoCompleteAddressAdapter(activity, null));
    receivingAddressView.setOnFocusChangeListener(receivingAddressListener);
    receivingAddressView.addTextChangedListener(receivingAddressListener);

    receivingStaticView = view.findViewById(R.id.send_coins_receiving_static);
    receivingStaticAddressView = (TextView) view.findViewById(R.id.send_coins_receiving_static_address);
    receivingStaticLabelView = (TextView) view.findViewById(R.id.send_coins_receiving_static_label);

    receivingStaticView.setOnFocusChangeListener(new OnFocusChangeListener() {
        private ActionMode actionMode;

        @Override/*from www  .  j a  v  a 2s  .c om*/
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus) {
                final Address address = paymentIntent.hasAddress() ? paymentIntent.getAddress()
                        : (validatedAddress != null ? validatedAddress.address : null);
                if (address != null)
                    actionMode = activity.startActionMode(new ReceivingAddressActionMode(address));
            } else {
                actionMode.finish();
            }
        }
    });

    final CurrencyAmountView btcAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount_btc);
    btcAmountView.setCurrencySymbol(config.getBtcPrefix());
    btcAmountView.setInputPrecision(config.getBtcMaxPrecision());
    btcAmountView.setHintPrecision(config.getBtcPrecision());
    btcAmountView.setShift(config.getBtcShift());

    final CurrencyAmountView localAmountView = (CurrencyAmountView) view
            .findViewById(R.id.send_coins_amount_local);
    localAmountView.setInputPrecision(Constants.LOCAL_PRECISION);
    localAmountView.setHintPrecision(Constants.LOCAL_PRECISION);
    amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView);
    amountCalculatorLink.setExchangeDirection(config.getLastExchangeDirection());

    directPaymentEnableView = (CheckBox) view.findViewById(R.id.send_coins_direct_payment_enable);
    directPaymentEnableView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (paymentIntent.isBluetoothPaymentUrl() && isChecked && !bluetoothAdapter.isEnabled()) {
                // ask for permission to enable bluetooth
                startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                        REQUEST_CODE_ENABLE_BLUETOOTH_FOR_DIRECT_PAYMENT);
            }
        }
    });

    directPaymentMessageView = (TextView) view.findViewById(R.id.send_coins_direct_payment_message);

    sentTransactionView = (ListView) view.findViewById(R.id.send_coins_sent_transaction);
    sentTransactionListAdapter = new TransactionsListAdapter(activity, wallet, application.maxConnectedPeers(),
            false);
    sentTransactionView.setAdapter(sentTransactionListAdapter);

    viewGo = (Button) view.findViewById(R.id.send_coins_go);
    viewGo.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            validateReceivingAddress(true);
            isAmountValid();

            if (everythingValid())
                handleGo();
            else
                requestFocusFirst();
        }
    });

    amountCalculatorLink.setNextFocusId(viewGo.getId());

    viewCancel = (Button) view.findViewById(R.id.send_coins_cancel);
    viewCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (state == State.INPUT)
                activity.setResult(Activity.RESULT_CANCELED);

            activity.finish();
        }
    });

    popupMessageView = (TextView) inflater.inflate(R.layout.send_coins_popup_message, container);

    return view;
}

From source file:com.evolup.test.IAPTest01.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./*  w w w  . j  a  va2s  . c  o m*/
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != mRequestCode)
        return false;

    checkSetupDone("handleActivityResult");

    // end of async purchase operation
    flagEndAsync();

    if (data == null) {
        logError("Null data in IAB activity result.");
        result = new IabResult(IABHELPER_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());

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

        Purchase purchase = null;
        try {
            purchase = new Purchase(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(IABHELPER_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(IABHELPER_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(IABHELPER_USER_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(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    return true;
}