hook flip button up with board_canFlip result after every draw() call.

Begin process of moving knowledge of button layout into Toolbar.
This commit is contained in:
Andy2 2010-07-01 18:20:53 -07:00
parent 2f59836fc4
commit 7895325f74
3 changed files with 62 additions and 6 deletions

View file

@ -693,6 +693,8 @@ public class BoardActivity extends Activity implements UtilCtxt {
case JNIThread.QUERY_ENDGAME:
showDialog( QUERY_ENDGAME );
break;
case JNIThread.TOOLBAR_STATES:
m_toolbar.update( msg.arg1, msg.arg2 );
}
}
} );
@ -706,7 +708,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
// setTitle( GameUtils.gameName( this, m_path ) );
m_toolbar =
new Toolbar( findViewById( R.id.toolbar_horizontal ),
new Toolbar( this, findViewById( R.id.toolbar_horizontal ),
findViewById( R.id.toolbar_vertical ) );
boolean isLandscape =

View file

@ -21,18 +21,45 @@
package org.eehouse.android.xw4;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Button;
import android.view.LayoutInflater;
import java.util.HashMap;
import junit.framework.Assert;
import android.widget.ImageButton;
//import android.view.LayoutInflater;
//import java.util.HashMap;
//import junit.framework.Assert;
import org.eehouse.android.xw4.jni.*;
public class Toolbar {
private static class TBButtonInfo {
public TBButtonInfo( int horID, int vertID ) {
m_horID = horID;
m_vertID = vertID;
}
public int m_horID;
public int m_vertID;
}
public static final int BUTTON_HINT_PREV = 0;
public static final int BUTTON_HINT_NEXT = 1;
public static final int BUTTON_FLIP = 2;
private static TBButtonInfo[] s_buttonInfo = {
// BUTTON_HINT_PREV
new TBButtonInfo(R.id.prevhint_button_horizontal,
R.id.prevhint_button_vertical),
// BUTTON_HINT_NEXT
new TBButtonInfo(R.id.nexthint_button_horizontal,
R.id.nexthint_button_vertical),
// BUTTON_FLIP
new TBButtonInfo(R.id.flip_button_horizontal,
R.id.flip_button_vertical),
};
private Activity m_activity;
private LinearLayout m_horLayout;
private LinearLayout m_vertLayout;
@ -42,8 +69,9 @@ public class Toolbar {
};
private ORIENTATION m_curOrient = ORIENTATION.ORIENT_UNKNOWN;
public Toolbar( View horLayout, View vertLayout )
public Toolbar( Activity activity, View horLayout, View vertLayout )
{
m_activity = activity;
m_horLayout = (LinearLayout)horLayout;
m_vertLayout = (LinearLayout)vertLayout;
}
@ -70,4 +98,18 @@ public class Toolbar {
nextLayout.setVisibility( View.VISIBLE );
}
}
public void update( int index, int enable )
{
boolean show = enable!=0;
TBButtonInfo info = s_buttonInfo[index];
int vis = enable != 0 ? View.VISIBLE : View.GONE;
ImageButton button;
button = (ImageButton)m_activity.findViewById( info.m_horID );
button.setVisibility( vis );
button = (ImageButton)m_activity.findViewById( info.m_vertID );
button.setVisibility( vis );
}
}

View file

@ -34,6 +34,7 @@ import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.BoardDims;
import org.eehouse.android.xw4.GameUtils;
import org.eehouse.android.xw4.DBUtils;
import org.eehouse.android.xw4.Toolbar;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
public class JNIThread extends Thread {
@ -79,6 +80,7 @@ public class JNIThread extends Thread {
public static final int DRAW = 2;
public static final int DIALOG = 3;
public static final int QUERY_ENDGAME = 4;
public static final int TOOLBAR_STATES = 5;
private boolean m_stopped = false;
private int m_jniGamePtr;
@ -245,6 +247,13 @@ public class JNIThread extends Thread {
}
}
return draw;
} // processKeyEvent
private void checkButtons()
{
int canFlip = XwJNI.board_canFlip( m_jniGamePtr ) ? 1 : 0;
Message.obtain( m_handler, TOOLBAR_STATES, Toolbar.BUTTON_FLIP,
canFlip ).sendToTarget();
}
public void run()
@ -481,6 +490,8 @@ public class JNIThread extends Thread {
// main UI thread has to invalidate view as it created
// it.
Message.obtain( m_handler, DRAW ).sendToTarget();
checkButtons();
}
}
Utils.logf( "run exiting" );
@ -492,4 +503,5 @@ public class JNIThread extends Thread {
// Utils.logf( "adding: " + cmd.toString() );
m_queue.add( elem );
}
}