handle orientation changes at least as well as the old dualpane stuff

did. Only obvious problem is that the board doesn't always lay itself
out optimally for its half of the board when orientation changes.
This commit is contained in:
Eric House 2016-07-13 15:50:48 -07:00
parent 325304d83d
commit 7b2392842e
4 changed files with 346 additions and 290 deletions

View file

@ -19,13 +19,14 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.graphics.Rect;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnCancelListener;
import android.content.Intent; import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.graphics.Point;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -250,26 +251,26 @@ public class DelegateBase implements DlgClickNotify,
protected boolean isPortrait() protected boolean isPortrait()
{ {
int[] containerDims = getContainerDims( new int[2] ); Point size = getContainerSize();
boolean result = containerDims[0] < containerDims[1]; boolean result = size.x < size.y;
DbgUtils.logdf( "%s.isPortrait() => %b", DbgUtils.logdf( "%s.isPortrait() => %b",
getClass().getSimpleName(), result ); getClass().getSimpleName(), result );
return result; return result;
} }
protected int[] getContainerDims( int[] outDims ) private Point getContainerSize()
{ {
if ( m_activity instanceof FragActivity ) { Point result = null;
((FragActivity)m_activity).getFragmentDims( outDims ); if ( m_activity instanceof MainActivity ) {
result = ((MainActivity)m_activity).getFragmentSize();
} else { } else {
Rect rect = new Rect(); Rect rect = new Rect();
m_rootView.getWindowVisibleDisplayFrame( rect ); m_rootView.getWindowVisibleDisplayFrame( rect );
outDims[0] = rect.width(); result = new Point( rect.width(), rect.height() );
outDims[1] = rect.height();
} }
DbgUtils.logdf( "%s.getContainerDims(): width => %d, height => %d", DbgUtils.logdf( "%s.getContainerSize(): width => %d, height => %d",
getClass().getSimpleName(), outDims[0], outDims[1] ); getClass().getSimpleName(), result.x, result.y );
return outDims; return result;
} }
protected String getString( int resID, Object... params ) protected String getString( int resID, Object... params )

View file

@ -1,309 +1,309 @@
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */ // /* -*- compile-command: "find-and-ant.sh debug install"; -*- */
/* // /*
* Copyright 2014-2016 by Eric House (xwords@eehouse.org). All rights // * Copyright 2014-2016 by Eric House (xwords@eehouse.org). All rights
* reserved. // * reserved.
* // *
* This program is free software; you can redistribute it and/or // * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as // * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the // * published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version. // * License, or (at your option) any later version.
* // *
* This program is distributed in the hope that it will be useful, but // * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of // * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. // * General Public License for more details.
* // *
* You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software // * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ // */
package org.eehouse.android.xw4; // package org.eehouse.android.xw4;
import android.graphics.Rect; // import android.graphics.Rect;
import android.app.Dialog; // import android.app.Dialog;
import android.content.res.Configuration; // import android.content.res.Configuration;
import android.os.Bundle; // import android.os.Bundle;
import android.support.v4.app.Fragment; // import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; // import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; // import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManager.BackStackEntry; // import android.support.v4.app.FragmentManager.BackStackEntry;
import android.support.v4.app.FragmentTransaction; // import android.support.v4.app.FragmentTransaction;
import android.view.View; // import android.view.View;
import android.widget.FrameLayout; // import android.widget.FrameLayout;
import android.widget.LinearLayout.LayoutParams; // import android.widget.LinearLayout.LayoutParams;
import android.widget.LinearLayout; // import android.widget.LinearLayout;
import android.widget.LinearLayout; // import android.widget.LinearLayout;
import junit.framework.Assert; // import junit.framework.Assert;
public class FragActivity extends FragmentActivity // public class FragActivity extends FragmentActivity
implements FragmentManager.OnBackStackChangedListener { // implements FragmentManager.OnBackStackChangedListener {
private static final int MAX_PANES_LANDSCAPE = 3; // private static final int MAX_PANES_LANDSCAPE = 3;
public interface OrientChangeListener { // // public interface OrientChangeListener {
void orientationChanged(); // // void orientationChanged();
} // // }
private static FragActivity s_this; // private static FragActivity s_this;
private LinearLayout m_root; // private LinearLayout m_root;
private int m_nextID = 0x00FFFFFF; // private int m_nextID = 0x00FFFFFF;
private int m_maxPanes; // private int m_maxPanes;
private Boolean m_isPortrait; // private Boolean m_isPortrait;
@Override // @Override
public void onCreate( Bundle savedInstanceState ) // public void onCreate( Bundle savedInstanceState )
{ // {
s_this = this; // s_this = this;
super.onCreate( savedInstanceState ); // super.onCreate( savedInstanceState );
setContentView( R.layout.dualcontainer ); // setContentView( R.layout.dualcontainer );
m_root = (LinearLayout)findViewById( R.id.main_container ); // m_root = (LinearLayout)findViewById( R.id.main_container );
getSupportFragmentManager().addOnBackStackChangedListener( this ); // getSupportFragmentManager().addOnBackStackChangedListener( this );
m_maxPanes = maxPanes(); // m_maxPanes = maxPanes();
// Nothing to do if we're restarting // // Nothing to do if we're restarting
if ( savedInstanceState == null ) { // if ( savedInstanceState == null ) {
// In case this activity was started with special instructions from an Intent, // // In case this activity was started with special instructions from an Intent,
// pass the Intent's extras to the fragment as arguments // // pass the Intent's extras to the fragment as arguments
addFragmentImpl( new GamesListFrag(), getIntent().getExtras(), null ); // addFragmentImpl( new GamesListFrag(), getIntent().getExtras(), null );
} // }
} // }
@Override // @Override
public void onBackPressed() // public void onBackPressed()
{ // {
DbgUtils.logf( "FragActivity.onBackPressed()" ); // DbgUtils.logf( "FragActivity.onBackPressed()" );
super.onBackPressed(); // super.onBackPressed();
} // }
@Override // @Override
public void onConfigurationChanged( Configuration newConfig ) // public void onConfigurationChanged( Configuration newConfig )
{ // {
Rect rect = new Rect(); // Rect rect = new Rect();
m_root.getWindowVisibleDisplayFrame( rect ); // m_root.getWindowVisibleDisplayFrame( rect );
boolean isPortrait // boolean isPortrait
= Configuration.ORIENTATION_PORTRAIT == newConfig.orientation; // = Configuration.ORIENTATION_PORTRAIT == newConfig.orientation;
DbgUtils.logf( "FragActivity.onConfigurationChanged(isPortrait=%b)", // DbgUtils.logf( "FragActivity.onConfigurationChanged(isPortrait=%b)",
isPortrait ); // isPortrait );
m_isPortrait = isPortrait; // m_isPortrait = isPortrait;
if ( isPortrait != (rect.width() <= rect.height()) ) { // if ( isPortrait != (rect.width() <= rect.height()) ) {
DbgUtils.logdf( "FragActivity.onConfigurationChanged(): isPortrait:" // DbgUtils.logdf( "FragActivity.onConfigurationChanged(): isPortrait:"
+ " %b; width: %d; height: %d", // + " %b; width: %d; height: %d",
isPortrait, rect.width(), rect.height() ); // isPortrait, rect.width(), rect.height() );
} // }
int maxPanes = isPortrait? 1 : MAX_PANES_LANDSCAPE; // int maxPanes = isPortrait? 1 : MAX_PANES_LANDSCAPE;
if ( m_maxPanes != maxPanes ) { // if ( m_maxPanes != maxPanes ) {
m_maxPanes = maxPanes; // m_maxPanes = maxPanes;
setVisiblePanes(); // setVisiblePanes();
} // }
tellOrientationChanged(); // tellOrientationChanged();
super.onConfigurationChanged( newConfig ); // super.onConfigurationChanged( newConfig );
} // }
protected void getFragmentDims( int[] dims ) // protected void getFragmentDims( int[] dims )
{ // {
Rect rect = new Rect(); // Rect rect = new Rect();
m_root.getWindowVisibleDisplayFrame( rect ); // m_root.getWindowVisibleDisplayFrame( rect );
int width = rect.width(); // int width = rect.width();
int height = rect.height(); // int height = rect.height();
if ( null != m_isPortrait && m_isPortrait && height < width ) { // if ( null != m_isPortrait && m_isPortrait && height < width ) {
int tmp = width; // int tmp = width;
width = height; // width = height;
height = tmp; // height = tmp;
} // }
dims[0] = width / Math.min( m_maxPanes, m_root.getChildCount() ); // dims[0] = width / Math.min( m_maxPanes, m_root.getChildCount() );
dims[1] = height; // dims[1] = height;
} // }
@Override // @Override
protected Dialog onCreateDialog( int id ) // protected Dialog onCreateDialog( int id )
{ // {
return DlgDelegate.onCreateDialog( id ); // return DlgDelegate.onCreateDialog( id );
} // }
@Override // @Override
protected void onPrepareDialog( int id, Dialog dialog ) // protected void onPrepareDialog( int id, Dialog dialog )
{ // {
DlgDelegate.onPrepareDialog( id, dialog ); // DlgDelegate.onPrepareDialog( id, dialog );
} // }
////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////
// FragmentManager.OnBackStackChangedListener // // FragmentManager.OnBackStackChangedListener
////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////
public void onBackStackChanged() // public void onBackStackChanged()
{ // {
DbgUtils.logf( "FragActivity.onBackStackChanged()" ); // DbgUtils.logf( "FragActivity.onBackStackChanged()" );
// make sure the right-most are visible // // make sure the right-most are visible
int fragCount = getSupportFragmentManager().getBackStackEntryCount(); // int fragCount = getSupportFragmentManager().getBackStackEntryCount();
if ( 0 == fragCount ) { // if ( 0 == fragCount ) {
finish(); // finish();
} else if ( fragCount == m_root.getChildCount() - 1 ) { // } else if ( fragCount == m_root.getChildCount() - 1 ) {
m_root.removeViewAt( fragCount ); // m_root.removeViewAt( fragCount );
setVisiblePanes(); // setVisiblePanes();
} // }
} // }
// public void launchDictFrag( Bundle args ) // // public void launchDictFrag( Bundle args )
// { // // {
// // DictBrowseFrag dbf = new DictBrowseFrag(); // // // DictBrowseFrag dbf = new DictBrowseFrag();
// // dbf.setArguments( args ); // // // dbf.setArguments( args );
// // addFragment( dbf ); // // // addFragment( dbf );
// } // // }
protected void finishFragment() // protected void finishFragment()
{ // {
popFragment( null ); // popFragment( null );
} // }
protected void popFragment( Fragment frag ) // protected void popFragment( Fragment frag )
{ // {
getSupportFragmentManager().popBackStack(); // getSupportFragmentManager().popBackStack();
} // }
private void addFragmentImpl( Fragment fragment, Bundle bundle, // private void addFragmentImpl( Fragment fragment, Bundle bundle,
Delegator parent ) // Delegator parent )
{ // {
fragment.setArguments( bundle ); // fragment.setArguments( bundle );
addFragmentImpl( fragment, parent ); // addFragmentImpl( fragment, parent );
} // }
private void addFragmentImpl( Fragment fragment, Delegator delegator ) // private void addFragmentImpl( Fragment fragment, Delegator delegator )
{ // {
String newName = fragment.getClass().getName(); // String newName = fragment.getClass().getName();
boolean replace = false; // boolean replace = false;
FragmentManager fm = getSupportFragmentManager(); // FragmentManager fm = getSupportFragmentManager();
int fragCount = fm.getBackStackEntryCount(); // int fragCount = fm.getBackStackEntryCount();
int containerCount = m_root.getChildCount(); // int containerCount = m_root.getChildCount();
DbgUtils.logf( "fragCount: %d; containerCount: %d", fragCount, containerCount ); // DbgUtils.logf( "fragCount: %d; containerCount: %d", fragCount, containerCount );
// Assert.assertTrue( fragCount == containerCount ); // // Assert.assertTrue( fragCount == containerCount );
// Replace IF we're adding something of the same class at right OR if // // Replace IF we're adding something of the same class at right OR if
// we're adding something with the existing left pane as its parent // // we're adding something with the existing left pane as its parent
// (delegator) // // (delegator)
if ( 0 < fragCount ) { // if ( 0 < fragCount ) {
FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt( fragCount - 1 ); // FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt( fragCount - 1 );
String curName = entry.getName(); // String curName = entry.getName();
DbgUtils.logf( "name of last entry: %s", curName ); // DbgUtils.logf( "name of last entry: %s", curName );
replace = curName.equals( newName ); // replace = curName.equals( newName );
if ( !replace && 1 < fragCount ) { // if ( !replace && 1 < fragCount ) {
entry = fm.getBackStackEntryAt( fragCount - 2 ); // entry = fm.getBackStackEntryAt( fragCount - 2 );
curName = entry.getName(); // curName = entry.getName();
String delName = delegator.getClass().getName(); // String delName = delegator.getClass().getName();
DbgUtils.logf( "comparing %s, %s", curName, delName ); // DbgUtils.logf( "comparing %s, %s", curName, delName );
replace = curName.equals( delName ); // replace = curName.equals( delName );
} // }
if ( replace ) { // if ( replace ) {
fm.popBackStack(); // fm.popBackStack();
} // }
} // }
// Replace doesn't seem to work with generated IDs, so we'll create a // // Replace doesn't seem to work with generated IDs, so we'll create a
// new FrameLayout each time. If we're replacing, we'll replace the // // new FrameLayout each time. If we're replacing, we'll replace the
// current rightmost FrameLayout. Otherwise we'll add a new one. // // current rightmost FrameLayout. Otherwise we'll add a new one.
FrameLayout cont = new FrameLayout( this ); // FrameLayout cont = new FrameLayout( this );
cont.setLayoutParams( new LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) ); // cont.setLayoutParams( new LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) );
int id = --m_nextID; // int id = --m_nextID;
cont.setId( id ); // cont.setId( id );
m_root.addView( cont, replace ? containerCount - 1 : containerCount ); // m_root.addView( cont, replace ? containerCount - 1 : containerCount );
if ( !replace && containerCount >= m_maxPanes ) { // if ( !replace && containerCount >= m_maxPanes ) {
int indx = containerCount - m_maxPanes; // int indx = containerCount - m_maxPanes;
View child = m_root.getChildAt( indx ); // View child = m_root.getChildAt( indx );
child.setVisibility( View.GONE ); // child.setVisibility( View.GONE );
setMenuVisibility( child, false ); // setMenuVisibility( child, false );
DbgUtils.logf( "hiding %dth container", indx ); // DbgUtils.logf( "hiding %dth container", indx );
} // }
fm.beginTransaction() // fm.beginTransaction()
.add( id, fragment ) // .add( id, fragment )
.addToBackStack( newName ) // .addToBackStack( newName )
.commit(); // .commit();
// fm.executePendingTransactions(); // // fm.executePendingTransactions();
} // }
private void setVisiblePanes() // private void setVisiblePanes()
{ // {
// hide all but the right-most m_maxPanes children // // hide all but the right-most m_maxPanes children
int nPanes = m_root.getChildCount(); // int nPanes = m_root.getChildCount();
for ( int ii = 0; ii < nPanes; ++ii ) { // for ( int ii = 0; ii < nPanes; ++ii ) {
View child = m_root.getChildAt( ii ); // View child = m_root.getChildAt( ii );
boolean visible = ii >= nPanes - m_maxPanes; // boolean visible = ii >= nPanes - m_maxPanes;
DbgUtils.logf( "pane %d: visible=%b", ii, visible ); // DbgUtils.logf( "pane %d: visible=%b", ii, visible );
child.setVisibility( visible ? View.VISIBLE : View.GONE ); // child.setVisibility( visible ? View.VISIBLE : View.GONE );
setMenuVisibility( child, visible ); // setMenuVisibility( child, visible );
} // }
} // }
private void setMenuVisibility( View cont, boolean visible ) // private void setMenuVisibility( View cont, boolean visible )
{ // {
FrameLayout layout = (FrameLayout)cont; // FrameLayout layout = (FrameLayout)cont;
FragmentManager fm = getSupportFragmentManager(); // FragmentManager fm = getSupportFragmentManager();
int hidingId = layout.getId(); // int hidingId = layout.getId();
Fragment frag = fm.findFragmentById( hidingId ); // Fragment frag = fm.findFragmentById( hidingId );
if ( null != frag ) { // hasn't been popped? // if ( null != frag ) { // hasn't been popped?
frag.setMenuVisibility( visible ); // frag.setMenuVisibility( visible );
} // }
} // }
// Walk all Fragment children and if they care notify of change. // // Walk all Fragment children and if they care notify of change.
private void tellOrientationChanged() // private void tellOrientationChanged()
{ // {
FragmentManager fm = getSupportFragmentManager(); // FragmentManager fm = getSupportFragmentManager();
int nPanes = m_root.getChildCount(); // int nPanes = m_root.getChildCount();
for ( int ii = 0; ii < nPanes; ++ii ) { // for ( int ii = 0; ii < nPanes; ++ii ) {
FrameLayout frame = (FrameLayout)m_root.getChildAt( ii ); // FrameLayout frame = (FrameLayout)m_root.getChildAt( ii );
int id = frame.getId(); // int id = frame.getId();
Fragment frag = fm.findFragmentById( id ); // Fragment frag = fm.findFragmentById( id );
if ( null == frag ) { // if ( null == frag ) {
DbgUtils.logf( "tellOrienationChanged: NO FRAG at %d, id=%d", ii, id ); // DbgUtils.logf( "tellOrienationChanged: NO FRAG at %d, id=%d", ii, id );
} else if ( frag instanceof OrientChangeListener ) { // } else if ( frag instanceof XWFragment ) {
((OrientChangeListener)frag).orientationChanged(); // ((XWFragment)frag).getDelegate().orientationChanged();
} // }
} // }
} // }
private int maxPanes() // private int maxPanes()
{ // {
int result; // int result;
int orientation = getResources().getConfiguration().orientation; // int orientation = getResources().getConfiguration().orientation;
if ( XWPrefs.getIsTablet( this ) // if ( XWPrefs.getIsTablet( this )
&& Configuration.ORIENTATION_LANDSCAPE == orientation ) { // && Configuration.ORIENTATION_LANDSCAPE == orientation ) {
result = 2; // result = 2;
} else { // } else {
result = 1; // result = 1;
} // }
return result; // return result;
} // }
private static FragActivity getThis() // private static FragActivity getThis()
{ // {
Assert.assertNotNull( s_this ); // Assert.assertNotNull( s_this );
return s_this; // return s_this;
} // }
public static void addFragment( Fragment fragment, Bundle bundle ) // public static void addFragment( Fragment fragment, Bundle bundle )
{ // {
addFragment( fragment, bundle, null ); // addFragment( fragment, bundle, null );
} // }
public static void addFragment( Fragment fragment, Bundle bundle, // public static void addFragment( Fragment fragment, Bundle bundle,
Delegator parent ) // Delegator parent )
{ // {
getThis().addFragmentImpl( fragment, bundle, parent ); // getThis().addFragmentImpl( fragment, bundle, parent );
} // }
public static void addFragmentForResult( Fragment fragment, Bundle bundle, // public static void addFragmentForResult( Fragment fragment, Bundle bundle,
RequestCode requestCode, Delegator parent ) // RequestCode requestCode, Delegator parent )
{ // {
getThis().addFragmentImpl( fragment, bundle, parent ); // getThis().addFragmentImpl( fragment, bundle, parent );
} // }
} // }

View file

@ -24,6 +24,7 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -44,6 +45,8 @@ import junit.framework.Assert;
public class MainActivity extends XWActivity public class MainActivity extends XWActivity
implements FragmentManager.OnBackStackChangedListener { implements FragmentManager.OnBackStackChangedListener {
private static final int MAX_PANES_LANDSCAPE = 2;
private DelegateBase m_dlgt; private DelegateBase m_dlgt;
private boolean m_dpEnabled; private boolean m_dpEnabled;
@ -51,6 +54,7 @@ public class MainActivity extends XWActivity
private LinearLayout m_root; private LinearLayout m_root;
private int m_maxPanes; private int m_maxPanes;
private int m_nextID = 0x00FFFFFF; private int m_nextID = 0x00FFFFFF;
private Boolean m_isPortrait;
@Override @Override
protected void onCreate( Bundle savedInstanceState ) protected void onCreate( Bundle savedInstanceState )
@ -96,6 +100,33 @@ public class MainActivity extends XWActivity
m_dlgt.handleNewIntent( intent ); m_dlgt.handleNewIntent( intent );
} }
@Override
public void onConfigurationChanged( Configuration newConfig )
{
if ( m_dpEnabled ) {
Rect rect = new Rect();
m_root.getWindowVisibleDisplayFrame( rect );
boolean isPortrait
= Configuration.ORIENTATION_PORTRAIT == newConfig.orientation;
DbgUtils.logf( "MainActivity.onConfigurationChanged(isPortrait=%b)",
isPortrait );
m_isPortrait = isPortrait;
if ( isPortrait != (rect.width() <= rect.height()) ) {
DbgUtils.logdf( "FragActivity.onConfigurationChanged(): isPortrait:"
+ " %b; width: %d; height: %d",
isPortrait, rect.width(), rect.height() );
}
int maxPanes = isPortrait? 1 : MAX_PANES_LANDSCAPE;
if ( m_maxPanes != maxPanes ) {
m_maxPanes = maxPanes;
setVisiblePanes();
}
tellOrientationChanged();
}
super.onConfigurationChanged( newConfig );
}
/** /**
* Run down the list of fragments until one handles the intent. If no * Run down the list of fragments until one handles the intent. If no
* visible one does, pop hidden ones into view until one of them * visible one does, pop hidden ones into view until one of them
@ -158,6 +189,21 @@ public class MainActivity extends XWActivity
return handled; return handled;
} }
protected Point getFragmentSize()
{
Rect rect = new Rect();
m_root.getWindowVisibleDisplayFrame( rect );
int width = rect.width();
int height = rect.height();
if ( null != m_isPortrait && m_isPortrait && height < width ) {
int tmp = width;
width = height;
height = tmp;
}
return new Point( width / Math.min( m_maxPanes, m_root.getChildCount() ),
height );
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Delegator interface // Delegator interface
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -208,13 +254,30 @@ public class MainActivity extends XWActivity
// Dualpane mode stuff // Dualpane mode stuff
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Walk all Fragment children and if they care notify of change.
private void tellOrientationChanged()
{
FragmentManager fm = getSupportFragmentManager();
int nPanes = m_root.getChildCount();
for ( int ii = 0; ii < nPanes; ++ii ) {
FrameLayout frame = (FrameLayout)m_root.getChildAt( ii );
int id = frame.getId();
Fragment frag = fm.findFragmentById( id );
if ( null == frag ) {
DbgUtils.logf( "tellOrienationChanged: NO FRAG at %d, id=%d", ii, id );
} else if ( frag instanceof XWFragment ) {
((XWFragment)frag).getDelegate().orientationChanged();
}
}
}
private int maxPanes() private int maxPanes()
{ {
int result; int result;
int orientation = getResources().getConfiguration().orientation; int orientation = getResources().getConfiguration().orientation;
if ( XWPrefs.getIsTablet( this ) if ( XWPrefs.getIsTablet( this )
&& Configuration.ORIENTATION_LANDSCAPE == orientation ) { && Configuration.ORIENTATION_LANDSCAPE == orientation ) {
result = 2; result = MAX_PANES_LANDSCAPE;
} else { } else {
result = 1; result = 1;
} }

View file

@ -34,9 +34,7 @@ import android.widget.ListView;
import junit.framework.Assert; import junit.framework.Assert;
public class XWFragment extends Fragment public class XWFragment extends Fragment implements Delegator {
implements Delegator,
FragActivity.OrientChangeListener {
private DelegateBase m_dlgt; private DelegateBase m_dlgt;
private boolean m_hasOptionsMenu = false; private boolean m_hasOptionsMenu = false;
@ -164,12 +162,6 @@ public class XWFragment extends Fragment
public DelegateBase getDelegate() { return m_dlgt; } public DelegateBase getDelegate() { return m_dlgt; }
// FragActivity.OrientChangeListener
public void orientationChanged()
{
m_dlgt.orientationChanged();
}
public ListView getListView() public ListView getListView()
{ {
ListView view = (ListView)m_dlgt.findViewById( android.R.id.list ); ListView view = (ListView)m_dlgt.findViewById( android.R.id.list );