mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
add UI (some of it rough) to invite to play a new game via NBS and to
invite if a game is opened that has not been connected to yet.
This commit is contained in:
parent
905be85e92
commit
60d91f1a21
15 changed files with 402 additions and 47 deletions
|
@ -65,6 +65,9 @@
|
|||
<activity android:name="BTInviteActivity"
|
||||
android:theme="@android:style/Theme.Dialog"
|
||||
/>
|
||||
<activity android:name="NBSInviteActivity"
|
||||
android:theme="@android:style/Theme.Dialog"
|
||||
/>
|
||||
|
||||
<activity android:name="GameConfig"
|
||||
android:screenOrientation="sensor"
|
||||
|
|
|
@ -27,3 +27,4 @@ prefs_w_buttons.xml
|
|||
relay_game_config.xml
|
||||
rename_game.xml
|
||||
select_dialog_item.xml
|
||||
nbsinviter.xml
|
||||
|
|
|
@ -51,3 +51,4 @@ XWListItem.java
|
|||
XWListPreference.java
|
||||
GameNamer.java
|
||||
LookupActivity.java
|
||||
NBSInviteActivity.java
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.eehouse.android.xw4bt.jni.XwJNI;
|
|||
public class XWApp extends Application {
|
||||
|
||||
public static final boolean BTSUPPORTED = true;
|
||||
public static final boolean SMSSUPPORTED = true;
|
||||
public static final boolean NBSSUPPORTED = true;
|
||||
|
||||
private static UUID s_UUID = null;
|
||||
|
||||
|
|
34
xwords4/android/XWords4/res/layout/nbsinviter.xml
Normal file
34
xwords4/android/XWords4/res/layout/nbsinviter.xml
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
|
||||
<TextView android:id="@+id/invite_desc"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
|
||||
<EditText android:id="@+id/phone_edit"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_marginLeft="20dip"
|
||||
android:layout_marginRight="20dip"
|
||||
android:scrollHorizontally="true"
|
||||
android:phoneNumber="true"
|
||||
android:singleLine="true"
|
||||
android:maxLength="15"
|
||||
android:selectAllOnFocus="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
|
||||
<Button android:id="@+id/button_invite"
|
||||
android:text="@string/button_invite"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
|
@ -105,32 +105,32 @@
|
|||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Bluetooth -->
|
||||
<TextView android:id="@+id/bt_separator"
|
||||
<!-- NBS -->
|
||||
<TextView android:id="@+id/nbs_separator"
|
||||
style="@style/config_separator"
|
||||
android:layout_marginTop="10dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/newgame_bt_header"
|
||||
android:text="@string/newgame_nbs_header"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<LinearLayout android:id="@+id/bt_disabled"
|
||||
<LinearLayout android:id="@+id/nbs_disabled"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<TextView android:text="@string/bt_disabled"
|
||||
>
|
||||
<TextView android:text="@string/nbs_disabled"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
<Button android:id="@+id/newgame_enable_bt"
|
||||
<Button android:id="@+id/newgame_enable_nbs"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newgame_enable_bt"
|
||||
android:text="@string/newgame_enable_nbs"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/bt_stuff"
|
||||
<LinearLayout android:id="@+id/nbs_stuff"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -142,13 +142,13 @@
|
|||
android:layout_marginTop="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
>
|
||||
<ImageView android:src="@android:drawable/stat_sys_data_bluetooth"
|
||||
<ImageView android:src="@android:drawable/sym_action_chat"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
/>
|
||||
<TextView android:text="@string/bt_networked_desc"
|
||||
<TextView android:text="@string/nbs_networked_desc"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
@ -157,21 +157,88 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<Button android:id="@+id/newgame_invite_bt"
|
||||
<Button android:id="@+id/newgame_invite_nbs"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newgame_invite"
|
||||
/>
|
||||
|
||||
<Button android:id="@+id/newgame_bt_config"
|
||||
<Button android:id="@+id/newgame_nbs_config"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newgame_net_config"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Bluetooth -->
|
||||
<TextView android:id="@+id/bt_separator"
|
||||
style="@style/config_separator"
|
||||
android:layout_marginTop="10dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/newgame_bt_header"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<LinearLayout android:id="@+id/bt_disabled"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<TextView android:text="@string/bt_disabled"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
<Button android:id="@+id/newgame_enable_bt"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newgame_enable_bt"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/bt_stuff"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
>
|
||||
<ImageView android:src="@android:drawable/stat_sys_data_bluetooth"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
/>
|
||||
<TextView android:text="@string/bt_networked_desc"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<Button android:id="@+id/newgame_invite_bt"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newgame_invite"
|
||||
/>
|
||||
|
||||
<Button android:id="@+id/newgame_bt_config"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newgame_net_config"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
|
|
@ -1874,4 +1874,15 @@
|
|||
<string name="game_btname_title">Bluetooth game name</string>
|
||||
<string name="dft_bt_namef">Game %X</string>
|
||||
|
||||
<string name="newgame_nbs_header">New SMS Game</string>
|
||||
<string name="nbs_networked_desc">Create a game that will be
|
||||
played via invisible text messages. !!!DO NOT DO THIS UNLESS YOU HAVE
|
||||
AN UNLIMITED TEXT MESSAGING PLAN!!!</string>
|
||||
<string name="nbs_disabled">nbs_disabled</string>
|
||||
<string name="newgame_enable_nbs">newgame_enable_nbs</string>
|
||||
<string name="err_no_phone">Phone number required</string>
|
||||
<string name="dft_nbs_namef">SMS Game %X</string>
|
||||
<string name="nbs_devs_missing">Missing connections? Invite SMS
|
||||
devs? (I won\'t ask again until you reopen this game.)</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -76,6 +76,7 @@ public class BoardActivity extends XWActivity
|
|||
|
||||
private static final int CHAT_REQUEST = 1;
|
||||
private static final int BT_INVITE_RESULT = 2;
|
||||
private static final int NBS_INVITE_RESULT = 3;
|
||||
|
||||
private static final int SCREEN_ON_TIME = 10 * 60 * 1000; // 10 mins
|
||||
|
||||
|
@ -96,6 +97,7 @@ public class BoardActivity extends XWActivity
|
|||
private static final int BUTTON_BROWSE_ACTION = 15;
|
||||
private static final int VALUES_ACTION = 16;
|
||||
private static final int BT_PICK_ACTION = 17;
|
||||
private static final int NBS_PICK_ACTION = 18;
|
||||
|
||||
private static final String DLG_TITLE = "DLG_TITLE";
|
||||
private static final String DLG_TITLESTR = "DLG_TITLESTR";
|
||||
|
@ -127,7 +129,8 @@ public class BoardActivity extends XWActivity
|
|||
private int m_dlgTitle;
|
||||
private String m_dlgTitleStr;
|
||||
private String[] m_texts;
|
||||
private String[] m_btDevs;
|
||||
private CommsAddrRec.CommsConnType m_missingType;
|
||||
private String[] m_missingDevs;
|
||||
private String m_curTiles;
|
||||
private boolean m_canUndoTiles;
|
||||
private boolean m_firingPrefs;
|
||||
|
@ -527,7 +530,12 @@ public class BoardActivity extends XWActivity
|
|||
case BT_INVITE_RESULT:
|
||||
// onActivityResult is called immediately *before*
|
||||
// onResume -- meaning m_gi etc are still null.
|
||||
m_btDevs = data.getStringArrayExtra( BTInviteActivity.DEVS );
|
||||
m_missingDevs = data.getStringArrayExtra( BTInviteActivity.DEVS );
|
||||
break;
|
||||
case NBS_INVITE_RESULT:
|
||||
// onActivityResult is called immediately *before*
|
||||
// onResume -- meaning m_gi etc are still null.
|
||||
m_missingDevs = data.getStringArrayExtra( NBSInviteActivity.DEVS );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -737,6 +745,10 @@ public class BoardActivity extends XWActivity
|
|||
GameUtils.launchBTInviter( this, m_nMissingPlayers,
|
||||
BT_INVITE_RESULT );
|
||||
break;
|
||||
case NBS_PICK_ACTION:
|
||||
GameUtils.launchNBSInviter( this, m_nMissingPlayers,
|
||||
NBS_INVITE_RESULT );
|
||||
break;
|
||||
case COMMIT_ACTION:
|
||||
cmd = JNIThread.JNICmd.CMD_COMMIT;
|
||||
break;
|
||||
|
@ -1332,17 +1344,32 @@ public class BoardActivity extends XWActivity
|
|||
CommsAddrRec.CommsConnType connType,
|
||||
final int nMissingPlayers )
|
||||
{
|
||||
if ( 0 < nMissingPlayers && isServer && !m_haveInvited
|
||||
&& CommsAddrRec.CommsConnType.COMMS_CONN_BT == connType ) {
|
||||
int msgID = 0;
|
||||
int action = 0;
|
||||
if ( 0 < nMissingPlayers && isServer && !m_haveInvited ) {
|
||||
switch( connType ) {
|
||||
case COMMS_CONN_BT:
|
||||
msgID = R.string.bt_devs_missing;
|
||||
action = BT_PICK_ACTION;
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
msgID = R.string.nbs_devs_missing;
|
||||
action = NBS_PICK_ACTION;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( 0 != action ) {
|
||||
m_haveInvited = true;
|
||||
m_missingType = connType;
|
||||
final int faction = action;
|
||||
final int fmsgID = msgID;
|
||||
post( new Runnable() {
|
||||
public void run() {
|
||||
DbgUtils.showf( BoardActivity.this,
|
||||
"%d players missing",
|
||||
nMissingPlayers );
|
||||
m_nMissingPlayers = nMissingPlayers;
|
||||
showConfirmThen( R.string.bt_devs_missing,
|
||||
BT_PICK_ACTION );
|
||||
showConfirmThen( fmsgID, faction );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
@ -1523,7 +1550,7 @@ public class BoardActivity extends XWActivity
|
|||
if ( null != m_xport ) {
|
||||
trySendChats();
|
||||
m_xport.tickle();
|
||||
tryBTInvites();
|
||||
tryInvites();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1694,17 +1721,32 @@ public class BoardActivity extends XWActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void tryBTInvites()
|
||||
private void tryInvites()
|
||||
{
|
||||
if ( XWApp.BTSUPPORTED && null != m_btDevs ) {
|
||||
String gameName = GameUtils.getName( this, m_rowid );
|
||||
m_invitesPending = m_btDevs.length;
|
||||
for ( String dev : m_btDevs ) {
|
||||
BTService.inviteRemote( this, dev, m_gi.gameID, gameName,
|
||||
m_gi.dictLang, m_gi.nPlayers, 1 );
|
||||
if ( XWApp.BTSUPPORTED || XWApp.NBSSUPPORTED ) {
|
||||
if ( null != m_missingDevs ) {
|
||||
String gameName = GameUtils.getName( this, m_rowid );
|
||||
boolean doProgress = false;
|
||||
m_invitesPending = m_missingDevs.length;
|
||||
for ( String dev : m_missingDevs ) {
|
||||
switch( m_missingType ) {
|
||||
case COMMS_CONN_BT:
|
||||
BTService.inviteRemote( this, dev, m_gi.gameID,
|
||||
gameName, m_gi.dictLang,
|
||||
m_gi.nPlayers, 1 );
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
NBSReceiver.inviteRemote( this, dev, m_gi.gameID,
|
||||
gameName, m_gi.dictLang,
|
||||
m_gi.nPlayers, 1 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( doProgress ) {
|
||||
startProgress( R.string.invite_progress );
|
||||
}
|
||||
m_missingDevs = null;
|
||||
}
|
||||
startProgress( R.string.invite_progress );
|
||||
m_btDevs = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -198,6 +198,8 @@ public class GameListAdapter extends XWListAdapter {
|
|||
}
|
||||
} else if ( CommsConnType.COMMS_CONN_BT == conType ) {
|
||||
iconID = android.R.drawable.stat_sys_data_bluetooth;
|
||||
} else if ( CommsConnType.COMMS_CONN_SMS == conType ) {
|
||||
iconID = android.R.drawable.sym_action_chat;
|
||||
} else {
|
||||
iconID = R.drawable.sologame;
|
||||
}
|
||||
|
|
|
@ -454,6 +454,20 @@ public class GameUtils {
|
|||
null, gameID, isHost );
|
||||
}
|
||||
|
||||
public static long makeNewNBSGame( Context context, int gameID,
|
||||
CommsAddrRec addr, int lang,
|
||||
int nPlayersT, int nPlayersH )
|
||||
{
|
||||
long rowid = -1;
|
||||
int[] langa = { lang };
|
||||
boolean isHost = null == addr;
|
||||
if ( isHost ) {
|
||||
addr = new CommsAddrRec( context, null, 0 );
|
||||
}
|
||||
return makeNewMultiGame( context, addr, langa, nPlayersT, nPlayersH,
|
||||
null, gameID, isHost );
|
||||
}
|
||||
|
||||
public static void launchBTInviter( Activity activity, int nMissing,
|
||||
int requestCode )
|
||||
{
|
||||
|
@ -462,6 +476,14 @@ public class GameUtils {
|
|||
activity.startActivityForResult( intent, requestCode );
|
||||
}
|
||||
|
||||
public static void launchNBSInviter( Activity activity, int nMissing,
|
||||
int requestCode )
|
||||
{
|
||||
Intent intent = new Intent( activity, NBSInviteActivity.class );
|
||||
intent.putExtra( NBSInviteActivity.INTENT_KEY_NMISSING, nMissing );
|
||||
activity.startActivityForResult( intent, requestCode );
|
||||
}
|
||||
|
||||
public static void launchInviteActivity( Context context,
|
||||
boolean choseEmail,
|
||||
String room, String inviteID,
|
||||
|
|
|
@ -195,7 +195,7 @@ public class GamesList extends XWListActivity
|
|||
|
||||
// THIS IS FOR TESTING ONLY; DON'T SHIP
|
||||
case SEND_NBS:
|
||||
Assert.assertTrue( XWApp.SMSSUPPORTED );
|
||||
Assert.assertTrue( XWApp.NBSSUPPORTED );
|
||||
final GameNamer phoneNumView =
|
||||
(GameNamer)Utils.inflate( this, R.layout.rename_game );
|
||||
phoneNumView.setName( m_nbsPhone );
|
||||
|
@ -554,7 +554,7 @@ public class GamesList extends XWListActivity
|
|||
switch (item.getItemId()) {
|
||||
// for testing only; don't ship
|
||||
case R.id.gamel_menu_trynbs:
|
||||
if ( XWApp.SMSSUPPORTED ) {
|
||||
if ( XWApp.NBSSUPPORTED ) {
|
||||
showDialog( SEND_NBS );
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/* -*- compile-command: "cd ../../../../../; ant debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2009-2011 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.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class NBSInviteActivity extends XWActivity
|
||||
implements View.OnClickListener {
|
||||
public static final String DEVS = "DEVS";
|
||||
public static final String INTENT_KEY_NMISSING = "NMISSING";
|
||||
|
||||
private Button m_okButton;
|
||||
private EditText m_edit;
|
||||
private int m_nMissing;
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
super.onCreate( savedInstanceState );
|
||||
|
||||
Intent intent = getIntent();
|
||||
m_nMissing = intent.getIntExtra( INTENT_KEY_NMISSING, -1 );
|
||||
Assert.assertTrue( 1 == m_nMissing );
|
||||
|
||||
setContentView( R.layout.nbsinviter );
|
||||
|
||||
m_okButton = (Button)findViewById( R.id.button_invite );
|
||||
m_okButton.setOnClickListener( this );
|
||||
}
|
||||
|
||||
public void onClick( View view )
|
||||
{
|
||||
if ( m_okButton == view ) {
|
||||
EditText edit = (EditText)findViewById( R.id.phone_edit );
|
||||
String phone = edit.getText().toString();
|
||||
if ( null != phone && 0 < phone.length() ) {
|
||||
Intent intent = new Intent();
|
||||
String[] devs = { phone };
|
||||
intent.putExtra( DEVS, devs );
|
||||
setResult( Activity.RESULT_OK, intent );
|
||||
finish();
|
||||
} else {
|
||||
showOKOnlyDialog( R.string.err_no_phone );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -79,4 +79,13 @@ public class NBSReceiver extends BroadcastReceiver {
|
|||
DbgUtils.logf( "%s", iae.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
public static void inviteRemote( Context context, String phone,
|
||||
int gameID, String gameName,
|
||||
int lang, int nPlayersT,
|
||||
int nPlayersH )
|
||||
{
|
||||
DbgUtils.logf( "NBSReceiver.inviteRemote(phone=%s)", phone );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,9 @@ public class NewGameActivity extends XWActivity {
|
|||
private static final String SAVE_REMOTEGAME = "REMOTEGAME";
|
||||
private static final String SAVE_GAMEID = "GAMEID";
|
||||
private static final int CONFIG_FOR_BT = 1;
|
||||
private static final int INVITE_FOR_BT = 2;
|
||||
private static final int CONFIG_FOR_NBS = 2;
|
||||
private static final int INVITE_FOR_BT = 3;
|
||||
private static final int INVITE_FOR_NBS = 4;
|
||||
|
||||
// Dialogs
|
||||
private static final int NAME_GAME = DlgDelegate.DIALOG_LAST + 1;
|
||||
|
@ -59,10 +61,10 @@ public class NewGameActivity extends XWActivity {
|
|||
private boolean m_showsOn;
|
||||
private int m_chosen;
|
||||
private int m_lang = 0;
|
||||
private long m_btRowID = -1;
|
||||
private long m_newRowID = -1;
|
||||
private String m_gameName;
|
||||
private int m_gameID;
|
||||
private String m_remoteBTDev;
|
||||
private String m_remoteDev;
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
|
@ -111,20 +113,21 @@ public class NewGameActivity extends XWActivity {
|
|||
} );
|
||||
|
||||
checkEnableBT( true );
|
||||
checkEnableNBS();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState( Bundle outState )
|
||||
{
|
||||
super.onSaveInstanceState( outState );
|
||||
outState.putString( SAVE_REMOTEGAME, m_remoteBTDev );
|
||||
outState.putString( SAVE_REMOTEGAME, m_remoteDev );
|
||||
outState.putInt( SAVE_GAMEID, m_gameID );
|
||||
}
|
||||
|
||||
private void getBundledData( Bundle bundle )
|
||||
{
|
||||
if ( null != bundle ) {
|
||||
m_remoteBTDev = bundle.getString( SAVE_REMOTEGAME );
|
||||
m_remoteDev = bundle.getString( SAVE_REMOTEGAME );
|
||||
m_gameID = bundle.getInt( SAVE_GAMEID );
|
||||
}
|
||||
}
|
||||
|
@ -157,12 +160,13 @@ public class NewGameActivity extends XWActivity {
|
|||
if ( Activity.RESULT_CANCELED != resultCode ) {
|
||||
switch ( requestCode ) {
|
||||
case CONFIG_FOR_BT:
|
||||
case CONFIG_FOR_NBS:
|
||||
if ( Activity.RESULT_CANCELED == resultCode ) {
|
||||
DBUtils.deleteGame( this, m_btRowID );
|
||||
DBUtils.deleteGame( this, m_newRowID );
|
||||
} else {
|
||||
// We'll leave it up to BoardActivity to detect that
|
||||
// it's not had any remote connections yet.
|
||||
GameUtils.launchGame( this, m_btRowID );
|
||||
GameUtils.launchGame( this, m_newRowID );
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
|
@ -171,7 +175,7 @@ public class NewGameActivity extends XWActivity {
|
|||
String[] remoteDevs =
|
||||
data.getStringArrayExtra( BTInviteActivity.DEVS );
|
||||
Assert.assertTrue( 1 == remoteDevs.length );
|
||||
m_remoteBTDev = remoteDevs[0];
|
||||
m_remoteDev = remoteDevs[0];
|
||||
|
||||
m_gameID = GameUtils.newGameID();
|
||||
m_gameName = Utils.format( this, R.string.dft_bt_namef,
|
||||
|
@ -179,6 +183,27 @@ public class NewGameActivity extends XWActivity {
|
|||
showDialog( NAME_GAME );
|
||||
}
|
||||
break;
|
||||
|
||||
case INVITE_FOR_NBS:
|
||||
if ( Activity.RESULT_CANCELED != resultCode ) {
|
||||
String[] phones =
|
||||
data.getStringArrayExtra( NBSInviteActivity.DEVS );
|
||||
Assert.assertTrue( 1 == phones.length );
|
||||
|
||||
m_gameID = GameUtils.newGameID();
|
||||
m_gameName = Utils.format( this, R.string.dft_nbs_namef,
|
||||
m_gameID & 0xFFFF );
|
||||
NBSReceiver.inviteRemote( NewGameActivity.this, phones[0],
|
||||
m_gameID, m_gameName,
|
||||
m_lang, 2, 1 );
|
||||
long rowid =
|
||||
GameUtils.makeNewNBSGame( NewGameActivity.this,
|
||||
m_gameID, null, m_lang,
|
||||
2, 1 );
|
||||
GameUtils.launchGame( NewGameActivity.this, rowid, true );
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +225,7 @@ public class NewGameActivity extends XWActivity {
|
|||
public void onClick( DialogInterface dlg, int itm ) {
|
||||
m_gameName = namerView.getName();
|
||||
BTService.inviteRemote( NewGameActivity.this,
|
||||
m_remoteBTDev,
|
||||
m_remoteDev,
|
||||
m_gameID, m_gameName,
|
||||
m_lang, 2, 1 );
|
||||
startProgress( R.string.invite_progress );
|
||||
|
@ -310,12 +335,12 @@ public class NewGameActivity extends XWActivity {
|
|||
{
|
||||
int gameID = GameUtils.newGameID();
|
||||
if ( !useDefaults ) {
|
||||
m_btRowID = GameUtils.makeNewBTGame( NewGameActivity.this,
|
||||
m_newRowID = GameUtils.makeNewBTGame( NewGameActivity.this,
|
||||
gameID, null, m_lang,
|
||||
2, 1 ); // initial defaults
|
||||
Intent intent = new Intent( this, GameConfig.class );
|
||||
intent.setAction( Intent.ACTION_EDIT );
|
||||
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_btRowID );
|
||||
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_newRowID );
|
||||
intent.putExtra( GameUtils.INTENT_FORRESULT_ROWID, true );
|
||||
startActivityForResult( intent, CONFIG_FOR_BT );
|
||||
} else {
|
||||
|
@ -323,6 +348,23 @@ public class NewGameActivity extends XWActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private void makeNewNBSGame( boolean useDefaults )
|
||||
{
|
||||
int gameID = GameUtils.newGameID();
|
||||
if ( !useDefaults ) {
|
||||
m_newRowID = GameUtils.makeNewNBSGame( NewGameActivity.this,
|
||||
gameID, null, m_lang,
|
||||
2, 1 ); // initial defaults
|
||||
Intent intent = new Intent( this, GameConfig.class );
|
||||
intent.setAction( Intent.ACTION_EDIT );
|
||||
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_newRowID );
|
||||
intent.putExtra( GameUtils.INTENT_FORRESULT_ROWID, true );
|
||||
startActivityForResult( intent, CONFIG_FOR_NBS );
|
||||
} else {
|
||||
GameUtils.launchNBSInviter( this, 1, INVITE_FOR_NBS );
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEnableBT( boolean force )
|
||||
{
|
||||
if ( XWApp.BTSUPPORTED ) {
|
||||
|
@ -369,4 +411,43 @@ public class NewGameActivity extends XWActivity {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEnableNBS()
|
||||
{
|
||||
if ( XWApp.NBSSUPPORTED ) {
|
||||
boolean enabled = true; // is the phone on
|
||||
findViewById( R.id.nbs_separator ).setVisibility( View.VISIBLE );
|
||||
|
||||
findViewById( R.id.nbs_disabled ).
|
||||
setVisibility( enabled ? View.GONE : View.VISIBLE );
|
||||
findViewById( R.id.nbs_stuff ).
|
||||
setVisibility( enabled ? View.VISIBLE : View.GONE );
|
||||
|
||||
Button button;
|
||||
if ( enabled ) {
|
||||
button = (Button)findViewById( R.id.newgame_invite_nbs );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
makeNewNBSGame( true );
|
||||
}
|
||||
} );
|
||||
button = (Button)findViewById( R.id.newgame_nbs_config );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
makeNewNBSGame( false );
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
button = (Button)findViewById( R.id.newgame_enable_nbs );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
Utils.notImpl( NewGameActivity.this );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,8 +54,8 @@ public class CommsAddrRec {
|
|||
public String bt_btAddr;
|
||||
|
||||
// sms case
|
||||
// public String sms_phone;
|
||||
// public int sms_port; // NBS port, if they still use those
|
||||
public String sms_phone;
|
||||
public int sms_port; // NBS port, if they still use those
|
||||
|
||||
public CommsAddrRec( Context context, CommsConnType cTyp )
|
||||
{
|
||||
|
@ -80,6 +80,13 @@ public class CommsAddrRec {
|
|||
bt_btAddr = btAddr;
|
||||
}
|
||||
|
||||
public CommsAddrRec( Context context, String phone, int port )
|
||||
{
|
||||
this( context, CommsConnType.COMMS_CONN_SMS );
|
||||
sms_phone = phone;
|
||||
sms_port = port;
|
||||
}
|
||||
|
||||
public CommsAddrRec( final CommsAddrRec src )
|
||||
{
|
||||
this.copyFrom( src );
|
||||
|
@ -115,5 +122,8 @@ public class CommsAddrRec {
|
|||
|
||||
bt_hostName = src.bt_hostName;
|
||||
bt_btAddr = src.bt_btAddr;
|
||||
|
||||
sms_phone = src.sms_phone;
|
||||
sms_port = src.sms_port;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue