List of usage examples for android.os Bundle containsKey
public boolean containsKey(String key)
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Check if passed bundle contains a non-blank string at key k. * //from w w w . j a v a2s . c o m * @param b Bundle to check * @param key Key to check for * @return Present/absent */ public static boolean isNonBlankString(Bundle b, String key) { try { if (b.containsKey(key)) { String s = b.getString(key); return (s != null && s.length() > 0); } else { return false; } } catch (Exception e) { return false; } }
From source file:com.openerp.addons.messages.Message.java
@Override public void onStart() { super.onStart(); Bundle bundle = getArguments(); if (bundle != null) { if (bundle.containsKey("type")) { type = bundle.getString("type"); String title = ""; if (type.equals("inbox")) { // setupListView(TYPE.INBOX); loadMessage = new LoadMessages(TYPE.INBOX); loadMessage.execute((Void) null); title = ""; } else if (type.equals("to-me")) { title = "?"; // setupListView(TYPE.TOME); loadMessage = new LoadMessages(TYPE.TOME); loadMessage.execute((Void) null); } else if (type.equals("to-do")) { // setupListView(TYPE.TODO); title = ""; loadMessage = new LoadMessages(TYPE.TODO); loadMessage.execute((Void) null); } else if (type.equals("archive")) { // setupListView(TYPE.ARCHIVE); loadMessage = new LoadMessages(TYPE.ARCHIVE); loadMessage.execute((Void) null); }/*from w ww . j a va 2s .c om*/ scope.context().setTitle(title); } else { if (bundle.containsKey("group_id")) { group_id = bundle.getString("group_id"); loadMessage = new LoadMessages(TYPE.GROUP); loadMessage.execute((Void) null); } else { scope.context().setTitle(""); loadMessage = new LoadMessages(TYPE.INBOX); loadMessage.execute((Void) null); } } } }
From source file:com.facebook.Session.java
/** * Save the Session object into the supplied Bundle. This method is intended to be called from an * Activity or Fragment's onSaveInstanceState method in order to preserve Sessions across Activity lifecycle events. * * @param session the Session to save/*from w ww . j a v a 2 s. c om*/ * @param bundle the Bundle to save the Session to */ public static final void saveSession(Session session, Bundle bundle) { if (bundle != null && session != null && !bundle.containsKey(SESSION_BUNDLE_SAVE_KEY)) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { new ObjectOutputStream(outputStream).writeObject(session); } catch (IOException e) { throw new FacebookException("Unable to save session.", e); } bundle.putByteArray(SESSION_BUNDLE_SAVE_KEY, outputStream.toByteArray()); bundle.putBundle(AUTH_BUNDLE_SAVE_KEY, session.authorizationBundle); } }
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * If there is a '__thumbnails' key, pick the largest image, rename it * and delete the others. Finally, remove the key. * /*from w w w .j a va 2 s.c o m*/ * @param result Book data */ static public void cleanupThumbnails(Bundle result) { if (result.containsKey("__thumbnail")) { long best = -1; int bestFile = -1; // Parse the list ArrayList<String> files = Utils.decodeList(result.getString("__thumbnail"), '|'); // Just read the image files to get file size BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; // Scan, finding biggest for (int i = 0; i < files.size(); i++) { String filespec = files.get(i); File file = new File(filespec); if (file.exists()) { BitmapFactory.decodeFile(filespec, opt); // If no size info, assume file bad and skip if (opt.outHeight > 0 && opt.outWidth > 0) { long size = opt.outHeight * opt.outWidth; if (size > best) { best = size; bestFile = i; } } } } // Delete all but the best one. Note there *may* be no best one, // so all would be deleted. We do this first in case the list // contains a file with the same name as the target of our // rename. for (int i = 0; i < files.size(); i++) { if (i != bestFile) { File file = new File(files.get(i)); file.delete(); } } // Get the best file (if present) and rename it. if (bestFile >= 0) { File file = new File(files.get(bestFile)); file.renameTo(CatalogueDBAdapter.getTempThumbnail()); } // Finally, cleanup the data result.remove("__thumbnail"); result.putBoolean(CatalogueDBAdapter.KEY_THUMBNAIL, true); } }
From source file:com.soomla.store.billing.google.GoogleIabHelper.java
/** * Restores purchases from Google Play.// w ww . java2 s . co m * * @throws JSONException * @throws RemoteException */ private int queryPurchases(IabInventory inv, String itemType) throws JSONException, RemoteException { // Query purchases SoomlaUtils.LogDebug(TAG, "Querying owned items, item type: " + itemType); SoomlaUtils.LogDebug(TAG, "Package name: " + SoomlaApp.getAppContext().getPackageName()); boolean verificationFailed = false; String continueToken = null; do { SoomlaUtils.LogDebug(TAG, "Calling getPurchases with continuation token: " + continueToken); Bundle ownedItems = mService.getPurchases(3, SoomlaApp.getAppContext().getPackageName(), itemType, continueToken); int response = getResponseCodeFromBundle(ownedItems); SoomlaUtils.LogDebug(TAG, "Owned items response: " + String.valueOf(response)); if (response != IabResult.BILLING_RESPONSE_RESULT_OK) { SoomlaUtils.LogDebug(TAG, "getPurchases() failed: " + IabResult.getResponseDesc(response)); return response; } if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) { SoomlaUtils.LogError(TAG, "Bundle returned from getPurchases() doesn't contain required fields."); return IabResult.IABHELPER_BAD_RESPONSE; } ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST); ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST); ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST); SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME, Context.MODE_PRIVATE); String publicKey = prefs.getString(GooglePlayIabService.PUBLICKEY_KEY, ""); for (int i = 0; i < purchaseDataList.size(); ++i) { String purchaseData = purchaseDataList.get(i); String signature = signatureList.get(i); String sku = ownedSkus.get(i); if (Security.verifyPurchase(publicKey, purchaseData, signature)) { SoomlaUtils.LogDebug(TAG, "Sku is owned: " + sku); IabPurchase purchase = new IabPurchase(itemType, purchaseData, signature); if (TextUtils.isEmpty(purchase.getToken())) { SoomlaUtils.LogWarning(TAG, "BUG: empty/null token!"); SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData); } // Record ownership and token inv.addPurchase(purchase); } else { SoomlaUtils.LogWarning(TAG, "IabPurchase signature verification **FAILED**. Not adding item."); SoomlaUtils.LogDebug(TAG, " IabPurchase data: " + purchaseData); SoomlaUtils.LogDebug(TAG, " Signature: " + signature); verificationFailed = true; } } continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN); SoomlaUtils.LogDebug(TAG, "Continuation token: " + continueToken); } while (!TextUtils.isEmpty(continueToken)); return verificationFailed ? IabResult.IABHELPER_VERIFICATION_FAILED : IabResult.BILLING_RESPONSE_RESULT_OK; }
From source file:com.soomla.store.billing.tapclash.TapClashIabHelper.java
/** * Restores purchases from Google Play./*from ww w . j av a 2 s .co m*/ * * @throws JSONException * @throws RemoteException */ private int queryPurchases(IabInventory inv, String itemType) throws JSONException, RemoteException { // Query purchases SoomlaUtils.LogDebug(TAG, "Querying owned items, item type: " + itemType); SoomlaUtils.LogDebug(TAG, "Package name: " + SoomlaApp.getAppContext().getPackageName()); boolean verificationFailed = false; String continueToken = null; do { SoomlaUtils.LogDebug(TAG, "Calling getPurchases with continuation token: " + continueToken); Bundle ownedItems = mService.getPurchases(3, SoomlaApp.getAppContext().getPackageName(), itemType, continueToken); int response = getResponseCodeFromBundle(ownedItems); SoomlaUtils.LogDebug(TAG, "Owned items response: " + String.valueOf(response)); if (response != IabResult.BILLING_RESPONSE_RESULT_OK) { SoomlaUtils.LogDebug(TAG, "getPurchases() failed: " + IabResult.getResponseDesc(response)); return response; } if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) { SoomlaUtils.LogError(TAG, "Bundle returned from getPurchases() doesn't contain required fields."); return IabResult.IABHELPER_BAD_RESPONSE; } ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST); ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST); ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST); SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME, Context.MODE_PRIVATE); String publicKey = prefs.getString(TapClashIabService.PUBLICKEY_KEY, ""); for (int i = 0; i < purchaseDataList.size(); ++i) { String purchaseData = purchaseDataList.get(i); String signature = signatureList.get(i); String sku = ownedSkus.get(i); if (Security.verifyPurchase(publicKey, purchaseData, signature)) { SoomlaUtils.LogDebug(TAG, "Sku is owned: " + sku); IabPurchase purchase = new IabPurchase(itemType, purchaseData, signature); if (TextUtils.isEmpty(purchase.getToken())) { SoomlaUtils.LogWarning(TAG, "BUG: empty/null token!"); SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData); } // Record ownership and token inv.addPurchase(purchase); } else { SoomlaUtils.LogWarning(TAG, "IabPurchase signature verification **FAILED**. Not adding item."); SoomlaUtils.LogDebug(TAG, " IabPurchase data: " + purchaseData); SoomlaUtils.LogDebug(TAG, " Signature: " + signature); verificationFailed = true; } } continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN); SoomlaUtils.LogDebug(TAG, "Continuation token: " + continueToken); } while (!TextUtils.isEmpty(continueToken)); return verificationFailed ? IabResult.IABHELPER_VERIFICATION_FAILED : IabResult.BILLING_RESPONSE_RESULT_OK; }
From source file:com.soomla.store.billing.nokia.NokiaIabHelper.java
/** * Restores purchases from Nokia Store//from ww w . j av a 2 s. c o m * * @throws JSONException * @throws RemoteException */ private int queryPurchases(IabInventory inv, String itemType) throws JSONException, RemoteException { // Query purchases SoomlaUtils.LogDebug(TAG, "Querying owned items, item type: " + itemType); SoomlaUtils.LogDebug(TAG, "Package name: " + SoomlaApp.getAppContext().getPackageName()); boolean verificationFailed = false; String continueToken = null; //TODO: Tofix ArrayList<String> products = new ArrayList<String>(StoreInfo.getAllProductIds()); Bundle queryBundle = new Bundle(); queryBundle.putStringArrayList("ITEM_ID_LIST", products); do { SoomlaUtils.LogDebug(TAG, "Calling getPurchases with continuation token: " + continueToken); Bundle ownedItems = mService.getPurchases(3, SoomlaApp.getAppContext().getPackageName(), ITEM_TYPE_INAPP, queryBundle, continueToken); int response = getResponseCodeFromBundle(ownedItems); SoomlaUtils.LogDebug(TAG, "Owned items response: " + String.valueOf(response)); if (response != IabResult.BILLING_RESPONSE_RESULT_OK) { SoomlaUtils.LogDebug(TAG, "getPurchases() failed: " + IabResult.getResponseDesc(response)); return response; } if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST) //|| !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST) ) { SoomlaUtils.LogError(TAG, "Bundle returned from getPurchases() doesn't contain required fields."); return IabResult.IABHELPER_BAD_RESPONSE; } ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST); ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST); SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME, Context.MODE_PRIVATE); String publicKey = prefs.getString(NokiaStoreIabService.PUBLICKEY_KEY, ""); for (int i = 0; i < purchaseDataList.size(); ++i) { String purchaseData = purchaseDataList.get(i); String sku = ownedSkus.get(i); if (Security.verifyPurchase(publicKey, purchaseData)) { SoomlaUtils.LogDebug(TAG, "Sku is owned: " + sku); IabPurchase purchase = new IabPurchase(itemType, purchaseData, ""); if (TextUtils.isEmpty(purchase.getToken())) { SoomlaUtils.LogWarning(TAG, "BUG: empty/null token!"); SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData); } // Record ownership and token inv.addPurchase(purchase); } else { SoomlaUtils.LogWarning(TAG, "IabPurchase signature verification **FAILED**. Not adding item."); SoomlaUtils.LogDebug(TAG, " IabPurchase data: " + purchaseData); verificationFailed = true; } } continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN); SoomlaUtils.LogDebug(TAG, "Continuation token: " + continueToken); } while (!TextUtils.isEmpty(continueToken)); return verificationFailed ? IabResult.IABHELPER_VERIFICATION_FAILED : IabResult.BILLING_RESPONSE_RESULT_OK; }
From source file:com.krayzk9s.imgurholo.ui.ImagesFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);//w w w.j av a 2 s . c om ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); actionBar = activity.getActionBar(); SharedPreferences settings = activity.getApiCall().settings; Bundle bundle = getArguments(); if (savedInstanceState != null) { urls = savedInstanceState.getStringArrayList("urls"); ids = savedInstanceState.getParcelableArrayList("ids"); page = savedInstanceState.getInt("page"); } else { urls = new ArrayList<String>(); ids = new ArrayList<JSONParcelable>(); page = 0; } if (bundle != null && bundle.containsKey("id")) isGridView = settings.getString("GalleryLayout", getString(R.string.card_view)) .equals(getString(R.string.grid_view)); else { isGridView = settings.getString("ImagesLayout", getString(R.string.grid_view)) .equals(getString(R.string.grid_view)); } if (bundle == null) { return; } if (bundle.containsKey("id")) albumId = bundle.getString("id"); else albumId = null; if (bundle.containsKey("imageCall")) imageCall = bundle.getString("imageCall"); if (bundle.containsKey("albumData")) { JSONParcelable dataParcel = bundle.getParcelable("albumData"); if (dataParcel != null) galleryAlbumData = dataParcel.getJSONObject(); } }
From source file:com.cdvdev.subscriptiondemo.helpers.IabHelper.java
int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException { // Query purchases logDebug("Querying owned items, item type: " + itemType); logDebug("Package name: " + mContext.getPackageName()); boolean verificationFailed = false; String continueToken = null;/*from www. ja v a2 s . com*/ do { logDebug("Calling getPurchases with continuation token: " + continueToken); Bundle ownedItems = mIInAppBillingService.getPurchases(3, mContext.getPackageName(), itemType, continueToken); int response = getResponseCodeFromBundle(ownedItems); logDebug("Owned items response: " + String.valueOf(response)); if (response != BILLING_RESPONSE_RESULT_OK) { logDebug("getPurchases() failed: " + getResponseDesc(response)); return response; } if (!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; } ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST); ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST); ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST); for (int i = 0; i < purchaseDataList.size(); ++i) { String purchaseData = purchaseDataList.get(i); String signature = signatureList.get(i); String sku = ownedSkus.get(i); if (Security.verifyPurchase(mLicenseKey, purchaseData, signature)) { logDebug("Sku is owned: " + sku); Purchase purchase = new Purchase(itemType, purchaseData, signature); if (TextUtils.isEmpty(purchase.getToken())) { logWarn("BUG: empty/null token!"); logDebug("Purchase data: " + purchaseData); } // Record ownership and token 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 : BILLING_RESPONSE_RESULT_OK; }
From source file:com.evolup.test.IAPTest01.util.IabHelper.java
int queryPurchases(Inventory inv) throws JSONException, RemoteException { // Query purchases logDebug("Querying owned items..."); logDebug("Package name: " + mContext.getPackageName()); boolean hasMore = true; boolean verificationFailed = false; String continueToken = null;/*w ww . jav a2 s .co m*/ do { logDebug("Calling getPurchases with continuation token: " + continueToken); Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), ITEM_TYPE_INAPP, continueToken); int response = getResponseCodeFromBundle(ownedItems); logDebug("Owned items response: " + String.valueOf(response)); if (response != BILLING_RESPONSE_RESULT_OK) { logDebug("getPurchases() failed: " + getResponseDesc(response)); return response; } if (!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; } ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST); ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST); ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST); for (int i = 0; i < purchaseDataList.size(); ++i) { String purchaseData = purchaseDataList.get(i); String signature = signatureList.get(i); String sku = ownedSkus.get(i); if (Security.verifyPurchase(mSignatureBase64, purchaseData, signature)) { logDebug("Sku is owned: " + sku); Purchase purchase = new Purchase(purchaseData, signature); if (TextUtils.isEmpty(purchase.getToken())) { logWarn("BUG: empty/null token!"); logDebug("Purchase data: " + purchaseData); } // Record ownership and token 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 : BILLING_RESPONSE_RESULT_OK; }