Beispiel #1
0
  @Background
  void checkPremium() {
    // For in-app billing
    final String base64EncodedPublicKey =
        new StringBuilder("MIIBIjANBgkqhki")
            .append("G9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkNMrvFQmGKm5YoSD7UMCvKMvlEguAHVNCzEb")
            .append("Bww7T8iQHPr5H7Ltag03HLT4oToG1hDKsbEV7tks2tjwAm1ftzlud+gFMEG/GCL6G")
            .append("F+aisWKLJJZtpODRzidAAJVjlDaIROJBsnDnBQ2f8uoukSrXNaT42k/plIjhCiCdZ")
            .append("AmMb7Yb48v6aMvnB7FHXBffrkI2mpn4c8kSe721ROovZXNDw7/U94ZODKkOrnZGON")
            .append("rJ1isUwibFA3MhOfRdemE1aZF6KwCMD2EvgV8y9KVOPwF3lE0ucsJ4I56eEQpmzzR")
            .append("jItb/Gn8iHp0qa7IhSR/vXBL4p+byCcoQDlfvjeAmjY6dQIDAQAB")
            .toString();
    try {
      mBillingHelper = new IabHelper(this, base64EncodedPublicKey);
      // mBillingHelper.enableDebugLogging(true, "nononsenseapps billing");
      mBillingHelper.startSetup(
          new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
              if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d("nononsenseapps billing", "Problem setting up In-app Billing: " + result);
                return;
              }
              // Hooray, IAB is fully set up!
              mBillingHelper.queryInventoryAsync(mBillingInventoryListener);
            }
          });

      // See if the donate version is installed and offer to import if so
      isOldDonateVersionInstalled();
    } catch (Exception e) {
      Log.d("nononsenseapps billing", "InApp billing cant be allowed to crash app, EVER");
    }
  }
Beispiel #2
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   OrgSyncService.stop(this);
   try {
     if (mBillingHelper != null) mBillingHelper.dispose();
   } catch (Exception e) {
     // We are destroying, ignore all errors at this point
   }
   mBillingHelper = null;
 }
Beispiel #3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Pass the event to ActionBarDrawerToggle, if it returns
    // true, then it has handled the app icon touch event
    if (mDrawerToggle.onOptionsItemSelected(item)) {
      return true;
    }
    // Handle your other action bar items...
    int itemId = item.getItemId();
    if (itemId == android.R.id.home) {
      if (showingEditor) {
        // Only true in portrait mode
        final View focusView = ActivityMain.this.getCurrentFocus();
        if (inputManager != null && focusView != null) {
          inputManager.hideSoftInputFromWindow(
              focusView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }

        // Should load the same list again
        // Try getting the list from the original intent
        final long listId = getListId(getIntent());

        final Intent intent =
            new Intent()
                .setAction(Intent.ACTION_VIEW)
                .setClass(ActivityMain.this, ActivityMain_.class);
        if (listId > 0) {
          intent.setData(TaskList.getUri(listId));
        }

        // Set the intent before, so we set the correct
        // action bar
        setIntent(intent);
        while (getSupportFragmentManager().popBackStackImmediate()) {
          // Need to pop the entire stack and then load
        }

        reverseAnimation = true;
        Log.d("nononsenseapps fragment", "starting activity");

        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
      }
      // else
      // Handled by drawer
      return true;
    } else if (itemId == R.id.drawer_menu_createlist) {
      // Show fragment
      DialogEditList_ dialog = DialogEditList_.getInstance();
      dialog.setListener(
          new EditListDialogListener() {

            @Override
            public void onFinishEditDialog(long id) {
              openList(id);
            }
          });
      dialog.show(getSupportFragmentManager(), "fragment_create_list");
      return true;
    } else if (itemId == R.id.menu_preferences) {
      Intent intent = new Intent();
      intent.setClass(this, PrefsActivity.class);
      startActivity(intent);
      return true;
    } else if (itemId == R.id.menu_donate) {
      try {
        mBillingHelper.launchPurchaseFlow(
            this,
            SKU_INAPP_PREMIUM,
            SKU_DONATE_REQUEST_CODE,
            new IabHelper.OnIabPurchaseFinishedListener() {
              public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
                if (result.isFailure()) {
                  Log.d("nononsenseapps billing", "Error purchasing: " + result);
                  return;
                } else if (purchase.getSku().equals(SKU_INAPP_PREMIUM)) {
                  mHasPremiumAccess = true;
                  mDonatedInApp = true;
                  // Save in prefs
                  PreferenceManager.getDefaultSharedPreferences(ActivityMain.this)
                      .edit()
                      .putBoolean(SKU_INAPP_PREMIUM, true)
                      .putBoolean(PREMIUMSTATUS, true)
                      .commit();
                  // Update relevant parts of UI
                  updateUiDonate();
                  // Notify user of success
                  Toast.makeText(
                          ActivityMain.this,
                          R.string.premiums_unlocked_and_thanks,
                          Toast.LENGTH_SHORT)
                      .show();
                }
              }
            });
      } catch (Exception e) {
        Log.d("nononsenseapps billing", "Shouldnt start two purchases! " + e.getLocalizedMessage());
      }
      return true;
    } else if (itemId == R.id.menu_sync) {
      handleSyncRequest();
      return true;
    } else if (itemId == R.id.menu_delete) {
      return false;
    } else {
      return false;
    }
  }
Beispiel #4
0
 @OnActivityResult(SKU_DONATE_REQUEST_CODE)
 void onDonatePurchased(int resultCode, Intent data) {
   if (mBillingHelper != null)
     mBillingHelper.handleActivityResult(SKU_DONATE_REQUEST_CODE, resultCode, data);
 }