From d8c1e3822bf51bb3991ebdae9dd5adac89c9ed62 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 6 Oct 2011 17:47:00 -0700 Subject: [PATCH 1/6] fix problems with skipping singleton words and URLs; replace window title with TextView. --- xwords4/android/XWords4/res/layout/lookup.xml | 7 ++ .../eehouse/android/xw4/LookupActivity.java | 98 +++++++++++-------- 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/xwords4/android/XWords4/res/layout/lookup.xml b/xwords4/android/XWords4/res/layout/lookup.xml index 429e84ad4..cb0080a26 100644 --- a/xwords4/android/XWords4/res/layout/lookup.xml +++ b/xwords4/android/XWords4/res/layout/lookup.xml @@ -12,6 +12,13 @@ android:layout_height="fill_parent" > + + m_wordsAdapter; - private ArrayAdapter m_shown; private Button m_doneButton; + private TextView m_summary; @Override protected void onCreate( Bundle savedInstanceState ) @@ -69,6 +76,8 @@ public class LookupActivity extends XWListActivity super.onCreate( savedInstanceState ); getBundledData( savedInstanceState ); + requestWindowFeature( Window.FEATURE_NO_TITLE ); + Intent intent = getIntent(); m_words = intent.getStringArrayExtra( WORDS ); m_lang = intent.getIntExtra( LANG, -1 ); @@ -82,9 +91,10 @@ public class LookupActivity extends XWListActivity m_doneButton = (Button)findViewById( R.id.button_done ); m_doneButton.setOnClickListener( this ); + m_summary = (TextView)findViewById( R.id.summary ); - m_state = 0; - adjustForState(); + m_state = STATE_DONE; + adjustState( 1 ); } @Override @@ -99,25 +109,23 @@ public class LookupActivity extends XWListActivity /* View.OnClickListener -- just the Done button */ public void onClick( View view ) { - --m_state; - adjustForState(); + adjustState( -1 ); } /* AdapterView.OnItemClickListener */ public void onItemClick( AdapterView parent, View view, int position, long id ) { - if ( m_shown == m_wordsAdapter ) { + if ( STATE_WORDS == m_state ) { m_wordIndex = position; Utils.logf( "%s selected", m_words[position] ); - } else if ( m_shown == s_urlsAdapter ) { + } else if ( STATE_URLS == m_state ) { m_urlIndex = position; Utils.logf( "%s selected", s_lookupUrls[position] ); } else { Assert.fail(); } - ++m_state; - adjustForState(); + adjustState( 1 ); } private void getBundledData( Bundle bundle ) @@ -127,37 +135,42 @@ public class LookupActivity extends XWListActivity // } } - private void adjustForState() + private void adjustState( int incr ) { - if ( 0 > m_state ) { + m_state += incr; + if ( 1 >= m_words.length ) { + m_state += incr; + } + if ( 1 >= s_lookupUrls.length ) { + m_state += incr; + } + + switch( m_state ) { + case STATE_DONE: finish(); - } else { - switch( m_state ) { - case 0: - if ( 1 < m_words.length ) { - m_shown = m_wordsAdapter; - getListView().setAdapter( m_wordsAdapter ); - setTitle( R.string.title_lookup ); - m_doneButton.setText( R.string.button_done ); - break; - } - case 1: - if ( 1 < s_lookupUrls.length ) { - m_shown = s_urlsAdapter; - getListView().setAdapter( s_urlsAdapter ); - setTitle( m_words[m_wordIndex] ); - String txt = Utils.format( this, R.string.button_donef, - m_words[m_wordIndex] ); - m_doneButton.setText( txt ); - break; - } - case 2: - lookupWord( m_words[m_wordIndex], s_lookupUrls[m_urlIndex] ); - if ( 0 >= --m_state ) { - finish(); - } - break; - } + break; + case STATE_WORDS: + Assert.assertTrue( 1 < m_words.length ); + getListView().setAdapter( m_wordsAdapter ); + setSummary( R.string.title_lookup ); + m_doneButton.setText( R.string.button_done ); + break; + case STATE_URLS: + Assert.assertTrue( 1 < s_lookupUrls.length ); + getListView().setAdapter( s_urlsAdapter ); + setSummary( m_words[m_wordIndex] ); + String txt = Utils.format( this, R.string.button_donef, + m_words[m_wordIndex] ); + m_doneButton.setText( txt ); + break; + case STATE_LOOKUP: + lookupWord( m_words[m_wordIndex], s_lookupUrls[m_urlIndex] ); + adjustState( -1 ); + break; + default: + Utils.logf( "unexpected state %d", m_state ); + Assert.fail(); + break; } } @@ -207,10 +220,15 @@ public class LookupActivity extends XWListActivity } // initLookup } - private void setTitle( String word ) + private void setSummary( int id ) + { + m_summary.setText( getString( id ) ); + } + + private void setSummary( String word ) { String title = Utils.format( this, R.string.pick_url_titlef, word ); - super.setTitle( title ); + m_summary.setText( title ); } } From 0a474804ceb7aa6cb9af48afa558cb166c10c2ee Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 6 Oct 2011 18:25:17 -0700 Subject: [PATCH 2/6] fix to work with bundling, i.e. by removing configChanges entry in AndroidManifest.xml and changing orientation. --- .../eehouse/android/xw4/LookupActivity.java | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java index 106e41f8d..4e1489239 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java @@ -43,6 +43,9 @@ public class LookupActivity extends XWListActivity public static final String WORDS = "WORDS"; public static final String LANG = "LANG"; + public static final String STATE = "STATE"; + public static final String WORDINDEX = "WORDINDEX"; + public static final String URLINDEX = "URLINDEX"; private static final int STATE_DONE = 0; private static final int STATE_WORDS = 1; @@ -74,7 +77,6 @@ public class LookupActivity extends XWListActivity protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); - getBundledData( savedInstanceState ); requestWindowFeature( Window.FEATURE_NO_TITLE ); @@ -83,6 +85,8 @@ public class LookupActivity extends XWListActivity m_lang = intent.getIntExtra( LANG, -1 ); setLang( m_lang ); + getBundledData( savedInstanceState ); + setContentView( R.layout.lookup ); m_wordsAdapter = new ArrayAdapter( this, LIST_LAYOUT, @@ -93,23 +97,13 @@ public class LookupActivity extends XWListActivity m_doneButton.setOnClickListener( this ); m_summary = (TextView)findViewById( R.id.summary ); - m_state = STATE_DONE; - adjustState( 1 ); - } - - @Override - protected void onSaveInstanceState( Bundle outState ) - { - super.onSaveInstanceState( outState ); - // if ( null != m_words ) { - // outState.putStringArray( WORDS, m_words ); - // } + switchState(); } /* View.OnClickListener -- just the Done button */ public void onClick( View view ) { - adjustState( -1 ); + switchState( -1 ); } /* AdapterView.OnItemClickListener */ @@ -125,14 +119,28 @@ public class LookupActivity extends XWListActivity } else { Assert.fail(); } - adjustState( 1 ); + switchState( 1 ); + } + + @Override + protected void onSaveInstanceState( Bundle outState ) + { + super.onSaveInstanceState( outState ); + outState.putInt( STATE, m_state ); + outState.putInt( WORDINDEX, m_wordIndex ); + outState.putInt( URLINDEX, m_urlIndex ); } private void getBundledData( Bundle bundle ) { - // if ( null != bundle ) { - // m_words = bundle.getStringArray( WORDS ); - // } + if ( null == bundle ) { + m_state = STATE_DONE; + adjustState( 1 ); + } else { + m_state = bundle.getInt( STATE ); + m_wordIndex = bundle.getInt( WORDINDEX ); + m_urlIndex = bundle.getInt( URLINDEX ); + } } private void adjustState( int incr ) @@ -144,7 +152,16 @@ public class LookupActivity extends XWListActivity if ( 1 >= s_lookupUrls.length ) { m_state += incr; } + } + private void switchState( int incr ) + { + adjustState( incr ); + switchState(); + } + + private void switchState() + { switch( m_state ) { case STATE_DONE: finish(); @@ -165,14 +182,14 @@ public class LookupActivity extends XWListActivity break; case STATE_LOOKUP: lookupWord( m_words[m_wordIndex], s_lookupUrls[m_urlIndex] ); - adjustState( -1 ); + switchState( -1 ); break; default: Utils.logf( "unexpected state %d", m_state ); Assert.fail(); break; } - } + } // adjustState private void lookupWord( String word, String fmt ) { From a129f353f5ebc29508adcb4ebbc3757215c3e088 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 6 Oct 2011 18:44:24 -0700 Subject: [PATCH 3/6] fix assertion by skipping states only when applicable, and running in a loop so works in either direction. Cleanup -- this is done. --- .../eehouse/android/xw4/LookupActivity.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java index 4e1489239..5247b5d06 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java @@ -56,11 +56,7 @@ public class LookupActivity extends XWListActivity private static String[] s_lookupNames; private static String[] s_lookupUrls; private static ArrayAdapter s_urlsAdapter; - private static final int LIST_LAYOUT = - // android.R.layout.simple_spinner_item; - // android.R.layout.select_dialog_item - android.R.layout.simple_list_item_1 - ; + private static final int LIST_LAYOUT = android.R.layout.simple_list_item_1; private static int s_lang = -1; @@ -112,10 +108,8 @@ public class LookupActivity extends XWListActivity { if ( STATE_WORDS == m_state ) { m_wordIndex = position; - Utils.logf( "%s selected", m_words[position] ); } else if ( STATE_URLS == m_state ) { m_urlIndex = position; - Utils.logf( "%s selected", s_lookupUrls[position] ); } else { Assert.fail(); } @@ -146,11 +140,17 @@ public class LookupActivity extends XWListActivity private void adjustState( int incr ) { m_state += incr; - if ( 1 >= m_words.length ) { - m_state += incr; - } - if ( 1 >= s_lookupUrls.length ) { - m_state += incr; + for ( ; ; ) { + int curState = m_state; + if ( STATE_WORDS == m_state && 1 >= m_words.length ) { + m_state += incr; + } + if ( STATE_URLS == m_state && 1 >= s_lookupUrls.length ) { + m_state += incr; + } + if ( m_state == curState ) { + break; + } } } @@ -167,13 +167,11 @@ public class LookupActivity extends XWListActivity finish(); break; case STATE_WORDS: - Assert.assertTrue( 1 < m_words.length ); getListView().setAdapter( m_wordsAdapter ); setSummary( R.string.title_lookup ); m_doneButton.setText( R.string.button_done ); break; case STATE_URLS: - Assert.assertTrue( 1 < s_lookupUrls.length ); getListView().setAdapter( s_urlsAdapter ); setSummary( m_words[m_wordIndex] ); String txt = Utils.format( this, R.string.button_donef, @@ -185,7 +183,6 @@ public class LookupActivity extends XWListActivity switchState( -1 ); break; default: - Utils.logf( "unexpected state %d", m_state ); Assert.fail(); break; } @@ -232,7 +229,6 @@ public class LookupActivity extends XWListActivity s_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] ); s_urlsAdapter = new ArrayAdapter( this, LIST_LAYOUT, s_lookupNames ); - s_lang = lang; } // initLookup } From 152a9175c6b475932d0dd846239d8ae8219cdf99 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 6 Oct 2011 18:44:59 -0700 Subject: [PATCH 4/6] use dialog theme for lookups -- just works now, though didn't at first. --- xwords4/android/XWords4/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/android/XWords4/AndroidManifest.xml b/xwords4/android/XWords4/AndroidManifest.xml index 2959fc9c8..34772cf9f 100644 --- a/xwords4/android/XWords4/AndroidManifest.xml +++ b/xwords4/android/XWords4/AndroidManifest.xml @@ -83,9 +83,9 @@ > - From f084661ec332c3a2e1f10c6cf15b7770eef30c32 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 6 Oct 2011 18:47:08 -0700 Subject: [PATCH 5/6] Never meant to check in having lookup menuitem at top level. --- xwords4/android/XWords4/res/menu/board_menu.xml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/xwords4/android/XWords4/res/menu/board_menu.xml b/xwords4/android/XWords4/res/menu/board_menu.xml index 50305f9cd..0e4617561 100644 --- a/xwords4/android/XWords4/res/menu/board_menu.xml +++ b/xwords4/android/XWords4/res/menu/board_menu.xml @@ -2,9 +2,6 @@ - - - - + Date: Thu, 6 Oct 2011 19:03:07 -0700 Subject: [PATCH 6/6] add newbie warning/request for languages with only google as word-lookup site. --- .../XWords4/res/values/common_rsrc.xml | 1 + .../android/XWords4/res/values/strings.xml | 5 ++++ .../eehouse/android/xw4/LookupActivity.java | 25 +++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml index bdba75543..8b1934157 100644 --- a/xwords4/android/XWords4/res/values/common_rsrc.xml +++ b/xwords4/android/XWords4/res/values/common_rsrc.xml @@ -72,6 +72,7 @@ key_notagain_turnchanged key_notagain_newfrom key_notagain_trading + key_na_needUrlsForLang Crosswords diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 112d8439a..e76f63b4c 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -1777,5 +1777,10 @@ Look up %s at Pass + + Google is the only word + lookup site I have for this language. If you have suggestions + for word-lookup sites please email eehouse@eehouse.org + . diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java index 5247b5d06..aa22916c3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java @@ -33,6 +33,7 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; +import android.app.AlertDialog; import java.util.ArrayList; import junit.framework.Assert; @@ -52,6 +53,8 @@ public class LookupActivity extends XWListActivity private static final int STATE_URLS = 2; private static final int STATE_LOOKUP = 3; + private static final int LOOKUP_ACTION = 1; + private static String[] s_langCodes; private static String[] s_lookupNames; private static String[] s_lookupUrls; @@ -125,6 +128,19 @@ public class LookupActivity extends XWListActivity outState.putInt( URLINDEX, m_urlIndex ); } + ////////////////////////////////////////////////// + // DlgDelegate.DlgClickNotify interface + ////////////////////////////////////////////////// + @Override + public void dlgButtonClicked( int id, int which ) + { + if ( LOOKUP_ACTION == id + && AlertDialog.BUTTON_POSITIVE == which ) { + lookupWord( m_words[m_wordIndex], s_lookupUrls[m_urlIndex] ); + switchState( -1 ); + } + } + private void getBundledData( Bundle bundle ) { if ( null == bundle ) { @@ -179,8 +195,13 @@ public class LookupActivity extends XWListActivity m_doneButton.setText( txt ); break; case STATE_LOOKUP: - lookupWord( m_words[m_wordIndex], s_lookupUrls[m_urlIndex] ); - switchState( -1 ); + if ( 1 >= s_lookupUrls.length ) { + showNotAgainDlgThen( R.string.not_again_needUrlsForLang, + R.string.key_na_needUrlsForLang, + LOOKUP_ACTION ); + } else { + dlgButtonClicked( LOOKUP_ACTION, AlertDialog.BUTTON_POSITIVE ); + } break; default: Assert.fail();