Example #1
0
 @Override
 protected void onResume() {
   super.onResume();
   if (!readFromSavedInstance) {
     Log.d(TAMAGOTCHI, "Loading da tama");
     loadTamagotchi();
     initializePlayingfield();
   }
   if (tama != null) tama.UpdateText();
 }
Example #2
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.buttons = new ArrayList<Button>();

    setContentView(R.layout.main);

    SharedPreferences settings = this.getSharedPreferences(PREFNAME, 0);
    if (settings.contains("tama_name")) {
      tama = new Tamagotchi("");
      loadTamagotchi();
      tama.UpdateText();
    }
    button = (Button) findViewById(R.id.MyButton);
    output = (TextView) findViewById(R.id.OutputTextView);
    sua = new ShowUpdateAndroid(output, this);
    boolean isButtonEnabled = true;
    if (savedInstanceState != null) {
      // There is a state to restore
      output.setText(savedInstanceState.getString("outtext"));
      if (savedInstanceState.containsKey("tama_name")) {
        isButtonEnabled = false;
      }
      tama.restoreFromBundle(savedInstanceState);
      tama.setShowUpdater(sua);
      readFromSavedInstance = true;
    } else {
      loadTamagotchi();
      if (tama != null) tama.UpdateText();
    }
    button.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            tama = new Tamagotchi("Tama-chan");
            tama.setShowUpdater(sua);
            initializePlayingfield();
          }
        });

    Button b1 = ((Button) findViewById(R.id.EatAppleButton));
    b1.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            tama.EatFood(Tamagotchi.FoodItem.Apple);
          }
        });
    Button b2 = ((Button) findViewById(R.id.EatCandyButton));
    b2.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            tama.EatFood(Tamagotchi.FoodItem.Candy);
          }
        });
    Button b3 = ((Button) findViewById(R.id.EatMeatButton));
    b3.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            tama.EatFood(Tamagotchi.FoodItem.Meat);
          }
        });
    Button b4 = ((Button) findViewById(R.id.PoopButton));
    b4.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            tama.RemovePoop();
          }
        });
    Button b5 = ((Button) findViewById(R.id.PlayButton));
    b5.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            tama.PlayGame(Tamagotchi.Game.Simon);
          }
        });
    Button b6 = ((Button) findViewById(R.id.MedicineButton));
    b6.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            tama.GiveMedicine();
          }
        });
    buttons.add(b1);
    buttons.add(b2);
    buttons.add(b3);
    buttons.add(b4);
    buttons.add(b5);
    buttons.add(b6);
    for (Button b : buttons) b.setEnabled(!isButtonEnabled);
  }
Example #3
0
 private void loadTamagotchi() {
   SharedPreferences settings = this.getSharedPreferences(PREFNAME, 0);
   if (tama != null) tama.loadFromSharedPrefs(settings);
 }
Example #4
0
 private void saveTamagotchi() {
   SharedPreferences settings = this.getSharedPreferences(PREFNAME, 0);
   if (tama != null) tama.saveToSharedPrefs(settings);
 }
Example #5
0
 @Override
 public void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   if (tama != null) tama.updateBundle(outState);
   outState.putString("outtext", output.getText().toString());
 }
Example #6
0
 private void initializePlayingfield() {
   tama.setShowUpdater(sua);
   if (pi == null) setupAlarm();
   for (Button b : buttons) b.setEnabled(true);
   Log.d(TAMAGOTCHI, "Done initializeing the playing field");
 }