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,6 +59,7 @@ 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;
@ -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,6 +322,10 @@ public class NewGameActivity extends XWActivity {
private void makeNewGame( boolean networked, boolean launch, private void makeNewGame( boolean networked, boolean launch,
int chosen ) int chosen )
{ {
if ( DlgDelegate.NFC_BTN == chosen
&& !NFCUtils.nfcAvail( this )[1] ) {
showDialog( ENABLE_NFC );
} else {
String room = null; String room = null;
String inviteID = null; String inviteID = null;
long rowid; long rowid;
@ -331,7 +339,8 @@ public class NewGameActivity extends XWActivity {
rowid = GameUtils.makeNewNetGame( this, m_groupID, room, inviteID, rowid = GameUtils.makeNewNetGame( this, m_groupID, room, inviteID,
lang, dict, nPlayers, 1 ); lang, dict, nPlayers, 1 );
} else { } else {
rowid = GameUtils.saveNew( this, new CurGameInfo( this ), m_groupID ); rowid = GameUtils.saveNew( this, new CurGameInfo( this ),
m_groupID );
} }
if ( launch ) { if ( launch ) {
@ -347,6 +356,7 @@ public class NewGameActivity extends XWActivity {
finish(); finish();
} }
}
private void makeNewBTGame( boolean useDefaults ) private void makeNewBTGame( boolean useDefaults )
{ {