Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit b2ca3e1f7bb49d5294111ba64fb96a0ec77c30e1 1 parent 4caa4d4
@jcmurray jcmurray authored
Showing with 1,793 additions and 0 deletions.
  1. +7 −0 NFC/NfcVirtualTargetFun/.classpath
  2. +29 −0 NFC/NfcVirtualTargetFun/.project
  3. +3 −0  NFC/NfcVirtualTargetFun/.settings/net.rim.browser.tools.debug.widget.prefs
  4. +12 −0 NFC/NfcVirtualTargetFun/.settings/org.eclipse.jdt.core.prefs
  5. +23 −0 NFC/NfcVirtualTargetFun/BlackBerry_App_Descriptor.xml
  6. +45 −0 NFC/NfcVirtualTargetFun/README.md
  7. BIN  NFC/NfcVirtualTargetFun/docs/AN11004-MIFARE DESFire as Type 4 Tag.pdf
  8. BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.4.docx
  9. BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.5.docx
  10. BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.6.docx
  11. BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.7.docx
  12. BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.8.docx
  13. BIN  NFC/NfcVirtualTargetFun/docs/NFCForum-TS-Type-4-Tag_1.0.pdf
  14. +22 −0 NFC/NfcVirtualTargetFun/docs/sendApduToDevice.txt
  15. BIN  NFC/NfcVirtualTargetFun/res/img/SmartTag_Logo.png
  16. BIN  NFC/NfcVirtualTargetFun/res/img/Thumbs.db
  17. BIN  NFC/NfcVirtualTargetFun/res/img/emulate_reader_clicked.png
  18. BIN  NFC/NfcVirtualTargetFun/res/img/emulate_reader_focus.png
  19. BIN  NFC/NfcVirtualTargetFun/res/img/emulate_reader_no_focus.png
  20. BIN  NFC/NfcVirtualTargetFun/res/img/emulate_sc_clicked.png
  21. BIN  NFC/NfcVirtualTargetFun/res/img/emulate_sc_focus.png
  22. BIN  NFC/NfcVirtualTargetFun/res/img/emulate_sc_no_focus.png
  23. BIN  NFC/NfcVirtualTargetFun/res/img/icon.png
  24. BIN  NFC/NfcVirtualTargetFun/res/img/reader_icon.png
  25. BIN  NFC/NfcVirtualTargetFun/res/img/sc_icon.png
  26. +22 −0 NFC/NfcVirtualTargetFun/scripts/sendApduToDevice.txt
  27. +96 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/CommonADPUs.java
  28. +29 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/Constants.java
  29. +195 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/NfcVirtDetectionListener.java
  30. +71 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/NfcVirtTarg.java
  31. +176 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/NfcVirtTargListener.java
  32. +109 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/Utilities.java
  33. +41 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/buttons/MsbConfig.java
  34. +104 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/buttons/MsbState.java
  35. +144 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/buttons/MultiStateButtonField.java
  36. +34 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/EmulateScCommand.java
  37. +34 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/EmulateSrCommand.java
  38. +35 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/ResponseTextCommand.java
  39. +34 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/StartCommand.java
  40. +34 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/StopCommand.java
  41. +46 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/ui/AlternatingListField.java
  42. +269 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/ui/NfcVirtTargScreen.java
  43. +68 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/ui/ResponseTextScreen.java
  44. +111 −0 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/ui/RoleSelectionScreen.java
View
7 NFC/NfcVirtualTargetFun/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="res"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/net.rim.ejde.BlackBerryVMInstallType/BlackBerry JRE 7.0.0"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
29 NFC/NfcVirtualTargetFun/.project
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>NfcVirtualTargetFun</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>net.rim.ejde.internal.builder.BlackBerryPreprocessBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>net.rim.ejde.internal.builder.BlackBerryResourcesBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>net.rim.ejde.BlackBerryPreProcessNature</nature>
+ <nature>net.rim.ejde.BlackBerryProjectCoreNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
3  NFC/NfcVirtualTargetFun/.settings/net.rim.browser.tools.debug.widget.prefs
@@ -0,0 +1,3 @@
+#Mon Nov 14 16:19:15 GMT 2011
+eclipse.preferences.version=1
+outputfolder=build
View
12 NFC/NfcVirtualTargetFun/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Mon Nov 14 16:14:03 GMT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
+org.eclipse.jdt.core.compiler.source=1.3
View
23 NFC/NfcVirtualTargetFun/BlackBerry_App_Descriptor.xml
@@ -0,0 +1,23 @@
+<!-- This file has been generated by the BlackBerry Plugin for Eclipse v3.6.1. -->
+
+<Properties ModelVersion="1.1.2">
+ <General Title="NFC Virtual Target Fun" Version="1.0.4" Vendor="John Murray" Description="Fun with Virtual Targets"/>
+ <Application Type="BlackBerry Application" MainMIDletName="" MainArgs="" HomeScreenPosition="0" StartupTier="7" IsSystemModule="false" IsAutostartup="false"/>
+ <Resources hasTitleResource="false" TitleResourceBundleName="" TitleResourceBundleRelativePath="" TitleResourceBundleClassName="" TitleResourceBundleKey="" DescriptionId="">
+ <Icons>
+ <Icon CanonicalFileName="res/img/SmartTag_Logo.png" IsFocus="false"/>
+ </Icons>
+ </Resources>
+ <KeywordResources KeywordResourceBundleName="" KeywordResourceBundleRelativePath="" KeywordResourceBundleClassName="" KeywordResourceBundleKey=""/>
+ <Compile OutputCompilerMessages="false" ConvertImages="true" CreateWarningForNoExportedRoutine="true" CompressResources="false" AliasList="">
+ <PreprocessorDefines/>
+ </Compile>
+ <Packaging PreBuildStep="" PostBuildStep="" CleanStep="" OutputFileName="NfcVirtualTargetFun" OutputFolder="deliverables" GenerateALXFile="true">
+ <AlxFiles/>
+ </Packaging>
+ <HiddenProperties>
+ <ClassProtection/>
+ <PackageProtection/>
+ </HiddenProperties>
+ <AlternateEntryPoints/>
+</Properties>
View
45 NFC/NfcVirtualTargetFun/README.md
@@ -0,0 +1,45 @@
+# NFC Virtual Target Emulation Sample
+
+
+The purpose of this application is to demonstrate the emulation and reading of NFC virtual tags. In effect allowing a BlackBerry java application to appear to a reader as a smart card and, building on previous articles, enabling a second BlackBerry device to read the virtual tag emulated on the original device.
+
+The application is liberally instrumented with EventLogger Informational messages using the label "NfcVirtTargFun" that can be examined in the event log of a device. Use Alt-LGLG to set the log level to Information and to examine the event log or use javaloader -u eventlog>eventlog.txt to extract the log to your PC over USB.
+
+The sample code for this application is Open Source under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html).
+
+**Applies To**
+
+* [BlackBerry Java SDK for Smartphones](http://us.blackberry.com/developers/javaappdev/)
+
+
+**Author(s)**
+
+* [John Murray](https://github.com/jcmurray)
+* [Martin Woolley](https://github.com/mdwoolley)
+
+
+**Dependencies**
+
+1. BlackBerry Device Software 7.0 and above.
+
+
+**Known Issues**
+
+None
+
+**To contribute code to this repository you must be [signed up as an official contributor](http://blackberry.github.com/howToContribute.html).**
+
+
+## Contributing Changes
+
+Please see the [README](https://github.com/blackberry/BlackBerry-Java) of the BlackBerry-Java repository for instructions on how to add new Samples or make modifications to existing Samples.
+
+
+## Bug Reporting and Feature Requests
+
+If you find a bug in a Sample, or have an enhancement request, simply file an [Issue](https://github.com/blackberry/BlackBerry-Java/issues) for the Sample and send a message (via github messages) to the Sample Author(s) to let them know that you have filed an [Issue](https://github.com/blackberry/BlackBerry-Java/issues).
+
+
+## Disclaimer
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
BIN  NFC/NfcVirtualTargetFun/docs/AN11004-MIFARE DESFire as Type 4 Tag.pdf
Binary file not shown
View
BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.4.docx
Binary file not shown
View
BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.5.docx
Binary file not shown
View
BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.6.docx
Binary file not shown
View
BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.7.docx
Binary file not shown
View
BIN  NFC/NfcVirtualTargetFun/docs/NFC - Virtual Target Emulation V1.8.docx
Binary file not shown
View
BIN  NFC/NfcVirtualTargetFun/docs/NFCForum-TS-Type-4-Tag_1.0.pdf
Binary file not shown
View
22 NFC/NfcVirtualTargetFun/docs/sendApduToDevice.txt
@@ -0,0 +1,22 @@
+//
+// Copyright (c) 2012 Research In Motion Limited.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+establish_context
+enable_trace
+enable_timer
+card_connect
+send_apdu -APDU A0370000019900
+card_disconnect
+release_context
View
BIN  NFC/NfcVirtualTargetFun/res/img/SmartTag_Logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  NFC/NfcVirtualTargetFun/res/img/Thumbs.db
Binary file not shown
View
BIN  NFC/NfcVirtualTargetFun/res/img/emulate_reader_clicked.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  NFC/NfcVirtualTargetFun/res/img/emulate_reader_focus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  NFC/NfcVirtualTargetFun/res/img/emulate_reader_no_focus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  NFC/NfcVirtualTargetFun/res/img/emulate_sc_clicked.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  NFC/NfcVirtualTargetFun/res/img/emulate_sc_focus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  NFC/NfcVirtualTargetFun/res/img/emulate_sc_no_focus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  NFC/NfcVirtualTargetFun/res/img/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  NFC/NfcVirtualTargetFun/res/img/reader_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  NFC/NfcVirtualTargetFun/res/img/sc_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
22 NFC/NfcVirtualTargetFun/scripts/sendApduToDevice.txt
@@ -0,0 +1,22 @@
+//
+// Copyright (c) 2012 Research In Motion Limited.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+establish_context
+enable_trace
+enable_timer
+card_connect
+send_apdu -APDU A0370000019900
+card_disconnect
+release_context
View
96 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/CommonADPUs.java
@@ -0,0 +1,96 @@
+package nfc.sample.virtual.target;
+
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+public interface CommonADPUs {
+
+ public static final byte[] simpleISO14443Capdu = new byte[] {
+ (byte) 0xA0 // CLA - proprietary command type
+ , (byte) 0x37 // INS - arbitrary instruction code
+ , (byte) 0x00 // P1 - not used
+ , (byte) 0x00 // P2 - not used
+ , (byte) 0x01 // L(c) - length of 1 byte
+ , (byte) 0x99 // command payload (1 byte just for fun )
+ , (byte) 0x00 // L(e) ( up to 256 expected in response )
+ };
+
+ public static final byte[] goodResponseRapdu = new byte[] {
+ (byte) 0x90 // SW1 ...
+ , (byte) 0x00 // SW2 ... goodness! Deep joy!
+ };
+
+ public static final byte[] errorRapdu = new byte[] {
+ (byte) 0x6F // SW1 ...
+ , (byte) 0x00 // SW2 ... No precise diagnosis
+ };
+
+ public static final byte[] insNotSupportedRapdu = new byte[] {
+ (byte) 0x6D // SW1 ...
+ , (byte) 0x00 // SW2 ... INS Not SUpported
+ };
+
+ // ============== NFC Forum Type 4 NDEF Tag Application Select C-APDU =====
+ //
+ // AID of NDEF Application is D2 76 00 00 85 01 01
+ // APDU to send as documented in NFC Forum Type 4 Tag Specification v2.0
+ //
+
+ public static final byte[] ndefTagApplicationSelectV1Capdu = new byte[] {
+ (byte) 0x00 // CLA - See NFC Forum Type 4 NDEF Tag Application Select C-APDU
+ , (byte) 0xA4 // INS - ... " ...
+ , (byte) 0x04 // P1 - ... " ... - select by name
+ , (byte) 0x00 // P2 - ... " ... - first and only occurrence
+ , (byte) 0x07 // L(c) - length of 7 bytes
+ , (byte) 0xD2 // Per spec (v2.0)
+ , (byte) 0x76 // ... " ...
+ , (byte) 0x00 // ... " ...
+ , (byte) 0x00 // ... " ...
+ , (byte) 0x85 // ... " ...
+ , (byte) 0x01 // ... " ...
+ , (byte) 0x01 // ... " ...
+ , (byte) 0x00 // L(e) -- response data expected
+ };
+
+ // AID of NDEF Application is D2 76 00 00 85 01 00
+ // APDU to send as documented in the older NFC Forum Type 4 Tag Specification v1.0
+
+ public static final byte[] ndefTagApplicationSelectV0Capdu = new byte[] {
+ (byte) 0x00 // CLA - See NFC Forum Type 4 NDEF Tag Application Select C-APDU
+ , (byte) 0xA4 // INS - ... " ...
+ , (byte) 0x04 // P1 - ... " ... - select by name
+ , (byte) 0x00 // P2 - ... " ... - first and only occurrence
+ , (byte) 0x07 // L(c) - length of 7 bytes
+ , (byte) 0xD2 // Per spec (v1.0)
+ , (byte) 0x76 // ... " ...
+ , (byte) 0x00 // ... " ...
+ , (byte) 0x00 // ... " ...
+ , (byte) 0x85 // ... " ...
+ , (byte) 0x01 // ... " ...
+ , (byte) 0x00 // ... " ...
+ // L(e) -- not specified
+ };
+
+ public static final byte[] okRapdu = new byte[] {
+ (byte) 0x90 // File Control information may be returned
+ , (byte) 0x00 // ... " ...
+ };
+
+ public static final byte[] noNdefSupportRapdu = new byte[] {
+ (byte) 0x6A // NDEF Tag Application not found
+ , (byte) 0x82 // ... " ...
+ };
+
+}
View
29 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/Constants.java
@@ -0,0 +1,29 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target;
+
+public interface Constants {
+
+ public static final String MYAPP_VERSION = "1.0.6";
+ public static final String MY_ISO_TARGET_ID = "12131415";
+ public static final int DISPLAY_COLUMN_WIDTH = 8;
+
+ public static final int SC_BTN_STATE=0;
+ public static final int SR_BTN_STATE=0;
+
+ public static final int EMULATE_SC=0;
+ public static final int EMULATE_SR=1;
+}
View
195 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/NfcVirtDetectionListener.java
@@ -0,0 +1,195 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Enumeration;
+
+import javax.microedition.io.Connector;
+
+import net.rim.device.api.io.nfc.readerwriter.DetectionListener;
+import net.rim.device.api.io.nfc.readerwriter.ISO14443Part4Connection;
+import net.rim.device.api.io.nfc.readerwriter.Target;
+import net.rim.device.api.ui.UiApplication;
+import nfc.sample.virtual.target.ui.NfcVirtTargScreen;
+
+public class NfcVirtDetectionListener implements DetectionListener {
+
+ private NfcVirtTargScreen _screen;
+
+ public NfcVirtDetectionListener(NfcVirtTargScreen screen) {
+ this();
+ this._screen = screen;
+ Utilities.log("XXXX NfcVirtDetectionListener in constructor");
+ }
+
+ public NfcVirtDetectionListener() {
+ super();
+ }
+
+ public void onTargetDetected(Target target) {
+
+ Utilities.log("XXXX onTargetDetected detected a target");
+ _screen.logEvent("info:Target detected");
+
+ if(target.isType(Target.ISO_14443_3)) {
+ Utilities.log("XXXX onTargetDetected target is ISO_14443_3");
+ _screen.logEvent("info:Target is ISO_14443_3");
+ }
+
+ if(target.isType(Target.ISO_14443_4)) {
+ Utilities.log("XXXX onTargetDetected target is ISO_14443_4");
+ _screen.logEvent("info:Target is ISO_14443_4");
+ }
+
+ if(target.isType(Target.NDEF_TAG)) {
+ Utilities.log("XXXX onTargetDetected target is NDEF_TAG");
+ _screen.logEvent("info:Target is NDEF_TAG");
+ }
+
+ if(target.isType(Target.ISO_14443_3) || target.isType(Target.ISO_14443_4) || target.isType(Target.NDEF_TAG)) {
+
+ Enumeration targetProperties = target.getProperties();
+
+ if(targetProperties != null) {
+
+ for(Enumeration e = targetProperties; e.hasMoreElements();) {
+
+ String targetPropertyName = (String) e.nextElement();
+ String targetPropertyValue = target.getProperty(targetPropertyName);
+
+ if(!targetPropertyName.equals("SerialNumber")) {
+
+ String messageText = "info:Property(" + targetPropertyName + ")=" + targetPropertyValue;
+
+ Utilities.log("XXXX onTargetDetected " + messageText);
+ _screen.logEvent(messageText);
+
+ } else {
+ byte[] serialNumber=null;
+ try {
+ serialNumber = targetPropertyValue.getBytes("US-ASCII");
+ } catch(UnsupportedEncodingException e1) {
+ }
+
+ String messageText = "info:Property(" + targetPropertyName + ")="
+ + Utilities.formatAsHexPairs(Constants.DISPLAY_COLUMN_WIDTH, serialNumber);
+
+ Utilities.log("XXXX onTargetDetected " + messageText);
+ _screen.logEvent(messageText);
+ }
+ }
+ }
+ }
+
+ if(target.isType(Target.ISO_14443_4)) {
+
+ // This is the target type we are interested it. This should be the other BlackBerry
+ // device entering the RF field and emulating a virtual ISO_14443_4 target
+
+ Utilities.log("XXXX onTargetDetected attempting to communicate with ISO_14443_4 target");
+ _screen.logEvent("info:Attempting to communicate with ISO_14443_4 target");
+
+ String targetURI = target.getUri(Target.ISO_14443_4);
+
+ ISO14443Part4Connection targetISO14443Part4Connection = null;
+
+ byte[] tranceiveResponse = null;
+
+ try {
+
+ /*
+ * Now that we have an ISO_14443_4 target in the RF field we will send our simple
+ * proprietary C-APDU to request the contents of the screen on the other device
+ *
+ * The basic protocol sequence that is of importance is as follows:
+ *
+ * Device acting as card reader/writer
+ *
+ * Sends C-APDU -> A0 37 00 01 99 00
+ *
+ * Receives R-APDU <- 53 65 6e 64 20 74 6f 20 6f 74 68 65 72 20 64 65 76 69 63 65 90 00
+ * Text from screen == S e n d t o o t h e r d e v i c e
+ *
+ */
+
+
+ String record = "Sending command\n" + "Command Len: " + CommonADPUs.simpleISO14443Capdu.length + "\nPayload: \n"
+ + Utilities.formatAsHexPairs(Constants.DISPLAY_COLUMN_WIDTH, CommonADPUs.simpleISO14443Capdu);
+
+ Utilities.log("XXXX onTargetDetected: " + record);
+ String eventlog_msg="send:"+Utilities.formatAsHexPairs(Constants.DISPLAY_COLUMN_WIDTH, CommonADPUs.simpleISO14443Capdu);
+ _screen.logEvent(eventlog_msg);
+
+ targetISO14443Part4Connection = (ISO14443Part4Connection) Connector.open(targetURI);
+ tranceiveResponse = targetISO14443Part4Connection.transceive(CommonADPUs.simpleISO14443Capdu);
+
+ record = "Received:\n" + " Len: " + tranceiveResponse.length + "\nPayload: \n"
+ + Utilities.formatAsHexPairs(Constants.DISPLAY_COLUMN_WIDTH, tranceiveResponse);
+ eventlog_msg = "rcvd:"+Utilities.formatAsHexPairs(Constants.DISPLAY_COLUMN_WIDTH, tranceiveResponse);
+
+ Utilities.log("XXXX onTargetDetected: " + record);
+ _screen.logEvent(eventlog_msg);
+
+ /*
+ * Parse the R-APDU received in response to our command
+ * It contains a payload if it's > 2 bytes in length ( SW1/SW2 status bytes are 2 bytes in length )
+ */
+
+ if(tranceiveResponse.length > 2) {
+ byte[] statusCode = new byte[2];
+ byte[] responseMessage = new byte[tranceiveResponse.length - statusCode.length];
+
+ // parse out the response text and SW1/SW2 fields
+
+ System.arraycopy(tranceiveResponse, 0, responseMessage, 0, responseMessage.length);
+ System.arraycopy(tranceiveResponse, responseMessage.length, statusCode, 0, statusCode.length);
+
+ record = "Response details\n" + "Status: \n"
+ + Utilities.formatAsHexPairs(Constants.DISPLAY_COLUMN_WIDTH, statusCode) + "\nPayload (hex): \n"
+ + Utilities.formatAsHexPairs(Constants.DISPLAY_COLUMN_WIDTH, responseMessage)
+ + "\nPayload (printable): \n"
+ + Utilities.formatAsPrintable(Constants.DISPLAY_COLUMN_WIDTH, responseMessage);
+
+ eventlog_msg="resp:status="+ Utilities.formatAsHexPairs(Constants.DISPLAY_COLUMN_WIDTH, statusCode);
+ _screen.logEvent(eventlog_msg);
+
+ eventlog_msg="resp:"+ Utilities.formatAsHexPairs(Constants.DISPLAY_COLUMN_WIDTH, responseMessage);
+ _screen.logEvent(eventlog_msg);
+
+ eventlog_msg="resp:"+ Utilities.formatAsPrintable(Constants.DISPLAY_COLUMN_WIDTH, responseMessage);
+ _screen.logEvent(eventlog_msg);
+
+ // Display the text from the other device
+
+ _screen.logEvent("data:" + new String(responseMessage, "UTF-8"));
+ } else {
+ _screen.logEvent("info:Unable to parse response");
+ }
+
+ } catch(IOException e) {
+ e.printStackTrace();
+ Utilities.log("XXXX onTargetDetected Exception: " + e.getMessage());
+ _screen.logEvent("info:Exception: " + e.getMessage());
+ }
+
+ } else {
+ Utilities.log("XXXX onTargetDetected this application only works with a ISO_14443_4 target");
+ _screen.logEvent("info:This application only works with a ISO_14443_4 target");
+ }
+ }
+}
View
71 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/NfcVirtTarg.java
@@ -0,0 +1,71 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target;
+
+import net.rim.device.api.ui.UiApplication;
+import net.rim.device.api.ui.container.MainScreen;
+import nfc.sample.virtual.target.ui.RoleSelectionScreen;
+
+/**
+ * The purpose of this app is to demonstrate the emulation and reading of NFC virtual tags.
+ *
+ * The application is liberally instrumented with EventLogger Informational
+ * messages using the label "NfcVirtTargFun" that can be examined in the
+ * event log of a device. Use Alt-LGLG to set the log level to Information
+ * and to examine the event log or use javaloader -u eventlog>eventlog.txt to
+ * extract the log to your PC over USB.
+ *
+ * Authors: John Murray and Martin Woolley, Research In Motion
+ *
+ */
+public class NfcVirtTarg extends UiApplication {
+
+ private static MainScreen _screen;
+
+ /**
+ * Standard entry point for a BlackBerry java application
+ */
+ public static void main(String[] args) {
+ System.out.println("XXXX starting NfcVirtTarg: #args=" + args.length);
+
+ NfcVirtTarg myApp = new NfcVirtTarg();
+
+ /*
+ * Register with the event logger
+ */
+ Utilities.initLogging();
+
+
+ Utilities.log("XXXX NfcVirtTarg has registered with EventLogger");
+ Utilities.log("XXXX NfcVirtTarg: has #args=" + args.length);
+
+ _screen = new RoleSelectionScreen();
+
+ Utilities.log("XXXX NfcVirtTarg about to push main screen");
+
+ /*
+ * Push the screen onto the stack
+ */
+ myApp.pushScreen(_screen);
+
+ Utilities.log("XXXX NfcVirtTarg about to enter event dispatcher");
+
+ /*
+ * Enter the event dispatcher to receive events and handle them
+ */
+ myApp.enterEventDispatcher();
+ }
+}
View
176 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/NfcVirtTargListener.java
@@ -0,0 +1,176 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target;
+
+import net.rim.device.api.io.nfc.emulation.VirtualISO14443Part4TargetCallback;
+import net.rim.device.api.ui.UiApplication;
+import net.rim.device.api.util.Arrays;
+import nfc.sample.virtual.target.ui.NfcVirtTargScreen;
+
+public class NfcVirtTargListener implements VirtualISO14443Part4TargetCallback {
+
+ private NfcVirtTargScreen _screen;
+
+ public NfcVirtTargListener(NfcVirtTargScreen nfcVirtTargScreen) {
+ this();
+ this._screen = nfcVirtTargScreen;
+ Utilities.log("XXXX NfcVirtTargListener in constructor");
+ }
+
+ public NfcVirtTargListener() {
+ super();
+ }
+
+ public void onVirtualTargetEvent(int targetEvent) {
+ /*
+ * This detects events related to the activation or deactivation of the virtual target by an external reader.
+ *
+ * In the case of this sample application this will be another BlackBerry device.
+ */
+ String displayableTargetEvent;
+
+ switch(targetEvent) {
+ case VirtualISO14443Part4TargetCallback.DEACTIVATED:
+ displayableTargetEvent = "Deactivated";
+ break;
+ case VirtualISO14443Part4TargetCallback.EMULATION_STOPPED:
+ displayableTargetEvent = "Emulation stopped";
+ break;
+ case VirtualISO14443Part4TargetCallback.SELECTED:
+ displayableTargetEvent = "Target Selected";
+ break;
+ default:
+ displayableTargetEvent = "Unrecognised event type";
+ break;
+ }
+
+ Utilities.log("XXXX NfcVirtTargListener onVirtualTargetEvent:" + displayableTargetEvent);
+ _screen.logEvent("info:" + displayableTargetEvent);
+ }
+
+ public byte[] processCommand(byte[] command) {
+
+ /*
+ * This method receives APDUs that originate from the reader that has activated this virtual target.
+ *
+ * The basic protocol sequence that is of importance is as follows:
+ *
+ * Device acting as virtual target
+ *
+ * Receives C-APDU <- A0 37 00 01 99 00
+ *
+ * Sends R-APDU -> 53 65 6e 64 20 74 6f 20 6f 74 68 65 72 20 64 65 76 69 63 65 90 00 Text from screen == S e n d t o o t h
+ * e r d e v i c e
+ *
+ * There are some other C-APDU's that may need to be handled and responded to.
+ *
+ * The reader tries figure out if virtual target is NDE capable as a Type 4 tag.
+ *
+ * It does this by sending C-APDUs that are part of the NFC Forum Type-4 tag documentation. This sample show how to handle
+ * the NDEF Tag Application Select C-APDU which tries to SELECT the NDEF application on the target if it exists. In this
+ * example we are only interested in performing a simple proprietary C-/R-APDU exchange so we reject the select operation
+ * as follows:
+ *
+ * Receives C-APDU <- 00 A4 04 00 07 D2 76 00 00 85 01 00 (for NFC Forum Type 4 version 1.0 spec)
+ *
+ * or
+ *
+ * Receives C-APDU <- 00 A4 04 00 07 D2 76 00 00 85 01 01 00 (for NFC Forum Type 4 version 2.0 spec)
+ *
+ * Sends R-APDU -> 6A 82
+ *
+ * An SW1/SW2 of 6A/82 indicates that NDEF is not SELECTable as an application.
+ *
+ * All other C-APDUs are rejected in a similar manner.
+ */
+
+ int widthOfData = Constants.DISPLAY_COLUMN_WIDTH;
+
+ String hexPayload = Utilities.formatAsHexPairs(widthOfData, command);
+ String characterPayload = Utilities.formatAsPrintable(widthOfData, command);
+
+ String eventlog_msg = "";
+
+ String record = "Command received\n" + "Command Len: " + command.length + "\nHex Payload: \n" + hexPayload
+ + "\nCharacter Payload: \n" + characterPayload;
+
+ Utilities.log("XXXX NfcVirtTargListener processCommand=" + hexPayload);
+ eventlog_msg = "rcvd:" + hexPayload;
+ _screen.logEvent(eventlog_msg);
+
+ String responseText = _screen.getResponse_text();
+ Utilities.log("XXXX NfcVirtTargListener processCommand using user defined text value:" + responseText);
+
+ byte[] responseTextBytes = responseText.getBytes();
+ byte[] responseBytes = new byte[responseTextBytes.length + CommonADPUs.goodResponseRapdu.length];
+
+ if(Arrays.equals(command, CommonADPUs.simpleISO14443Capdu)) {
+
+ // This is the simple proprietary C-APDU that we use to requests the screen contents
+
+ System.arraycopy(responseTextBytes, 0, responseBytes, 0, responseTextBytes.length);
+
+ System.arraycopy(CommonADPUs.goodResponseRapdu, 0, responseBytes, responseTextBytes.length,
+ CommonADPUs.goodResponseRapdu.length);
+
+ record = "resp:" + "Len: " + responseText.length() + "\nHex Response: \n"
+ + Utilities.formatAsHexPairs(widthOfData, responseBytes) + "\nCharacter Response: \n"
+ + Utilities.formatAsPrintable(widthOfData, responseBytes);
+
+ eventlog_msg = "resp:" + Utilities.formatAsHexPairs(widthOfData, responseBytes);
+
+ Utilities.log("XXXX NfcVirtTargListener Response sent=" + Utilities.formatAsHexPairs(widthOfData, responseBytes));
+ _screen.logEvent(eventlog_msg);
+
+ return responseBytes;
+
+ } else if(Arrays.equals(command, CommonADPUs.ndefTagApplicationSelectV0Capdu) ||
+ Arrays.equals(command, CommonADPUs.ndefTagApplicationSelectV1Capdu)) {
+
+ // For this simple example say we don't support NDEF by rejecting both forms of
+ // the NDEF Application AIDs (V0 and V1) that are defined by the NFC Forum Specification !
+
+ record = "Responding to an NDEF Tag App Select Command\n" + "Len: " + CommonADPUs.noNdefSupportRapdu.length
+ + "\nHex Response: \n" + Utilities.formatAsHexPairs(widthOfData, CommonADPUs.noNdefSupportRapdu);
+
+ eventlog_msg = "resp:"+Utilities.formatAsHexPairs(widthOfData, CommonADPUs.noNdefSupportRapdu);
+
+ Utilities.log("XXXX NfcVirtTargListener Response sent="
+ + Utilities.formatAsHexPairs(widthOfData, CommonADPUs.noNdefSupportRapdu));
+
+ _screen.logEvent(eventlog_msg);
+
+ return CommonADPUs.noNdefSupportRapdu;
+
+ } else {
+
+ // Also reject all other C-APDUs in this example with INS not supported
+
+ record = "Not Supported Resonse sent\n" + "Len: " + CommonADPUs.insNotSupportedRapdu.length + "\nHex Response: \n"
+ + Utilities.formatAsHexPairs(widthOfData, CommonADPUs.insNotSupportedRapdu);
+
+ Utilities.log("XXXX NfcVirtTargListener Unsupported APDU received:" + hexPayload);
+ Utilities.log("XXXX NfcVirtTargListener Warning sent="
+ + Utilities.formatAsHexPairs(widthOfData, CommonADPUs.insNotSupportedRapdu));
+
+ eventlog_msg = "resp:"+Utilities.formatAsHexPairs(widthOfData, CommonADPUs.insNotSupportedRapdu);
+
+ _screen.logEvent(eventlog_msg);
+
+ return CommonADPUs.insNotSupportedRapdu;
+ }
+ }
+}
View
109 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/Utilities.java
@@ -0,0 +1,109 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target;
+
+import java.io.UnsupportedEncodingException;
+
+import net.rim.device.api.system.EventLogger;
+import net.rim.device.api.ui.UiApplication;
+import net.rim.device.api.ui.component.Dialog;
+
+public class Utilities implements Constants, CommonADPUs {
+
+ private static final long MYAPP_ID = 0x3db7a0becb8d1705L;
+ private static final String MYAPP_NAME = "NfcVirtTargFun";
+ private static final int UTF_16_TEXT = 0x80;
+ private static final int IANA_LANGUAGE_CODE_LEN_MASK = 0x1F;
+
+ /*
+ * Generic logging routine that writes entries to the event log and also to STDOUT when debugging
+ */
+ public static void log(String logMessage) {
+ System.out.println(logMessage);
+ try {
+ boolean ok = EventLogger.logEvent(MYAPP_ID, logMessage.getBytes("US-ASCII"), EventLogger.INFORMATION);
+ } catch(UnsupportedEncodingException e) {
+ }
+ }
+
+ public static void initLogging() {
+ EventLogger.register(MYAPP_ID, MYAPP_NAME, EventLogger.VIEWER_STRING);
+ }
+
+ public static void popupMessage(String message) {
+ synchronized(UiApplication.getEventLock()) {
+ Dialog.inform(message);
+ }
+ }
+
+ public static boolean isUtf16Encoded(int status_byte) {
+ return(status_byte == (status_byte & UTF_16_TEXT));
+ }
+
+ public static int getIanaLanguageCodeLength(int status_byte) {
+ return status_byte & IANA_LANGUAGE_CODE_LEN_MASK;
+ }
+
+ /*
+ * Helper to represent a byte as a printable ASCII character
+ */
+ public static char byte2Ascii(byte b) {
+ char character = '.';
+ if((20 <= b) && (126 >= b)) {
+ character = (char) b;
+ }
+ return character;
+ }
+
+ /*
+ * Helper to represent a byte as a printable hex pair.
+ */
+ public static String byte2HexPair(byte b) {
+ String hex;
+ hex = "00" + Integer.toHexString(b);
+ hex = hex.substring(hex.length() - 2).toUpperCase();
+ return hex;
+ }
+
+ public static String formatAsHexPairs(int widthOfRow, byte[] dataToFormat) {
+
+ StringBuffer hexFormattedData = new StringBuffer();
+ String hexpair;
+
+ for(int i = 0; i < dataToFormat.length; i++) {
+ hexpair = Utilities.byte2HexPair(dataToFormat[i]);
+ hexFormattedData.append(hexpair + " " + (((i + 1) % widthOfRow == 0) ? "\n" : ""));
+ }
+
+ return hexFormattedData.toString();
+ }
+
+ public static String formatAsPrintable(int widthOfRow, byte[] dataToFormat) {
+
+ StringBuffer printableFormattedData = new StringBuffer();
+ for(int i = 0; i < dataToFormat.length; i++) {
+ printableFormattedData.append(Utilities.byte2Ascii(dataToFormat[i]));
+ printableFormattedData.append((((i + 1) % widthOfRow == 0) ? "\n" : ""));
+ }
+
+ return printableFormattedData.toString();
+ }
+
+ public static boolean isOdd(int number) {
+ int remainder = number % 2;
+ return remainder == 1;
+ }
+}
View
41 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/buttons/MsbConfig.java
@@ -0,0 +1,41 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.buttons;
+
+import java.util.Hashtable;
+
+
+/**
+ * A MultiStateButtonField has a series of states, each of which has multiple visual indications depending on
+ * focused/unfocused
+ * click/unclick
+ *
+ */
+public class MsbConfig {
+
+ private Hashtable states = new Hashtable();
+
+ public void addState(MsbState state) {
+ Integer key = new Integer(state.getState_id());
+ states.put(key,state);
+ }
+
+ public MsbState getState(int state_id) {
+ MsbState state = (MsbState) states.get(new Integer(state_id));
+ return state;
+ }
+
+}
View
104 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/buttons/MsbState.java
@@ -0,0 +1,104 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.buttons;
+
+import net.rim.device.api.system.Bitmap;
+
+public class MsbState {
+
+ public static final int DEFAULT_STATE=0;
+
+ private int state_id; // zero is the default state
+ private String state_description; // e.g. "Service is currently ON"
+ private String state_label; // for display on buttons e.g. "ON"
+
+ private Bitmap bmp_unfocused;
+ private Bitmap bmp_focused;
+ private Bitmap bmp_clicked;
+ private Bitmap bmp_unclicked;
+
+ public MsbState(int state_id, String state_description, String state_label) {
+ this.state_id = state_id;
+ this.state_description = state_description;
+ this.state_label = state_label;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof MsbState) {
+ if (((MsbState) obj).getState_id() == this.state_id) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public int getState_id() {
+ return state_id;
+ }
+
+ public void setState_id(int state_id) {
+ this.state_id = state_id;
+ }
+
+ public String getState_description() {
+ return state_description;
+ }
+
+ public void setState_description(String state_description) {
+ this.state_description = state_description;
+ }
+
+ public String getState_label() {
+ return state_label;
+ }
+
+ public void setState_label(String state_label) {
+ this.state_label = state_label;
+ }
+
+ public Bitmap getbmp_unfocused() {
+ return bmp_unfocused;
+ }
+
+ public void setbmp_unfocused(Bitmap bmp_unfocused) {
+ this.bmp_unfocused = bmp_unfocused;
+ }
+
+ public Bitmap getbmp_focused() {
+ return bmp_focused;
+ }
+
+ public void setbmp_focused(Bitmap bmp_focused) {
+ this.bmp_focused = bmp_focused;
+ }
+
+ public Bitmap getbmp_clicked() {
+ return bmp_clicked;
+ }
+
+ public void setbmp_clicked(Bitmap bmp_clicked) {
+ this.bmp_clicked = bmp_clicked;
+ }
+
+ public Bitmap getbmp_unclicked() {
+ return bmp_unclicked;
+ }
+
+ public void setbmp_unclicked(Bitmap bmp_unclicked) {
+ this.bmp_unclicked = bmp_unclicked;
+ }
+
+}
View
144 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/buttons/MultiStateButtonField.java
@@ -0,0 +1,144 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.buttons;
+
+import net.rim.device.api.command.AlwaysExecutableCommand;
+import net.rim.device.api.system.Bitmap;
+import net.rim.device.api.ui.Field;
+import net.rim.device.api.ui.Graphics;
+import net.rim.device.api.ui.TouchEvent;
+import nfc.sample.virtual.target.Utilities;
+
+public class MultiStateButtonField extends Field {
+
+ private MsbConfig config;
+ private int current_state;
+ private Bitmap current_bitmap;
+ private AlwaysExecutableCommand command;
+
+ public MultiStateButtonField(MsbConfig config, AlwaysExecutableCommand command,int initial_state, long style) {
+ super(style);
+ this.config = config;
+ this.command = command;
+ this.current_state = initial_state;
+ current_bitmap = config.getState(initial_state).getbmp_unfocused();
+ }
+
+ protected void paint(Graphics graphics) {
+ if (current_bitmap != null) {
+ graphics.drawBitmap(0, 0, current_bitmap.getWidth(), current_bitmap.getHeight(), current_bitmap, 0, 0);
+ } else {
+ Utilities.log("XXXX "+config.getState(current_state).getState_label()+"-ERROR:current_bitmap=null");
+ }
+ }
+
+ protected void drawFocus(Graphics graphics,
+ boolean on) {
+ }
+
+ public void setMsbState(int state_id) {
+ current_state = state_id;
+ current_bitmap = config.getState(state_id).getbmp_unfocused();
+ }
+
+ public int getMsbState() {
+ return current_state;
+ }
+
+ protected boolean navigationClick(int status,
+ int time) {
+ setFocus();
+ if (config.getState(current_state).getbmp_clicked() != null) {
+ current_bitmap = config.getState(current_state).getbmp_clicked();
+ invalidate();
+ }
+ return true;
+ }
+
+ protected boolean navigationUnclick(int status,
+ int time) {
+ if (config.getState(current_state).getbmp_unclicked() != null) {
+ current_bitmap = config.getState(current_state).getbmp_unclicked();
+ invalidate();
+ }
+ // pass button so we can check its state
+ command.execute(null, this);
+ return true;
+ }
+
+ protected boolean touchEvent(TouchEvent message) {
+ if (message.getY(1) < 0) {
+ return false;
+ }
+ if (message.getY(1) > getHeight()){
+ return false;
+ }
+ if (message.getX(1) < 0){
+ return false;
+ }
+ if (message.getX(1) > getWidth()){
+ return false;
+ }
+
+ setFocus();
+ if (message.getEvent() == TouchEvent.DOWN && config.getState(current_state).getbmp_clicked() != null) {
+ current_bitmap = config.getState(current_state).getbmp_clicked();
+ invalidate();
+ return true;
+ }
+ if (message.getEvent() == TouchEvent.UP && config.getState(current_state).getbmp_focused() != null) {
+ current_bitmap = config.getState(current_state).getbmp_focused();
+ invalidate();
+ command.execute(null, null);
+ return true;
+ }
+ return false;
+ }
+
+ protected void onFocus(int direction) {
+ if (config.getState(current_state).getbmp_focused() != null) {
+ current_bitmap = config.getState(current_state).getbmp_focused();
+ invalidate();
+ }
+ }
+
+ protected void onUnfocus() {
+ if (config.getState(current_state).getbmp_unfocused() != null) {
+ current_bitmap = config.getState(current_state).getbmp_unfocused();
+ invalidate();
+ }
+ }
+
+ public void setImage() {
+ current_bitmap = config.getState(current_state).getbmp_focused();
+ }
+
+ public boolean isFocusable() {
+ return true;
+ }
+
+ protected void layout(int width, int height) {
+ setExtent(current_bitmap.getWidth(),current_bitmap.getHeight());
+ }
+
+ public int getPreferredWidth() {
+ return current_bitmap.getWidth();
+ }
+
+ public int getPreferredHeight() {
+ return current_bitmap.getHeight();
+ }
+}
View
34 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/EmulateScCommand.java
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.commands;
+
+import net.rim.device.api.command.AlwaysExecutableCommand;
+import net.rim.device.api.command.ReadOnlyCommandMetadata;
+import net.rim.device.api.ui.UiApplication;
+import net.rim.device.api.ui.container.MainScreen;
+import nfc.sample.virtual.target.Constants;
+import nfc.sample.virtual.target.ui.NfcVirtTargScreen;
+
+public class EmulateScCommand extends AlwaysExecutableCommand {
+
+ public void execute(ReadOnlyCommandMetadata metadata, Object context) {
+ synchronized(UiApplication.getUiApplication().getEventLock()) {
+ MainScreen screen = new NfcVirtTargScreen(Constants.EMULATE_SC);
+ UiApplication.getUiApplication().pushScreen(screen);
+ }
+ }
+
+}
View
34 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/EmulateSrCommand.java
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.commands;
+
+import net.rim.device.api.command.AlwaysExecutableCommand;
+import net.rim.device.api.command.ReadOnlyCommandMetadata;
+import net.rim.device.api.ui.UiApplication;
+import net.rim.device.api.ui.container.MainScreen;
+import nfc.sample.virtual.target.Constants;
+import nfc.sample.virtual.target.ui.NfcVirtTargScreen;
+
+public class EmulateSrCommand extends AlwaysExecutableCommand {
+
+ public void execute(ReadOnlyCommandMetadata metadata, Object context) {
+ synchronized(UiApplication.getUiApplication().getEventLock()) {
+ MainScreen screen = new NfcVirtTargScreen(Constants.EMULATE_SR);
+ UiApplication.getUiApplication().pushScreen(screen);
+ }
+ }
+
+}
View
35 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/ResponseTextCommand.java
@@ -0,0 +1,35 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.commands;
+
+import net.rim.device.api.command.AlwaysExecutableCommand;
+import net.rim.device.api.command.ReadOnlyCommandMetadata;
+import net.rim.device.api.ui.UiApplication;
+import net.rim.device.api.ui.container.MainScreen;
+import nfc.sample.virtual.target.ui.NfcVirtTargScreen;
+import nfc.sample.virtual.target.ui.ResponseTextScreen;
+
+public class ResponseTextCommand extends AlwaysExecutableCommand {
+
+ public void execute(ReadOnlyCommandMetadata metadata, Object context) {
+ NfcVirtTargScreen screen = (NfcVirtTargScreen) context;
+ synchronized(UiApplication.getUiApplication().getEventLock()) {
+ MainScreen text_screen = new ResponseTextScreen(screen);
+ UiApplication.getUiApplication().pushScreen(text_screen);
+ }
+ }
+
+}
View
34 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/StartCommand.java
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.commands;
+
+import net.rim.device.api.command.CommandHandler;
+import net.rim.device.api.command.ReadOnlyCommandMetadata;
+import nfc.sample.virtual.target.ui.NfcVirtTargScreen;
+
+public class StartCommand extends CommandHandler {
+
+ private NfcVirtTargScreen _screen;
+
+ public StartCommand(NfcVirtTargScreen screen) {
+ _screen = screen;
+ }
+
+ public void execute(ReadOnlyCommandMetadata metadata, Object context) {
+ _screen.start();
+ }
+
+}
View
34 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/commands/StopCommand.java
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.commands;
+
+import net.rim.device.api.command.CommandHandler;
+import net.rim.device.api.command.ReadOnlyCommandMetadata;
+import nfc.sample.virtual.target.ui.NfcVirtTargScreen;
+
+public class StopCommand extends CommandHandler {
+
+ private NfcVirtTargScreen _screen;
+
+ public StopCommand(NfcVirtTargScreen screen) {
+ _screen = screen;
+ }
+
+ public void execute(ReadOnlyCommandMetadata metadata, Object context) {
+ _screen.stop();
+ }
+
+}
View
46 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/ui/AlternatingListField.java
@@ -0,0 +1,46 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.ui;
+
+import net.rim.device.api.ui.Graphics;
+import net.rim.device.api.ui.component.ListField;
+import net.rim.device.api.ui.component.ObjectListField;
+import nfc.sample.virtual.target.Utilities;
+
+public class AlternatingListField extends ObjectListField {
+
+ private int _bg_even;
+ private int _bg_odd;
+
+ public AlternatingListField(int bg_even, int bg_odd, long style) {
+ super(style);
+ _bg_even = bg_even;
+ _bg_odd = bg_odd;
+ }
+
+ public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) {
+ if(index != getSelectedIndex()) {
+ if(Utilities.isOdd(index)) {
+ graphics.setBackgroundColor(_bg_odd);
+ } else {
+ graphics.setBackgroundColor(_bg_even);
+ }
+ graphics.clear();
+ }
+ super.drawListRow(listField, graphics, index, y, width);
+ }
+
+}
View
269 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/ui/NfcVirtTargScreen.java
@@ -0,0 +1,269 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.ui;
+
+import net.rim.device.api.command.Command;
+import net.rim.device.api.io.nfc.NFCException;
+import net.rim.device.api.io.nfc.emulation.VirtualISO14443Part4TypeATarget;
+import net.rim.device.api.io.nfc.readerwriter.ReaderWriterManager;
+import net.rim.device.api.system.Bitmap;
+import net.rim.device.api.ui.Color;
+import net.rim.device.api.ui.Field;
+import net.rim.device.api.ui.Font;
+import net.rim.device.api.ui.MenuItem;
+import net.rim.device.api.ui.component.BitmapField;
+import net.rim.device.api.ui.component.LabelField;
+import net.rim.device.api.ui.component.RichTextField;
+import net.rim.device.api.ui.component.SeparatorField;
+import net.rim.device.api.ui.container.HorizontalFieldManager;
+import net.rim.device.api.ui.container.MainScreen;
+import net.rim.device.api.util.StringProvider;
+import nfc.sample.virtual.target.Constants;
+import nfc.sample.virtual.target.NfcVirtDetectionListener;
+import nfc.sample.virtual.target.NfcVirtTargListener;
+import nfc.sample.virtual.target.Utilities;
+import nfc.sample.virtual.target.commands.ResponseTextCommand;
+import nfc.sample.virtual.target.commands.StartCommand;
+import nfc.sample.virtual.target.commands.StopCommand;
+
+/**
+ * A class extending the MainScreen class, which provides default standard behaviour for BlackBerry GUI applications.
+ */
+public final class NfcVirtTargScreen extends MainScreen {
+
+ private NfcVirtTargScreen _screen;
+
+ private HorizontalFieldManager icon_row = new HorizontalFieldManager();
+ private Bitmap sc_icon = Bitmap.getBitmapResource("sc_icon.png");
+ private Bitmap reader_icon = Bitmap.getBitmapResource("reader_icon.png");
+
+ private BitmapField icon;
+
+ private String response_text = "Send to other device";
+
+ private SeparatorField separator1 = new SeparatorField(Field.USE_ALL_WIDTH);
+ private SeparatorField separator2 = new SeparatorField(Field.USE_ALL_WIDTH);
+
+ private RichTextField heading = new RichTextField();
+
+ private Font heading_font;
+
+ private AlternatingListField _log = new AlternatingListField(Color.WHITE,Color.LIGHTGRAY,Field.USE_ALL_WIDTH);
+
+ private MenuItem mi_stop = new MenuItem(new StringProvider("Stop Emulation"), 110, 10);
+ private MenuItem mi_start = new MenuItem(new StringProvider("Restart Emulation"), 110, 10);
+ private MenuItem mi_response = new MenuItem(new StringProvider("Set Response Text"), 110, 10);
+
+ private VirtualISO14443Part4TypeATarget _virtualISO14443ATarget;
+ private NfcVirtDetectionListener _detectionListener;
+
+ private int _emulation_type;
+
+ /**
+ * Creates a new NfcVirtTargScreen object
+ */
+ public NfcVirtTargScreen(int emulation_type) {
+
+ super(MainScreen.HORIZONTAL_SCROLL);
+ this._screen = this;
+ this._detectionListener = new NfcVirtDetectionListener(_screen);
+ _emulation_type = emulation_type;
+
+ Utilities.log("XXXX NfcVirtTarg entered NfcVirtTargScreen constructor");
+ setTitle("NfcVirtualTargetFun V" + Constants.MYAPP_VERSION);
+
+ if(emulation_type == Constants.EMULATE_SC) {
+ emulateSmartCard();
+ } else {
+ emulateReader();
+ }
+ mi_stop.setCommandContext(this);
+ mi_stop.setCommand(new Command(new StopCommand(this)));
+ addMenuItem(mi_stop);
+
+ mi_start.setCommandContext(this);
+ mi_start.setCommand(new Command(new StartCommand(this)));
+
+ Font default_font = Font.getDefault();
+ heading_font = default_font.derive(Font.BOLD, 24);
+
+ heading.setText("Event Log (newest items first)");
+ heading.setFont(heading_font);
+
+ add(separator1);
+ add(heading);
+ add(separator2);
+ add(_log);
+
+ Utilities.log("XXXX NfcVirtTarg leaving NfcVirtTargScreen constructor");
+ }
+
+ private void emulateSmartCard() {
+ icon = new BitmapField(sc_icon);
+ icon_row.add(icon);
+ icon_row.add(new LabelField(" - emulating smart card"));
+ add(icon_row);
+ mi_response.setCommandContext(this);
+ mi_response.setCommand(new Command(new ResponseTextCommand()));
+ addMenuItem(mi_response);
+ startEmulationOfISO14443ATarget();
+
+ }
+
+ private void emulateReader() {
+ icon = new BitmapField(reader_icon);
+ icon_row.add(icon);
+ icon_row.add(new LabelField(" - emulating reader"));
+ add(icon_row);
+ startDetectionListener(_detectionListener);
+ }
+
+ protected void stopDetectionListener(NfcVirtDetectionListener detectionListener) {
+
+ ReaderWriterManager nfcManager;
+
+ Utilities.log("XXXX NfcVirtTarg 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(detectionListener);
+
+ Utilities.log("XXXX NfcVirtTarg remove Detection Listener success");
+ _screen.logEvent("info:Detection Listener removed");
+
+ } catch(NFCException e) {
+ e.printStackTrace();
+ Utilities.log("XXXX NfcVirtTarg NFCException on unregister");
+ _screen.logEvent("info:Detection Listener remove failed");
+ }
+ }
+
+ 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");
+ }
+
+ }
+
+ protected void stopEmulationOfISO14443ATarget() {
+ Utilities.log("XXXX NfcVirtTarg About to stop ISO14443-A virtual emulation");
+ try {
+ _virtualISO14443ATarget.stopEmulation();
+ Utilities.log("XXXX NfcVirtTarg ISO14443-A emulation stopped");
+ _screen.logEvent("info:ISO14443-A emulation stopped");
+ } catch(NFCException e) {
+ e.printStackTrace();
+ Utilities.log("XXXX NfcVirtTarg NFCException on stopping ISO14443-A emulation");
+ _screen.logEvent("info:Stopping ISO 14443-A emulation failed");
+
+ }
+ }
+
+ 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");
+ }
+ }
+
+ private void stopSmartcardEmulation() {
+ Utilities.log("XXXX NfcVirtTarg handling Unregister To Send button event");
+
+ logEvent("info:Stop sending data option selected");
+
+ stopEmulationOfISO14443ATarget();
+ }
+
+ private void stopReaderEmulation() {
+ Utilities.log("XXXX NfcVirtTarg handling Unregister To Receive button event");
+
+ logEvent("info:Stop receiving data option selected");
+
+ stopDetectionListener(_detectionListener);
+ }
+
+ public void start() {
+ removeMenuItem(mi_start);
+ addMenuItem(mi_stop);
+ switch(_emulation_type) {
+ case Constants.EMULATE_SC:
+ startEmulationOfISO14443ATarget();
+ break;
+ case Constants.EMULATE_SR:
+ startDetectionListener(_detectionListener);
+ break;
+ }
+ }
+
+ public void stop() {
+ removeMenuItem(mi_stop);
+ addMenuItem(mi_start);
+ switch(_emulation_type) {
+ case Constants.EMULATE_SC:
+ stopSmartcardEmulation();
+ break;
+ case Constants.EMULATE_SR:
+ stopReaderEmulation();
+ break;
+ }
+ }
+
+ public void logEvent(String event_message) {
+ _log.insert(0, event_message);
+ _log.setSelectedIndex(0);
+ }
+
+ public String getResponse_text() {
+ return response_text;
+ }
+
+ public void setResponse_text(String response_text) {
+ this.response_text = response_text;
+ }
+
+ public boolean onClose() {
+ stop();
+ return super.onClose();
+ }
+
+}
View
68 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/ui/ResponseTextScreen.java
@@ -0,0 +1,68 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.ui;
+
+import java.io.IOException;
+
+import net.rim.device.api.ui.Field;
+import net.rim.device.api.ui.FieldChangeListener;
+import net.rim.device.api.ui.component.ButtonField;
+import net.rim.device.api.ui.component.EditField;
+import net.rim.device.api.ui.container.MainScreen;
+import nfc.sample.virtual.target.Constants;
+import nfc.sample.virtual.target.Utilities;
+
+public class ResponseTextScreen extends MainScreen {
+
+ private EditField text = new EditField("Respond with text: ", "Send to other device");
+ private ButtonField btn_save_settings = new ButtonField("Apply", ButtonField.CONSUME_CLICK);
+
+ private FieldChangeListener listener = new FieldChangeListener() {
+
+ public void fieldChanged(Field field, int context) {
+ if (field == btn_save_settings) {
+ applySettings();
+ }
+ }
+ };
+
+ private NfcVirtTargScreen _screen;
+
+ public ResponseTextScreen(NfcVirtTargScreen screen) {
+ setTitle("NfcVirtualTargetFun V" + Constants.MYAPP_VERSION);
+ _screen = screen;
+ add(text);
+ add(btn_save_settings);
+ btn_save_settings.setChangeListener(listener);
+
+ }
+
+ public void save() {
+ applySettings();
+ try {
+ super.save();
+ } catch (IOException e) {
+ }
+ }
+
+ private void applySettings() {
+ _screen.setResponse_text(text.getText());
+ setDirty(false);
+ Utilities.popupMessage("New settings applied");
+
+ }
+
+}
View
111 NFC/NfcVirtualTargetFun/src/nfc/sample/virtual/target/ui/RoleSelectionScreen.java
@@ -0,0 +1,111 @@
+/*
+* Copyright (c) 2012 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package nfc.sample.virtual.target.ui;
+
+import net.rim.device.api.system.Bitmap;
+import net.rim.device.api.system.Display;
+import net.rim.device.api.ui.Field;
+import net.rim.device.api.ui.FocusChangeListener;
+import net.rim.device.api.ui.UiApplication;
+import net.rim.device.api.ui.component.LabelField;
+import net.rim.device.api.ui.container.AbsoluteFieldManager;
+import net.rim.device.api.ui.container.MainScreen;
+import nfc.sample.virtual.target.Constants;
+import nfc.sample.virtual.target.buttons.MsbConfig;
+import nfc.sample.virtual.target.buttons.MsbState;
+import nfc.sample.virtual.target.buttons.MultiStateButtonField;
+import nfc.sample.virtual.target.commands.EmulateScCommand;
+import nfc.sample.virtual.target.commands.EmulateSrCommand;
+
+public class RoleSelectionScreen extends MainScreen {
+
+ private Bitmap sc_focused = Bitmap.getBitmapResource("emulate_sc_focus.png");
+ private Bitmap sc_unfocused = Bitmap.getBitmapResource("emulate_sc_no_focus.png");
+ private Bitmap sc_clicked = Bitmap.getBitmapResource("emulate_sc_clicked.png");
+
+ private Bitmap sr_focused = Bitmap.getBitmapResource("emulate_reader_focus.png");
+ private Bitmap sr_unfocused = Bitmap.getBitmapResource("emulate_reader_no_focus.png");
+ private Bitmap sr_clicked = Bitmap.getBitmapResource("emulate_reader_clicked.png");
+
+ private MultiStateButtonField msbf_sc;
+ private MultiStateButtonField msbf_sr;
+
+ private LabelField ui_msg=new LabelField("",Field.FIELD_HCENTER);
+
+ private int focused_button = 0;
+
+ private FocusChangeListener focus_listener = new FocusChangeListener() {
+
+ public void focusChanged(Field field, int eventType) {
+ if (field == msbf_sc) {
+ focused_button = 0;
+ setMessage("BlackBerry will act like a smart card");
+ }
+ if (field == msbf_sr) {
+ focused_button = 1;
+ setMessage("BlackBerry will act like a smart card reader");
+ }
+ }
+
+ };
+
+ public RoleSelectionScreen() {
+ super(USE_ALL_HEIGHT | USE_ALL_WIDTH | FIELD_HCENTER | FIELD_VCENTER | NO_VERTICAL_SCROLL);
+ setTitle("NfcVirtualTargetFun V" + Constants.MYAPP_VERSION);
+
+ AbsoluteFieldManager btn_row = new AbsoluteFieldManager();
+ // bitmaps are 120 x 120
+ int hgap = (int) ((Display.getWidth() - 240) / 3);
+ int vgap = (int) (Display.getHeight() - 120) / 2;
+ int x1= hgap;
+ int x2= x1 + 120 + hgap;
+ int y = (int) (vgap * 0.75);
+
+ MsbConfig sc_btn_config = new MsbConfig();
+ MsbState sc_btn_state = new MsbState(Constants.SC_BTN_STATE, "Emulate Smart Card", "Emulate Smart Card");
+ sc_btn_state.setbmp_focused(sc_focused);
+ sc_btn_state.setbmp_unfocused(sc_unfocused);
+ sc_btn_state.setbmp_clicked(sc_clicked);
+ sc_btn_state.setbmp_unclicked(sc_focused);
+ sc_btn_config.addState(sc_btn_state);
+ msbf_sc = new MultiStateButtonField(sc_btn_config, new EmulateScCommand(), 0, Field.FIELD_HCENTER);
+ btn_row.add(msbf_sc,x1,y);
+
+ MsbConfig sr_btn_config = new MsbConfig();
+ MsbState sr_btn_state = new MsbState(Constants.SR_BTN_STATE, "Emulate Reader", "Emulate Reader");
+ sr_btn_state.setbmp_focused(sr_focused);
+ sr_btn_state.setbmp_unfocused(sr_unfocused);
+ sr_btn_state.setbmp_clicked(sr_clicked);
+ sr_btn_state.setbmp_unclicked(sr_focused);
+ sr_btn_config.addState(sr_btn_state);
+ msbf_sr = new MultiStateButtonField(sr_btn_config, new EmulateSrCommand(), 0, Field.FIELD_HCENTER);
+ btn_row.add(msbf_sr,x2,y);
+
+ msbf_sc.setFocusListener(focus_listener);
+ msbf_sr.setFocusListener(focus_listener);
+
+ add(btn_row);
+ add(ui_msg);
+ }
+
+ private void setMessage(String message) {
+ synchronized (UiApplication.getEventLock()) {
+ ui_msg.setText(message);
+ }
+
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.