set and save new booleans, etc. Relay params UI seems to work now

except for listing public rooms (still hard-coded)
This commit is contained in:
Andy2 2010-09-03 06:39:46 -07:00
parent b742c7dbb7
commit e6545d8d57
4 changed files with 48 additions and 12 deletions

View file

@ -74,7 +74,7 @@
<!-- We'll use either the spinner or simple edit text
depending on whether user is naming room or picking from
a set one. -->
<CheckBox android:id="@+id/join_room_check"
<CheckBox android:id="@+id/join_public_room_check"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/join_room"
@ -93,7 +93,7 @@
android:capitalize="none"
android:hint="@string/new_room_hint"
/>
<CheckBox android:id="@+id/room_public_check"
<CheckBox android:id="@+id/advertise_new_room_check"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/room_public"
@ -111,6 +111,7 @@
android:drawSelectorOnTop="true"
android:gravity="left"
android:layout_weight="1"
android:prompt="@string/room_public_prompt"
/>
<ImageButton android:id="@+id/refresh_button"
android:layout_width="wrap_content"

View file

@ -166,6 +166,7 @@
<string name="room_public">Make new room public</string>
<string name="join_room">Join public room</string>
<string name="new_room_hint">New room name</string>
<string name="room_public_prompt">Pick room to play in</string>
<string name="configure_role">Configure connection</string>
<string name="configure_rolef">Configure %s connection</string>

View file

@ -48,6 +48,7 @@ import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ListAdapter;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
import android.database.DataSetObserver;
import junit.framework.Assert;
@ -66,8 +67,7 @@ public class GameConfig extends Activity implements View.OnClickListener,
private static final int CONFIRM_CHANGE = 6;
private CheckBox m_notNetworkedGameCheckbx;
private CheckBox m_joinRoomCheck;
private EditText m_roomEdit;
private CheckBox m_joinPublicCheck;
private LinearLayout m_publicRoomsSet;
private LinearLayout m_privateRoomsSet;
@ -348,12 +348,14 @@ public class GameConfig extends Activity implements View.OnClickListener,
// m_notNetworkedGameCheckbx.setChecked( true );
// m_notNetworkedGame = true;
m_joinRoomCheck = (CheckBox)findViewById(R.id.join_room_check);
m_joinRoomCheck.setOnClickListener( this );
m_roomEdit = (EditText)findViewById(R.id.room_edit);
m_joinPublicCheck = (CheckBox)findViewById(R.id.join_public_room_check);
m_joinPublicCheck.setOnClickListener( this );
m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom );
Utils.setChecked( this, 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 );
adjustConnectStuff();
Utils.setText( this, R.id.room_edit, m_car.ip_relay_invite );
m_addPlayerButton = (Button)findViewById(R.id.add_player);
m_addPlayerButton.setOnClickListener( this );
@ -372,6 +374,8 @@ public class GameConfig extends Activity implements View.OnClickListener,
rooms );
m_roomChoose.setAdapter( adapter );
adjustConnectStuff();
m_playerLayout = (LinearLayout)findViewById( R.id.player_list );
m_notNetworkedGame = DeviceRole.SERVER_STANDALONE == m_gi.serverRole;
m_notNetworkedGameCheckbx.setChecked( m_notNetworkedGame );
@ -458,7 +462,7 @@ public class GameConfig extends Activity implements View.OnClickListener,
: DeviceRole.SERVER_ISSERVER );
loadPlayers();
} else if ( m_joinRoomCheck == view ) {
} else if ( m_joinPublicCheck == view ) {
adjustConnectStuff();
// } else if ( m_configureButton == view ) {
// int position = m_connectSpinner.getSelectedItemPosition();
@ -666,9 +670,21 @@ public class GameConfig extends Activity implements View.OnClickListener,
private void adjustConnectStuff()
{
if ( m_joinRoomCheck.isChecked() ) {
if ( m_joinPublicCheck.isChecked() ) {
m_privateRoomsSet.setVisibility( View.GONE );
m_publicRoomsSet.setVisibility( View.VISIBLE );
// make the room spinner match the saved value if present
String invite = m_car.ip_relay_invite;
ArrayAdapter<String> adapter =
(ArrayAdapter<String>)m_roomChoose.getAdapter();
for ( int ii = 0; ii < adapter.getCount(); ++ii ) {
if ( adapter.getItem(ii).equals( invite ) ) {
m_roomChoose.setSelection( ii );
break;
}
}
} else {
m_privateRoomsSet.setVisibility( View.VISIBLE );
m_publicRoomsSet.setVisibility( View.GONE );
@ -751,6 +767,22 @@ public class GameConfig extends Activity implements View.OnClickListener,
int position = m_phoniesSpinner.getSelectedItemPosition();
m_gi.phoniesAction = CurGameInfo.XWPhoniesChoice.values()[position];
if ( !m_notNetworkedGame ) {
m_car.ip_relay_seeksPublicRoom = m_joinPublicCheck.isChecked();
Utils.logf( "ip_relay_seeksPublicRoom: %s",
m_car.ip_relay_seeksPublicRoom?"true":"false" );
m_car.ip_relay_advertiseRoom =
Utils.getChecked( this, R.id.advertise_new_room_check );
if ( m_car.ip_relay_seeksPublicRoom ) {
ArrayAdapter<String> adapter =
(ArrayAdapter<String>)m_roomChoose.getAdapter();
m_car.ip_relay_invite =
adapter.getItem(m_roomChoose.getSelectedItemPosition());
} else {
m_car.ip_relay_invite = Utils.getText( this, R.id.room_edit );
}
}
m_gi.fixup();
// position = m_connectSpinner.getSelectedItemPosition();

View file

@ -45,6 +45,8 @@ public class CommsAddrRec {
public String ip_relay_hostName;
public InetAddress ip_relay_ipAddr; // a cache, maybe unused in java
public int ip_relay_port;
public boolean ip_relay_seeksPublicRoom;
public boolean ip_relay_advertiseRoom;
// sms case
public String sms_phone;
@ -52,9 +54,7 @@ public class CommsAddrRec {
public CommsAddrRec( Context context )
{
Utils.logf( "CommsAddrRec() called " );
conType = CommsConnType.COMMS_CONN_RELAY;
ip_relay_invite = "Room 1";
ip_relay_hostName = CommonPrefs.getDefaultRelayHost( context );
ip_relay_port = CommonPrefs.getDefaultRelayPort( context );
}
@ -81,5 +81,7 @@ public class CommsAddrRec {
ip_relay_invite = src.ip_relay_invite;
ip_relay_hostName = src.ip_relay_hostName;
ip_relay_port = src.ip_relay_port;
ip_relay_seeksPublicRoom = src.ip_relay_seeksPublicRoom;
ip_relay_advertiseRoom = src.ip_relay_advertiseRoom;
}
}