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:cx.ring.fragments.MediaPreferenceFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_CANCELED)
        return;//from ww  w  . j a va  2s.com

    File myFile = new File(data.getData().getPath());
    Log.i(TAG, "file selected:" + data.getData());
    if (requestCode == SELECT_RINGTONE_PATH) {
        findPreference(AccountDetailAdvanced.CONFIG_RINGTONE_PATH).setSummary(myFile.getName());
        mCallbacks.getAccount().getAdvancedDetails().setDetailString(AccountDetailAdvanced.CONFIG_RINGTONE_PATH,
                myFile.getAbsolutePath());
        mCallbacks.getAccount().notifyObservers();
    }

}

From source file:com.techjoynt.android.nxt.activity.RemoteControl.java

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

    switch (requestCode) {

    case REQUEST_ENABLE_BT:
        if (resultCode == Activity.RESULT_OK) {
            checkForDefault();/*from  w w w  .  ja va2 s.c  om*/

        } else if (resultCode == Activity.RESULT_CANCELED) {
            bluetoothNotTurnedOn().show();
        }
    }
}

From source file:com.mobicage.rogerthat.SendMessageButtonActivity.java

@Override
protected void onServiceBound() {
    setContentView(R.layout.send_message_button);
    setActivityName("send_message_button");
    setTitle(R.string.title_buttons);/*  w  w w  .j a v  a  2s  . co  m*/

    Intent intent = getIntent();
    try {
        mCannedButtons = (CannedButtons) Pickler
                .createObjectFromPickle(intent.getByteArrayExtra(CANNED_BUTTONS));
        mButtons = new LinkedHashSet<Long>();
        long[] buttons = intent.getLongArrayExtra(BUTTONS);
        if (buttons != null) {
            for (long l : buttons) {
                mButtons.add(l);
            }
        }
    } catch (Exception e) {
        L.bug(e);
        setResult(Activity.RESULT_CANCELED);
        finish();
    }

    FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.add);
    floatingActionButton.setImageDrawable(
            new IconicsDrawable(this, FontAwesome.Icon.faw_plus).color(Color.WHITE).sizeDp(24));
    floatingActionButton.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            addButton();
        }
    });

    initButtonsList();
}

From source file:com.home.young.filepicker.AbstractFilePickerActivity.java

@Override
@SuppressWarnings("unchecked")
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.nnf_activity_filepicker);

    Intent intent = getIntent();//from   w w  w  .  ja  va 2 s . c o  m
    if (intent != null) {
        startPath = intent.getStringExtra(EXTRA_START_PATH);
        mode = intent.getIntExtra(EXTRA_MODE, mode);
        allowCreateDir = intent.getBooleanExtra(EXTRA_ALLOW_CREATE_DIR, allowCreateDir);
        allowMultiple = intent.getBooleanExtra(EXTRA_ALLOW_MULTIPLE, allowMultiple);
    }

    FragmentManager fm = getSupportFragmentManager();
    AbstractFilePickerFragment<T> fragment = (AbstractFilePickerFragment<T>) fm.findFragmentByTag(TAG);

    if (fragment == null) {
        fragment = getFragment(startPath, mode, allowMultiple, allowCreateDir);
    }

    if (fragment != null) {
        fm.beginTransaction().replace(R.id.fragment, fragment, TAG).commit();
    }

    // Default to cancelled
    setResult(Activity.RESULT_CANCELED);
}

From source file:org.fdroid.fdroid.privileged.views.UninstallDialogActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME);

    PackageManager pm = getPackageManager();

    ApplicationInfo appInfo;//from  w ww .j  av  a2  s .com
    try {
        //noinspection WrongConstant (lint is actually wrong here!)
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("Failed to get ApplicationInfo for uninstalling");
    }

    final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    final boolean isUpdate = (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;

    if (isSystem && !isUpdate) {
        // Cannot remove system apps unless we're uninstalling updates
        throw new RuntimeException("Cannot remove system apps unless we're uninstalling updates");
    }

    int messageId;
    if (isUpdate) {
        messageId = R.string.uninstall_update_confirm;
    } else {
        messageId = R.string.uninstall_confirm;
    }

    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    final AlertDialog.Builder builder = new AlertDialog.Builder(theme);
    builder.setTitle(appInfo.loadLabel(pm));
    builder.setIcon(appInfo.loadIcon(pm));
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent data = new Intent();
            data.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName);
            setResult(Activity.RESULT_OK, intent);
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setMessage(messageId);
    builder.create().show();
}

From source file:com.cachirulop.moneybox.fragment.MovementsFragment.java

/**
 * Called when returns of the edit detail window. Refresh the movement list
 * to show the possible changes do it in the edit detail window.
 *///from   ww w  .  j a v  a  2  s.  c  o  m
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == EDIT_MOVEMENT_REQUEST) {
        Movement m;

        m = (Movement) data.getExtras().get("movement");
        switch (resultCode) {
        case MovementDetailActivity.RESULT_GET_MOVEMENT:
            ((IMoneyboxListener) getActivity()).onGetMovement(m);
            break;

        case MovementDetailActivity.RESULT_DELETE_MOVEMENT:
            ((IMoneyboxListener) getActivity()).onDeleteMovement(m);
            break;

        case MovementDetailActivity.RESULT_DROP_MOVEMENT:
            // ((IMoneyboxListener) getActivity ()).onDeleteMovement (m);
            break;
        }

        if (resultCode != Activity.RESULT_CANCELED) {
            refresh();
        }
    }

}

From source file:com.appsimobile.appsii.iab.IabPurchaseHelper.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 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  ww. j  av  a 2 s.  c  o m*/
 */
public static int handleActivityResult(int resultCode, Intent data,
        OnIabPurchaseFinishedListener purchaseListener, String itemType, String devPayload) {

    if (data == null) {
        logError("Null data in IAB activity result.");
        return IABHELPER_BAD_RESPONSE;
    }

    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: " + itemType);

        if (purchaseData == null || dataSignature == null) {
            logError("BUG: either purchaseData or dataSignature is null.");
            logDebug("Extras: " + data.getExtras().toString());
            return IABHELPER_UNKNOWN_ERROR;
        }

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

            // Verify signature
            if (!Security.verifyPurchase(RSA_CODE, purchaseData, dataSignature)) {
                logError("Purchase signature verification FAILED for sku " + sku);
                return IABHELPER_VERIFICATION_FAILED;
            }
            logDebug("Purchase signature successfully verified.");
            if (!Security.verifyDeveloperPayload(purchase, devPayload)) {
                logError("Purchase payload verification FAILED for sku " + sku);
                return IABHELPER_DEVELOPER_PAYLOAD_FAILED;
            }
            logDebug("Developer payload successfully verified.");
        } catch (JSONException e) {
            logError("Failed to parse purchase data.");
            e.printStackTrace();
            return IABHELPER_BAD_RESPONSE;
        }

        if (purchaseListener != null) {
            purchaseListener.onIabPurchaseSuccess(purchase);
        }
        return BILLING_RESPONSE_RESULT_OK;

    } 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));
        return responseCode;
    } else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        return IABHELPER_USER_CANCELLED;
    } else {
        logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: "
                + getResponseDesc(responseCode));
        return IABHELPER_UNKNOWN_PURCHASE_RESPONSE;
    }
}

From source file:com.nononsenseapps.filepicker.ui.core.AbstractFilePickerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_ACTION_BAR);
    setupFauxDialog();/*from ww w  .  j a  va2 s . c o  m*/
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_filepicker);

    Intent intent = getIntent();
    if (intent != null) {
        startPath = intent.getStringExtra(Extras.EXTRA_START_PATH);
        mode = AbstractFilePickerFragment.SelectionMode.values()[intent.getIntExtra(Extras.EXTRA_MODE,
                AbstractFilePickerFragment.SelectionMode.MODE_FILE.ordinal())];
        allowCreateDir = intent.getBooleanExtra(Extras.EXTRA_ALLOW_CREATE_DIR, allowCreateDir);
        allowMultiple = intent.getBooleanExtra(Extras.EXTRA_ALLOW_MULTIPLE, allowMultiple);
    }

    setupActionBar();

    FragmentManager fm = getSupportFragmentManager();
    AbstractFilePickerFragment fragment = (AbstractFilePickerFragment) fm.findFragmentByTag(TAG);

    if (fragment == null) {
        fragment = getFragment(startPath, mode, allowMultiple, allowCreateDir);
    }

    if (fragment != null) {
        fm.beginTransaction().replace(R.id.fragment, fragment, TAG).commit();
    }

    // Default to cancelled
    setResult(Activity.RESULT_CANCELED);
}

From source file:com.phonegap.plugins.barcodescanner.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  .j  av a2  s . co  m*/
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);
        }
        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);
        } else {
            this.error(new PluginResult(PluginResult.Status.ERROR), this.callback);
        }
    }
}

From source file:net.kenevans.android.bleexplorer.DeviceScanActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setTitle(R.string.title_devices);
    }/*from   w ww.j  a  v a2  s . com*/
    mHandler = new Handler();

    // Use this check to determine whether BLE is supported on the device.
    // Then you can
    // selectively disable BLE-related features.
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_LONG).show();
        finish();
    }

    // Initializes a Bluetooth adapter. For API level 18 and above, get a
    // reference to BluetoothAdapter through BluetoothManager.
    mBluetoothAdapter = null;
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (bluetoothManager == null) {
        Toast.makeText(this, R.string.error_bluetooth_manager, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    try {
        mBluetoothAdapter = bluetoothManager.getAdapter();
    } catch (NullPointerException ex) {
        Toast.makeText(this, R.string.error_bluetooth_adapter, Toast.LENGTH_LONG).show();
    }

    // Checks if Bluetooth is supported on the device.
    if (mBluetoothAdapter == null) {
        String msg = getString(R.string.bluetooth_not_supported);
        Utils.errMsg(this, msg);
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        finish();
    }

    // Set result CANCELED in case the user backs out
    setResult(Activity.RESULT_CANCELED);
}