Android Open Source - DroidChineseCheckers Checkers Main Menu






From Project

Back to project page DroidChineseCheckers.

License

The source code is released under:

Apache License

If you think the Android project DroidChineseCheckers 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.whiterabbit.checkers.ui;
/*  w w  w .ja v  a  2 s.  c o  m*/
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.bugsense.trace.BugSenseHandler;
import com.immersion.uhl.Launcher;
import com.whiterabbit.checkers.Constants;
import com.whiterabbit.checkers.R;
import com.whiterabbit.checkers.util.Utils;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.Entity;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.ui.activity.BaseGameActivity;


public class CheckersMainMenu extends BaseGameActivity {
  // ===========================================================
  // Constants
  // ===========================================================



  protected static final int MENU_OK = 0;
  protected static final int MENU_QUIT = MENU_OK + 1;
  static final int MENU_OPTIONS = Menu.FIRST;

  // ===========================================================
  // Fields
  // ===========================================================

  protected Camera mCamera;

  protected Scene mMainScene;
  private BitmapTextureAtlas mPlayTexture;
  protected ITextureRegion mPlayTextureRegion;

  protected ITextureRegion mBackgroundTextureRegion;
  protected BitmapTextureAtlas mBackgroundTexture;
  private Launcher mHapticsLauncher;
  
  // ===========================================================
  // Constructors
  // ===========================================================

  // ===========================================================
  // Getter & Setter
  // ===========================================================

  // ===========================================================
  // Methods for/from SuperClass/Interfaces
  // ===========================================================


    @Override
    public EngineOptions onCreateEngineOptions() {
        int width = Constants.CAMERA_WIDTH;
        int height = Constants.getHeight(width, this);
        this.mCamera = new Camera(0, 0, width, height);

        return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(width, height), this.mCamera);
    }





  @Override
    protected void onCreate(Bundle pSavedInstanceState) {
        mHapticsLauncher = new Launcher(this);
        BugSenseHandler.initAndStartSession(this, getString(R.string.bugsensekey));
        super.onCreate(pSavedInstanceState);
    }
    


    @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    
    int groupId = 0;
    int menuItemId = MENU_OPTIONS;
    int menuItemOrder = Menu.NONE;   
    int menuItemText = R.string.options;
    
    menu.add(groupId, menuItemId, menuItemOrder, menuItemText).setIcon(android.R.drawable.ic_menu_preferences);
    return true;
  }
    
    
    @Override
  public boolean onOptionsItemSelected(MenuItem item) 
  {
    super.onOptionsItemSelected(item);
    switch(item.getItemId()){
      case MENU_OPTIONS:{
        Intent i = new Intent(this, PegDroidPrefs.class); 
        startActivity(i);
        break;
      }
    }

    return true;
  }


    @Override
    public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception  {

        mPlayTexture =  new BitmapTextureAtlas(getTextureManager(), 512, 256);
        mPlayTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mPlayTexture, this, "gfx/play_button.png", 0, 0);
        mEngine.getTextureManager().loadTexture(mPlayTexture);


    this.mBackgroundTexture = new BitmapTextureAtlas(getTextureManager(), 1024, 1024);
    this.mBackgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBackgroundTexture, this, "gfx/menu_back.png", 0, 0);
    this.mEngine.getTextureManager().loadTexture(this.mBackgroundTexture);
        pOnCreateResourcesCallback.onCreateResourcesFinished();

    }



    @Override
    public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
    /* Just a simple scene with an animated face flying around. */
    this.mMainScene = new Scene();
        mMainScene.attachChild(new Entity());
        mMainScene.attachChild(new Entity());
    mMainScene.getChildByIndex(0).attachChild(new Sprite(0, 0, mBackgroundTextureRegion, getVertexBufferObjectManager()));

    Sprite playSprite = new Sprite(Constants.CAMERA_WIDTH - 200, Constants.getHeight(Constants.CAMERA_WIDTH, this) - 200, this.mPlayTextureRegion, getVertexBufferObjectManager()){

      @Override
      public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
          float pTouchAreaLocalX, float pTouchAreaLocalY) {
                if(pSceneTouchEvent.isActionUp()){
            Utils.playButtonPressed(mHapticsLauncher, CheckersMainMenu.this);
            Intent i = new Intent(CheckersMainMenu.this, BoardsListActivity.class);
                startActivity(i);
            return true;
                }
                return false;
      }

    };


    this.mMainScene.getChildByIndex(1).attachChild(playSprite);
    this.mMainScene.registerTouchArea(playSprite);
        this.mMainScene.setTouchAreaBindingOnActionDownEnabled(true);
        pOnCreateSceneCallback.onCreateSceneFinished(mMainScene);
  }

    @Override
    public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
        pOnPopulateSceneCallback.onPopulateSceneFinished();
    }


}




Java Source Code List

com.whiterabbit.checkers.Constants.java
com.whiterabbit.checkers.PegDroidApplication.java
com.whiterabbit.checkers.PreferencesStore.java
com.whiterabbit.checkers.board.AndEngineBoard.java
com.whiterabbit.checkers.board.BoardCell.java
com.whiterabbit.checkers.board.FillableBoardCell.java
com.whiterabbit.checkers.board.FilledBoardCell.java
com.whiterabbit.checkers.board.LastMove.java
com.whiterabbit.checkers.boards.Board32Diamond.java
com.whiterabbit.checkers.boards.BoardAsymmetrical.java
com.whiterabbit.checkers.boards.BoardClassicEng.java
com.whiterabbit.checkers.boards.BoardClassicExtended.java
com.whiterabbit.checkers.boards.BoardClassic.java
com.whiterabbit.checkers.boards.BoardKind.java
com.whiterabbit.checkers.boards.BoardS.java
com.whiterabbit.checkers.boards.BoardStar.java
com.whiterabbit.checkers.boards.CheckersDbHelper.java
com.whiterabbit.checkers.boards.CheckersStorage.java
com.whiterabbit.checkers.boards.HoleMushroom.java
com.whiterabbit.checkers.boards.NineByNineBoard.java
com.whiterabbit.checkers.boards.SimpleCross1.java
com.whiterabbit.checkers.boards.SimpleCross2.java
com.whiterabbit.checkers.boards.SimpleCross3.java
com.whiterabbit.checkers.boards.SixBySixBoard.java
com.whiterabbit.checkers.boards.WieglebBoard.java
com.whiterabbit.checkers.exceptions.CantFillException.java
com.whiterabbit.checkers.ui.BackArrowSprite.java
com.whiterabbit.checkers.ui.BallSprite.java
com.whiterabbit.checkers.ui.BoardListElem.java
com.whiterabbit.checkers.ui.BoardSprite.java
com.whiterabbit.checkers.ui.BoardsListActivity.java
com.whiterabbit.checkers.ui.CheckersGameActivity.java
com.whiterabbit.checkers.ui.CheckersMainMenu.java
com.whiterabbit.checkers.ui.CheckersSpriteFactory.java
com.whiterabbit.checkers.ui.CheckersStallActivity.java
com.whiterabbit.checkers.ui.PegDroidPrefs.java
com.whiterabbit.checkers.util.Utils.java