Android Open Source - Do-not-get-annoyed Start Activity






From Project

Back to project page Do-not-get-annoyed.

License

The source code is released under:

Apache License

If you think the Android project Do-not-get-annoyed listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package mn100013d.pmu;
/*from  w  w w  .j  av a  2s  .c  o m*/
import mn100013d.pmu.data.GameSettingsEditor;
import mn100013d.pmu.exceptions.PlayerNotRegisteredException;
import mn100013d.pmu.services.PopupService;
import mn100013d.pmu.services.SoundService;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.SeekBar;

public class StartActivity extends Activity {
  
  private ImageView newGame;
  private ImageView settings;
  private ImageView results;
  private PopupService newGamePopupService;
  private PopupService settingsPopupService;
  private GameSettingsEditor gsEditor;
  Boolean menu_shown = false;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start);
    
    newGame = (ImageView) findViewById(R.id.bt_new_game);
    results = (ImageView) findViewById(R.id.bt_results);
    settings = (ImageView) findViewById(R.id.bt_settings);
    
    gsEditor = new GameSettingsEditor(this);
    
    ImageView zombie = (ImageView) findViewById(R.id.image_zombie);
    Animation zombieMove = AnimationUtils.loadAnimation(this, R.anim.zombie_move_forward);
    zombie.startAnimation(zombieMove);
    
    
    try {
      SoundService.getInstance().setContext(this);
      SoundService.getInstance().instantiateService();
      SoundService.getInstance().play(SoundService.JINGLE, true);
    } catch (PlayerNotRegisteredException e) {
      e.printStackTrace();
    }
    newGamePopupService = new PopupService(PopupService.NEW_GAME, findViewById(R.id.main_layout), this) {
      
      @Override
      public void onHide() {
        menu_shown = false;
        newGame.setVisibility(View.VISIBLE);
        results.setVisibility(View.VISIBLE);
        settings.setVisibility(View.VISIBLE);
      }

      @Override
      public void onShow() {
        menu_shown = true;
        newGame.setVisibility(View.GONE);
        results.setVisibility(View.GONE);
        settings.setVisibility(View.GONE);

        ImageView singlePlayerButton = (ImageView) findViewById(R.id.bt_home);
        ImageView multiPlayerButton = (ImageView) findViewById(R.id.bt_settings1);
        singlePlayerButton.setOnClickListener(new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            try {
              SoundService.getInstance().play(SoundService.GAME_START, false).setOnCompletionListener(new OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                  Intent i = new Intent(getBaseContext(),
                      NewGameActivity.class);
                  startActivity(i);
                }
              });
            } catch (PlayerNotRegisteredException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }      
          }
        });
        
      }

      @Override
      public Boolean setHideOnOutsideClick() {
        return true;
      }
    };
    settingsPopupService = new PopupService(PopupService.SETTINGS, findViewById(R.id.main_layout), this) {
      
      @Override
      public Boolean setHideOnOutsideClick() {
        return true;
      }
      
      @Override
      public void onShow() {
        menu_shown = true;
        newGame.setVisibility(View.GONE);
        results.setVisibility(View.GONE);
        settings.setVisibility(View.GONE);
        ImageView save_settings = (ImageView)findViewById(R.id.bt_settings_save);
        final SeekBar music_volume = (SeekBar)findViewById(R.id.volume_level);
        final SeekBar sensitivity = (SeekBar)findViewById(R.id.sensitivity_level);
        music_volume.setProgress(gsEditor.getVolume());
        sensitivity.setProgress(gsEditor.getSensitivity());
        save_settings.setOnClickListener(new View.OnClickListener() {
          
          @Override
          public void onClick(View v) {
            
            gsEditor.setMusicVolume(music_volume.getProgress());
            gsEditor.setSensitivity(sensitivity.getProgress());
            Log.i("Nikola", "Sens "+sensitivity.getProgress()+ " "+gsEditor.getSensitivity());
            try {
              SoundService.getInstance().play(SoundService.CLICK_SOUND, false);
            } catch (PlayerNotRegisteredException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            settingsPopupService.hide();
          }
          
        });
      }
      
      @Override
      public void onHide() {
        menu_shown = false;
        newGame.setVisibility(View.VISIBLE);
        results.setVisibility(View.VISIBLE);
        settings.setVisibility(View.VISIBLE);
        
        
      }
    };
    
    newGame.setOnClickListener(new View.OnClickListener() {

      @Override 
      public void onClick(View v) {
        try {
          SoundService.getInstance().play(SoundService.CLICK_SOUND, false);
          newGamePopupService.show();
        } catch (PlayerNotRegisteredException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        
      }

    });
    results.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        try {
          SoundService.getInstance().play(SoundService.CLICK_SOUND, false);
        } catch (PlayerNotRegisteredException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

      }
    });
    settings.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        settingsPopupService.show();
        try {
          SoundService.getInstance().play(SoundService.CLICK_SOUND, false);
        } catch (PlayerNotRegisteredException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    });
    
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    return true;
  }

  @Override
  protected void onPause() {
    try {
      SoundService.getInstance().stop(SoundService.JINGLE);
    } catch (PlayerNotRegisteredException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    super.onPause();
  }

  @Override
  protected void onResume() {
    try {
      SoundService.getInstance().play(SoundService.JINGLE, true);
    } catch (PlayerNotRegisteredException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    super.onResume();
  }

}




Java Source Code List

mn100013d.pmu.BeginingActivity.java
mn100013d.pmu.GameTypeFragment.java
mn100013d.pmu.NewGameActivity.java
mn100013d.pmu.NewGameFragment.java
mn100013d.pmu.PauseFragment.java
mn100013d.pmu.PauseGameFragment.java
mn100013d.pmu.ScoresFragment.java
mn100013d.pmu.SettingsFragment.java
mn100013d.pmu.StartActivity.java
mn100013d.pmu.StartGameFragment.java
mn100013d.pmu.controllers.GameController.java
mn100013d.pmu.data.GameDataDbHelper.java
mn100013d.pmu.data.GameSettingsEditor.java
mn100013d.pmu.data.GameTableContract.java
mn100013d.pmu.exceptions.ContextNotSetException.java
mn100013d.pmu.exceptions.GameExceptions.java
mn100013d.pmu.exceptions.PlayerNotRegisteredException.java
mn100013d.pmu.models.Board.java
mn100013d.pmu.models.CPUGamePlayer.java
mn100013d.pmu.models.Color.java
mn100013d.pmu.models.Dice.java
mn100013d.pmu.models.Field.java
mn100013d.pmu.models.FinishField.java
mn100013d.pmu.models.GamePlayer.java
mn100013d.pmu.models.HomeField.java
mn100013d.pmu.models.HumanGamePlayer.java
mn100013d.pmu.models.PathField.java
mn100013d.pmu.models.Pawn.java
mn100013d.pmu.models.Result.java
mn100013d.pmu.services.FragmentProvider.java
mn100013d.pmu.services.GamePlayerFactory.java
mn100013d.pmu.services.PopupService.java
mn100013d.pmu.services.Randomizer.java
mn100013d.pmu.services.ShakeDetector.java
mn100013d.pmu.services.SoundService.java