mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
add interface to ConnStatusHandler as part of moving UI-based response
into Activity.
This commit is contained in:
parent
dbc1bb1cd5
commit
758c6a6c5c
3 changed files with 41 additions and 14 deletions
|
@ -57,7 +57,8 @@ import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
|
|||
|
||||
public class BoardActivity extends XWActivity
|
||||
implements TransportProcs.TPMsgHandler, View.OnClickListener,
|
||||
DictImportActivity.DownloadFinishedListener {
|
||||
DictImportActivity.DownloadFinishedListener,
|
||||
ConnStatusHandler.ConnStatusCBacks {
|
||||
|
||||
public static final String INTENT_KEY_CHAT = "chat";
|
||||
|
||||
|
@ -560,7 +561,7 @@ public class BoardActivity extends XWActivity
|
|||
protected void onPause()
|
||||
{
|
||||
m_handler = null;
|
||||
ConnStatusHandler.setHandler( null );
|
||||
ConnStatusHandler.setHandler( null, null );
|
||||
waitCloseGame( true );
|
||||
super.onPause();
|
||||
}
|
||||
|
@ -576,12 +577,7 @@ public class BoardActivity extends XWActivity
|
|||
|
||||
loadGame();
|
||||
|
||||
Handler handler = new Handler() {
|
||||
public void handleMessage( Message msg ) {
|
||||
m_view.invalidate();
|
||||
}
|
||||
};
|
||||
ConnStatusHandler.setHandler( handler );
|
||||
ConnStatusHandler.setHandler( m_handler, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1127,6 +1123,28 @@ public class BoardActivity extends XWActivity
|
|||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// ConnStatusHandler.ConnStatusCBacks
|
||||
//////////////////////////////////////////////////
|
||||
public void invalidateParent()
|
||||
{
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
m_view.invalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onStatusClicked()
|
||||
{
|
||||
final String msg = ConnStatusHandler.getStatusText( this, m_connType );
|
||||
post( new Runnable() {
|
||||
public void run() {
|
||||
showOKOnlyDialog( msg );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
private void setGotGameDict( String getDict )
|
||||
{
|
||||
m_jniThread.setSaveDict( getDict );
|
||||
|
|
|
@ -211,9 +211,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
|
|||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if ( ConnStatusHandler.handleUp( xx, yy ) ) {
|
||||
String msg = ConnStatusHandler.getStatusText( m_context,
|
||||
m_connType );
|
||||
m_parent.showOKOnlyDialog( msg );
|
||||
// do nothing
|
||||
} else {
|
||||
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_UP, xx, yy );
|
||||
}
|
||||
|
|
|
@ -43,6 +43,12 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
|||
import org.eehouse.android.xw4.jni.XwJNI;
|
||||
|
||||
public class ConnStatusHandler {
|
||||
|
||||
public interface ConnStatusCBacks {
|
||||
public void invalidateParent();
|
||||
public void onStatusClicked();
|
||||
}
|
||||
|
||||
// private static final int GREEN = 0x7F00FF00;
|
||||
// private static final int RED = 0x7FFF0000;
|
||||
private static final int GREEN = 0xFF00FF00;
|
||||
|
@ -54,6 +60,7 @@ public class ConnStatusHandler {
|
|||
private static Rect s_rect;
|
||||
private static boolean s_downOnMe = false;
|
||||
private static Handler s_handler;
|
||||
private static ConnStatusCBacks s_cbacks;
|
||||
private static Paint s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG );
|
||||
private static boolean[] s_showSuccesses = { false, false };
|
||||
|
||||
|
@ -134,9 +141,10 @@ public class ConnStatusHandler {
|
|||
s_rect = new Rect( left, top, right, bottom );
|
||||
}
|
||||
|
||||
public static void setHandler( Handler handler )
|
||||
public static void setHandler( Handler handler, ConnStatusCBacks cbacks )
|
||||
{
|
||||
s_handler = handler;
|
||||
s_cbacks = cbacks;
|
||||
}
|
||||
|
||||
public static boolean handleDown( int xx, int yy )
|
||||
|
@ -148,6 +156,9 @@ public class ConnStatusHandler {
|
|||
public static boolean handleUp( int xx, int yy )
|
||||
{
|
||||
boolean result = s_downOnMe && s_rect.contains( xx, yy );
|
||||
if ( result && null != s_cbacks ) {
|
||||
s_cbacks.onStatusClicked();
|
||||
}
|
||||
s_downOnMe = false;
|
||||
return result;
|
||||
}
|
||||
|
@ -210,8 +221,8 @@ public class ConnStatusHandler {
|
|||
|
||||
private static void invalidateParent()
|
||||
{
|
||||
if ( null != s_handler ) {
|
||||
Message.obtain( s_handler ).sendToTarget();
|
||||
if ( null != s_cbacks ) {
|
||||
s_cbacks.invalidateParent();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue