Android Open Source - game-api-android Game Form






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  w  w.j a  v  a  2 s.com*/
import android.gameengine.icadroids.engine.GameEngine;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

/**
 * With GameForm you can create (and delete) views on top of the current view.
 * 
 * <b> Always create a GameForm inside a triggerAlarm! Else the GameForm will not be
 * shown! </b>
 * 
 * <b> When you show a view, the GameView will still be running! You must pause
 * this view by yourself. </b>
 * 
 * The layout of the views are made in a android XML layout file. You can use
 * the UI builder from android to make one. Layouts are saved in the /res/layout
 * folder.
 * 
 * To receive touch inputs, you must implement the IFormInput interface.
 * 
 * @author Bas van der Zandt
 * 
 */
public class GameForm {

  /**
   * The GameEngine where the game is currently running on
   */
  private GameEngine gameEngine;

  /**
   * Make a GameForm and show immediately the given Layout
   * 
   * @param layoutName
   *            The layout name given in the res/layout folder. <b>Give the
   *            name without .XML extension! </b> . So if your layout is
   *            called 'main.xml', this parameter should be "main" .
   * @param IformInput
   *            The IFormInput object that will receive touch inputs of this
   *            layout
   * @param gameEngine
   *            The GameEngine which this game is currently running on.
   */
  public GameForm(String layoutName, IFormInput IformInput,
      GameEngine gameEngine) {
    this.gameEngine = gameEngine;
    showView(layoutName, IformInput);
  }

  /**
   * Make a GameForm without adding a new layout.
   * 
   * @param gameEngine
   *            The GameEngine which the game is currently running on
   */
  public GameForm(GameEngine gameEngine) {
    this.gameEngine = gameEngine;
  }

  /**
   * Add a new view (layout) on the top of the current view.
   * 
   * @param layoutName
   *            The layout name given in the res/layout folder. <b>Give the
   *            name without .XML extension! </b> . So if your layout is
   *            called 'main.xml', this parameter should be "main" .
   * @param IformInput
   *            The IFormInput object that will receive touch inputs of this
   *            layout
   */
  public void showView(String layoutName, IFormInput IformInput) {
    int resID = getViewID(layoutName);
    ViewCreator vw = new ViewCreator(gameEngine, resID, IformInput);
    gameEngine.runOnUiThread(vw);
  }

  /**
   * Get the numeric ID of the layout.
   * 
   * @param layoutName
   *            The layout name without xml extension
   * @return The numeric ID of the layout
   */
  private int getViewID(String layoutName) {
    return gameEngine.getResources().getIdentifier(layoutName, "layout",
        gameEngine.getPackageName());
  }

  /**
   * Get the ID name of an view element, like a button or textbox.
   * 
   * @param viewElement
   * @return The name of the view element. This name is specified in
   *         android:id in your android layout xml.
   */
  public String getElementName(View viewElement) {
    return gameEngine.getResources().getResourceEntryName(
        viewElement.getId());
  }

  /**
   * Toast are little grey boxes with text in it that appear a few seconds on
   * the screen. You can make a toast with this method.
   * 
   * @param text
   *            The text that will be visible in the toast
   * @param duration
   *            The duration of the toast in seconds
   */
  public void sendToast(String text, int duration) {
    Toast.makeText(GameEngine.getAppContext(), text, duration).show();
  }

  /**
   * Get text from a textfield.
   * 
   * @param textfieldName
   *            The android:id name of the textfield specified in your android
   *            layout xml file
   * @return Text in textfield
   */
  public String getTextFromTextfield(String textfieldName) {
    int resID = gameEngine.getResources().getIdentifier(textfieldName,
        "id", gameEngine.getPackageName());

    EditText textField = (EditText) gameEngine.findViewById(resID);
    return textField.getText().toString();
  }

  /**
   * Remove the specified view from the screen.
   * 
   * @param layoutName
   *            The layout name given in the res/layout folder. <b>Give the
   *            name without .XML extension! </b> . So if your layout is
   *            called 'main.xml', this parameter should be "main" .
   */
  public void removeView(String layoutName) {
    int resID = getViewID(layoutName);
    ViewRemover vr = new ViewRemover(resID);
    gameEngine.runOnUiThread(vr);
  }

  /**
   * Get the view of a elementname
   * @param idName the id name of the view
   * @return The coresponding View
   */
  public View findViewElementByName(String idName) {
    int resID = gameEngine.getResources().getIdentifier(idName, "id",
        gameEngine.getPackageName());
    return gameEngine.findViewById(resID);
  }

}




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