mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-10 05:26:10 +01:00
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:
parent
7329cb842d
commit
4f4a84ccf5
3 changed files with 36 additions and 6 deletions
|
@ -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 );
|
||||
|
|
|
@ -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<Integer, WeakReference<DelegateBase>> s_pendings
|
||||
= new HashMap<Integer, WeakReference<DelegateBase>>();
|
||||
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<DlgID, DlgState> 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<DlgID,DlgState>();
|
||||
|
@ -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<DelegateBase>(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<DelegateBase> ref = s_pendings.get( id );
|
||||
DelegateBase dlgt = ref.get();
|
||||
if ( null != dlgt ) {
|
||||
result = dlgt.onCreateDialog( id );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in a new issue