Android Open Source - it.alcacoop.fourinaline Purchase Activity






From Project

Back to project page it.alcacoop.fourinaline.

License

The source code is released under:

GNU General Public License

If you think the Android project it.alcacoop.fourinaline listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package it.alcacoop.fourinaline;
/*from  w w  w  .j  a v a 2s.co  m*/
import it.alcacoop.fourinaline.billingutils.IabHelper;
import it.alcacoop.fourinaline.billingutils.IabResult;
import it.alcacoop.fourinaline.billingutils.Purchase;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;


public class PurchaseActivity extends Activity {


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.purchase_activity);
  }


  private void purchase(String sku) {
    IabHelper h = PrivateDataManager.getHelper();
    int ret = h.launchPurchaseFlow(this, sku, PrivateDataManager.RC_REQUEST, mPurchaseFinishedListener, PrivateDataManager.verifyCode);
    if (ret == 0) {
      System.out.println("BILLING: RET=" + ret);
      _toast("Application error: transaction not completed");
      this.setResult(10000);
      finish();
    }
  }


  // User clicked the "Upgrade to Premium" button.
  public void onUpgradeClicked(View v) {
    purchase(PrivateDataManager.SKU_NOADS);
  }


  // User clicked the "Upgrade to Premium" button.
  public void onDonateClicked(View v) {
    purchase(PrivateDataManager.SKU_DONATE);
  }


  // Callback for when a purchase is finished
  IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
      if (result.isFailure()) {
        // toast("An error occurred: " + result);
        return;
      }
      if (!PrivateDataManager.verifyDeveloperPayload(purchase)) {
        // toast("Error purchasing. Authenticity verification failed.");
        return;
      }
      // Log.d(TAG, "Purchase successful.");
      if (purchase.getSku().equals(PrivateDataManager.SKU_NOADS)) {
        alert("Your request has been successfully processed and Ads will be removed.\n\nThanks for your purchase!");
        PrivateDataManager.msIsPremium = true;
      }
      if (purchase.getSku().equals(PrivateDataManager.SKU_DONATE)) {
        alert("Your request has been successfully processed and Ads will be removed.\n\nThanks for your donation!");
        PrivateDataManager.msIsPremium = true;
      }
    }
  };


  private void alert(String message) {
    AlertDialog.Builder bld = new AlertDialog.Builder(this);
    bld.setMessage(message);
    bld.setNeutralButton("OK", new OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        finish();
      }
    });
    bld.create().show();
  }


  private void _toast(String message) {
    Toast t = Toast.makeText(this, message, Toast.LENGTH_LONG);
    t.show();
  }


  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (!PrivateDataManager.getHelper().handleActivityResult(requestCode, resultCode, data)) {
      super.onActivityResult(requestCode, resultCode, data);
    }
  }

}




Java Source Code List

android.UnusedStub.java
it.alcacoop.fourinaline.BaseGServiceApplication.java
it.alcacoop.fourinaline.FourInALineDesktop.java
it.alcacoop.fourinaline.FourInALine.java
it.alcacoop.fourinaline.GServiceApplication.java
it.alcacoop.fourinaline.GServiceInterface.java
it.alcacoop.fourinaline.MainActivity.java
it.alcacoop.fourinaline.NativeFunctions.java
it.alcacoop.fourinaline.PrivateDataManager.java
it.alcacoop.fourinaline.PurchaseActivity.java
it.alcacoop.fourinaline.SoundManager.java
it.alcacoop.fourinaline.actors.BoardImage.java
it.alcacoop.fourinaline.actors.Board.java
it.alcacoop.fourinaline.actors.ChatBox.java
it.alcacoop.fourinaline.actors.Checker.java
it.alcacoop.fourinaline.actors.FixedButtonGroup.java
it.alcacoop.fourinaline.actors.IconButton.java
it.alcacoop.fourinaline.actors.ParticleEffectActor.java
it.alcacoop.fourinaline.actors.PlayerBlock.java
it.alcacoop.fourinaline.actors.UIDialog.java
it.alcacoop.fourinaline.billingutils.Base64DecoderException.java
it.alcacoop.fourinaline.billingutils.Base64.java
it.alcacoop.fourinaline.billingutils.IabException.java
it.alcacoop.fourinaline.billingutils.IabHelper.java
it.alcacoop.fourinaline.billingutils.IabResult.java
it.alcacoop.fourinaline.billingutils.Inventory.java
it.alcacoop.fourinaline.billingutils.Purchase.java
it.alcacoop.fourinaline.billingutils.Security.java
it.alcacoop.fourinaline.billingutils.SkuDetails.java
it.alcacoop.fourinaline.client.GwtLauncher.java
it.alcacoop.fourinaline.fsm.FSM.java
it.alcacoop.fourinaline.gservice.GServiceClient.java
it.alcacoop.fourinaline.gservice.GServiceCookieMonster.java
it.alcacoop.fourinaline.gservice.GServiceMessages.java
it.alcacoop.fourinaline.gservice.GServiceNetHandler.java
it.alcacoop.fourinaline.layers.BaseScreen.java
it.alcacoop.fourinaline.layers.GameScreen.java
it.alcacoop.fourinaline.layers.MatchOptionsScreen.java
it.alcacoop.fourinaline.layers.MenuScreen.java
it.alcacoop.fourinaline.layers.OptionsScreen.java
it.alcacoop.fourinaline.layers.SplashScreen.java
it.alcacoop.fourinaline.logic.AIExecutor.java
it.alcacoop.fourinaline.logic.MatchState.java
it.alcacoop.fourinaline.util.Base64DecoderException.java
it.alcacoop.fourinaline.util.Base64.java
it.alcacoop.fourinaline.util.GServiceGameHelper.java
it.alcacoop.fourinaline.util.GameHelperUtils.java
it.alcacoop.fourinaline.utils.AchievementsManager.java
it.alcacoop.fourinaline.utils.AppDataManager.java
it.alcacoop.fourinaline.utils.ELORatingManager.java
org.gojul.fourinaline.model.AlphaBeta.java
org.gojul.fourinaline.model.DefaultEvalScore.java
org.gojul.fourinaline.model.EvalScore.java
org.gojul.fourinaline.model.GameModel.java