@ -13,11 +13,12 @@ public class ControlEventReader {
private static final int SCROLL_PAYLOAD_LENGTH = 20 ;
private static final int SCROLL_PAYLOAD_LENGTH = 20 ;
public static final int TEXT_MAX_LENGTH = 300 ;
public static final int TEXT_MAX_LENGTH = 300 ;
public static final int CLIPBOARD_TEXT_MAX_LENGTH = 4093 ;
private static final int RAW_BUFFER_SIZE = 1024 ;
private static final int RAW_BUFFER_SIZE = 1024 ;
private final byte [ ] rawBuffer = new byte [ RAW_BUFFER_SIZE ] ;
private final byte [ ] rawBuffer = new byte [ RAW_BUFFER_SIZE ] ;
private final ByteBuffer buffer = ByteBuffer . wrap ( rawBuffer ) ;
private final ByteBuffer buffer = ByteBuffer . wrap ( rawBuffer ) ;
private final byte [ ] textBuffer = new byte [ TEXT_MAX_LENGTH] ;
private final byte [ ] textBuffer = new byte [ CLIPBOARD_ TEXT_MAX_LENGTH] ;
public ControlEventReader ( ) {
public ControlEventReader ( ) {
// invariant: the buffer is always in "get" mode
// invariant: the buffer is always in "get" mode
@ -63,6 +64,9 @@ public class ControlEventReader {
case ControlEvent . TYPE_SCROLL :
case ControlEvent . TYPE_SCROLL :
controlEvent = parseScrollControlEvent ( ) ;
controlEvent = parseScrollControlEvent ( ) ;
break ;
break ;
case ControlEvent . TYPE_SET_CLIPBOARD :
controlEvent = parseSetClipboardEvent ( ) ;
break ;
case ControlEvent . TYPE_BACK_OR_SCREEN_ON :
case ControlEvent . TYPE_BACK_OR_SCREEN_ON :
case ControlEvent . TYPE_EXPAND_NOTIFICATION_PANEL :
case ControlEvent . TYPE_EXPAND_NOTIFICATION_PANEL :
case ControlEvent . TYPE_COLLAPSE_NOTIFICATION_PANEL :
case ControlEvent . TYPE_COLLAPSE_NOTIFICATION_PANEL :
@ -132,6 +136,14 @@ public class ControlEventReader {
return ControlEvent . createScrollControlEvent ( position , hScroll , vScroll ) ;
return ControlEvent . createScrollControlEvent ( position , hScroll , vScroll ) ;
}
}
private ControlEvent parseSetClipboardEvent ( ) {
String text = parseString ( ) ;
if ( text = = null ) {
return null ;
}
return ControlEvent . createSetClipboardControlEvent ( text ) ;
}
private static Position readPosition ( ByteBuffer buffer ) {
private static Position readPosition ( ByteBuffer buffer ) {
int x = buffer . getInt ( ) ;
int x = buffer . getInt ( ) ;
int y = buffer . getInt ( ) ;
int y = buffer . getInt ( ) ;