changes, previously committed, to take advantage of new zoom API: hook

up to volume key and to ZoomButtonsController, pass from UI thread to
JNI thread and back, dis/enable buttons based on zoomability, and
remove zoom submenu.
This commit is contained in:
eehouse 2010-04-15 02:16:30 +00:00
parent 7f7af21ff4
commit 7a5b2e10c3
8 changed files with 79 additions and 34 deletions

View file

@ -1,12 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/board_menu_zoomin"
android:title="@string/board_menu_zoomin"
/>
<item android:id="@+id/board_menu_zoomout"
android:title="@string/board_menu_zoomout"
/>
<item android:id="@+id/board_menu_done"
android:title="@string/board_menu_done"
android:alphabeticShortcut="D"
@ -54,6 +48,7 @@
/>
</menu>
</item>
<item android:title="@string/board_submenu_game">
<menu>
<item android:id="@+id/board_menu_game_counts"

View file

@ -72,8 +72,6 @@
<string name="finalscores_title">Final scores</string>
<!-- system menu for main board view -->
<string name="board_menu_zoomin">Zoom in</string>
<string name="board_menu_zoomout">Zoom out</string>
<string name="board_menu_done">Turn done</string>
<string name="board_menu_juggle">Juggle</string>
<string name="board_menu_flip">Flip</string>

View file

@ -56,6 +56,8 @@ public class BoardActivity extends Activity implements UtilCtxt {
private static final int QUERY_ENDGAME = Utils.DIALOG_LAST + 5;
private static final int ASK_PASSWORD_BLK = Utils.DIALOG_LAST + 6;
private static final int ZOOM_AMT = 2;
private BoardView m_view;
private int m_jniGamePtr;
private CurGameInfo m_gi;
@ -309,13 +311,23 @@ public class BoardActivity extends Activity implements UtilCtxt {
@Override
public boolean onKeyDown( int keyCode, KeyEvent event )
{
boolean handled = false;
if ( null != m_jniThread ) {
XwJNI.XP_Key xpKey = keyCodeToXPKey( keyCode );
if ( XwJNI.XP_Key.XP_KEY_NONE != xpKey ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_KEYDOWN, xpKey );
} else {
switch( keyCode ) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
handled = doZoom( -ZOOM_AMT );
break;
case KeyEvent.KEYCODE_VOLUME_UP:
handled = doZoom( ZOOM_AMT );
break;
}
}
}
return super.onKeyDown( keyCode, event );
return handled || super.onKeyDown( keyCode, event );
}
@Override
@ -346,11 +358,6 @@ public class BoardActivity extends Activity implements UtilCtxt {
case R.id.board_menu_done:
cmd = JNIThread.JNICmd.CMD_COMMIT;
break;
case R.id.board_menu_zoomout:
case R.id.board_menu_zoomin:
m_jniThread.handle( JNIThread.JNICmd.CMD_ZOOM,
id == R.id.board_menu_zoomout? -2 : 2 );
break;
case R.id.board_menu_juggle:
cmd = JNIThread.JNICmd.CMD_JUGGLE;
break;
@ -591,6 +598,8 @@ public class BoardActivity extends Activity implements UtilCtxt {
m_xport.setReceiver( m_jniThread );
}
m_jniThread.handle( JNICmd.CMD_START );
// check and disable zoom button at limit
m_jniThread.handle( JNICmd.CMD_ZOOM, 0 );
}
}
} // loadGame
@ -648,6 +657,15 @@ public class BoardActivity extends Activity implements UtilCtxt {
} );
}
private boolean doZoom( int zoomBy )
{
boolean handled = null != m_jniThread;
if ( handled ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_ZOOM, zoomBy );
}
return handled;
}
// This is supposed to be called from the jni thread
public int userPickTile( int playerNum, String[] texts )
{

View file

@ -33,6 +33,8 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.BitmapDrawable;
import android.content.res.Resources;
import android.graphics.Paint.FontMetricsInt;
import android.widget.ZoomButtonsController;
import android.os.Handler;
import java.util.HashMap;
import java.nio.IntBuffer;
@ -60,7 +62,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
private Drawable m_rightArrow;
private Drawable m_downArrow;
private Drawable m_origin;
private int m_top, m_left;
private int m_top;
private JNIThread m_jniThread;
private String[] m_scores;
private String[] m_dictChars;
@ -69,6 +71,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
private int m_dictPtr = 0;
private int m_lastSecsLeft;
private HashMap<String,BitmapDrawable> m_bitmapsCache;
private Handler m_viewHandler;
// FontDims: exists to translate space available to the largest
// font we can draw within that space taking advantage of our use
@ -109,6 +112,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
private int[] m_bonusColors;
private int[] m_playerColors;
private int[] m_otherColors;
private ZoomButtonsController m_zoomButtons;
public BoardView( Context context )
{
@ -131,14 +135,16 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
public boolean onTouchEvent( MotionEvent event )
{
int action = event.getAction();
int xx = (int)event.getX() - m_left;
int xx = (int)event.getX();
int yy = (int)event.getY() - m_top;
switch ( action ) {
case MotionEvent.ACTION_DOWN:
m_zoomButtons.setVisible( true );
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_DOWN, xx, yy );
break;
case MotionEvent.ACTION_MOVE:
m_zoomButtons.setVisible( true );
m_jniThread.handle( JNIThread.JNICmd.CMD_PEN_MOVE, xx, yy );
break;
case MotionEvent.ACTION_UP:
@ -158,11 +164,18 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
{
synchronized( this ) {
if ( layoutBoardOnce() ) {
canvas.drawBitmap( m_bitmap, m_left, m_top, m_drawPaint );
canvas.drawBitmap( m_bitmap, 0, m_top, m_drawPaint );
}
}
}
@Override
protected void onDetachedFromWindow()
{
m_zoomButtons.setVisible( false );
super.onDetachedFromWindow();
}
private void init()
{
m_drawPaint = new Paint();
@ -190,6 +203,22 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
m_playerColors = prefs.playerColors;
m_bonusColors = prefs.bonusColors;
m_otherColors = prefs.otherColors;
m_viewHandler = new Handler();
m_zoomButtons = new ZoomButtonsController( this );
ZoomButtonsController.OnZoomListener lstnr =
new ZoomButtonsController.OnZoomListener(){
public void onVisibilityChanged( boolean visible ){}
public void onZoom( boolean zoomIn )
{
if ( null != m_jniThread ) {
int zoomBy = zoomIn ? 2 : -2;
m_jniThread.handle( JNIThread.JNICmd.CMD_ZOOM, zoomBy );
}
}
};
m_zoomButtons.setOnZoomListener( lstnr );
m_zoomButtons.setZoomSpeed( 100 ); // milliseconds
}
private boolean layoutBoardOnce()
@ -208,7 +237,6 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
int nCells = m_gi.boardSize;
int cellSize = width / nCells;
m_left = (width % nCells) / 2;
// If we're vertical, we can likely fit all the board and
// have a tall tray too. If horizontal, let's assume
@ -231,7 +259,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
m_top = 0;
}
m_bitmap = Bitmap.createBitmap( 1 + (cellSize*nCells),
m_bitmap = Bitmap.createBitmap( 1 + width,
1 + trayHt + scoreHt
+ (cellSize *(nCells-nToScroll)),
Bitmap.Config.ARGB_8888 );
@ -288,6 +316,16 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
}
}
public void zoomChanged( final boolean[] canZoom )
{
m_viewHandler.post( new Runnable() {
public void run() {
m_zoomButtons.setZoomInEnabled( canZoom[0] );
m_zoomButtons.setZoomOutEnabled( canZoom[1] );
}
} );
}
// DrawCtxt interface implementation
public void scoreBegin( Rect rect, int numPlayers, int[] scores,
int remCount, int dfs )
@ -382,12 +420,6 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
}
}
public boolean boardBegin( Rect rect, int cellWidth, int cellHeight,
int dfs )
{
return true;
}
public boolean drawCell( Rect rect, String text, BitmapDrawable[] bitmaps,
int tile, int owner, int bonus, int hintAtts,
int flags )

View file

@ -49,7 +49,6 @@ public interface DrawCtx {
void score_drawPlayer( Rect rInner, Rect rOuter, DrawScoreInfo dsi );
void drawTimer( Rect rect, int player, int secondsLeft );
boolean boardBegin( Rect rect, int cellWidth, int cellHeight, int dfs );
boolean drawCell( Rect rect, String text, BitmapDrawable[] bitmaps, int tile,
int owner, int bonus, int hintAtts, int flags );
void drawBoardArrow ( Rect rect, int bonus, boolean vert, int hintAtts,

View file

@ -163,7 +163,7 @@ public class JNIThread extends Thread {
trayHt = height - (cellSize * (1 + (nCells-nToScroll)));
}
int scoreWidth = nCells * cellSize;
int scoreWidth = width;
if ( DeviceRole.SERVER_STANDALONE != m_gi.serverRole ) {
scoreWidth -= cellSize;
@ -185,14 +185,12 @@ public class JNIThread extends Thread {
scoreHt, true );
XwJNI.board_setPos( m_jniGamePtr, 0, scoreHt,
width, scoreHt + ((nCells-nToScroll) * cellSize),
width-1, ((nCells-nToScroll) * cellSize),
false );
XwJNI.board_setTrayLoc( m_jniGamePtr, 0,
scoreHt + ((nCells-nToScroll) * cellSize),
nCells * cellSize, // width
trayHt, // height
kMinDivWidth );
width, trayHt, kMinDivWidth );
XwJNI.board_invalAll( m_jniGamePtr );
}
@ -260,7 +258,7 @@ public class JNIThread extends Thread {
public void run()
{
boolean[] barr = new boolean[1]; // scratch boolean
boolean[] barr = new boolean[2]; // scratch boolean
while ( !m_stopped ) {
QueueElem elem;
Object[] args;
@ -382,7 +380,9 @@ public class JNIThread extends Thread {
case CMD_ZOOM:
draw = XwJNI.board_zoom( m_jniGamePtr,
((Integer)args[0]).intValue() );
((Integer)args[0]).intValue(),
barr );
m_drawer.zoomChanged( barr );
break;
case CMD_VALUES:

View file

@ -1,3 +1,4 @@
/* -*- compile-command: "cd ../../../../../../; ant install"; -*- */
/*
* Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
* rights reserved.
@ -25,4 +26,5 @@ public interface SyncedDraw {
void doJNIDraw();
void doIconDraw( int resID, final Rect rect );
void prefsChanged();
void zoomChanged( boolean[] canZoom );
}

View file

@ -96,7 +96,8 @@ public class XwJNI {
public static native void board_setPos( int gamePtr, int left, int top,
int width, int height,
boolean lefty );
public static native boolean board_zoom( int gamePtr, int zoomBy );
public static native boolean board_zoom( int gamePtr, int zoomBy,
boolean[] canZoom );
public static native void board_setScoreboardLoc( int gamePtr, int left,
int top, int width,
int height,