Exemplo n.º 1
0
 @Override
 public void onBackPressed() {
   // TODO Auto-generated method stub
   if (wheelScrolled) {
     Log.e("SlotMachineActivity", "onBackPressed-wheelScrolled");
     Intent i = new Intent();
     if (spinned) {
       i.putExtra("is_used_free_spin", true);
       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", receive_free_ticket);
     }
     setResult(RESULT_OK, i);
     Log.e("receive_free_ticket on back pressed", receive_free_ticket + "");
     finish();
   }
 }
Exemplo n.º 2
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);
    }
  }