Example usage for android.os Bundle getStringArrayList

List of usage examples for android.os Bundle getStringArrayList

Introduction

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

Prototype

@Override
@Nullable
public ArrayList<String> getStringArrayList(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:org.anhonesteffort.flock.sync.account.AccountSyncWorker.java

private List<JSONObject> getPurchasedGoogleSubscriptions() {
    List<JSONObject> subscriptions = new LinkedList<>();

    if (billingService == null) {
        Log.e(TAG, "billing service is null");
        return subscriptions;
    }/*from   ww w.java  2s  .c  o  m*/

    try {

        Bundle ownedItems = billingService.getPurchases(3,
                SubscriptionGoogleFragment.class.getPackage().getName(),
                SubscriptionGoogleFragment.PRODUCT_TYPE_SUBSCRIPTION, null);

        ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");

        for (int i = 0; i < purchaseDataList.size(); ++i) {
            JSONObject productObject = new JSONObject(purchaseDataList.get(i));
            if (productObject.getString("productId") != null)
                subscriptions.add(productObject);
        }

    } catch (RemoteException e) {
        SyncWorkerUtil.handleException(context, e, result);
    } catch (JSONException e) {
        SyncWorkerUtil.handleException(context, e, result);
    }

    return subscriptions;
}

From source file:org.thialfihar.android.apg.ui.KeyListPublicFragment.java

/**
 * Show dialog to delete key/*w w w .j  a  v a  2s.  com*/
 *
 * @param keyRingRowIds
 */
@TargetApi(11)
public void showDeleteKeyDialog(final ActionMode mode, long[] keyRingRowIds) {
    // Message is received after key is deleted
    Handler returnHandler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
                Bundle returnData = message.getData();
                if (returnData != null && returnData.containsKey(DeleteKeyDialogFragment.MESSAGE_NOT_DELETED)) {
                    ArrayList<String> notDeleted = returnData
                            .getStringArrayList(DeleteKeyDialogFragment.MESSAGE_NOT_DELETED);
                    String notDeletedMsg = "";
                    for (String userId : notDeleted) {
                        notDeletedMsg += userId + "\n";
                    }
                    Toast.makeText(getActivity(),
                            getString(R.string.error_can_not_delete_contacts, notDeletedMsg) + getResources()
                                    .getQuantityString(R.plurals.error_can_not_delete_info, notDeleted.size()),
                            Toast.LENGTH_LONG).show();

                    mode.finish();
                }
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(returnHandler);

    DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, keyRingRowIds,
            Id.type.public_key);

    deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog");
}

From source file:com.zd.vpn.fragments.AboutFragment.java

private void initGMSDonateOptions() {
    try {/*  w  w  w.ja v  a  2s  .  co m*/
        int billingSupported = mService.isBillingSupported(3, getActivity().getPackageName(),
                INAPPITEM_TYPE_INAPP);
        if (billingSupported != BILLING_RESPONSE_RESULT_OK) {
            Log.i("OpenVPN", "Play store billing not supported");
            return;
        }

        ArrayList skuList = new ArrayList();
        Collections.addAll(skuList, donationSkus);
        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList("ITEM_ID_LIST", skuList);

        Bundle ownedItems = mService.getPurchases(3, getActivity().getPackageName(), INAPPITEM_TYPE_INAPP,
                null);

        if (ownedItems.getInt(RESPONSE_CODE) != BILLING_RESPONSE_RESULT_OK)
            return;

        final ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");

        Bundle skuDetails = mService.getSkuDetails(3, getActivity().getPackageName(), INAPPITEM_TYPE_INAPP,
                querySkus);

        if (skuDetails.getInt(RESPONSE_CODE) != BILLING_RESPONSE_RESULT_OK)
            return;

        final ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");

        if (getActivity() != null) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    createPlayBuyOptions(ownedSkus, responseList);

                }
            });
        }

    } catch (RemoteException e) {
        VpnStatus.logException(e);
    }
}

From source file:net.olejon.spotcommander.DonateActivity.java

private void resetDonations() {
    try {// w  w  w . j av a2  s.  com
        final Bundle purchasesBundle = mIInAppBillingService.getPurchases(3, getPackageName(), "inapp", null);

        final int responseCode = purchasesBundle.getInt("RESPONSE_CODE");

        if (responseCode == 0) {
            final ArrayList<String> purchaseDataList = purchasesBundle
                    .getStringArrayList("INAPP_PURCHASE_DATA_LIST");

            if (purchaseDataList != null) {
                for (String purchaseData : purchaseDataList) {
                    consumeDonation(new JSONObject(purchaseData).getString("purchaseToken"));
                }
            }

            mTools.showToast(getString(R.string.donate_reset_success), 0);
        } else {
            mTools.showToast(getString(R.string.donate_something_went_wrong), 1);
        }
    } catch (Exception e) {
        mTools.showToast(getString(R.string.donate_something_went_wrong), 1);

        Log.e("DonateActivity", Log.getStackTraceString(e));
    }
}

From source file:com.gamethrive.TrackGooglePurchase.java

private void sendPurchases(final ArrayList<String> skusToAdd, final ArrayList<String> newPurchaseTokens) {
    try {/*from w w  w.ja v a2 s . co m*/
        if (getSkuDetailsMethod == null)
            getSkuDetailsMethod = IInAppBillingServiceClass.getMethod("getSkuDetails", int.class, String.class,
                    String.class, Bundle.class);

        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList("ITEM_ID_LIST", skusToAdd);
        Bundle skuDetails = (Bundle) getSkuDetailsMethod.invoke(mIInAppBillingService, 3,
                appContext.getPackageName(), "inapp", querySkus);

        int response = skuDetails.getInt("RESPONSE_CODE");
        if (response == 0) {
            ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
            Map<String, JSONObject> currentSkus = new HashMap<String, JSONObject>();
            JSONObject jsonItem;
            for (String thisResponse : responseList) {
                JSONObject object = new JSONObject(thisResponse);
                String sku = object.getString("productId");
                BigDecimal price = new BigDecimal(object.getString("price_amount_micros"));
                price = price.divide(new BigDecimal(1000000));

                jsonItem = new JSONObject();
                jsonItem.put("sku", sku);
                jsonItem.put("iso", object.getString("price_currency_code"));
                jsonItem.put("amount", price.toString());
                currentSkus.put(sku, jsonItem);
            }

            JSONArray purchasesToReport = new JSONArray();
            for (String sku : skusToAdd) {
                if (!currentSkus.containsKey(sku))
                    continue;
                purchasesToReport.put(currentSkus.get(sku));
            }

            // New purchases to report.
            // Wait until we have a playerID then send purchases to server. If successful then mark them as tracked.
            if (purchasesToReport.length() > 0) {
                final JSONArray finalPurchasesToReport = purchasesToReport;
                gameThrive.idsAvailable(new IdsAvailableHandler() {
                    public void idsAvailable(String playerId, String registrationId) {
                        gameThrive.sendPurchases(finalPurchasesToReport, newAsExisting,
                                new JsonHttpResponseHandler() {
                                    public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                                            JSONObject errorResponse) {
                                        Log.i(GameThrive.TAG, "JSON sendPurchases Failed");
                                        throwable.printStackTrace();
                                        isWaitingForPurchasesRequest = false;
                                    }

                                    public void onSuccess(int statusCode, Header[] headers,
                                            JSONObject response) {
                                        purchaseTokens.addAll(newPurchaseTokens);
                                        prefsEditor.putString("purchaseTokens", purchaseTokens.toString());
                                        prefsEditor.remove("ExistingPurchases");
                                        prefsEditor.commit();
                                        newAsExisting = false;
                                        isWaitingForPurchasesRequest = false;
                                    }
                                });
                    }
                });

            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.thunder.iap.IAPActivity.java

/**
 * returns the purchased items for a user
 * @param itemType/* ww w.  j av a 2 s.c  om*/
 * @param purchasedItemsListener
 */
public void getPurchasedItems(String itemType, PurchasedItemsListener purchasedItemsListener) {
    try {
        Bundle ownedItems = mService.getPurchases(3, getPackageName(), itemType, null);
        int response = ownedItems.getInt("RESPONSE_CODE");
        if (response == 0) {
            ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
            ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
            ArrayList<String> signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
            String continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");
            Map<String, PurchasedItem> skuToPurchasedItem = new HashMap<String, PurchasedItem>();
            for (int i = 0; i < purchaseDataList.size(); ++i) {
                String purchaseData = purchaseDataList.get(i);
                String signature = signatureList.get(i);
                String sku = ownedSkus.get(i);
                // do something with this purchase information
                // e.g. display the updated list of products owned by user
                skuToPurchasedItem.put(sku, new PurchasedItem(purchaseData, signature, sku));
            }
            while (continuationToken != null) {
                try {
                    ownedItems = mService.getPurchases(3, getPackageName(), itemType, continuationToken);
                    response = ownedItems.getInt("RESPONSE_CODE");
                    if (response == 0) {
                        ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
                        purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
                        signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
                        continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");
                        for (int i = 0; i < purchaseDataList.size(); ++i) {
                            String purchaseData = purchaseDataList.get(i);
                            String signature = signatureList.get(i);
                            String sku = ownedSkus.get(i);
                            // do something with this purchase information
                            // e.g. display the updated list of products owned by user
                            skuToPurchasedItem.put(sku, new PurchasedItem(purchaseData, signature, sku));
                        }
                    } else {
                        purchasedItemsListener.onServerError(ownedItems);
                    }
                } catch (RemoteException e) {
                    e.printStackTrace();
                    purchasedItemsListener.onError(e);
                }
            }
            // if continuationToken != null, call getPurchases again
            // and pass in the token to retrieve more items
        } else {
            purchasedItemsListener.onServerError(ownedItems);
        }
    } catch (RemoteException e) {
        e.printStackTrace();
        purchasedItemsListener.onError(e);
    }
}

From source file:eu.trentorise.smartcampus.eb.fragments.experience.AssignCollectionFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final List<ExpCollection> collections = EBHelper.getUserPreference().getCollections();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.expmenu_assign_collection);

    if (savedInstanceState != null) {
        selected = savedInstanceState.getBooleanArray("selected");
        selectedIds = new HashSet<String>(savedInstanceState.getStringArrayList("selectedIds"));
        items = savedInstanceState.getStringArray("items");
    } else {/*from   w w  w. jav a  2s. co m*/
        items = new String[collections.size()];
        selected = new boolean[collections.size()];
        for (int i = 0; i < items.length; i++) {
            items[i] = collections.get(i).getName();
            boolean b = false;
            if (getArguments().getStringArrayList(ARG_COLLS) != null) {
                for (String s : getArguments().getStringArrayList(ARG_COLLS)) {
                    if (s.equals(collections.get(i).getId())) {
                        b = true;
                        break;
                    }
                }
            }
            selected[i] = b;
        }
        selectedIds = new HashSet<String>();
        if (getArguments().getStringArrayList(ARG_COLLS) != null)
            selectedIds.addAll(getArguments().getStringArrayList(ARG_COLLS));
    }

    builder.setMultiChoiceItems(items, selected, new OnMultiChoiceClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            if (isChecked)
                selectedIds.add(collections.get(which).getId());
            else
                selectedIds.remove(collections.get(which).getId());
        }
    });

    builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //            exp.setCollectionIds(new ArrayList<String>(selectedIds));
            //            Fragment f = getFragmentManager().findFragmentById(containerId);
            AssignCollectionsCallback c = ((DialogCallbackContainer) getActivity())
                    .getAssignCollectionsCallback();
            c.onCollectionsAssigned(getArguments().getString(ARG_ID), new ArrayList<String>(selectedIds));
            dialog.dismiss();
        }
    });
    builder.setPositiveButton(R.string.dialog_collection_add, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            DialogFragment newCollFragment = new NewCollectionDialogFragment();
            newCollFragment.setArguments(NewCollectionDialogFragment.prepare(null));
            newCollFragment.show(getActivity().getSupportFragmentManager(), "exp_coll");
            //
            //             NewCollectionDialogFragment.saveCollectionDialog(getActivity(), null, new CollectionSavedHandler() {
            //               @Override
            //               public void onCollectionSaved(ExpCollection coll) {
            ////                  exp.setCollectionIds(Collections.singletonList(coll.getId()));
            //                  ((AssignCollectionsCallback)getFragmentManager().findFragmentById(android.R.id.content)).onCollectionsAssigned(getArguments().getString(ARG_ID), Collections.singletonList(coll.getId()));
            //               }
            //            }).show();
            dialog.dismiss();
        }
    });

    return builder.create();
}

From source file:eu.faircode.adblocker.IAB.java

public List<String> getPurchases() throws RemoteException {
    // Get purchases
    Bundle bundle = service.getPurchases(IAB_VERSION, context.getPackageName(), "inapp", null);
    Log.i(TAG, "getPurchases");
    Util.logBundle(bundle);// w ww  . j a va  2 s  .  c  om
    int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1));
    Log.i(TAG, "Response=" + getResult(response));
    if (response != 0)
        throw new IllegalArgumentException(getResult(response));

    ArrayList<String> details = bundle.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
    return (details == null ? new ArrayList<String>() : details);
}

From source file:com.odo.kcl.mobileminer.activities.MainActivity.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);

    this.miningButtonState = savedInstanceState.getBoolean("miningButtonState", false);

    if (savedInstanceState.getString("cellText") != null) {
        this.cellButton.setText(savedInstanceState.getString("cellText"));
    }//from w  w  w .  j  a  v  a2s  .co  m

    if (savedInstanceState.getStringArrayList("processHeader") != null) {
        this.processHeader = savedInstanceState.getStringArrayList("processHeader");
        for (String key : this.processHeader) {
            socketChild.put(key, savedInstanceState.getStringArrayList(key));
        }
    }

    enableMiningButton(miningButtonState);
}

From source file:com.onesignal.TrackGooglePurchase.java

private void sendPurchases(final ArrayList<String> skusToAdd, final ArrayList<String> newPurchaseTokens) {
    try {// w ww . j  ava  2 s .  co  m
        if (getSkuDetailsMethod == null) {
            getSkuDetailsMethod = getGetSkuDetailsMethod(IInAppBillingServiceClass);
            getSkuDetailsMethod.setAccessible(true);
        }

        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList("ITEM_ID_LIST", skusToAdd);
        Bundle skuDetails = (Bundle) getSkuDetailsMethod.invoke(mIInAppBillingService, 3,
                appContext.getPackageName(), "inapp", querySkus);

        int response = skuDetails.getInt("RESPONSE_CODE");
        if (response == 0) {
            ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
            Map<String, JSONObject> currentSkus = new HashMap<String, JSONObject>();
            JSONObject jsonItem;
            for (String thisResponse : responseList) {
                JSONObject object = new JSONObject(thisResponse);
                String sku = object.getString("productId");
                BigDecimal price = new BigDecimal(object.getString("price_amount_micros"));
                price = price.divide(new BigDecimal(1000000));

                jsonItem = new JSONObject();
                jsonItem.put("sku", sku);
                jsonItem.put("iso", object.getString("price_currency_code"));
                jsonItem.put("amount", price.toString());
                currentSkus.put(sku, jsonItem);
            }

            JSONArray purchasesToReport = new JSONArray();
            for (String sku : skusToAdd) {
                if (!currentSkus.containsKey(sku))
                    continue;
                purchasesToReport.put(currentSkus.get(sku));
            }

            // New purchases to report.
            // Wait until we have a userID then send purchases to server. If successful then mark them as tracked.
            if (purchasesToReport.length() > 0) {
                final JSONArray finalPurchasesToReport = purchasesToReport;
                OneSignal.idsAvailable(new IdsAvailableHandler() {
                    public void idsAvailable(String userId, String registrationId) {
                        OneSignal.sendPurchases(finalPurchasesToReport, newAsExisting,
                                new OneSignalRestClient.ResponseHandler() {
                                    public void onFailure(int statusCode, JSONObject response,
                                            Throwable throwable) {
                                        OneSignal.Log(OneSignal.LOG_LEVEL.WARN,
                                                "HTTP sendPurchases failed to send.", throwable);
                                        isWaitingForPurchasesRequest = false;
                                    }

                                    public void onSuccess(String response) {
                                        purchaseTokens.addAll(newPurchaseTokens);
                                        prefsEditor.putString("purchaseTokens", purchaseTokens.toString());
                                        prefsEditor.remove("ExistingPurchases");
                                        prefsEditor.commit();
                                        newAsExisting = false;
                                        isWaitingForPurchasesRequest = false;
                                    }
                                });
                    }
                });

            }
        }
    } catch (Throwable t) {
        OneSignal.Log(OneSignal.LOG_LEVEL.WARN, "Failed to track IAP purchases", t);
    }
}