Пример #1
0
 @Override
 public void onRequestPurchaseResponse(RequestPurchase request, ResponseCode responseCode) {
   if (responseCode == ResponseCode.RESULT_OK) {
     UiUtils.showToast(getActivity(), "Donation request sent successfully");
   } else if (responseCode == ResponseCode.RESULT_USER_CANCELED) {
     UiUtils.showToast(getActivity(), "Donation request cancelled");
   } else {
     UiUtils.showToast(getActivity(), "Donation request failed");
   }
 }
Пример #2
0
 @Override
 public void onClick(View v) {
   String productId = (String) v.getTag();
   if (!mBillingService.requestPurchase(productId, null)) {
     UiUtils.showToast(getActivity(), "Google Play billing service is not supported");
   }
 }
Пример #3
0
 @Override
 public void onRestoreTransactionsResponse(
     RestoreTransactions request, ResponseCode responseCode) {
   Log.d("onRestoreTransactionsResponse", responseCode.toString());
   if (responseCode == ResponseCode.RESULT_OK) {
     // Update the shared preferences so that we don't perform
     // a RestoreTransactions again.
     SharedPreferences prefs = getActivity().getPreferences(Context.MODE_PRIVATE);
     SharedPreferences.Editor edit = prefs.edit();
     edit.putBoolean(DONATIONS_INITIALIZED, true);
     edit.commit();
     UiUtils.showToast(getActivity(), "Past donations restored successfully");
   } else {
     UiUtils.showToast(getActivity(), "Unable to restore donation transactions");
   }
   showDonationView(BILLING_AVAILABLE);
 }
Пример #4
0
 private boolean restoreDatabase() {
   SharedPreferences prefs = getActivity().getPreferences(MODE_PRIVATE);
   boolean initialized = prefs.getBoolean(DONATIONS_INITIALIZED, false);
   if (!initialized) {
     mBillingService.restoreTransactions();
     UiUtils.showToast(getActivity(), "Restoring past donation transactions");
   }
   return initialized;
 }
Пример #5
0
    protected void showDonationView(int status) {
      HashMap<String, Time> donations = new HashMap<String, Time>();
      if (mCursor.moveToFirst()) {
        do {
          String productId = mCursor.getString(mCursor.getColumnIndex(Donations.PRODUCT_ID));
          Time time = new Time();
          String purchaseTime = mCursor.getString(mCursor.getColumnIndex(Donations.PURCHASE_TIME));
          time.parse3339(purchaseTime);
          donations.put(productId, time);
        } while (mCursor.moveToNext());
      }

      TextView tv = (TextView) findViewById(R.id.donate_text);

      if (status == BILLING_CANNOT_CONNECT) {
        tv.setText(
            "ERROR:\nCannot connect to Google Play application. Your version of app"
                + " may be out of date. You can continue to use this app but certain"
                + " features may not be available.");
      } else if (status == BILLING_NOT_SUPPORTED) {
        tv.setText(
            "ERROR:\nGoogle Play in-app billing is not available this time. You can"
                + " continue to use this app but certain features may not be available.");
      } else if (status == BILLING_ERROR_RESTORE) {
        tv.setText(
            "ERROR:\nThere was an error trying to restore your past donations. This"
                + " could be a temporary failure. Please try again later.");
      } else {
        tv.setText(
            "Please consider donating to help me recover my costs to develop"
                + " the app and provide you with data updates. You may also choose not to"
                + " donate at all and that is fine too."
                + "\n\n"
                + "You will be redirected to Google Play checkout to allow you to securely"
                + " complete your payment transaction."
                + "\n\n"
                + "Please donate generously to show your appreciation.");

        tv = (TextView) findViewById(R.id.donate_level_label);
        LinearLayout layout = (LinearLayout) findViewById(R.id.donate_level_layout);
        layout.removeAllViews();

        int count = mDonationLevels.length - donations.size();
        for (int i = 0; i < mDonationLevels.length; ++i) {
          DonationLevel level = mDonationLevels[i];
          if (!donations.containsKey(level.productId)) {
            View row = addRow(layout, level.description, FormatUtils.formatCurrency(level.amount));
            row.setTag(level.productId);
            row.setOnClickListener(this);
            row.setBackgroundResource(UiUtils.getRowSelector(i, count));
          }
        }

        if (layout.getChildCount() > 0) {
          tv.setVisibility(View.VISIBLE);
          layout.setVisibility(View.VISIBLE);
        } else {
          tv.setVisibility(View.GONE);
          layout.setVisibility(View.GONE);
        }
      }

      tv = (TextView) findViewById(R.id.donate_text2);
      LinearLayout layout = (LinearLayout) findViewById(R.id.past_donations_layout);
      layout.removeAllViews();
      if (donations.isEmpty()) {
        Application.sDonationDone = false;
        addRow(layout, "No donations made yet");
        tv.setVisibility(View.GONE);
      } else {
        Application.sDonationDone = true;
        for (String productId : donations.keySet()) {
          Time time = donations.get(productId);
          DonationLevel level = getDonationLevel(productId);
          if (level != null) {
            addRow(
                layout,
                TimeUtils.formatDateTimeLocal(getActivity(), time.toMillis(true)),
                FormatUtils.formatCurrency(level.amount));
          }
        }

        tv.setText(
            "You can restore the above donations on your other devices by"
                + " simply visiting this screen on those devices.");
        tv.setVisibility(View.VISIBLE);
      }

      setContentShown(true);
    }