first set of EditTexts getting 'X' clear button

I'm using SearchView for now. Would rather have a custom layout without
a magnifying glass I need to hide, but this works for now.
This commit is contained in:
Eric House 2019-07-20 21:54:35 -07:00
parent af1ac3f779
commit 597bcebefa
8 changed files with 103 additions and 49 deletions

View file

@ -334,13 +334,13 @@ public class DictBrowseDelegate extends DelegateBase
private String getFindText()
{
EditText edit = (EditText)findViewById( R.id.word_edit );
EditWClear edit = (EditWClear)findViewById( R.id.word_edit );
return edit.getText().toString();
}
private void setFindText( String text )
{
EditText edit = (EditText)findViewById( R.id.word_edit );
EditWClear edit = (EditWClear)findViewById( R.id.word_edit );
edit.setText( text );
}

View file

@ -0,0 +1,43 @@
/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
/*
* Copyright 2019 by Eric House (xwords@eehouse.org). All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.widget.SearchView;
import android.content.Context;
import android.util.AttributeSet;
public class EditWClear extends SearchView {
private static final String TAG = EditWClear.class.getSimpleName();
public EditWClear( Context context, AttributeSet as )
{
super( context, as );
}
void setText( String txt )
{
super.setQuery( txt, false );
}
CharSequence getText()
{
return super.getQuery();
}
}

View file

@ -44,12 +44,6 @@ public class GameNamer extends LinearLayout {
view.setText( label );
}
public void setKeyListener( KeyListener lstnr )
{
EditText view = (EditText)findViewById( R.id.name_edit );
view.setKeyListener( lstnr );
}
public void setLabel( int id )
{
setLabel( LocUtils.getString( getContext(), id ) );
@ -57,14 +51,17 @@ public class GameNamer extends LinearLayout {
public void setName( String text )
{
EditText view = (EditText)findViewById( R.id.name_edit );
view.setText( text );
getEdit().setText( text );
}
public String getName()
{
EditText view = (EditText)findViewById( R.id.name_edit );
return view.getText().toString();
return getEdit().getText().toString();
}
private EditWClear getEdit()
{
EditWClear view = (EditWClear)findViewById( R.id.name_edit );
return view;
}
}

View file

@ -862,9 +862,10 @@ public class GamesListDelegate extends ListDelegateBase
case GAMES_LIST_NEWGAME: {
boolean solo = (Boolean)params[0];
LinearLayout view = (LinearLayout)
final LinearLayout view = (LinearLayout)
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit );
final EditText edit = (EditText)view.findViewById( R.id.edit );
final EditWClear edit = (EditWClear)view.findViewById( R.id.edit );
edit.setText( GameUtils.makeDefaultName( m_activity ) );
boolean canDoDefaults = solo ||
0 < XWPrefs.getAddrTypes( m_activity ).size();
@ -878,8 +879,6 @@ public class GamesListDelegate extends ListDelegateBase
}
TextView tmpEdit = (TextView)view.findViewById( R.id.msg );
tmpEdit.setText( msg );
tmpEdit = (TextView)view.findViewById( R.id.edit );
tmpEdit.setText( GameUtils.makeDefaultName( m_activity ) );
lstnr = new OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
@ -907,11 +906,11 @@ public class GamesListDelegate extends ListDelegateBase
break;
case GAMES_LIST_NAME_REMATCH: {
LinearLayout view = (LinearLayout)
final LinearLayout view = (LinearLayout)
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit );
int iconResID = R.drawable.sologame__gen;
if ( null != m_rematchExtras ) {
EditText edit = (EditText)view.findViewById( R.id.edit );
EditWClear edit = (EditWClear)view.findViewById( R.id.edit );
edit.setText( m_rematchExtras.getString( REMATCH_NEWNAME_EXTRA ));
boolean solo = m_rematchExtras.getBoolean( REMATCH_IS_SOLO, true );
if ( !solo ) {
@ -925,8 +924,9 @@ public class GamesListDelegate extends ListDelegateBase
.setTitle( R.string.button_rematch )
.setIcon( iconResID )
.setPositiveButton( android.R.string.ok, new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
EditText edit = (EditText)((Dialog)dlg)
EditWClear edit = (EditWClear)((Dialog)dlg)
.findViewById( R.id.edit );
String gameName = edit.getText().toString();
startRematchWithName( gameName, true );

View file

@ -23,15 +23,18 @@
android:layout_weight="0"
android:layout_below="@id/desc"
>
<EditText android:id="@+id/word_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text"
android:layout_weight="1"
android:hint="@string/word_search_hint"
android:capitalize="characters"
/>
<org.eehouse.android.xw4.EditWClear
android:id="@+id/word_edit"
style="@style/edit_w_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text"
android:layout_weight="1"
android:hint="@string/word_search_hint"
android:capitalize="characters"
/>
<Button android:id="@+id/search_button"
android:layout_width="wrap_content"

View file

@ -14,16 +14,18 @@
android:text="@string/game_name_label"
/>
<EditText android:id="@+id/edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollHorizontally="true"
android:maxLines="1"
android:inputType="textCapWords"
android:maxLength="32"
android:textAppearance="?android:attr/textAppearanceMedium"
android:selectAllOnFocus="true"
/>
<org.eehouse.android.xw4.EditWClear
android:id="@+id/edit"
style="@style/edit_w_clear"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollHorizontally="true"
android:maxLines="1"
android:inputType="textCapWords"
android:maxLength="32"
android:textAppearance="?android:attr/textAppearanceMedium"
android:selectAllOnFocus="true"
/>
<TextView android:id="@+id/msg"
android:layout_height="wrap_content"

View file

@ -14,15 +14,18 @@
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText android:id="@+id/name_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:autoText="false"
android:maxLines="1"
android:inputType="text"
android:selectAllOnFocus="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<org.eehouse.android.xw4.EditWClear
android:id="@+id/name_edit"
style="@style/edit_w_clear"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:autoText="false"
android:maxLines="1"
android:inputType="text"
android:selectAllOnFocus="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</org.eehouse.android.xw4.GameNamer>

View file

@ -105,4 +105,10 @@
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
</style>
<style name="edit_w_clear">
<item name="android:iconifiedByDefault">false</item>
<item name="android:searchIcon">@null</item>
<item name="android:searchHintIcon">@null</item>
</style>
</resources>