@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_start: startActivity(new Intent(context, SpeedGameActivity.class)); break; case R.id.btn_shengyin: if (SPUtil.getObject(V_SP.SP_USER_Audio_Boolean, Boolean.class, false)) { AudioHandleUtils.getInstance().playMusic("mp3/bg.mp3", true); btn_shengyin.setImageResource(R.drawable.icon_audio_on); SPUtil.saveObject(V_SP.SP_USER_Audio_Boolean, false); AudioHandleUtils.getInstance().setAllEnable(true); } else { AudioHandleUtils.getInstance().stopMusic(); btn_shengyin.setImageResource(R.drawable.icon_audio_off); SPUtil.saveObject(V_SP.SP_USER_Audio_Boolean, true); AudioHandleUtils.getInstance().setAllEnable(false); } break; case R.id.btn_paihangbang: startActivity(new Intent(context, RanKingActivity.class)); break; case R.id.btn_continue: // 继续游戏 Intent intent = new Intent(context, SpeedGameActivity.class); intent.putExtra(SpeedGameActivity.INTENT_IS_NEW_GAME, false); startActivity(intent); break; } }
@Override protected void onResume() { super.onResume(); if (btn_continue != null) { SpeedGameEntity speedGame = SPUtil.getObject(V_SP.SP_SPEED_GAME_continue_ENTITY, SpeedGameEntity.class); if (speedGame != null) btn_continue.setVisibility(View.VISIBLE); else btn_continue.setVisibility(View.GONE); } }
private void initLayoutAndView() { layout_user = findViewById(R.id.layout_user); btn_shengyin = (ImageButton) findViewById(R.id.btn_shengyin); btn_author = (ImageButton) findViewById(R.id.btn_author); btn_paihangbang = (ImageButton) findViewById(R.id.btn_paihangbang); btn_shengyin.setOnClickListener(this); btn_author.setOnClickListener(this); btn_paihangbang.setOnClickListener(this); btn_start = (Button) findViewById(R.id.btn_start); btn_continue = (Button) findViewById(R.id.btn_continue); btn_start.setOnClickListener(this); btn_continue.setOnClickListener(this); // 是否登陆 if (!EmptyUtil.emptyOfString(HaisApp.USER.uid)) { Http.displayImageAutoSize((ImageView) findViewById(R.id.image_user_icon), HaisApp.USER.photo); ((TextView) findViewById(R.id.text_user_name)).setText(HaisApp.USER.name); ((TextView) findViewById(R.id.text_user_restall)) .setText( "极速:" + HaisApp.USER.speedGame.results + "\t\t闯关:" + HaisApp.USER.intrudesGame.results); } else { layout_user.setVisibility(View.GONE); } // 声音 if (!SPUtil.getObject(V_SP.SP_USER_Audio_Boolean, Boolean.class, false)) { AudioHandleUtils.getInstance().playMusic("mp3/bg.mp3", true); btn_shengyin.setImageResource(R.drawable.icon_audio_on); AudioHandleUtils.getInstance().setAllEnable(true); } // 判断是否继续游戏 SpeedGameEntity speedGame = SPUtil.getObject(V_SP.SP_SPEED_GAME_continue_ENTITY, SpeedGameEntity.class); if (speedGame != null) btn_continue.setVisibility(View.VISIBLE); }