Merge branch 'android_branch' into send_in_background

This commit is contained in:
eehouse@eehouse.org 2011-10-07 05:49:52 -07:00 committed by Andy2
commit 8712918e73
6 changed files with 128 additions and 66 deletions

View file

@ -83,9 +83,9 @@
> >
</activity> </activity>
<!-- android:theme="@android:style/Theme.Dialog" -->
<activity android:name="LookupActivity" <activity android:name="LookupActivity"
android:configChanges="keyboardHidden|orientation" android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.Dialog"
/> />
<receiver android:name="RelayReceiver"> <receiver android:name="RelayReceiver">

View file

@ -12,6 +12,13 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
> >
<TextView android:id="@+id/summary"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center"
/>
<ListView android:id="@+id/android:list" <ListView android:id="@+id/android:list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"

View file

@ -2,9 +2,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/board_menu_lookup"
android:title="@string/button_lookup" />
<group android:id="@+id/group_done"> <group android:id="@+id/group_done">
<!-- title set in BoardActivity --> <!-- title set in BoardActivity -->
<item android:id="@+id/board_menu_done" <item android:id="@+id/board_menu_done"
@ -33,8 +30,8 @@
<item android:title="@string/board_submenu_game"> <item android:title="@string/board_submenu_game">
<menu> <menu>
<!-- <item android:id="@+id/board_menu_lookup" --> <item android:id="@+id/board_menu_lookup"
<!-- android:title="@string/button_lookup" /> --> android:title="@string/button_lookup" />
<item android:id="@+id/board_menu_game_counts" <item android:id="@+id/board_menu_game_counts"
android:title="@string/board_menu_game_counts" /> android:title="@string/board_menu_game_counts" />
<item android:id="@+id/board_menu_game_left" <item android:id="@+id/board_menu_game_left"

View file

@ -72,6 +72,7 @@
<string name="key_notagain_turnchanged">key_notagain_turnchanged</string> <string name="key_notagain_turnchanged">key_notagain_turnchanged</string>
<string name="key_notagain_newfrom">key_notagain_newfrom</string> <string name="key_notagain_newfrom">key_notagain_newfrom</string>
<string name="key_notagain_trading">key_notagain_trading</string> <string name="key_notagain_trading">key_notagain_trading</string>
<string name="key_na_needUrlsForLang">key_na_needUrlsForLang</string>
<!-- Name is not localized --> <!-- Name is not localized -->
<string name="app_name">Crosswords</string> <string name="app_name">Crosswords</string>

View file

@ -1777,5 +1777,10 @@
<string name="pick_url_titlef">Look up %s at</string> <string name="pick_url_titlef">Look up %s at</string>
<string name="board_menu_pass">Pass</string> <string name="board_menu_pass">Pass</string>
<string name="not_again_needUrlsForLang">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
.</string>
</resources> </resources>

View file

@ -27,10 +27,13 @@ import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.Window;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
import android.app.AlertDialog;
import java.util.ArrayList; import java.util.ArrayList;
import junit.framework.Assert; import junit.framework.Assert;
@ -41,16 +44,22 @@ public class LookupActivity extends XWListActivity
public static final String WORDS = "WORDS"; public static final String WORDS = "WORDS";
public static final String LANG = "LANG"; 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;
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_langCodes;
private static String[] s_lookupNames; private static String[] s_lookupNames;
private static String[] s_lookupUrls; private static String[] s_lookupUrls;
private static ArrayAdapter<String> s_urlsAdapter; private static ArrayAdapter<String> s_urlsAdapter;
private static final int LIST_LAYOUT = private static final int LIST_LAYOUT = android.R.layout.simple_list_item_1;
// android.R.layout.simple_spinner_item;
// android.R.layout.select_dialog_item
android.R.layout.simple_list_item_1
;
private static int s_lang = -1; private static int s_lang = -1;
@ -60,20 +69,23 @@ public class LookupActivity extends XWListActivity
private int m_urlIndex = 0; private int m_urlIndex = 0;
private int m_state; private int m_state;
private ArrayAdapter<String> m_wordsAdapter; private ArrayAdapter<String> m_wordsAdapter;
private ArrayAdapter<String> m_shown;
private Button m_doneButton; private Button m_doneButton;
private TextView m_summary;
@Override @Override
protected void onCreate( Bundle savedInstanceState ) protected void onCreate( Bundle savedInstanceState )
{ {
super.onCreate( savedInstanceState ); super.onCreate( savedInstanceState );
getBundledData( savedInstanceState );
requestWindowFeature( Window.FEATURE_NO_TITLE );
Intent intent = getIntent(); Intent intent = getIntent();
m_words = intent.getStringArrayExtra( WORDS ); m_words = intent.getStringArrayExtra( WORDS );
m_lang = intent.getIntExtra( LANG, -1 ); m_lang = intent.getIntExtra( LANG, -1 );
setLang( m_lang ); setLang( m_lang );
getBundledData( savedInstanceState );
setContentView( R.layout.lookup ); setContentView( R.layout.lookup );
m_wordsAdapter = new ArrayAdapter<String>( this, LIST_LAYOUT, m_wordsAdapter = new ArrayAdapter<String>( this, LIST_LAYOUT,
@ -82,84 +94,120 @@ public class LookupActivity extends XWListActivity
m_doneButton = (Button)findViewById( R.id.button_done ); m_doneButton = (Button)findViewById( R.id.button_done );
m_doneButton.setOnClickListener( this ); m_doneButton.setOnClickListener( this );
m_summary = (TextView)findViewById( R.id.summary );
m_state = 0; switchState();
adjustForState();
}
@Override
protected void onSaveInstanceState( Bundle outState )
{
super.onSaveInstanceState( outState );
// if ( null != m_words ) {
// outState.putStringArray( WORDS, m_words );
// }
} }
/* View.OnClickListener -- just the Done button */ /* View.OnClickListener -- just the Done button */
public void onClick( View view ) public void onClick( View view )
{ {
--m_state; switchState( -1 );
adjustForState();
} }
/* AdapterView.OnItemClickListener */ /* AdapterView.OnItemClickListener */
public void onItemClick( AdapterView<?> parent, View view, public void onItemClick( AdapterView<?> parent, View view,
int position, long id ) int position, long id )
{ {
if ( m_shown == m_wordsAdapter ) { if ( STATE_WORDS == m_state ) {
m_wordIndex = position; m_wordIndex = position;
Utils.logf( "%s selected", m_words[position] ); } else if ( STATE_URLS == m_state ) {
} else if ( m_shown == s_urlsAdapter ) {
m_urlIndex = position; m_urlIndex = position;
Utils.logf( "%s selected", s_lookupUrls[position] );
} else { } else {
Assert.fail(); Assert.fail();
} }
++m_state; switchState( 1 );
adjustForState(); }
@Override
protected void onSaveInstanceState( Bundle outState )
{
super.onSaveInstanceState( outState );
outState.putInt( STATE, m_state );
outState.putInt( WORDINDEX, m_wordIndex );
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 ) private void getBundledData( Bundle bundle )
{ {
// if ( null != bundle ) { if ( null == bundle ) {
// m_words = bundle.getStringArray( WORDS ); m_state = STATE_DONE;
// } adjustState( 1 );
} else {
m_state = bundle.getInt( STATE );
m_wordIndex = bundle.getInt( WORDINDEX );
m_urlIndex = bundle.getInt( URLINDEX );
}
} }
private void adjustForState() private void adjustState( int incr )
{ {
if ( 0 > m_state ) { m_state += incr;
finish(); for ( ; ; ) {
} else { int curState = m_state;
switch( m_state ) { if ( STATE_WORDS == m_state && 1 >= m_words.length ) {
case 0: m_state += incr;
if ( 1 < m_words.length ) { }
m_shown = m_wordsAdapter; if ( STATE_URLS == m_state && 1 >= s_lookupUrls.length ) {
getListView().setAdapter( m_wordsAdapter ); m_state += incr;
setTitle( R.string.title_lookup ); }
m_doneButton.setText( R.string.button_done ); if ( m_state == curState ) {
break; break;
} }
case 1: }
if ( 1 < s_lookupUrls.length ) { }
m_shown = s_urlsAdapter;
private void switchState( int incr )
{
adjustState( incr );
switchState();
}
private void switchState()
{
switch( m_state ) {
case STATE_DONE:
finish();
break;
case STATE_WORDS:
getListView().setAdapter( m_wordsAdapter );
setSummary( R.string.title_lookup );
m_doneButton.setText( R.string.button_done );
break;
case STATE_URLS:
getListView().setAdapter( s_urlsAdapter ); getListView().setAdapter( s_urlsAdapter );
setTitle( m_words[m_wordIndex] ); setSummary( m_words[m_wordIndex] );
String txt = Utils.format( this, R.string.button_donef, String txt = Utils.format( this, R.string.button_donef,
m_words[m_wordIndex] ); m_words[m_wordIndex] );
m_doneButton.setText( txt ); m_doneButton.setText( txt );
break; break;
} case STATE_LOOKUP:
case 2: if ( 1 >= s_lookupUrls.length ) {
lookupWord( m_words[m_wordIndex], s_lookupUrls[m_urlIndex] ); showNotAgainDlgThen( R.string.not_again_needUrlsForLang,
if ( 0 >= --m_state ) { R.string.key_na_needUrlsForLang,
finish(); LOOKUP_ACTION );
} else {
dlgButtonClicked( LOOKUP_ACTION, AlertDialog.BUTTON_POSITIVE );
} }
break; break;
default:
Assert.fail();
break;
} }
} } // adjustState
}
private void lookupWord( String word, String fmt ) private void lookupWord( String word, String fmt )
{ {
@ -202,15 +250,19 @@ public class LookupActivity extends XWListActivity
s_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] ); s_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] );
s_urlsAdapter = new ArrayAdapter<String>( this, LIST_LAYOUT, s_urlsAdapter = new ArrayAdapter<String>( this, LIST_LAYOUT,
s_lookupNames ); s_lookupNames );
s_lang = lang; s_lang = lang;
} // initLookup } // 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 ); String title = Utils.format( this, R.string.pick_url_titlef, word );
super.setTitle( title ); m_summary.setText( title );
} }
} }