public class

DirectionalPad

extends RectangleShape
java.lang.Object
   ↳ sofia.graphics.Shape
     ↳ sofia.graphics.StrokedShape
       ↳ sofia.graphics.FillableShape
         ↳ sofia.graphics.RectangleShape
           ↳ sofia.graphics.DirectionalPad

Class Overview

An on-screen directional pad (d-pad) suitable for games, based on the cross-shaped d-pad used on classic console game systems. The d-pad responds to touch events and translates them as key events (with key codes KeyEvent#KEYCODE_DPAD_*) that get sent to the ShapeView that contains the shape. The d-pad also fades out slightly when it is not being touched, so that it does not completely obscure the rest of the screen content.

Summary

Public Constructors
DirectionalPad(RectF bounds)
Creates a new directional pad with the specified bounds.
Public Methods
int getInactiveAlpha()
Gets the alpha value of the directional pad when it is inactive (has not been touched for one second).
void onAnimationDone(Animator<?> animator)
Implemented to handle the fading in/out logic of the d-pad.
void onTouchDown(MotionEvent e)
Handles a touch down event on the directional pad, mapping it to appropriate key events.
void onTouchUp(MotionEvent e)
Handles a touch up event on the directional pad, mapping it to appropriate key events.
void setInactiveAlpha(int newAlpha)
Sets the alpha value of the directional pad when it is inactive (has not been touched for one second).
[Expand]
Inherited Methods
From class sofia.graphics.RectangleShape
From class sofia.graphics.FillableShape
From class sofia.graphics.StrokedShape
From class sofia.graphics.Shape
From class java.lang.Object

Public Constructors

public DirectionalPad (RectF bounds)

Creates a new directional pad with the specified bounds. For best results, the bounds should be square, but no checking is done to verify this.

Parameters
bounds the bounds of the directional pad

Public Methods

public int getInactiveAlpha ()

Gets the alpha value of the directional pad when it is inactive (has not been touched for one second).

Returns
  • the alpha value of the directional pad when it is inactive

public void onAnimationDone (Animator<?> animator)

Implemented to handle the fading in/out logic of the d-pad. Not intended to be called by clients.

Parameters
animator the animator

public void onTouchDown (MotionEvent e)

Handles a touch down event on the directional pad, mapping it to appropriate key events.

Parameters
e a MotionEvent describing the touch

public void onTouchUp (MotionEvent e)

Handles a touch up event on the directional pad, mapping it to appropriate key events.

Parameters
e a MotionEvent describing the touch

public void setInactiveAlpha (int newAlpha)

Sets the alpha value of the directional pad when it is inactive (has not been touched for one second). Be careful not to set this value too low, or it will make the directional pad difficult to see when it is not in use.

Parameters
newAlpha the new alpha value of the directional pad when it is inactive