Exemple #1
0
  private void setItemForEachWheel(WheelView wheel, int index) {

    wheel.setIndexOfWheel(index);
    int cycle = 0;
    while (cycle == 0) {
      cycle = (int) (Math.random() * 10);
    }
    wheel.setCycle(cycle);
  }
Exemple #2
0
 /**
  * Initializes wheel
  *
  * @param id the wheel widget Id
  */
 private WheelView initWheel(int id) {
   WheelView wheel = getWheel(id);
   wheel.setViewAdapter(new SlotMachineAdapter(this));
   wheel.addChangingListener(changedListener);
   wheel.addScrollingListener(scrolledListener);
   wheel.setCyclic(true);
   wheel.setEnabled(false);
   return wheel;
 }
Exemple #3
0
  /** Updates status */
  private void updateStatus() {
    // process if the wheels run separately
    if (!wheel1.isScrollingPerformed()
        && !wheel2.isScrollingPerformed()
        && wheel3.isScrollingPerformed()) {
      wheelScrolled = true;
      if (soundPool != null) {
        soundPool.stop(soundSpinning);
      }

      if (checkTheResult()) {
        if (soundPool != null) {
          if (receivedReward.getType().equalsIgnoreCase("OOS")) {
            soundPool.play(soundMissedGift, 0.99f, 0.99f, 0, 0, 1);
          } else {
            soundPool.play(soundWinning, 0.99f, 0.99f, 0, 0, 1);
          }
        }
        AlertDialog.Builder winDialog = new AlertDialog.Builder(SlotMachineActivity.this);
        LayoutInflater factory = LayoutInflater.from(this);
        final View view;
        LinearLayout giftListLayout;
        if (receivedReward.getGifts().size() == 0) {
          view = factory.inflate(R.layout.win_item_bg_layout, null);
          ImageView giftIcon = (ImageView) view.findViewById(R.id.giftIcon);

          if (receivedReward.getType().equalsIgnoreCase(REWARD.free_ticket.toString())) {
            receive_free_ticket = true;
            giftIcon.setImageResource(R.drawable.bonus_free_spin2x);
          } else if (receivedReward.getType().equalsIgnoreCase(REWARD.gold_ticket.toString())) {
            giftIcon.setImageResource(R.drawable.bonus_gold_ticket2x);
          } else if (receivedReward.getType().equalsIgnoreCase(REWARD.purple_tym.toString())) {
            giftIcon.setImageResource(R.drawable.reward_6_2x);
          } else if (receivedReward.getType().equalsIgnoreCase(REWARD.yellow_tym.toString())) {
            giftIcon.setImageResource(R.drawable.reward_5_2x);
          }
          if (receivedReward.getType().contains("card")) {
            RelativeLayout giftCodeLayOut = (RelativeLayout) view.findViewById(R.id.giftCodeLayOut);
            giftCodeLayOut.setVisibility(View.VISIBLE);
            TextView giftCode = (TextView) view.findViewById(R.id.giftCode);
            giftCode.setText(receivedReward.getCode());
            giftCode.setTextColor(Color.BLUE);
            final String msg = getResources().getString(R.string.copyCode);
            giftCode.setOnClickListener(
                new View.OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    // TODO Auto-generated method stub

                    ClipboardManager clipboard =
                        (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(receivedReward.getCode());
                    Toast info = Toast.makeText(getContext(), msg, Toast.LENGTH_LONG);
                    info.show();
                  }
                });
          }

        } else {
          view = factory.inflate(R.layout.win_items_bg_layout, null);
          giftListLayout = (LinearLayout) view.findViewById(R.id.giftListLayout);
          for (int i = 0; i < receivedReward.getGifts().size(); i++) {
            LinearLayout fLayout = new LinearLayout(SlotMachineActivity.this);
            fLayout.setLayoutParams(
                new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 1f));
            RelativeLayout rel = new RelativeLayout(SlotMachineActivity.this);
            RelativeLayout.LayoutParams rlp =
                new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            rel.setBackgroundResource(R.drawable.gift_bordert);
            rel.setLayoutParams(rlp);
            ImageView icon = new ImageView(SlotMachineActivity.this);
            icon.setImageResource(receivedReward.getGifts().get(i).getSrc());
            icon.setId(i);
            ImageView cardbg = new ImageView(SlotMachineActivity.this);
            cardbg.setImageResource(R.drawable.card_bg2x);
            rlp.addRule(RelativeLayout.BELOW, i);
            rlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
            rlp.addRule(RelativeLayout.CENTER_VERTICAL);
            TextView cardNo = new TextView(SlotMachineActivity.this);
            cardNo.setTextColor(Color.BLUE);
            cardNo.setText(receivedReward.getGifts().get(i).getValue() + "");
            cardbg.setLayoutParams(rlp);
            cardNo.setLayoutParams(rlp);
            rlp =
                new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            rlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
            rlp.addRule(RelativeLayout.CENTER_VERTICAL);
            icon.setLayoutParams(rlp);
            rel.addView(icon);
            if (receivedReward.getGifts().get(i).getType().contains("card")) {
              rel.addView(cardbg);
              rel.addView(cardNo);
            }
            TextView giftDescription = new TextView(SlotMachineActivity.this);
            if (receivedReward.getGifts().get(i).getType().equalsIgnoreCase("apple_giftcard")
                || receivedReward.getGifts().get(i).getType().equalsIgnoreCase("google_giftcard")
                || receivedReward.getGifts().get(i).getType().equalsIgnoreCase("viettel_phonecard")
                || receivedReward
                    .getGifts()
                    .get(i)
                    .getType()
                    .equalsIgnoreCase("vinaphone_phonecard")
                || receivedReward
                    .getGifts()
                    .get(i)
                    .getType()
                    .equalsIgnoreCase("mobifone_phonecard")) {
              giftDescription.setText(
                  receivedReward.getGifts().get(i).getType().replace('_', ' ')
                      + " : "
                      + receivedReward.getValue()
                      + ".");
            } else {
              giftDescription.setText(
                  receivedReward.getGifts().get(i).getValue()
                      + " "
                      + receivedReward.getGifts().get(i).getType().replace('_', ' '));
            }

            LinearLayout.LayoutParams linear =
                new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            giftDescription.setLayoutParams(linear);
            fLayout.setOrientation(LinearLayout.VERTICAL);
            fLayout.setGravity(Gravity.CENTER_HORIZONTAL);
            fLayout.addView(rel);
            fLayout.addView(giftDescription);
            giftListLayout.addView(fLayout);
          }
        }

        TextView giftDescription = (TextView) view.findViewById(R.id.giftDescription);

        Button continue_btn = (Button) view.findViewById(R.id.continueBtn);
        continue_btn.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                dialog.dismiss();
                Log.e("SlotMachineActivity", "onClick-Continue Btn");
                Intent i = new Intent();
                if (spinned) {
                  i.putExtra("is_used_free_spin", receive_free_ticket);
                  if (receivedReward != null) {
                    i.putExtra("new_purple_tym", receivedReward.getNew_purple_tym());
                    i.putExtra("new_green_tym", receivedReward.getNew_green_tym());
                    i.putExtra("new_yellow_tym", receivedReward.getNew_yellow_tym());
                  }
                } else {
                  i.putExtra("is_used_free_spin", false);
                }
                setResult(RESULT_OK, i);
                Log.e("receive_free_ticket", receive_free_ticket + "");
                finish();
              }
            });
        Button shareBtn = (Button) view.findViewById(R.id.sharebtn);
        shareBtn.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                progressDialog.setMessage(getResources().getString(R.string.sharing_on_facebook));
                progressDialog.show();
                final ArrayList<String> permis = new ArrayList<String>();
                final JSONObject pram = new JSONObject();
                try {
                  //							if(receivedReward.getGifts().size()>0)
                  //							{
                  //								String allGifts=receivedReward.getDescription()+"(";
                  //								for(int i=0;i<receivedReward.getGifts().size();i++)
                  //								{
                  //
                  //	if(receivedReward.getGifts().get(i).getType().equalsIgnoreCase("apple_giftcard")||receivedReward.getGifts().get(i).getType().equalsIgnoreCase("google_giftcard")||receivedReward.getGifts().get(i).getType().equalsIgnoreCase("viettel_phonecard")||receivedReward.getGifts().get(i).getType().equalsIgnoreCase("vinaphone_phonecard")||receivedReward.getGifts().get(i).getType().equalsIgnoreCase("mobifone_phonecard"))
                  //									{
                  //										allGifts+=receivedReward.getGifts()
                  //												.get(i).getType().replace('_', ' ')+" : "+receivedReward.getValue()
                  // +".";
                  //									}else
                  //									{
                  //										allGifts+=receivedReward.getGifts()
                  //												.get(i).getValue() +" "+ receivedReward.getGifts()
                  //												.get(i).getType().replace('_', ' ');
                  //									}
                  //								}
                  //								allGifts+=")";
                  //								pram.put("message", allGifts);
                  //							}else
                  //							{
                  //								pram.put("message", receivedReward.getDescription());
                  //							}
                  pram.put("message", receivedReward.getDescription());
                  pram.put(
                      "link", "https://play.google.com/store/apps/details?id=com.appstoregp.vn");
                } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }

                permis.add("publish_actions");
                permis.add("publish_stream");
                if (Session.getActiveSession() == null || Session.getActiveSession().isClosed()) {
                  Log.e(
                      "openActiveSession because it is null or is closed",
                      "openActiveSession because it is null or is closed");
                  Session.openActiveSession(
                      SlotMachineActivity.this,
                      true,
                      new Session.StatusCallback() {

                        @Override
                        public void call(Session session, SessionState state, Exception exception) {
                          // TODO Auto-generated method stub
                          if (exception == null) {
                            if (!session.getPermissions().contains("publish_actions")
                                || !session.getPermissions().contains("publish_stream")) {
                              try {
                                session.requestNewPublishPermissions(
                                    new Session.NewPermissionsRequest(
                                        SlotMachineActivity.this, permis));
                                Log.e("REQUESTPUBLISHpermission", "REQUESTPUBLISHpermission");
                                Toast.makeText(
                                        SlotMachineActivity.this,
                                        getResources()
                                            .getString(R.string.getting_permission_at_first),
                                        Toast.LENGTH_LONG)
                                    .show();
                              } catch (Exception e) {
                                // TODO: handle exception
                                e.printStackTrace();
                              }
                              Log.e("REQUESTPUBLISHpermission2", "REQUESTPUBLISHpermission2");
                              return;
                            }
                            Request a =
                                Request.newPostRequest(
                                    Session.getActiveSession(),
                                    "/me/feed",
                                    GraphObject.Factory.create(pram),
                                    new Request.Callback() {
                                      @Override
                                      public void onCompleted(Response response) {
                                        showPublishOnWallResult(
                                            response.getGraphObject(), response.getError());
                                      }
                                    });
                            a.executeAsync();
                          }
                        }
                      });

                } else {
                  //				        	session.requestNewPublishPermissions(new
                  // Session.NewPermissionsRequest(
                  //									SlotMachineActivity.this, permis));
                  Request a =
                      Request.newPostRequest(
                          Session.getActiveSession(),
                          "/me/feed",
                          GraphObject.Factory.create(pram),
                          new Request.Callback() {
                            @Override
                            public void onCompleted(Response response) {
                              showPublishOnWallResult(
                                  response.getGraphObject(), response.getError());
                            }
                          });
                  a.executeAsync();
                }
              }
            });
        if (receivedReward.getGifts().size() == 0
            && !receivedReward.getType().contains("card")
            && !receivedReward.getType().equalsIgnoreCase("OOS")) {
          String tym_type = "";
          if (receivedReward.getType().replace('_', ' ').contains("purple")) {
            tym_type = getResources().getString(R.string.tym_purple);
          } else if (receivedReward.getType().replace('_', ' ').contains("green")) {
            tym_type = getResources().getString(R.string.tym_purple);
          } else if (receivedReward.getType().replace('_', ' ').contains("yellow")) {
            tym_type = getResources().getString(R.string.tym_yellow);
          }
          giftDescription.setText(receivedReward.getValue() + " " + tym_type);
        } else if (receivedReward.getGifts().size() == 0
            && receivedReward.getType().contains("card")) {

          giftDescription.setText(
              receivedReward.getDescription() + " " + receivedReward.getValue());
        } else if (receivedReward.getType().equalsIgnoreCase("OOS")) {
          giftDescription.setText(getResources().getString(R.string.oos));
          RelativeLayout forOOS = (RelativeLayout) view.findViewById(R.id.forOOS);
          forOOS.setVisibility(View.GONE);
          shareBtn.setEnabled(false);
        }
        //				view.setBackgroundColor(android.graphics.Color.TRANSPARENT);
        winDialog.setView(view);
        dialog = winDialog.create();
        //				dialog.getWindow().setBackgroundDrawable(new
        // ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.setCancelable(false);
        dialog.show();
      } else {
        AlertDialog.Builder info = new AlertDialog.Builder(SlotMachineActivity.this);
        info.setTitle(getResources().getString(R.string.message_title_dialog));
        info.setMessage(getResources().getString(R.string.message_not_win));
        info.setPositiveButton(
            getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface arg0, int arg1) {}
            });
        info.show();
      }
    }
    if (!_onPause) {
      soundPool.play(soundEndOfSpinning, 0.99f, 0.99f, 0, 0, 1);
    }
  }
Exemple #4
0
  protected void spin() {
    if (willbeRecievedReward) {
      // reset wheels
      wheel1.setCurrentItem(0, false);
      wheel2.setCurrentItem(0, false);
      wheel3.setCurrentItem(0, false);
      // Temporary take random index
      Random random = new Random();
      indexOfReward = random.nextInt(8);
      setItemForEachWheel(wheel1, indexOfReward);
      setItemForEachWheel(wheel2, indexOfReward);
      setItemForEachWheel(wheel3, indexOfReward);
      // index of item/reward
      // check what item will be the rewarded item
      if (indexOfReward == 0) {
        wheel1.scroll(-30000 * wheel1.getCycle(), 3000);
        wheel2.scroll(-30000 * wheel2.getCycle(), 4500);
        wheel3.scroll(-30000 * wheel3.getCycle(), 6000);
        Log.e("Item", "Bi' mat");
      } else if (indexOfReward == 1) {
        wheel1.scroll(-30000 * wheel1.getCycle() + 1, 3000);
        wheel2.scroll(-30000 * wheel2.getCycle() + 1, 4500);
        wheel3.scroll(-30000 * wheel3.getCycle() + 1, 6000);
        Log.e("Item", "Mario");
      } else if (indexOfReward == 2) {
        wheel1.scroll(-30000 * wheel1.getCycle() + 2, 3000);
        wheel2.scroll(-30000 * wheel2.getCycle() + 2, 4500);
        wheel3.scroll(-30000 * wheel3.getCycle() + 2, 6000);
        Log.e("Item", "Tao Do");
      } else if (indexOfReward == 3) {
        wheel1.scroll(-30000 * wheel1.getCycle() + 3, 3000);
        wheel2.scroll(-30000 * wheel2.getCycle() + 3, 4500);
        wheel3.scroll(-30000 * wheel3.getCycle() + 3, 6000);
        Log.e("Item", "Tim Do");
      } else if (indexOfReward == 4) {
        wheel1.scroll(-30000 * wheel1.getCycle() + 4, 3000);
        wheel2.scroll(-30000 * wheel2.getCycle() + 4, 4500);
        wheel3.scroll(-30000 * wheel3.getCycle() + 4, 6000);
        Log.e("Item", "Tim Vang");
      } else if (indexOfReward == 5) {
        wheel1.scroll(-30000 * wheel1.getCycle() + 5, 3000);
        wheel2.scroll(-30000 * wheel2.getCycle() + 5, 4500);
        wheel3.scroll(-30000 * wheel3.getCycle() + 5, 6000);
        Log.e("Item", "Tim Tim");
      } else if (indexOfReward == 6) {
        wheel1.scroll(-30000 * wheel1.getCycle() + 6, 3000);
        wheel2.scroll(-30000 * wheel2.getCycle() + 6, 4500);
        wheel3.scroll(-30000 * wheel3.getCycle() + 6, 6000);
        Log.e("Item", "Tim xanh");
      } else {
        wheel1.scroll(-30000 * wheel1.getCycle() + 7, 3000);
        wheel2.scroll(-30000 * wheel2.getCycle() + 7, 4500);
        wheel3.scroll(-30000 * wheel3.getCycle() + 7, 6000);
        Log.e("Item", "Hop Qua");
      }
    } else {
      int distance1 = -6000 + (int) (Math.random() * 50);
      int distance2 = -6000 + (int) (Math.random() * 50);
      int distance3 = -6000 + (int) (Math.random() * 50);
      Log.d("distance 1 :", "" + distance1 + " %3 : " + distance1 % 3);
      Log.d("distance 2 :", "" + distance2 + " %3 : " + distance2 % 3);
      Log.d("distance 3 :", "" + distance3 + " %3 : " + distance3 % 3);

      if (distance1 % 3 == distance2 % 3 && distance1 % 3 == distance3 % 3) {
        Log.d("An Exception", "Exception has been processed");
        while (distance3 % 3 == distance1 % 3) {
          distance3 = -600 + (int) (Math.random() * 50);
        }
        Log.d("distance 3 re-assigned to :", "" + distance3 + " %3 : " + distance3 % 3);
      }
      wheel1.scroll(distance1, 3000);
      wheel2.scroll(distance2, 4500);
      wheel3.scroll(distance3, 6000);
    }
    soundPool.play(soundSpinning, 0.99f, 0.99f, 0, -1, 1);
  }