add Toolbar class and use it to hide whichever toolbar isn't wanted in

the current screen orientation.
This commit is contained in:
Andy2 2010-06-26 12:39:10 -07:00
parent 3e9c94118a
commit 29ba0cf4f2
3 changed files with 89 additions and 5 deletions

View file

@ -21,7 +21,8 @@
android:longClickable="true" android:longClickable="true"
android:drawSelectorOnTop="false"/> android:drawSelectorOnTop="false"/>
<LinearLayout android:orientation="horizontal" <LinearLayout android:id="@+id/toolbar_horizontal"
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
> >
@ -37,18 +38,19 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout android:orientation="vertical" <LinearLayout android:id="@+id/toolbar_vertical"
android:orientation="vertical"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_height="fill_parent"
> >
<Button style="@style/toolbar_button" <Button style="@style/toolbar_button"
android:text="1" android:text="4"
/> />
<Button style="@style/toolbar_button" <Button style="@style/toolbar_button"
android:text="2" android:text="5"
/> />
<Button style="@style/toolbar_button" <Button style="@style/toolbar_button"
android:text="3" android:text="6"
/> />
</LinearLayout> </LinearLayout>

View file

@ -66,6 +66,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
private TimerRunnable[] m_timers; private TimerRunnable[] m_timers;
private String m_path; private String m_path;
private int m_currentOrient; private int m_currentOrient;
private Toolbar m_toolbar;
private String m_dlgBytes = null; private String m_dlgBytes = null;
private EditText m_passwdEdit = null; private EditText m_passwdEdit = null;
@ -346,6 +347,11 @@ public class BoardActivity extends Activity implements UtilCtxt {
public void onConfigurationChanged( Configuration newConfig ) public void onConfigurationChanged( Configuration newConfig )
{ {
m_currentOrient = newConfig.orientation; m_currentOrient = newConfig.orientation;
if ( null != m_toolbar ) {
boolean landscape =
m_currentOrient == Configuration.ORIENTATION_LANDSCAPE;
m_toolbar.orientChanged( landscape );
}
super.onConfigurationChanged( newConfig ); super.onConfigurationChanged( newConfig );
} }
@ -694,6 +700,15 @@ public class BoardActivity extends Activity implements UtilCtxt {
m_jniThread.handle( JNICmd.CMD_START ); m_jniThread.handle( JNICmd.CMD_START );
setTitle( GameUtils.gameName( this, m_path ) ); setTitle( GameUtils.gameName( this, m_path ) );
m_toolbar =
new Toolbar( m_jniThread,
findViewById( R.id.toolbar_horizontal ),
findViewById( R.id.toolbar_vertical ) );
boolean isLandscape =
getResources().getConfiguration().orientation
== Configuration.ORIENTATION_LANDSCAPE;
m_toolbar.orientChanged( isLandscape );
} }
} }
} // loadGame } // loadGame

View file

@ -0,0 +1,67 @@
/* -*- compile-command: "cd ../../../../../; ant 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.view.View;
import org.eehouse.android.xw4.jni.*;
public class Toolbar {
private View m_horLayout;
private View m_vertLayout;
private JNIThread m_jniThread;
private enum ORIENTATION { ORIENT_UNKNOWN,
ORIENT_PORTRAIT,
ORIENT_LANDSCAPE,
};
private ORIENTATION m_curOrient = ORIENTATION.ORIENT_UNKNOWN;
public Toolbar( JNIThread jniThread, View horLayout,
View vertLayout )
{
m_jniThread = jniThread;
m_horLayout = horLayout;
m_vertLayout = vertLayout;
}
public void orientChanged( boolean landscape )
{
if ( landscape && m_curOrient == ORIENTATION.ORIENT_LANDSCAPE ) {
// do nothing
} else if ( !landscape && m_curOrient == ORIENTATION.ORIENT_PORTRAIT ) {
// do nothing
} else {
if ( landscape ) {
m_curOrient = ORIENTATION.ORIENT_LANDSCAPE;
m_horLayout.setVisibility( View.GONE );
m_vertLayout.setVisibility( View.VISIBLE );
} else {
m_curOrient = ORIENTATION.ORIENT_PORTRAIT;
m_horLayout.setVisibility( View.VISIBLE );
m_vertLayout.setVisibility( View.GONE );
}
}
}
}