Search in sources :

Example 11 with NFCException

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

Example 12 with NFCException

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);
        }
    });
}
Also used : NFCException(net.rim.device.api.io.nfc.NFCException) MainScreen(net.rim.device.api.ui.container.MainScreen)

Example 13 with NFCException

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

Example 14 with NFCException

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

Example 15 with NFCException

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

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