diff --git a/xwords4/android/XWords4/res/layout/wordlist_view.xml b/xwords4/android/XWords4/res/layout/wordlist_view.xml index 2fc096058..2fd980698 100644 --- a/xwords4/android/XWords4/res/layout/wordlist_view.xml +++ b/xwords4/android/XWords4/res/layout/wordlist_view.xml @@ -5,6 +5,21 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + + + + + 4.4 beta 34 //%1$s/newgame.php - - http://%1$s.thefreedictionary.com/_/dict.aspx?word=%2$s - For debugging You should never need these... @@ -152,19 +149,19 @@ - English - French - German - Turkish - Arabic - Spanish - Swedish - Polish - Danish - Italian - Dutch - Catalan - Portuguese + English + French + German + Turkish + Arabic + Spanish + Swedish + Polish + Danish + Italian + Dutch + Catalan + Portuguese Russian @@ -173,6 +170,45 @@ Slovak + + + en + fr + de + + + es + + + + it + + ca + + + + + + + + + + + + + Dictionary.com + :en: + http://dictionary.com/browse/%2$s --> + + TheFreeDictionary.com + :en:es: + http://%1$s.thefreedictionary.com/_/dict.aspx?word=%2$s + + Google + + http://www.google.com/search?nl=%1$s\u0026q=%2$s + + @string/game_summary_field_empty @string/game_summary_field_language diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index b05c2b52c..270963d3f 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -1769,5 +1769,9 @@ Tap to lookup Done + Pick a site + Pick a site + Tap word to search + diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index fe4a7fcf2..636947699 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -48,10 +48,12 @@ import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.EditText; import android.widget.ListView; +import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import junit.framework.Assert; import android.content.res.Configuration; +import android.content.res.Resources; import android.content.pm.ActivityInfo; import android.net.Uri; @@ -143,6 +145,10 @@ public class BoardActivity extends XWActivity private String m_room; private String m_toastStr; private String[] m_words; + private String[] m_langCodes; + private String[] m_lookupUrls; + private String[] m_lookupNames; + private int m_missing; private boolean m_haveInvited = false; @@ -242,15 +248,13 @@ public class BoardActivity extends XWActivity }; ab.setNegativeButton( R.string.button_no, lstnr ); } else if ( DLG_SCORES_BLK == id ) { - if ( curLangSupported() ) { - lstnr = new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dialog, - int whichButton ) { - m_jniThread.handle( JNICmd.CMD_WORDS ); - } - }; - ab.setNegativeButton( R.string.button_lookup, lstnr ); - } + lstnr = new DialogInterface.OnClickListener() { + public void onClick( DialogInterface dialog, + int whichButton ) { + m_jniThread.handle( JNICmd.CMD_WORDS ); + } + }; + ab.setNegativeButton( R.string.button_lookup, lstnr ); } dialog = ab.create(); @@ -322,26 +326,9 @@ public class BoardActivity extends XWActivity } break; case DLG_WORDPICK: - LinearLayout layout = - (LinearLayout)Utils.inflate( this, R.layout.wordlist_view ); - ListView list = (ListView)layout.findViewById( R.id.words ); - ArrayAdapter adapter = - new ArrayAdapter( this, - //android.R.layout.select_dialog_item, - android.R.layout.simple_list_item_1, - m_words ) ; - list.setAdapter( adapter ); - OnItemClickListener oicl = new OnItemClickListener() { - public void onItemClick(AdapterView parent, - View view, - int position, long id ) { - lookupWord( m_words[position] ); - } - }; - list.setOnItemClickListener( oicl ); dialog = new AlertDialog.Builder( this ) .setTitle( R.string.title_lookup ) - .setView( layout ) + .setView( buildLookupDlg() ) .setNegativeButton( R.string.button_done, null ) .create(); Utils.setRemoveOnDismiss( this, dialog, id ); @@ -1284,8 +1271,8 @@ public class BoardActivity extends XWActivity TextUtils.split( (String)msg.obj, "\n" ); if ( 0 == m_words.length ) { // drop it - } else if ( 1 == m_words.length ) { - lookupWord( m_words[0] ); + // } else if ( 1 == m_words.length ) { + // lookupWord( m_words[0] ); } else { showDialog( DLG_WORDPICK ); } @@ -1562,9 +1549,41 @@ public class BoardActivity extends XWActivity } } - private void lookupWord( String word ) + private View buildLookupDlg() + { + init_lookup(); + + LinearLayout layout = + (LinearLayout)Utils.inflate( this, R.layout.wordlist_view ); + + final Spinner spinner = + (Spinner)layout.findViewById( R.id.site_spinner ); + ArrayAdapter adapter = new ArrayAdapter(this, + android.R.layout.simple_spinner_item, + m_lookupNames ); + spinner.setAdapter( adapter ); + + ListView list = (ListView)layout.findViewById( R.id.words ); + adapter = new ArrayAdapter( this, + //android.R.layout.select_dialog_item, + android.R.layout.simple_list_item_1, + m_words ) ; + list.setAdapter( adapter ); + OnItemClickListener oicl = new OnItemClickListener() { + public void onItemClick(AdapterView parent, + View view, + int position, long id ) { + int urlPos = spinner.getSelectedItemPosition(); + lookupWord( m_words[position], m_lookupUrls[urlPos] ); + } + }; + list.setOnItemClickListener( oicl ); + + return layout; + } + + private void lookupWord( String word, String fmt ) { - String fmt = getString( R.string.word_lookupf ); String dict_url = String.format( fmt, curLangCode(), word ); Uri uri = Uri.parse( dict_url ); Intent intent = new Intent( Intent.ACTION_VIEW, uri ); @@ -1579,22 +1598,31 @@ public class BoardActivity extends XWActivity private String curLangCode() { - // from string-array name="language_names" in common_rsrc.xml - switch( m_gi.dictLang ) { - case 1: - return "en"; - case 2: - return "fr"; - case 3: - return "de"; - default: - return null; + init_lookup(); + return m_langCodes[m_gi.dictLang]; + } + + private void init_lookup() + { + if ( null == m_langCodes ) { + Resources res = getResources(); + m_langCodes = res.getStringArray( R.array.language_codes ); + + String[] urls = res.getStringArray( R.array.lookup_urls ); + ArrayList tmpUrls = new ArrayList(); + ArrayList tmpNames = new ArrayList(); + String langCode = + String.format( ":%s:", m_langCodes[m_gi.dictLang] ); + for ( int ii = 0; ii < urls.length; ii += 3 ) { + String codes = urls[ii+1]; + if ( 0 == codes.length() || codes.contains( langCode ) ) { + tmpNames.add( urls[ii] ); + tmpUrls.add( urls[ii+2] ); + } + } + m_lookupNames = tmpNames.toArray( new String[tmpNames.size()] ); + m_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] ); } } - private boolean curLangSupported() - { - return null != curLangCode(); - } - } // class BoardActivity