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.mobicage.rogerthat.SendMessageButtonActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    T.UI();//ww w .j  av a  2s.c  o m

    switch (item.getItemId()) {
    case R.id.save:
        try {
            Intent resultIntent = new Intent();
            resultIntent.putExtra(CANNED_BUTTONS, Pickler.getPickleFromObject(mCannedButtons));
            long[] primitiveLongArray = new long[mButtons.size()];
            Long[] longArray = mButtons.toArray(new Long[mButtons.size()]);
            for (int i = 0; i < longArray.length; i++) {
                primitiveLongArray[i] = longArray[i].longValue();
            }
            resultIntent.putExtra(BUTTONS, primitiveLongArray);
            setResult(Activity.RESULT_OK, resultIntent);
        } catch (Exception e) {
            L.bug(e);
            setResult(Activity.RESULT_CANCELED);
        }
        finish();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.turbulenz.turbulenz.googlepayment.java

public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    _log("handleActivityResult: requestCode: " + requestCode + " resultCode: " + resultCode);

    if (0 == mPurchaseContext) {
        _error("handleActivityResult: no purchase context registered");
        return true;
    }//from w  w w .  j  av a 2 s  . c o  m

    if (Activity.RESULT_CANCELED == resultCode) {
        _log("handleActivityResult: cancelled");
        sendPurchaseFailure(mPurchaseContext, null);
        mPurchaseContext = 0;
        return true;
    }

    if (Activity.RESULT_OK != resultCode) {
        _log("onActivityResult: unknown result code");
        sendPurchaseFailure(mPurchaseContext, "Unknown GooglePlay failure");
        mPurchaseContext = 0;
        return true;
    }

    _log("handleActivityResult: resultCode was OK");

    int purchaseResponse = getResponseCodeFromIntent(data);
    if (BILLING_RESPONSE_RESULT_OK != purchaseResponse) {
        _log("onActivityResult: bad purchaseResponse: " + purchaseResponse);
        sendPurchaseFailure(mPurchaseContext, "Purchase did not complete");
        mPurchaseContext = 0;
        return true;
    }

    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String purchaseSig = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);
    String purchaseGoogleToken;
    String purchaseDevPayload;

    _log("onActivityResult: purchaseResponse: OK" + ", purchaseData: " + purchaseData + ", purchaseSig: "
            + purchaseSig);

    if (null == purchaseData || null == purchaseSig) {
        _log("onActivityResult: bad purchase data");
        sendPurchaseFailure(mPurchaseContext, "bad purchase data");
        mPurchaseContext = 0;
        return true;
    }

    if (!verifyPurchase(purchaseData, purchaseSig)) {
        _log("onActivityResult: invalid signature");
        sendPurchaseFailure(mPurchaseContext, "invalid signature");
        mPurchaseContext = 0;
        return true;
    }

    // Extract the sku name from the purchase data

    String sku;
    String googleToken;
    String devPayload;
    try {
        JSONObject o = new JSONObject(purchaseData);
        sku = o.optString("productId");
        googleToken = o.optString("token", o.optString("purchaseToken"));
        devPayload = o.optString("developerPayload");
    } catch (JSONException e) {
        sendPurchaseFailure(mPurchaseContext, "no sku data in GooglePlaye response");
        mPurchaseContext = 0;
        return true;
    }

    if (TextUtils.isEmpty(sku)) {
        sendPurchaseFailure(mPurchaseContext, "sku name was empty");
        mPurchaseContext = 0;
        return true;
    }

    _log("onActivityResult: purchase succeeded");
    sendPurchaseResult(mPurchaseContext, sku, purchaseData, googleToken, devPayload, purchaseSig);
    mPurchaseContext = 0;
    return true;
}

From source file:com.facebook.login.LoginManager.java

boolean onActivityResult(int resultCode, Intent data, FacebookCallback<LoginResult> callback) {
    FacebookException exception = null;/* w  ww  .  j a v  a 2s. c  o m*/
    AccessToken newToken = null;
    LoginClient.Result.Code code = LoginClient.Result.Code.ERROR;
    Map<String, String> loggingExtras = null;
    LoginClient.Request originalRequest = null;

    boolean isCanceled = false;
    if (data != null) {
        LoginClient.Result result = (LoginClient.Result) data.getParcelableExtra(LoginFragment.RESULT_KEY);
        if (result != null) {
            originalRequest = result.request;
            code = result.code;
            if (resultCode == Activity.RESULT_OK) {
                if (result.code == LoginClient.Result.Code.SUCCESS) {
                    newToken = result.token;
                } else {
                    exception = new FacebookAuthorizationException(result.errorMessage);
                }
            } else if (resultCode == Activity.RESULT_CANCELED) {
                isCanceled = true;
            }
            loggingExtras = result.loggingExtras;
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        isCanceled = true;
        code = LoginClient.Result.Code.CANCEL;
    }

    if (exception == null && newToken == null && !isCanceled) {
        exception = new FacebookException("Unexpected call to LoginManager.onActivityResult");
    }

    boolean wasLoginActivityTried = true;
    Context context = null; //Sadly, there is no way to get activity context at this point.S
    logCompleteLogin(context, code, loggingExtras, exception, wasLoginActivityTried, originalRequest);

    finishLogin(newToken, originalRequest, exception, isCanceled, callback);

    return true;
}

From source file:com.clearbon.cordova.netswipe.NetSwipePlugin.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == NetswipeSDK.REQUEST_CODE) {
        /*ArrayList<String> scanAttempts = 
        data.getStringArrayListExtra(NetswipeSDK.EXTRA_SCAN_ATTEMPTS);*/
        if (resultCode == Activity.RESULT_OK) {
            NetswipeCardInformation cardInformation = data
                    .getParcelableExtra(NetswipeSDK.EXTRA_CARD_INFORMATION);

            //TODO card type
            //CreditCardType creditCardType = cardInformation.getCardType();

            JSONObject cardInfo = new JSONObject();
            try {
                cardInfo.put("cardNumber", getStringValue(cardInformation.getCardNumber(), true));
                cardInfo.put("expiryMonth", getStringValue(cardInformation.getExpiryDateMonth(), false));
                cardInfo.put("expiryYear", getStringValue(cardInformation.getExpiryDateYear(), false));
                cardInfo.put("cvv", getStringValue(cardInformation.getCvvCode(), false));
                cardInfo.put("cardHolderName", getStringValue(cardInformation.getCardHolderName(), false));
                cardInfo.put("sortCode", getStringValue(cardInformation.getSortCode(), false));
                cardInfo.put("accountNumber", getStringValue(cardInformation.getAccountNumber(), false));
                cardInfo.put("cardNumberManuallyEntered", cardInformation.isCardNumberManuallyEntered());

                //TODO custom fields
                //String zipCode = cardInformation.getCustomField("zip_code");

                callbackContext.success(cardInfo);

            } catch (JSONException e) {
                Log.e(LogTag, "Error creating return parameters for success callback.", e);
            } finally {
                cardInformation.clear();
                cardInfo.remove("cardNumber");
                cardInfo.remove("expiryMonth");
                cardInfo.remove("expiryYear");
                cardInfo.remove("cvv");
                cardInfo.remove("cardHolderName");
                cardInfo.remove("sortCode");
                cardInfo.remove("accountNumber");
                cardInfo.remove("cardNumberManuallyEntered");
                cardInfo = null;/* ww w .  j ava2 s  .c o m*/
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            try {
                int errorCode = data.getIntExtra(NetswipeSDK.EXTRA_ERROR_CODE, 0);
                String errorMessage = data.getStringExtra(NetswipeSDK.EXTRA_ERROR_MESSAGE);

                JSONObject cardInfo = new JSONObject();
                cardInfo.put("code", errorCode);
                cardInfo.put("message", errorMessage);

                callbackContext.error(cardInfo);
            } catch (JSONException e) {
                Log.e(LogTag, "Error creating return parameters for error callback.", e);
            }
        }
    }
}

From source file:com.laevatein.internal.ui.PhotoSelectionActivity.java

@Override
public void onPositive() {
    setResult(Activity.RESULT_CANCELED);
    finish();
}

From source file:com.devgmail.mitroshin.totutu.controllers.StartFragment.java

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

    //            ?,     Back.
    if (resultCode == Activity.RESULT_CANCELED) {
        return;/*w  w w. j  a v a  2s. c  o m*/
    }

    //        ??   ? ?, ?  ??,
    //         ??     ?? ?

    if (requestCode == REQUEST_STATION_OBJECT) {
        if (data == null) {
            return;
        }
        mResultDirectionType = ListFragment.resultDirectionType(data);

        //             ??      ??   ?,
        //              ??  ?  ? ?.
        updateUI(mResultDirectionType, data);
    }
}

From source file:com.gbaldera.tipaypal.TipaypalModule.java

@Override
public void onResult(Activity activity, int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);

        if (confirm != null) {
            try {

                // send 'confirm' to your server for verification.
                // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                // for more details.

                Log.i(TAG, confirm.toJSONObject().toString(4));
                processResult(resultCode, new KrollDict(confirm.toJSONObject()));

            } catch (JSONException e) {
                processFailed(resultCode, e);
            }/*from   w  w  w  .j  a va 2  s  .  co  m*/
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        processCanceled(resultCode);
    } else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
        processInvalid(resultCode);
    }
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningActivity.java

private void onProvisioningAborted() {
    stopService(new Intent(this, ProfileOwnerProvisioningService.class));
    setResult(Activity.RESULT_CANCELED);
    finish();/*  w w w  .j  a  va 2s.c  o m*/
}

From source file:dev.dworks.apps.anexplorer.DocumentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    if (SettingsActivity.getTranslucentMode(this) && Utils.hasKitKat()) {
        setTheme(R.style.Theme_Translucent);
    }//from  w  w w.j a  v a  2s  . c  om
    super.onCreate(icicle);

    mRoots = DocumentsApplication.getRootsCache(this);

    setResult(Activity.RESULT_CANCELED);
    setContentView(R.layout.activity);

    final Resources res = getResources();
    mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);

    if (mShowAsDialog) {
        // backgroundDimAmount from theme isn't applied; do it manually
        final WindowManager.LayoutParams a = getWindow().getAttributes();
        a.dimAmount = 0.6f;
        getWindow().setAttributes(a);

        getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        // Inset ourselves to look like a dialog
        final Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);

        final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x);
        final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y);
        final int insetX = (size.x - width) / 2;
        final int insetY = (size.y - height) / 2;

        final Drawable before = getWindow().getDecorView().getBackground();
        final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY);
        ViewCompat.setBackground(getWindow().getDecorView(), after);

        // Dismiss when touch down in the dimmed inset area
        getWindow().getDecorView().setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    final float x = event.getX();
                    final float y = event.getY();
                    if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) {
                        finish();
                        return true;
                    }
                }
                return false;
            }
        });

    } else {
        // Non-dialog means we have a drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph,
                R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);

        mRootsContainer = findViewById(R.id.container_roots);
    }

    mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);
    mSaveContainer = (FrameLayout) findViewById(R.id.container_save);

    if (icicle != null) {
        mState = icicle.getParcelable(EXTRA_STATE);
        authenticated = icicle.getBoolean(EXTRA_AUTHENTICATED);
    } else {
        buildDefaultState();
    }

    initProtection();

    // Hide roots when we're managing a specific root
    if (mState.action == ACTION_MANAGE) {
        if (mShowAsDialog) {
            findViewById(R.id.dialog_roots).setVisibility(View.GONE);
        } else {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    }

    if (mState.action == ACTION_CREATE) {
        final String mimeType = getIntent().getType();
        final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE);
        SaveFragment.show(getFragmentManager(), mimeType, title);
    }

    if (mState.action == ACTION_BROWSE) {
        final Intent moreApps = new Intent(getIntent());
        moreApps.setComponent(null);
        moreApps.setPackage(null);
        RootsFragment.show(getFragmentManager(), null);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE
            || mState.action == ACTION_GET_CONTENT) {
        RootsFragment.show(getFragmentManager(), new Intent());
    }

    if (!mState.restored) {
        if (mState.action == ACTION_MANAGE) {
            final Uri rootUri = getIntent().getData();
            new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
        } else {
            new RestoreStackTask().execute();
        }
    } else {
        onCurrentDirectoryChanged(ANIM_NONE);
    }

    if (Utils.hasKitKat()) {
        if (SettingsActivity.getTranslucentMode(this)) {
            SystemBarTintManager.setupTint(this);
            SystemBarTintManager.setNavigationInsets(this, mSaveContainer);
            mDirectoryContainer
                    .setLayoutParams(SystemBarTintManager.getToggleParams(false, R.id.container_save));
        } else {
            mDirectoryContainer
                    .setLayoutParams(SystemBarTintManager.getToggleParams(true, R.id.container_save));
        }
    }
}

From source file:com.zion.htf.ui.ArtistDetailsActivity.java

@Override
public void onArtistFavoriteStatusChanged(boolean isFavorite) {
    this.setResult(isFavorite ? Activity.RESULT_CANCELED : Activity.RESULT_OK);
}