mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-13 20:48:02 +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.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
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.DlgDelegate.Action;
|
||||||
import org.eehouse.android.xw4.loc.LocUtils;
|
import org.eehouse.android.xw4.loc.LocUtils;
|
||||||
|
@ -218,6 +221,50 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
|
||||||
m_activity.runOnUiThread( runnable );
|
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 )
|
protected void showDialog( DlgID dlgID )
|
||||||
{
|
{
|
||||||
m_delegate.showDialog( dlgID );
|
m_delegate.showDialog( dlgID );
|
||||||
|
|
|
@ -534,14 +534,14 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
(CheckBox)findViewById(R.id.join_public_room_check);
|
(CheckBox)findViewById(R.id.join_public_room_check);
|
||||||
m_joinPublicCheck.setOnClickListener( this );
|
m_joinPublicCheck.setOnClickListener( this );
|
||||||
m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom );
|
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_car.ip_relay_advertiseRoom );
|
||||||
m_publicRoomsSet =
|
m_publicRoomsSet =
|
||||||
(LinearLayout)findViewById(R.id.public_rooms_set );
|
(LinearLayout)findViewById(R.id.public_rooms_set );
|
||||||
m_privateRoomsSet =
|
m_privateRoomsSet =
|
||||||
(LinearLayout)findViewById(R.id.private_rooms_set );
|
(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 );
|
m_roomChoose = (Spinner)findViewById( R.id.room_spinner );
|
||||||
|
|
||||||
|
@ -561,12 +561,10 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
|
|
||||||
setSmartnessSpinner();
|
setSmartnessSpinner();
|
||||||
|
|
||||||
Utils.setChecked( m_activity, R.id.hints_allowed,
|
setChecked( R.id.hints_allowed, !m_gi.hintsNotAllowed );
|
||||||
!m_gi.hintsNotAllowed );
|
setChecked( R.id.pick_faceup, m_gi.allowPickTiles );
|
||||||
Utils.setChecked( m_activity, R.id.pick_faceup,
|
setInt( R.id.timer_minutes_edit,
|
||||||
m_gi.allowPickTiles );
|
m_gi.gameSeconds/60/m_gi.nPlayers );
|
||||||
Utils.setInt( m_activity, R.id.timer_minutes_edit,
|
|
||||||
m_gi.gameSeconds/60/m_gi.nPlayers );
|
|
||||||
|
|
||||||
CheckBox check = (CheckBox)findViewById( R.id.use_timer );
|
CheckBox check = (CheckBox)findViewById( R.id.use_timer );
|
||||||
CompoundButton.OnCheckedChangeListener lstnr =
|
CompoundButton.OnCheckedChangeListener lstnr =
|
||||||
|
@ -578,7 +576,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
check.setOnCheckedChangeListener( lstnr );
|
check.setOnCheckedChangeListener( lstnr );
|
||||||
Utils.setChecked( m_activity, R.id.use_timer, m_gi.timerEnabled );
|
setChecked( R.id.use_timer, m_gi.timerEnabled );
|
||||||
|
|
||||||
setBoardsizeSpinner();
|
setBoardsizeSpinner();
|
||||||
}
|
}
|
||||||
|
@ -1067,11 +1065,11 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_gi.hintsNotAllowed = !Utils.getChecked( m_activity, R.id.hints_allowed );
|
m_gi.hintsNotAllowed = !getChecked( R.id.hints_allowed );
|
||||||
m_gi.allowPickTiles = Utils.getChecked( m_activity, R.id.pick_faceup );
|
m_gi.allowPickTiles = getChecked( R.id.pick_faceup );
|
||||||
m_gi.timerEnabled = Utils.getChecked( m_activity, R.id.use_timer );
|
m_gi.timerEnabled = getChecked( R.id.use_timer );
|
||||||
m_gi.gameSeconds = 60 * m_gi.nPlayers *
|
m_gi.gameSeconds =
|
||||||
Utils.getInt( m_activity, R.id.timer_minutes_edit );
|
60 * m_gi.nPlayers * getInt( R.id.timer_minutes_edit );
|
||||||
|
|
||||||
int position = m_phoniesSpinner.getSelectedItemPosition();
|
int position = m_phoniesSpinner.getSelectedItemPosition();
|
||||||
m_gi.phoniesAction = CurGameInfo.XWPhoniesChoice.values()[position];
|
m_gi.phoniesAction = CurGameInfo.XWPhoniesChoice.values()[position];
|
||||||
|
@ -1085,10 +1083,8 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
switch( m_conType ) {
|
switch( m_conType ) {
|
||||||
case COMMS_CONN_RELAY:
|
case COMMS_CONN_RELAY:
|
||||||
m_car.ip_relay_seeksPublicRoom = m_joinPublicCheck.isChecked();
|
m_car.ip_relay_seeksPublicRoom = m_joinPublicCheck.isChecked();
|
||||||
DbgUtils.logf( "ip_relay_seeksPublicRoom: %b",
|
|
||||||
m_car.ip_relay_seeksPublicRoom );
|
|
||||||
m_car.ip_relay_advertiseRoom =
|
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 ) {
|
if ( m_car.ip_relay_seeksPublicRoom ) {
|
||||||
SpinnerAdapter adapter = m_roomChoose.getAdapter();
|
SpinnerAdapter adapter = m_roomChoose.getAdapter();
|
||||||
if ( null != adapter ) {
|
if ( null != adapter ) {
|
||||||
|
@ -1098,8 +1094,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m_car.ip_relay_invite =
|
m_car.ip_relay_invite = getText( R.id.room_edit ).trim();
|
||||||
Utils.getText( m_activity, R.id.room_edit ).trim();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// nothing to save for BT yet
|
// nothing to save for BT yet
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class RelayGameDelegate extends DelegateBase
|
||||||
|
|
||||||
public void onClick( View view )
|
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 ( view == m_playButton ) {
|
||||||
if ( room.length() == 0 ) {
|
if ( room.length() == 0 ) {
|
||||||
showOKOnlyDialog( R.string.no_empty_rooms );
|
showOKOnlyDialog( R.string.no_empty_rooms );
|
||||||
|
@ -127,7 +127,7 @@ public class RelayGameDelegate extends DelegateBase
|
||||||
{
|
{
|
||||||
boolean canSave = null != m_gameLock;
|
boolean canSave = null != m_gameLock;
|
||||||
if ( canSave ) {
|
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
|
if ( name.length() > 0 ) { // don't wipe existing
|
||||||
m_gi.setFirstLocalName( name );
|
m_gi.setFirstLocalName( name );
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,12 +283,6 @@ public class Utils {
|
||||||
return name;
|
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 )
|
public static void setChecked( Dialog dialog, int id, boolean value )
|
||||||
{
|
{
|
||||||
CheckBox cbx = (CheckBox)dialog.findViewById( id );
|
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 )
|
public static void setInt( Dialog dialog, int id, int value )
|
||||||
{
|
{
|
||||||
String str = Integer.toString(value);
|
String str = Integer.toString(value);
|
||||||
setText( dialog, id, str );
|
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 )
|
public static void setEnabled( Dialog dialog, int id, boolean enabled )
|
||||||
{
|
{
|
||||||
View view = dialog.findViewById( id );
|
View view = dialog.findViewById( id );
|
||||||
view.setEnabled( enabled );
|
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 )
|
public static boolean getChecked( Dialog dialog, int id )
|
||||||
{
|
{
|
||||||
CheckBox cbx = (CheckBox)dialog.findViewById( id );
|
CheckBox cbx = (CheckBox)dialog.findViewById( id );
|
||||||
|
@ -347,12 +321,6 @@ public class Utils {
|
||||||
return editText.getText().toString();
|
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 )
|
public static int getInt( Dialog dialog, int id )
|
||||||
{
|
{
|
||||||
String str = getText( dialog, 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 )
|
public static void setItemVisible( Menu menu, int id, boolean enabled )
|
||||||
{
|
{
|
||||||
MenuItem item = menu.findItem( id );
|
MenuItem item = menu.findItem( id );
|
||||||
|
|
Loading…
Add table
Reference in a new issue