use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class DetectionListenerManager method unRegisterListener.
public void unRegisterListener(NfcWriteNdefSmartTagListener nfcWriteNdefSmartTagListener) {
ReaderWriterManager nfcManager;
Utilities.log("XXXX NfcWriteNdefSmartTag about to remove Detection Listener");
try {
nfcManager = ReaderWriterManager.getInstance();
/*
* This is the converse of the call to register our interest in
* tags of a certain type.
*/
nfcManager.removeDetectionListener(nfcWriteNdefSmartTagListener);
Utilities.log("XXXX NfcWriteNdefSmartTag remove Detcetion Listener success");
logEvent("Detection Listener removed");
rts.replace(Constants.LISTENER_STATE_TOKEN, new Boolean(false));
} catch (NFCException e) {
e.printStackTrace();
Utilities.log("XXXX NfcWriteNdefSmartTag NFCException on unregister");
logEvent("Detection Listener remove failed");
}
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class NfcWriteNdefSmartTagListener method writeSpTag.
private void writeSpTag(String target_uri) {
Utilities.log("XXXX Writing SP tag");
NDEFTagConnection tagConnection = null;
String willWriteMsg = "Writing Smart Poster Tag " + _screen.getTagDetails() + ",Language: " + URL_TEXT_LOCALE;
_screen.logEvent(willWriteMsg);
try {
NDEFMessage smartPosterTag = createSmartPosterTag();
tagConnection = (NDEFTagConnection) Connector.open(target_uri);
tagConnection.write(smartPosterTag);
Utilities.log("XXXX NfcWriteNdefSmartTagListener SP Tag written successfully");
_screen.logEvent("SP tag written successfully");
} catch (NFCException e) {
e.printStackTrace();
Utilities.log("XXXX NfcWriteNdefSmartTagListener NFCException");
} catch (IOException e) {
e.printStackTrace();
Utilities.log("XXXX NfcWriteNdefSmartTagListener IOException");
}
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class NfcVirtTargScreen method startEmulationOfISO14443ATarget.
protected void startEmulationOfISO14443ATarget() {
Utilities.log("XXXX NfcVirtTarg About to start ISO14443-A virtual emulation");
try {
// note that the ID parameter is not actually used by the API
_virtualISO14443ATarget = new VirtualISO14443Part4TypeATarget(new NfcVirtTargListener(this), Constants.MY_ISO_TARGET_ID, null);
_virtualISO14443ATarget.startEmulation();
Utilities.log("XXXX NfcVirtTarg ISO14443-A emulation started");
_screen.logEvent("info:ISO14443-A emulation started");
} catch (NFCException e) {
e.printStackTrace();
Utilities.log("XXXX NfcVirtTarg NFCException on starting ISO14443-A emulation");
_screen.logEvent("info:Starting ISO 14443-A emulation failed");
}
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class NfcVirtTargScreen method startDetectionListener.
protected void startDetectionListener(NfcVirtDetectionListener detectionListener) {
ReaderWriterManager nfcManager;
Utilities.log("XXXX NfcVirtTarg about to add Detection Listener");
try {
nfcManager = ReaderWriterManager.getInstance();
nfcManager.addDetectionListener(detectionListener);
Utilities.log("XXXX NfcVirtTarg add Detection Listener success");
_screen.logEvent("info:Detection Listener added");
} catch (NFCException e) {
e.printStackTrace();
Utilities.log("XXXX NfcVirtTarg NFCException on register");
_screen.logEvent("info:Detection Listener add failed");
}
}
use of net.rim.device.api.io.nfc.NFCException in project Samples-for-Java by blackberry.
the class GameScreen method gameMessage.
public void gameMessage(ProtocolMessage message) {
Utilities.log("XXXX gameMessage:" + message);
// should indicate it's now our turn
if (message instanceof ProtocolMessageTurnOver) {
// OK, it's our turn now!
ProtocolMessageTurnOver pmsg_to = (ProtocolMessageTurnOver) message;
Utilities.log("XXXX gameMessage: ProtocolMessageTurnOver");
game_state.setBoardLocked(false);
int other_symbol = pmsg_to.get_symbol_played();
// derive the symbol we're playing with from the one player 1 is using (they got to choose)
if (other_symbol == Constants.PLAYER_SYMBOL_CROSS) {
_symbol = Constants.PLAYER_SYMBOL_NOUGHT;
} else {
_symbol = Constants.PLAYER_SYMBOL_CROSS;
}
cmd_select_tile.set_symbol(_symbol);
int other_player_tile = pmsg_to.get_tile_changed();
game_state.updateTileOtherPlayer(other_player_tile, other_symbol);
setStatusMessage("It's your turn now!");
proto.stopListeningForMessages();
return;
}
if (message instanceof ProtocolMessageMasterBid) {
// from this screen, this means "let's start a new game"
// we may or may not have already sent our bid
Utilities.log("XXXX gameMessage: ProtocolMessageMasterBid: game_state.isBid_sent()=" + game_state.isBid_sent());
boolean ok = true;
other_bid = (ProtocolMessageMasterBid) message;
game_state.setOther_bid_received(other_bid);
// if we've received this message then one way or another it must be game over (maybe the other device has won)
game_state.setGame_over(true);
if (!game_state.isBid_sent()) {
my_bid = new ProtocolMessageMasterBid();
try {
proto.sendMasterBid(my_bid);
ok = true;
} catch (NFCException e1) {
ok = false;
Utilities.log("XXXX " + e1.getClass().getName() + ":" + e1.getMessage());
setStatusMessage("Error - try again");
}
}
proto.stopListeningForMessages();
if (ok) {
checkBids();
}
return;
}
if (message instanceof ProtocolMessageResetBidState) {
Utilities.log("XXXX gameMessage: ProtocolMessageResetBidState");
proto.stopListeningForMessages();
setStatusMessage("Please touch devices again");
resetBidStateTracking();
return;
}
}
Aggregations