fix showDialog to work when parent activity is the FragActivity

(shared by all DelegateBase instances).  Fix is a hack to continue
using old-style managed alerts because the DialogFragment
implementation takes over onDismissListener and onCancelListener and I
use them too much.
This commit is contained in:
Eric House 2014-08-07 06:36:41 -07:00
parent 7329cb842d
commit 4f4a84ccf5
3 changed files with 36 additions and 6 deletions

View file

@ -59,7 +59,7 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
Assert.assertTrue( 0 < menuID ); Assert.assertTrue( 0 < menuID );
m_delegator = delegator; m_delegator = delegator;
m_activity = delegator.getActivity(); 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_layoutID = layoutID;
m_optionsMenuID = menuID; m_optionsMenuID = menuID;
LocUtils.xlateTitle( m_activity ); LocUtils.xlateTitle( m_activity );

View file

@ -33,8 +33,11 @@ import android.os.Handler;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.lang.ref.WeakReference;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import junit.framework.Assert; import junit.framework.Assert;
@ -117,7 +120,10 @@ public class DlgDelegate {
void showNotAgainDlgThen( int msgID, int prefsKey, Action action ); void showNotAgainDlgThen( int msgID, int prefsKey, Action action );
} }
private static Map<Integer, WeakReference<DelegateBase>> s_pendings
= new HashMap<Integer, WeakReference<DelegateBase>>();
private Activity m_activity; private Activity m_activity;
private DelegateBase m_dlgt;
private DlgClickNotify m_clickCallback; private DlgClickNotify m_clickCallback;
private String m_dictName = null; private String m_dictName = null;
private ProgressDialog m_progress; private ProgressDialog m_progress;
@ -125,10 +131,11 @@ public class DlgDelegate {
private HashMap<DlgID, DlgState> m_dlgStates; private HashMap<DlgID, DlgState> m_dlgStates;
public DlgDelegate( Activity activity, DlgClickNotify callback, public DlgDelegate( Activity activity, DelegateBase dlgt,
Bundle bundle ) DlgClickNotify callback, Bundle bundle )
{ {
m_activity = activity; m_activity = activity;
m_dlgt = dlgt;
m_clickCallback = callback; m_clickCallback = callback;
m_handler = new Handler(); m_handler = new Handler();
m_dlgStates = new HashMap<DlgID,DlgState>(); m_dlgStates = new HashMap<DlgID,DlgState>();
@ -163,7 +170,11 @@ public class DlgDelegate {
protected void showDialog( DlgID dlgID ) 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<DelegateBase>(m_dlgt) );
}
m_activity.showDialog( id );
} }
public Dialog createDialog( int id ) public Dialog createDialog( int id )
@ -212,7 +223,8 @@ public class DlgDelegate {
public void showOKOnlyDialog( int msgID ) 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() public void showDictGoneFinish()
@ -381,7 +393,8 @@ public class DlgDelegate {
return true; return true;
} }
public void eventOccurred( MultiService.MultiEvent event, final Object ... args ) public void eventOccurred( MultiService.MultiEvent event,
final Object ... args )
{ {
String msg = null; String msg = null;
boolean asToast = true; boolean asToast = true;
@ -637,4 +650,14 @@ public class DlgDelegate {
m_dlgStates.put( state.m_id, state ); m_dlgStates.put( state.m_id, state );
} }
public static Dialog onCreateDialog( int id )
{
Dialog result = null;
WeakReference<DelegateBase> ref = s_pendings.get( id );
DelegateBase dlgt = ref.get();
if ( null != dlgt ) {
result = dlgt.onCreateDialog( id );
}
return result;
}
} }

View file

@ -20,6 +20,7 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.app.Dialog;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -97,6 +98,12 @@ public class FragActivity extends FragmentActivity
super.onConfigurationChanged( newConfig ); super.onConfigurationChanged( newConfig );
} }
@Override
protected Dialog onCreateDialog( int id )
{
return DlgDelegate.onCreateDialog( id );
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// FragmentManager.OnBackStackChangedListener // FragmentManager.OnBackStackChangedListener
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////