mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
make lookup dialog two-part, with list of lang-supporting URLs at top
and words at bottom. You choose a URL/site, then tap a word, and repeat until you're done.
This commit is contained in:
parent
11d44ba72a
commit
617de4eb7e
4 changed files with 145 additions and 62 deletions
|
@ -5,6 +5,21 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView style="@style/config_separator"
|
||||
android:text="@string/site_spinner_label"
|
||||
/>
|
||||
|
||||
<Spinner android:id="@+id/site_spinner"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawSelectorOnTop="true"
|
||||
android:prompt="@string/site_spinner_prompt"
|
||||
/>
|
||||
|
||||
<TextView style="@style/config_separator"
|
||||
android:text="@string/word_list_label"
|
||||
/>
|
||||
|
||||
<ListView android:id="@+id/words"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -84,9 +84,6 @@
|
|||
<string name="app_version">4.4 beta 34</string>
|
||||
<string name="game_url_pathf">//%1$s/newgame.php</string>
|
||||
|
||||
<!-- <string name="word_lookupf">http://dictionary.com/browse/%s</string> -->
|
||||
<string name="word_lookupf">http://%1$s.thefreedictionary.com/_/dict.aspx?word=%2$s</string>
|
||||
|
||||
<!-- Debugging stuff. No point in localizing it. -->
|
||||
<string name="advanced">For debugging</string>
|
||||
<string name="advanced_summary">You should never need these...</string>
|
||||
|
@ -152,19 +149,19 @@
|
|||
|
||||
<string-array name="language_names">
|
||||
<item></item> <!-- Unknown -->
|
||||
<item>English</item>
|
||||
<item>French</item>
|
||||
<item>German</item>
|
||||
<item>Turkish</item>
|
||||
<item>Arabic</item>
|
||||
<item>Spanish</item>
|
||||
<item>Swedish</item>
|
||||
<item>Polish</item>
|
||||
<item>Danish</item>
|
||||
<item>Italian</item>
|
||||
<item>Dutch</item>
|
||||
<item>Catalan</item>
|
||||
<item>Portuguese</item>
|
||||
<item>English</item> <!-- 1 -->
|
||||
<item>French</item> <!-- 2 -->
|
||||
<item>German</item> <!-- 3 -->
|
||||
<item>Turkish</item> <!-- 4 -->
|
||||
<item>Arabic</item> <!-- 5 -->
|
||||
<item>Spanish</item> <!-- 6 -->
|
||||
<item>Swedish</item> <!-- 7 -->
|
||||
<item>Polish</item> <!-- 8 -->
|
||||
<item>Danish</item> <!-- 9 -->
|
||||
<item>Italian</item> <!-- A -->
|
||||
<item>Dutch</item> <!-- B -->
|
||||
<item>Catalan</item> <!-- C -->
|
||||
<item>Portuguese</item> <!-- D -->
|
||||
<item></item> <!-- E -->
|
||||
<item>Russian</item>
|
||||
<item></item> <!-- 10 -->
|
||||
|
@ -173,6 +170,45 @@
|
|||
<item>Slovak</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="language_codes">
|
||||
<item></item>
|
||||
<item>en</item>
|
||||
<item>fr</item>
|
||||
<item>de</item>
|
||||
<item></item>
|
||||
<item></item>
|
||||
<item>es</item>
|
||||
<item></item>
|
||||
<item></item>
|
||||
<item></item>
|
||||
<item>it</item>
|
||||
<item></item>
|
||||
<item>ca</item>
|
||||
<item></item>
|
||||
<item></item>
|
||||
<item></item>
|
||||
<item></item>
|
||||
<item></item>
|
||||
<item></item>
|
||||
<item></item>
|
||||
</string-array>
|
||||
|
||||
<!-- Triples of Name, supported codes, and URL format string -->
|
||||
<string-array name="lookup_urls">
|
||||
<!-- -->
|
||||
<item>Dictionary.com</item>
|
||||
<item>:en:</item> <!-- means all supported -->
|
||||
<item>http://dictionary.com/browse/%2$s</item> -->
|
||||
<!-- -->
|
||||
<item>TheFreeDictionary.com</item>
|
||||
<item>:en:es:</item> <!-- means all supported -->
|
||||
<item>http://%1$s.thefreedictionary.com/_/dict.aspx?word=%2$s</item>
|
||||
<!-- -->
|
||||
<item>Google</item>
|
||||
<item></item> <!-- means all supported -->
|
||||
<item>http://www.google.com/search?nl=%1$s\u0026q=%2$s</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="game_summary_values">
|
||||
<item>@string/game_summary_field_empty</item>
|
||||
<item>@string/game_summary_field_language</item>
|
||||
|
|
|
@ -1769,5 +1769,9 @@
|
|||
<string name="title_lookup">Tap to lookup</string>
|
||||
<string name="button_done">Done</string>
|
||||
|
||||
<string name="site_spinner_label">Pick a site</string>
|
||||
<string name="site_spinner_prompt">Pick a site</string>
|
||||
<string name="word_list_label">Tap word to search</string>
|
||||
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -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<String> adapter =
|
||||
new ArrayAdapter<String>( 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<String> adapter = new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_spinner_item,
|
||||
m_lookupNames );
|
||||
spinner.setAdapter( adapter );
|
||||
|
||||
ListView list = (ListView)layout.findViewById( R.id.words );
|
||||
adapter = new ArrayAdapter<String>( 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<String> tmpUrls = new ArrayList<String>();
|
||||
ArrayList<String> tmpNames = new ArrayList<String>();
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue