コード例 #1
1
  @Override
  public void onClick(View v) {
    SharedPreferences gameSettings = getSharedPreferences(GAME_SETTING_PREFS, 0);
    SharedPreferences.Editor editor = gameSettings.edit();

    if (v.getId() == R.id.playBtn) {
      Intent nextIntent;

      SharedPreferences gameState = getSharedPreferences(GameActivity.GAME_STATE_PREFS, 0);
      final int currLevel = gameState.getInt(GameActivity.STATE_LEVEL, 0);

      nextIntent = new Intent(this, GameActivity.class);
      MediaController.stopLoopingSound();

      // startNext intent
      startActivity(nextIntent);
    } else if (v.getId() == R.id.settings_btn) {
      RelativeLayout settingsWrap = (RelativeLayout) findViewById(R.id.other_settings_buttons_wrap);
      if (View.GONE == settingsWrap.getVisibility()) {
        settingsWrap.setVisibility(View.VISIBLE);
      } else {
        settingsWrap.setVisibility(View.GONE);
      }
    } else if (v.getId() == R.id.toggle_sound) {
      boolean soundEdit = gameSettings.getBoolean(SOUND_PREF, true);
      editor.putBoolean(SOUND_PREF, !soundEdit);
      editor.commit();

      if (soundEdit) {
        Toast.makeText(getApplicationContext(), "Sound is turned off", Toast.LENGTH_SHORT).show();
        MediaController.stopLoopingSound();
      } else {
        Toast.makeText(getApplicationContext(), "Sound is turned on", Toast.LENGTH_SHORT).show();
        MediaController.playSoundClip(this, R.raw.background_intro, true);
      }
    } else if (v.getId() == R.id.toggle_vibration) {
      boolean vibrateEdit = gameSettings.getBoolean(VIBRATE_PREF, true);
      editor.putBoolean(VIBRATE_PREF, !vibrateEdit);

      String vibrateState = (!vibrateEdit) ? "on" : "off";
      Toast.makeText(
              getApplicationContext(), "Vibration is turned " + vibrateState, Toast.LENGTH_SHORT)
          .show();
    } else if (v.getId() == R.id.show_credits) {
      new GameAlertDialogBuilder(this)
          .setTitle("Credits")
          .setMessage(this.getResources().getString(R.string.credits))
          .setPositiveButton(
              android.R.string.no,
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                  dialog.cancel();
                }
              })
          .show();
    }
    editor.commit();

    updateColorOfSettingsButtons();
  }
コード例 #2
0
  @Override
  public void onPause() {
    super.onPause();

    GameLoop.instance().stopLevelAndLoop();

    stars_creator.stopSpawningStars();

    adView.pause();
    MediaController.stopLoopingSound();
  }
コード例 #3
0
  @Override
  public void onResume() {
    super.onResume();

    GameLoop.instance().startLevelAndLoop(this, null);

    stars_creator.startSpawningStars();

    // set GameTextViews here, as the text may have updated since onCreate
    // (user plays game, gets new record, and goes back to mainActivity)
    SharedPreferences gameMeta = getSharedPreferences(MainActivity.GAME_META_DATA_PREFS, 0);
    GameTextView score = (GameTextView) findViewById(R.id.high_score);
    score.setText(formatInt(gameMeta.getInt(HIGHEST_SCORE, 0)));
    GameTextView days = (GameTextView) findViewById(R.id.max_day);
    days.setText(formatInt(gameMeta.getInt(MAX_LEVEL, 0)));

    adView.resume();
    MediaController.playSoundClip(this, R.raw.background_intro, true);
  }