From aef95ae498d11604bc4117599090d2520bca47f7 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 21 Jul 2016 08:47:03 -0700 Subject: [PATCH] dispatch onActivityResult() from DualpaneDelegate Inviting didn't work because it's done by a separate activity whose onActivityResult() was dropped because DualpaneDelegate was the recipient. That now handles it by asking MainActivity to sent it to a contained Delegate. Currently will go only to the top (rightmost) one. --- .../org/eehouse/android/xw4/DelegateBase.java | 3 ++- .../eehouse/android/xw4/DualpaneDelegate.java | 7 +++++ .../org/eehouse/android/xw4/MainActivity.java | 27 ++++++++++++++++--- .../org/eehouse/android/xw4/XWFragment.java | 2 ++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java index 857f5488e..1db2f92c5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java @@ -111,7 +111,8 @@ public class DelegateBase implements DlgClickNotify, protected void onActivityResult( RequestCode requestCode, int resultCode, Intent data ) { - DbgUtils.logf( "DelegateBase.onActivityResult(): subclass responsibility!!!" ); + DbgUtils.logf( "%s.onActivityResult(): subclass responsibility!!!", + getClass().getSimpleName() ); } protected void onResume() diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java index e0aed8a4e..fc62a5e81 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DualpaneDelegate.java @@ -68,4 +68,11 @@ public class DualpaneDelegate extends DelegateBase { DbgUtils.logf( "DualpaneDelegate.handleBackPressed() => %b", handled ); return handled; } + + @Override + protected void onActivityResult( RequestCode requestCode, int resultCode, Intent data ) + { + MainActivity main = (MainActivity)m_activity; + main.dispatchOnActivityResult( requestCode, resultCode, data ); + } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java index d352cbc2b..e47ef5fff 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/MainActivity.java @@ -185,14 +185,25 @@ public class MainActivity extends XWActivity */ protected boolean dispatchBackPressed() { - View child = m_root.getChildAt( m_root.getChildCount() - 1 ); - Fragment frag = getSupportFragmentManager() - .findFragmentById( child.getId() ); + XWFragment frag = getTopFragment(); boolean handled = null != frag - &&((XWFragment)frag).getDelegate().handleBackPressed(); + && frag.getDelegate().handleBackPressed(); return handled; } + protected void dispatchOnActivityResult( RequestCode requestCode, + int resultCode, Intent data ) + { + XWFragment frag = getTopFragment(); + + if ( null != frag ) { + frag.onActivityResult( requestCode.ordinal(), resultCode, data ); + } else { + DbgUtils.logdf( "dispatchOnActivityResult(): can't dispatch %s", + requestCode.toString() ); + } + } + protected Point getFragmentSize() { Rect rect = new Rect(); @@ -305,6 +316,14 @@ public class MainActivity extends XWActivity // Dualpane mode stuff //////////////////////////////////////////////////////////////////////// + private XWFragment getTopFragment() + { + View child = m_root.getChildAt( m_root.getChildCount() - 1 ); + XWFragment frag = (XWFragment)getSupportFragmentManager() + .findFragmentById( child.getId() ); + return frag; + } + // Walk all Fragment children and if they care notify of change. private void tellOrientationChanged() { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java index 87bcbf9ba..8845130b9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWFragment.java @@ -90,6 +90,8 @@ public class XWFragment extends Fragment implements Delegator { @Override public void onResume() { + DbgUtils.logdf( "%s.onResume() called", + this.getClass().getSimpleName() ); super.onResume(); m_dlgt.onResume(); }