Example usage for android.os Bundle containsKey

List of usage examples for android.os Bundle containsKey

Introduction

In this page you can find the example usage for android.os Bundle containsKey.

Prototype

public boolean containsKey(String key) 

Source Link

Document

Returns true if the given key is contained in the mapping of this Bundle.

Usage

From source file:com.github.jberkel.pay.me.IabHelper.java

private int queryPurchases(Inventory inv, ItemType itemType)
        throws JSONException, RemoteException, IabException {
    checkNotDisposed();//from  w ww . ja  v  a 2 s.  c om

    logDebug("Querying owned items, item type: " + itemType);
    boolean verificationFailed = false;
    String continueToken = null;
    do {
        Bundle ownedItems = mService.getPurchases(API_VERSION, mContext.getPackageName(), itemType.toString(),
                continueToken);

        int response = getResponseCodeFromBundle(ownedItems);
        if (response != OK.code) {
            logDebug("getPurchases() failed: " + getDescription(response));
            return response;
        }
        if (ownedItems == null || !ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) {
            logError("Bundle returned from getPurchases() doesn't contain required fields.");
            return IABHELPER_BAD_RESPONSE.code;
        }

        List<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST);
        List<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
        List<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);

        if (signatureList.size() < purchaseDataList.size() || ownedSkus.size() < purchaseDataList.size()) {
            logError("invalid data returned by service");
            return ERROR.code;
        }

        for (int i = 0; i < purchaseDataList.size(); i++) {
            String purchaseData = purchaseDataList.get(i);
            String signature = signatureList.get(i);
            if (mSignatureValidator.validate(purchaseData, signature)) {
                Purchase purchase = new Purchase(itemType, purchaseData, signature);

                if (TextUtils.isEmpty(purchase.getToken())) {
                    logWarn("BUG: empty/null token!");
                    logDebug("Purchase data: " + purchaseData);
                }

                inv.addPurchase(purchase);
            } else {
                logWarn("Purchase signature verification **FAILED**. Not adding item.");
                logDebug("   Purchase data: " + purchaseData);
                logDebug("   Signature: " + signature);
                verificationFailed = true;
            }
        }
        continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
        logDebug("Continuation token: " + continueToken);
    } while (!TextUtils.isEmpty(continueToken));

    return verificationFailed ? IABHELPER_VERIFICATION_FAILED.code : OK.code;
}

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

void threadQueryProduct(final String sku, final long context) {
    ArrayList skuList = new ArrayList();
    skuList.add(sku);/*from  w w w .j  av  a2  s.co m*/
    Bundle productQueryBundle = new Bundle();
    productQueryBundle.putStringArrayList("ITEM_ID_LIST", skuList);

    Bundle skuDetails;
    try {
        skuDetails = mService.getSkuDetails(3, mActivity.getPackageName(), ITEM_TYPE_INAPP, productQueryBundle);
    } catch (RemoteException e) {
        _error("threadQueryProduct: remote exception: " + e);
        e.printStackTrace();
        sendProductInfoError(context, sku);
        return;
    }

    int response = getResponseCodeFromBundle(skuDetails);
    if (BILLING_RESPONSE_RESULT_OK != response) {
        _log("threadQueryProduct: bad response from getSkuDetails: " + response);
        sendProductInfoError(context, sku);
        return;
    }

    if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
        _log("threadQueryProduct: bundle doens't contain list");
        sendProductInfoError(context, sku);
        return;
    }

    ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

    if (1 != responseList.size()) {
        _log("threadQueryProduct: repsonse list has unexpected length: " + responseList.size());
        sendProductInfoError(context, sku);
        return;
    }

    String responseString = responseList.get(0);
    try {
        JSONObject o = new JSONObject(responseString);
        final String _sku = o.getString("productId");
        final String title = o.getString("title");
        final String description = o.getString("description");

        // TODO: something with price
        final String price = o.getString("price");

        // TOOD: check _sku == sku

        sendProductInfo(context, sku, title, description, price);
    } catch (JSONException e) {
        _error("threadQueryProduct: failed parsing JSON");
        sendProductInfoError(context, sku);
    }
}

From source file:com.openerp.addons.messages.Message.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_fragment_message, menu);
    // Associate searchable configuration with the SearchView
    searchView = (SearchView) menu.findItem(R.id.menu_message_search).getActionView();
    Bundle bundle = getArguments();
    if (bundle != null && bundle.containsKey("group_id")) {
        MenuItem compose = menu.findItem(R.id.menu_message_compose);
        compose.setVisible(false);//from w  ww  .ja  va 2  s .co  m
    }
}

From source file:com.segma.trim.InAppBillingUtilities.InAppBillingHelper.java

int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus)
        throws RemoteException, JSONException {
    logDebug("Querying SKU details.");
    ArrayList<String> skuList = new ArrayList<String>();
    skuList.addAll(inv.getAllOwnedSkus(itemType));
    if (moreSkus != null) {
        for (String sku : moreSkus) {
            if (!skuList.contains(sku)) {
                skuList.add(sku);//from w  w w  .j a v a2  s  .  c  o m
            }
        }
    }

    if (skuList.size() == 0) {
        logDebug("queryPrices: nothing to do because there are no SKUs.");
        return BILLING_RESPONSE_RESULT_OK;
    }

    // Split the sku list in blocks of no more than 20 elements.
    ArrayList<ArrayList<String>> packs = new ArrayList<ArrayList<String>>();
    ArrayList<String> tempList;
    int n = skuList.size() / 20;
    int mod = skuList.size() % 20;
    for (int i = 0; i < n; i++) {
        tempList = new ArrayList<String>();
        for (String s : skuList.subList(i * 20, i * 20 + 20)) {
            tempList.add(s);
        }
        packs.add(tempList);
    }
    if (mod != 0) {
        tempList = new ArrayList<String>();
        for (String s : skuList.subList(n * 20, n * 20 + mod)) {
            tempList.add(s);
        }
        packs.add(tempList);
    }

    for (ArrayList<String> skuPartList : packs) {
        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuPartList);
        Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);

        if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
            int response = getResponseCodeFromBundle(skuDetails);
            if (response != BILLING_RESPONSE_RESULT_OK) {
                logDebug("getSkuDetails() failed: " + getResponseDesc(response));
                return response;
            } else {
                logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
                return IABHELPER_BAD_RESPONSE;
            }
        }

        ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

        for (String thisResponse : responseList) {
            StockKeepingUnitDetails d = new StockKeepingUnitDetails(itemType, thisResponse);
            logDebug("Got sku details: " + d);
            inv.addSkuDetails(d);
        }
    }

    return BILLING_RESPONSE_RESULT_OK;
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
 * Convert text at specified key to proper case.
 * /*www  .  j a  va 2s. c  o m*/
 * @param values
 * @param key
 */
public static void doProperCase(Bundle values, String key) {
    if (!values.containsKey(key))
        return;
    values.putString(key, properCase(values.getString(key)));
}

From source file:com.mirasense.scanditsdk.plugin.ScanditSDK.java

private void scan(JSONArray data) {
    if (mPendingOperation) {
        return;/*from   w w w.j ava  2  s .c o  m*/
    }
    mPendingOperation = true;
    mHandler.start();

    final Bundle bundle = new Bundle();
    try {
        bundle.putString(ScanditSDKParameterParser.paramAppKey, data.getString(0));
    } catch (JSONException e) {
        Log.e("ScanditSDK", "Function called through Java Script contained illegal objects.");
        e.printStackTrace();
        return;
    }

    if (data.length() > 1) {
        // We extract all options and add them to the intent extra bundle.
        try {
            setOptionsOnBundle(data.getJSONObject(1), bundle);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    if (bundle.containsKey(ScanditSDKParameterParser.paramContinuousMode)) {
        mContinuousMode = bundle.getBoolean(ScanditSDKParameterParser.paramContinuousMode);
    }

    ScanditLicense.setAppKey(bundle.getString(ScanditSDKParameterParser.paramAppKey));
    ScanditSDKGlobals.usedFramework = "phonegap";

    if (bundle.containsKey(ScanditSDKParameterParser.paramPortraitMargins)
            || bundle.containsKey(ScanditSDKParameterParser.paramLandscapeMargins)) {
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                ScanSettings settings = ScanditSDKParameterParser.settingsForBundle(bundle);
                mBarcodePicker = new SearchBarBarcodePicker(cordova.getActivity(), settings);
                mBarcodePicker.setOnScanListener(ScanditSDK.this);
                mBarcodePicker.setOnSearchBarListener(ScanditSDK.this);
                mLayout = new RelativeLayout(cordova.getActivity());

                ViewGroup viewGroup = getViewGroupToAddTo();
                if (viewGroup != null) {
                    viewGroup.addView(mLayout);
                }

                Display display = cordova.getActivity().getWindowManager().getDefaultDisplay();
                ScanditSDKParameterParser.updatePickerUIFromBundle(mBarcodePicker, bundle, display.getWidth(),
                        display.getHeight());

                RelativeLayout.LayoutParams rLayoutParams = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                mLayout.addView(mBarcodePicker, rLayoutParams);
                adjustLayout(bundle, 0);

                if (bundle.containsKey(ScanditSDKParameterParser.paramPaused)
                        && bundle.getBoolean(ScanditSDKParameterParser.paramPaused)) {
                    mBarcodePicker.startScanning(true);
                } else {
                    mBarcodePicker.startScanning();
                }
            }
        });

    } else {
        ScanditSDKResultRelay.setCallback(this);
        Intent intent = new Intent(cordova.getActivity(), ScanditSDKActivity.class);
        intent.putExtras(bundle);
        cordova.startActivityForResult(this, intent, 1);
    }
}

From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java

/**
 * EventBus listener for Event Bundle// w  w w  .j a  v a  2 s .c om
 * @param {Bundle} event
 */
@Subscribe
public void onEventMainThread(Bundle event) {
    if (event.containsKey("request")) {
        return;
    }
    String name = event.getString("name");

    if (BackgroundGeolocationService.ACTION_START.equalsIgnoreCase(name)) {
        onStarted(event);
    } else if (BackgroundGeolocationService.ACTION_ON_MOTION_CHANGE.equalsIgnoreCase(name)) {
        boolean nowMoving = event.getBoolean("isMoving");
        try {
            JSONObject locationData = new JSONObject(event.getString("location"));
            onMotionChange(nowMoving, locationData);
        } catch (JSONException e) {
            Log.e(TAG, "Error decoding JSON");
            e.printStackTrace();
        }
    } else if (BackgroundGeolocationService.ACTION_GET_LOCATIONS.equalsIgnoreCase(name)) {
        try {
            JSONObject params = new JSONObject();
            params.put("locations", new JSONArray(event.getString("data")));
            params.put("taskId", "android-bg-task-id");
            PluginResult result = new PluginResult(PluginResult.Status.OK, params);
            getLocationsCallback.sendPluginResult(result);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            PluginResult result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
            getLocationsCallback.sendPluginResult(result);
        }
    } else if (BackgroundGeolocationService.ACTION_SYNC.equalsIgnoreCase(name)) {
        Boolean success = event.getBoolean("success");
        if (success) {
            try {
                JSONObject params = new JSONObject();
                params.put("locations", new JSONArray(event.getString("data")));
                params.put("taskId", "android-bg-task-id");
                PluginResult result = new PluginResult(PluginResult.Status.OK, params);
                syncCallback.sendPluginResult(result);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            PluginResult result = new PluginResult(PluginResult.Status.IO_EXCEPTION,
                    event.getString("message"));
            syncCallback.sendPluginResult(result);
        }
    } else if (BackgroundGeolocationService.ACTION_RESET_ODOMETER.equalsIgnoreCase(name)) {
        this.onResetOdometer(event);
    } else if (BackgroundGeolocationService.ACTION_CHANGE_PACE.equalsIgnoreCase(name)) {
        this.onChangePace(event);
    } else if (BackgroundGeolocationService.ACTION_GET_GEOFENCES.equalsIgnoreCase(name)) {
        try {
            JSONArray json = new JSONArray(event.getString("data"));
            PluginResult result = new PluginResult(PluginResult.Status.OK, json);
            getGeofencesCallback.sendPluginResult(result);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            PluginResult result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
            getGeofencesCallback.sendPluginResult(result);
        }
    } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_GOOGLE_PLAY_SERVICES_CONNECT_ERROR)) {
        GoogleApiAvailability.getInstance()
                .getErrorDialog(this.cordova.getActivity(), event.getInt("errorCode"), 1001).show();
    } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_LOCATION_ERROR)) {
        this.onLocationError(event);
    } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_ADD_GEOFENCE)) {
        this.onAddGeofence(event);
    } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_ADD_GEOFENCES)) {
        this.onAddGeofence(event);
    } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_HTTP_RESPONSE)) {
        this.onHttpResponse(event);
    } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_GET_CURRENT_POSITION)) {
        this.onLocationError(event);
    } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_INSERT_LOCATION)) {
        this.onInsertLocation(event);
    } else if (name.equalsIgnoreCase(BackgroundGeolocationService.ACTION_GET_COUNT)) {
        this.onGetCount(event);
    }
}