Search in sources :

Example 6 with NFCException

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");
    }
}
Also used : NFCException(net.rim.device.api.io.nfc.NFCException) ReaderWriterManager(net.rim.device.api.io.nfc.readerwriter.ReaderWriterManager)

Example 7 with NFCException

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");
    }
}
Also used : NDEFTagConnection(net.rim.device.api.io.nfc.ndef.NDEFTagConnection) NFCException(net.rim.device.api.io.nfc.NFCException) NDEFMessage(net.rim.device.api.io.nfc.ndef.NDEFMessage) IOException(java.io.IOException)

Example 8 with NFCException

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");
    }
}
Also used : VirtualISO14443Part4TypeATarget(net.rim.device.api.io.nfc.emulation.VirtualISO14443Part4TypeATarget) NfcVirtTargListener(nfc.sample.virtual.target.NfcVirtTargListener) NFCException(net.rim.device.api.io.nfc.NFCException)

Example 9 with NFCException

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");
    }
}
Also used : NFCException(net.rim.device.api.io.nfc.NFCException) ReaderWriterManager(net.rim.device.api.io.nfc.readerwriter.ReaderWriterManager)

Example 10 with NFCException

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;
    }
}
Also used : ProtocolMessageMasterBid(nfc.sample.tictactoe.protocol.ProtocolMessageMasterBid) ProtocolMessageTurnOver(nfc.sample.tictactoe.protocol.ProtocolMessageTurnOver) ProtocolMessageResetBidState(nfc.sample.tictactoe.protocol.ProtocolMessageResetBidState) NFCException(net.rim.device.api.io.nfc.NFCException)

Aggregations

NFCException (net.rim.device.api.io.nfc.NFCException)24 ReaderWriterManager (net.rim.device.api.io.nfc.readerwriter.ReaderWriterManager)8 ProtocolMessageMasterBid (nfc.sample.tictactoe.protocol.ProtocolMessageMasterBid)5 NDEFMessage (net.rim.device.api.io.nfc.ndef.NDEFMessage)4 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 NDEFRecord (net.rim.device.api.io.nfc.ndef.NDEFRecord)2 SecureElement (net.rim.device.api.io.nfc.se.SecureElement)2 SecureElementManager (net.rim.device.api.io.nfc.se.SecureElementManager)2 MainScreen (net.rim.device.api.ui.container.MainScreen)2 VirtualISO14443Part4TypeATarget (net.rim.device.api.io.nfc.emulation.VirtualISO14443Part4TypeATarget)1 BadFormatException (net.rim.device.api.io.nfc.ndef.BadFormatException)1 NDEFTagConnection (net.rim.device.api.io.nfc.ndef.NDEFTagConnection)1 SmartPosterRecord (net.rim.device.api.io.nfc.ndef.rtd.SmartPosterRecord)1 Settings (nfc.sample.nfctransaction.Settings)1 CardEmulation (nfc.sample.nfctransaction.nfc.CardEmulation)1 NfcTransScreen (nfc.sample.nfctransaction.ui.NfcTransScreen)1 GameProtocol (nfc.sample.tictactoe.protocol.GameProtocol)1 ProtocolMessageResetBidState (nfc.sample.tictactoe.protocol.ProtocolMessageResetBidState)1 ProtocolMessageTurnOver (nfc.sample.tictactoe.protocol.ProtocolMessageTurnOver)1