com.blackledge.david.tivo.widgets.qk
Class QuickKeyboard

java.lang.Object
  extended by com.tivo.hme.sdk.HmeObject
      extended by com.tivo.hme.sdk.View
          extended by com.tivo.hme.bananas.BView
              extended by com.blackledge.david.tivo.widgets.qk.QuickKeyboard
All Implemented Interfaces:
com.tivo.hme.bananas.IBananas, com.tivo.hme.bananas.IHighlightsLayout, com.tivo.hme.sdk.IHmeEventHandler, com.tivo.hme.sdk.IHmeProtocol

public class QuickKeyboard
extends com.tivo.hme.bananas.BView

Superclass of a quicker keyboard concept for use with infrared remote controls. Designed to minimize the number of button presses to indicate a character (typically 2 button presses per letter). Many handler subclasses possible.

Version:
1.0
Author:
http://David.Blackledge.com

Field Summary
static List AVAILABLE_KEYBOARDS
          List of all known keyboard handler class names cycled through via the "change keyboard" command.
static String KEYBOARD_DIRECTIONAL
          QuickKeyboardHandler class name constant to pass in to constructor.
static String KEYBOARD_PHONE
          QuickKeyboardHandler class name constant to pass in to constructor.
static String KEYBOARD_PHONE_ROW_COLUMN
          QuickKeyboardHandler class name constant to pass in to constructor.
static String KEYBOARD_QUADRANTS
          QuickKeyboardHandler class name constant to pass in to constructor.
static String KEYBOARD_ROW_COLUMN
          QuickKeyboardHandler class name constant to pass in to constructor.
 
Fields inherited from interface com.tivo.hme.bananas.IBananas
A_ANCHOR_MASK, A_BOTTOM, A_CENTER, A_DELTA_MASK, A_LEFT, A_NEGATIVE_MASK, A_RIGHT, A_TOP, ARROW_NAMES, BAR_DEFAULT, BAR_HANG, BEVT_ACTION, BEVT_FOCUS, BEVT_SCREEN_ENTER, BEVT_SCREEN_EXIT, H_BAR, H_DOWN, H_KEYBOARD, H_LEFT, H_PAGEDOWN, H_PAGEUP, H_RIGHT, H_UP, H_VIS_FALSE, H_VIS_FOCUS, H_VIS_TRUE, TRANSITION_FADE, TRANSITION_LEFT, TRANSITION_NONE
 
Fields inherited from interface com.tivo.hme.sdk.IHmeProtocol
APP_ERROR_BAD_ARGUMENT, APP_ERROR_BAD_COMMAND, APP_ERROR_OTHER, APP_ERROR_OUT_OF_MEMORY, APP_ERROR_RSRC_NOT_FOUND, APP_ERROR_UNKNOWN, APP_ERROR_VIEW_NOT_FOUND, CMD_RECEIVER_ACKNOWLEDGE_IDLE, CMD_RECEIVER_TRANSITION, CMD_RESERVED, CMD_RSRC_ADD_ANIM, CMD_RSRC_ADD_COLOR, CMD_RSRC_ADD_FONT, CMD_RSRC_ADD_IMAGE, CMD_RSRC_ADD_SOUND, CMD_RSRC_ADD_STREAM, CMD_RSRC_ADD_TEXT, CMD_RSRC_ADD_TTF, CMD_RSRC_CLOSE, CMD_RSRC_REMOVE, CMD_RSRC_SEND_EVENT, CMD_RSRC_SET_ACTIVE, CMD_RSRC_SET_POSITION, CMD_RSRC_SET_SPEED, CMD_VIEW_ADD, CMD_VIEW_REMOVE, CMD_VIEW_SET_BOUNDS, CMD_VIEW_SET_PAINTING, CMD_VIEW_SET_RESOURCE, CMD_VIEW_SET_SCALE, CMD_VIEW_SET_TRANSLATION, CMD_VIEW_SET_TRANSPARENCY, CMD_VIEW_SET_VISIBLE, EVT_APP_INFO, EVT_DEVICE_INFO, EVT_FONT_INFO, EVT_IDLE, EVT_INIT_INFO, EVT_KEY, EVT_RESERVED, EVT_RSRC_INFO, FONT_BOLD, FONT_BOLDITALIC, FONT_ITALIC, FONT_METRICS_BASIC, FONT_METRICS_GLYPH, FONT_PLAIN, ID_ALERT_SOUND, ID_BONK_SOUND, ID_CLIENT, ID_CLIENT_PRE_0_38, ID_DEFAULT_TTF, ID_DESELECT_SOUND, ID_ERROR_SOUND, ID_LEFT_SOUND, ID_NULL, ID_PAGEDOWN_SOUND, ID_PAGEUP_SOUND, ID_RESERVED, ID_RIGHT_SOUND, ID_ROOT_STREAM, ID_ROOT_VIEW, ID_SELECT_SOUND, ID_SLOWDOWN1_SOUND, ID_SPEEDUP1_SOUND, ID_SPEEDUP2_SOUND, ID_SPEEDUP3_SOUND, ID_SYSTEM_TTF, ID_THUMBSDOWN_SOUND, ID_THUMBSUP_SOUND, ID_TIVO_SOUND, ID_UPDOWN_SOUND, KEY_ADVANCE, KEY_CHANNELDOWN, KEY_CHANNELUP, KEY_CLEAR, KEY_DISPLAY, KEY_DOWN, KEY_ENTER, KEY_FORWARD, KEY_INFO, KEY_LEFT, KEY_LIVETV, KEY_MUTE, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_OPT_ANGLE, KEY_OPT_ASPECT, KEY_OPT_DVD, KEY_OPT_EXIT, KEY_OPT_GUIDE, KEY_OPT_LIST, KEY_OPT_MENU, KEY_OPT_PIP, KEY_OPT_STOP, KEY_OPT_TOP_MENU, KEY_OPT_WINDOW, KEY_PAUSE, KEY_PLAY, KEY_PRESS, KEY_RECORD, KEY_RELEASE, KEY_REPEAT, KEY_REPLAY, KEY_REVERSE, KEY_RIGHT, KEY_SELECT, KEY_SLOW, KEY_THUMBSDOWN, KEY_THUMBSUP, KEY_TIVO, KEY_UNKNOWN, KEY_UP, KEY_VOLUMEDOWN, KEY_VOLUMEUP, LIMIT_CMD_NBYTES, LIMIT_EVENT_NBYTES, LIMIT_FONT_POINT_SIZE, LIMIT_IMAGE_HEIGHT, LIMIT_IMAGE_NBYTES, LIMIT_IMAGE_WIDTH, LIMIT_SOUND_NBYTES, LIMIT_TEXT_NBYTES, LIMIT_URL_NBYTES, LIMIT_VIEW_DEPTH, MAGIC, RSRC_ERROR_BAD_ARGUMENT, RSRC_ERROR_BAD_DATA, RSRC_ERROR_BAD_MAGIC, RSRC_ERROR_BAD_STATE, RSRC_ERROR_BAD_VERSION, RSRC_ERROR_CONNECT_FAILED, RSRC_ERROR_CONNECTION_LOST, RSRC_ERROR_CONNECTION_TIMEOUT, RSRC_ERROR_HOST_NOT_FOUND, RSRC_ERROR_INCOMPATIBLE, RSRC_ERROR_NOT_SUPPORTED, RSRC_ERROR_OTHER, RSRC_ERROR_UNKNOWN, RSRC_HALIGN_CENTER, RSRC_HALIGN_LEFT, RSRC_HALIGN_MASK, RSRC_HALIGN_RIGHT, RSRC_IMAGE_BESTFIT, RSRC_IMAGE_HFIT, RSRC_IMAGE_MASK, RSRC_IMAGE_VFIT, RSRC_STATUS_CLOSED, RSRC_STATUS_COMPLETE, RSRC_STATUS_CONNECTED, RSRC_STATUS_CONNECTING, RSRC_STATUS_ERROR, RSRC_STATUS_LOADING, RSRC_STATUS_PAUSED, RSRC_STATUS_PLAYING, RSRC_STATUS_READY, RSRC_STATUS_SEEKING, RSRC_STATUS_UNKNOWN, RSRC_TEXT_MASK, RSRC_TEXT_WRAP, RSRC_VALIGN_BOTTOM, RSRC_VALIGN_CENTER, RSRC_VALIGN_MASK, RSRC_VALIGN_TOP, SAFE_ACTION_H, SAFE_ACTION_V, SAFE_TITLE_H, SAFE_TITLE_V, TRANSITION_BACK, TRANSITION_FORWARD, TRANSITION_TELEPORT, VERSION, VERSION_0_38, VERSION_0_40, VERSION_MAJOR, VERSION_MINOR, VERSION_STRING
 
Constructor Summary
QuickKeyboard(com.tivo.hme.bananas.BView parent, int x, int y, int width, int height)
          Minmal Constructor.
QuickKeyboard(String keyboardHandlerClass, com.tivo.hme.bananas.BView parent, int x, int y, int width, int height)
           
QuickKeyboard(String keyboardHandlerClass, com.tivo.hme.bananas.BView parent, int x, int y, int width, int height, boolean visible)
           
 
Method Summary
 String backspaceCharacter()
           
 String changeKeyboard()
          Cycles through keyboard handlers available in AVAILABLE_KEYBOARDS.
 String deleteCharacter()
          delete character after cursor (to backspace: previousCharacter(), then deleteCharacter() if not at position 0)
 QKCue getCue(int keyCode)
          helper to work back in case you can easily determine what to do based on the cue, especially if using own cue subclasses.
 int getCursor()
          get the current cursor position
 Map getDefaultExtraKeys()
           
 String getDisplayedValue()
          Similar to getValue() but does not actually commit the latest set character.
static String getKeyChar(int keyCode)
           
static String getKeyName(int keyCode)
           
 com.tivo.hme.sdk.Resource getKeyResource(int keyCode)
           
 String getValue()
          Get the current value typed into the keyboard.
 boolean handleEvent(com.tivo.hme.sdk.HmeEvent event)
          Catch the FontInfo event we registered for with our font resource.
 boolean handleKeyPress(int code, long rawcode)
           
 boolean handleKeyRepeat(int code, long rawcode)
           
 boolean isOverwriteMode()
           
 void nextCharacter()
           
 void previousCharacter()
           
 void setCharacter(String text)
          Updates the display with this currently selected keyboard character but does not advance the cursor or commit the character to the value.
 void setCursor(int pos)
          - set cursor to that location in string and scroll into view.
 void setOverwriteMode(boolean overwrite)
          (if overwrite, setCharacter always calls deleteCharacter first.)
 void setValue(String value)
          sets the keyboard's typed value, calls QuickKeyboardHandler.abortCharacter(), and moves the cursor to the end.
 
Methods inherited from class com.tivo.hme.bananas.BView
getBApp, getFocusBounds, getHighlightBounds, getHighlightIsVisible, getHighlights, getScreen, handleAction, handleFocus, hasFocus, isAncestorOf, isFocusable, setFocusable, setHighlights, toScreen, toScreen, toScreenBounds, toScreenBounds, toString
 
Methods inherited from class com.tivo.hme.sdk.View
clearResource, dump, getBounds, getChild, getChildCount, getFlags, getHeight, getLocation, getPainting, getParent, getResource, getScaleX, getScaleY, getSize, getTranslate, getTranslationX, getTranslationY, getTransparency, getVisible, getWidth, getX, getY, handleFocus, layoutText, postEvent, remove, remove, setBounds, setBounds, setFocus, setLocation, setLocation, setPainting, setResource, setResource, setResource, setResource, setScale, setScale, setSize, setSize, setTranslation, setTranslation, setTransparency, setTransparency, setVisible, setVisible, translate, translate
 
Methods inherited from class com.tivo.hme.sdk.HmeObject
createAnimation, createAnimation, createColor, createFont, createFont, createImage, createImage, createImage, createImage, createSound, createSound, createSound, createStream, createStream, createStream, createText, createTrueType, flush, getApp, getContext, getID, getResource, handleKeyRelease, parseQuery, play, rsrcFlagsToString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEYBOARD_QUADRANTS

public static final String KEYBOARD_QUADRANTS
QuickKeyboardHandler class name constant to pass in to constructor. Keyboard broken into 4 alphabet quadrants (+ others for other characters)- select 1 of them and make a selection from the choices in the quadrant. Kind of like Stephen Hawking's set up.


KEYBOARD_PHONE

public static final String KEYBOARD_PHONE
QuickKeyboardHandler class name constant to pass in to constructor. Phone text messaging style - e.g. keep hitting 2 to cycle through a, b, c, and 2.


KEYBOARD_PHONE_ROW_COLUMN

public static final String KEYBOARD_PHONE_ROW_COLUMN
QuickKeyboardHandler class name constant to pass in to constructor. Phone text messaging style crossed with row/column style - rows match texting rows, columsn are position of that character on the list for that key.


KEYBOARD_DIRECTIONAL

public static final String KEYBOARD_DIRECTIONAL
QuickKeyboardHandler class name constant to pass in to constructor. Use the numbers as directions to move your selection on the keyboard: 1 is diagonal up/left, 2 is up ... 5 is select... 8 is down, 9 is diagonal down/right.


KEYBOARD_ROW_COLUMN

public static final String KEYBOARD_ROW_COLUMN
QuickKeyboardHandler class name constant to pass in to constructor. Keyboard that let's you enter 1 digit each for row and column to select your key. Set up so that you enter the number for the position in the alphabet (01=a [or 1+enter/ff=a], 26=z)


AVAILABLE_KEYBOARDS

public static final List AVAILABLE_KEYBOARDS
List of all known keyboard handler class names cycled through via the "change keyboard" command. Initialized with the constants from this class, but you may alter the list to include your choices and remove existing ones. Argument to constructor automatically added to the list if not already present and it is valid.

Constructor Detail

QuickKeyboard

public QuickKeyboard(String keyboardHandlerClass,
                     com.tivo.hme.bananas.BView parent,
                     int x,
                     int y,
                     int width,
                     int height,
                     boolean visible)
              throws IllegalArgumentException
Parameters:
keyboardHandlerClass - the fully qualified class name of the handler class - or one of the supplied constants.
parent -
x -
y -
width -
height -
visible -
Throws:
IllegalArgumentException - if keyboardHandlerClass cannot be instantiated.

QuickKeyboard

public QuickKeyboard(String keyboardHandlerClass,
                     com.tivo.hme.bananas.BView parent,
                     int x,
                     int y,
                     int width,
                     int height)
              throws IllegalArgumentException
Throws:
IllegalArgumentException

QuickKeyboard

public QuickKeyboard(com.tivo.hme.bananas.BView parent,
                     int x,
                     int y,
                     int width,
                     int height)
              throws IllegalArgumentException
Minmal Constructor. Uses the first keyboardhandlerclass available in AVAILABLE_KEYBOARDS.

Parameters:
parent -
x -
y -
width -
height -
Throws:
IllegalArgumentException
Method Detail

changeKeyboard

public String changeKeyboard()
Cycles through keyboard handlers available in AVAILABLE_KEYBOARDS. First tells any existing keyboard to abort the current character.

Returns:
the string entry of AVAILABLE_KEYBOARDS that was used, or null if the handler wasn't changed because the list is empty (or size 1) or the keyboard could not be instantiated.

getCue

public QKCue getCue(int keyCode)
helper to work back in case you can easily determine what to do based on the cue, especially if using own cue subclasses. use setCues to set the list of cues that should be returned when this cue is selected. Could even pre-create a hierarchy of cues in some (most?) cases.

Parameters:
keyCode -
Returns:
the cue currently associated with this keyCode, or null.

deleteCharacter

public String deleteCharacter()
delete character after cursor (to backspace: previousCharacter(), then deleteCharacter() if not at position 0)

Returns:
the character deleted or an empty string.

backspaceCharacter

public String backspaceCharacter()

previousCharacter

public void previousCharacter()

nextCharacter

public void nextCharacter()

setCharacter

public void setCharacter(String text)
Updates the display with this currently selected keyboard character but does not advance the cursor or commit the character to the value. Therefore, you can call this repeatedly, even every time the user hits a button, not committing until they hit a button that causes your handler to call nextCharacter(). If isOverwriteMode(), the ONE character after the cursor is deleted first if this is the first call since the last character was committed. Note that this character will automatically be committed if getValue() is called or setCursor(int) is called (perhaps via nextCharacter() or previousCharacter()). HOWEVER, every commit attempt will first call QuickKeyboardHandler.finishCharacter(), allowing you to call setCharacter(String) with a null or empty string, preventing the commit. To get the displayed result of this call, use getDisplayedValue() which will not commit the character.

Parameters:
text - the character (may be more than one character long) to place at the cursor position.

getDisplayedValue

public String getDisplayedValue()
Similar to getValue() but does not actually commit the latest set character.

Returns:
the value used in the display (sans any adjustments for scrolling/cursor placement)

setCursor

public void setCursor(int pos)
- set cursor to that location in string and scroll into view.


getCursor

public int getCursor()
get the current cursor position

Returns:
a value between 0 (beginning) and the length of the committed value (end) (i.e. cursor at end doesn't include the length of the last setCharacter(String) if it wasn't committed by moving the cursor or calling getValue())

getValue

public String getValue()
Get the current value typed into the keyboard. Attempts to commit the last setCharacter(String) value first.

Returns:
the current value typed into the keyboard.

setValue

public void setValue(String value)
sets the keyboard's typed value, calls QuickKeyboardHandler.abortCharacter(), and moves the cursor to the end.

Parameters:
value -

setOverwriteMode

public void setOverwriteMode(boolean overwrite)
(if overwrite, setCharacter always calls deleteCharacter first.)


isOverwriteMode

public boolean isOverwriteMode()

getDefaultExtraKeys

public Map getDefaultExtraKeys()

getKeyChar

public static String getKeyChar(int keyCode)

getKeyName

public static String getKeyName(int keyCode)

getKeyResource

public com.tivo.hme.sdk.Resource getKeyResource(int keyCode)

handleKeyRepeat

public boolean handleKeyRepeat(int code,
                               long rawcode)
Overrides:
handleKeyRepeat in class com.tivo.hme.sdk.HmeObject

handleKeyPress

public boolean handleKeyPress(int code,
                              long rawcode)
Overrides:
handleKeyPress in class com.tivo.hme.bananas.BView

handleEvent

public boolean handleEvent(com.tivo.hme.sdk.HmeEvent event)
Catch the FontInfo event we registered for with our font resource.

Overrides:
handleEvent in class com.tivo.hme.bananas.BView
See Also:
BView.handleEvent(com.tivo.hme.sdk.HmeEvent)