mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
fix onResult stuff, at least for game config
This commit is contained in:
parent
5bb707fc57
commit
1ed9dc7c9d
3 changed files with 40 additions and 3 deletions
|
@ -212,7 +212,8 @@ public class DelegateBase implements DlgClickNotify,
|
|||
protected void setResult( int result, Intent intent )
|
||||
{
|
||||
if ( m_activity instanceof MainActivity ) {
|
||||
Assert.fail();
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
main.setFragmentResult( this, result, intent );
|
||||
} else {
|
||||
m_activity.setResult( result, intent );
|
||||
}
|
||||
|
|
|
@ -1213,7 +1213,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
bundle.putLong( GameUtils.INTENT_KEY_ROWID, rowID );
|
||||
bundle.putBoolean( INTENT_FORRESULT_ROWID, true );
|
||||
|
||||
if ( false && delegator.inDPMode() ) {
|
||||
if ( delegator.inDPMode() ) {
|
||||
delegator.addFragmentForResult( new GameConfigFrag(), bundle, requestCode );
|
||||
} else {
|
||||
Activity activity = delegator.getActivity();
|
||||
|
|
|
@ -39,6 +39,11 @@ import android.widget.FrameLayout;
|
|||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eehouse.android.xw4.jni.CurGameInfo;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
@ -56,6 +61,10 @@ public class MainActivity extends XWActivity
|
|||
private int m_nextID = 0x00FFFFFF;
|
||||
private Boolean m_isPortrait;
|
||||
|
||||
// for tracking launchForResult callback recipients
|
||||
private Map<RequestCode, WeakReference<DelegateBase>> m_pendingCodes
|
||||
= new HashMap<RequestCode, WeakReference<DelegateBase>>();
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
|
@ -215,10 +224,37 @@ public class MainActivity extends XWActivity
|
|||
public void addFragmentForResult( XWFragment fragment, Bundle extras,
|
||||
RequestCode requestCode )
|
||||
{
|
||||
DbgUtils.logf( "addFragmentForResult(): dropping requestCode" );
|
||||
DbgUtils.assertOnUIThread();
|
||||
|
||||
WeakReference<DelegateBase> ref
|
||||
= new WeakReference<DelegateBase>(fragment.getDelegate());
|
||||
m_pendingCodes.put( requestCode, ref );
|
||||
|
||||
addFragmentImpl( fragment, extras, this );
|
||||
}
|
||||
|
||||
protected void setFragmentResult( DelegateBase delegate, int resultCode,
|
||||
Intent data )
|
||||
{
|
||||
DbgUtils.assertOnUIThread();
|
||||
RequestCode requestCode = null;
|
||||
Iterator<RequestCode> iter = m_pendingCodes.keySet().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
RequestCode key = iter.next();
|
||||
WeakReference<DelegateBase> ref = m_pendingCodes.get(key);
|
||||
DelegateBase thisOne = ref.get();
|
||||
if ( null != thisOne && thisOne.equals(delegate) ) {
|
||||
requestCode = key;
|
||||
iter.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( null != requestCode ) {
|
||||
delegate.onActivityResult( requestCode, resultCode, data );
|
||||
}
|
||||
}
|
||||
|
||||
protected void finishFragment()
|
||||
{
|
||||
getSupportFragmentManager().popBackStack();
|
||||
|
|
Loading…
Reference in a new issue