mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-07 20:46:17 +01:00
cleanup: move functions from Utils to DelegateBase (and make non-static)
This commit is contained in:
parent
38b9420fa0
commit
69482bf442
4 changed files with 64 additions and 64 deletions
|
@ -31,6 +31,9 @@ import android.view.MenuInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
@ -218,6 +221,50 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
|
|||
m_activity.runOnUiThread( runnable );
|
||||
}
|
||||
|
||||
public void setText( int id, String value )
|
||||
{
|
||||
EditText editText = (EditText)findViewById( id );
|
||||
if ( null != editText ) {
|
||||
editText.setText( value, TextView.BufferType.EDITABLE );
|
||||
}
|
||||
}
|
||||
|
||||
public String getText( int id )
|
||||
{
|
||||
EditText editText = (EditText)findViewById( id );
|
||||
return editText.getText().toString();
|
||||
}
|
||||
|
||||
public void setInt( int id, int value )
|
||||
{
|
||||
String str = Integer.toString( value );
|
||||
setText( id, str );
|
||||
}
|
||||
|
||||
public int getInt( int id )
|
||||
{
|
||||
int result = 0;
|
||||
String str = getText( id );
|
||||
try {
|
||||
result = Integer.parseInt( str );
|
||||
} catch ( NumberFormatException nfe ) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void setChecked( int id, boolean value )
|
||||
{
|
||||
CheckBox cbx = (CheckBox)findViewById( id );
|
||||
cbx.setChecked( value );
|
||||
}
|
||||
|
||||
public boolean getChecked( int id )
|
||||
{
|
||||
CheckBox cbx = (CheckBox)findViewById( id );
|
||||
return cbx.isChecked();
|
||||
}
|
||||
|
||||
protected void showDialog( DlgID dlgID )
|
||||
{
|
||||
m_delegate.showDialog( dlgID );
|
||||
|
|
|
@ -534,14 +534,14 @@ public class GameConfigDelegate extends DelegateBase
|
|||
(CheckBox)findViewById(R.id.join_public_room_check);
|
||||
m_joinPublicCheck.setOnClickListener( this );
|
||||
m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom );
|
||||
Utils.setChecked( m_activity, R.id.advertise_new_room_check,
|
||||
setChecked( R.id.advertise_new_room_check,
|
||||
m_car.ip_relay_advertiseRoom );
|
||||
m_publicRoomsSet =
|
||||
(LinearLayout)findViewById(R.id.public_rooms_set );
|
||||
m_privateRoomsSet =
|
||||
(LinearLayout)findViewById(R.id.private_rooms_set );
|
||||
|
||||
Utils.setText( m_activity, R.id.room_edit, m_car.ip_relay_invite );
|
||||
setText( R.id.room_edit, m_car.ip_relay_invite );
|
||||
|
||||
m_roomChoose = (Spinner)findViewById( R.id.room_spinner );
|
||||
|
||||
|
@ -561,11 +561,9 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
setSmartnessSpinner();
|
||||
|
||||
Utils.setChecked( m_activity, R.id.hints_allowed,
|
||||
!m_gi.hintsNotAllowed );
|
||||
Utils.setChecked( m_activity, R.id.pick_faceup,
|
||||
m_gi.allowPickTiles );
|
||||
Utils.setInt( m_activity, R.id.timer_minutes_edit,
|
||||
setChecked( R.id.hints_allowed, !m_gi.hintsNotAllowed );
|
||||
setChecked( R.id.pick_faceup, m_gi.allowPickTiles );
|
||||
setInt( R.id.timer_minutes_edit,
|
||||
m_gi.gameSeconds/60/m_gi.nPlayers );
|
||||
|
||||
CheckBox check = (CheckBox)findViewById( R.id.use_timer );
|
||||
|
@ -578,7 +576,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
};
|
||||
check.setOnCheckedChangeListener( lstnr );
|
||||
Utils.setChecked( m_activity, R.id.use_timer, m_gi.timerEnabled );
|
||||
setChecked( R.id.use_timer, m_gi.timerEnabled );
|
||||
|
||||
setBoardsizeSpinner();
|
||||
}
|
||||
|
@ -1067,11 +1065,11 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
m_gi.hintsNotAllowed = !Utils.getChecked( m_activity, R.id.hints_allowed );
|
||||
m_gi.allowPickTiles = Utils.getChecked( m_activity, R.id.pick_faceup );
|
||||
m_gi.timerEnabled = Utils.getChecked( m_activity, R.id.use_timer );
|
||||
m_gi.gameSeconds = 60 * m_gi.nPlayers *
|
||||
Utils.getInt( m_activity, R.id.timer_minutes_edit );
|
||||
m_gi.hintsNotAllowed = !getChecked( R.id.hints_allowed );
|
||||
m_gi.allowPickTiles = getChecked( R.id.pick_faceup );
|
||||
m_gi.timerEnabled = getChecked( R.id.use_timer );
|
||||
m_gi.gameSeconds =
|
||||
60 * m_gi.nPlayers * getInt( R.id.timer_minutes_edit );
|
||||
|
||||
int position = m_phoniesSpinner.getSelectedItemPosition();
|
||||
m_gi.phoniesAction = CurGameInfo.XWPhoniesChoice.values()[position];
|
||||
|
@ -1085,10 +1083,8 @@ public class GameConfigDelegate extends DelegateBase
|
|||
switch( m_conType ) {
|
||||
case COMMS_CONN_RELAY:
|
||||
m_car.ip_relay_seeksPublicRoom = m_joinPublicCheck.isChecked();
|
||||
DbgUtils.logf( "ip_relay_seeksPublicRoom: %b",
|
||||
m_car.ip_relay_seeksPublicRoom );
|
||||
m_car.ip_relay_advertiseRoom =
|
||||
Utils.getChecked( m_activity, R.id.advertise_new_room_check );
|
||||
getChecked( R.id.advertise_new_room_check );
|
||||
if ( m_car.ip_relay_seeksPublicRoom ) {
|
||||
SpinnerAdapter adapter = m_roomChoose.getAdapter();
|
||||
if ( null != adapter ) {
|
||||
|
@ -1098,8 +1094,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
} else {
|
||||
m_car.ip_relay_invite =
|
||||
Utils.getText( m_activity, R.id.room_edit ).trim();
|
||||
m_car.ip_relay_invite = getText( R.id.room_edit ).trim();
|
||||
}
|
||||
break;
|
||||
// nothing to save for BT yet
|
||||
|
|
|
@ -101,7 +101,7 @@ public class RelayGameDelegate extends DelegateBase
|
|||
|
||||
public void onClick( View view )
|
||||
{
|
||||
String room = Utils.getText( m_activity, R.id.room_edit ).trim();
|
||||
String room = getText( R.id.room_edit ).trim();
|
||||
if ( view == m_playButton ) {
|
||||
if ( room.length() == 0 ) {
|
||||
showOKOnlyDialog( R.string.no_empty_rooms );
|
||||
|
@ -127,7 +127,7 @@ public class RelayGameDelegate extends DelegateBase
|
|||
{
|
||||
boolean canSave = null != m_gameLock;
|
||||
if ( canSave ) {
|
||||
String name = Utils.getText( m_activity, R.id.local_name_edit );
|
||||
String name = getText( R.id.local_name_edit );
|
||||
if ( name.length() > 0 ) { // don't wipe existing
|
||||
m_gi.setFirstLocalName( name );
|
||||
}
|
||||
|
|
|
@ -283,12 +283,6 @@ public class Utils {
|
|||
return name;
|
||||
}
|
||||
|
||||
public static void setChecked( Activity activity, int id, boolean value )
|
||||
{
|
||||
CheckBox cbx = (CheckBox)activity.findViewById( id );
|
||||
cbx.setChecked( value );
|
||||
}
|
||||
|
||||
public static void setChecked( Dialog dialog, int id, boolean value )
|
||||
{
|
||||
CheckBox cbx = (CheckBox)dialog.findViewById( id );
|
||||
|
@ -303,38 +297,18 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void setText( Activity activity, int id, String value )
|
||||
{
|
||||
EditText editText = (EditText)activity.findViewById( id );
|
||||
if ( null != editText ) {
|
||||
editText.setText( value, TextView.BufferType.EDITABLE );
|
||||
}
|
||||
}
|
||||
|
||||
public static void setInt( Dialog dialog, int id, int value )
|
||||
{
|
||||
String str = Integer.toString(value);
|
||||
setText( dialog, id, str );
|
||||
}
|
||||
|
||||
public static void setInt( Activity activity, int id, int value )
|
||||
{
|
||||
String str = Integer.toString(value);
|
||||
setText( activity, id, str );
|
||||
}
|
||||
|
||||
public static void setEnabled( Dialog dialog, int id, boolean enabled )
|
||||
{
|
||||
View view = dialog.findViewById( id );
|
||||
view.setEnabled( enabled );
|
||||
}
|
||||
|
||||
public static boolean getChecked( Activity activity, int id )
|
||||
{
|
||||
CheckBox cbx = (CheckBox)activity.findViewById( id );
|
||||
return cbx.isChecked();
|
||||
}
|
||||
|
||||
public static boolean getChecked( Dialog dialog, int id )
|
||||
{
|
||||
CheckBox cbx = (CheckBox)dialog.findViewById( id );
|
||||
|
@ -347,12 +321,6 @@ public class Utils {
|
|||
return editText.getText().toString();
|
||||
}
|
||||
|
||||
public static String getText( Activity activity, int id )
|
||||
{
|
||||
EditText editText = (EditText)activity.findViewById( id );
|
||||
return editText.getText().toString();
|
||||
}
|
||||
|
||||
public static int getInt( Dialog dialog, int id )
|
||||
{
|
||||
String str = getText( dialog, id );
|
||||
|
@ -363,16 +331,6 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
public static int getInt( Activity activity, int id )
|
||||
{
|
||||
String str = getText( activity, id );
|
||||
try {
|
||||
return Integer.parseInt( str );
|
||||
} catch ( NumberFormatException nfe ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setItemVisible( Menu menu, int id, boolean enabled )
|
||||
{
|
||||
MenuItem item = menu.findItem( id );
|
||||
|
|
Loading…
Add table
Reference in a new issue