mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-14 08:01:38 +01:00
Go back to lookup dialog as dialog-themed activity. I just can't get
contrast right on all platforms any other way. Previous change to using dialogs was motivated by speed, but I don't see any slowdown so far. Will address if I find it.
This commit is contained in:
parent
3aa6932f03
commit
0d69c6097a
4 changed files with 80 additions and 84 deletions
|
@ -83,6 +83,11 @@
|
|||
>
|
||||
</activity>
|
||||
|
||||
<activity android:name="LookupView"
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:theme="@android:style/Theme.Dialog"
|
||||
/>
|
||||
|
||||
<receiver android:name="RelayReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<org.eehouse.android.xw4.LookupView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
|
||||
<ListView android:id="@+id/lookup_list"
|
||||
<TextView android:id="@+id/summary"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:paddingLeft="8dp"
|
||||
/>
|
||||
|
||||
<ListView android:id="@+id/android:list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:drawSelectorOnTop="false"
|
||||
|
@ -19,4 +24,4 @@
|
|||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
</org.eehouse.android.xw4.LookupView>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -43,8 +43,7 @@ public class DlgDelegate {
|
|||
public static final int CONFIRM_THEN = 4;
|
||||
public static final int TEXT_OR_HTML_THEN = 5;
|
||||
public static final int DLG_DICTGONE = 6;
|
||||
public static final int DLG_LOOKUP = 7;
|
||||
public static final int DIALOG_LAST = DLG_LOOKUP;
|
||||
public static final int DIALOG_LAST = DLG_DICTGONE;
|
||||
|
||||
public static final int SMS_BTN = AlertDialog.BUTTON_POSITIVE;
|
||||
public static final int EMAIL_BTN = AlertDialog.BUTTON_NEGATIVE;
|
||||
|
@ -75,9 +74,6 @@ public class DlgDelegate {
|
|||
private Activity m_activity;
|
||||
private DlgClickNotify m_clickCallback;
|
||||
private String m_dictName = null;
|
||||
private String[] m_words = null;
|
||||
private int m_wordsLang = -1;
|
||||
private boolean m_forceList = false;
|
||||
|
||||
public DlgDelegate( Activity activity, DlgClickNotify callback,
|
||||
Bundle bundle )
|
||||
|
@ -90,9 +86,6 @@ public class DlgDelegate {
|
|||
m_cbckID = bundle.getInt( CALLBACK );
|
||||
m_posButton = bundle.getInt( POSBUTTON );
|
||||
m_prefsKey = bundle.getInt( PREFSKEY );
|
||||
m_words = bundle.getStringArray( WORDS );
|
||||
m_wordsLang = bundle.getInt( LANG );
|
||||
m_forceList = bundle.getBoolean( FORCELIST );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,9 +95,6 @@ public class DlgDelegate {
|
|||
outState.putInt( CALLBACK, m_cbckID );
|
||||
outState.putInt( POSBUTTON, m_posButton );
|
||||
outState.putInt( PREFSKEY, m_prefsKey );
|
||||
outState.putStringArray( WORDS, m_words );
|
||||
outState.putInt( LANG, m_wordsLang );
|
||||
outState.putBoolean( FORCELIST, m_forceList );
|
||||
}
|
||||
|
||||
public Dialog onCreateDialog( int id )
|
||||
|
@ -129,15 +119,6 @@ public class DlgDelegate {
|
|||
case DLG_DICTGONE:
|
||||
dialog = createDictGoneDialog();
|
||||
break;
|
||||
case DLG_LOOKUP:
|
||||
LookupView view = (LookupView)Utils.inflate( m_activity,
|
||||
R.layout.lookup );
|
||||
dialog = new AlertDialog.Builder( m_activity )
|
||||
.setView( view )
|
||||
.create();
|
||||
view.setDialog( dialog, DLG_LOOKUP );
|
||||
view.setWords( m_words, m_wordsLang, m_forceList );
|
||||
break;
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
@ -254,11 +235,11 @@ public class DlgDelegate {
|
|||
|
||||
public void launchLookup( String[] words, int lang, boolean forceList )
|
||||
{
|
||||
Assert.assertTrue( null != words && 0 < words.length );
|
||||
m_words = words;
|
||||
m_wordsLang = lang;
|
||||
m_forceList = forceList;
|
||||
m_activity.showDialog( DLG_LOOKUP );
|
||||
Intent intent = new Intent( m_activity, LookupView.class );
|
||||
intent.putExtra( LookupView.WORDS, words );
|
||||
intent.putExtra( LookupView.LANG, lang );
|
||||
|
||||
m_activity.startActivity( intent );
|
||||
}
|
||||
|
||||
private Dialog createAboutDialog()
|
||||
|
|
|
@ -20,9 +20,7 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
|
@ -32,19 +30,21 @@ import android.view.Window;
|
|||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.app.AlertDialog;
|
||||
import java.util.ArrayList;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class LookupView extends LinearLayout
|
||||
public class LookupView extends XWListActivity
|
||||
implements View.OnClickListener,
|
||||
AdapterView.OnItemClickListener,
|
||||
DialogInterface.OnDismissListener {
|
||||
AdapterView.OnItemClickListener {
|
||||
|
||||
public static final String WORDS = "WORDS";
|
||||
public static final String LANG = "LANG";
|
||||
public static final String FORCELIST = "FORCELIST";
|
||||
private static final String STATE = "STATE";
|
||||
private static final String WORDINDEX = "WORDINDEX";
|
||||
private static final String URLINDEX = "URLINDEX";
|
||||
|
||||
private static final int STATE_DONE = 0;
|
||||
private static final int STATE_WORDS = 1;
|
||||
|
@ -55,55 +55,66 @@ public class LookupView extends LinearLayout
|
|||
private static String[] s_lookupNames;
|
||||
private static String[] s_lookupUrls;
|
||||
private static ArrayAdapter<String> s_urlsAdapter;
|
||||
private static final int LIST_LAYOUT = // android.R.layout.simple_list_item_1;
|
||||
android.R.layout.select_dialog_item;
|
||||
//R.layout.select_dialog_item;
|
||||
private static final int LIST_LAYOUT = android.R.layout.simple_list_item_1;
|
||||
// android.R.layout.select_dialog_item;
|
||||
|
||||
private static int s_lang = -1;
|
||||
|
||||
private String[] m_words;
|
||||
private boolean m_forceList;
|
||||
private static int m_lang;
|
||||
private int m_wordIndex = 0;
|
||||
private int m_urlIndex = 0;
|
||||
private int m_state;
|
||||
private ArrayAdapter<String> m_wordsAdapter;
|
||||
private Button m_doneButton;
|
||||
private Dialog m_dialog;
|
||||
private Context m_context;
|
||||
private int m_dlgId;
|
||||
private ListView m_list;
|
||||
private TextView m_summary;
|
||||
|
||||
public LookupView( Context cx, AttributeSet as ) {
|
||||
super( cx, as );
|
||||
m_context = cx;
|
||||
}
|
||||
|
||||
public void setWords( String[] words, int lang, boolean forceList )
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
m_words = words;
|
||||
m_forceList = forceList;
|
||||
setLang( lang );
|
||||
super.onCreate( savedInstanceState );
|
||||
requestWindowFeature( Window.FEATURE_NO_TITLE );
|
||||
setContentView( R.layout.lookup );
|
||||
|
||||
Intent intent = getIntent();
|
||||
m_words = intent.getStringArrayExtra( WORDS );
|
||||
setLang( intent.getIntExtra( LANG, -1 ) );
|
||||
m_forceList = intent.getBooleanExtra( FORCELIST, false );
|
||||
|
||||
m_state = STATE_DONE;
|
||||
adjustState( 1 );
|
||||
|
||||
m_wordsAdapter = new ArrayAdapter<String>( m_context, LIST_LAYOUT,
|
||||
m_wordsAdapter = new ArrayAdapter<String>( this, LIST_LAYOUT,
|
||||
m_words );
|
||||
m_list = (ListView)findViewById( R.id.lookup_list );
|
||||
m_list.setOnItemClickListener( this );
|
||||
getListView().setOnItemClickListener( this );
|
||||
|
||||
m_doneButton = (Button)findViewById( R.id.button_done );
|
||||
m_doneButton.setOnClickListener( this );
|
||||
|
||||
m_summary = (TextView)findViewById( R.id.summary );
|
||||
|
||||
switchState();
|
||||
}
|
||||
|
||||
public void setDialog( Dialog dialog, int id )
|
||||
@Override
|
||||
protected void onSaveInstanceState( Bundle outState )
|
||||
{
|
||||
m_dialog = dialog;
|
||||
m_dlgId = id;
|
||||
m_dialog.setOnDismissListener( this );
|
||||
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_state = STATE_DONE;
|
||||
adjustState( 1 );
|
||||
} else {
|
||||
m_state = bundle.getInt( STATE );
|
||||
m_wordIndex = bundle.getInt( WORDINDEX );
|
||||
m_urlIndex = bundle.getInt( URLINDEX );
|
||||
}
|
||||
}
|
||||
|
||||
/* View.OnClickListener -- just the Done button */
|
||||
|
@ -126,12 +137,6 @@ public class LookupView extends LinearLayout
|
|||
switchState( 1 );
|
||||
}
|
||||
|
||||
/* DialogInterface.OnDismissListener interface */
|
||||
public void onDismiss( DialogInterface di )
|
||||
{
|
||||
m_dialog.getOwnerActivity().removeDialog( m_dlgId );
|
||||
}
|
||||
|
||||
private void adjustState( int incr )
|
||||
{
|
||||
m_state += incr;
|
||||
|
@ -160,17 +165,17 @@ public class LookupView extends LinearLayout
|
|||
{
|
||||
switch( m_state ) {
|
||||
case STATE_DONE:
|
||||
m_dialog.dismiss();
|
||||
finish();
|
||||
break;
|
||||
case STATE_WORDS:
|
||||
m_list.setAdapter( m_wordsAdapter );
|
||||
getListView().setAdapter( m_wordsAdapter );
|
||||
setSummary( R.string.title_lookup );
|
||||
m_doneButton.setText( R.string.button_done );
|
||||
break;
|
||||
case STATE_URLS:
|
||||
m_list.setAdapter( s_urlsAdapter );
|
||||
getListView().setAdapter( s_urlsAdapter );
|
||||
setSummary( m_words[m_wordIndex] );
|
||||
String txt = Utils.format( m_context, R.string.button_donef,
|
||||
String txt = Utils.format( this, R.string.button_donef,
|
||||
m_words[m_wordIndex] );
|
||||
m_doneButton.setText( txt );
|
||||
break;
|
||||
|
@ -182,7 +187,7 @@ public class LookupView extends LinearLayout
|
|||
Assert.fail();
|
||||
break;
|
||||
}
|
||||
} // adjustState
|
||||
} // switchState
|
||||
|
||||
private void lookupWord( String word, String fmt )
|
||||
{
|
||||
|
@ -196,14 +201,14 @@ public class LookupView extends LinearLayout
|
|||
intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
|
||||
try {
|
||||
m_context.startActivity( intent );
|
||||
startActivity( intent );
|
||||
} catch ( android.content.ActivityNotFoundException anfe ) {
|
||||
DbgUtils.logf( "%s", anfe.toString() );
|
||||
}
|
||||
}
|
||||
} // lookupWord
|
||||
|
||||
public void setLang( int lang )
|
||||
private void setLang( int lang )
|
||||
{
|
||||
if ( null == s_langCodes ) {
|
||||
s_langCodes = getResources().getStringArray( R.array.language_codes );
|
||||
|
@ -223,20 +228,20 @@ public class LookupView extends LinearLayout
|
|||
}
|
||||
s_lookupNames = tmpNames.toArray( new String[tmpNames.size()] );
|
||||
s_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] );
|
||||
s_urlsAdapter = new ArrayAdapter<String>( m_context, LIST_LAYOUT,
|
||||
s_urlsAdapter = new ArrayAdapter<String>( this, LIST_LAYOUT,
|
||||
s_lookupNames );
|
||||
s_lang = lang;
|
||||
} // initLookup
|
||||
}
|
||||
}
|
||||
|
||||
private void setSummary( int id )
|
||||
{
|
||||
m_dialog.setTitle( m_context.getString( id ) );
|
||||
m_summary.setText( getString( id ) );
|
||||
}
|
||||
|
||||
private void setSummary( String word )
|
||||
{
|
||||
String title = Utils.format( m_context, R.string.pick_url_titlef, word );
|
||||
m_dialog.setTitle( title );
|
||||
String title = Utils.format( this, R.string.pick_url_titlef, word );
|
||||
m_summary.setText( title );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue