Android Open Source - game-api-android On Screen Button






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.input;
//from   w ww .j a  v  a  2s  .co m
import android.content.Context;
import android.util.AttributeSet;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.widget.ImageButton;

/**
 * An custom (android) imageButton used in the onScreenButtons. Every button of
 * the OnScreenButtons is an instance of this class. A OnScreenButton can be
 * added programmatically or with the android layout xml editor (under Custom &
 * Library views).
 * 
 * @author Bas
 * 
 */
public class OnScreenButton extends ImageButton {

  /**
   * Default constructor for an ImageButton
   */
  public OnScreenButton(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    intializeButton();
  }

  /**
   * Default constructor for an ImageButton
   */
  public OnScreenButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    intializeButton();
  }

  /**
   * Default constructor for an ImageButton
   */
  public OnScreenButton(Context context) {
    super(context);
    intializeButton();
  }

  /**
   * Initialize the button layout, like the opacity and the background.
   */
  @SuppressWarnings("deprecation")
  // New implementations are only supported
  // by android 4.0+
  private void intializeButton() {
    setAlpha(OnScreenButtons.opacity); // 255 is max (visible)
    setBackgroundDrawable(null);
    setPadding(0, 0, 0, 0);
  }

  /**
   * DO NOT CALL THIS FUNCTION.<br />
   * Called by Android device to notify the Game of an user action.
   * 
   * @see android.view.View#onTouchEvent(android.view.MotionEvent)
   */
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() != MotionEvent.ACTION_UP) {
      OnScreenButtons.buttonPressed(getId());
    } else {
      OnScreenButtons.buttonReleased(getId());
    }

    if (OnScreenButtons.feedback && (event.getAction() == MotionEvent.ACTION_DOWN)) {
      performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
    }

    return super.onTouchEvent(event);
  }

}




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