cleanup: reduce number of params required

This commit is contained in:
Eric House 2013-08-10 17:36:37 -07:00
parent 758c6a6c5c
commit de1803c9dd
3 changed files with 67 additions and 53 deletions

View file

@ -980,7 +980,7 @@ public class BoardActivity extends XWActivity
// m_jniThread.handle( JNICmd.CMD_DRAW_BT_STATUS, accepted ); // m_jniThread.handle( JNICmd.CMD_DRAW_BT_STATUS, accepted );
// } // }
ConnStatusHandler. ConnStatusHandler.
updateStatusIn(this, m_handler, updateStatusIn(this, this,
CommsAddrRec.CommsConnType.COMMS_CONN_BT, CommsAddrRec.CommsConnType.COMMS_CONN_BT,
MultiService.MultiEvent.MESSAGE_ACCEPTED == event); MultiService.MultiEvent.MESSAGE_ACCEPTED == event);
break; break;
@ -1017,10 +1017,10 @@ public class BoardActivity extends XWActivity
break; break;
case SMS_SEND_OK: case SMS_SEND_OK:
ConnStatusHandler.showSuccessOut( m_handler ); ConnStatusHandler.showSuccessOut( this );
break; break;
case SMS_RECEIVE_OK: case SMS_RECEIVE_OK:
ConnStatusHandler.showSuccessIn( m_handler ); ConnStatusHandler.showSuccessIn( this );
break; break;
case SMS_SEND_FAILED: case SMS_SEND_FAILED:
case SMS_SEND_FAILED_NORADIO: case SMS_SEND_FAILED_NORADIO:
@ -1145,6 +1145,11 @@ public class BoardActivity extends XWActivity
} ); } );
} }
public Handler getHandler()
{
return m_handler;
}
private void setGotGameDict( String getDict ) private void setGotGameDict( String getDict )
{ {
m_jniThread.setSaveDict( getDict ); m_jniThread.setSaveDict( getDict );

View file

@ -182,7 +182,7 @@ public class CommsTransport implements TransportProcs,
addIncoming(); addIncoming();
} }
ConnStatusHandler. ConnStatusHandler.
updateStatusIn( m_context, m_handler, updateStatusIn( m_context, null,
CommsConnType.COMMS_CONN_RELAY, CommsConnType.COMMS_CONN_RELAY,
0 <= nRead ); 0 <= nRead );
} }
@ -191,7 +191,7 @@ public class CommsTransport implements TransportProcs,
if ( null != m_bytesOut ) { if ( null != m_bytesOut ) {
int nWritten = channel.write( m_bytesOut ); int nWritten = channel.write( m_bytesOut );
ConnStatusHandler. ConnStatusHandler.
updateStatusOut( m_context, m_handler, updateStatusOut( m_context, null,
CommsConnType.COMMS_CONN_RELAY, CommsConnType.COMMS_CONN_RELAY,
0 < nWritten ); 0 < nWritten );
} }
@ -420,21 +420,21 @@ public class CommsTransport implements TransportProcs,
case COMMS_RELAYSTATE_UNCONNECTED: case COMMS_RELAYSTATE_UNCONNECTED:
case COMMS_RELAYSTATE_DENIED: case COMMS_RELAYSTATE_DENIED:
case COMMS_RELAYSTATE_CONNECT_PENDING: case COMMS_RELAYSTATE_CONNECT_PENDING:
ConnStatusHandler.updateStatusOut( m_context, m_handler, ConnStatusHandler.updateStatusOut( m_context, null,
CommsConnType.COMMS_CONN_RELAY, CommsConnType.COMMS_CONN_RELAY,
false ); false );
ConnStatusHandler.updateStatusIn( m_context, m_handler, ConnStatusHandler.updateStatusIn( m_context, null,
CommsConnType.COMMS_CONN_RELAY, CommsConnType.COMMS_CONN_RELAY,
false ); false );
break; break;
case COMMS_RELAYSTATE_CONNECTED: case COMMS_RELAYSTATE_CONNECTED:
case COMMS_RELAYSTATE_RECONNECTED: case COMMS_RELAYSTATE_RECONNECTED:
ConnStatusHandler.updateStatusOut( m_context, m_handler, ConnStatusHandler.updateStatusOut( m_context, null,
CommsConnType.COMMS_CONN_RELAY, CommsConnType.COMMS_CONN_RELAY,
true ); true );
break; break;
case COMMS_RELAYSTATE_ALLCONNECTED: case COMMS_RELAYSTATE_ALLCONNECTED:
ConnStatusHandler.updateStatusIn( m_context, m_handler, ConnStatusHandler.updateStatusIn( m_context, null,
CommsConnType.COMMS_CONN_RELAY, CommsConnType.COMMS_CONN_RELAY,
true ); true );
break; break;

View file

@ -47,6 +47,7 @@ public class ConnStatusHandler {
public interface ConnStatusCBacks { public interface ConnStatusCBacks {
public void invalidateParent(); public void invalidateParent();
public void onStatusClicked(); public void onStatusClicked();
public Handler getHandler();
} }
// private static final int GREEN = 0x7F00FF00; // private static final int GREEN = 0x7F00FF00;
@ -59,7 +60,6 @@ public class ConnStatusHandler {
private static Rect s_rect; private static Rect s_rect;
private static boolean s_downOnMe = false; private static boolean s_downOnMe = false;
private static Handler s_handler;
private static ConnStatusCBacks s_cbacks; private static ConnStatusCBacks s_cbacks;
private static Paint s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG ); private static Paint s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG );
private static boolean[] s_showSuccesses = { false, false }; private static boolean[] s_showSuccesses = { false, false };
@ -143,7 +143,6 @@ public class ConnStatusHandler {
public static void setHandler( Handler handler, ConnStatusCBacks cbacks ) public static void setHandler( Handler handler, ConnStatusCBacks cbacks )
{ {
s_handler = handler;
s_cbacks = cbacks; s_cbacks = cbacks;
} }
@ -225,53 +224,56 @@ public class ConnStatusHandler {
s_cbacks.invalidateParent(); s_cbacks.invalidateParent();
} }
} }
public static void updateStatusIn( Context context, Handler handler, public static void updateStatusIn( Context context, ConnStatusCBacks cbacks,
CommsConnType connType, boolean success ) CommsConnType connType, boolean success )
{ {
synchronized( s_lockObj ) { updateStatusImpl( context, cbacks, connType, success, true );
SuccessRecord record = recordFor( connType, true );
record.update( success );
}
invalidateParent();
saveState( context, handler );
if ( success ) {
showSuccess( handler, true );
}
} }
public static void updateStatusOut( Context context, Handler handler, public static void updateStatusOut( Context context, ConnStatusCBacks cbacks,
CommsConnType connType, boolean success ) CommsConnType connType, boolean success )
{ {
updateStatusImpl( context, cbacks, connType, success, false );
}
public static void updateStatusImpl( Context context, ConnStatusCBacks cbacks,
CommsConnType connType, boolean success,
boolean isIn )
{
if ( null == cbacks ) {
cbacks = s_cbacks;
}
synchronized( s_lockObj ) { synchronized( s_lockObj ) {
SuccessRecord record = recordFor( connType, false ); SuccessRecord record = recordFor( connType, isIn );
record.update( success ); record.update( success );
} }
invalidateParent(); invalidateParent();
saveState( context, handler ); saveState( context, cbacks );
if ( success ) { if ( success ) {
showSuccess( handler, false ); showSuccess( cbacks, isIn );
} }
} }
public static void showSuccessIn( Handler handler ) public static void showSuccessIn( ConnStatusCBacks cbcks )
{ {
showSuccess( handler, true ); showSuccess( cbcks, true );
} }
public static void showSuccessIn() public static void showSuccessIn()
{ {
showSuccessIn( s_handler ); showSuccessIn( s_cbacks );
} }
public static void showSuccessOut( Handler handler ) public static void showSuccessOut( ConnStatusCBacks cbcks )
{ {
showSuccess( handler, false ); showSuccess( cbcks, false );
} }
public static void showSuccessOut() public static void showSuccessOut()
{ {
showSuccessOut( s_handler ); showSuccessOut( s_cbacks );
} }
public static void draw( Context context, Canvas canvas, Resources res, public static void draw( Context context, Canvas canvas, Resources res,
@ -371,9 +373,10 @@ public class ConnStatusHandler {
} }
} }
private static void saveState( final Context context, Handler handler ) private static void saveState( final Context context,
ConnStatusCBacks cbcks )
{ {
if ( null == handler ) { if ( null == cbcks ) {
doSave( context ); doSave( context );
} else { } else {
boolean savePending; boolean savePending;
@ -385,38 +388,44 @@ public class ConnStatusHandler {
} }
if ( !savePending ) { if ( !savePending ) {
Runnable proc = new Runnable() { Handler handler = cbcks.getHandler();
public void run() { if ( null != handler ) {
doSave( context ); Runnable proc = new Runnable() {
} public void run() {
}; doSave( context );
handler.postDelayed( proc, 5000 ); }
};
handler.postDelayed( proc, 5000 );
}
} }
} }
} }
private static void showSuccess( Handler handler, boolean isIn ) private static void showSuccess( ConnStatusCBacks cbcks, boolean isIn )
{ {
if ( null != handler ) { if ( null != cbcks ) {
synchronized( s_lockObj ) { synchronized( s_lockObj ) {
if ( isIn && s_showSuccesses[SUCCESS_IN] ) { if ( isIn && s_showSuccesses[SUCCESS_IN] ) {
// do nothing // do nothing
} else if ( !isIn && s_showSuccesses[SUCCESS_OUT] ) { } else if ( !isIn && s_showSuccesses[SUCCESS_OUT] ) {
// do nothing // do nothing
} else { } else {
final int index = isIn? SUCCESS_IN : SUCCESS_OUT; Handler handler = cbcks.getHandler();
s_showSuccesses[index] = true; if ( null != handler ) {
final int index = isIn? SUCCESS_IN : SUCCESS_OUT;
s_showSuccesses[index] = true;
Runnable proc = new Runnable() { Runnable proc = new Runnable() {
public void run() { public void run() {
synchronized( s_lockObj ) { synchronized( s_lockObj ) {
s_showSuccesses[index] = false; s_showSuccesses[index] = false;
invalidateParent(); invalidateParent();
}
} }
} };
}; handler.postDelayed( proc, SHOW_SUCCESS_INTERVAL );
handler.postDelayed( proc, SHOW_SUCCESS_INTERVAL ); invalidateParent();
invalidateParent(); }
} }
} }
} }