Android Open Source - Apocalypse-Defense Exit Confirmation Dialog






From Project

Back to project page Apocalypse-Defense.

License

The source code is released under:

MIT License

If you think the Android project Apocalypse-Defense 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 com.apocalypsedefense.app;
//from  w  w  w. ja v  a 2s  . c o  m
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class ExitConfirmationDialog extends Dialog {
  public ExitConfirmationDialog(Context context) {
    super(context);
  }

  @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.exit_game_dialog);
        
        //TODO: pause game (done in activity, but should it be?)
        
        final ExitConfirmationDialog dialog = this;
        
        // Continue game handler - dismisses dialog (and unpauses game?)
        View continueGame = findViewById(R.id.continue_game);
        continueGame.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        dialog.dismiss();
        // unpause game? No, that's a bad practice.
      }
    });
        
        // Main menu handler - go to main menu 
        View mainMenu = findViewById(R.id.main_menu_in_exit_dialog);
        mainMenu.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        // maybe manipulate the back stack so it doesn't take us back here
        dialog.dismiss();

        Activity ownerActivity = getOwnerActivity();
        Intent intent = new Intent(ownerActivity,
            ApocalypseDefenseActivity.class);
        // Clear back stack http://stackoverflow.com/questions/5794506/android-clear-the-back-stack#5794572
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Doesn't seem to be necessary
        ownerActivity.startActivity(intent);
      }
    });
        
        // Exit handler - exit app
        View exitApp = findViewById(R.id.exit_game);
        exitApp.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        dialog.dismiss();

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getOwnerActivity().startActivity(intent);
      }
    });
  }
}




Java Source Code List

com.apocalypsedefense.app.AchievementsActivity.java
com.apocalypsedefense.app.ApocalypseDefenseActivity.java
com.apocalypsedefense.app.EndOfGameDialog.java
com.apocalypsedefense.app.ExitConfirmationDialog.java
com.apocalypsedefense.app.InGameActivity.java
com.apocalypsedefense.app.InstructionsDialog.java
com.apocalypsedefense.app.NewGameSettingsActivity.java
com.apocalypsedefense.app.OverwriteExistingGameDialog.java
com.apocalypsedefense.app.gameplay_visuals.AndroidLogAdapter.java
com.apocalypsedefense.app.gameplay_visuals.GameFacade.java
com.apocalypsedefense.app.gameplay_visuals.GameObject.java
com.apocalypsedefense.app.gameplay_visuals.GameSurfaceView.java
com.apocalypsedefense.app.gameplay_visuals.GameThread.java
com.apocalypsedefense.app.gameplay_visuals.OnGameEndListener.java
com.apocalypsedefense.app.gameplay_visuals.OnStatsChangedListener.java
com.apocalypsedefense.app.gameplay_visuals.Sprite.java
com.apocalypsedefense.core.ActorType.java
com.apocalypsedefense.core.Armor.java
com.apocalypsedefense.core.GameData.java
com.apocalypsedefense.core.GameState.java
com.apocalypsedefense.core.Game.java
com.apocalypsedefense.core.Gun.java
com.apocalypsedefense.core.LogAdapter.java
com.apocalypsedefense.core.MapElement.java
com.apocalypsedefense.core.Map.java
com.apocalypsedefense.core.Movement.java
com.apocalypsedefense.core.Person.java
com.apocalypsedefense.core.Point.java
com.apocalypsedefense.core.PrintLogAdapter.java
com.apocalypsedefense.core.Shared.java
com.apocalypsedefense.core.SurvivorManager.java
com.apocalypsedefense.core.Survivor.java
com.apocalypsedefense.core.Weapon.java
com.apocalypsedefense.core.ZombieManager.java
com.apocalypsedefense.core.Zombie.java
com.apocalypsedefense.core.testDriver.java