Android Open Source - Droid-Maze Main Menu Activity






From Project

Back to project page Droid-Maze.

License

The source code is released under:

Apache License

If you think the Android project Droid-Maze 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 2011 Massimo Gaddini//  w w w .j av  a 2 s. co m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.  
 */
package com.sgxmobileapps.droidmaze.ui;


import android.util.DisplayMetrics;

import com.sgxmobileapps.droidmaze.ui.animator.MultiSlideMenuAnimator;
import com.sgxmobileapps.droidmaze.util.ActivityUtils;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.scene.menu.MenuScene;
import org.anddev.andengine.entity.scene.menu.item.IMenuItem;
import org.anddev.andengine.entity.scene.menu.item.SpriteMenuItem;
import org.anddev.andengine.entity.scene.menu.item.decorator.ScaleMenuItemDecorator;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import org.anddev.andengine.util.Debug;
import org.anddev.andengine.util.modifier.ease.EaseBackOut;

import javax.microedition.khronos.opengles.GL10;


/**
 * @author Massimo Gaddini
 *
 */
public class MainMenuActivity extends BaseGameActivity implements MenuScene.IOnMenuItemClickListener {
    
    protected static final int MENU_START = 0;
    protected static final int MENU_QUIT = MENU_START + 1;

    protected Camera camera;
    protected BitmapTextureAtlas mMenuTexture;
    protected TextureRegion mMenuStartTextureRegion;
    protected TextureRegion mMenuQuitTextureRegion;
//    protected TextureRegion mBackgroundTextureRegion;
    
    /* 
     * @see org.anddev.andengine.ui.IGameInterface#onLoadEngine()
     */
    @Override
    public Engine onLoadEngine() {
        Debug.setDebugTag("MainMenuActivity");
        
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);

        int cameraWidth = dm.widthPixels;
        int cameraHeight = dm.heightPixels;
        
        camera = new Camera(0, 0, cameraWidth, cameraHeight);
        return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT,
                new RatioResolutionPolicy(cameraWidth, cameraHeight), camera));
    }

    /* (non-Javadoc)
     * @see org.anddev.andengine.ui.IGameInterface#onLoadComplete()
     */
    @Override
    public void onLoadComplete() {
    }

    /* (non-Javadoc)
     * @see org.anddev.andengine.ui.IGameInterface#onLoadResources()
     */
    @Override
    public void onLoadResources() {
        mMenuTexture = new BitmapTextureAtlas(256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        mMenuStartTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuTexture, this, "gfx/menu_start.png", 0, 0);
        mMenuQuitTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuTexture, this, "gfx/menu_exit.png", 0, 50);
        mEngine.getTextureManager().loadTexture(mMenuTexture);
        
//        ITextureSource textureSource = new AssetTextureSource(this, "gfx/menu_background.jpg");
//        final Texture backgroundTexture = TextureFactory.createForTextureSourceSize(textureSource, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
//        mBackgroundTextureRegion = TextureRegionFactory.createFromSource(backgroundTexture, textureSource, 0, 0);
//        mEngine.getTextureManager().loadTexture(backgroundTexture);
    }

    /* (non-Javadoc)
     * @see org.anddev.andengine.ui.IGameInterface#onLoadScene()
     */
    @Override
    public Scene onLoadScene() {
        MenuScene menuScene = new MenuScene(camera);
        
        IMenuItem startMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_START, mMenuStartTextureRegion), (float) 1.2, 1);
        startMenuItem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
        menuScene.addMenuItem(startMenuItem);

        IMenuItem quitMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_QUIT, mMenuQuitTextureRegion), (float) 1.2, 1);
        quitMenuItem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
        menuScene.addMenuItem(quitMenuItem);
        
//        Sprite backgroundSprite = new Sprite(getCamera().getMinX(), getCamera().getMinY(), getCamera().getWidth(), getCamera().getHeight(), mBackgroundTextureRegion);
//        menuScene.setBackground(new SpriteBackground(backgroundSprite));
        
        MultiSlideMenuAnimator menuAnimator = new MultiSlideMenuAnimator(20, EaseBackOut.getInstance());
        menuAnimator.setDuration(2);
        menuScene.setMenuAnimator(menuAnimator);
        menuScene.buildAnimations();

        menuScene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
        menuScene.setOnMenuItemClickListener(this);
        
        return menuScene;
    }

    /* (non-Javadoc)
     * @see org.anddev.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener#onMenuItemClicked(org.anddev.andengine.entity.scene.menu.MenuScene, org.anddev.andengine.entity.scene.menu.item.IMenuItem, float, float)
     */
    @Override
    public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem,
            float pMenuItemLocalX, float pMenuItemLocalY) {
        
        switch(pMenuItem.getID()) {
        case MENU_START:
            Debug.i("Pressed Start menu");
            ActivityUtils.launchActivity(this, MazeActivity.class);
            return true;
        case MENU_QUIT:        
            finish();
            return true;
        default:
            return false;
        }
    }
}




Java Source Code List

com.sgxmobileapps.droidmaze.datastore.DroidMazeDbAdapter.java
com.sgxmobileapps.droidmaze.datastore.DroidMazeDbMetadata.java
com.sgxmobileapps.droidmaze.game.GameLevelManager.java
com.sgxmobileapps.droidmaze.game.model.GamePlayerProfile.java
com.sgxmobileapps.droidmaze.maze.generator.BacktrackingMazeGenerator.java
com.sgxmobileapps.droidmaze.maze.generator.IterativeBacktrackingMazeGenerator.java
com.sgxmobileapps.droidmaze.maze.generator.KruskalMazeGenerator.java
com.sgxmobileapps.droidmaze.maze.generator.MazeCell.java
com.sgxmobileapps.droidmaze.maze.generator.MazeGenerator.java
com.sgxmobileapps.droidmaze.maze.generator.PrimMazeGenerator.java
com.sgxmobileapps.droidmaze.ui.MainMenuActivity.java
com.sgxmobileapps.droidmaze.ui.MainSplashActivity.java
com.sgxmobileapps.droidmaze.ui.MazeActivity.java
com.sgxmobileapps.droidmaze.ui.animator.MultiSlideMenuAnimator.java
com.sgxmobileapps.droidmaze.ui.shape.ComplexShape.java
com.sgxmobileapps.droidmaze.ui.shape.LevelBarShape.java
com.sgxmobileapps.droidmaze.ui.shape.LoadingShape.java
com.sgxmobileapps.droidmaze.ui.shape.MazeShape.java
com.sgxmobileapps.droidmaze.util.ActivityUtils.java