コード例 #1
0
 protected void onResume() {
   super.onResume();
   numberOfStars = Wallet.getCredits(this);
 }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_unlock_south_america_flags);

    SharedPreferences preferencesStars = getSharedPreferences("TOTALSTARS", Context.MODE_PRIVATE);
    final SharedPreferences.Editor editorStars = preferencesStars.edit();

    preferences2 = getSharedPreferences("CUSTOMLIST", Context.MODE_PRIVATE);

    southAmericaUnlocked = preferences2.getInt("SOUTHAMERICAUNLOCKED", 0);

    numberOfStars = preferencesStars.getInt("TOTALSTARS", 0);

    booleanFor10 = preferences2.getBoolean("BOOLEANFOR10", true);
    if (booleanFor10) {
      numberOfStars = numberOfStars + preferences2.getInt("TOTALSTARS1", 0);
      SharedPreferences.Editor editor = preferences2.edit();
      editor.putBoolean("BOOLEANFOR10", false);
      editor.commit();
    }

    booleanFor25 = preferences2.getBoolean("BOOLEANFOR25", true);
    if (booleanFor25) {
      numberOfStars = numberOfStars + preferences2.getInt("TOTALSTARS2", 0);
      SharedPreferences.Editor editor = preferences2.edit();
      editor.putBoolean("BOOLEANFOR25", false);
      editor.commit();
    }

    Toast toast =
        Toast.makeText(
            UnlockSouthAmericaFlagsActivity.this,
            "Scroll down to unlock new flags",
            Toast.LENGTH_SHORT);
    toast.show();

    // unlocked countries
    unlockedFlagImageId.add(0, R.drawable.argentina);
    unlockedFlagImageId.add(1, R.drawable.brazil);
    unlockedFlagImageId.add(2, R.drawable.colombia);
    // locked countries
    unlockedFlagImageId.add(3, R.drawable.bolivia);
    unlockedFlagImageId.add(4, R.drawable.chile);
    unlockedFlagImageId.add(5, R.drawable.ecuador);
    unlockedFlagImageId.add(6, R.drawable.guyana);
    unlockedFlagImageId.add(7, R.drawable.paraguay);
    unlockedFlagImageId.add(8, R.drawable.peru);
    unlockedFlagImageId.add(9, R.drawable.uruguay);
    unlockedFlagImageId.add(10, R.drawable.venezuela);
    unlockedFlagImageId.add(11, R.drawable.questionmark);

    // unlocked countries
    countryNames.add(0, "Argentina");
    countryNames.add(1, "Brazil");
    countryNames.add(2, "Colombia");
    // locked countries
    countryNames.add(3, "Bolivia");
    countryNames.add(4, "Chile");
    countryNames.add(5, "Ecuador");
    countryNames.add(6, "Guyana");
    countryNames.add(7, "Paraguay");
    countryNames.add(8, "Peru");
    countryNames.add(9, "Uruguay");
    countryNames.add(10, "Venezuela");

    setWeb();

    SharedPreferences.Editor editor = preferences2.edit();
    editor.putInt("SOUTHAMERICAUNLOCKED", southAmericaUnlocked);
    editor.commit();
    if (southAmericaUnlocked == 8) {
      southAmericaCleared = true;
      editor.putBoolean("SOUTHAMERICACLEAREDBOOLEAN", southAmericaCleared);
      editor.commit();
    }

    adapter = new SouthAmericaCustomList(UnlockSouthAmericaFlagsActivity.this, web, flagImageId);
    list = (ListView) findViewById(R.id.southAmericaList);
    list.setAdapter(adapter);

    list.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(
              AdapterView<?> parent, final View view, final int position, long id) {

            final SharedPreferences preferences =
                getSharedPreferences("CUSTOMLIST", Context.MODE_PRIVATE);
            final SharedPreferences.Editor editor = preferences.edit();

            DialogInterface.OnClickListener dialogClickListener =
                new DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                      case DialogInterface.BUTTON_POSITIVE:
                        if ((((position + 1) * 2) - 6) <= numberOfStars) {

                          editor.putInt("FLAG" + position, flagImageId.get(position));
                          editor.putBoolean("SOUTHAMERICABOOLEAN" + position, false);
                          editor.commit();

                          adapter.clear();

                          setWeb();
                          SharedPreferences.Editor editor = preferences2.edit();
                          editor.putInt("SOUTHAMERICAUNLOCKED", southAmericaUnlocked);
                          editor.commit();
                          if (southAmericaUnlocked == 8) {
                            southAmericaCleared = true;
                            editor.putBoolean("SOUTHAMERICACLEAREDBOOLEAN", southAmericaCleared);
                            editor.commit();
                          }
                          numberOfStars = numberOfStars - (((position + 1) * 2) - 6);
                          editorStars.putInt("TOTALSTARS", numberOfStars);
                          editorStars.commit();

                          Toast toast =
                              Toast.makeText(
                                  UnlockSouthAmericaFlagsActivity.this,
                                  "You unlocked "
                                      + countryNames.get(position)
                                      + ". You have "
                                      + numberOfStars
                                      + " stars left!",
                                  Toast.LENGTH_SHORT);
                          toast.show();

                        } else {

                          DialogInterface.OnClickListener dialogClickListener =
                              new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                  switch (which) {
                                    case DialogInterface.BUTTON_POSITIVE:
                                      PaymentRequest.PaymentRequestBuilder builder =
                                          new PaymentRequest.PaymentRequestBuilder();
                                      builder.setService(
                                          "b95c10b4e3bdf5d12ed7cc2741db5656",
                                          "3769b7c1775ca856e1927fdc026a442f");
                                      builder.setDisplayString("Stars"); // shown on user receipt
                                      builder.setProductName(
                                          "Stars"); // non-consumable purchases are restored using
                                                    // this value
                                      builder.setType(
                                          MpUtils
                                              .PRODUCT_TYPE_CONSUMABLE); // non-consumable items can
                                                                         // be later restored
                                      builder.setIcon(R.drawable.ic_launcher);
                                      PaymentRequest pr = builder.build();
                                      makePayment(pr);

                                    case DialogInterface.BUTTON_NEGATIVE:
                                      break;
                                  }
                                }
                              };
                          AlertDialog.Builder builder =
                              new AlertDialog.Builder(UnlockSouthAmericaFlagsActivity.this);
                          builder
                              .setMessage("You don't have enough stars. Do you want to buy more?")
                              .setPositiveButton("Yes", dialogClickListener)
                              .setNegativeButton("No", dialogClickListener)
                              .show();
                        }
                      case DialogInterface.BUTTON_NEGATIVE:
                        // No button clicked
                        break;
                    }
                  }
                };

            AlertDialog.Builder builder =
                new AlertDialog.Builder(UnlockSouthAmericaFlagsActivity.this);
            builder
                .setMessage(
                    "Are you sure you want to spend "
                        + (((position + 1) * 2) - 6)
                        + " stars to unlock new flag?")
                .setPositiveButton("Yes", dialogClickListener)
                .setNegativeButton("No", dialogClickListener)
                .show();
          }
        });
  }
コード例 #3
0
 @Override
 protected void onPause() {
   super.onPause();
 }