mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
add new activity for starting a new game. Has four buttons and
(eventually) explanatory text. Currently more-or-less works, including sending an email with a link that when clicked launches Crosswords. (Still need to respond to that link on receipt, but I'm at least pulling out the necessary fields.)
This commit is contained in:
parent
77bf5e2d36
commit
249402758a
7 changed files with 258 additions and 40 deletions
|
@ -69,6 +69,10 @@
|
||||||
android:label="@string/title_dicts_list"
|
android:label="@string/title_dicts_list"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<activity android:name="NewGameActivity"
|
||||||
|
android:label="@string/title_newgame"
|
||||||
|
/>
|
||||||
|
|
||||||
<activity android:name="GameConfig"
|
<activity android:name="GameConfig"
|
||||||
android:screenOrientation="sensor"
|
android:screenOrientation="sensor"
|
||||||
android:configChanges="keyboardHidden|orientation"
|
android:configChanges="keyboardHidden|orientation"
|
||||||
|
|
|
@ -42,11 +42,11 @@
|
||||||
android:text="@string/button_new_game"
|
android:text="@string/button_new_game"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button android:id="@+id/new_game_net"
|
<!-- <Button android:id="@+id/new_game_net" -->
|
||||||
android:layout_width="fill_parent"
|
<!-- android:layout_width="fill_parent" -->
|
||||||
android:layout_height="wrap_content"
|
<!-- android:layout_height="wrap_content" -->
|
||||||
android:layout_gravity="right"
|
<!-- android:layout_gravity="right" -->
|
||||||
android:text="@string/button_new_game_net"
|
<!-- android:text="@string/button_new_game_net" -->
|
||||||
/>
|
<!-- /> -->
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
60
xwords4/android/XWords4/res/layout/new_game.xml
Normal file
60
xwords4/android/XWords4/res/layout/new_game.xml
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2007 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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:text="explanatory text"
|
||||||
|
style="@style/relay_explain"
|
||||||
|
/>
|
||||||
|
<Button android:id="@+id/new_game_local"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_game_local"
|
||||||
|
/>
|
||||||
|
<TextView android:text="explanatory text"
|
||||||
|
style="@style/relay_explain"
|
||||||
|
/>
|
||||||
|
<Button android:id="@+id/new_game_local_config"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_game_local_config"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView android:text="explanatory text"
|
||||||
|
style="@style/relay_explain"
|
||||||
|
/>
|
||||||
|
<Button android:id="@+id/new_game_invite"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_game_invite"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView android:text="explanatory text"
|
||||||
|
style="@style/relay_explain"
|
||||||
|
/>
|
||||||
|
<Button android:id="@+id/new_game_net_config"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_game_net_config"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
<!-- <item android:id="@+id/gamel_menu_view_hidden" -->
|
<!-- <item android:id="@+id/gamel_menu_view_hidden" -->
|
||||||
<!-- android:title="@string/gamel_menu_view_hidden" -->
|
<!-- android:title="@string/gamel_menu_view_hidden" -->
|
||||||
<!-- /> -->
|
<!-- /> -->
|
||||||
|
<item android:id="@+id/gamel_menu_newgame"
|
||||||
|
android:title="@string/button_new_game"
|
||||||
|
/>
|
||||||
<item android:id="@+id/gamel_menu_prefs"
|
<item android:id="@+id/gamel_menu_prefs"
|
||||||
android:title="@string/menu_prefs"
|
android:title="@string/menu_prefs"
|
||||||
android:icon="@android:drawable/ic_menu_preferences"
|
android:icon="@android:drawable/ic_menu_preferences"
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<string name="menu_delete">Delete</string>
|
<string name="menu_delete">Delete</string>
|
||||||
<string name="button_new_game">Add single-device game</string>
|
<string name="button_new_game">Add game</string>
|
||||||
<string name="button_new_game_net">Add multi-device game</string>
|
<!-- <string name="button_new_game_net">Add multi-device game</string> -->
|
||||||
|
|
||||||
<string name="list_item_play">Play game</string>
|
<string name="list_item_play">Play game</string>
|
||||||
<string name="list_item_config">Game settings...</string>
|
<string name="list_item_config">Game settings...</string>
|
||||||
|
@ -41,6 +41,7 @@
|
||||||
<string name="title_edit">Edit game</string>
|
<string name="title_edit">Edit game</string>
|
||||||
<string name="title_games_list">Crosswords</string>
|
<string name="title_games_list">Crosswords</string>
|
||||||
<string name="title_dicts_list">Dictionaries (wordcount)</string>
|
<string name="title_dicts_list">Dictionaries (wordcount)</string>
|
||||||
|
<string name="title_newgame">New game</string>
|
||||||
<string name="title_langs_list">Languages (based on installed
|
<string name="title_langs_list">Languages (based on installed
|
||||||
dictionaries)</string>
|
dictionaries)</string>
|
||||||
<string name="lang_label">Game language</string>
|
<string name="lang_label">Game language</string>
|
||||||
|
@ -51,6 +52,11 @@
|
||||||
|
|
||||||
<string name="app_name">Crosswords</string>
|
<string name="app_name">Crosswords</string>
|
||||||
|
|
||||||
|
<string name="new_game_local">Play new local game</string>
|
||||||
|
<string name="new_game_local_config">Configure new local game</string>
|
||||||
|
<string name="new_game_invite">Invite to new networked game</string>
|
||||||
|
<string name="new_game_net_config">Configure new networked game</string>
|
||||||
|
|
||||||
<string name="button_ok">OK</string>
|
<string name="button_ok">OK</string>
|
||||||
<string name="button_cancel">Cancel</string>
|
<string name="button_cancel">Cancel</string>
|
||||||
<string name="button_yes">Yes</string>
|
<string name="button_yes">Yes</string>
|
||||||
|
|
|
@ -186,27 +186,31 @@ public class GamesList extends XWListActivity
|
||||||
newGameB.setOnClickListener( new View.OnClickListener() {
|
newGameB.setOnClickListener( new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick( View v ) {
|
public void onClick( View v ) {
|
||||||
addGame( false );
|
// addGame( false );
|
||||||
showNotAgainDlg( R.string.not_again_newgame,
|
startActivity( new Intent( GamesList.this,
|
||||||
R.string.key_notagain_newgame );
|
NewGameActivity.class ) );
|
||||||
}
|
// showNotAgainDlg( R.string.not_again_newgame,
|
||||||
});
|
// R.string.key_notagain_newgame );
|
||||||
newGameB = (Button)findViewById(R.id.new_game_net);
|
|
||||||
newGameB.setOnClickListener( new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick( View v ) {
|
|
||||||
String path = addGame( true );
|
|
||||||
GameUtils.doConfig( GamesList.this, path,
|
|
||||||
RelayGameActivity.class );
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// newGameB = (Button)findViewById(R.id.new_game_net);
|
||||||
|
// newGameB.setOnClickListener( new View.OnClickListener() {
|
||||||
|
// @Override
|
||||||
|
// public void onClick( View v ) {
|
||||||
|
// String path = addGame( true );
|
||||||
|
// GameUtils.doConfig( GamesList.this, path,
|
||||||
|
// RelayGameActivity.class );
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
m_adapter = new GameListAdapter( this, this );
|
m_adapter = new GameListAdapter( this, this );
|
||||||
setListAdapter( m_adapter );
|
setListAdapter( m_adapter );
|
||||||
|
|
||||||
NetUtils.informOfDeaths( this );
|
NetUtils.informOfDeaths( this );
|
||||||
|
|
||||||
startFirstHasDict( getIntent() );
|
Intent intent = getIntent();
|
||||||
|
startFirstHasDict( intent );
|
||||||
|
startNewGameIf( intent );
|
||||||
|
|
||||||
DBUtils.setDBChangeListener( this );
|
DBUtils.setDBChangeListener( this );
|
||||||
} // onCreate
|
} // onCreate
|
||||||
|
@ -494,25 +498,6 @@ public class GamesList extends XWListActivity
|
||||||
return hasDicts;
|
return hasDicts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String saveNew( CurGameInfo gi )
|
|
||||||
{
|
|
||||||
String path = null;
|
|
||||||
byte[] bytes = XwJNI.gi_to_stream( gi );
|
|
||||||
if ( null != bytes ) {
|
|
||||||
GameUtils.GameLock lock = GameUtils.saveGame( this, bytes );
|
|
||||||
path = lock.getPath();
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String addGame( boolean networked )
|
|
||||||
{
|
|
||||||
String path = saveNew( new CurGameInfo( this, networked ) );
|
|
||||||
GameUtils.resetGame( this, path );
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void invalRelayIDs( String[] relayIDs )
|
private void invalRelayIDs( String[] relayIDs )
|
||||||
{
|
{
|
||||||
if ( null == relayIDs ) {
|
if ( null == relayIDs ) {
|
||||||
|
@ -550,4 +535,17 @@ public class GamesList extends XWListActivity
|
||||||
startFirstHasDict( relayIDs );
|
startFirstHasDict( relayIDs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startNewGameIf( Intent intent )
|
||||||
|
{
|
||||||
|
if ( null != intent ) {
|
||||||
|
Uri data = intent.getData();
|
||||||
|
if ( null != data ) {
|
||||||
|
String room = data.getQueryParameter( "room" );
|
||||||
|
String langStr = data.getQueryParameter( "lang" );
|
||||||
|
int lang = Integer.decode( langStr );
|
||||||
|
Utils.logf( "got data: lang: %d; room: %s", lang, room );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,147 @@
|
||||||
|
/* -*- compile-command: "cd ../../../../../; ant 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.eehouse.android.xw4;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
public class NewGameActivity extends XWActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate( savedInstanceState );
|
||||||
|
|
||||||
|
setContentView( R.layout.new_game );
|
||||||
|
|
||||||
|
Button button = (Button)findViewById( R.id.new_game_local );
|
||||||
|
button.setOnClickListener( new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View v ) {
|
||||||
|
newAndLaunch();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
button = (Button)findViewById( R.id.new_game_local_config );
|
||||||
|
button.setOnClickListener( new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View v ) {
|
||||||
|
newAndConfigure( false );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
button = (Button)findViewById( R.id.new_game_invite );
|
||||||
|
button.setOnClickListener( new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View v ) {
|
||||||
|
newNetworkedAndLaunch();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
button = (Button)findViewById( R.id.new_game_net_config );
|
||||||
|
button.setOnClickListener( new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick( View v ) {
|
||||||
|
newAndConfigure( true );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String saveNew( CurGameInfo gi )
|
||||||
|
{
|
||||||
|
String path = null;
|
||||||
|
byte[] bytes = XwJNI.gi_to_stream( gi );
|
||||||
|
if ( null != bytes ) {
|
||||||
|
GameUtils.GameLock lock = GameUtils.saveGame( this, bytes );
|
||||||
|
path = lock.getPath();
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void newAndLaunch()
|
||||||
|
{
|
||||||
|
String path = saveNew( new CurGameInfo( this ) );
|
||||||
|
GameUtils.launchGame( this, path );
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
// So: Query the user for the desired room name and player name,
|
||||||
|
// providing defaults.
|
||||||
|
private void newNetworkedAndLaunch()
|
||||||
|
{
|
||||||
|
CommsAddrRec addr = new CommsAddrRec( this );
|
||||||
|
Random random = new Random();
|
||||||
|
addr.ip_relay_invite = String.format( "%X", random.nextInt() );
|
||||||
|
Utils.logf( "room: %s", addr.ip_relay_invite );
|
||||||
|
|
||||||
|
CurGameInfo gi = new CurGameInfo( this, true );
|
||||||
|
String path = saveNew( gi );
|
||||||
|
|
||||||
|
GameUtils.GameLock lock =
|
||||||
|
new GameUtils.GameLock( path, true ).lock();
|
||||||
|
GameUtils.applyChanges( this, gi, addr, lock, false );
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
Intent intent = new Intent( Intent.ACTION_SEND );
|
||||||
|
intent.setType( "plain/text" );
|
||||||
|
intent.putExtra( Intent.EXTRA_SUBJECT, "Let's play Crosswords" );
|
||||||
|
intent.putExtra( Intent.EXTRA_TEXT,
|
||||||
|
mkMsgWithLink( addr.ip_relay_invite, gi.dictLang ) );
|
||||||
|
|
||||||
|
GameUtils.launchGame( this, path );
|
||||||
|
|
||||||
|
startActivity( Intent.createChooser( intent,
|
||||||
|
"Send your invitation via" ) );
|
||||||
|
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mkMsgWithLink( String room, int lang )
|
||||||
|
{
|
||||||
|
String host = CommonPrefs.getDefaultRelayHost( this );
|
||||||
|
String format = "Click on this link to start a game: " +
|
||||||
|
"http://%s/redir.php?room=%s&lang=%d";
|
||||||
|
return String.format( format, host, room, lang );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void newAndConfigure( boolean networked )
|
||||||
|
{
|
||||||
|
String path = saveNew( new CurGameInfo( this, networked ) );
|
||||||
|
GameUtils.doConfig( this, path, GameConfig.class );
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue