Modifier and Type | Field and Description |
---|---|
int[] |
codes
All the key codes (unicode or custom code) that this key could generate, zero'th
being the most important.
|
int |
edgeFlags
Flags that specify the anchoring to edges of the keyboard for detecting touch events
that are just out of the boundary of the key.
|
int |
gap
The horizontal gap before this key
|
int |
height
Height of the key, not including the gap
|
Drawable |
icon
Icon to display instead of a label.
|
Drawable |
iconPreview
Preview version of the icon, for the preview popup
|
CharSequence |
label
Label to display
|
boolean |
modifier
Whether this is a modifier key, such as Shift or Alt
|
boolean |
on
If this is a sticky key, is it on?
|
CharSequence |
popupCharacters
Popup characters
|
int |
popupResId
If this key pops up a mini keyboard, this is the resource id for the XML layout for that
keyboard.
|
boolean |
pressed
The current pressed state of this key
|
boolean |
repeatable
Whether this key repeats itself when held down
|
boolean |
sticky
Whether this key is sticky, i.e., a toggle key
|
CharSequence |
text
Text to output when pressed.
|
int |
width
Width of the key, not including the gap
|
int |
x
X coordinate of the key in the keyboard layout
|
int |
y
Y coordinate of the key in the keyboard layout
|
Constructor and Description |
---|
Key(Keyboard.Row parent)
Create an empty key with no attributes.
|
Key(Resources res,
Keyboard.Row parent,
int x,
int y,
XmlResourceParser parser)
Create a key with the given top-left coordinate and extract its attributes from
the XML parser.
|
Modifier and Type | Method and Description |
---|---|
int[] |
getCurrentDrawableState()
Returns the drawable state for the key, based on the current state and type of the key.
|
boolean |
isInside(int x,
int y)
Detects if a point falls inside this key.
|
void |
onPressed()
Informs the key that it has been pressed, in case it needs to change its appearance or
state.
|
void |
onReleased(boolean inside)
Changes the pressed state of the key.
|
int |
squaredDistanceFrom(int x,
int y)
Returns the square of the distance between the center of the key and the given point.
|
public int[] codes
public CharSequence label
public Drawable icon
public Drawable iconPreview
public int width
public int height
public int gap
public boolean sticky
public int x
public int y
public boolean pressed
public boolean on
public CharSequence text
public CharSequence popupCharacters
public int edgeFlags
Keyboard.EDGE_LEFT
, Keyboard.EDGE_RIGHT
, Keyboard.EDGE_TOP
and
Keyboard.EDGE_BOTTOM
.public boolean modifier
public int popupResId
public boolean repeatable
public Key(Keyboard.Row parent)
public Key(Resources res, Keyboard.Row parent, int x, int y, XmlResourceParser parser)
res
- resources associated with the caller's contextparent
- the row that this key belongs to. The row must already be attached to
a Keyboard
.x
- the x coordinate of the top-lefty
- the y coordinate of the top-leftparser
- the XML parser containing the attributes for this keypublic void onPressed()
onReleased(boolean)
public void onReleased(boolean inside)
Toggled state of the key will be flipped when all the following conditions are fulfilled:
sticky
is true
.
inside
is true
.
Build.VERSION.SDK_INT
is greater than
Build.VERSION_CODES.LOLLIPOP_MR1
.
inside
- whether the finger was released inside the key. Works only on Android M and
later. See the method document for details.onPressed()
public boolean isInside(int x, int y)
x
- the x-coordinate of the pointy
- the y-coordinate of the pointpublic int squaredDistanceFrom(int x, int y)
x
- the x-coordinate of the pointy
- the y-coordinate of the pointpublic int[] getCurrentDrawableState()
Drawable.setState(int[])