mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +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
|
@ -586,6 +586,12 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
|
|
||||||
protected boolean isVisible() { return m_isVisible; }
|
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
|
// MultiService.MultiEventListener interface
|
||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
|
@ -681,5 +687,4 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
{
|
{
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,18 @@
|
||||||
|
|
||||||
package org.eehouse.android.xw4;
|
package org.eehouse.android.xw4;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class DualpaneDelegate extends DelegateBase {
|
public class DualpaneDelegate extends DelegateBase {
|
||||||
|
private Activity m_activity;
|
||||||
|
|
||||||
public DualpaneDelegate( Delegator delegator, Bundle sis )
|
public DualpaneDelegate( Delegator delegator, Bundle sis )
|
||||||
{
|
{
|
||||||
super( delegator, sis, R.layout.dualcontainer );
|
super( delegator, sis, R.layout.dualcontainer );
|
||||||
|
m_activity = delegator.getActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,4 +50,13 @@ public class DualpaneDelegate extends DelegateBase {
|
||||||
{
|
{
|
||||||
DlgDelegate.onPrepareDialog( dlgId.ordinal(), dialog );
|
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();
|
getDictForLangIf();
|
||||||
} // init
|
} // init
|
||||||
|
|
||||||
// called when we're brought to the front (probably as a result of
|
@Override
|
||||||
// notification)
|
protected boolean handleNewIntent( Intent intent )
|
||||||
protected void onNewIntent( Intent intent )
|
|
||||||
{
|
{
|
||||||
// super.onNewIntent( intent );
|
DbgUtils.logf( "GamesListDelegate.handleNewIntent(%s)",
|
||||||
|
intent.toString() );
|
||||||
|
|
||||||
m_launchedGames.clear();
|
m_launchedGames.clear();
|
||||||
Assert.assertNotNull( intent );
|
Assert.assertNotNull( intent );
|
||||||
invalRelayIDs( intent.getStringArrayExtra( RELAYIDS_EXTRA ) );
|
invalRelayIDs( intent.getStringArrayExtra( RELAYIDS_EXTRA ) );
|
||||||
reloadGame( intent.getLongExtra( ROWID_EXTRA, -1 ) );
|
reloadGame( intent.getLongExtra( ROWID_EXTRA, -1 ) );
|
||||||
tryStartsFromIntent( intent );
|
tryStartsFromIntent( intent );
|
||||||
|
return true; // handled it
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onStop()
|
protected void onStop()
|
||||||
|
|
|
@ -93,10 +93,56 @@ public class MainActivity extends XWActivity
|
||||||
{
|
{
|
||||||
super.onNewIntent( intent );
|
super.onNewIntent( intent );
|
||||||
|
|
||||||
// HACK!!!!! FIXME
|
m_dlgt.handleNewIntent( intent );
|
||||||
if ( m_dlgt instanceof GamesListDelegate ) {
|
|
||||||
((GamesListDelegate)m_dlgt).onNewIntent( 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 );
|
main.addFragmentForResult( fragment, extras, code );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DelegateBase getDelegate() { return m_dlgt; }
|
||||||
|
|
||||||
// FragActivity.OrientChangeListener
|
// FragActivity.OrientChangeListener
|
||||||
public void orientationChanged()
|
public void orientationChanged()
|
||||||
{
|
{
|
||||||
|
@ -184,5 +186,3 @@ public class XWFragment extends Fragment
|
||||||
return getListView().getAdapter();
|
return getListView().getAdapter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue