mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
fix NPE: jniThread gets turned to null sometimes, so test
This commit is contained in:
parent
2dd56d08af
commit
d3ce4aa4c7
1 changed files with 42 additions and 40 deletions
|
@ -81,51 +81,53 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent( MotionEvent event )
|
public boolean onTouchEvent( MotionEvent event )
|
||||||
{
|
{
|
||||||
int action = event.getAction();
|
boolean wantMore = null != m_jniThread;
|
||||||
int xx = (int)event.getX();
|
if ( wantMore ) {
|
||||||
int yy = (int)event.getY();
|
int action = event.getAction();
|
||||||
|
int xx = (int)event.getX();
|
||||||
|
int yy = (int)event.getY();
|
||||||
|
|
||||||
switch ( action ) {
|
switch ( action ) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
m_lastSpacing = MULTI_INACTIVE;
|
m_lastSpacing = MULTI_INACTIVE;
|
||||||
if ( !ConnStatusHandler.handleDown( xx, yy ) ) {
|
if ( !ConnStatusHandler.handleDown( xx, yy ) ) {
|
||||||
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_DOWN, xx, yy );
|
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_DOWN, xx, yy );
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
|
||||||
if ( ConnStatusHandler.handleMove( xx, yy ) ) {
|
|
||||||
} else if ( MULTI_INACTIVE == m_lastSpacing ) {
|
|
||||||
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_MOVE, xx, yy );
|
|
||||||
} else {
|
|
||||||
int zoomBy = figureZoom( event );
|
|
||||||
if ( 0 != zoomBy ) {
|
|
||||||
m_jniThread.handle( JNIThread.JNICmd.CMD_ZOOM,
|
|
||||||
zoomBy < 0 ? -2 : 2 );
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case MotionEvent.ACTION_MOVE:
|
||||||
case MotionEvent.ACTION_UP:
|
if ( ConnStatusHandler.handleMove( xx, yy ) ) {
|
||||||
if ( ConnStatusHandler.handleUp( xx, yy ) ) {
|
} else if ( MULTI_INACTIVE == m_lastSpacing ) {
|
||||||
// do nothing
|
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_MOVE, xx, yy );
|
||||||
} else {
|
} else {
|
||||||
|
int zoomBy = figureZoom( event );
|
||||||
|
if ( 0 != zoomBy ) {
|
||||||
|
m_jniThread.handle( JNIThread.JNICmd.CMD_ZOOM,
|
||||||
|
zoomBy < 0 ? -2 : 2 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
if ( ConnStatusHandler.handleUp( xx, yy ) ) {
|
||||||
|
// do nothing
|
||||||
|
} else {
|
||||||
|
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_UP, xx, yy );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
|
case MotionEvent.ACTION_POINTER_2_DOWN:
|
||||||
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_UP, xx, yy );
|
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_UP, xx, yy );
|
||||||
|
m_lastSpacing = getSpacing( event );
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
|
case MotionEvent.ACTION_POINTER_2_UP:
|
||||||
|
m_lastSpacing = MULTI_INACTIVE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DbgUtils.logf( "onTouchEvent: unknown action: %d", action );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
|
||||||
case MotionEvent.ACTION_POINTER_2_DOWN:
|
|
||||||
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_UP, xx, yy );
|
|
||||||
m_lastSpacing = getSpacing( event );
|
|
||||||
break;
|
|
||||||
case MotionEvent.ACTION_POINTER_UP:
|
|
||||||
case MotionEvent.ACTION_POINTER_2_UP:
|
|
||||||
m_lastSpacing = MULTI_INACTIVE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DbgUtils.logf( "onTouchEvent: unknown action: %d", action );
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return wantMore; // true required to get subsequent events
|
||||||
return true; // required to get subsequent events
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void printMode( String comment, int mode )
|
// private void printMode( String comment, int mode )
|
||||||
|
|
Loading…
Add table
Reference in a new issue