add ui support for min,max filtering of wordlist. Not yet wired into

jni.  But: even disabled it seems to lead to much slower scrolling, so
I need to investigate that before taking this any further.
This commit is contained in:
Andy2 2011-11-04 06:18:11 -07:00
parent 1bba95a985
commit fa14f02b69
4 changed files with 101 additions and 5 deletions

View file

@ -35,4 +35,32 @@
android:drawSelectorOnTop="false"
/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/min_len"
/>
<Spinner android:id="@+id/wordlen_min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/minmax_values"
android:drawSelectorOnTop="true"
android:prompt="@string/prompt_min_len"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/max_len"
/>
<Spinner android:id="@+id/wordlen_max"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/minmax_values"
android:drawSelectorOnTop="true"
android:prompt="@string/prompt_max_len"
/>
</LinearLayout>
</LinearLayout>

View file

@ -150,6 +150,23 @@
<item>86400</item>
</string-array>
<string-array name="minmax_values">
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
<item>13</item>
<item>14</item>
<item>15</item>
</string-array>
<string-array name="language_names">
<item></item> <!-- Unknown -->
<item>English</item> <!-- 1 -->

View file

@ -1790,4 +1790,9 @@
<string name="not_again_browse">This button opens the wordlist
browser on the current player\'s wordlist.</string>
<string name="min_len">Min len</string>
<string name="max_len">Max len</string>
<string name="prompt_min_len">Words no shorter than</string>
<string name="prompt_max_len">Words no longer than</string>
</resources>

View file

@ -32,7 +32,10 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.SectionIndexer;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import java.util.Arrays;
import junit.framework.Assert;
@ -41,15 +44,22 @@ import org.eehouse.android.xw4.jni.JNIUtilsImpl;
import org.eehouse.android.xw4.jni.XwJNI;
public class DictBrowseActivity extends XWListActivity
implements View.OnClickListener {
implements View.OnClickListener, OnItemSelectedListener {
public static final String DICT_NAME = "DICT_NAME";
private static final int MIN_LEN = 2;
private int m_dictClosure = 0;
private int m_lang;
private String m_name;
private int m_nWords;
private float m_textSize;
private Spinner m_minSpinner;
private Spinner m_maxSpinner;
private int m_min = MIN_LEN;
private int m_max;
// - Steps to reproduce the problem:
// Create ListView, set custom adapter which implements ListAdapter and
@ -137,13 +147,9 @@ public class DictBrowseActivity extends XWListActivity
setTitle( Utils.format( this, R.string.dict_browse_titlef,
name, m_nWords ) );
Utils.logf( "calling makeIndex" );
XwJNI.dict_iter_makeIndex( m_dictClosure );
Utils.logf( "makeIndex done" );
setContentView( R.layout.dict_browser );
setListAdapter( new DictListAdapter() );
getListView().setFastScrollEnabled( true );
Button button = (Button)findViewById( R.id.search_button );
button.setOnClickListener( new View.OnClickListener() {
@ -152,6 +158,17 @@ public class DictBrowseActivity extends XWListActivity
findButtonClicked();
}
} );
m_minSpinner = (Spinner)findViewById( R.id.wordlen_min );
m_minSpinner.setOnItemSelectedListener( this );
m_minSpinner.setSelection( 0 );
m_maxSpinner = (Spinner)findViewById( R.id.wordlen_max );
m_maxSpinner.setOnItemSelectedListener( this );
m_max = m_maxSpinner.getCount() + MIN_LEN - 1;
m_maxSpinner.setSelection( m_max - MIN_LEN );
setListAdapter( new DictListAdapter() );
getListView().setFastScrollEnabled( true );
}
}
@ -187,6 +204,25 @@ public class DictBrowseActivity extends XWListActivity
launchLookup( words, m_lang, true );
}
//////////////////////////////////////////////////
// AdapterView.OnItemSelectedListener interface
//////////////////////////////////////////////////
public void onItemSelected( AdapterView<?> parent, View view,
int position, long id )
{
int newval = position + MIN_LEN;
if ( parent == m_minSpinner ) {
setMinMax( newval, m_max );
} else if ( parent == m_maxSpinner ) {
setMinMax( m_min, newval );
}
}
public void onNothingSelected( AdapterView<?> parent )
{
}
private void findButtonClicked()
{
EditText edit = (EditText)findViewById( R.id.word_edit );
@ -202,6 +238,16 @@ public class DictBrowseActivity extends XWListActivity
}
}
private void setMinMax( int min, int max )
{
if ( m_min != min || m_max != max ) {
m_min = min;
m_max = max;
setListAdapter( new DictListAdapter() );
Utils.logf( "setMinMax(%d,%d)", min, max );
}
}
public static void launch( Context caller, String name )
{
Intent intent = new Intent( caller, DictBrowseActivity.class );