public class Keyboard extends Object
The layout file for a keyboard contains XML that looks like the following snippet:
<Keyboard android:keyWidth="%10p" android:keyHeight="50px" android:horizontalGap="2px" android:verticalGap="2px" > <Row android:keyWidth="32px" > <Key android:keyLabel="A" /> ... </Row> ... </Keyboard>
Modifier and Type | Class and Description |
---|---|
static class |
Keyboard.Key
Class for describing the position and characteristics of a single key in the keyboard.
|
static class |
Keyboard.Row
Container for keys in the keyboard.
|
Modifier and Type | Field and Description |
---|---|
static int |
EDGE_BOTTOM |
static int |
EDGE_LEFT |
static int |
EDGE_RIGHT |
static int |
EDGE_TOP |
static int |
KEYCODE_ALT |
static int |
KEYCODE_CANCEL |
static int |
KEYCODE_DELETE |
static int |
KEYCODE_DONE |
static int |
KEYCODE_MODE_CHANGE |
static int |
KEYCODE_SHIFT |
Constructor and Description |
---|
Keyboard(Context context,
int xmlLayoutResId)
Creates a keyboard from the given xml key layout file.
|
Keyboard(Context context,
int layoutTemplateResId,
CharSequence characters,
int columns,
int horizontalPadding)
Creates a blank keyboard from the given resource file and populates it with the specified
characters in left-to-right, top-to-bottom fashion, using the specified number of columns.
|
Keyboard(Context context,
int xmlLayoutResId,
int modeId)
Creates a keyboard from the given xml key layout file.
|
Keyboard(Context context,
int xmlLayoutResId,
int modeId,
int width,
int height)
Creates a keyboard from the given xml key layout file.
|
Modifier and Type | Method and Description |
---|---|
protected Keyboard.Key |
createKeyFromXml(Resources res,
Keyboard.Row parent,
int x,
int y,
XmlResourceParser parser) |
protected Keyboard.Row |
createRowFromXml(Resources res,
XmlResourceParser parser) |
int |
getHeight()
Returns the total height of the keyboard
|
protected int |
getHorizontalGap() |
protected int |
getKeyHeight() |
List<Keyboard.Key> |
getKeys() |
protected int |
getKeyWidth() |
int |
getMinWidth() |
List<Keyboard.Key> |
getModifierKeys() |
int[] |
getNearestKeys(int x,
int y)
Returns the indices of the keys that are closest to the given point.
|
int |
getShiftKeyIndex() |
int[] |
getShiftKeyIndices() |
protected int |
getVerticalGap() |
boolean |
isShifted() |
protected void |
setHorizontalGap(int gap) |
protected void |
setKeyHeight(int height) |
protected void |
setKeyWidth(int width) |
boolean |
setShifted(boolean shiftState) |
protected void |
setVerticalGap(int gap) |
public static final int EDGE_LEFT
public static final int EDGE_RIGHT
public static final int EDGE_TOP
public static final int EDGE_BOTTOM
public static final int KEYCODE_SHIFT
public static final int KEYCODE_MODE_CHANGE
public static final int KEYCODE_CANCEL
public static final int KEYCODE_DONE
public static final int KEYCODE_DELETE
public static final int KEYCODE_ALT
public Keyboard(Context context, int xmlLayoutResId)
context
- the application or service contextxmlLayoutResId
- the resource file that contains the keyboard layout and keys.public Keyboard(Context context, @XmlRes int xmlLayoutResId, int modeId, int width, int height)
context
- the application or service contextxmlLayoutResId
- the resource file that contains the keyboard layout and keys.modeId
- keyboard mode identifierwidth
- sets width of keyboardheight
- sets height of keyboardpublic Keyboard(Context context, @XmlRes int xmlLayoutResId, int modeId)
context
- the application or service contextxmlLayoutResId
- the resource file that contains the keyboard layout and keys.modeId
- keyboard mode identifierpublic Keyboard(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding)
Creates a blank keyboard from the given resource file and populates it with the specified characters in left-to-right, top-to-bottom fashion, using the specified number of columns.
If the specified number of columns is -1, then the keyboard will fit as many keys as possible in each row.
context
- the application or service contextlayoutTemplateResId
- the layout template file, containing no keys.characters
- the list of characters to display on the keyboard. One key will be created
for each character.columns
- the number of columns of keys to display. If this number is greater than the
number of keys that can fit in a row, it will be ignored. If this number is -1, the
keyboard will fit as many keys as possible in each row.public List<Keyboard.Key> getKeys()
public List<Keyboard.Key> getModifierKeys()
protected int getHorizontalGap()
protected void setHorizontalGap(int gap)
protected int getVerticalGap()
protected void setVerticalGap(int gap)
protected int getKeyHeight()
protected void setKeyHeight(int height)
protected int getKeyWidth()
protected void setKeyWidth(int width)
public int getHeight()
public int getMinWidth()
public boolean setShifted(boolean shiftState)
public boolean isShifted()
public int[] getShiftKeyIndices()
public int getShiftKeyIndex()
public int[] getNearestKeys(int x, int y)
x
- the x-coordinate of the pointy
- the y-coordinate of the pointprotected Keyboard.Row createRowFromXml(Resources res, XmlResourceParser parser)
protected Keyboard.Key createKeyFromXml(Resources res, Keyboard.Row parent, int x, int y, XmlResourceParser parser)