Android Open Source - game-api-android View Creator






From Project

Back to project page game-api-android.

License

The source code is released under:

MIT License

If you think the Android project game-api-android 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 android.gameengine.icadroids.forms;
//from   w  ww. j ava2 s.c om
import java.util.ArrayList;
import java.util.Vector;

import android.gameengine.icadroids.engine.GameEngine;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;

/**
 * ViewCreator puts (form)views on top of the GameView. This views are made in
 * Android Layout XML. It also registers any touchable components in the view.
 * 
 * <b> Don't use this class by yourself! It's used by GameForm to correctly add
 * views </b>
 * 
 * <b>Note: This class must run on the UI thread.</b>
 * 
 * @author Bas
 */
public class ViewCreator implements Runnable {

  /**
   * The GameEngine that is currently running
   */
  GameEngine gameEngine;
  /**
   * The IFormInput that must be informed of inputs
   */
  IFormInput IformInput;
  /**
   * The ID of the view that must be added
   */
  int layoutID;
  /**
   * Vector with all the formViews that are currently availble
   */
  public static Vector<View> formViews = new Vector<View>();

  /**
   * Creates a view on top of the GameView that are made in the android XML
   * layout file
   * 
   * @param gameengine
   * @param layoutID
   * @param IformInput
   */
  protected ViewCreator(GameEngine gameengine, int layoutID,
      IFormInput IformInput) {
    this.IformInput = IformInput;
    gameEngine = gameengine;
    this.layoutID = layoutID;
  }

  /**
   * Add a view on top of the current view and register any touchable
   * components in the view to a touch-listener so the IFormInput object can
   * receive touch calls.
   * 
   * run() runs on the UI thread for one time
   */
  public void run() {
    GameEngine.getAppView().setVisibility(View.VISIBLE);

    LayoutParams lp = new ViewGroup.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.MATCH_PARENT);
    View formView = gameEngine.getLayoutInflater().inflate(layoutID, null);
    formView.setTag(layoutID);
    gameEngine.getWindow().addContentView(formView, lp);

    ArrayList<View> touchables = formView.getTouchables();

    for (int i = 0; i < touchables.size(); i++) {

      touchables.get(i).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          if (v instanceof EditText) {
            // Show the Soft-Keyboard. Android does not show
            // the soft-keyboard automatically
            gameEngine.showKeyboard();
          }
          IformInput.formElementClicked(v);
        }
      });

    }
    formViews.add(formView);
  }
}




Java Source Code List

android.gameengine.icadroids.alarms.Alarm.java
android.gameengine.icadroids.alarms.IAlarm.java
android.gameengine.icadroids.dashboard.DashboardImageView.java
android.gameengine.icadroids.dashboard.DashboardTextView.java
android.gameengine.icadroids.engine.GameEngine.java
android.gameengine.icadroids.engine.GameFPSCounter.java
android.gameengine.icadroids.engine.GameThread.java
android.gameengine.icadroids.engine.GameView.java
android.gameengine.icadroids.engine.Viewport.java
android.gameengine.icadroids.forms.GameForm.java
android.gameengine.icadroids.forms.IFormInput.java
android.gameengine.icadroids.forms.ViewCreator.java
android.gameengine.icadroids.forms.ViewRemover.java
android.gameengine.icadroids.input.MotionSensor.java
android.gameengine.icadroids.input.OnScreenButton.java
android.gameengine.icadroids.input.OnScreenButtons.java
android.gameengine.icadroids.input.TouchInput.java
android.gameengine.icadroids.objects.GameObject.java
android.gameengine.icadroids.objects.MoveableGameObject.java
android.gameengine.icadroids.objects.collisions.CollidingObject.java
android.gameengine.icadroids.objects.collisions.ICollision.java
android.gameengine.icadroids.objects.collisions.TileCollision.java
android.gameengine.icadroids.objects.graphics.AnimatedSprite.java
android.gameengine.icadroids.objects.graphics.Sprite.java
android.gameengine.icadroids.persistence.GamePersistence.java
android.gameengine.icadroids.sound.GameSound.java
android.gameengine.icadroids.sound.MusicPlayer.java
android.gameengine.icadroids.tiles.GameTiles.java
android.gameengine.icadroids.tiles.Tile.java
com.android.vissenspel.Monster.java
com.android.vissenspel.StrawberryControler.java
com.android.vissenspel.Strawberry.java
com.android.vissenspel.Vis.java
com.android.vissenspel.Vissenkom.java
game.MyAndroidGame.java
testGames.AndroidCraft_demo.java
testGames.FormTest.java
testGames.Player.java
testGames.TestGameBas.java
testGames.TestGameLex.java
testGames.TestGameRoel.java
testGames.gameEngineTest.DebugEngine.java
testGames.gameEngineTest.GameEngineTestGame.java
testGames.gameEngineTest.TestGameObject.java
testGames.gameEngineTest.debugObject.java
testGames.gameEngineTest.randomObject.java
testGames.testGameObjectBas.java
testGames.testGame.java