use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class GameScreen method staleMate.
private void staleMate() {
game_state.lockBoard();
setStatusMessage(Constants.STALE_MATE_MESSAGE, true);
for (int i = 0; i < 9; i++) {
if (game_state.getTileState(i) == Constants.PLAYER_SYMBOL_CROSS) {
tiles[i].setImage(stale_mate_cross_bmp);
} else {
tiles[i].setImage(stale_mate_nought_bmp);
}
}
game_state.setGame_over(true);
my_bid = new ProtocolMessageMasterBid();
try {
proto.sendMasterBid(my_bid);
proto.listenForMessages();
} catch (NFCException e) {
Utilities.log("XXXX " + e.getClass().getName() + ":" + e.getMessage());
setStatusMessage("It didn't work, please try again");
}
Utilities.popupMessage("Stale mate!");
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class GameScreen method checkBids.
private void checkBids() {
Utilities.log("XXXX checkBids: game_state.getMy_bid_sent()=" + game_state.getMy_bid_sent() + ",game_state.getOther_bid_received()=" + game_state.getOther_bid_received());
if (game_state.getMy_bid_sent() == null || game_state.getOther_bid_received() == null) {
return;
}
int device_role = 0;
if (my_bid.getBid() > other_bid.getBid()) {
Utilities.log("XXXX won the bid: player 1");
device_role = Constants.PLAYER_1;
} else {
if (my_bid.getBid() < other_bid.getBid()) {
Utilities.log("XXXX lost the bid: player 2");
device_role = Constants.PLAYER_2;
} else {
setStatusMessage("It didn't work, please try again!");
return;
}
}
try {
proto.disableMessaging();
} catch (NFCException e) {
Utilities.log("XXXX GameScreen:" + e.getClass().getName() + ":" + e.getMessage());
setStatusMessage("It didn't work, try again!");
return;
}
resetBidStateTracking();
final int player_no = device_role;
final MainScreen next_screen;
if (player_no == Constants.PLAYER_2) {
next_screen = GameScreen.getInstance(player_no);
} else {
next_screen = new SymbolSelectionScreen();
}
final GameScreen this_screen = this;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(this_screen);
}
});
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(next_screen);
}
});
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class StartGameScreen method initNewGameMessaging.
public void initNewGameMessaging() {
try {
// send bid message over SNEP
proto = new GameProtocol(this);
my_bid = new ProtocolMessageMasterBid();
proto.sendMasterBid(my_bid);
proto.listenForMessages();
} catch (NFCException e) {
Utilities.log("XXXX StartGameScreen:" + e.getClass().getName() + ":" + e.getMessage());
Utilities.popupMessage("Error: separate devices and try again!");
}
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class NfcSettingsScreen method applySettings.
private void applySettings() {
try {
if ((current_se == SecureElement.SIM) && (se_choices.getSelectedIndex() == 1)) {
ce.initCe(SecureElement.EMBEDDED);
settings.setSeEmbedded();
} else {
if ((current_se == SecureElement.EMBEDDED) && (se_choices.getSelectedIndex() == 0)) {
ce.initCe(SecureElement.SIM);
settings.setSeSIM();
}
}
} catch (NFCException e) {
Utilities.popupAlert("Error: could not change SE selection");
return;
}
int tech_types = TechnologyType.NONE;
if (cbx_iso1443a.getChecked() == true) {
tech_types = tech_types | TechnologyType.ISO14443A;
}
if (cbx_iso1443b.getChecked() == true) {
tech_types = tech_types | TechnologyType.ISO14443B;
}
if (cbx_iso1443b_prime.getChecked() == true) {
tech_types = tech_types | TechnologyType.ISO14443B_PRIME;
}
settings.setISO14443A(cbx_iso1443a.getChecked());
settings.setISO14443B(cbx_iso1443b.getChecked());
settings.setISO14443B_PRIME(cbx_iso1443b_prime.getChecked());
if (!settings.getRegisteredAIDAsString().equals(edt_aid.getText())) {
settings.setRegisteredAID(edt_aid.getText());
CardEmulation ce = CardEmulation.getInstance();
ce.removeTransactionListener();
CardEmulation.registerTransactionListener(NfcTransHandlerApp.getTransactionListener());
}
settings.setAPDU(edt_apdu.getText());
Utilities.log("XXXX " + Thread.currentThread().getName() + " Selected tech types=" + Utilities.getTechnologyTypesNames(tech_types));
if (current_tt != tech_types) {
try {
ce.setRoutingOn(tech_types);
} catch (NFCException e) {
Utilities.popupAlert("Error: could not change CE technology types");
return;
} catch (Exception e) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " " + e.getClass().getName() + ":" + e.getMessage());
Utilities.popupAlert(e.getClass().getName() + ": could not change CE technology types");
return;
}
}
Utilities.log("XXXX " + Thread.currentThread().getName() + " applySettings 11");
setDirty(false);
Utilities.log("XXXX " + Thread.currentThread().getName() + " applySettings 12");
Utilities.popupMessage("New settings applied");
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class NdefListenerManager method registerListener.
public void registerListener(Listener listener) {
// unRegisterListener(); // just in case already registered
ReaderWriterManager nfcManager;
try {
nfcManager = ReaderWriterManager.getInstance();
nfcManager.addNDEFMessageListener(listener, NDEFRecord.TNF_EXTERNAL, "my.rim.com:myrecordtype", true);
rts.replace(Constants.LISTENER_STATE_TOKEN, new Boolean(true));
Utilities.log("XXXX listener registered");
} catch (NFCException e) {
Utilities.log("XXXX " + e.getClass().getName() + ":" + e.getMessage());
}
}
Aggregations