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 d392dad5f..dfc324a75 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java @@ -59,7 +59,7 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify, Assert.assertTrue( 0 < menuID ); m_delegator = delegator; m_activity = delegator.getActivity(); - m_delegate = new DlgDelegate( m_activity, this, bundle ); + m_delegate = new DlgDelegate( m_activity, this, this, bundle ); m_layoutID = layoutID; m_optionsMenuID = menuID; LocUtils.xlateTitle( m_activity ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index dd895f57b..57ee29ae7 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -33,8 +33,11 @@ import android.os.Handler; import android.view.View; import android.widget.TextView; import android.widget.Toast; +import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; + import junit.framework.Assert; @@ -117,7 +120,10 @@ public class DlgDelegate { void showNotAgainDlgThen( int msgID, int prefsKey, Action action ); } + private static Map> s_pendings + = new HashMap>(); private Activity m_activity; + private DelegateBase m_dlgt; private DlgClickNotify m_clickCallback; private String m_dictName = null; private ProgressDialog m_progress; @@ -125,10 +131,11 @@ public class DlgDelegate { private HashMap m_dlgStates; - public DlgDelegate( Activity activity, DlgClickNotify callback, - Bundle bundle ) + public DlgDelegate( Activity activity, DelegateBase dlgt, + DlgClickNotify callback, Bundle bundle ) { m_activity = activity; + m_dlgt = dlgt; m_clickCallback = callback; m_handler = new Handler(); m_dlgStates = new HashMap(); @@ -163,7 +170,11 @@ public class DlgDelegate { protected void showDialog( DlgID dlgID ) { - m_activity.showDialog( dlgID.ordinal() ); + int id = dlgID.ordinal(); + if ( m_activity instanceof FragActivity ) { + s_pendings.put( id, new WeakReference(m_dlgt) ); + } + m_activity.showDialog( id ); } public Dialog createDialog( int id ) @@ -212,7 +223,8 @@ public class DlgDelegate { public void showOKOnlyDialog( int msgID ) { - showOKOnlyDialog( LocUtils.getString( m_activity, msgID ), Action.SKIP_CALLBACK ); + showOKOnlyDialog( LocUtils.getString( m_activity, msgID ), + Action.SKIP_CALLBACK ); } public void showDictGoneFinish() @@ -381,7 +393,8 @@ public class DlgDelegate { return true; } - public void eventOccurred( MultiService.MultiEvent event, final Object ... args ) + public void eventOccurred( MultiService.MultiEvent event, + final Object ... args ) { String msg = null; boolean asToast = true; @@ -637,4 +650,14 @@ public class DlgDelegate { m_dlgStates.put( state.m_id, state ); } + public static Dialog onCreateDialog( int id ) + { + Dialog result = null; + WeakReference ref = s_pendings.get( id ); + DelegateBase dlgt = ref.get(); + if ( null != dlgt ) { + result = dlgt.onCreateDialog( id ); + } + return result; + } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/FragActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/FragActivity.java index a4b92367c..84c69c758 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/FragActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/FragActivity.java @@ -20,6 +20,7 @@ package org.eehouse.android.xw4; +import android.app.Dialog; import android.content.res.Configuration; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -97,6 +98,12 @@ public class FragActivity extends FragmentActivity super.onConfigurationChanged( newConfig ); } + @Override + protected Dialog onCreateDialog( int id ) + { + return DlgDelegate.onCreateDialog( id ); + } + ////////////////////////////////////////////////////////////////////// // FragmentManager.OnBackStackChangedListener //////////////////////////////////////////////////////////////////////