mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
launch DictsActivity for result, and have it return the last language
and wordlist downloaded. Use that information to update the spinner that launched it so that choosing "download more" then downloading a German wordlist causes German to be selected.
This commit is contained in:
parent
c31697ea47
commit
509dfb4b4f
11 changed files with 138 additions and 85 deletions
|
@ -42,12 +42,6 @@ public class BoardActivity extends XWActivity {
|
|||
}
|
||||
} // onCreate
|
||||
|
||||
@Override
|
||||
protected void onActivityResult( int requestCode, int resultCode, Intent data )
|
||||
{
|
||||
m_dlgt.onActivityResult( requestCode, resultCode, data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged( boolean hasFocus )
|
||||
{
|
||||
|
|
|
@ -1138,7 +1138,8 @@ public class BoardDelegate extends DelegateBase
|
|||
//////////////////////////////////////////////////
|
||||
// DwnldActivity.DownloadFinishedListener interface
|
||||
//////////////////////////////////////////////////
|
||||
public void downloadFinished( final String name, final boolean success )
|
||||
public void downloadFinished( String lang, final String name,
|
||||
boolean success )
|
||||
{
|
||||
if ( success ) {
|
||||
post( new Runnable() {
|
||||
|
|
|
@ -68,14 +68,11 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
|
|||
protected void onDestroy() {}
|
||||
protected boolean onBackPressed() { return false; }
|
||||
protected void prepareDialog( DlgID dlgID, Dialog dialog ) {}
|
||||
|
||||
// public boolean onOptionsItemSelected( MenuItem item )
|
||||
// {
|
||||
// }
|
||||
protected void onActivityResult( int requestCode, int resultCode,
|
||||
Intent data ) {}
|
||||
|
||||
public boolean onCreateOptionsMenu( Menu menu )
|
||||
{
|
||||
DbgUtils.logf( "DelegateBase.onCreateOptionsMenu()" );
|
||||
boolean handled = 0 < m_optionsMenuID;
|
||||
if ( handled ) {
|
||||
m_activity.getMenuInflater().inflate( m_optionsMenuID, menu );
|
||||
|
|
|
@ -74,6 +74,9 @@ public class DictsDelegate extends ListDelegateBase
|
|||
protected static final String DICT_SHOWREMOTE = "do_launch";
|
||||
protected static final String DICT_LANG_EXTRA = "use_lang";
|
||||
protected static final String DICT_NAME_EXTRA = "use_dict";
|
||||
protected static final String RESULT_LAST_LANG = "last_lang";
|
||||
protected static final String RESULT_LAST_DICT = "last_dict";
|
||||
|
||||
private static final int SEL_LOCAL = 0;
|
||||
private static final int SEL_REMOTE = 1;
|
||||
|
||||
|
@ -94,6 +97,8 @@ public class DictsDelegate extends ListDelegateBase
|
|||
private Map<String, String> m_needUpdates;
|
||||
private HashMap<String, XWListItem> m_curDownloads;
|
||||
private String m_onServerStr;
|
||||
private String m_lastLang;
|
||||
private String m_lastDict;
|
||||
|
||||
private static class DictInfo implements Comparable {
|
||||
public String m_name;
|
||||
|
@ -530,6 +535,15 @@ public class DictsDelegate extends ListDelegateBase
|
|||
boolean handled = 0 < m_selDicts.size();
|
||||
if ( handled ) {
|
||||
clearSelections();
|
||||
} else {
|
||||
Intent intent = new Intent();
|
||||
if ( null != m_lastLang ) {
|
||||
intent.putExtra( RESULT_LAST_LANG, m_lastLang );
|
||||
}
|
||||
if ( null != m_lastDict ) {
|
||||
intent.putExtra( RESULT_LAST_DICT, m_lastDict );
|
||||
}
|
||||
setResult( Activity.RESULT_OK, intent );
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
@ -930,8 +944,8 @@ public class DictsDelegate extends ListDelegateBase
|
|||
// return mkDownloadIntent( context, dict_url );
|
||||
}
|
||||
|
||||
public static void launchForDownload( Activity activity, int lang,
|
||||
String name )
|
||||
public static void launchForResult( Activity activity, int requestCode,
|
||||
int lang, String name )
|
||||
{
|
||||
Intent intent = new Intent( activity, DictsActivity.class );
|
||||
intent.putExtra( DICT_SHOWREMOTE, true );
|
||||
|
@ -943,24 +957,31 @@ public class DictsDelegate extends ListDelegateBase
|
|||
intent.putExtra( DICT_NAME_EXTRA, name );
|
||||
}
|
||||
|
||||
activity.startActivity( intent );
|
||||
activity.startActivityForResult( intent, requestCode );
|
||||
}
|
||||
|
||||
public static void launchForDownload( Activity activity, int lang )
|
||||
public static void launchForResult( Activity activity, int requestCode,
|
||||
int lang )
|
||||
{
|
||||
launchForDownload( activity, lang, null );
|
||||
launchForResult( activity, requestCode, lang, null );
|
||||
}
|
||||
|
||||
public static void launchForDownload( Activity activity )
|
||||
public static void launchForResult( Activity activity, int requestCode )
|
||||
{
|
||||
launchForDownload( activity, 0, null );
|
||||
launchForResult( activity, requestCode, 0, null );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// DwnldActivity.DownloadFinishedListener interface
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public void downloadFinished( final String name, final boolean success )
|
||||
public void downloadFinished( String lang, final String name,
|
||||
final boolean success )
|
||||
{
|
||||
if ( success && m_showRemote ) {
|
||||
m_lastLang = lang;
|
||||
m_lastDict = name;
|
||||
}
|
||||
|
||||
if ( m_launchedForMissing ) {
|
||||
post( new Runnable() {
|
||||
public void run() {
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
|
@ -57,7 +58,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
private ArrayList<LinearLayout> m_views;
|
||||
|
||||
public interface DownloadFinishedListener {
|
||||
void downloadFinished( String name, boolean success );
|
||||
void downloadFinished( String lang, String name, boolean success );
|
||||
}
|
||||
|
||||
public DwnldDelegate( ListActivity activity, Bundle savedInstanceState )
|
||||
|
@ -298,6 +299,14 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
return new File(path).getName();
|
||||
}
|
||||
|
||||
private static String langFromUrl( String url )
|
||||
{
|
||||
String[] parts = TextUtils.split( url, "/" );
|
||||
String result = parts[parts.length - 2];
|
||||
// DbgUtils.logf( "langFromUrl(%s) => %s", url, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void rememberListener( String url, String name,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
|
@ -328,10 +337,11 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
}
|
||||
if ( null != ld ) {
|
||||
String name = ld.m_name;
|
||||
String lang = langFromUrl( url );
|
||||
if ( null == name ) {
|
||||
name = uri.toString();
|
||||
}
|
||||
ld.m_lstnr.downloadFinished( name, success );
|
||||
ld.m_lstnr.downloadFinished( lang, name, success );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,8 @@ public class GameConfigDelegate extends DelegateBase
|
|||
,RefreshNamesTask.NoNameFound {
|
||||
|
||||
private static final String WHICH_PLAYER = "WHICH_PLAYER";
|
||||
private static final int REQUEST_LANG = 1;
|
||||
private static final int REQUEST_DICT = 2;
|
||||
|
||||
private Activity m_activity;
|
||||
private CheckBox m_joinPublicCheck;
|
||||
|
@ -74,6 +76,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
private View m_connectSetRelay;
|
||||
private View m_connectSetSMS;
|
||||
private Spinner m_dictSpinner;
|
||||
private Spinner m_playerDictSpinner;
|
||||
private Spinner m_roomChoose;
|
||||
// private Button m_configureButton;
|
||||
private long m_rowid;
|
||||
|
@ -314,11 +317,12 @@ public class GameConfigDelegate extends DelegateBase
|
|||
} else {
|
||||
dictLabel.setVisibility( View.GONE );
|
||||
}
|
||||
Spinner dictSpinner = (Spinner)dialog.findViewById( R.id.dict_spinner );
|
||||
m_playerDictSpinner = (Spinner)dialog.findViewById( R.id.dict_spinner );
|
||||
if ( localOnlyGame() ) {
|
||||
configDictSpinner( dictSpinner, m_gi.dictLang, m_gi.dictName(lp) );
|
||||
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, m_gi.dictName(lp) );
|
||||
} else {
|
||||
dictSpinner.setVisibility( View.GONE );
|
||||
m_playerDictSpinner.setVisibility( View.GONE );
|
||||
m_playerDictSpinner = null;
|
||||
}
|
||||
|
||||
final View localSet = dialog.findViewById( R.id.local_player_set );
|
||||
|
@ -364,10 +368,13 @@ public class GameConfigDelegate extends DelegateBase
|
|||
lp.password = Utils.getText( dialog, R.id.password_edit );
|
||||
|
||||
if ( localOnlyGame() ) {
|
||||
{
|
||||
Spinner spinner =
|
||||
(Spinner)((Dialog)di).findViewById( R.id.dict_spinner );
|
||||
int position = spinner.getSelectedItemPosition();
|
||||
SpinnerAdapter adapter = spinner.getAdapter();
|
||||
Assert.assertTrue( m_playerDictSpinner == spinner );
|
||||
}
|
||||
int position = m_playerDictSpinner.getSelectedItemPosition();
|
||||
SpinnerAdapter adapter = m_playerDictSpinner.getAdapter();
|
||||
|
||||
if ( null != adapter && position < adapter.getCount() ) {
|
||||
String name = (String)adapter.getItem( position );
|
||||
|
@ -417,11 +424,10 @@ public class GameConfigDelegate extends DelegateBase
|
|||
m_playButton.setOnClickListener( this );
|
||||
|
||||
m_playerLayout = (LinearLayout)findViewById( R.id.player_list );
|
||||
m_langSpinner = (Spinner)findViewById( R.id.lang_spinner );
|
||||
m_phoniesSpinner = (Spinner)findViewById( R.id.phonies_spinner );
|
||||
m_boardsizeSpinner = (Spinner)findViewById( R.id.boardsize_spinner );
|
||||
m_smartnessSpinner = (Spinner)findViewById( R.id.smart_robot );
|
||||
} // onCreate
|
||||
} // init
|
||||
|
||||
protected void onStart()
|
||||
{
|
||||
|
@ -449,6 +455,25 @@ public class GameConfigDelegate extends DelegateBase
|
|||
outState.putInt( WHICH_PLAYER, m_whichPlayer );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult( int requestCode, int resultCode, Intent data )
|
||||
{
|
||||
if ( Activity.RESULT_CANCELED != resultCode ) {
|
||||
switch( requestCode ) {
|
||||
case REQUEST_DICT:
|
||||
String dictName = data.getStringExtra( DictsDelegate.RESULT_LAST_DICT );
|
||||
setSpinnerSelection( m_playerDictSpinner, dictName );
|
||||
break;
|
||||
case REQUEST_LANG:
|
||||
String langName = data.getStringExtra( DictsDelegate.RESULT_LAST_LANG );
|
||||
setSpinnerSelection( m_langSpinner, langName );
|
||||
break;
|
||||
default:
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadGame()
|
||||
{
|
||||
if ( null == m_giOrig ) {
|
||||
|
@ -740,7 +765,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
(String)parentView.getItemAtPosition( position );
|
||||
|
||||
if ( chosen.equals( m_browseText ) ) {
|
||||
DictsDelegate.launchForDownload( m_activity,
|
||||
DictsDelegate.launchForResult( m_activity, REQUEST_DICT,
|
||||
m_gi.dictLang );
|
||||
}
|
||||
}
|
||||
|
@ -757,6 +782,9 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
private void configLangSpinner()
|
||||
{
|
||||
if ( null == m_langSpinner ) {
|
||||
m_langSpinner = (Spinner)findViewById( R.id.lang_spinner );
|
||||
|
||||
OnItemSelectedListener onSel =
|
||||
new OnItemSelectedListener() {
|
||||
@Override
|
||||
|
@ -766,7 +794,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
String chosen =
|
||||
(String)parentView.getItemAtPosition( position );
|
||||
if ( chosen.equals( m_browseText ) ) {
|
||||
DictsDelegate.launchForDownload( m_activity );
|
||||
DictsDelegate.launchForResult( m_activity, REQUEST_LANG );
|
||||
} else {
|
||||
m_gi.setLang( DictLangCache.
|
||||
getLangLangCode( m_activity,
|
||||
|
@ -783,14 +811,14 @@ public class GameConfigDelegate extends DelegateBase
|
|||
public void onNothingSelected(AdapterView<?> parentView) {}
|
||||
};
|
||||
|
||||
ArrayAdapter<String> adapter =
|
||||
DictLangCache.getLangsAdapter( m_activity );
|
||||
ArrayAdapter adapter = DictLangCache.getLangsAdapter( m_activity );
|
||||
String lang = DictLangCache.getLangName( m_activity, m_gi.dictLang );
|
||||
configSpinnerWDownload( m_langSpinner, adapter, onSel, lang );
|
||||
}
|
||||
}
|
||||
|
||||
private void configSpinnerWDownload( Spinner spinner,
|
||||
ArrayAdapter<String> adapter,
|
||||
ArrayAdapter adapter,
|
||||
OnItemSelectedListener onSel,
|
||||
String curSel )
|
||||
{
|
||||
|
@ -798,17 +826,17 @@ public class GameConfigDelegate extends DelegateBase
|
|||
adapter.setDropDownViewResource( resID );
|
||||
spinner.setAdapter( adapter );
|
||||
spinner.setOnItemSelectedListener( onSel );
|
||||
setSpinnerSelection( spinner, adapter, curSel );
|
||||
setSpinnerSelection( spinner, curSel );
|
||||
}
|
||||
|
||||
private void setSpinnerSelection( Spinner spinner,
|
||||
ArrayAdapter<String> adapter,
|
||||
String sel )
|
||||
private void setSpinnerSelection( Spinner spinner, String sel )
|
||||
{
|
||||
if ( null != sel ) {
|
||||
for ( int ii = 0; ii < adapter.getCount(); ++ii ) {
|
||||
if ( null != sel && null != spinner ) {
|
||||
SpinnerAdapter adapter = spinner.getAdapter();
|
||||
int count = adapter.getCount();
|
||||
for ( int ii = 0; ii < count; ++ii ) {
|
||||
if ( sel.equals( adapter.getItem( ii ) ) ) {
|
||||
spinner.setSelection( ii );
|
||||
spinner.setSelection( ii, true );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
public void onClick( DialogInterface dlg, int item ) {
|
||||
// no name, so user must pick
|
||||
if ( null == m_missingDictName ) {
|
||||
DictsDelegate.launchForDownload( m_activity,
|
||||
DictsDelegate.launchForResult( m_activity,
|
||||
m_missingDictLang );
|
||||
} else {
|
||||
DwnldDelegate
|
||||
|
@ -879,7 +879,8 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
// DwnldActivity.DownloadFinishedListener interface
|
||||
public void downloadFinished( String name, final boolean success )
|
||||
public void downloadFinished( String lang, String name,
|
||||
final boolean success )
|
||||
{
|
||||
post( new Runnable() {
|
||||
public void run() {
|
||||
|
|
|
@ -41,11 +41,4 @@ public class NewGameActivity extends XWActivity {
|
|||
super.onWindowFocusChanged( hasFocus );
|
||||
m_dlgt.onWindowFocusChanged( hasFocus );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult( int requestCode, int resultCode,
|
||||
Intent data )
|
||||
{
|
||||
m_dlgt.onActivityResult( requestCode, resultCode, data );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,4 @@ public class SMSInviteActivity extends InviteActivity {
|
|||
m_dlgt = new SMSInviteDelegate( this, savedInstanceState );
|
||||
super.onCreate( savedInstanceState, m_dlgt );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult( int requestCode, int resultCode,
|
||||
Intent data )
|
||||
{
|
||||
super.onActivityResult( requestCode, resultCode, data );
|
||||
m_dlgt.onActivityResult( requestCode, resultCode, data );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eehouse.android.xw4;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -123,4 +124,11 @@ public class XWActivity extends Activity {
|
|||
super.onPrepareDialog( id, dialog );
|
||||
m_dlgt.prepareDialog( DlgID.values()[id], dialog );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult( int requestCode, int resultCode,
|
||||
Intent data )
|
||||
{
|
||||
m_dlgt.onActivityResult( requestCode, resultCode, data );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eehouse.android.xw4;
|
|||
|
||||
import android.app.Dialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -123,4 +124,11 @@ public class XWListActivity extends ListActivity {
|
|||
super.onPrepareDialog( id, dialog );
|
||||
m_dlgt.prepareDialog( DlgID.values()[id], dialog );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult( int requestCode, int resultCode,
|
||||
Intent data )
|
||||
{
|
||||
m_dlgt.onActivityResult( requestCode, resultCode, data );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue