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:
Eric House 2013-11-20 07:56:05 -08:00
parent 5f7242f01b
commit 2e5e10ef6d
4 changed files with 61 additions and 40 deletions

View file

@ -88,7 +88,7 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
> >
<Button android:id="@+id/newgame_invite" <Button android:id="@+id/newgame_invite_net"
android:text="@string/newgame_invite" android:text="@string/newgame_invite"
style="@style/spaced_buttons" style="@style/spaced_buttons"
/> />

View file

@ -515,19 +515,7 @@ public class BoardActivity extends XWActivity
break; break;
case ENABLE_NFC: case ENABLE_NFC:
lstnr = new DialogInterface.OnClickListener() { dialog = NFCUtils.makeEnableNFCDialog( this );
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();
break; break;
default: default:

View file

@ -21,7 +21,11 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.nfc.NdefMessage; import android.nfc.NdefMessage;
import android.nfc.NdefRecord; 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 ) private static NdefMessage makeMessage( Activity activity, String data )
{ {
String mimeType = activity.getString( R.string.xwords_nfc_mime ); String mimeType = activity.getString( R.string.xwords_nfc_mime );

View file

@ -1,6 +1,6 @@
/* -*- compile-command: "cd ../../../../../; ant debug install"; -*- */ /* -*- 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. * rights reserved.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -59,7 +59,8 @@ public class NewGameActivity extends XWActivity {
// Dialogs // Dialogs
private static final int NAME_GAME = DlgDelegate.DIALOG_LAST + 1; 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_showsOn;
private boolean m_nameForBT; private boolean m_nameForBT;
private boolean m_firingPrefs = false; 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() { button.setOnClickListener( new View.OnClickListener() {
@Override @Override
public void onClick( View v ) { public void onClick( View v ) {
@ -254,6 +255,9 @@ public class NewGameActivity extends XWActivity {
.create(); .create();
Utils.setRemoveOnDismiss( this, dialog, id ); Utils.setRemoveOnDismiss( this, dialog, id );
break;
case ENABLE_NFC:
dialog = NFCUtils.makeEnableNFCDialog( this );
break; break;
} }
} }
@ -318,34 +322,40 @@ public class NewGameActivity extends XWActivity {
private void makeNewGame( boolean networked, boolean launch, private void makeNewGame( boolean networked, boolean launch,
int chosen ) int chosen )
{ {
String room = null; if ( DlgDelegate.NFC_BTN == chosen
String inviteID = null; && !NFCUtils.nfcAvail( this )[1] ) {
long rowid; showDialog( ENABLE_NFC );
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 );
} else { } 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 ) { if ( networked ) {
GameUtils.launchInviteActivity( this, chosen, room, room = GameUtils.makeRandomID();
inviteID, lang[0], dict[0], inviteID = GameUtils.makeRandomID();
nPlayers ); 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 ) private void makeNewBTGame( boolean useDefaults )