add new class that will be responsible for drawing network status icon

at right end of scoreboard.  It now shows the same icon as the games
list per connection type and gives a stubbed-out status message dialog
when tapped.  Still need to add actual status: when was the last
successful send or receive; and need to add decorations to show
connection state.
This commit is contained in:
Eric House 2012-06-10 07:40:33 -07:00
parent 4fc33fe4e5
commit ac74e2e832
5 changed files with 138 additions and 26 deletions

View file

@ -1406,6 +1406,7 @@ public class BoardActivity extends XWActivity
final int nMissingPlayers )
{
m_connType = connType;
ConnStatusHandler.setType( connType );
int msgID = 0;
int action = 0;

View file

@ -50,6 +50,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
private static final float MIN_FONT_DIPS = 14.0f;
private static final int MULTI_INACTIVE = -1;
private static final boolean FRAME_TRAY_RECTS = false; // for debugging
private static Bitmap s_bitmap; // the board
private static final int IN_TRADE_ALPHA = 0x3FFFFFFF;
@ -193,10 +194,13 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
switch ( action ) {
case MotionEvent.ACTION_DOWN:
m_lastSpacing = MULTI_INACTIVE;
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_DOWN, xx, yy );
if ( !ConnStatusHandler.handleDown( xx, yy ) ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_DOWN, xx, yy );
}
break;
case MotionEvent.ACTION_MOVE:
if ( MULTI_INACTIVE == m_lastSpacing ) {
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 );
@ -207,7 +211,12 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
}
break;
case MotionEvent.ACTION_UP:
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_UP, xx, yy );
if ( ConnStatusHandler.handleUp( xx, yy ) ) {
String msg = ConnStatusHandler.getStatusText();
m_parent.showOKOnlyDialog( msg );
} else {
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_UP, xx, yy );
}
break;
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_POINTER_2_DOWN:
@ -233,6 +242,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
synchronized( this ) {
if ( layoutBoardOnce() ) {
canvas.drawBitmap( s_bitmap, m_left, m_top, m_drawPaint );
ConnStatusHandler.draw( canvas, getResources(), m_left, m_top );
}
}
}
@ -367,17 +377,17 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
public void doIconDraw( int resID, final Rect rect )
{
synchronized( this ) {
if ( null != m_canvas ) {
if ( 0 == resID ) {
fillRectOther( rect, CommonPrefs.COLOR_BACKGRND );
} else {
Drawable icon = getResources().getDrawable( resID );
icon.setBounds( rect );
icon.draw( m_canvas );
}
}
}
// synchronized( this ) {
// if ( null != m_canvas ) {
// if ( 0 == resID ) {
// fillRectOther( rect, CommonPrefs.COLOR_BACKGRND );
// } else {
// Drawable icon = getResources().getDrawable( resID );
// icon.setBounds( rect );
// icon.draw( m_canvas );
// }
// }
// }
}
public void setInTrade( boolean inTrade )
@ -817,6 +827,9 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
}
m_letterRect.offsetTo( rect.left+2, rect.top+2 );
drawCentered( text, m_letterRect, m_fontDims );
if ( FRAME_TRAY_RECTS ) {
m_canvas.drawRect( m_letterRect, m_strokePaint );
}
}
if ( val >= 0 ) {
@ -832,6 +845,9 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
m_fillPaint.setTextAlign( Paint.Align.RIGHT );
m_canvas.drawText( text, m_valRect.right, m_valRect.bottom,
m_fillPaint );
if ( FRAME_TRAY_RECTS ) {
m_canvas.drawRect( m_valRect, m_strokePaint );
}
}
}
}

View file

@ -0,0 +1,98 @@
/* -*- compile-command: "cd ../../../../../; ant debug install"; -*- */
/*
* Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
* rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import org.eehouse.android.xw4.jni.CommsAddrRec;
public class ConnStatusHandler {
private static CommsAddrRec.CommsConnType s_connType =
CommsAddrRec.CommsConnType.COMMS_CONN_NONE;
private static Rect s_rect;
private static boolean s_downOnMe = false;
public static void setRect( int left, int top, int right, int bottom )
{
s_rect = new Rect( left, top, right, bottom );
}
public static void setType( CommsAddrRec.CommsConnType connType )
{
s_connType = connType;
}
public static boolean handleDown( int xx, int yy )
{
s_downOnMe = s_rect.contains( xx, yy );
return s_downOnMe;
}
public static boolean handleUp( int xx, int yy )
{
boolean result = s_downOnMe && s_rect.contains( xx, yy );
s_downOnMe = false;
return result;
}
public static boolean handleMove( int xx, int yy )
{
return s_downOnMe && s_rect.contains( xx, yy );
}
public static String getStatusText()
{
// To be improved :-)
return "You tapped the connection icon.";
}
public static void draw( Canvas canvas, Resources res,
int offsetX, int offsetY )
{
if ( null != s_rect ) {
int iconID;
switch( s_connType ) {
case COMMS_CONN_RELAY:
iconID = R.drawable.relaygame;
break;
case COMMS_CONN_SMS:
iconID = android.R.drawable.sym_action_chat;
break;
case COMMS_CONN_BT:
iconID = android.R.drawable.stat_sys_data_bluetooth;
break;
case COMMS_CONN_NONE:
default:
iconID = R.drawable.sologame;
break;
}
Drawable icon = res.getDrawable( iconID );
Rect rect = new Rect( s_rect );
rect.offset( offsetX, offsetY );
icon.setBounds( rect );
icon.draw( canvas );
}
}
}

View file

@ -135,6 +135,11 @@ public class XWActivity extends Activity
m_delegate.showOKOnlyDialog( msgID );
}
protected void showOKOnlyDialog( String msg )
{
m_delegate.showOKOnlyDialog( msg, 0 );
}
protected void showDictGoneFinish()
{
m_delegate.showDictGoneFinish();

View file

@ -32,6 +32,7 @@ import android.graphics.Rect;
import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.DbgUtils;
import org.eehouse.android.xw4.ConnStatusHandler;
import org.eehouse.android.xw4.BoardDims;
import org.eehouse.android.xw4.GameUtils;
import org.eehouse.android.xw4.DBUtils;
@ -125,7 +126,6 @@ public class JNIThread extends Thread {
private Handler m_handler;
private SyncedDraw m_drawer;
private static final int kMinDivWidth = 10;
private Rect m_connsIconRect;
private int m_connsIconID = 0;
LinkedBlockingQueue<QueueElem> m_queue;
@ -217,14 +217,9 @@ public class JNIThread extends Thread {
private void doLayout( BoardDims dims )
{
int scoreWidth = dims.width;
if ( DeviceRole.SERVER_STANDALONE != m_gi.serverRole ) {
scoreWidth -= dims.cellSize;
m_connsIconRect =
new Rect( scoreWidth, 0, scoreWidth + dims.cellSize,
dims.scoreHt );
}
int scoreWidth = dims.width - dims.cellSize;
ConnStatusHandler.setRect( scoreWidth, 0, scoreWidth + dims.cellSize,
dims.scoreHt );
if ( m_gi.timerEnabled ) {
scoreWidth -= dims.timerWidth;
@ -581,9 +576,6 @@ public class JNIThread extends Thread {
// where it can be synchronized with that class's use
// of the same bitmap for blitting.
m_drawer.doJNIDraw();
if ( null != m_connsIconRect ) {
m_drawer.doIconDraw( m_connsIconID, m_connsIconRect );
}
// main UI thread has to invalidate view as it created
// it.