mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
handle notification intents: each delegate gets a chance to handle
them (only GamesListDelegate does), and MainActivity pops fragments/delegates until one's exposed that does.
This commit is contained in:
parent
0c4c1af926
commit
4fc2dd97b3
5 changed files with 76 additions and 10 deletions
|
@ -585,6 +585,12 @@ public class DelegateBase implements DlgClickNotify,
|
|||
}
|
||||
|
||||
protected boolean isVisible() { return m_isVisible; }
|
||||
|
||||
protected boolean handleNewIntent( Intent intent ) {
|
||||
DbgUtils.logf( "%s.handleNewIntent(%s): not handling",
|
||||
getClass().getSimpleName(), intent.toString() );
|
||||
return false; // not handled
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// MultiService.MultiEventListener interface
|
||||
|
@ -681,5 +687,4 @@ public class DelegateBase implements DlgClickNotify,
|
|||
{
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,14 +20,18 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class DualpaneDelegate extends DelegateBase {
|
||||
private Activity m_activity;
|
||||
|
||||
public DualpaneDelegate( Delegator delegator, Bundle sis )
|
||||
{
|
||||
super( delegator, sis, R.layout.dualcontainer );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,4 +50,13 @@ public class DualpaneDelegate extends DelegateBase {
|
|||
{
|
||||
DlgDelegate.onPrepareDialog( dlgId.ordinal(), dialog );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleNewIntent( Intent intent )
|
||||
{
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
boolean handled = main.dispatchNewIntent( intent );
|
||||
DbgUtils.logf( "DualpaneDelegate.handleNewIntent() => %b", handled );
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -955,16 +955,18 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
getDictForLangIf();
|
||||
} // init
|
||||
|
||||
// called when we're brought to the front (probably as a result of
|
||||
// notification)
|
||||
protected void onNewIntent( Intent intent )
|
||||
@Override
|
||||
protected boolean handleNewIntent( Intent intent )
|
||||
{
|
||||
// super.onNewIntent( intent );
|
||||
DbgUtils.logf( "GamesListDelegate.handleNewIntent(%s)",
|
||||
intent.toString() );
|
||||
|
||||
m_launchedGames.clear();
|
||||
Assert.assertNotNull( intent );
|
||||
invalRelayIDs( intent.getStringArrayExtra( RELAYIDS_EXTRA ) );
|
||||
reloadGame( intent.getLongExtra( ROWID_EXTRA, -1 ) );
|
||||
tryStartsFromIntent( intent );
|
||||
return true; // handled it
|
||||
}
|
||||
|
||||
protected void onStop()
|
||||
|
|
|
@ -93,10 +93,56 @@ public class MainActivity extends XWActivity
|
|||
{
|
||||
super.onNewIntent( intent );
|
||||
|
||||
// HACK!!!!! FIXME
|
||||
if ( m_dlgt instanceof GamesListDelegate ) {
|
||||
((GamesListDelegate)m_dlgt).onNewIntent( intent );
|
||||
m_dlgt.handleNewIntent( intent );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* does. Yes, this will take us back to GamesList being visible even if
|
||||
* nothing handles the intent, but at least now all are handled by
|
||||
* GamesList anyway.
|
||||
*/
|
||||
protected boolean dispatchNewIntent( Intent intent )
|
||||
{
|
||||
boolean handled = false;
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
|
||||
// First try non-left-most fragments, if any. Once we've eliminated
|
||||
// them we can just iterate on the leftmost fragment.
|
||||
int nNonLeft = m_maxPanes - 1;
|
||||
// include paged-to-left invisible views
|
||||
int viewCount = m_root.getChildCount();
|
||||
for ( int ii = nNonLeft; !handled && 0 < ii; --ii ) {
|
||||
View child = m_root.getChildAt( viewCount - ii );
|
||||
Fragment frag = fm.findFragmentById( child.getId() );
|
||||
handled = ((XWFragment)frag).getDelegate().handleNewIntent( intent );
|
||||
}
|
||||
|
||||
while ( !handled ) {
|
||||
// Now iterate on the leftmost, popping if necessary to page new
|
||||
// ones into place
|
||||
int childCount = m_root.getChildCount();
|
||||
int hiddenCount = Math.max( 0, childCount - m_maxPanes );
|
||||
for ( int ii = hiddenCount; ii >= 0; --ii ) {
|
||||
View child = m_root.getChildAt( ii );
|
||||
Fragment frag = fm.findFragmentById( child.getId() );
|
||||
// DbgUtils.logf( "left-most case (child %d): %s", hiddenCount,
|
||||
// frag.getClass().getSimpleName() );
|
||||
handled = ((XWFragment)frag).getDelegate()
|
||||
.handleNewIntent( intent );
|
||||
|
||||
if ( handled ) {
|
||||
break;
|
||||
} else if ( ii > 0 ) {
|
||||
DbgUtils.logf( "popping %s",
|
||||
frag.getClass().getSimpleName() );
|
||||
fm.popBackStackImmediate(); // callback removes view
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -162,6 +162,8 @@ public class XWFragment extends Fragment
|
|||
main.addFragmentForResult( fragment, extras, code );
|
||||
}
|
||||
|
||||
public DelegateBase getDelegate() { return m_dlgt; }
|
||||
|
||||
// FragActivity.OrientChangeListener
|
||||
public void orientationChanged()
|
||||
{
|
||||
|
@ -184,5 +186,3 @@ public class XWFragment extends Fragment
|
|||
return getListView().getAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue