Android Open Source - minecraft-connect-4 Main Menu Activity






From Project

Back to project page minecraft-connect-4.

License

The source code is released under:

MIT License

If you think the Android project minecraft-connect-4 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

/* COPYRIGHT (C) 2014 Aleksandr Belkin. All Rights Reserved. */
package sq.squ1rr.mcc4;
/*from w w w. j a v  a 2 s  . c om*/
import java.util.ArrayList;

import sq.squ1rr.mcc4.layout.LayoutManager;
import sq.squ1rr.mcc4.util.GlobalConstants;
import android.os.Bundle;
import android.util.Log;

/**
 * Main application activity. The program will launch from here.
 * Displays menu from which user may choose what to do next.
 * Does not use XML layout.
 * @author Aleksandr Belkin
 */
public class MainMenuActivity extends BaseActivity {
    /** tag name for debug */
    private static final String TAG = MainMenuActivity.class.getName();
    
    /** Menu IDs */
    public enum MenuId {
        MAIN_MENU, QUICK_GAME, STATS, OPTIONS, ABOUT;
    }
    
    /** currently shown menu */
    private MenuId menuId = null;
    
    /** layout manager to manage the current layout */
    private LayoutManager layout;
    
    /** history of opened menus */
    private final ArrayList<MenuId> history = new ArrayList<MenuId>();

    /*
     * (non-Javadoc)
     * @see sq.squ1rr.mcc4.util.FullscreenActivity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        layout = new LayoutManager(this);
        showMenu(MenuId.MAIN_MENU, false);
    }
    
    /**
     * Shows selected menu
     * @param menuId
     */
    public void showMenu(MenuId menuId) {
        showMenu(menuId, true);
    }
    
    /**
     * Show menu if it's not the same already
     * @param menuId which menu
     */
    private void showMenu(MenuId _menuId, boolean save) {
        if(menuId == _menuId) return;
        else {
            if(save) history.add(menuId);
            menuId = _menuId;
        }

        switch(menuId) {
        case MAIN_MENU: layout.setLayout(new MainMenu(this)); break;
        case QUICK_GAME: layout.setLayout(new QuickGameMenu(this)); break;
        case STATS: layout.setLayout(new StatsMenu(this)); break;
        case OPTIONS: layout.setLayout(new OptionsMenu(this)); break;
        case ABOUT: layout.setLayout(new AboutMenu(this)); break;
        default:
            if(GlobalConstants.DEBUG) Log.wtf(TAG, "Undefined Menu ID");
            throw new RuntimeException("Undefined Menu ID");
        }
    }
    
    /**
     * Make this menu "first" in history
     */
    public void resetHistory() {
        history.clear();
    }
    
    /**
     * Refresh current layout
     */
    public void refresh() {
        layout.refresh();
    }
    
    /*
     * (non-Javadoc)
     * @see android.app.Activity#onBackPressed()
     */
    @Override
    public void onBackPressed() {
        if(history.size() > 0) {
            showMenu(history.get(history.size() - 1), false);
            history.remove(history.size() - 1);
        } else super.onBackPressed();
    }
}




Java Source Code List

sq.squ1rr.mcc4.AboutMenu.java
sq.squ1rr.mcc4.BaseActivity.java
sq.squ1rr.mcc4.GameActivity.java
sq.squ1rr.mcc4.MainMenuActivity.java
sq.squ1rr.mcc4.MainMenu.java
sq.squ1rr.mcc4.MenuLayout.java
sq.squ1rr.mcc4.OptionsMenu.java
sq.squ1rr.mcc4.QuickGameMenu.java
sq.squ1rr.mcc4.StatsMenu.java
sq.squ1rr.mcc4.Stats.java
sq.squ1rr.mcc4.ai.Ai.java
sq.squ1rr.mcc4.ai.EasyAi.java
sq.squ1rr.mcc4.ai.HardAi.java
sq.squ1rr.mcc4.ai.NormalAi.java
sq.squ1rr.mcc4.ai.PeacefulAi.java
sq.squ1rr.mcc4.board.BoardDialogue.java
sq.squ1rr.mcc4.board.BoardLogic.java
sq.squ1rr.mcc4.board.BoardRenderer.java
sq.squ1rr.mcc4.board.BoardView.java
sq.squ1rr.mcc4.board.GameBoard.java
sq.squ1rr.mcc4.board.Texture.java
sq.squ1rr.mcc4.gl.Rectangle.java
sq.squ1rr.mcc4.gl.SpriteBatch.java
sq.squ1rr.mcc4.gl.SpriteString.java
sq.squ1rr.mcc4.gl.Sprite.java
sq.squ1rr.mcc4.layout.LayoutManager.java
sq.squ1rr.mcc4.layout.McButton.java
sq.squ1rr.mcc4.layout.McGroup.java
sq.squ1rr.mcc4.layout.McSelector.java
sq.squ1rr.mcc4.layout.McStyle.java
sq.squ1rr.mcc4.layout.McText.java
sq.squ1rr.mcc4.layout.McToggler.java
sq.squ1rr.mcc4.layout.McToken.java
sq.squ1rr.mcc4.rules.GameRules.java
sq.squ1rr.mcc4.rules.Player.java
sq.squ1rr.mcc4.rules.Rule.java
sq.squ1rr.mcc4.util.GlobalConstants.java