mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
when filtering, enter key hides keyboard and applies filter
This commit is contained in:
parent
e2b51beb60
commit
5736870357
3 changed files with 52 additions and 14 deletions
|
@ -30,6 +30,7 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
|
@ -58,7 +59,8 @@ import java.util.Arrays;
|
|||
import java.io.Serializable;
|
||||
|
||||
public class DictBrowseDelegate extends DelegateBase
|
||||
implements View.OnClickListener, View.OnLongClickListener {
|
||||
implements View.OnClickListener, View.OnLongClickListener,
|
||||
PatTableRow.EnterPressed {
|
||||
private static final String TAG = DictBrowseDelegate.class.getSimpleName();
|
||||
private static final String DELIM = ".";
|
||||
private static final boolean SHOW_NUM = false;
|
||||
|
@ -285,6 +287,7 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
}
|
||||
} // init
|
||||
|
||||
@Override
|
||||
protected void onPause()
|
||||
{
|
||||
scrapeBrowseState();
|
||||
|
@ -458,6 +461,17 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
return handled;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// PatTableRow.EnterPressed
|
||||
//////////////////////////////////////////////////
|
||||
@Override
|
||||
public boolean enterPressed()
|
||||
{
|
||||
hideSoftKeyboard();
|
||||
useButtonClicked();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void scrapeBrowseState()
|
||||
{
|
||||
Assert.assertTrueNR( null != m_browseState );
|
||||
|
@ -536,6 +550,7 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
PatTableRow row = (PatTableRow)child;
|
||||
m_rows[nFound++] = row;
|
||||
row.setOnFocusGained( mFocusGainedProc );
|
||||
row.setOnEnterPressed(this);
|
||||
}
|
||||
}
|
||||
Assert.assertTrueNR( nFound == m_rows.length );
|
||||
|
@ -804,6 +819,14 @@ public class DictBrowseDelegate extends DelegateBase
|
|||
tv.setText( summary );
|
||||
}
|
||||
|
||||
private void hideSoftKeyboard()
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager)
|
||||
m_activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow( m_activity.getCurrentFocus()
|
||||
.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
private static void launch( Delegator delegator, Bundle bundle )
|
||||
{
|
||||
delegator.addFragment( DictBrowseFrag.newInstance( delegator ),
|
||||
|
|
|
@ -21,28 +21,52 @@ package org.eehouse.android.xw4;
|
|||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.eehouse.android.xw4.jni.XwJNI.PatDesc;
|
||||
|
||||
public class PatTableRow extends TableRow {
|
||||
public class PatTableRow extends TableRow implements OnEditorActionListener {
|
||||
private static final String TAG = PatTableRow.class.getSimpleName();
|
||||
private EditText mEdit;
|
||||
private CheckBox mCheck;
|
||||
private EnterPressed mEnterProc;
|
||||
|
||||
public interface EnterPressed {
|
||||
public boolean enterPressed();
|
||||
}
|
||||
|
||||
public PatTableRow( Context context, AttributeSet as )
|
||||
{
|
||||
super( context, as );
|
||||
}
|
||||
|
||||
void setOnEnterPressed( EnterPressed proc ) { mEnterProc = proc; }
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate()
|
||||
{
|
||||
mCheck = (CheckBox)Utils.getChildInstanceOf( this, CheckBox.class );
|
||||
mEdit = (EditText)Utils.getChildInstanceOf( this, EditText.class );
|
||||
mEdit.setOnEditorActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction( TextView tv, int actionId, KeyEvent event )
|
||||
{
|
||||
return EditorInfo.IME_ACTION_SEND == actionId
|
||||
&& null != mEnterProc
|
||||
&& mEnterProc.enterPressed();
|
||||
}
|
||||
|
||||
public void getToDesc( PatDesc out )
|
||||
{
|
||||
getFields();
|
||||
|
||||
String strPat = mEdit.getText().toString();
|
||||
out.strPat = strPat;
|
||||
out.anyOrderOk = mCheck.isChecked();
|
||||
|
@ -50,16 +74,12 @@ public class PatTableRow extends TableRow {
|
|||
|
||||
public void setFromDesc( PatDesc desc )
|
||||
{
|
||||
getFields();
|
||||
|
||||
mEdit.setText(desc.strPat);
|
||||
mCheck.setChecked(desc.anyOrderOk);
|
||||
}
|
||||
|
||||
public boolean addBlankToFocussed( String blank )
|
||||
{
|
||||
getFields();
|
||||
|
||||
boolean handled = mEdit.hasFocus();
|
||||
if ( handled ) {
|
||||
mEdit.getText().insert(mEdit.getSelectionStart(), blank );
|
||||
|
@ -81,7 +101,6 @@ public class PatTableRow extends TableRow {
|
|||
|
||||
void setOnFocusGained( final Runnable proc )
|
||||
{
|
||||
getFields();
|
||||
mEdit.setOnFocusChangeListener( new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange( View view, boolean hasFocus )
|
||||
|
@ -93,9 +112,4 @@ public class PatTableRow extends TableRow {
|
|||
} );
|
||||
}
|
||||
|
||||
private void getFields()
|
||||
{
|
||||
mEdit = (EditText)Utils.getChildInstanceOf( this, EditText.class );
|
||||
mCheck = (CheckBox)Utils.getChildInstanceOf( this, CheckBox.class );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,6 +143,7 @@
|
|||
<item name="android:maxLength">15</item>
|
||||
<item name="android:inputType">textCapCharacters|textNoSuggestions</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
<item name="android:imeOptions">actionSend</item>
|
||||
</style>
|
||||
|
||||
<style name="pat_table_check">
|
||||
|
|
Loading…
Add table
Reference in a new issue