mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
move dialog asking to enable NFC into NFCUtils, and use it when
creating a new game to be invited via (disabled) NFC
This commit is contained in:
parent
5f7242f01b
commit
2e5e10ef6d
4 changed files with 61 additions and 40 deletions
|
@ -88,7 +88,7 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<Button android:id="@+id/newgame_invite"
|
||||
<Button android:id="@+id/newgame_invite_net"
|
||||
android:text="@string/newgame_invite"
|
||||
style="@style/spaced_buttons"
|
||||
/>
|
||||
|
|
|
@ -515,19 +515,7 @@ public class BoardActivity extends XWActivity
|
|||
break;
|
||||
|
||||
case ENABLE_NFC:
|
||||
lstnr = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int item ) {
|
||||
startActivity( new Intent("android.settings"
|
||||
+ ".NFC_SETTINGS" ) );
|
||||
}
|
||||
};
|
||||
dialog = new AlertDialog.Builder( this )
|
||||
.setTitle( R.string.info_title )
|
||||
.setMessage( R.string.enable_nfc )
|
||||
.setPositiveButton( R.string.button_cancel, null )
|
||||
.setNegativeButton( R.string.button_go_settings, lstnr )
|
||||
.create();
|
||||
dialog = NFCUtils.makeEnableNFCDialog( this );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -21,7 +21,11 @@
|
|||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
|
@ -116,6 +120,25 @@ public class NFCUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static Dialog makeEnableNFCDialog( final Activity activity )
|
||||
{
|
||||
DialogInterface.OnClickListener lstnr
|
||||
= new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
int item ) {
|
||||
activity.
|
||||
startActivity( new Intent("android.settings"
|
||||
+ ".NFC_SETTINGS" ) );
|
||||
}
|
||||
};
|
||||
return new AlertDialog.Builder( activity )
|
||||
.setTitle( R.string.info_title )
|
||||
.setMessage( R.string.enable_nfc )
|
||||
.setPositiveButton( R.string.button_cancel, null )
|
||||
.setNegativeButton( R.string.button_go_settings, lstnr )
|
||||
.create();
|
||||
}
|
||||
|
||||
private static NdefMessage makeMessage( Activity activity, String data )
|
||||
{
|
||||
String mimeType = activity.getString( R.string.xwords_nfc_mime );
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- compile-command: "cd ../../../../../; ant debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
|
||||
* Copyright 2009 - 2013 by Eric House (xwords@eehouse.org). All
|
||||
* rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -59,7 +59,8 @@ public class NewGameActivity extends XWActivity {
|
|||
|
||||
// Dialogs
|
||||
private static final int NAME_GAME = DlgDelegate.DIALOG_LAST + 1;
|
||||
|
||||
private static final int ENABLE_NFC = DlgDelegate.DIALOG_LAST + 2;
|
||||
|
||||
private boolean m_showsOn;
|
||||
private boolean m_nameForBT;
|
||||
private boolean m_firingPrefs = false;
|
||||
|
@ -103,7 +104,7 @@ public class NewGameActivity extends XWActivity {
|
|||
}
|
||||
} );
|
||||
|
||||
button = (Button)findViewById( R.id.newgame_invite );
|
||||
button = (Button)findViewById( R.id.newgame_invite_net );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
|
@ -254,6 +255,9 @@ public class NewGameActivity extends XWActivity {
|
|||
.create();
|
||||
Utils.setRemoveOnDismiss( this, dialog, id );
|
||||
|
||||
break;
|
||||
case ENABLE_NFC:
|
||||
dialog = NFCUtils.makeEnableNFCDialog( this );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -318,34 +322,40 @@ public class NewGameActivity extends XWActivity {
|
|||
private void makeNewGame( boolean networked, boolean launch,
|
||||
int chosen )
|
||||
{
|
||||
String room = null;
|
||||
String inviteID = null;
|
||||
long rowid;
|
||||
int[] lang = {0};
|
||||
String[] dict = {null};
|
||||
final int nPlayers = 2; // hard-coded for no-configure case
|
||||
|
||||
if ( networked ) {
|
||||
room = GameUtils.makeRandomID();
|
||||
inviteID = GameUtils.makeRandomID();
|
||||
rowid = GameUtils.makeNewNetGame( this, m_groupID, room, inviteID,
|
||||
lang, dict, nPlayers, 1 );
|
||||
if ( DlgDelegate.NFC_BTN == chosen
|
||||
&& !NFCUtils.nfcAvail( this )[1] ) {
|
||||
showDialog( ENABLE_NFC );
|
||||
} else {
|
||||
rowid = GameUtils.saveNew( this, new CurGameInfo( this ), m_groupID );
|
||||
}
|
||||
String room = null;
|
||||
String inviteID = null;
|
||||
long rowid;
|
||||
int[] lang = {0};
|
||||
String[] dict = {null};
|
||||
final int nPlayers = 2; // hard-coded for no-configure case
|
||||
|
||||
if ( launch ) {
|
||||
GameUtils.launchGame( this, rowid, networked );
|
||||
if ( networked ) {
|
||||
GameUtils.launchInviteActivity( this, chosen, room,
|
||||
inviteID, lang[0], dict[0],
|
||||
nPlayers );
|
||||
room = GameUtils.makeRandomID();
|
||||
inviteID = GameUtils.makeRandomID();
|
||||
rowid = GameUtils.makeNewNetGame( this, m_groupID, room, inviteID,
|
||||
lang, dict, nPlayers, 1 );
|
||||
} else {
|
||||
rowid = GameUtils.saveNew( this, new CurGameInfo( this ),
|
||||
m_groupID );
|
||||
}
|
||||
} else {
|
||||
GameUtils.doConfig( this, rowid, GameConfig.class );
|
||||
}
|
||||
|
||||
finish();
|
||||
if ( launch ) {
|
||||
GameUtils.launchGame( this, rowid, networked );
|
||||
if ( networked ) {
|
||||
GameUtils.launchInviteActivity( this, chosen, room,
|
||||
inviteID, lang[0], dict[0],
|
||||
nPlayers );
|
||||
}
|
||||
} else {
|
||||
GameUtils.doConfig( this, rowid, GameConfig.class );
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void makeNewBTGame( boolean useDefaults )
|
||||
|
|
Loading…
Reference in a new issue