jackpal.androidterm.emulatorview
Class EmulatorView

java.lang.Object
  extended by android.view.View
      extended by jackpal.androidterm.emulatorview.EmulatorView
All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, GestureDetector.OnGestureListener, KeyEvent.Callback

public class EmulatorView
extends View
implements GestureDetector.OnGestureListener

A view on a TermSession. Displays the terminal emulator's screen, provides access to its scrollback buffer, and passes input through to the terminal emulator.

If this view is inflated from an XML layout, you need to call attachSession and setDensity before using the view. If creating this view from code, use the EmulatorView(Context, TermSession, DisplayMetrics) constructor, which will take care of this for you.


Nested Class Summary
 
Nested classes/interfaces inherited from class android.view.View
View.BaseSavedState, View.DragShadowBuilder, View.MeasureSpec, View.OnClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnSystemUiVisibilityChangeListener, View.OnTouchListener
 
Field Summary
 
Fields inherited from class android.view.View
DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, NO_ID, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, STATUS_BAR_HIDDEN, STATUS_BAR_VISIBLE, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET
 
Constructor Summary
EmulatorView(Context context, AttributeSet attrs)
          Constructor called when inflating this view from XML.
EmulatorView(Context context, AttributeSet attrs, int defStyle)
          Constructor called when inflating this view from XML with a default style set.
EmulatorView(Context context, TermSession session, DisplayMetrics metrics)
          Create an EmulatorView for a TermSession.
 
Method Summary
 void attachSession(TermSession session)
          Attach a TermSession to this view.
protected  int computeVerticalScrollExtent()
          Compute the vertical extent of the horizontal scrollbar's thumb within the vertical range.
protected  int computeVerticalScrollOffset()
          Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range.
protected  int computeVerticalScrollRange()
          Compute the vertical range that the vertical scrollbar represents.
 boolean getKeypadApplicationMode()
          Get the terminal emulator's keypad application mode.
 String getSelectedText()
          Get selected text.
 boolean getSelectingText()
          Whether the view is currently in text selection mode.
 TermSession getTermSession()
          Get the TermSession corresponding to this view.
 int getVisibleHeight()
          Get the height of the visible portion of this view.
 int getVisibleWidth()
          Get the width of the visible portion of this view.
 boolean onCheckIsTextEditor()
           
 InputConnection onCreateInputConnection(EditorInfo outAttrs)
           
 boolean onDown(MotionEvent e)
           
protected  void onDraw(Canvas canvas)
          Draw the view to the provided Canvas.
 boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
           
 boolean onJumpTapDown(MotionEvent e1, MotionEvent e2)
           
 boolean onJumpTapUp(MotionEvent e1, MotionEvent e2)
           
 boolean onKeyDown(int keyCode, KeyEvent event)
          Called when a key is pressed in the view.
 boolean onKeyUp(int keyCode, KeyEvent event)
          Called when a key is released in the view.
 void onLongPress(MotionEvent e)
           
 void onPause()
          Inform the view that it is no longer visible on the screen.
 void onResume()
          Inform the view that it is now visible on screen.
 boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
           
 void onShowPress(MotionEvent e)
           
 void onSingleTapConfirmed(MotionEvent e)
           
 boolean onSingleTapUp(MotionEvent e)
           
protected  void onSizeChanged(int w, int h, int oldw, int oldh)
          This is called during layout when the size of this view has changed.
 boolean onTouchEvent(MotionEvent ev)
           
 void page(int delta)
          Page the terminal view (scroll it up or down by delta screenfuls).
 void pageHorizontal(int deltaColumns)
          Page the terminal view horizontally.
 void sendControlKey()
          Send a Ctrl key event to the terminal.
 void sendFnKey()
          Send an Fn key event to the terminal.
 void setBackKeyCharacter(int keyCode)
          Set the key code to be sent when the Back key is pressed.
 void setColorScheme(ColorScheme scheme)
          Set this EmulatorView's color scheme.
 void setControlKeyCode(int keyCode)
          Set the keycode corresponding to the Ctrl key.
 void setCursorStyle(int style, int blink)
          Sets style information about the cursor.
 void setDensity(DisplayMetrics metrics)
          Update the screen density for the screen on which the view is displayed.
 void setExtGestureListener(GestureDetector.OnGestureListener listener)
          Set a GestureDetector.OnGestureListener to receive gestures performed on this view.
 void setFnKeyCode(int keyCode)
          Set the keycode corresponding to the Fn key.
 void setTextSize(int fontSize)
          Sets the text size, which in turn sets the number of rows and columns.
 void setUseCookedIME(boolean useCookedIME)
          Sets the IME mode ("cooked" or "raw").
 void toggleSelectingText()
          Toggle text selection mode in the view.
 void updateSize(boolean force)
          Update the view's idea of its size.
 
Methods inherited from class android.view.View
addFocusables, addFocusables, addOnLayoutChangeListener, addTouchables, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, cancelLongPress, checkInputConnectionProxy, clearAnimation, clearFocus, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, createContextMenu, destroyDrawingCache, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, draw, drawableStateChanged, findFocus, findViewById, findViewWithTag, fitSystemWindows, focusSearch, forceLayout, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFilterTouchesWhenObscured, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getKeepScreenOn, getKeyDispatcherState, getLayerType, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOverScrollMode, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getPivotX, getPivotY, getResources, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getTranslationX, getTranslationY, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, hasFocus, hasFocusable, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, invalidateDrawable, isActivated, isClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPaddingOffsetRequired, isPressed, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, jumpDrawablesToCurrentState, layout, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAnimationEnd, onAnimationStart, onAttachedToWindow, onConfigurationChanged, onCreateContextMenu, onCreateDrawableState, onDetachedFromWindow, onDisplayHint, onDragEvent, onDrawScrollBars, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onLayout, onMeasure, onOverScrolled, onRestoreInstanceState, onSaveInstanceState, onScrollChanged, onSetAlpha, onStartTemporaryDetach, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, onWindowVisibilityChanged, overScrollBy, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, refreshDrawableState, removeCallbacks, removeOnLayoutChangeListener, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, resolveSizeAndState, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setActivated, setAlpha, setAnimation, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBottom, setClickable, setContentDescription, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFocusable, setFocusableInTouchMode, setHapticFeedbackEnabled, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setId, setKeepScreenOn, setLayerType, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnKeyListener, setOnLongClickListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOverScrollMode, setPadding, setPivotX, setPivotY, setPressed, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollbarFadingEnabled, setScrollBarStyle, setScrollContainer, setSelected, setSoundEffectsEnabled, setSystemUiVisibility, setTag, setTag, setTop, setTouchDelegate, setTranslationX, setTranslationY, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, showContextMenu, startActionMode, startAnimation, startDrag, unscheduleDrawable, unscheduleDrawable, verifyDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmulatorView

public EmulatorView(Context context,
                    TermSession session,
                    DisplayMetrics metrics)
Create an EmulatorView for a TermSession.

Parameters:
context - The Context for the view.
session - The TermSession this view will be displaying.
metrics - The DisplayMetrics of the screen on which the view will be displayed.

EmulatorView

public EmulatorView(Context context,
                    AttributeSet attrs)
Constructor called when inflating this view from XML.

You should call attachSession and setDensity before using an EmulatorView created using this constructor.


EmulatorView

public EmulatorView(Context context,
                    AttributeSet attrs,
                    int defStyle)
Constructor called when inflating this view from XML with a default style set.

You should call attachSession and setDensity before using an EmulatorView created using this constructor.

Method Detail

attachSession

public void attachSession(TermSession session)
Attach a TermSession to this view.

Parameters:
session - The TermSession this view will be displaying.

setDensity

public void setDensity(DisplayMetrics metrics)
Update the screen density for the screen on which the view is displayed.

Parameters:
metrics - The DisplayMetrics of the screen.

onResume

public void onResume()
Inform the view that it is now visible on screen.


onPause

public void onPause()
Inform the view that it is no longer visible on the screen.


setColorScheme

public void setColorScheme(ColorScheme scheme)
Set this EmulatorView's color scheme.

Parameters:
scheme - The ColorScheme to use (use null for the default scheme).
See Also:
TermSession.setColorScheme(jackpal.androidterm.emulatorview.ColorScheme), ColorScheme

onCheckIsTextEditor

public boolean onCheckIsTextEditor()
Overrides:
onCheckIsTextEditor in class View

onCreateInputConnection

public InputConnection onCreateInputConnection(EditorInfo outAttrs)
Overrides:
onCreateInputConnection in class View

getKeypadApplicationMode

public boolean getKeypadApplicationMode()
Get the terminal emulator's keypad application mode.


setExtGestureListener

public void setExtGestureListener(GestureDetector.OnGestureListener listener)
Set a GestureDetector.OnGestureListener to receive gestures performed on this view. Can be used to implement additional functionality via touch gestures or override built-in gestures.

Parameters:
listener - The GestureDetector.OnGestureListener which will receive gestures.

computeVerticalScrollRange

protected int computeVerticalScrollRange()
Compute the vertical range that the vertical scrollbar represents.

Overrides:
computeVerticalScrollRange in class View

computeVerticalScrollExtent

protected int computeVerticalScrollExtent()
Compute the vertical extent of the horizontal scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.

Overrides:
computeVerticalScrollExtent in class View

computeVerticalScrollOffset

protected int computeVerticalScrollOffset()
Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.

Overrides:
computeVerticalScrollOffset in class View

getTermSession

public TermSession getTermSession()
Get the TermSession corresponding to this view.

Returns:
The TermSession object for this view.

getVisibleWidth

public int getVisibleWidth()
Get the width of the visible portion of this view.

Returns:
The width of the visible portion of this view, in pixels.

getVisibleHeight

public int getVisibleHeight()
Get the height of the visible portion of this view.

Returns:
The height of the visible portion of this view, in pixels.

page

public void page(int delta)
Page the terminal view (scroll it up or down by delta screenfuls).

Parameters:
delta - The number of screens to scroll. Positive means scroll down, negative means scroll up.

pageHorizontal

public void pageHorizontal(int deltaColumns)
Page the terminal view horizontally.

Parameters:
deltaColumns - the number of columns to scroll. Positive scrolls to the right.

setTextSize

public void setTextSize(int fontSize)
Sets the text size, which in turn sets the number of rows and columns.

Parameters:
fontSize - the new font size, in density-independent pixels.

setCursorStyle

public void setCursorStyle(int style,
                           int blink)
Sets style information about the cursor.

Parameters:
style - The style of the cursor.
blink - Whether the cursor should blink.

setUseCookedIME

public void setUseCookedIME(boolean useCookedIME)
Sets the IME mode ("cooked" or "raw").

Parameters:
useCookedIME - Whether the IME should be used in cooked mode.

onSingleTapUp

public boolean onSingleTapUp(MotionEvent e)
Specified by:
onSingleTapUp in interface GestureDetector.OnGestureListener

onLongPress

public void onLongPress(MotionEvent e)
Specified by:
onLongPress in interface GestureDetector.OnGestureListener

onScroll

public boolean onScroll(MotionEvent e1,
                        MotionEvent e2,
                        float distanceX,
                        float distanceY)
Specified by:
onScroll in interface GestureDetector.OnGestureListener

onSingleTapConfirmed

public void onSingleTapConfirmed(MotionEvent e)

onJumpTapDown

public boolean onJumpTapDown(MotionEvent e1,
                             MotionEvent e2)

onJumpTapUp

public boolean onJumpTapUp(MotionEvent e1,
                           MotionEvent e2)

onFling

public boolean onFling(MotionEvent e1,
                       MotionEvent e2,
                       float velocityX,
                       float velocityY)
Specified by:
onFling in interface GestureDetector.OnGestureListener

onShowPress

public void onShowPress(MotionEvent e)
Specified by:
onShowPress in interface GestureDetector.OnGestureListener

onDown

public boolean onDown(MotionEvent e)
Specified by:
onDown in interface GestureDetector.OnGestureListener

onTouchEvent

public boolean onTouchEvent(MotionEvent ev)
Overrides:
onTouchEvent in class View

onKeyDown

public boolean onKeyDown(int keyCode,
                         KeyEvent event)
Called when a key is pressed in the view.

Specified by:
onKeyDown in interface KeyEvent.Callback
Overrides:
onKeyDown in class View
Parameters:
keyCode - The keycode of the key which was pressed.
event - A KeyEvent describing the event.
Returns:
Whether the event was handled.

onKeyUp

public boolean onKeyUp(int keyCode,
                       KeyEvent event)
Called when a key is released in the view.

Specified by:
onKeyUp in interface KeyEvent.Callback
Overrides:
onKeyUp in class View
Parameters:
keyCode - The keycode of the key which was released.
event - A KeyEvent describing the event.
Returns:
Whether the event was handled.

onSizeChanged

protected void onSizeChanged(int w,
                             int h,
                             int oldw,
                             int oldh)
This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.

Overrides:
onSizeChanged in class View

updateSize

public void updateSize(boolean force)
Update the view's idea of its size.

Parameters:
force - Whether a size adjustment should be performed even if the view's size has not changed.

onDraw

protected void onDraw(Canvas canvas)
Draw the view to the provided Canvas.

Overrides:
onDraw in class View
Parameters:
canvas - The Canvas to draw the view to.

toggleSelectingText

public void toggleSelectingText()
Toggle text selection mode in the view.


getSelectingText

public boolean getSelectingText()
Whether the view is currently in text selection mode.


getSelectedText

public String getSelectedText()
Get selected text.

Returns:
A String with the selected text.

sendControlKey

public void sendControlKey()
Send a Ctrl key event to the terminal.


sendFnKey

public void sendFnKey()
Send an Fn key event to the terminal. The Fn modifier key can be used to generate various special characters and escape codes.


setBackKeyCharacter

public void setBackKeyCharacter(int keyCode)
Set the key code to be sent when the Back key is pressed.


setControlKeyCode

public void setControlKeyCode(int keyCode)
Set the keycode corresponding to the Ctrl key.


setFnKeyCode

public void setFnKeyCode(int keyCode)
Set the keycode corresponding to the Fn key.