remove dead classes and layouts; add menu to create networked games.

This commit is contained in:
Eric House 2014-11-15 20:42:09 -08:00
parent 64276b041e
commit 11f7083eb6
15 changed files with 496 additions and 1458 deletions

View file

@ -92,9 +92,6 @@
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity android:name="NewGameActivity"
android:theme="@android:style/Theme.NoTitleBar"
/>
<activity android:name="BTInviteActivity"
android:label="@string/bt_invite_title"
android:theme="@android:style/Theme.Dialog"
@ -192,9 +189,6 @@
</intent-filter>
</activity>
<activity android:name="RelayGameActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity android:name="DictBrowseActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
/>

File diff suppressed because it is too large Load diff

View file

@ -1,93 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- local game -->
<include layout="@layout/expander_header"
android:id="@+id/newgame_local_header"
/>
<LinearLayout android:orientation="vertical"
android:id="@+id/newgame_local_hideable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<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="@drawable/sologame"
style="@style/newgame_connicon"
/>
<TextView android:id="@+id/newgame_local_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_local"
android:text="@string/newgame_local"
style="@style/evenly_spaced_horizontal"
/>
<Button android:id="@+id/newgame_local_config"
android:text="@string/newgame_configure_first"
style="@style/evenly_spaced_horizontal"
/>
</LinearLayout>
</LinearLayout>
<!-- networked game -->
<include layout="@layout/expander_header"
android:id="@+id/newgame_relay_header"
/>
<!-- Wrapper so can show/hide -->
<LinearLayout android:orientation="vertical"
android:id="@+id/newgame_networked_hideable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<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="@drawable/relaygame"
style="@style/newgame_connicon"
/>
<TextView android:text="@string/newgame_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_net_invite"
android:text="@string/newgame_invite"
style="@style/evenly_spaced_horizontal"
/>
<Button android:id="@+id/newgame_net_config"
android:text="@string/newgame_configure_first"
style="@style/evenly_spaced_horizontal"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -1,69 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- only one direct child possible -->
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="@+id/explain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView android:text="@string/explain_b1"
style="@style/relay_explain"
/>
<TextView android:text="@string/explain_b2"
style="@style/relay_explain"
/>
<TextView android:text="@string/explain_b3"
style="@style/relay_explain"
/>
<TextView android:text="@string/explain_b4"
style="@style/relay_explain"
/>
<EditText android:id="@+id/room_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollHorizontally="false"
android:autoText="false"
android:capitalize="none"
android:singleLine="true"
android:selectAllOnFocus="true"
android:maxLength="31"
android:hint="@string/new_room_hint"
/>
<EditText android:id="@+id/local_name_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollHorizontally="false"
android:autoText="false"
android:capitalize="none"
android:singleLine="true"
android:selectAllOnFocus="true"
android:hint="@string/local_name_hint"
/>
<Button android:id="@+id/play_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/play"
/>
<Button android:id="@+id/config_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/advanced_config"
/>
</LinearLayout>
</ScrollView>

View file

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/games_menu_newgame"
android:title="@string/button_new_game"
<item android:id="@+id/games_menu_newgame_solo"
android:title="@string/new_game"
android:icon="@drawable/content_new__gen"
android:showAsAction="ifRoom"
/>
<item android:id="@+id/games_menu_newgame_net"
android:title="@string/new_game_networked"
android:icon="@drawable/content_new__gen"
android:showAsAction="ifRoom"
/>

View file

@ -1235,40 +1235,6 @@
transmitted. -->
<string name="chat_menu_clear">Clear history</string>
<!-- ############################################################
# :Screens:
# RelayGameActivity screen
#
# This screen is a simple alternative to the Game Configure
# screen. You'll get it when you choose the list_item_config
# on certain unconfigured simple relay games (currently simple
# means they have 2 players. These days about the only way to
# get this screen is to create a relay game manually and to
# abort after making the room name empty. That is, this is
# left over from an older way of helping people connect, from
# before invitations.
# The dialog has a list of instructions, two text fields for
# room name and local player name, and two buttons.
############################################################
-->
<!-- This is the heading above the list of steps. The default
language is substituted for %1$s. -->
<string name="relay_game_explain_fmt">To start a basic networked two-player
game in %1$s:</string>
<!-- These four strings are displayed as step-by-step
instructions-->
<string name="explain_b1">• Agree on a room name with the other
player.</string>
<string name="explain_b2">• Enter the room name in the first box
below. The room names on your two phones must be
identical.</string>
<string name="explain_b3">• Optionally, enter player names in the
second box (one per phone)</string>
<string name="explain_b4">• Press the \"Play game\" button on both
phones to start the game.</string>
<!-- This is the "hint" printed in light text in the empty player
name field -->

View file

@ -1058,38 +1058,6 @@
other devices in the game: no "clear chat" message is
transmitted. -->
<string name="chat_menu_clear">Raelc yrotsih</string>
<!-- ############################################################
# :Screens:
# RelayGameActivity screen
#
# This screen is a simple alternative to the Game Configure
# screen. You'll get it when you choose the list_item_config
# on certain unconfigured simple relay games (currently simple
# means they have 2 players. These days about the only way to
# get this screen is to create a relay game manually and to
# abort after making the room name empty. That is, this is
# left over from an older way of helping people connect, from
# before invitations.
# The dialog has a list of instructions, two text fields for
# room name and local player name, and two buttons.
############################################################
-->
<!-- This is the heading above the list of steps. The default
language is substituted for %1$s. -->
<string name="relay_game_explain_fmt">Ot trats a cisab dekrowten reyalp-owt
emag ni %1$s:</string>
<!-- These four strings are displayed as step-by-step
instructions-->
<string name="explain_b1">• Eerga no a moor eman htiw eht rehto
reyalp.</string>
<string name="explain_b2">• Retne eht moor eman ni eht tsrif xob
woleb. Eht moor seman no ruoy owt senohp tsum eb
lacitnedi.</string>
<string name="explain_b3">• ,yllanoitpo retne reyalp seman ni eht
dnoces xob eno( rep )enohp</string>
<string name="explain_b4">• Sserp eht \"Yalp emag\" nottub no htob
senohp ot trats eht emag.</string>
<!-- This is the "hint" printed in light text in the empty player
name field -->
<string name="local_name_hint">Reyalp eman</string>

View file

@ -1058,38 +1058,6 @@
other devices in the game: no "clear chat" message is
transmitted. -->
<string name="chat_menu_clear">CLEAR HISTORY</string>
<!-- ############################################################
# :Screens:
# RelayGameActivity screen
#
# This screen is a simple alternative to the Game Configure
# screen. You'll get it when you choose the list_item_config
# on certain unconfigured simple relay games (currently simple
# means they have 2 players. These days about the only way to
# get this screen is to create a relay game manually and to
# abort after making the room name empty. That is, this is
# left over from an older way of helping people connect, from
# before invitations.
# The dialog has a list of instructions, two text fields for
# room name and local player name, and two buttons.
############################################################
-->
<!-- This is the heading above the list of steps. The default
language is substituted for %1$s. -->
<string name="relay_game_explain_fmt">TO START A BASIC NETWORKED TWO-PLAYER
GAME IN %1$s:</string>
<!-- These four strings are displayed as step-by-step
instructions-->
<string name="explain_b1">• AGREE ON A ROOM NAME WITH THE OTHER
PLAYER.</string>
<string name="explain_b2">• ENTER THE ROOM NAME IN THE FIRST BOX
BELOW. THE ROOM NAMES ON YOUR TWO PHONES MUST BE
IDENTICAL.</string>
<string name="explain_b3">• OPTIONALLY, ENTER PLAYER NAMES IN THE
SECOND BOX (ONE PER PHONE)</string>
<string name="explain_b4">• PRESS THE \"PLAY GAME\" BUTTON ON BOTH
PHONES TO START THE GAME.</string>
<!-- This is the "hint" printed in light text in the empty player
name field -->
<string name="local_name_hint">PLAYER NAME</string>

View file

@ -463,26 +463,27 @@ public class GameUtils {
nli.gameID, false );
}
public static long makeNewMultiGame( Context context, String room, String inviteID )
public static long makeNewMultiGame( Context context, String inviteID )
{
int[] lang = {0};
String[] dict = {null};
CommsAddrRec addr = new CommsAddrRec( XWPrefs.getAddrTypes( context ) );
addr.populate( context );
return makeNewMultiGame( context, null, DBUtils.GROUPID_UNSPEC, addr,
lang, dict, 2, 1, inviteID, 0, true );
}
private static long makeNewMultiGame( Context context, long groupID,
CommsAddrRec addr,
int[] lang, String[] dict,
int nPlayersT, int nPlayersH,
String inviteID, int gameID,
boolean isHost )
{
return makeNewMultiGame( context, null, groupID, addr, lang, dict,
nPlayersT, nPlayersH, inviteID, gameID,
isHost );
}
// private static long makeNewMultiGame( Context context, long groupID,
// CommsAddrRec addr,
// int[] lang, String[] dict,
// int nPlayersT, int nPlayersH,
// String inviteID, int gameID,
// boolean isHost )
// {
// return makeNewMultiGame( context, null, groupID, addr, lang, dict,
// nPlayersT, nPlayersH, inviteID, gameID,
// isHost );
// }
private static long makeNewMultiGame( Context context, MultiMsgSink sink, long groupID,
CommsAddrRec addr, int[] lang, String[] dict,
@ -518,54 +519,6 @@ public class GameUtils {
return rowid;
}
public static long makeNewRelayGame( Context context, long groupID,
String room, String inviteID, int[] lang,
String[] dict, int nPlayersT,
int nPlayersH )
{
long rowid = -1;
CommsAddrRec addr = new CommsAddrRec();
for ( CommsConnType typ : XWPrefs.getAddrTypes( context ).getTypes() ) {
addr.conTypes.add( typ );
switch( typ ) {
case COMMS_CONN_RELAY:
String name = XWPrefs.getDefaultRelayHost( context );
int port = XWPrefs.getDefaultRelayPort( context );
addr.setRelayParams( name, port, room );
break;
case COMMS_CONN_BT:
// String[] strs = BTService.getBTNameAndAddress();
// addr.bt_hostName = strs[0];
// addr.bt_btAddr = strs[1];
break;
default:
// Assert.fail();
break;
}
}
return makeNewMultiGame( context, groupID, addr, lang, dict,
nPlayersT, nPlayersH, inviteID, 0, true );
}
public static long makeNewRelayGame( Context context, long groupID,
String room, String inviteID, int lang,
String dict, int nPlayers )
{
int[] langarr = { lang };
String[] dictArr = { dict };
return makeNewRelayGame( context, groupID, room, inviteID, langarr,
dictArr, nPlayers, 1 );
}
public static long makeNewRelayGame( Context context, NetLaunchInfo info )
{
return makeNewRelayGame( context, DBUtils.GROUPID_UNSPEC, info.room,
info.inviteID, info.lang, info.dict,
info.nPlayersT );
}
public static long makeNewGame( Context context, MultiMsgSink sink,
int gameID, CommsAddrRec addr, int lang,
String dict, int nPlayersT,
@ -592,18 +545,9 @@ public class GameUtils {
lang, dict, nPlayersT, nPlayersH );
}
// public static long makeNewBTGame( Context context, NetLaunchInfo nli )
// {
// Assert.fail();
// return -1;
// // return makeNewBTGame( context, null, DBUtils.GROUPID_UNSPEC, nli.gameID,
// // nli.btAddress, nli.lang, nli.dict,
// // nli.nPlayersT, 1 );
// }
public static long makeNewGame( Context context, MultiMsgSink sink,
long groupID, int gameID, CommsAddrRec addr,
int lang, String dict,
int lang, String dict,
int nPlayersT, int nPlayersH )
{
long rowid = -1;
@ -619,33 +563,6 @@ public class GameUtils {
isHost );
}
// public static long makeNewSMSGame( Context context, int gameID,
// CommsAddrRec addr,
// int lang, String dict, int nPlayersT,
// int nPlayersH )
// {
// return makeNewSMSGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
// lang, dict, nPlayersT, nPlayersH );
// }
// public static long makeNewSMSGame( Context context, long groupID,
// int gameID, CommsAddrRec addr,
// int lang, String dict, int nPlayersT,
// int nPlayersH )
// {
// long rowid = -1;
// int[] langa = { lang };
// String[] dicta = { dict };
// boolean isHost = null == addr;
// if ( isHost ) {
// addr = new CommsAddrRec( CommsConnType.COMMS_CONN_SMS );
// }
// String inviteID = GameUtils.formatGameID( gameID );
// return makeNewMultiGame( context, groupID, addr, langa, dicta,
// nPlayersT, nPlayersH, inviteID, gameID,
// isHost );
// }
public static void launchEmailInviteActivity( Activity activity, NetLaunchInfo nli )
{
DbgUtils.logf( "launchEmailInviteActivity: nli=%s", nli.makeLaunchJSON() );

View file

@ -69,6 +69,7 @@ public class GamesListDelegate extends ListDelegateBase
private static final String SAVE_ROWIDS = "SAVE_ROWIDS";
private static final String SAVE_GROUPID = "SAVE_GROUPID";
private static final String SAVE_DICTNAMES = "SAVE_DICTNAMES";
private static final String SAVE_NEXTSOLO = "SAVE_NEXTSOLO";
private static final int REQUEST_LANG = 1;
private static final int CONFIG_GAME = 2;
@ -919,6 +920,7 @@ public class GamesListDelegate extends ListDelegateBase
outState.putLongArray( SAVE_ROWIDS, m_rowids );
outState.putLong( SAVE_GROUPID, m_groupid );
outState.putString( SAVE_DICTNAMES, m_missingDictName );
outState.putBoolean( SAVE_NEXTSOLO, m_nextIsSolo );
if ( null != m_netLaunchInfo ) {
m_netLaunchInfo.putSelf( outState );
}
@ -932,6 +934,7 @@ public class GamesListDelegate extends ListDelegateBase
m_groupid = bundle.getLong( SAVE_GROUPID );
m_netLaunchInfo = new NetLaunchInfo( bundle );
m_missingDictName = bundle.getString( SAVE_DICTNAMES );
m_nextIsSolo = bundle.getBoolean( SAVE_NEXTSOLO );
}
}
@ -1226,7 +1229,9 @@ public class GamesListDelegate extends ListDelegateBase
&& (selGroupPos + 1) < groupCount );
// New game available when nothing selected or one group
Utils.setItemVisible( menu, R.id.games_menu_newgame,
Utils.setItemVisible( menu, R.id.games_menu_newgame_solo,
nothingSelected || 1 == nGroupsSelected );
Utils.setItemVisible( menu, R.id.games_menu_newgame_net,
nothingSelected || 1 == nGroupsSelected );
// Multiples can be deleted
@ -1285,8 +1290,13 @@ public class GamesListDelegate extends ListDelegateBase
case R.id.games_menu_resend:
GameUtils.resendAllIf( m_activity, null, true );
break;
case R.id.games_menu_newgame:
startNewGameActivity( groupID );
case R.id.games_menu_newgame_solo:
m_nextIsSolo = true;
showDialog( DlgID.GAMES_LIST_NEWGAME );
break;
case R.id.games_menu_newgame_net:
m_nextIsSolo = false;
showDialog( DlgID.GAMES_LIST_NEWGAME );
break;
case R.id.games_menu_newgroup:
@ -1640,11 +1650,6 @@ public class GamesListDelegate extends ListDelegateBase
}
}
private void startNewGameActivity( long groupID )
{
NewGameDelegate.startActivity( m_activity, groupID );
}
private void startNewNetGame( NetLaunchInfo nli )
{
Assert.assertTrue( nli.isValid() );
@ -1907,17 +1912,18 @@ public class GamesListDelegate extends ListDelegateBase
if ( summary.conTypes.contains( CommsAddrRec.CommsConnType.COMMS_CONN_RELAY )
&& summary.roomName.length() == 0 ) {
Assert.fail();
// If it's unconfigured and of the type RelayGameActivity
// can handle send it there, otherwise use the full-on
// config.
Class clazz;
// Class clazz;
if ( RelayGameDelegate.isSimpleGame( summary ) ) {
clazz = RelayGameActivity.class;
} else {
clazz = GameConfigActivity.class;
}
GameUtils.doConfig( m_activity, rowid, clazz );
// if ( RelayGameDelegate.isSimpleGame( summary ) ) {
// clazz = RelayGameActivity.class;
// } else {
// clazz = GameConfigActivity.class;
// }
// GameUtils.doConfig( m_activity, rowid, clazz );
} else {
if ( checkWarnNoDict( rowid ) ) {
launchGame( rowid );
@ -1997,9 +2003,8 @@ public class GamesListDelegate extends ListDelegateBase
new CurGameInfo( m_activity ),
groupID );
} else {
String room = GameUtils.makeRandomID();
String inviteID = GameUtils.makeRandomID();
rowID = GameUtils.makeNewMultiGame( m_activity, room, inviteID );
rowID = GameUtils.makeNewMultiGame( m_activity, inviteID );
}
if ( doConfigure ) {

View file

@ -1,37 +0,0 @@
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
/*
* Copyright 2009 - 2013 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;
public class NewGameActivity extends XWActivity {
private NewGameDelegate m_dlgt;
@Override
protected void onCreate( Bundle savedInstanceState )
{
m_dlgt = new NewGameDelegate( this, savedInstanceState );
super.onCreate( savedInstanceState, m_dlgt );
}
}

View file

@ -1,391 +0,0 @@
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
/*
* Copyright 2009 - 2013 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.app.AlertDialog;
import android.app.Dialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.Random;
import junit.framework.Assert;
import org.eehouse.android.xw4.jni.CurGameInfo;
import org.eehouse.android.xw4.jni.CommonPrefs;
import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans;
import org.eehouse.android.xw4.DlgDelegate.Action;
public class NewGameDelegate extends DelegateBase {
// private static final String SAVE_DEVNAMES = "DEVNAMES";
private static final String SAVE_REMOTEGAME = "REMOTEGAME";
private static final String SAVE_GAMEID = "GAMEID";
private static final String SAVE_NAMEFOR = "SAVE_NAMEFOR";
private static final String GROUPID_EXTRA = "groupid";
private static final int CONFIG_FOR_BT = 1;
private static final int CONFIG_FOR_SMS = 2;
private static final int CONFIG_FOR_NET = 3;
private static final int INVITE_FOR_BT = 4;
private static final int INVITE_FOR_SMS = 5;
private boolean m_showsOn;
private boolean m_nameForBT;
private boolean m_firingPrefs = false;
private int m_chosen;
private int m_lang = 0;
private String m_dict = null;
private long m_newRowID = -1;
private String m_gameName;
private int m_gameID;
private long m_groupID;
private String m_remoteDev;
private Activity m_activity;
private int m_hidden;
protected NewGameDelegate( Delegator delegator, Bundle savedInstanceState )
{
super( delegator, savedInstanceState, R.layout.new_game );
m_activity = delegator.getActivity();
}
protected void init( Bundle savedInstanceState )
{
getBundledData( savedInstanceState );
m_groupID = getIntent().getLongExtra( GROUPID_EXTRA, -1 );
setupShowHide();
TextView desc = (TextView)findViewById( R.id.newgame_local_desc );
m_dict = CommonPrefs.getDefaultHumanDict( m_activity );
String lang = DictLangCache.getLangName( m_activity, m_dict );
m_lang = DictLangCache.getLangLangCode( m_activity, lang );
desc.setText( getString( R.string.newgame_local_desc_fmt, lang ) );
Button button = (Button)findViewById( R.id.newgame_local );
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View v ) {
makeNewGame( false, true );
}
} );
button = (Button)findViewById( R.id.newgame_local_config );
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View v ) {
makeNewGame( false, false );
}
} );
button = (Button)findViewById( R.id.newgame_net_invite );
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View v ) {
makeNewGame( true, true );
}
} );
button = (Button)findViewById( R.id.newgame_net_config );
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View v ) {
makeNewGame( true, false );
}
} );
}
protected void onSaveInstanceState( Bundle outState )
{
outState.putString( SAVE_REMOTEGAME, m_remoteDev );
outState.putInt( SAVE_GAMEID, m_gameID );
outState.putBoolean( SAVE_NAMEFOR, m_nameForBT );
}
private void getBundledData( Bundle bundle )
{
if ( null != bundle ) {
m_remoteDev = bundle.getString( SAVE_REMOTEGAME );
m_gameID = bundle.getInt( SAVE_GAMEID );
m_nameForBT = bundle.getBoolean( SAVE_NAMEFOR );
}
}
// DlgDelegate.DlgClickNotify interface
@Override
public void inviteChoiceMade( Action action, InviteMeans means,
Object[] params )
{
switch( action ) {
case NEW_GAME_ACTION:
makeNewGame( true, true, means );
break;
default:
Assert.fail();
}
}
@Override
protected void onPause() {
super.onPause();
saveShowHide();
}
protected void onActivityResult( int requestCode, int resultCode,
Intent data )
{
if ( Activity.RESULT_CANCELED == resultCode ) {
if ( 0 < m_newRowID ) {
DBUtils.deleteGame( m_activity, m_newRowID );
m_newRowID = -1;
}
} else {
switch ( requestCode ) {
case CONFIG_FOR_BT:
case CONFIG_FOR_SMS:
case CONFIG_FOR_NET:
// We'll leave it up to BoardActivity to detect that
// it's not had any remote connections yet.
GameUtils.launchGame( m_activity, m_newRowID );
finish();
break;
case INVITE_FOR_BT: // user selected device
case INVITE_FOR_SMS:
m_nameForBT = INVITE_FOR_BT == requestCode;
String[] remoteDevs =
data.getStringArrayExtra( InviteDelegate.DEVS );
Assert.assertTrue( 1 == remoteDevs.length );
m_remoteDev = remoteDevs[0];
m_gameID = GameUtils.newGameID();
m_gameName = getString( R.string.dft_name_fmt,
m_gameID & 0xFFFF );
showDialog( DlgID.NAME_GAME );
break;
}
}
}
protected Dialog onCreateDialog( int id )
{
Dialog dialog = null;
DlgID dlgID = DlgID.values()[id];
switch( dlgID ) {
case NAME_GAME:
final GameNamer namerView = (GameNamer)inflate( R.layout.rename_game );
namerView.setLabel( m_nameForBT ? R.string.btname_label
: R.string.smsname_label );
namerView.setName( m_gameName );
OnClickListener lstnr =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int itm ) {
m_gameName = namerView.getName();
long rowid;
CommsAddrRec addr = null;
rowid = GameUtils
.makeNewGame( m_activity, m_groupID, m_gameID,
addr, m_lang, m_dict, 2, 1 );
Assert.fail();
if ( m_nameForBT ) {
// BTService.inviteRemote( m_activity, m_remoteDev,
// m_gameID, m_gameName,
// m_lang, m_dict, 2, 1 );
} else {
// SMSService.inviteRemote( m_activity, m_remoteDev,
// m_gameID, m_gameName,
// m_lang, m_dict, 2, 1 );
}
DBUtils.setName( m_activity, rowid, m_gameName );
GameUtils.launchGame( m_activity, rowid, true );
finish();
}
};
dialog = makeAlertBuilder()
.setTitle( m_nameForBT ? R.string.game_btname_title
: R.string.game_smsname_title )
.setNegativeButton( R.string.button_cancel, null )
.setPositiveButton( R.string.button_ok, lstnr )
.setView( namerView )
.create();
setRemoveOnDismiss( dialog, dlgID );
break;
case ENABLE_NFC:
dialog = NFCUtils.makeEnableNFCDialog( m_activity );
break;
default:
dialog = super.onCreateDialog( id );
break;
}
return dialog;
}
private void makeNewGame( boolean networked, boolean launch )
{
if ( launch && networked ) {
// Let 'em cancel before we make the game
showInviteChoicesThen( DlgDelegate.Action.NEW_GAME_ACTION );
} else {
makeNewGame( networked, launch, InviteMeans.SMS );
}
}
private void makeNewGame( boolean networked, boolean launch,
InviteMeans inviteHow )
{
boolean viaNFC = InviteMeans.NFC == inviteHow;
if ( viaNFC && !NFCUtils.nfcAvail( m_activity )[1] ) {
showDialog( DlgID.ENABLE_NFC );
} else {
String room = null;
String inviteID = null;
int[] lang = {0};
String[] dict = {null};
final int nPlayers = 2; // hard-coded for no-configure case
if ( networked ) {
room = GameUtils.makeRandomID();
inviteID = GameUtils.makeRandomID();
m_newRowID = GameUtils.makeNewRelayGame( m_activity, m_groupID,
room, inviteID, lang,
dict, nPlayers, 1 );
} else {
m_newRowID = GameUtils.saveNew( m_activity,
new CurGameInfo( m_activity ),
m_groupID );
}
if ( launch ) {
GameUtils.launchGame( m_activity, m_newRowID, networked );
if ( networked ) {
Assert.fail();
// GameUtils.launchInviteActivity( m_activity, inviteHow, room,
// inviteID, lang[0], dict[0],
// nPlayers );
}
finish();
} else {
GameConfigDelegate.editForResult( m_activity, CONFIG_FOR_NET, m_newRowID );
}
}
}
// private void makeNewBTGame( boolean useDefaults )
// {
// if ( XWApp.BTSUPPORTED ) {
// int gameID = GameUtils.newGameID();
// if ( !useDefaults ) {
// m_newRowID = GameUtils.makeNewBTGame( m_activity,
// m_groupID, gameID, null,
// m_lang, m_dict, 2, 1 );
// GameConfigDelegate.editForResult( m_activity, CONFIG_FOR_BT, m_newRowID );
// } else {
// BTInviteDelegate.launchForResult( m_activity, 1, INVITE_FOR_BT );
// }
// }
// }
// private void makeNewSMSGame( boolean useDefaults )
// {
// int gameID = GameUtils.newGameID();
// if ( !useDefaults ) {
// m_newRowID = GameUtils.makeNewSMSGame( m_activity,
// m_groupID, gameID, null,
// m_lang, m_dict, 2, 1 );
// String name = getString( R.string.dft_sms_name_fmt, gameID & 0xFFFF );
// DBUtils.setName( m_activity, m_newRowID, name );
// GameConfigDelegate.editForResult( m_activity, CONFIG_FOR_SMS, m_newRowID );
// } else {
// SMSInviteDelegate.launchForResult( m_activity, 1, INVITE_FOR_SMS );
// }
// }
private static final int HIDE_MASK_LOCAL = 1;
private static final int HIDE_MASK_NET = 2;
private static final String NGD_HIDDEN = "NGD_HIDDEN";
private static final int[][] SHOW_HIDE_PAIRS = {
{ R.id.newgame_local_header,
R.string.newgame_local_header,
R.id.newgame_local_hideable,
HIDE_MASK_LOCAL,
},
{ R.id.newgame_relay_header,
R.string.newgame_networked_header,
R.id.newgame_networked_hideable,
HIDE_MASK_NET,
},
};
private void setupShowHide()
{
m_hidden = DBUtils.getIntFor( m_activity, NGD_HIDDEN, 0 );
for ( int[] pair : SHOW_HIDE_PAIRS ) {
HeaderWithExpander header = (HeaderWithExpander)findViewById( pair[0] );
header.setText( pair[1] );
final View nv = findViewById( pair[2] );
final int mask = pair[3];
header.setOnExpandedListener(new HeaderWithExpander.OnExpandedListener() {
public void expanded( boolean expanded ) {
if ( expanded ) {
nv.setVisibility( View.VISIBLE );
m_hidden &= ~mask;
} else {
nv.setVisibility( View.GONE );
m_hidden |= mask;
}
}
});
header.setExpanded( 0 == (m_hidden & mask) );
}
}
private void saveShowHide()
{
DBUtils.setIntFor( m_activity, NGD_HIDDEN, m_hidden );
}
public static void startActivity( Activity parent, long groupID )
{
Bundle extras = new Bundle();
extras.putLong( GROUPID_EXTRA, groupID );
Intent intent = new Intent( parent, NewGameActivity.class );
intent.putExtras( extras );
parent.startActivity( intent );
}
}

View file

@ -1,39 +0,0 @@
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
/*
* Copyright 2009-2010 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.
*/
// This activity is for newbies. Bring it up when network game
// created. It explains they need only a room name -- that everything
// else is derived from defaults and configurable via the main config
// dialog (which offer to launch)
package org.eehouse.android.xw4;
import android.os.Bundle;
public class RelayGameActivity extends XWActivity {
@Override
public void onCreate( Bundle savedInstanceState )
{
RelayGameDelegate dlgt = new RelayGameDelegate( this, savedInstanceState );
super.onCreate( savedInstanceState, dlgt );
} // onCreate
} // class RelayGameActivity

View file

@ -1,143 +0,0 @@
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
/*
* Copyright 2009-2010 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.
*/
// This activity is for newbies. Bring it up when network game
// created. It explains they need only a room name -- that everything
// else is derived from defaults and configurable via the main config
// dialog (which offer to launch)
package org.eehouse.android.xw4;
import android.app.Activity;
import java.io.File;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
import android.content.Intent;
import junit.framework.Assert;
import org.eehouse.android.xw4.jni.*;
public class RelayGameDelegate extends DelegateBase
implements View.OnClickListener {
private Activity m_activity;
private long m_rowid;
private CurGameInfo m_gi;
private GameLock m_gameLock;
private CommsAddrRec m_car;
private Button m_playButton;
private Button m_configButton;
protected RelayGameDelegate( Delegator delegator, Bundle savedInstanceState )
{
super( delegator, savedInstanceState, R.layout.relay_game_config );
m_activity = delegator.getActivity();
}
protected void init( Bundle savedInstanceState )
{
m_rowid = getIntent().getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 );
m_playButton = (Button)findViewById( R.id.play_button );
m_playButton.setOnClickListener( this );
m_configButton = (Button)findViewById( R.id.config_button );
m_configButton.setOnClickListener( this );
} // onCreate
protected void onStart()
{
m_gi = new CurGameInfo( m_activity );
m_gameLock = new GameLock( m_rowid, true ).lock( 300 );
if ( null == m_gameLock ) {
DbgUtils.logf( "RelayGameActivity.onStart(): unable to lock rowid %d",
m_rowid );
finish();
} else {
int gamePtr = GameUtils.loadMakeGame( m_activity, m_gi, m_gameLock );
m_car = new CommsAddrRec();
if ( XwJNI.game_hasComms( gamePtr ) ) {
XwJNI.comms_getAddr( gamePtr, m_car );
} else {
Assert.fail();
// String relayName = CommonPrefs.getDefaultRelayHost( this );
// int relayPort = CommonPrefs.getDefaultRelayPort( this );
// XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort );
}
XwJNI.game_dispose( gamePtr );
String lang = DictLangCache.getLangName( m_activity, m_gi.dictLang );
TextView text = (TextView)findViewById( R.id.explain );
text.setText( getString( R.string.relay_game_explain_fmt, lang ) );
}
}
protected void onPause()
{
if ( null != m_gameLock ) {
m_gameLock.unlock();
m_gameLock = null;
}
super.onPause();
}
public void onClick( View view )
{
String room = getText( R.id.room_edit ).trim();
if ( view == m_playButton ) {
if ( room.length() == 0 ) {
showOKOnlyDialog( R.string.no_empty_rooms );
} else {
if ( saveRoomAndName( room ) ) {
GameUtils.launchGameAndFinish( m_activity, m_rowid );
}
}
} else if ( view == m_configButton ) {
if ( saveRoomAndName( room ) ) {
GameUtils.doConfig( m_activity, m_rowid, GameConfigActivity.class );
finish();
}
}
}
public static boolean isSimpleGame( GameSummary summary )
{
return summary.nPlayers == 2;
}
private boolean saveRoomAndName( String room )
{
boolean canSave = null != m_gameLock;
if ( canSave ) {
String name = getText( R.id.local_name_edit );
if ( name.length() > 0 ) { // don't wipe existing
m_gi.setFirstLocalName( name );
}
m_car.ip_relay_invite = room;
GameUtils.applyChanges( m_activity, m_gi, m_car, m_gameLock, false );
m_gameLock.unlock();
m_gameLock = null;
}
return canSave;
}
} // class RelayGameActivity

View file

@ -32,6 +32,9 @@ import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.DbgUtils;
import org.eehouse.android.xw4.GameUtils;
import org.eehouse.android.xw4.XWPrefs;
import org.eehouse.android.xw4.BTService;
public class CommsAddrRec {
@ -166,6 +169,31 @@ public class CommsAddrRec {
ip_relay_advertiseRoom = false;
}
public void populate( Context context )
{
for ( CommsConnType typ : conTypes.getTypes() ) {
switch ( typ ) {
case COMMS_CONN_RELAY:
String room = GameUtils.makeRandomID();
String host = XWPrefs.getDefaultRelayHost( context );
int port = XWPrefs.getDefaultRelayPort( context );
setRelayParams( host, port, room );
break;
case COMMS_CONN_BT:
String[] strs = BTService.getBTNameAndAddress();
if ( null != strs ) {
bt_hostName = strs[0];
bt_btAddr = strs[1];
}
break;
case COMMS_CONN_SMS:
// FIXME
default:
Assert.fail();
}
}
}
public boolean changesMatter( final CommsAddrRec other )
{
boolean matter = ! conTypes.equals( other.conTypes );