mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-20 22:26:54 +01:00
change how games are launched: works to show next to games list! But
there seems to be something wrong with how alerts are being posted.
This commit is contained in:
parent
9865c0c68c
commit
b8b73cc321
6 changed files with 207 additions and 12 deletions
|
@ -28,6 +28,8 @@ public interface Delegator {
|
||||||
Activity getActivity();
|
Activity getActivity();
|
||||||
Bundle getArguments();
|
Bundle getArguments();
|
||||||
void finish();
|
void finish();
|
||||||
|
boolean inDPMode();
|
||||||
|
void addFragment( XWFragment fragment, Bundle extras );
|
||||||
|
|
||||||
// For activities with lists
|
// For activities with lists
|
||||||
void setListAdapter( ListAdapter adapter );
|
void setListAdapter( ListAdapter adapter );
|
||||||
|
|
|
@ -851,11 +851,11 @@ public class GameUtils {
|
||||||
public static void launchGame( Delegator delegator, long rowid,
|
public static void launchGame( Delegator delegator, long rowid,
|
||||||
boolean invited )
|
boolean invited )
|
||||||
{
|
{
|
||||||
Activity activity = delegator.getActivity();
|
|
||||||
Bundle extras = makeLaunchExtras( rowid, invited );
|
Bundle extras = makeLaunchExtras( rowid, invited );
|
||||||
if ( activity instanceof FragActivity ) {
|
if ( delegator.inDPMode() ) {
|
||||||
FragActivity.addFragment( new BoardFrag(), extras, delegator );
|
delegator.addFragment( new BoardFrag(), extras );
|
||||||
} else {
|
} else {
|
||||||
|
Activity activity = delegator.getActivity();
|
||||||
Intent intent = new Intent( activity, BoardActivity.class );
|
Intent intent = new Intent( activity, BoardActivity.class );
|
||||||
intent.putExtras( extras );
|
intent.putExtras( extras );
|
||||||
activity.startActivity( intent );
|
activity.startActivity( intent );
|
||||||
|
|
|
@ -20,28 +20,64 @@
|
||||||
|
|
||||||
package org.eehouse.android.xw4;
|
package org.eehouse.android.xw4;
|
||||||
|
|
||||||
|
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.graphics.Rect;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v4.app.FragmentManager.BackStackEntry;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout.LayoutParams;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.jni.CurGameInfo;
|
import org.eehouse.android.xw4.jni.CurGameInfo;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
public class MainActivity extends XWActivity {
|
public class MainActivity extends XWActivity
|
||||||
|
implements FragmentManager.OnBackStackChangedListener {
|
||||||
private DelegateBase m_dlgt;
|
private DelegateBase m_dlgt;
|
||||||
|
private boolean m_dpEnabled;
|
||||||
|
|
||||||
|
// Used only if m_dpEnabled is true
|
||||||
|
private LinearLayout m_root;
|
||||||
|
private int m_maxPanes;
|
||||||
|
private int m_nextID = 0x00FFFFFF;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate( Bundle savedInstanceState )
|
protected void onCreate( Bundle savedInstanceState )
|
||||||
{
|
{
|
||||||
if ( XWPrefs.dualpaneEnabled( this ) ) {
|
m_dpEnabled = XWPrefs.dualpaneEnabled( this );
|
||||||
|
if ( m_dpEnabled ) {
|
||||||
m_dlgt = new DualpaneDelegate( this, savedInstanceState );
|
m_dlgt = new DualpaneDelegate( this, savedInstanceState );
|
||||||
|
Utils.showToast( this, "dualpane mode" );
|
||||||
} else {
|
} else {
|
||||||
m_dlgt = new GamesListDelegate( this, savedInstanceState );
|
m_dlgt = new GamesListDelegate( this, savedInstanceState );
|
||||||
}
|
}
|
||||||
super.onCreate( savedInstanceState, m_dlgt );
|
super.onCreate( savedInstanceState, m_dlgt );
|
||||||
|
|
||||||
|
if ( m_dpEnabled ) {
|
||||||
|
m_root = (LinearLayout)findViewById( R.id.main_container );
|
||||||
|
getSupportFragmentManager().addOnBackStackChangedListener( this );
|
||||||
|
|
||||||
|
m_maxPanes = maxPanes();
|
||||||
|
|
||||||
|
// Nothing to do if we're restarting
|
||||||
|
if ( savedInstanceState == null ) {
|
||||||
|
// In case this activity was started with special instructions from an Intent,
|
||||||
|
// pass the Intent's extras to the fragment as arguments
|
||||||
|
addFragmentImpl( new GamesListFrag(), getIntent().getExtras(), null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Trying to debug situation where two of this activity are running at
|
// Trying to debug situation where two of this activity are running at
|
||||||
// once. finish()ing when Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT is
|
// once. finish()ing when Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT is
|
||||||
// passed is not the fix, but perhaps there's another
|
// passed is not the fix, but perhaps there's another
|
||||||
|
@ -64,10 +100,139 @@ public class MainActivity extends XWActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// GamesListDelegator interface
|
// Delegator interface
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
public void launchGame( long rowID, boolean invited )
|
@Override
|
||||||
{
|
public boolean inDPMode() {
|
||||||
GameUtils.launchGame( this, rowID, invited );
|
return m_dpEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFragment( XWFragment fragment, Bundle extras )
|
||||||
|
{
|
||||||
|
addFragmentImpl( fragment, extras, this );
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// FragmentManager.OnBackStackChangedListener
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
public void onBackStackChanged()
|
||||||
|
{
|
||||||
|
DbgUtils.logf( "FragActivity.onBackStackChanged()" );
|
||||||
|
// make sure the right-most are visible
|
||||||
|
int fragCount = getSupportFragmentManager().getBackStackEntryCount();
|
||||||
|
if ( 0 == fragCount ) {
|
||||||
|
finish();
|
||||||
|
} else if ( fragCount == m_root.getChildCount() - 1 ) {
|
||||||
|
m_root.removeViewAt( fragCount );
|
||||||
|
setVisiblePanes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// Dualpane mode stuff
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
private int maxPanes()
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
int orientation = getResources().getConfiguration().orientation;
|
||||||
|
if ( XWPrefs.getIsTablet( this )
|
||||||
|
&& Configuration.ORIENTATION_LANDSCAPE == orientation ) {
|
||||||
|
result = 2;
|
||||||
|
} else {
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setVisiblePanes()
|
||||||
|
{
|
||||||
|
// hide all but the right-most m_maxPanes children
|
||||||
|
int nPanes = m_root.getChildCount();
|
||||||
|
for ( int ii = 0; ii < nPanes; ++ii ) {
|
||||||
|
View child = m_root.getChildAt( ii );
|
||||||
|
boolean visible = ii >= nPanes - m_maxPanes;
|
||||||
|
DbgUtils.logf( "pane %d: visible=%b", ii, visible );
|
||||||
|
child.setVisibility( visible ? View.VISIBLE : View.GONE );
|
||||||
|
setMenuVisibility( child, visible );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMenuVisibility( View cont, boolean visible )
|
||||||
|
{
|
||||||
|
FrameLayout layout = (FrameLayout)cont;
|
||||||
|
FragmentManager fm = getSupportFragmentManager();
|
||||||
|
int hidingId = layout.getId();
|
||||||
|
Fragment frag = fm.findFragmentById( hidingId );
|
||||||
|
if ( null != frag ) { // hasn't been popped?
|
||||||
|
frag.setMenuVisibility( visible );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addFragmentImpl( Fragment fragment, Bundle bundle,
|
||||||
|
Delegator parent )
|
||||||
|
{
|
||||||
|
fragment.setArguments( bundle );
|
||||||
|
addFragmentImpl( fragment, parent );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addFragmentImpl( Fragment fragment, Delegator delegator )
|
||||||
|
{
|
||||||
|
String newName = fragment.getClass().getName();
|
||||||
|
boolean replace = false;
|
||||||
|
FragmentManager fm = getSupportFragmentManager();
|
||||||
|
int fragCount = fm.getBackStackEntryCount();
|
||||||
|
int containerCount = m_root.getChildCount();
|
||||||
|
DbgUtils.logf( "fragCount: %d; containerCount: %d", fragCount, containerCount );
|
||||||
|
// Assert.assertTrue( fragCount == containerCount );
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// (delegator)
|
||||||
|
if ( 0 < fragCount ) {
|
||||||
|
FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt( fragCount - 1 );
|
||||||
|
String curName = entry.getName();
|
||||||
|
DbgUtils.logf( "name of last entry: %s", curName );
|
||||||
|
replace = curName.equals( newName );
|
||||||
|
|
||||||
|
if ( !replace && 1 < fragCount ) {
|
||||||
|
entry = fm.getBackStackEntryAt( fragCount - 2 );
|
||||||
|
curName = entry.getName();
|
||||||
|
String delName = delegator.getClass().getName();
|
||||||
|
DbgUtils.logf( "comparing %s, %s", curName, delName );
|
||||||
|
replace = curName.equals( delName );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( replace ) {
|
||||||
|
fm.popBackStack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// current rightmost FrameLayout. Otherwise we'll add a new one.
|
||||||
|
FrameLayout cont = new FrameLayout( this );
|
||||||
|
cont.setLayoutParams( new LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) );
|
||||||
|
int id = --m_nextID;
|
||||||
|
cont.setId( id );
|
||||||
|
m_root.addView( cont, replace ? containerCount - 1 : containerCount );
|
||||||
|
|
||||||
|
if ( !replace && containerCount >= m_maxPanes ) {
|
||||||
|
int indx = containerCount - m_maxPanes;
|
||||||
|
View child = m_root.getChildAt( indx );
|
||||||
|
child.setVisibility( View.GONE );
|
||||||
|
|
||||||
|
setMenuVisibility( child, false );
|
||||||
|
|
||||||
|
DbgUtils.logf( "hiding %dth container", indx );
|
||||||
|
}
|
||||||
|
|
||||||
|
fm.beginTransaction()
|
||||||
|
.add( id, fragment )
|
||||||
|
.addToBackStack( newName )
|
||||||
|
.commit();
|
||||||
|
// fm.executePendingTransactions();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.loc.LocUtils;
|
import org.eehouse.android.xw4.loc.LocUtils;
|
||||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||||
|
|
||||||
|
@ -141,4 +143,7 @@ public class PrefsActivity extends PreferenceActivity
|
||||||
{
|
{
|
||||||
return getIntent().getExtras();
|
return getIntent().getExtras();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean inDPMode() { Assert.fail(); return false; }
|
||||||
|
public void addFragment( XWFragment fragment, Bundle extras ) { Assert.fail(); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import android.app.Dialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
@ -35,9 +36,7 @@ import android.widget.ListView;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
public class XWActivity extends FragmentActivity implements Delegator {
|
||||||
|
|
||||||
public class XWActivity extends Activity implements Delegator {
|
|
||||||
|
|
||||||
private DelegateBase m_dlgt;
|
private DelegateBase m_dlgt;
|
||||||
|
|
||||||
|
@ -222,4 +221,14 @@ public class XWActivity extends Activity implements Delegator {
|
||||||
{
|
{
|
||||||
return getListView().getAdapter();
|
return getListView().getAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean inDPMode() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFragment( XWFragment fragment, Bundle extras )
|
||||||
|
{
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,6 +135,20 @@ public class XWFragment extends Fragment
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inDPMode() {
|
||||||
|
MainActivity main = (MainActivity)getActivity();
|
||||||
|
Assert.assertTrue( main.inDPMode() ); // otherwise should be somewhere else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFragment( XWFragment fragment, Bundle extras )
|
||||||
|
{
|
||||||
|
MainActivity main = (MainActivity)getActivity();
|
||||||
|
main.addFragment( fragment, extras );
|
||||||
|
}
|
||||||
|
|
||||||
// FragActivity.OrientChangeListener
|
// FragActivity.OrientChangeListener
|
||||||
public void orientationChanged()
|
public void orientationChanged()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue