├── .gitignore
├── LICENSE.txt
├── Readme.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── implementationApp
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.txt
└── src
│ ├── androidTest
│ └── java
│ │ └── be
│ │ └── appfoundry
│ │ └── nfc
│ │ └── implementation
│ │ ├── TestEmptyFieldsNfcActivity.java
│ │ └── TestFilledFieldsNfcActivity.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── be
│ │ └── appfoundry
│ │ └── nfc
│ │ └── implementation
│ │ └── MainActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── layout
│ └── activity_main.xml
│ ├── menu
│ ├── main.xml
│ └── nfc.xml
│ ├── values-nl
│ └── strings.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── nfclib
├── .gitignore
├── build.gradle
├── proguard-rules.txt
└── src
│ ├── androidTest
│ └── java
│ │ └── be
│ │ └── appfoundry
│ │ └── nfclibrary
│ │ └── utilities
│ │ ├── TestUtilities.java
│ │ ├── async
│ │ ├── AbstractFailsTestsAsync.java
│ │ └── GenericTaskTestsAsync.java
│ │ └── sync
│ │ ├── WriteEmailFailsTests.java
│ │ ├── WriteEmailSucceedsTests.java
│ │ ├── WriteGeolocationFailsTests.java
│ │ ├── WriteGeolocationSucceedsTests.java
│ │ ├── WritePhoneFailsTests.java
│ │ ├── WritePhoneSucceedsTests.java
│ │ ├── WriteUriFailsTests.java
│ │ └── WriteUriSucceedsTests.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── be
│ │ └── appfoundry
│ │ └── nfclibrary
│ │ ├── activities
│ │ └── NfcActivity.java
│ │ ├── constants
│ │ ├── NfcPayloadHeader.java
│ │ └── NfcType.java
│ │ ├── exceptions
│ │ ├── InsufficientCapacityException.java
│ │ ├── ReadOnlyTagException.java
│ │ ├── TagNotPresentException.java
│ │ └── TagNotWritableException.java
│ │ ├── tasks
│ │ ├── GenericTask.java
│ │ └── interfaces
│ │ │ ├── AsyncOperationCallback.java
│ │ │ └── AsyncUiCallback.java
│ │ └── utilities
│ │ ├── async
│ │ ├── AbstractNfcAsync.java
│ │ ├── WriteBluetoothNfcAsync.java
│ │ ├── WriteCallbackNfcAsync.java
│ │ ├── WriteEmailNfcAsync.java
│ │ ├── WriteGeoLocationNfcAsync.java
│ │ ├── WritePhoneNfcAsync.java
│ │ ├── WriteSmsNfcAsync.java
│ │ └── WriteUriNfcAsync.java
│ │ ├── interfaces
│ │ ├── AsyncNfcWriteOperation.java
│ │ ├── NdefWrite.java
│ │ ├── NfcMessageUtility.java
│ │ ├── NfcReadUtility.java
│ │ ├── NfcWriteUtility.java
│ │ └── WriteUtility.java
│ │ └── sync
│ │ ├── NdefWriteImpl.java
│ │ ├── NfcMessageUtilityImpl.java
│ │ ├── NfcReadUtilityImpl.java
│ │ ├── NfcWriteUtilityImpl.java
│ │ └── WriteUtilityImpl.java
│ └── res
│ └── xml
│ └── nfc_tech.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Copyright: Benjamin Weiss (keyboardsurfer) https://github.com/keyboardsurfer
2 | # Under CC-BY-SA V3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode)
3 |
4 | #Jenv file
5 | .java-version
6 |
7 | # built application files
8 | *.apk
9 | *.ap_
10 | *.jar
11 |
12 | # lint folder
13 | lint
14 |
15 | # files for the dex VM
16 | *.dex
17 |
18 | # Java class files
19 | *.class
20 |
21 | # generated files
22 | bin/
23 | gen/
24 | classes/
25 | gen-external-apklibs/
26 | javadoc/
27 | # maven output folder
28 | target
29 |
30 | # Local configuration file (sdk path, etc)
31 | local.properties
32 |
33 | # Eclipse project files
34 | .classpath
35 | .project
36 | .metadata
37 | .settings
38 |
39 | # IntelliJ files
40 | .idea
41 | *.iml
42 |
43 | # OSX files
44 | .DS_Store
45 | *.DS_Store
46 | clover/*
47 | # Windows files
48 | Thumbs.db
49 |
50 | # vi swap files
51 | *.swp
52 |
53 | # backup files
54 | *.bak
55 |
56 | # gradle directory
57 | .gradle
58 | #gradlew
59 | #gradlew.bat
60 | #gradle/
61 | !/gradle/**
62 | build/
63 |
64 | #for oh-my-zsh jira plugin (https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#jira)
65 | .jira-url
66 | atlassian-ide-plugin.xml
67 |
68 | .clover/
69 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 AppFoundry
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # Android NFC Library
2 |
3 |
4 | What you'll need when using this library :
5 |
6 | |Android | ver |
7 | |:-------------|:------:|
8 | | API| >=16|
9 |
10 |
11 | ## Quick start
12 |
13 | In order to get a quick demo running you could perform the following steps :
14 |
15 | * Add this to the repositories block :
16 |
17 | ``` groovy
18 | repositories {
19 | maven{
20 | url "http://maven.appfoundry.be"
21 | }
22 | }
23 | ```
24 | * Go to your project's `build.gradle` file, and change the dependencies block to match the following line of code there :
25 |
26 | ``` groovy
27 | compile 'be.appfoundry:nfc-lib:1.1'
28 | ```
29 |
30 | Now go to the created activity, and either
31 |
32 | * Implement [FGD] yourself
33 |
34 | ``` java
35 | public class MyActivity{
36 | private PendingIntent pendingIntent;
37 | private IntentFilter[] mIntentFilters;
38 | private String[][] mTechLists;
39 | private NfcAdapter mNfcAdapter;
40 |
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.activity_main);
44 | mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
45 | pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
46 | mIntentFilters = new IntentFilter[]{new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED)};
47 | mTechLists = new String[][]{new String[]{Ndef.class.getName()},
48 | new String[]{NdefFormatable.class.getName()}};
49 | }
50 | public void onResume(){
51 | super.onResume();
52 | if (mNfcAdapter != null) {
53 | mNfcAdapter.enableForegroundDispatch(this, pendingIntent, mIntentFilters, mTechLists);
54 | }
55 | }
56 | public void onPause(){
57 | super.onPause();
58 | if (mNfcAdapter != null)
59 | {
60 | mNfcAdapter.disableForegroundDispatch(this);
61 | }
62 | }
63 | }
64 |
65 | ```
66 | * Or extend from NfcActivity:
67 |
68 | ``` java
69 | public class MyActivity extends NfcActivity{
70 | protected void onCreate(Bundle savedInstanceState){
71 | super.onCreate(savedInstanceState);
72 | setContentView(R.layout.activity_main);
73 | }
74 | }
75 | ```
76 |
77 |
78 | * **In both cases, add the following to your AndroidManifest.xml file :**
79 | ``` xml
80 |
81 | ```
82 |
83 | ## Start Reading
84 |
85 | * Paste this in the activity if you're **extending our class** :
86 |
87 |
88 | ``` java
89 | @Override
90 | protected void onNewIntent(Intent intent) {
91 | super.onNewIntent(intent);
92 | for (String message : getNfcMessages()){
93 | Toast.makeText(this,message,Toast.LENGTH_SHORT).show();
94 | }
95 | }
96 | ```
97 |
98 | * Otherwise :
99 |
100 | ``` java
101 | @Override
102 | protected void onNewIntent(Intent intent) {
103 | super.onNewIntent(intent);
104 | SparseArray res = new NfcReadUtilityImpl().readFromTagWithSparseArray(intent);
105 | for (int i =0; i < res.size() ; i++ ) {
106 | Toast.makeText(this, res.valueAt(i), Toast.LENGTH_SHORT).show();
107 | }
108 | }
109 | ```
110 | * If you like the Map implementation more you might as well use :
111 |
112 | ``` java
113 | @Override
114 | protected void onNewIntent(Intent intent) {
115 | super.onNewIntent(intent);
116 | for (String message : new NfcReadUtilityImpl().readFromTagWithMap(intent).values()) {
117 | Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
118 | }
119 | }
120 | ```
121 |
122 | * Now you're able to read the NFC Tags as long as the library supports the data in it when held to your phone!
123 |
124 | ## Write to a tag
125 | * Let your activity implement `AsyncUiCallback`:
126 |
127 |
128 | ``` java
129 | @Override
130 | public void callbackWithReturnValue(Boolean result) {
131 | String message = result ? "Success" : "Failed!";
132 | Toast.makeText(this,message,Toast.LENGTH_SHORT).show();
133 | }
134 |
135 | @Override
136 | public void onProgressUpdate(Boolean... booleans) {
137 | Toast.makeText(this, booleans[0] ? "We started writing" : "We could not write!",Toast.LENGTH_SHORT).show();
138 | }
139 |
140 | @Override
141 | public void onError(Exception e) {
142 | Toast.makeText(this,e.getMessage(),Toast.LENGTH_SHORT).show();
143 | }
144 | ```
145 |
146 | * Create a field with an `AsyncOperationCallback` in the following way :
147 |
148 | ``` java
149 | AsyncOperationCallback mAsyncOperationCallback = new AsyncOperationCallback() {
150 |
151 | @Override
152 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
153 | return writeUtility.writeEmailToTagFromIntent("some@email.tld","Subject","Message",getIntent());
154 | }
155 | };
156 | ```
157 |
158 | * Override the `onNewIntent(Intent)` method in the following way :
159 |
160 | ``` java
161 | @Override
162 | protected void onNewIntent(Intent intent) {
163 | super.onNewIntent(intent);
164 | new WriteEmailNfcAsync(this,mAsyncOperationCallback).executeWriteOperation();
165 | }
166 | ```
167 | * If you hold a tag against the phone and it is NFC Enabled, your implementation of the methods will be executed.
168 |
169 | ## Android Beam
170 | * When extending our class, all you have to do in order to enable Android Beam is call the `enableBeam()` method.
171 | * This enables Android Beam
172 | * Provides a default implementation with a standard text
173 |
174 | * If you did not opt for extending, take a look at the [official docs], or the source code.
175 |
176 | [NFC Forum]:http://members.nfc-forum.org/specs/
177 | [FGD]:http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch
178 | [official docs]:http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#p2p
179 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * build.gradle
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
23 |
24 | buildscript {
25 | repositories {
26 | jcenter()
27 | maven{
28 | url "${repositoryUrl}"
29 | }
30 | maven {
31 | url 'https://maven.google.com/'
32 | name 'Google'
33 | }
34 | google()
35 | }
36 | dependencies {
37 | classpath 'com.android.tools.build:gradle:3.5.2'
38 | }
39 | }
40 |
41 | allprojects {
42 | repositories {
43 | jcenter()
44 | maven {
45 | url 'https://maven.google.com/'
46 | name 'Google'
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # gradle.properties
3 | # NfcLibrary project.
4 | #
5 | # Created by : Daneo van Overloop - 17/6/2014.
6 | #
7 | # The MIT License (MIT)
8 | #
9 | # Copyright (c) 2014 AppFoundry. All rights reserved.
10 | #
11 | # Permission is hereby granted, free of charge, to any person obtaining a copy
12 | # of this software and associated documentation files (the "Software"), to deal
13 | # in the Software without restriction, including without limitation the rights
14 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | # copies of the Software, and to permit persons to whom the Software is
16 | # furnished to do so, subject to the following conditions:
17 | #
18 | # The above copyright notice and this permission notice shall be included in all
19 | # copies or substantial portions of the Software.
20 | #
21 |
22 | # Project-wide Gradle settings.
23 |
24 | # IDE (e.g. Android Studio) users:
25 | # Settings specified in this file will override any Gradle settings
26 | # configured through the IDE.
27 |
28 | # For more details on how to configure your build environment visit
29 | # http://www.gradle.org/docs/current/userguide/build_environment.html
30 |
31 | # Specifies the JVM arguments used for the daemon process.
32 | # The setting is particularly useful for tweaking memory settings.
33 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
34 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
35 |
36 | # When configured, Gradle will run in incubating parallel mode.
37 | # This option should only be used with decoupled projects. More details, visit
38 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
39 | # org.gradle.parallel=true
40 | repositoryUrl=http://www.appfoundry.be/maven
41 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 07 09:10:58 CET 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/implementationApp/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | .DS_STORE
3 | *.iml
--------------------------------------------------------------------------------
/implementationApp/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * build.gradle
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | apply plugin: 'com.android.application'
23 | apply plugin: 'spoon'
24 |
25 | android {
26 | packagingOptions {
27 | exclude 'META-INF/LICENSE.txt'
28 | exclude 'META-INF/NOTICE.txt'
29 | exclude 'NOTICE'
30 | exclude 'LICENSE.txt'
31 | }
32 | compileSdkVersion 29
33 | buildToolsVersion '29.0.2'
34 |
35 | defaultConfig {
36 | applicationId "be.appfoundry.nfc.implementation"
37 | testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
38 | minSdkVersion 18
39 | targetSdkVersion 29
40 | versionCode 12
41 | versionName "1.2"
42 | }
43 | buildTypes {
44 | release {
45 | minifyEnabled false
46 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
47 | }
48 | debug {
49 | debuggable true
50 | jniDebuggable true
51 | minifyEnabled false
52 | }
53 | }
54 | configurations {
55 | provided
56 | }
57 | }
58 |
59 | buildscript {
60 | repositories {
61 | //maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
62 | jcenter()
63 | }
64 | dependencies {
65 | classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2'
66 | }
67 | }
68 |
69 | repositories{
70 | maven{
71 | url "http://maven.appfoundry.be"
72 | }
73 |
74 | maven {
75 | url "https://oss.sonatype.org/content/repositories/snapshots"
76 | }
77 | jcenter()
78 | }
79 | spoon {
80 | adbTimeout = 15
81 | failIfNoDeviceConnected = false
82 | }
83 |
84 | dependencies {
85 | implementation fileTree(dir: 'libs', include: ['*.jar'])
86 | implementation project(':nfclib')
87 | //compile 'be.appfoundry:nfc-lib:1.2'
88 |
89 | androidTestImplementation 'com.jakewharton.espresso:espresso:1.1-r3'
90 | androidTestImplementation 'com.squareup.spoon:spoon-client:1.7.1'
91 |
92 | implementation 'com.google.android.material:material:1.0.0'
93 | implementation 'javax.annotation:jsr250-api:1.0'
94 | }
--------------------------------------------------------------------------------
/implementationApp/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # gradle.properties
3 | # NfcLibrary project.
4 | #
5 | # Created by : Daneo van Overloop - 17/6/2014.
6 | #
7 | # The MIT License (MIT)
8 | #
9 | # Copyright (c) 2014 AppFoundry. All rights reserved.
10 | #
11 | # Permission is hereby granted, free of charge, to any person obtaining a copy
12 | # of this software and associated documentation files (the "Software"), to deal
13 | # in the Software without restriction, including without limitation the rights
14 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | # copies of the Software, and to permit persons to whom the Software is
16 | # furnished to do so, subject to the following conditions:
17 | #
18 | # The above copyright notice and this permission notice shall be included in all
19 | # copies or substantial portions of the Software.
20 | #
21 |
22 |
--------------------------------------------------------------------------------
/implementationApp/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /opt/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/implementationApp/src/androidTest/java/be/appfoundry/nfc/implementation/TestEmptyFieldsNfcActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * TestEmptyFieldsNfcActivity.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfc.implementation;
23 |
24 | import android.test.ActivityInstrumentationTestCase2;
25 | import android.widget.EditText;
26 |
27 | import com.google.android.apps.common.testing.ui.espresso.ViewInteraction;
28 | import com.squareup.spoon.Spoon;
29 |
30 | import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
31 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
32 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeText;
33 | import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.doesNotExist;
34 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
35 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
36 |
37 | /**
38 | * NfcLibrary by daneo
39 | * Created on 30/04/14.
40 | */
41 | public class TestEmptyFieldsNfcActivity extends ActivityInstrumentationTestCase2 {
42 |
43 | public TestEmptyFieldsNfcActivity() {
44 | super(MainActivity.class);
45 | }
46 |
47 | @Override
48 | public void setUp() throws Exception {
49 | super.setUp();
50 | getActivity();
51 | }
52 |
53 | public void testEmptyUriFieldNotDisplayingAfterClick() {
54 | makeEmpty(R.id.input_text_uri_target);
55 | emptyFieldNotDisplayingToast(R.id.btn_write_uri_nfc);
56 | }
57 |
58 | public void testEmptyGeoFieldNotDisplayingAfterClick() {
59 | makeEmpty(R.id.input_text_geo_lat_target);
60 | emptyFieldNotDisplayingToast(R.id.btn_write_geolocation_nfc);
61 | }
62 |
63 | public void testEmptyEmailFieldNotDisplayingAfterClick() {
64 | makeEmpty(R.id.input_text_email_target);
65 | emptyFieldNotDisplayingToast(R.id.btn_write_email_nfc);
66 | }
67 |
68 | public void testEmptySmsFieldNotDisplayingAfterClick() {
69 | makeEmpty(R.id.input_text_sms_target);
70 | emptyFieldNotDisplayingToast(R.id.btn_write_sms_nfc);
71 | }
72 |
73 |
74 | public void testEmptyBluetoothFieldNotDisplayingAfterClick() {
75 | final EditText editText = (EditText) getActivity().findViewById(R.id.input_text_bluetooth_address);
76 | editText.post(new Runnable() {
77 | @Override
78 | public void run() {
79 | editText.setText(null);
80 | }
81 | });
82 | emptyFieldNotDisplayingToast(R.id.btn_write_bluetooth_nfc);
83 | }
84 |
85 | public void testEmptyTelFieldNotDisplayingAfterClick() {
86 | makeEmpty(R.id.input_text_tel_target);
87 | emptyFieldNotDisplayingToast(R.id.btn_write_tel_nfc);
88 | }
89 |
90 |
91 | public void emptyFieldNotDisplayingToast(int id) {
92 | onView(withId(id)).perform(click());
93 |
94 | // Not able to check for Toast being displayed due to their async nature
95 |
96 | // onView(withText(R.string.no_input)).check(matches(isDisplayed()));
97 |
98 | checkProgressDialogNotShowing();
99 | makeScreenshot("end");
100 | }
101 |
102 | private ViewInteraction makeEmpty(int id) {
103 | makeScreenshot("init");
104 | return onView(withId(id)).perform(typeText(""));
105 | }
106 |
107 | private void makeScreenshot(String tag) {
108 | Spoon.screenshot(getActivity(), tag);
109 | }
110 |
111 | protected void checkProgressDialogNotShowing() {
112 | getInstrumentation().waitForIdleSync();
113 | onView(withText(getActivity().getString(R.string.progressdialog_waiting_for_tag))).check(doesNotExist());
114 |
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/implementationApp/src/androidTest/java/be/appfoundry/nfc/implementation/TestFilledFieldsNfcActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * TestFilledFieldsNfcActivity.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfc.implementation;
23 |
24 | import android.test.ActivityInstrumentationTestCase2;
25 | import android.widget.EditText;
26 |
27 | import com.squareup.spoon.Spoon;
28 |
29 |
30 | import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
31 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
32 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.pressImeActionButton;
33 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeText;
34 | import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
35 | import static com.google.android.apps.common.testing.ui.espresso.matcher.RootMatchers.withDecorView;
36 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
37 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
38 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
39 | import static org.hamcrest.CoreMatchers.not;
40 | import static org.hamcrest.core.Is.is;
41 |
42 | /**
43 | * NfcLibrary by daneo
44 | * Created on 14/04/14.
45 | */
46 | public class TestFilledFieldsNfcActivity extends ActivityInstrumentationTestCase2 {
47 |
48 | private static final String TAG = TestFilledFieldsNfcActivity.class.getSimpleName();
49 |
50 | public TestFilledFieldsNfcActivity() {
51 | super(MainActivity.class);
52 | }
53 |
54 | @Override
55 | public void setUp() throws Exception {
56 | super.setUp();
57 | getActivity();
58 | }
59 |
60 | public void testFilledUriFieldButtonClickShowsProgressDialog() throws Exception {
61 | //checkAndDismissBluetoothDialog();
62 | makeScreenshot("init");
63 | onView(withId(R.id.input_text_uri_target)).perform(typeText("google.be"));
64 | onView(withId(R.id.btn_write_uri_nfc)).perform(click());
65 | makeScreenshot("Showing_progressdialog");
66 | checkProgressDialogShowing();
67 | makeScreenshot("end");
68 | }
69 |
70 | public void testFilledGeoFieldButtonClickShowsProgressDialog() throws Exception {
71 | //checkAndDismissBluetoothDialog();
72 | makeScreenshot("init");
73 | onView(withId(R.id.input_text_geo_lat_target)).perform(typeText("50.2345323"));
74 | onView(withId(R.id.input_text_geo_long_target)).perform(typeText("50.2345323"));
75 | onView(withId(R.id.btn_write_geolocation_nfc)).perform(click());
76 | makeScreenshot("Showing_progressdialog");
77 | checkProgressDialogShowing();
78 | makeScreenshot("end");
79 | }
80 |
81 | public void testFilledEmailFieldButtonClickShowsProgressDialog() throws Exception {
82 | //checkAndDismissBluetoothDialog();
83 | makeScreenshot("init");
84 | onView(withId(R.id.input_text_email_target)).perform(typeText("daneo@derp.com"));
85 | onView(withId(R.id.btn_write_email_nfc)).perform(click());
86 | makeScreenshot("Showing_progressdialog");
87 | checkProgressDialogShowing();
88 | makeScreenshot("end");
89 | }
90 |
91 | public void testFilledSmsFieldButtonClickShowsProgressDialog() throws Exception {
92 | //checkAndDismissBluetoothDialog();
93 | makeScreenshot("init");
94 | onView(withId(R.id.input_text_sms_target)).perform(typeText("0123456789"));
95 | onView(withId(R.id.btn_write_sms_nfc)).perform(click());
96 | makeScreenshot("Showing_progressdialog");
97 | checkProgressDialogShowing();
98 | makeScreenshot("end");
99 | }
100 |
101 | //2131296269
102 | public void testFilledBluetoothMacAddressFieldButtonClickShowsProgressDialog() throws Exception {
103 | //checkAndDismissBluetoothDialog();
104 | makeScreenshot("init");
105 | final EditText text = (EditText) getActivity().findViewById(R.id.input_text_bluetooth_address);
106 |
107 | final String macAddress = "00:11:22:33:44";
108 |
109 | text.post(new Runnable() {
110 | @Override
111 | public void run() {
112 | text.setText(macAddress);
113 | }
114 | });
115 |
116 | makeScreenshot("Item_filled");
117 | onView(withId(R.id.input_text_bluetooth_address)).perform(click());
118 |
119 |
120 | // onView(withId(R.id.spinner_bluetooth_addresses)).perform(click(pressImeActionButton()));
121 | onView(withId(R.id.btn_write_bluetooth_nfc)).perform(click());
122 | makeScreenshot("Showing_progressdialog");
123 | checkProgressDialogShowing();
124 | makeScreenshot("end");
125 | }
126 |
127 | public void testFilledTelephoneFieldButtonClickShowsProgressDialog() throws Exception {
128 | //checkAndDismissBluetoothDialog();
129 | makeScreenshot("init");
130 | onView(withId(R.id.input_text_tel_target)).perform(typeText("0123456789"));
131 | onView(withId(R.id.btn_write_tel_nfc)).perform(click());
132 | checkProgressDialogShowing();
133 | }
134 |
135 | private void checkAndDismissBluetoothDialog() {
136 | onView(withText("Bluetooth"))
137 | .inRoot(withDecorView(not(is(getActivity().getWindow().getDecorView()))))
138 | .perform(click(pressImeActionButton()));
139 | }
140 |
141 | protected void checkProgressDialogShowing() {
142 | onView(withText(getActivity().getString(R.string.progressdialog_waiting_for_tag))).check(matches(isDisplayed()));
143 | }
144 |
145 | private void makeScreenshot(final String tag) {
146 | Spoon.screenshot(getActivity(),tag);
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/implementationApp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
33 |
34 |
35 |
36 |
37 |
43 |
44 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/implementationApp/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/implementationApp/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/implementationApp/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/implementationApp/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/implementationApp/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/implementationApp/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/implementationApp/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/implementationApp/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/implementationApp/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
27 |
28 |
31 |
32 |
40 |
41 |
46 |
47 |
53 |
54 |
60 |
61 |
66 |
67 |
72 |
73 |
79 |
80 |
85 |
86 |
91 |
92 |
98 |
99 |
104 |
105 |
111 |
112 |
117 |
118 |
124 |
125 |
126 |
127 |
132 |
133 |
139 |
140 |
145 |
146 |
151 |
152 |
158 |
159 |
163 |
164 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
--------------------------------------------------------------------------------
/implementationApp/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
31 |
--------------------------------------------------------------------------------
/implementationApp/src/main/res/menu/nfc.xml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
31 |
--------------------------------------------------------------------------------
/implementationApp/src/main/res/values-nl/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
24 |
25 | NfcLibrary Implementation
26 | Hello world!
27 | Settings
28 | NfcActivity
29 | Bluetooth is niet beschikbaar op dit toestel!
30 | Email template schrijven
31 | Standaard SMS schrijven
32 | Standaardlocatie schrijven
33 | Standaard URI schrijven
34 | Standaard telefoonnummer schrijven
35 | Bluetooth profiel schrijven
36 | Wachten …
37 | Raak tag aan om te schrijven
38 | You should give me something to write
39 |
40 |
--------------------------------------------------------------------------------
/implementationApp/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
23 |
26 | 64dp
27 |
28 |
--------------------------------------------------------------------------------
/implementationApp/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
23 |
24 | 16dp
25 | 16dp
26 |
27 |
28 |
--------------------------------------------------------------------------------
/implementationApp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
24 |
25 | NfcLibrary Implementation
26 | Hello world!
27 | Settings
28 | Bluetooth is not supported by this device!
29 | NfcActivity
30 | Write email
31 | Write an SMS
32 | Write Geolocation
33 | Write URI
34 | Write Tel
35 | Write Bluetooth MAC
36 | Waiting for tag…
37 | Tap tag to write…
38 | You should give me something to write
39 |
40 |
41 |
--------------------------------------------------------------------------------
/implementationApp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/nfclib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/nfclib/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * build.gradle
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | import com.android.builder.core.BuilderConstants
23 |
24 | apply plugin: 'com.android.library'
25 | //apply plugin: 'maven-publish'
26 | apply plugin: 'maven'
27 | apply plugin: 'signing'
28 |
29 | //publishing {
30 | // publications {
31 | // maven(MavenPublication) {
32 | // groupId 'be.idamediafoundry'
33 | // artifactId 'nfc-lib'
34 | // version '1.0'
35 | // pom.withXml {
36 | // asNode().appendNode('description', 'Library facilitating the use of NFC on the Android platform.' +
37 | // '')
38 | // }
39 | ////
40 | //// from components.java
41 | // }
42 | // }
43 | //}
44 |
45 | android {
46 | compileSdkVersion 29
47 | buildToolsVersion "29.0.2"
48 |
49 | defaultConfig {
50 | minSdkVersion 16
51 | targetSdkVersion 29
52 | versionCode 12
53 | versionName "1.2"
54 | }
55 | buildTypes {
56 | release {
57 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
58 | }
59 | debug {
60 | minifyEnabled false
61 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
62 | }
63 | }
64 | lintOptions {
65 | disable 'InvalidPackage'
66 | abortOnError false
67 | }
68 | }
69 |
70 | dependencies {
71 | implementation fileTree(dir: 'libs', include: ['*.jar'])
72 | implementation 'androidx.appcompat:appcompat:1.1.0'
73 | implementation 'com.intellij:annotations:12.0'
74 | }
75 |
76 | android.libraryVariants.all { variant ->
77 |
78 | task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
79 |
80 | //JavaDoc stuff
81 | description "Generates Javadoc for $variant.name."
82 | source = variant.javaCompile.source
83 | ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
84 | doFirst { classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) }
85 | String path = buildDir.absolutePath + ("/javadoc/javadoc-${variant.name}")
86 | File output_dir = new File(path)
87 |
88 | output_dir.mkdirs()
89 | destinationDir = output_dir
90 |
91 |
92 | // Packaging stuff
93 | def name = variant.buildType.name
94 | if (name == BuilderConstants.DEBUG) {
95 | return // Skip debug builds.
96 | }
97 | def task = project.tasks.create "jar${name.capitalize()}", Jar
98 | task.dependsOn variant.javaCompile
99 | task.from variant.javaCompile.destinationDir
100 | artifacts.add('archives', task)
101 | }
102 |
103 | }
104 |
105 |
106 | build.doLast {
107 | File javaDocDir = new File(buildDir.absolutePath + "/javadoc/")
108 | javaDocDir.deleteDir()
109 | tasks.findAll { it.name.startsWith("generate") && it.name.endsWith("Javadoc")}.each {
110 | it.execute()
111 | }
112 | }
113 |
114 | /**
115 | * Maven publishing info
116 | */
117 |
118 | signing {
119 | required { gradle.taskGraph.hasTask("uploadArchives") }
120 | sign configurations.archives
121 | }
122 | def coreAarFile = file('build/outputs/aar/nfclib.aar')
123 | artifacts {
124 | archives coreAarFile
125 | }
126 | uploadArchives {
127 | repositories {
128 | mavenDeployer {
129 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
130 |
131 | repository(url: "file:///Users/daneo/.m2/repository")
132 |
133 | pom.project {
134 | name 'AppFoundry\'s NFC Lib '
135 | groupId 'be.appfoundry'
136 | artifactId 'nfc-lib'
137 | packaging 'aar'
138 | version '1.0'
139 | organization {
140 | name 'AppFoundry'
141 | url 'http://www.appfoundry.be'
142 | }
143 | url 'http://dproductions.be/mvn'
144 | // optionally artifactId can be defined here
145 | description 'NFC Library meant to facilitate the use of NFC on the Android platform'
146 |
147 | //
148 | // scm {
149 | // connection 'scm:svn:http://foo.googlecode.com/svn/trunk/'
150 | // developerConnection 'scm:svn:https://foo.googlecode.com/svn/trunk/'
151 | // url 'http://foo.googlecode.com/svn/trunk/'
152 | // }
153 |
154 | developers {
155 | developer {
156 | id 'daneov'
157 | name 'Daneo van Overloop'
158 | roles{
159 | role 'developer'
160 | }
161 | organization {
162 | name 'AppFoundry'
163 | }
164 | email 'daneo.vanoverloop@ida-mediafoundry.be'
165 | }
166 | }
167 | }
168 | }
169 | }
170 | }
171 |
172 |
--------------------------------------------------------------------------------
/nfclib/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /opt/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/TestUtilities.java:
--------------------------------------------------------------------------------
1 | /*
2 | * TestUtilities.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities;
23 |
24 | import android.nfc.FormatException;
25 | import android.nfc.NdefMessage;
26 | import android.nfc.Tag;
27 | import android.nfc.tech.Ndef;
28 | import android.nfc.tech.NdefFormatable;
29 | import android.nfc.tech.TagTechnology;
30 | import android.os.Bundle;
31 | import android.os.Parcel;
32 |
33 | import org.jetbrains.annotations.NotNull;
34 |
35 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
36 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
37 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
38 | import be.appfoundry.nfclibrary.utilities.interfaces.NdefWrite;
39 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
40 | import be.appfoundry.nfclibrary.utilities.sync.NfcWriteUtilityImpl;
41 | import be.appfoundry.nfclibrary.utilities.sync.WriteUtilityImpl;
42 |
43 | /**
44 | * NfcLibrary by daneo
45 | * Created on 14/04/14.
46 | */
47 | public class TestUtilities {
48 |
49 | public static final String NDEF_FORMATABLE = "NDEF_FORMATABLE";
50 | public static final String NDEF = "NDEF";
51 | public NdefMessage resultMessage;
52 |
53 | public TestUtilities() {
54 | }
55 |
56 |
57 | public boolean checkResult(@NotNull String expected) {
58 | if (resultMessage == null)
59 | return false;
60 | byte[] payload = resultMessage.getRecords()[0].getPayload();
61 | if (checkPayloadHeader(NfcPayloadHeader.CUSTOM_SCHEME)) {
62 | return new String(payload).contains(expected);
63 | } else {
64 | return new String(payload, 1, payload.length - 1).contains(expected);
65 | }
66 | }
67 |
68 | public NfcWriteUtility mockNdefWriteUtility() {
69 | final NdefWrite ndefWrite = new NdefWrite() {
70 | @Override
71 | public boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
72 | resultMessage = message;
73 | return true;
74 | }
75 |
76 | @Override
77 | public boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
78 | resultMessage = message;
79 | return true;
80 | }
81 |
82 | @Override
83 | public boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException {
84 | return false;
85 | }
86 |
87 | @Override
88 | public boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException {
89 | return false;
90 | }
91 | };
92 | return getNfcWriteUtility(ndefWrite);
93 | }
94 |
95 | private NfcWriteUtilityImpl getNfcWriteUtility(NdefWrite ndefWrite) {
96 | return new NfcWriteUtilityImpl(new WriteUtilityImpl(ndefWrite));
97 | }
98 |
99 | public NfcWriteUtility mockNdefFormatableWrite() {
100 | final NdefWrite ndefWrite = new NdefWrite() {
101 | @Override
102 | public boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
103 | return false;
104 | }
105 |
106 | @Override
107 | public boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
108 | return false;
109 | }
110 |
111 | @Override
112 | public boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException {
113 | resultMessage = message;
114 | return true;
115 | }
116 |
117 | @Override
118 | public boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException {
119 | resultMessage = message;
120 | return true;
121 | }
122 | };
123 | return new NfcWriteUtilityImpl(new WriteUtilityImpl(ndefWrite)) {
124 | };
125 | }
126 |
127 | public Tag mockTag(String technology) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
128 | // For future reference
129 |
130 | // Parameters :
131 | byte[] b = {0x8};
132 | String ndefClass = "android.nfc.tech.Ndef";
133 |
134 | // FieldName which marks the capacity of the tag
135 | String extraNdefMaxlength = (String) Class.forName(ndefClass).getField("EXTRA_NDEF_MAXLENGTH").get(null);
136 |
137 | // FieldName which marks the tags writability
138 | String cardWritableStateField = (String) Class.forName(ndefClass).getField("EXTRA_NDEF_CARDSTATE").get(null);
139 |
140 | // Field to mark tag R/W
141 | int cardWritable = Class.forName(ndefClass).getField("NDEF_MODE_READ_WRITE").getInt(null);
142 |
143 | Bundle techExtras = new Bundle();
144 |
145 | techExtras.putInt(extraNdefMaxlength, 2048);
146 | techExtras.putInt(cardWritableStateField, cardWritable);
147 | Bundle[] extras = {techExtras};
148 | int[] technologies = {TagTechnology.class.getField(technology.toUpperCase()).getInt(null)}; //https://android.googlesource.com/platform/frameworks/base.git/+/android-4.3_r2/core/java/android/nfc/tech/TagTechnology.java
149 |
150 |
151 | // https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/nfc/Tag.java :376
152 | Parcel parcel = Parcel.obtain();
153 |
154 | parcel.writeByteArray(b); //Sets the ID
155 | parcel.writeIntArray(technologies); // Sets the technology to NDEF
156 | parcel.writeArray(extras); // Needed to set properties for NDEF tag
157 | parcel.writeInt(1); // Service handle
158 | parcel.writeInt(1); // Indicating a mock
159 |
160 | return Tag.CREATOR.createFromParcel(parcel);
161 | }
162 |
163 | @NotNull
164 | public NfcWriteUtility determineMockType(String technology) {
165 |
166 | return technology == null ? mockFailNdefWrite() : ( technology.equals(NDEF)) ? mockNdefWriteUtility() : mockNdefFormatableWrite();
167 |
168 | }
169 |
170 | public NfcWriteUtility mockFailNdefWrite() {
171 | return getNfcWriteUtility(new NdefWrite() {
172 | @Override
173 | public boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
174 | return false;
175 | }
176 |
177 | @Override
178 | public boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
179 | return false;
180 | }
181 |
182 | @Override
183 | public boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException {
184 | return false;
185 | }
186 |
187 | @Override
188 | public boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException {
189 | return false;
190 | }
191 | });
192 | }
193 |
194 | public boolean checkPayloadHeader(byte expectedHeader) {
195 | return resultMessage!= null && resultMessage.getRecords()[0].getPayload()[0] == expectedHeader;
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/async/AbstractFailsTestsAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * AbstractFailsTestsAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.nfc.FormatException;
25 | import android.os.HandlerThread;
26 | import android.test.InstrumentationTestCase;
27 |
28 | import java.util.concurrent.Semaphore;
29 |
30 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
31 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
32 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
33 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
34 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
35 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
36 | import be.appfoundry.nfclibrary.utilities.interfaces.AsyncNfcWriteOperation;
37 | import be.appfoundry.nfclibrary.utilities.async.WriteEmailNfcAsync;
38 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
39 |
40 | /**
41 | * NfcLibrary by daneo
42 | * Created on 30/05/14.
43 | */
44 | public class AbstractFailsTestsAsync extends InstrumentationTestCase {
45 | protected HandlerThread mHandlerThread;
46 | protected TestUtilities mTestUtilities = new TestUtilities();
47 | protected AsyncNfcWriteOperation mAsyncNfcWriteOperation;
48 | protected Semaphore mSemaphore;
49 |
50 | protected void performAsyncTaskWithReturnValue(AsyncUiCallback asyncUiCallback, NfcWriteUtility nfcWriteUtility, final boolean returnValue) throws InterruptedException {
51 | mSemaphore = new Semaphore(0);
52 |
53 | this.mAsyncNfcWriteOperation = new WriteEmailNfcAsync(asyncUiCallback,
54 | new AsyncOperationCallback() {
55 | @Override
56 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
57 | return returnValue;
58 | }
59 | }
60 | ,
61 | nfcWriteUtility
62 | );
63 |
64 | mHandlerThread.start();
65 | mSemaphore.acquire();
66 | }
67 |
68 | protected void performAsyncTaskWithReturnValue(AsyncUiCallback asyncUiCallback, AsyncOperationCallback asyncOperationCallback, NfcWriteUtility nfcWriteUtility) throws InterruptedException {
69 | mSemaphore = new Semaphore(0);
70 |
71 | this.mAsyncNfcWriteOperation = new WriteEmailNfcAsync(asyncUiCallback,
72 | asyncOperationCallback,
73 | nfcWriteUtility
74 | );
75 |
76 | // TODO : Thread in thread. mAsyncWriteOperation launches a thread on its own, so we lose control.
77 |
78 | //this.mAsyncNfcWriteOperation;
79 | mSemaphore.acquire();
80 | }
81 |
82 | protected boolean checkResult(String value) {
83 | return mTestUtilities.checkResult(value);
84 | }
85 |
86 | protected AsyncUiCallback getSucceedingAsyncUiCallback() {
87 | return new AsyncUiCallback() {
88 | @Override
89 | public void callbackWithReturnValue(Boolean result) {
90 | assertTrue(result);
91 | }
92 |
93 | @Override
94 | public void onProgressUpdate(Boolean... values) {
95 | assertTrue(values[0]);
96 | }
97 |
98 | @Override
99 | public void onError(Exception e) {
100 | fail(e.getMessage());
101 | }
102 | };
103 | }
104 |
105 | protected AsyncUiCallback getFailingAsyncUiCallback(){
106 | return new AsyncUiCallback() {
107 | @Override
108 | public void callbackWithReturnValue(Boolean result) {
109 | assertFalse(result);
110 | }
111 |
112 | @Override
113 | public void onProgressUpdate(Boolean... values) {
114 | assertTrue(values[0]);
115 | }
116 |
117 | @Override
118 | public void onError(Exception e) {
119 | fail(e.getMessage());
120 | }
121 | };
122 | }
123 | protected void release() {
124 | mSemaphore.release();
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/async/GenericTaskTestsAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * GenericTaskTestsAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NfcAdapter;
27 | import android.nfc.Tag;
28 | import android.os.HandlerThread;
29 | import android.util.Log;
30 |
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
34 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
35 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
36 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
37 |
38 | /**
39 | * NfcLibrary by daneo
40 | * Created on 28/05/14.
41 | */
42 | public class GenericTaskTestsAsync extends AbstractFailsTestsAsync {
43 |
44 | private static final String TAG = GenericTaskTestsAsync.class.getSimpleName();
45 |
46 | public GenericTaskTestsAsync() {
47 | mHandlerThread = new HandlerThread("Test") {
48 | @Override
49 | public void run() {
50 | if (mAsyncNfcWriteOperation != null) {
51 | mAsyncNfcWriteOperation.executeWriteOperation();
52 | } else {
53 | Log.d(TAG, "EmailAsync = null!");
54 | }
55 | release();
56 | }
57 | };
58 | }
59 |
60 | @Override
61 | protected void setUp() throws Exception {
62 | super.setUp();
63 | }
64 |
65 | public void testWriteFailedNdef() throws InterruptedException {
66 | performAsyncTaskWithReturnValue(getSucceedingAsyncUiCallback(), getFailingAsyncOperationCallback(), mTestUtilities.mockFailNdefWrite());
67 | assertFalse("Result was true!", checkResult("derp.com"));
68 | }
69 |
70 | public void testWriteFailedNdefFormatable() throws InterruptedException {
71 | performAsyncTaskWithReturnValue(getSucceedingAsyncUiCallback(), getFailingAsyncOperationCallback(), mTestUtilities.mockFailNdefWrite());
72 | assertFalse("Result was true!", checkResult("derp.com"));
73 | }
74 |
75 |
76 | public void testWriteSucceededNdef() throws InterruptedException, IllegalAccessException, NoSuchFieldException, ClassNotFoundException {
77 | performAsyncTaskWithReturnValue(getSucceedingAsyncUiCallback(), getSucceedingAsyncOperationCallback(), mTestUtilities.mockNdefWriteUtility());
78 | assertTrue("Result was false!", checkResult("derp.com"));
79 | }
80 |
81 | public void testWriteSucceededNdefFormatable() throws InterruptedException, IllegalAccessException, NoSuchFieldException, ClassNotFoundException {
82 | performAsyncTaskWithReturnValue(getSucceedingAsyncUiCallback(), getSucceedingAsyncOperationCallback(), mTestUtilities.mockNdefFormatableWrite());
83 | assertTrue("Result was false!", checkResult("derp.com"));
84 | }
85 |
86 |
87 | private AsyncOperationCallback getSucceedingAsyncOperationCallback() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException {
88 | final Tag mockTag = mTestUtilities.mockTag(TestUtilities.NDEF);
89 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
90 | return new AsyncOperationCallback() {
91 | @Override
92 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
93 | return true;
94 | }
95 | };
96 | }
97 |
98 | private AsyncOperationCallback getFailingAsyncOperationCallback() {
99 | return new AsyncOperationCallback() {
100 | @Override
101 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
102 | return false;
103 | }
104 | };
105 | }
106 |
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/sync/WriteEmailFailsTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteEmailFailsTests.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NfcAdapter;
27 | import android.nfc.Tag;
28 | import android.test.AndroidTestCase;
29 |
30 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
34 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * NfcLibrary by daneo
39 | * Created on 28/05/14.
40 | */
41 | public class WriteEmailFailsTests extends AndroidTestCase {
42 |
43 | private TestUtilities mTestUtilities = new TestUtilities();
44 |
45 |
46 | public void testWriteEmailFailedNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
47 | String email = "derpherp.com";
48 | final String ndef = TestUtilities.NDEF;
49 |
50 | performWriteAndChecks(email, ndef,false);
51 | }
52 |
53 |
54 |
55 | public void testWriteEmailReadonlyFailedNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
56 | String email = "derp@herp.com";
57 | final String ndef = TestUtilities.NDEF;
58 |
59 | performWriteAndChecks(email, ndef,true);
60 | }
61 |
62 | public void testWriteEmailFailNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
63 | String email = "derp@herp.com";
64 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
65 | performWriteAndChecks(email, ndefFormatable,false);
66 | }
67 |
68 | public void testWriteEmailReadonlyFailNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
69 | String email = "derp@herp.com";
70 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
71 | performWriteAndChecks(email, ndefFormatable,true);
72 | }
73 | private void performWriteAndChecks(String email, String ndef, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
74 | assertFalse(writeFailEmailToTag(email, ndef, readonly));
75 | assertFalse(mTestUtilities.checkResult(email));
76 | assertFalse(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.MAILTO));
77 | }
78 |
79 | boolean writeFailEmailToTag(String email, String technology, boolean readOnly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
80 | final Tag mockTag = mTestUtilities.mockTag(technology);
81 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
82 | NfcWriteUtility nfcWriteUtility = mTestUtilities.determineMockType(null);
83 | return readOnly ? nfcWriteUtility.makeOperationReadOnly().writeEmailToTagFromIntent(email, "", "", intent) : nfcWriteUtility.writeEmailToTagFromIntent(email, "", "", intent);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/sync/WriteEmailSucceedsTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteEmailSucceedsTests.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NfcAdapter;
27 | import android.nfc.Tag;
28 | import android.test.AndroidTestCase;
29 |
30 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
34 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * NfcLibrary by daneo
39 | * Created on 28/03/14.
40 | */
41 | public class WriteEmailSucceedsTests extends AndroidTestCase {
42 |
43 | private static final String TAG = "be.idamediafoundry.nfclibrary.implementationapp.NFCActivity";
44 |
45 | TestUtilities mTestUtilities = new TestUtilities();
46 |
47 | public WriteEmailSucceedsTests() {
48 | //super(NFCActivity.class);
49 | }
50 |
51 |
52 | /**
53 | * Sets up the tag for each test case
54 | *
55 | * @throws Exception
56 | */
57 | @Override
58 | protected void setUp() throws Exception {
59 | super.setUp();
60 |
61 | }
62 |
63 | // Email
64 | public void testWriteEmailNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
65 | String email = "derp@herp.com";
66 | assertTrue(writeEmailToTag(email, TestUtilities.NDEF, false));
67 |
68 | assertTrue(mTestUtilities.checkResult(email));
69 | assertTrue(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.MAILTO));
70 | }
71 |
72 |
73 | public void testWriteEmailReadonlyNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
74 | String email = "derp@herp.com";
75 | assertTrue(writeEmailToTag(email, TestUtilities.NDEF, true));
76 |
77 | assertTrue(mTestUtilities.checkResult(email));
78 | assertTrue(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.MAILTO));
79 | }
80 |
81 |
82 | public void testWriteEmailNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
83 | String email = "derp@herp.com";
84 | assertTrue(writeEmailToTag(email, TestUtilities.NDEF_FORMATABLE, false));
85 |
86 | assertTrue(mTestUtilities.checkResult(email));
87 | assertTrue(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.MAILTO));
88 | }
89 |
90 | public void testWriteEmailReadonlyNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
91 | String email = "derp@herp.com";
92 | assertTrue(writeEmailToTag(email, TestUtilities.NDEF_FORMATABLE, true));
93 |
94 | assertTrue(mTestUtilities.checkResult(email));
95 | assertTrue(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.MAILTO));
96 | }
97 |
98 | boolean writeEmailToTag(String email, String technology, boolean readOnly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
99 | final Tag mockTag = mTestUtilities.mockTag(technology);
100 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
101 | NfcWriteUtility nfcWriteUtility = mTestUtilities.determineMockType(technology);
102 | return nfcWriteUtility != null && (readOnly ? nfcWriteUtility.makeOperationReadOnly().writeEmailToTagFromIntent(email, "", "", intent) : nfcWriteUtility.writeEmailToTagFromIntent(email, "", "", intent));
103 | }
104 |
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/sync/WriteGeolocationFailsTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteGeolocationFailsTests.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NfcAdapter;
27 | import android.nfc.Tag;
28 | import android.test.AndroidTestCase;
29 |
30 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
34 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * NfcLibrary by daneo
39 | * Created on 14/04/14.
40 | */
41 | public class WriteGeolocationFailsTests extends AndroidTestCase {
42 | private TestUtilities mTestUtilities = new TestUtilities();
43 |
44 | // GeoLocation
45 | public void testWriteGeoLocationFailsNdef() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
46 | double latitude = 0, longitude = 0;
47 | final String ndef = TestUtilities.NDEF;
48 |
49 | performWriteAndChecks(latitude, longitude, ndef,false);
50 | }
51 |
52 | public void testWriteGeoLocationReadOnlyNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
53 | double latitude = 0, longitude = 0;
54 | final String ndef = TestUtilities.NDEF;
55 | performWriteAndChecks(latitude, longitude, ndef, true);
56 | }
57 |
58 | public void testWriteGeoLocationNdefFormatable() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
59 | double latitude = 0, longitude = 0;
60 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
61 | performWriteAndChecks(latitude, longitude, ndefFormatable,false);
62 | }
63 |
64 | public void testWriteGeoLocationReadOnlyNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
65 | double latitude = 0, longitude = 0;
66 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
67 | performWriteAndChecks(latitude, longitude, ndefFormatable, true);
68 | }
69 |
70 | private void performWriteAndChecks(double latitude, double longitude, String ndefFormatable,boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
71 | assertFalse(writeGeoLocation(latitude, longitude, ndefFormatable, false));
72 | assertFalse(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.CUSTOM_SCHEME));
73 | }
74 |
75 | boolean writeGeoLocation(Double latitude, Double longitude, String technology, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
76 | final Tag mockTag = mTestUtilities.mockTag(technology);
77 |
78 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
79 | NfcWriteUtility nfcMessageUtility = mTestUtilities.determineMockType(null);
80 |
81 | return (readonly ? nfcMessageUtility.makeOperationReadOnly().writeGeolocationToTagFromIntent(latitude, longitude, intent) : nfcMessageUtility.writeGeolocationToTagFromIntent(latitude, longitude, intent));
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/sync/WriteGeolocationSucceedsTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteGeolocationSucceedsTests.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NfcAdapter;
27 | import android.nfc.Tag;
28 | import android.test.AndroidTestCase;
29 |
30 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
34 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * NfcLibrary by daneo
39 | * Created on 14/04/14.
40 | */
41 | public class WriteGeolocationSucceedsTests extends AndroidTestCase {
42 | private TestUtilities mTestUtilities = new TestUtilities();
43 |
44 | // GeoLocation
45 | public void testWriteGeoLocationNdef() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
46 | double latitude = 0, longitude = 0;
47 | final String ndef = TestUtilities.NDEF;
48 |
49 | performWriteAndChecks(latitude, longitude, ndef, false);
50 | }
51 |
52 | public void testWriteGeoLocationReadOnlyNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
53 | double latitude = 0, longitude = 0;
54 | final String ndef = TestUtilities.NDEF;
55 | performWriteAndChecks(latitude, longitude, ndef,true);
56 | }
57 |
58 | public void testWriteGeoLocationNdefFormatable() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
59 | double latitude = 0, longitude = 0;
60 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
61 | performWriteAndChecks(latitude, longitude, ndefFormatable, false);
62 | }
63 |
64 | public void testWriteGeoLocationReadOnlyNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
65 | double latitude = 0, longitude = 0;
66 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
67 | performWriteAndChecks(latitude, longitude, ndefFormatable,true);
68 | }
69 |
70 | private void performWriteAndChecks(double latitude, double longitude, String ndef,boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
71 | assertTrue(writeGeoLocation(latitude, longitude, ndef, readonly));
72 | assertTrue(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.CUSTOM_SCHEME));
73 | }
74 |
75 | boolean writeGeoLocation(Double latitude, Double longitude, String technology, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
76 | final Tag mockTag = mTestUtilities.mockTag(technology);
77 |
78 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
79 | NfcWriteUtility nfcMessageUtility = mTestUtilities.determineMockType(technology);
80 |
81 | return (readonly ? nfcMessageUtility.makeOperationReadOnly().writeGeolocationToTagFromIntent(latitude, longitude, intent) : nfcMessageUtility.writeGeolocationToTagFromIntent(latitude, longitude, intent));
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/sync/WritePhoneFailsTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WritePhoneFailsTests.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NfcAdapter;
27 | import android.nfc.Tag;
28 | import android.test.AndroidTestCase;
29 |
30 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
34 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * NfcLibrary by daneo
39 | * Created on 14/04/14.
40 | */
41 | public class WritePhoneFailsTests extends AndroidTestCase {
42 |
43 | private TestUtilities mTestUtilities = new TestUtilities();
44 |
45 | // Telephone
46 | public void testWriteTelephoneNdef() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
47 | String phoneNumber = "0123456789";
48 | final String ndef = TestUtilities.NDEF;
49 | performWriteAndChecks(phoneNumber, ndef, false);
50 | }
51 |
52 | public void testWriteTelephoneReadOnlyNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
53 | String phoneNumber = "0123456789";
54 | final String ndef = TestUtilities.NDEF;
55 | performWriteAndChecks(phoneNumber, ndef,true);
56 | }
57 |
58 | public void testWriteTelephoneNdefFormatable() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
59 | String phoneNumber = "0123456789";
60 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
61 | performWriteAndChecks(phoneNumber, ndefFormatable, false);
62 | }
63 |
64 | public void testWriteTelephoneReadOnlyNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
65 | String phoneNumber = "0123456789";
66 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
67 | performWriteAndChecks(phoneNumber, ndefFormatable,true);
68 | }
69 |
70 | private void performWriteAndChecks(String phoneNumber, String ndefFormatable,boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
71 | assertFalse(writePhoneNumber(phoneNumber, ndefFormatable, readonly));
72 | assertFalse(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.TEL));
73 | }
74 |
75 | boolean writePhoneNumber(String phoneNumber, String technology, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
76 | final Tag mockTag = mTestUtilities.mockTag(technology);
77 |
78 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG,mockTag);
79 | NfcWriteUtility nfcMessageUtility = mTestUtilities.determineMockType(null);
80 |
81 | return nfcMessageUtility != null && (readonly ? nfcMessageUtility.makeOperationReadOnly().writeTelToTagFromIntent(phoneNumber, intent) : nfcMessageUtility.writeTelToTagFromIntent(phoneNumber, intent));
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/sync/WritePhoneSucceedsTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WritePhoneSucceedsTests.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NfcAdapter;
27 | import android.nfc.Tag;
28 | import android.test.AndroidTestCase;
29 |
30 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
34 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * NfcLibrary by daneo
39 | * Created on 14/04/14.
40 | */
41 | public class WritePhoneSucceedsTests extends AndroidTestCase {
42 |
43 | private TestUtilities mTestUtilities = new TestUtilities();
44 |
45 | // Telephone
46 | public void testWriteTelephoneNdef() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
47 | String phoneNumber = "0123456789";
48 | final String ndef = TestUtilities.NDEF;
49 | performWriteAndChecks(phoneNumber, ndef, false);
50 | }
51 |
52 | public void testWriteTelephoneReadOnlyNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
53 | String phoneNumber = "0123456789";
54 | final String ndef = TestUtilities.NDEF;
55 | performWriteAndChecks(phoneNumber, ndef,true);
56 | }
57 |
58 | public void testWriteTelephoneNdefFormatable() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
59 | String phoneNumber = "0123456789";
60 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
61 | performWriteAndChecks(phoneNumber, ndefFormatable, false);
62 | }
63 |
64 | public void testWriteTelephoneReadOnlyNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
65 | String phoneNumber = "0123456789";
66 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
67 | performWriteAndChecks(phoneNumber, ndefFormatable,true);
68 | }
69 |
70 | private void performWriteAndChecks(String phoneNumber, String ndefFormatable,boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
71 | assertTrue(writePhoneNumber(phoneNumber, ndefFormatable, readonly));
72 | assertTrue(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.TEL));
73 | }
74 |
75 | boolean writePhoneNumber(String phoneNumber, String technology, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
76 | final Tag mockTag = mTestUtilities.mockTag(technology);
77 |
78 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG,mockTag);
79 | NfcWriteUtility nfcMessageUtility = mTestUtilities.determineMockType(technology);
80 |
81 | return nfcMessageUtility != null && (readonly ? nfcMessageUtility.makeOperationReadOnly().writeTelToTagFromIntent(phoneNumber, intent) : nfcMessageUtility.writeTelToTagFromIntent(phoneNumber, intent));
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/sync/WriteUriFailsTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteUriFailsTests.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NfcAdapter;
27 | import android.nfc.Tag;
28 | import android.test.AndroidTestCase;
29 |
30 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
34 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * NfcLibrary by daneo
39 | * Created on 14/04/14.
40 | */
41 | public class WriteUriFailsTests extends AndroidTestCase {
42 |
43 | private TestUtilities mTestUtilities = new TestUtilities();
44 |
45 | // Uri
46 | public void testWriteUriNdef() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
47 | String uri = "http://www.derp.com";
48 | final String ndef = TestUtilities.NDEF;
49 | performWriteAndChecks(uri, ndef, false);
50 | }
51 |
52 | public void testWriteUriReadOnlyNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
53 | String uri = "http://www.derp.com";
54 | final String ndef = TestUtilities.NDEF;
55 | performWriteAndChecks(uri, ndef, true);
56 | }
57 |
58 | public void testWriteUriNdefFormatable() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
59 | String uri = "http://www.derp.com";
60 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
61 | performWriteAndChecks(uri, ndefFormatable, false);
62 | }
63 |
64 | public void testWriteUriReadOnlyNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
65 | String uri = "http://www.derp.com";
66 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
67 | performWriteAndChecks(uri, ndefFormatable, true);
68 | }
69 |
70 | private void performWriteAndChecks(String uri, String ndefFormatable, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
71 | assertFalse(writeUri(uri, ndefFormatable, readonly));
72 | assertFalse(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.HTTP_WWW));
73 | }
74 |
75 | public void testWriteUriFtpNdef() throws IllegalAccessException, FormatException, TagNotPresentException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException {
76 | String uri = "derp.com";
77 | final String ndef = TestUtilities.NDEF;
78 | assertFalse(writeUriCustomHeader(uri, ndef, NfcPayloadHeader.HTTP, false));
79 | }
80 |
81 | boolean writeUri(String uri, String technology, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
82 | final Tag mockTag = mTestUtilities.mockTag(technology);
83 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
84 | NfcWriteUtility nfcWriteUtility = mTestUtilities.determineMockType(technology);
85 |
86 | return writeUriCustomHeader(uri, technology, NfcPayloadHeader.HTTP_WWW, false);
87 | }
88 |
89 | boolean writeUriCustomHeader(String uri, String technology, byte header, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
90 | final Tag mockTag = mTestUtilities.mockTag(technology);
91 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
92 | NfcWriteUtility nfcWriteUtility = mTestUtilities.determineMockType(null);
93 |
94 | return nfcWriteUtility != null && (readonly ? nfcWriteUtility.makeOperationReadOnly().writeUriWithPayloadToTagFromIntent(uri, header, intent) : nfcWriteUtility.writeUriWithPayloadToTagFromIntent(uri, header, intent));
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/nfclib/src/androidTest/java/be/appfoundry/nfclibrary/utilities/sync/WriteUriSucceedsTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteUriSucceedsTests.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NfcAdapter;
27 | import android.nfc.Tag;
28 | import android.test.AndroidTestCase;
29 |
30 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
34 | import be.appfoundry.nfclibrary.utilities.TestUtilities;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * NfcLibrary by daneo
39 | * Created on 14/04/14.
40 | */
41 | public class WriteUriSucceedsTests extends AndroidTestCase {
42 |
43 | private TestUtilities mTestUtilities = new TestUtilities();
44 |
45 | // Uri
46 | public void testWriteUriNdef() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
47 | String uri = "http://www.derp.com";
48 | final String ndef = TestUtilities.NDEF;
49 | assertTrue(writeUri(uri, ndef, false));
50 | assertTrue(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.HTTP_WWW));
51 | }
52 |
53 | public void testWriteUriReadOnlyNdef() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
54 | String uri = "http://www.derp.com";
55 | final String ndef = TestUtilities.NDEF;
56 | performWriteAndChecks(uri, ndef);
57 | }
58 |
59 | public void testWriteUriNdefFormatable() throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
60 | String uri = "http://www.derp.com";
61 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
62 | assertTrue(writeUri(uri, ndefFormatable, false));
63 | assertTrue(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.HTTP_WWW));
64 | }
65 |
66 | public void testWriteUriReadOnlyNdefFormatable() throws IllegalAccessException, FormatException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException, TagNotPresentException {
67 | String uri = "http://www.derp.com";
68 | final String ndefFormatable = TestUtilities.NDEF_FORMATABLE;
69 | performWriteAndChecks(uri, ndefFormatable);
70 | }
71 |
72 | private void performWriteAndChecks(String uri, String ndefFormatable) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
73 | assertTrue(writeUri(uri, ndefFormatable, true));
74 | assertTrue(mTestUtilities.checkPayloadHeader(NfcPayloadHeader.HTTP_WWW));
75 | }
76 |
77 | public void testWriteUriFtpNdef() throws IllegalAccessException, FormatException, TagNotPresentException, ClassNotFoundException, ReadOnlyTagException, InsufficientCapacityException, NoSuchFieldException {
78 | String uri = "derp.com";
79 | final String ndef = TestUtilities.NDEF;
80 | assertTrue(writeUriCustomHeader(uri, ndef,NfcPayloadHeader.HTTP,false));
81 | }
82 |
83 | boolean writeUri(String uri, String technology, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
84 | final Tag mockTag = mTestUtilities.mockTag(technology);
85 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
86 | NfcWriteUtility nfcWriteUtility = mTestUtilities.determineMockType(technology);
87 |
88 | return writeUriCustomHeader(uri,technology,NfcPayloadHeader.HTTP_WWW,false);
89 | }
90 |
91 | boolean writeUriCustomHeader(String uri, String technology, byte header, boolean readonly) throws IllegalAccessException, NoSuchFieldException, ClassNotFoundException, InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException {
92 | final Tag mockTag = mTestUtilities.mockTag(technology);
93 | final Intent intent = new Intent().putExtra(NfcAdapter.EXTRA_TAG, mockTag);
94 | NfcWriteUtility nfcWriteUtility = mTestUtilities.determineMockType(technology);
95 |
96 | return nfcWriteUtility != null && (readonly ? nfcWriteUtility.makeOperationReadOnly().writeUriWithPayloadToTagFromIntent(uri, header, intent) : nfcWriteUtility.writeUriWithPayloadToTagFromIntent(uri, header, intent));
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/nfclib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/constants/NfcPayloadHeader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NfcPayloadHeader.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.constants;
23 |
24 | /**
25 | * Class containing all payload headers which can be currently used according to the NFC Forum's specification.
26 | * This is done to allow the library user to specify the needed type.
27 | * @author Daneo Van Overloop
28 | * NfcLibrary
29 | * Created on 08/04/14.
30 | */
31 | public class NfcPayloadHeader {
32 |
33 | public static final byte CUSTOM_SCHEME = 0x00;
34 | /**
35 | * This URI is in the format of http://www.
36 | */
37 | public static final byte HTTP_WWW = 0x01;
38 | /**
39 | * This URI is in the format of https://www.
40 | */
41 | public static final byte HTTPS_WWW = 0x02;
42 | /**
43 | * This URI is in the format of http://.
44 | */
45 | public static final byte HTTP = 0x03;
46 | /**
47 | * This URI is in the format of https://.
48 | */
49 | public static final byte HTTPS = 0x04;
50 | /**
51 | * This URI is in the format of tel:
52 | */
53 | public static final byte TEL = 0x05;
54 | /**
55 | * This URI is in the format of mailto:.
56 | */
57 | public static final byte MAILTO = 0x06;
58 | /**
59 | * This URI is in the format of ftp://anonymous:anonymous@
60 | */
61 | public static final byte FTP_ANONYMOUS = 0x07;
62 | /**
63 | * This URI is in the format of ftp://ftp.
64 | */
65 | public static final byte FTP_URI = 0x08;
66 | /**
67 | * This URI is in the format of ftps://
68 | */
69 | public static final byte FTPS = 0x09;
70 | /**
71 | * This URI is in the format of sftp://
72 | */
73 | public static final byte SFTP = 0x0A;
74 | /**
75 | * This URI is in the format of smb://
76 | */
77 | public static final byte SMB = 0x0B;
78 | /**
79 | * This URI is in the format of nfs://
80 | */
81 | public static final byte NFS = 0x0C;
82 | /**
83 | * This URI is in the format of ftp://
84 | */
85 | public static final byte FTP = 0x0D;
86 | /**
87 | * This URI is in the format of dav://
88 | */
89 | public static final byte DAV = 0x0E;
90 | /**
91 | * This URI is in the format of news://
92 | */
93 | public static final byte NEWS = 0x0F;
94 | /**
95 | * This URI is in the format of telnet://
96 | */
97 | public static final byte TELNET = 0x10;
98 | /**
99 | * This URI is in the format of imap:
100 | */
101 | public static final byte IMAP = 0x11;
102 | /**
103 | * This URI is in the format of rtsp://.
104 | */
105 | public static final byte RTSP = 0x12;
106 | /**
107 | * This URI is in the format of urn:
108 | */
109 | public static final byte URN = 0x13;
110 | /**
111 | * This URI is in the format of pop:
112 | */
113 | public static final byte POP = 0x14;
114 | /**
115 | * This URI is in the format of sip:
116 | */
117 | public static final byte SIP = 0x15;
118 | /**
119 | * This URI is in the format of sips:
120 | */
121 | public static final byte SIPS = 0x16;
122 | /**
123 | * This URI is in the format of tftp:
124 | */
125 | public static final byte TFTP = 0x17;
126 | /**
127 | * This URI is in the format of btspp://
128 | */
129 | public static final byte BT_SPP = 0x18;
130 | /**
131 | * This URI is in the format of bt12cap://.
132 | */
133 | public static final byte BT_12CAP = 0x19;
134 | /**
135 | * This URI is in the format of btgoep://.
136 | */
137 | public static final byte BT_GOEP = 0x1A;
138 | /**
139 | * This URI is in the format of tcpobex://
140 | */
141 | public static final byte TCP_OBEX = 0x1B;
142 | /**
143 | * This URI is in the format of irdaobex://
144 | */
145 | public static final byte IRDA_OBEX = 0x1C;
146 | /**
147 | * This URI is in the format of file://
148 | */
149 | public static final byte FILE = 0x1D;
150 | /**
151 | * This URI is in the format of urn:epc:id:
152 | */
153 | public static final byte URN_EPC_ID = 0x1E;
154 | /**
155 | * This URI is in the format of urn:epc:tag:
156 | */
157 | public static final byte URN_EPC_TAG = 0x1F;
158 |
159 | /**
160 | * This URI is in the format of urn:epc:pat:
161 | */
162 | public static final byte URN_EPC_PAT = 0x20;
163 |
164 | /**
165 | * This URI is in the format of urn:epc:raw:
166 | */
167 | public static final byte URN_EPC_RAW = 0x21;
168 |
169 | /**
170 | * This URI is in the format of urn:epc:
171 | */
172 | public static final byte URN_EPC = 0x22;
173 |
174 | /**
175 | * This URI is in the format of urn:nfc:
176 | */
177 | public static final byte URN_NFC = 0x23;
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/constants/NfcType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NfcType.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.constants;
23 |
24 | /**
25 | * Holding Android Application Record Types
26 | * @author Daneo Van Overloop
27 | * NfcLibrary
28 | * Created on 16/04/14.
29 | */
30 | public class NfcType {
31 |
32 | /**
33 | * Type for the Bluetooth Application Record
34 | */
35 | public static final byte[] BLUETOOTH_AAR = "application/vnd.bluetooth.ep.oob".getBytes();
36 | }
37 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/InsufficientCapacityException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * InsufficientCapacityException.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.exceptions;
23 |
24 | /**
25 | * @author Daneo Van Overloop
26 | * NfcLibrary
27 | * Created on 31/03/14.
28 | */
29 | public class InsufficientCapacityException extends Exception {
30 |
31 | public InsufficientCapacityException() {
32 | }
33 |
34 | public InsufficientCapacityException(String message) {
35 | super(message);
36 | }
37 |
38 | public InsufficientCapacityException(StackTraceElement[] stackTraceElements) {
39 | setStackTrace(stackTraceElements);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/ReadOnlyTagException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * ReadOnlyTagException.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.exceptions;
23 |
24 | /**
25 | * @author Daneo Van Overloop
26 | * NfcLibrary
27 | * Created on 31/03/14.
28 | */
29 | public class ReadOnlyTagException extends TagNotWritableException {
30 |
31 | public ReadOnlyTagException() {
32 | }
33 |
34 | public ReadOnlyTagException(String message) {
35 | super(message);
36 | }
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/TagNotPresentException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * TagNotPresentException.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.exceptions;
23 |
24 | /**
25 | * @author Daneo Van Overloop
26 | * NfcLibrary
27 | * Created on 28/03/14.
28 | */
29 | public class TagNotPresentException extends Exception {
30 |
31 | public TagNotPresentException(){
32 | super("Intent does not contain a tag");
33 | }
34 |
35 | public TagNotPresentException(String message){
36 | super(message);
37 | }
38 |
39 | public TagNotPresentException(Exception e){
40 | this.setStackTrace(e.getStackTrace());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/TagNotWritableException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * TagNotWritableException.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.exceptions;
23 |
24 | /**
25 | * Exception created when a tag cannot be written to
26 | * @author Daneo Van Overloop
27 | * NfcLibrary
28 | * Created on 27/03/14.
29 | */
30 | public class TagNotWritableException extends Exception {
31 |
32 | public TagNotWritableException(){}
33 | public TagNotWritableException(String message) {
34 | super();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/tasks/GenericTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * GenericTask.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.tasks;
23 |
24 | import android.os.AsyncTask;
25 | import android.util.Log;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 |
29 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
30 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
31 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
32 | import be.appfoundry.nfclibrary.utilities.sync.NfcWriteUtilityImpl;
33 |
34 | /**
35 | * AsyncTask providing the implementation of a task according to the 2 interfaces in {@link be.appfoundry.nfclibrary.tasks.interfaces}
36 | * @author Daneo Van Overloop
37 | * NfcLibrary
38 | * Created on 18/04/14.
39 | */
40 | public class GenericTask extends AsyncTask {
41 |
42 | private static final String TAG = GenericTask.class.getSimpleName();
43 | private final NfcWriteUtility mNfcWriteUtility;
44 |
45 | private AsyncUiCallback mAsyncUiCallback;
46 | private AsyncOperationCallback mAsyncOperationCallback;
47 | private Exception error;
48 |
49 | /**
50 | * @param asyncUiCallback
51 | * callback executed on UI thread
52 | * @param asyncOperationCallback
53 | * callback to be executed in the background
54 | *
55 | * @throws java.lang.NullPointerException
56 | * if (asyncOperationCallback == null)
57 | */
58 | public GenericTask(AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback) {
59 | mAsyncUiCallback = asyncUiCallback;
60 | mAsyncOperationCallback = asyncOperationCallback;
61 | mNfcWriteUtility = new NfcWriteUtilityImpl();
62 | }
63 |
64 | /**
65 | * @param nfcWriteUtility
66 | * to be passed to the asyncOperationCallback
67 | *
68 | * @throws java.lang.NullPointerException
69 | * if (nfcWriteUtility == null)
70 | * @see #GenericTask(be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback, be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback)
71 | */
72 | public GenericTask(AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback, @NotNull NfcWriteUtility nfcWriteUtility) {
73 | mAsyncUiCallback = asyncUiCallback;
74 | mAsyncOperationCallback = asyncOperationCallback;
75 | mNfcWriteUtility = nfcWriteUtility;
76 | }
77 |
78 | /**
79 | * Job to be done in the background.
80 | * Any error is rerouted to {@link #onPostExecute(Boolean)}, and hence to the callback onError()
81 | * @param params
82 | * @return AsyncOperationCallback.performWrite() == true
83 | */
84 | @Override
85 | protected Boolean doInBackground(Void... params) {
86 | Log.d(TAG, "Writing ..");
87 |
88 | boolean res = false;
89 | try {
90 | publishProgress(true);
91 | if (mAsyncOperationCallback != null) {
92 | res = mAsyncOperationCallback.performWrite(mNfcWriteUtility);
93 | } else {
94 | error = new NullPointerException("OperationCallback is null");
95 | }
96 |
97 | } catch (Exception e) {
98 | Log.w(TAG, e);
99 | mAsyncUiCallback.onError(e);
100 | error = e;
101 | }
102 |
103 | // Remove tag from intent in order to prevent writing to a not present tag
104 | return res;
105 | }
106 |
107 |
108 | @Override
109 | protected void onPreExecute() {
110 | super.onPreExecute();
111 | }
112 |
113 | /**
114 | * Fire the callbackWithReturnValue.
115 | * If the error != null then onError is executed as well.
116 | * @param result
117 | */
118 | @Override
119 | protected void onPostExecute(Boolean result) {
120 | super.onPostExecute(result);
121 | if (mAsyncOperationCallback != null && mAsyncUiCallback != null) {
122 | if (error != null) {
123 | mAsyncUiCallback.onError(error);
124 | }
125 | mAsyncUiCallback.callbackWithReturnValue(result);
126 | }
127 | }
128 |
129 | @Override
130 | protected void onProgressUpdate(Boolean... values) {
131 | super.onProgressUpdate(values);
132 | if (mAsyncUiCallback != null) {
133 | mAsyncUiCallback.onProgressUpdate(values);
134 | }
135 | }
136 |
137 | }
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/tasks/interfaces/AsyncOperationCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * AsyncOperationCallback.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.tasks.interfaces;
23 |
24 | import android.nfc.FormatException;
25 |
26 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
27 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
28 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
29 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
30 |
31 | /**
32 | * Interface providing the ability to perform an operation in the background
33 | * @author Daneo Van Overloop
34 | * NfcLibrary
35 | * Created on 22/04/14.
36 | */
37 | public interface AsyncOperationCallback {
38 |
39 | /**
40 | * Executed on background thread, do NOT perform any UI logic here !
41 | * @return
42 | */
43 |
44 | boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException;
45 | }
46 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/tasks/interfaces/AsyncUiCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * AsyncUiCallback.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.tasks.interfaces;
23 |
24 | /**
25 | * Interface providing callback methods which are ensured to be executed on the UI thread.
26 | * @author Daneo Van Overloop
27 | * NfcLibrary
28 | * Created on 18/04/14.
29 | */
30 | public interface AsyncUiCallback {
31 |
32 | /**
33 | * Used to deliver the result of the operation.
34 | * @param result of the operation
35 | */
36 | void callbackWithReturnValue(Boolean result);
37 |
38 | /**
39 | * Used to signal current state of the task.
40 | * @param values containing the state in values[0]
41 | */
42 | void onProgressUpdate(Boolean... values);
43 |
44 | /**
45 | * When any error occurs, the error is passed here.
46 | * @param e the cause of the task to stopping or malfunctioning
47 | */
48 | void onError(Exception e);
49 | }
50 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/async/AbstractNfcAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * AbstractNfcAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.content.Intent;
25 | import android.os.AsyncTask;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 | import org.jetbrains.annotations.Nullable;
29 |
30 | import be.appfoundry.nfclibrary.tasks.GenericTask;
31 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
32 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
33 | import be.appfoundry.nfclibrary.utilities.interfaces.AsyncNfcWriteOperation;
34 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
35 |
36 | /**
37 | * Class utilizing a {@link be.appfoundry.nfclibrary.tasks.GenericTask} to write async
38 | * @author Daneo Van Overloop
39 | * NfcLibrary
40 | */
41 | public abstract class AbstractNfcAsync implements AsyncNfcWriteOperation {
42 |
43 | protected NfcWriteUtility mNfcWriteUtility;
44 |
45 | protected AsyncOperationCallback mAsyncOperationCallback;
46 | protected AsyncUiCallback mAsyncUiCallback;
47 |
48 | /**
49 | * @param asyncUiCallback
50 | * callback executed on the UI thread
51 | */
52 | public AbstractNfcAsync(final AsyncUiCallback asyncUiCallback) {
53 | setAsyncUiCallback(asyncUiCallback);
54 | }
55 |
56 | /**
57 | * @param nfcWriteUtility
58 | * implementation of {@link be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility} to use
59 | *
60 | * @see #AbstractNfcAsync(be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback)
61 | */
62 | public AbstractNfcAsync(final AsyncUiCallback asyncUiCallback, NfcWriteUtility nfcWriteUtility) {
63 | setAsyncUiCallback(asyncUiCallback);
64 | setNfcWriteUtility(nfcWriteUtility);
65 | }
66 |
67 | /**
68 | * @param asyncOperationCallback
69 | * callback executed on a background thread
70 | *
71 | * @see #AbstractNfcAsync(be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback)
72 | */
73 | public AbstractNfcAsync(final @Nullable AsyncUiCallback asyncUiCallback, final @NotNull AsyncOperationCallback asyncOperationCallback) {
74 | this(asyncUiCallback);
75 | setAsyncOperationCallback(asyncOperationCallback);
76 | }
77 |
78 | /**
79 | * Constructor taking an AsyncUI-, AsyncOperationCallback and an {@link be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility}
80 | *
81 | * @param nfcWriteUtility
82 | * implementation of {@link be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility} to use
83 | *
84 | * @see #AbstractNfcAsync(be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback, be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback)
85 | */
86 | public AbstractNfcAsync(final @Nullable AsyncUiCallback asyncUiCallback, final @NotNull AsyncOperationCallback asyncOperationCallback, final @NotNull NfcWriteUtility nfcWriteUtility) {
87 | this(asyncUiCallback, nfcWriteUtility);
88 | setAsyncOperationCallback(asyncOperationCallback);
89 | }
90 |
91 | protected AsyncUiCallback getAsyncUiCallback() {
92 | return mAsyncUiCallback;
93 | }
94 |
95 | protected void setAsyncUiCallback(AsyncUiCallback asyncUiCallback) {
96 | mAsyncUiCallback = asyncUiCallback;
97 | }
98 |
99 | protected AsyncOperationCallback getAsyncOperationCallback() {
100 | return mAsyncOperationCallback;
101 | }
102 |
103 | protected void setAsyncOperationCallback(AsyncOperationCallback asyncOperationCallback) {
104 | mAsyncOperationCallback = asyncOperationCallback;
105 | }
106 |
107 | protected NfcWriteUtility getNfcWriteUtility() {
108 | return mNfcWriteUtility;
109 | }
110 |
111 | protected void setNfcWriteUtility(NfcWriteUtility nfcWriteUtility) {
112 | mNfcWriteUtility = nfcWriteUtility;
113 | }
114 |
115 | /**
116 | * Creates an async task with the current {@link #getAsyncOperationCallback()} as action
117 | *
118 | * @throws java.lang.NullPointerException
119 | * if {@link #getAsyncOperationCallback()} is null
120 | * @see AsyncNfcWriteOperation#executeWriteOperation()
121 | */
122 | @Override
123 | public void executeWriteOperation() {
124 | if (getNfcWriteUtility() != null) {
125 | new GenericTask(mAsyncUiCallback, getAsyncOperationCallback(), getNfcWriteUtility()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
126 | } else {
127 | new GenericTask(mAsyncUiCallback, getAsyncOperationCallback()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
128 | }
129 | }
130 |
131 | /**
132 | * Convenience method making it possible not to define an {@link be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback} at construction time but rather pass arguments and let the implementation handle it
133 | * Should set the AsyncOperationCallback, and then call {@link #executeWriteOperation()}
134 | *
135 | * @param intent
136 | * to be passed to the write utility
137 | * @param args
138 | * to be passed to the method
139 | *
140 | * @see #setAsyncOperationCallback(be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback)
141 | * @see AsyncNfcWriteOperation#executeWriteOperation()
142 | */
143 | @Override
144 | public abstract void executeWriteOperation(Intent intent, Object... args);
145 |
146 | /**
147 | * Used to check whether the passed type is equal to a String array
148 | *
149 | * @param type
150 | * to compare with
151 | *
152 | * @return type.equals(String[].class)
153 | */
154 | protected boolean checkStringArguments(Class> type) {
155 | return (type.equals(String[].class));
156 | }
157 |
158 | /**
159 | * Used to check whether the passed type is equal to a Double array
160 | *
161 | * @param type
162 | * to compare with
163 | *
164 | * @return type.equals(Double[].class)
165 | */
166 | protected boolean checkDoubleArguments(Class> type) {
167 | return type.equals(Double[].class);
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/async/WriteBluetoothNfcAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteBluetoothNfcAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 | import org.jetbrains.annotations.Nullable;
29 |
30 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
31 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
32 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
33 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
34 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * @author Daneo Van Overloop
39 | * NfcLibrary
40 | * Created on 22/04/14.
41 | */
42 | public class WriteBluetoothNfcAsync extends AbstractNfcAsync {
43 |
44 | /**
45 | * Instantiates a new WriteBluetoothNfcAsync.
46 | *
47 | * @param asyncUiCallback the async ui callback
48 | */
49 | public WriteBluetoothNfcAsync(AsyncUiCallback asyncUiCallback) {
50 | super(asyncUiCallback);
51 | }
52 |
53 | /**
54 | * Instantiates a new WriteBluetoothNfcAsync.
55 | *
56 | * @param asyncUiCallback the async ui callback
57 | * @param asyncOperationCallback the async operation callback
58 | */
59 | public WriteBluetoothNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback) {
60 | super(asyncUiCallback, asyncOperationCallback);
61 | }
62 |
63 | /**
64 | * Instantiates a new WriteBluetoothNfcAsync.
65 | *
66 | * @param asyncUiCallback the async ui callback
67 | * @param asyncOperationCallback the async operation callback
68 | * @param nfcWriteUtility the nfc write utility
69 | */
70 | public WriteBluetoothNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback, @NotNull NfcWriteUtility nfcWriteUtility) {
71 | super(asyncUiCallback, asyncOperationCallback, nfcWriteUtility);
72 | }
73 |
74 | /**
75 | * @see be.appfoundry.nfclibrary.utilities.async.AbstractNfcAsync#executeWriteOperation(android.content.Intent, Object...)
76 | */
77 | @Override
78 | public void executeWriteOperation(final Intent intent, final Object... args) {
79 | if (checkStringArguments(args.getClass()) || args.length != 2 || intent == null) {
80 | throw new UnsupportedOperationException("Invalid arguments");
81 | }
82 |
83 | setAsyncOperationCallback(new AsyncOperationCallback() {
84 | @Override
85 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
86 | return writeUtility.writeSmsToTagFromIntent((String) args[0], (String) args[1], intent);
87 | }
88 | });
89 | executeWriteOperation();
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/async/WriteCallbackNfcAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteCallbackNfcAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.content.Intent;
25 |
26 | import org.jetbrains.annotations.NotNull;
27 | import org.jetbrains.annotations.Nullable;
28 |
29 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
30 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
31 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
32 |
33 | /**
34 | * @author Daneo Van Overloop
35 | * NfcLibrary
36 | * Created on 24/04/14.
37 | */
38 | public class WriteCallbackNfcAsync extends AbstractNfcAsync {
39 |
40 | /**
41 | * Instantiates a new WriteCallbackNfcAsync.
42 | *
43 | * @param asyncUiCallback the async ui callback
44 | */
45 | public WriteCallbackNfcAsync(AsyncUiCallback asyncUiCallback) {
46 | super(asyncUiCallback);
47 | }
48 |
49 | /**
50 | * Instantiates a new WriteCallbackNfcAsync.
51 | *
52 | * @param asyncUiCallback the async ui callback
53 | * @param asyncOperationCallback the async operation callback
54 | */
55 | public WriteCallbackNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback) {
56 | super(asyncUiCallback, asyncOperationCallback);
57 | }
58 |
59 | /**
60 | * Instantiates a new WriteCallbackNfcAsync.
61 | *
62 | * @param asyncUiCallback the async ui callback
63 | * @param asyncOperationCallback the async operation callback
64 | * @param nfcWriteUtility the nfc write utility
65 | */
66 | public WriteCallbackNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback, @NotNull NfcWriteUtility nfcWriteUtility) {
67 | super(asyncUiCallback, asyncOperationCallback, nfcWriteUtility);
68 | }
69 |
70 | @Override
71 | public void executeWriteOperation(Intent intent, Object... args) {
72 | super.executeWriteOperation();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/async/WriteEmailNfcAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteEmailNfcAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 | import org.jetbrains.annotations.Nullable;
29 |
30 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
31 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
32 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
33 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
34 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * @author Daneo Van Overloop
39 | * NfcLibrary
40 | * Created on 22/04/14.
41 | */
42 | public class WriteEmailNfcAsync extends AbstractNfcAsync {
43 |
44 | /**
45 | * Instantiates a new WriteEmailNfcAsync.
46 | *
47 | * @param uiCallback the ui callback
48 | * @see AbstractNfcAsync#AbstractNfcAsync(be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback)
49 | */
50 | public WriteEmailNfcAsync(@Nullable AsyncUiCallback uiCallback) {
51 | super(uiCallback);
52 | }
53 |
54 | /**
55 | * Instantiates a new WriteEmailNfcAsync.
56 | *
57 | * @param asyncUiCallback the async ui callback
58 | * @param asyncOperationCallback the async operation callback
59 | * @see AbstractNfcAsync#AbstractNfcAsync(be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback, be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback)
60 | */
61 | public WriteEmailNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback) {
62 | super(asyncUiCallback, asyncOperationCallback);
63 | }
64 |
65 | /**
66 | * Instantiates a new WriteEmailNfcAsync.
67 | *
68 | * @param asyncUiCallback the async ui callback
69 | * @param asyncOperationCallback the async operation callback
70 | * @param nfcWriteUtility the nfc write utility
71 | */
72 | public WriteEmailNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback, @NotNull NfcWriteUtility nfcWriteUtility) {
73 | super(asyncUiCallback, asyncOperationCallback, nfcWriteUtility);
74 | }
75 |
76 | @Override
77 | public void executeWriteOperation(final Intent intent, Object... args) {
78 | if (!checkStringArguments(args.getClass()) || args.length == 0) {
79 | throw new UnsupportedOperationException("Incorrect arguments");
80 | }
81 |
82 | final String recipient = (String) args[0], subject = args.length > 1 ? (String) args[1] : null, message = args.length == 3 ? (String) args[2] : null;
83 |
84 | setAsyncOperationCallback(new AsyncOperationCallback() {
85 | @Override
86 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
87 |
88 | return writeUtility.writeEmailToTagFromIntent(recipient, subject, message, intent);
89 | }
90 | });
91 |
92 | super.executeWriteOperation();
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/async/WriteGeoLocationNfcAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteGeoLocationNfcAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 | import org.jetbrains.annotations.Nullable;
29 |
30 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
31 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
32 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
33 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
34 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * @author Daneo Van Overloop
39 | * NfcLibrary
40 | * Created on 22/04/14.
41 | */
42 | public class WriteGeoLocationNfcAsync extends AbstractNfcAsync {
43 |
44 | /**
45 | * Instantiates a new WriteGeoLocationNfcAsync.
46 | *
47 | * @param asyncUiCallback the async ui callback
48 | */
49 | public WriteGeoLocationNfcAsync(AsyncUiCallback asyncUiCallback) {
50 | super(asyncUiCallback);
51 | }
52 |
53 | /**
54 | * Instantiates a new WriteGeoLocationNfcAsync.
55 | *
56 | * @param asyncUiCallback the async ui callback
57 | * @param asyncOperationCallback the async operation callback
58 | */
59 | public WriteGeoLocationNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback) {
60 | super(asyncUiCallback, asyncOperationCallback);
61 | }
62 |
63 | /**
64 | * Instantiates a new WriteGeoLocationNfcAsync.
65 | *
66 | * @param asyncUiCallback the async ui callback
67 | * @param asyncOperationCallback the async operation callback
68 | * @param nfcWriteUtility the nfc write utility
69 | */
70 | public WriteGeoLocationNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback, @NotNull NfcWriteUtility nfcWriteUtility) {
71 | super(asyncUiCallback, asyncOperationCallback, nfcWriteUtility);
72 | }
73 |
74 | @Override
75 | public void executeWriteOperation(final Intent intent, final Object... args) {
76 | if (checkDoubleArguments(args.getClass()) || args.length != 2 || intent == null) {
77 | throw new UnsupportedOperationException("Invalid arguments");
78 | }
79 |
80 | setAsyncOperationCallback(new AsyncOperationCallback() {
81 | @Override
82 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
83 | return writeUtility.writeGeolocationToTagFromIntent((Double) args[0], (Double) args[1], intent);
84 | }
85 | });
86 |
87 | super.executeWriteOperation();
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/async/WritePhoneNfcAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WritePhoneNfcAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 | import org.jetbrains.annotations.Nullable;
29 |
30 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
31 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
32 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
33 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
34 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * @author Daneo Van Overloop
39 | * NfcLibrary
40 | * Created on 22/04/14.
41 | */
42 | public class WritePhoneNfcAsync extends AbstractNfcAsync {
43 | /**
44 | * Instantiates a new WritePhoneNfcAsync.
45 | *
46 | * @param asyncUiCallback the async ui callback
47 | */
48 | public WritePhoneNfcAsync(AsyncUiCallback asyncUiCallback) {
49 | super(asyncUiCallback);
50 | }
51 |
52 | /**
53 | * Instantiates a new WritePhoneNfcAsync.
54 | *
55 | * @param asyncUiCallback the async ui callback
56 | * @param asyncOperationCallback the async operation callback
57 | */
58 | public WritePhoneNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback) {
59 | super(asyncUiCallback, asyncOperationCallback);
60 | }
61 |
62 | /**
63 | * Instantiates a new WritePhoneNfcAsync.
64 | *
65 | * @param asyncUiCallback the async ui callback
66 | * @param asyncOperationCallback the async operation callback
67 | * @param nfcWriteUtility the nfc write utility
68 | */
69 | public WritePhoneNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback, @NotNull NfcWriteUtility nfcWriteUtility) {
70 | super(asyncUiCallback, asyncOperationCallback, nfcWriteUtility);
71 | }
72 |
73 | @Override
74 | public void executeWriteOperation(final Intent intent, final Object... args) {
75 | if (checkStringArguments(args.getClass()) || args.length != 1 || intent == null) {
76 | throw new UnsupportedOperationException("Invalid arguments");
77 | }
78 |
79 | setAsyncOperationCallback(new AsyncOperationCallback() {
80 | @Override
81 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
82 | return writeUtility.writeTelToTagFromIntent((String) args[0], intent);
83 | }
84 | });
85 | super.executeWriteOperation();
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/async/WriteSmsNfcAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteSmsNfcAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 | import org.jetbrains.annotations.Nullable;
29 |
30 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
31 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
32 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
33 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
34 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * @author Daneo Van Overloop
39 | * NfcLibrary
40 | * Created on 22/04/14.
41 | */
42 | public class WriteSmsNfcAsync extends AbstractNfcAsync {
43 |
44 | /**
45 | * Instantiates a new WriteSmsNfcAsync.
46 | *
47 | * @param asyncUiCallback the async ui callback
48 | */
49 | public WriteSmsNfcAsync(AsyncUiCallback asyncUiCallback) {
50 | super(asyncUiCallback);
51 | }
52 |
53 | /**
54 | * Instantiates a new WriteSmsNfcAsync.
55 | *
56 | * @param asyncUiCallback the async ui callback
57 | * @param asyncOperationCallback the async operation callback
58 | */
59 | public WriteSmsNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback) {
60 | super(asyncUiCallback, asyncOperationCallback);
61 | }
62 |
63 | /**
64 | * Instantiates a new WriteSmsNfcAsync.
65 | *
66 | * @param asyncUiCallback the async ui callback
67 | * @param asyncOperationCallback the async operation callback
68 | * @param nfcWriteUtility the nfc write utility
69 | */
70 | public WriteSmsNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback, @NotNull NfcWriteUtility nfcWriteUtility) {
71 | super(asyncUiCallback, asyncOperationCallback, nfcWriteUtility);
72 | }
73 |
74 | @Override
75 | public void executeWriteOperation(final Intent intent, final Object... args) {
76 | if (checkStringArguments(args.getClass()) || args.length != 2 || intent == null) {
77 | throw new UnsupportedOperationException("Invalid arguments");
78 | }
79 |
80 | setAsyncOperationCallback(new AsyncOperationCallback() {
81 | @Override
82 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
83 | return writeUtility.writeSmsToTagFromIntent((String) args[0], (String) args[1], intent);
84 | }
85 | });
86 | super.executeWriteOperation();
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/async/WriteUriNfcAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteUriNfcAsync.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.async;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 | import org.jetbrains.annotations.Nullable;
29 |
30 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
31 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
32 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
33 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
34 | import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;
36 |
37 | /**
38 | * @author Daneo Van Overloop
39 | * NfcLibrary
40 | * Created on 22/04/14.
41 | */
42 | public class WriteUriNfcAsync extends AbstractNfcAsync {
43 |
44 | /**
45 | * Instantiates a new WriteUriNfcAsync.
46 | *
47 | * @param asyncUiCallback the async ui callback
48 | */
49 | public WriteUriNfcAsync(AsyncUiCallback asyncUiCallback) {
50 | super(asyncUiCallback);
51 | }
52 |
53 | /**
54 | * Instantiates a new WriteUriNfcAsync.
55 | *
56 | * @param asyncUiCallback the async ui callback
57 | * @param asyncOperationCallback the async operation callback
58 | */
59 | public WriteUriNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback) {
60 | super(asyncUiCallback, asyncOperationCallback);
61 | }
62 |
63 | /**
64 | * Instantiates a new WriteUriNfcAsync.
65 | *
66 | * @param asyncUiCallback the async ui callback
67 | * @param asyncOperationCallback the async operation callback
68 | * @param nfcWriteUtility the nfc write utility
69 | */
70 | public WriteUriNfcAsync(@Nullable AsyncUiCallback asyncUiCallback, @NotNull AsyncOperationCallback asyncOperationCallback, @NotNull NfcWriteUtility nfcWriteUtility) {
71 | super(asyncUiCallback, asyncOperationCallback, nfcWriteUtility);
72 | }
73 |
74 | @Override
75 | public void executeWriteOperation(final Intent intent, final Object... args) {
76 | if (!checkStringArguments(args.getClass()) || args.length != 1 || !args[0].equals("")){
77 | throw new UnsupportedOperationException("Invalid arguments!");
78 | }
79 |
80 | setAsyncOperationCallback(new AsyncOperationCallback() {
81 | @Override
82 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
83 | return writeUtility.writeUriToTagFromIntent((String) args[0],intent);
84 | }
85 | });
86 |
87 | super.executeWriteOperation();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/AsyncNfcWriteOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * AsyncNfcWriteOperation.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.interfaces;
23 |
24 | import android.content.Intent;
25 |
26 | /**
27 | * NfcLibrary by daneo
28 | * Created on 22/04/14.
29 | */
30 | public interface AsyncNfcWriteOperation {
31 | /**
32 | * Method executed asynchronously, do **NOT** execute any UI logic in here! Funky stuff may occur
33 | */
34 | void executeWriteOperation();
35 |
36 | /**
37 | * Method executed asynchronously, do **NOT** execute any UI logic in here ! Funky stuff may occur
38 | * @param intent to be passed to the write utility
39 | * @param args to be passed to the method
40 | */
41 | void executeWriteOperation(Intent intent, Object... args);
42 | }
43 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NdefWrite.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NdefWrite.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.interfaces;
23 |
24 | import android.nfc.FormatException;
25 | import android.nfc.NdefMessage;
26 | import android.nfc.tech.Ndef;
27 | import android.nfc.tech.NdefFormatable;
28 |
29 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
30 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
31 |
32 | /**
33 | * Interface for the lowest level write methods, layer 1 in abstraction.
34 | */
35 | public interface NdefWrite {
36 | /**
37 | * Write message to ndef
38 | *
39 | * @param message
40 | * to write
41 | * @param ndef
42 | * from tag to write to
43 | *
44 | * @return true if success, false if ndef == null || message == null
45 | *
46 | * @throws ReadOnlyTagException
47 | * if tag is read-only
48 | * @throws InsufficientCapacityException
49 | * if the tag's capacity is not sufficient
50 | * @throws FormatException
51 | * if the message is malformed
52 | */
53 | boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
54 |
55 | /**
56 | * Write message to ndef and make readonly
57 | *
58 | * @see NdefWrite#writeToNdef(android.nfc.NdefMessage, android.nfc.tech.Ndef)
59 | */
60 | boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
61 |
62 | /**
63 | * Write the message to an NdefFormatable
64 | * @param message to write
65 | * @param ndefFormatable to write to
66 | * @return true if success, false if ndefFormatable == null || message == null
67 | * @throws FormatException
68 | */
69 | boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException;
70 |
71 | /**
72 | * Write the message to an NdefFormatable and make readonly
73 | * @see NdefWrite#writeToNdefFormatable(android.nfc.NdefMessage, android.nfc.tech.NdefFormatable)
74 | */
75 | boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException;
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NfcMessageUtility.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NfcMessageUtility.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.interfaces;
23 |
24 | import android.nfc.FormatException;
25 | import android.nfc.NdefMessage;
26 |
27 | import org.jetbrains.annotations.NotNull;
28 |
29 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
30 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
31 |
32 | /**
33 | * Interface containing the highest level methods, providing the user with a total abstraction of the way NFC works, layer 3 in abstraction.
34 | */
35 | public interface NfcMessageUtility {
36 | /**
37 | * @param urlAddress
38 | * The url, auto-prefixed with the http://www. header
39 | * @return true if successful
40 | */
41 | NdefMessage createUri(@NotNull String urlAddress) throws FormatException;
42 |
43 | /**
44 | * Creates a telephone number - NdefMessage
45 | *
46 | * @param telephone
47 | * number to create
48 | * @return true if success
49 | */
50 | NdefMessage createTel(@NotNull String telephone) throws FormatException;
51 |
52 | /**
53 | * Create SMS - NdefMessage. Due to a bug in Android this is not correctly implemented by the OS.
54 | *
55 | * @param message
56 | * to send to the person
57 | * @param number
58 | * of the recipient
59 | * @return true if success
60 | */
61 | NdefMessage createSms(@NotNull String number, String message) throws FormatException;
62 |
63 | /**
64 | * Creates a Geolocation - NdefMessage.
65 | * @param latitude
66 | * maximum 6 decimals
67 | * @param longitude
68 | * maximum 6 DECIMALS
69 | * @return true if success
70 | */
71 | NdefMessage createGeolocation(Double latitude, Double longitude) throws FormatException;
72 |
73 | /**
74 | * Create recipient, subject and message email - NdefMessage
75 | *
76 | * @param recipient
77 | * to whom the mail should be sent
78 | * @param subject
79 | * of the email
80 | * @param message
81 | * body of the email
82 | * @return true if success
83 | */
84 | NdefMessage createEmail(@NotNull String recipient, String subject, String message) throws FormatException;
85 |
86 | /**
87 | * Create the bluetooth address - NdefMessage
88 | *
89 | * @param macAddress
90 | * to create NdefMessage. Must be in format XX:XX:XX:XX:XX:XX, separator may differ
91 | * @return true if success
92 | */
93 | NdefMessage createBluetoothAddress(@NotNull String macAddress) throws InsufficientCapacityException, FormatException, ReadOnlyTagException;
94 |
95 |
96 | /**
97 | * Create the message with plain text
98 | * @param text to transfer
99 | * @return prepared NdefMessage
100 | * @throws FormatException
101 | */
102 | NdefMessage createText(@NotNull String text) throws FormatException;
103 |
104 | /**
105 | * Create the address with the given header
106 | * @see #createUri(String)
107 | */
108 | NdefMessage createUri(String urlAddress, byte payloadHeader) throws FormatException;
109 | }
110 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NfcReadUtility.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NfcReadUtility.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.interfaces;
23 |
24 | import android.content.Intent;
25 | import android.nfc.NdefMessage;
26 |
27 | import java.util.Map;
28 |
29 | /**
30 | * Interface for the Read utility, containing methods which could be convenient
31 | */
32 | public interface NfcReadUtility {
33 |
34 | /**
35 | * Read data from received {@link android.content.Intent}
36 | *
37 | * @param nfcDataIntent
38 | * the intent containing the data to read
39 | *
40 | * @return the data in an array of {@link android.content.Intent}'s or an empty {@link android.util.SparseArray} array
41 | */
42 | android.util.SparseArray readFromTagWithSparseArray(Intent nfcDataIntent);
43 |
44 | /**
45 | * Read data from received {@link android.content.Intent}
46 | * @param nfcDataIntent the intent containing the data to read
47 | * @return the data is either a filled or empty {@link java.util.Map} depending on whether parsing was successful
48 | */
49 | Map readFromTagWithMap(Intent nfcDataIntent);
50 |
51 |
52 | /**
53 | * Retrieve the content type from the message
54 | * @param message type {@link be.appfoundry.nfclibrary.constants.NfcPayloadHeader}
55 | * @return {@link be.appfoundry.nfclibrary.constants.NfcPayloadHeader}
56 | */
57 | java.util.Iterator retrieveMessageTypes(NdefMessage message);
58 |
59 | /**
60 | * Retrieve the actual message content
61 | * @param message to parse
62 | * @return the formatted message
63 | */
64 | String retrieveMessage(NdefMessage message);
65 | }
66 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NfcWriteUtility.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NfcWriteUtility.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.interfaces;
23 |
24 | import android.content.Intent;
25 | import android.nfc.FormatException;
26 | import android.nfc.NdefMessage;
27 |
28 | import org.jetbrains.annotations.NotNull;
29 |
30 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
31 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
32 | import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
33 |
34 | /**
35 | * NfcLibrary by daneo
36 | * Created on 17/04/14.
37 | */
38 | public interface NfcWriteUtility {
39 | /**
40 | * @param urlAddress
41 | * The url, do not put in any prefix, {@link be.appfoundry.nfclibrary.constants.NfcPayloadHeader#HTTP_WWW} is auto added.
42 | * @param intent
43 | * to write to
44 | *
45 | * @return true if successful
46 | */
47 | boolean writeUriToTagFromIntent(@NotNull String urlAddress, @NotNull Intent intent) throws FormatException, ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException;
48 |
49 | /**
50 | * @param urlAddress
51 | * The url, do not put in any prefix, {@link be.appfoundry.nfclibrary.constants.NfcPayloadHeader#HTTP_WWW} is auto added.
52 | * @param intent
53 | * to write to
54 | *
55 | * @return true if successful
56 | */
57 | boolean writeUriWithPayloadToTagFromIntent(@NotNull String urlAddress, byte payloadHeader, @NotNull Intent intent) throws FormatException, ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException;
58 |
59 |
60 | /**
61 | * Writes a telephone number to the tag
62 | *
63 | * @param telephone
64 | * number to write
65 | * @param intent
66 | * to write to
67 | * e to
68 | *
69 | * @return true if success
70 | */
71 | boolean writeTelToTagFromIntent(@NotNull String telephone, @NotNull Intent intent) throws FormatException, ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException;
72 |
73 | /**
74 | * Write SMS to tag. Due to a bug in Android this is not correctly implemented by the OS.
75 | *
76 | * @param number
77 | * of the recipient
78 | * @param message
79 | * to send to the person
80 | * @param intent
81 | * to write to
82 | *
83 | * @return true if success
84 | */
85 | boolean writeSmsToTagFromIntent(@NotNull String number, String message, @NotNull Intent intent) throws FormatException, ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException;
86 |
87 | /**
88 | * @param latitude
89 | * maximum 6 decimals
90 | * @param longitude
91 | * maximum 6 DECIMALS
92 | * @param intent
93 | * to to write to
94 | *
95 | * @return true if success
96 | */
97 | boolean writeGeolocationToTagFromIntent(Double latitude, Double longitude, @NotNull Intent intent) throws FormatException, ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException;
98 |
99 | /**
100 | * Write recipient, subject and message to tag
101 | *
102 | * @param recipient
103 | * to whom the mail should be sent
104 | * @param subject
105 | * of the email
106 | * @param message
107 | * body of the email
108 | * @param intent
109 | * to write to
110 | *
111 | * @return true if success
112 | */
113 | boolean writeEmailToTagFromIntent(@NotNull String recipient, String subject, String message, @NotNull Intent intent) throws FormatException, ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException;
114 |
115 | /**
116 | * Write the bluetooth address to the tag
117 | *
118 | * @param macAddress
119 | * to write to the tag. Must be in format XX:XX:XX:XX:XX:XX, separator may differ
120 | * @param intent
121 | * to write to
122 | *
123 | * @return true if success
124 | */
125 | boolean writeBluetoothAddressToTagFromIntent(@NotNull String macAddress, Intent intent) throws InsufficientCapacityException, FormatException, ReadOnlyTagException, TagNotPresentException;
126 |
127 |
128 | /**
129 | * Pass a raw NdefMessage along to write
130 | * @param message to write to the tag
131 | * @param intent to write to
132 | * @return true if success
133 | * @throws FormatException
134 | */
135 | boolean writeNdefMessageToTagFromIntent(@NotNull NdefMessage message, Intent intent) throws FormatException, TagNotPresentException, ReadOnlyTagException, InsufficientCapacityException;
136 |
137 | /**
138 | * Pass a raw NdefMessage along to write
139 | * @param message to write to the tag
140 | * @param intent to write to
141 | * @return true if success
142 | * @throws FormatException
143 | */
144 | boolean writeTextToTagFromIntent(@NotNull String message, Intent intent) throws FormatException, TagNotPresentException, ReadOnlyTagException, InsufficientCapacityException;
145 |
146 | /**
147 | * Used to mark the following operation as readonly
148 | *
149 | * @return an instance of WriteUtility in order to chain
150 | */
151 | NfcWriteUtility makeOperationReadOnly();
152 |
153 | }
154 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/WriteUtility.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteUtility.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.interfaces;
23 |
24 | import android.nfc.FormatException;
25 | import android.nfc.NdefMessage;
26 | import android.nfc.Tag;
27 |
28 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
29 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
30 |
31 | /**
32 | * Interface containing a few convenience methods for the user. Layer 2 in abstraction.
33 | */
34 | public interface WriteUtility extends NdefWrite {
35 |
36 |
37 | /**
38 | * Writes towards a {@link android.nfc.Tag}
39 | *
40 | * @param message
41 | * to write
42 | * @param tag
43 | * to write to
44 | *
45 | * @return true if success
46 | *
47 | * @see #writeToNdef(android.nfc.NdefMessage, android.nfc.tech.Ndef)
48 | */
49 | boolean writeSafelyToTag(NdefMessage message, Tag tag);
50 |
51 | /**
52 | * Write the given message to the tag
53 | *
54 | * @param message
55 | * to write
56 | * @param tag
57 | * to write to
58 | *
59 | * @return true if success
60 | *
61 | * @throws android.nfc.FormatException if the message is in an incorrect format
62 | * @throws be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException if there is not enough space available on the tag
63 | * @throws be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException when attempting to write to a read-only tag
64 | */
65 | boolean writeToTag(NdefMessage message, Tag tag) throws FormatException, ReadOnlyTagException, InsufficientCapacityException;
66 |
67 | /**
68 | * Used to mark the following operation as readonly
69 | * @return an instance of WriteUtility in order to chain
70 | */
71 | WriteUtility makeOperationReadOnly();
72 | }
73 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/sync/NdefWriteImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NdefWriteImpl.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.nfc.FormatException;
25 | import android.nfc.NdefMessage;
26 | import android.nfc.TagLostException;
27 | import android.nfc.tech.Ndef;
28 | import android.nfc.tech.NdefFormatable;
29 | import android.util.Log;
30 |
31 | import java.io.IOException;
32 |
33 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
34 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NdefWrite;
36 |
37 | /**
38 | * Class used for writing the message towards an NFC tag
39 | * @author Daneo Van Overloop
40 | * NfcLibrary
41 | */
42 | public class NdefWriteImpl implements NdefWrite {
43 |
44 | private static final String TAG = NdefWriteImpl.class.getName();
45 |
46 | private boolean mReadOnly = false;
47 |
48 | /**
49 | * Instantiates a new NdefWriteImpl.
50 | */
51 | public NdefWriteImpl() {
52 |
53 | }
54 |
55 |
56 | /**
57 | * {@inheritDoc}
58 | */
59 | @Override
60 | public boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
61 |
62 | if (message == null || ndef == null) {
63 | return false;
64 | }
65 |
66 | int size = message.getByteArrayLength();
67 |
68 | try {
69 |
70 | ndef.connect();
71 | if (!ndef.isWritable()) {
72 | throw new ReadOnlyTagException();
73 | }
74 | if (ndef.getMaxSize() < size) {
75 | throw new InsufficientCapacityException();
76 | }
77 | ndef.writeNdefMessage(message);
78 | if (ndef.canMakeReadOnly() && mReadOnly) {
79 | ndef.makeReadOnly();
80 | } else if (mReadOnly) {
81 | throw new UnsupportedOperationException();
82 | }
83 | return true;
84 | } catch (IOException e) {
85 | Log.w(TAG, "IOException occurred", e);
86 | } finally {
87 | if (ndef.isConnected()) {
88 | try {
89 | ndef.close();
90 | } catch (IOException e) {
91 | Log.v(TAG, "IOException occurred at closing.", e);
92 | }
93 | }
94 | }
95 | return false;
96 | }
97 |
98 | /**
99 | * {@inheritDoc}
100 | */
101 | @Override
102 | public boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
103 | setReadOnly(true);
104 | boolean result = writeToNdef(message, ndef);
105 | setReadOnly(false);
106 | return result;
107 | }
108 |
109 | /**
110 | * {@inheritDoc}
111 | */
112 | @Override
113 | public boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException {
114 | setReadOnly(true);
115 | boolean result = writeToNdefFormatable(message, ndefFormat);
116 | setReadOnly(false);
117 |
118 | return result;
119 |
120 | }
121 |
122 | /**
123 | * {@inheritDoc}
124 | */
125 | @Override
126 | public boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException {
127 | if (ndefFormatable == null || message == null) {
128 | return false;
129 | }
130 |
131 | try {
132 | ndefFormatable.connect();
133 | if (mReadOnly) {
134 | ndefFormatable.formatReadOnly(message);
135 | } else {
136 | ndefFormatable.format(message);
137 | }
138 |
139 | return true;
140 | } catch (TagLostException e) {
141 | Log.d(TAG, "We lost our tag !", e);
142 | } catch (IOException e) {
143 | Log.w(TAG, "IOException occured", e);
144 | } catch (FormatException e) {
145 | Log.w(TAG, "Message is malformed occurred", e);
146 | throw e;
147 | } finally {
148 | if (ndefFormatable.isConnected()) {
149 | try {
150 | ndefFormatable.close();
151 | } catch (IOException e) {
152 | Log.w(TAG, "IOException occurred at closing.", e);
153 | }
154 | }
155 | }
156 |
157 | return false;
158 | }
159 |
160 | /**
161 | * Sets read only.
162 | *
163 | * @param readOnly the read only
164 | */
165 | void setReadOnly(boolean readOnly) {
166 | mReadOnly = readOnly;
167 | }
168 | }
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/sync/NfcMessageUtilityImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NfcMessageUtilityImpl.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.nfc.FormatException;
25 | import android.nfc.NdefMessage;
26 | import android.nfc.NdefRecord;
27 | import android.telephony.PhoneNumberUtils;
28 |
29 | import org.jetbrains.annotations.NotNull;
30 |
31 | import java.nio.charset.Charset;
32 |
33 | import be.appfoundry.nfclibrary.constants.NfcPayloadHeader;
34 | import be.appfoundry.nfclibrary.constants.NfcType;
35 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcMessageUtility;
36 |
37 | /**
38 | * Class used in order to write to NFC tags
39 | * @author Daneo Van Overloop
40 | * NfcLibrary
41 | * Created on 27/03/14.
42 | */
43 | public class NfcMessageUtilityImpl implements NfcMessageUtility {
44 |
45 | private static final String TAG = NfcMessageUtilityImpl.class.getCanonicalName();
46 |
47 |
48 | // Source : http://stackoverflow.com/questions/12295711/split-a-string-at-every-nth-position
49 | private static String[] splitStringEvery(String s, int interval) {
50 | int arrayLength = (int) Math.ceil(((s.length() / (double) interval)));
51 | String[] result = new String[arrayLength];
52 |
53 | int j = 0;
54 | int lastIndex = result.length - 1;
55 | for (int i = 0; i < lastIndex; i++, j += interval) {
56 | result[i] = s.substring(j, j + interval);
57 | } //Add the last bit
58 | result[lastIndex] = s.substring(j);
59 |
60 | return result;
61 | }
62 |
63 | /**
64 | * Internal method to write TNF to tag
65 | *
66 | * @param tnfType
67 | * e.g. NdefRecord.TNF_WELL_KNOWN
68 | * @param type
69 | * e.g. NdefRecord.RTD_URI
70 | * @param payload
71 | * byte form of the content
72 | *
73 | * @return NdefMessage
74 | */
75 | private NdefMessage createNdefMessage(short tnfType, byte[] type, byte[] payload) {
76 | NdefRecord record = new NdefRecord(tnfType, type, new byte[0], payload);
77 | return new NdefMessage(record);
78 | }
79 |
80 | /**
81 | * {@inheritDoc}
82 | * Precondition : UrlAddress should not be null
83 | */
84 | @Override
85 | public NdefMessage createUri(@NotNull String urlAddress) throws FormatException {
86 | return createUriMessage(urlAddress, NfcPayloadHeader.HTTP_WWW);
87 | }
88 |
89 | /**
90 | * {@inheritDoc}
91 | * Precondition : Telephone should not be null
92 | */
93 | @Override
94 | public NdefMessage createTel(@NotNull String telephone) throws FormatException {
95 | telephone = telephone.startsWith("+") ? "+" + telephone.replaceAll("\\D", "") : telephone.replaceAll("\\D", "");
96 | if (!PhoneNumberUtils.isGlobalPhoneNumber(telephone)) {
97 | throw new FormatException();
98 | }
99 |
100 | return createUriMessage(telephone, NfcPayloadHeader.TEL);
101 | }
102 |
103 | /**
104 | * {@inheritDoc}
105 | * Precondition : At least number should not be null
106 | */
107 | @Override
108 | public NdefMessage createSms(@NotNull String number, String message) throws FormatException {
109 | number = number.startsWith("+") ? "+" + number.replaceAll("\\D", "") : number.replaceAll("\\D", "");
110 | if (!PhoneNumberUtils.isGlobalPhoneNumber((number))) {
111 | throw new FormatException();
112 | }
113 | String smsPattern = "sms:" + number + "?body=" + message;
114 | //String externalType = "nfclab.com:smsService";
115 | return createUriMessage(smsPattern, NfcPayloadHeader.CUSTOM_SCHEME);
116 | }
117 |
118 | /**
119 | * {@inheritDoc}
120 | * Precondition : lat- and longitude, max 6 decimals
121 | */
122 | @Override
123 | public NdefMessage createGeolocation(Double latitude, Double longitude) throws FormatException {
124 | latitude = Math.round(latitude * Math.pow(10, 6)) / Math.pow(10, 6);
125 | longitude = Math.round(longitude * Math.pow(10, 6)) / Math.pow(10, 6);
126 | String address = "geo:" + latitude.floatValue() + "," + longitude.floatValue();
127 | String externalType = "nfclab.com:geoService";
128 |
129 | return createUriMessage(address, NfcPayloadHeader.CUSTOM_SCHEME);
130 | }
131 |
132 |
133 | /**
134 | * {@inheritDoc}
135 | * Precondition : At least recipient should not be null
136 | */
137 | @Override
138 | public NdefMessage createEmail(@NotNull String recipient, String subject, String message) throws FormatException {
139 | subject = (subject != null) ? subject : "";
140 | message = (message != null) ? message : "";
141 | String address = recipient + "?subject=" + subject + "&body=" + message;
142 |
143 | return createUriMessage(address, NfcPayloadHeader.MAILTO);
144 | }
145 |
146 | /**
147 | * {@inheritDoc}
148 | * Precondition : macAddress should not be null
149 | */
150 | @Override
151 | public NdefMessage createBluetoothAddress(@NotNull String macAddress) throws FormatException {
152 | byte[] payload = convertBluetoothToNdefFormat(macAddress);
153 | NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, NfcType.BLUETOOTH_AAR, null, payload);
154 |
155 | return new NdefMessage(record);
156 | }
157 |
158 | /**
159 | * {@inheritDoc}
160 | * Precondition : Text should not be null, encoded in UTF8
161 | */
162 | @Override
163 | public NdefMessage createText(@NotNull String text) {
164 | byte[] payload = new byte[text.getBytes().length+1];
165 | System.arraycopy(text.getBytes(),0, payload,1, text.length());
166 |
167 | return createNdefMessage(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, payload);
168 | }
169 |
170 | /**
171 | * {@inheritDoc}
172 | */
173 | @Override
174 | public NdefMessage createUri(String urlAddress, byte payloadHeader) throws FormatException {
175 | return createUriMessage(urlAddress,payloadHeader);
176 | }
177 |
178 | /**
179 | * Write URI to tag
180 | *
181 | * @param urlAddress
182 | * to write to tag
183 | * @param payloadHeader
184 | * defining the prefix
185 | *
186 | * @return true if success
187 | */
188 | private NdefMessage createUriMessage(@NotNull String urlAddress, byte payloadHeader) {
189 | byte[] uriField = urlAddress.getBytes(Charset.forName("US-ASCII"));
190 | byte[] payload = new byte[uriField.length + 1];
191 | payload[0] = payloadHeader; // Marks the prefix
192 | System.arraycopy(uriField, 0, payload, 1, uriField.length);
193 | return createNdefMessage(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, payload);
194 | }
195 |
196 | /**
197 | * The MAC-Address has to be in reverse order, the first 2 bits indicate the length.
198 | *
199 | * @param bluetoothAddress
200 | * to be transformed.
201 | *
202 | * @return MAC-Address in the right format
203 | *
204 | * http://members.nfc-forum.org/resources/AppDocs/NFCForum_AD_BTSSP_1_0.pdf
205 | */
206 | private byte[] convertBluetoothToNdefFormat(String bluetoothAddress) {
207 | byte[] res = new byte[8];
208 | String[] parts = bluetoothAddress.split(".(?=[\\w\\d]{2})");
209 |
210 | if (bluetoothAddress.length() == 12) {
211 | parts = splitStringEvery(bluetoothAddress, 2);
212 | }
213 |
214 | if (parts.length != 6) {
215 | return res;
216 | }
217 |
218 | // Leave 1st 2 bits untouched, have to be adjusted in order to make this recognisable
219 | for (int i = 5; i >= 0; i--) {
220 | res[7 - i] = (byte) Integer.parseInt(parts[i], 16);
221 | System.out.println(res[5 - i]);
222 | }
223 |
224 | res[0] = (byte) (res.length % 256);
225 | res[1] = (byte) (res.length / 256);
226 | return res;
227 | }
228 |
229 | }
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/sync/NfcReadUtilityImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * NfcReadUtilityImpl.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.content.Intent;
25 | import android.net.Uri;
26 | import android.nfc.NdefMessage;
27 | import android.nfc.NdefRecord;
28 | import android.nfc.NfcAdapter;
29 | import android.os.Parcelable;
30 | import android.util.SparseArray;
31 |
32 | import org.jetbrains.annotations.NotNull;
33 |
34 | import java.nio.charset.Charset;
35 | import java.util.ArrayList;
36 | import java.util.Arrays;
37 | import java.util.Collection;
38 | import java.util.HashMap;
39 | import java.util.Iterator;
40 | import java.util.Map;
41 |
42 | import be.appfoundry.nfclibrary.constants.NfcType;
43 | import be.appfoundry.nfclibrary.utilities.interfaces.NfcReadUtility;
44 |
45 | /**
46 | * @author Daneo Van Overloop
47 | * NfcLibrary
48 | * Created on 28/03/14.
49 | */
50 |
51 | public class NfcReadUtilityImpl implements NfcReadUtility {
52 |
53 | private static final String TAG = NfcReadUtilityImpl.class.getCanonicalName();
54 |
55 |
56 | /**
57 | * {@inheritDoc}
58 | */
59 | @Override
60 | public SparseArray readFromTagWithSparseArray(Intent nfcDataIntent) {
61 | Parcelable[] messages = nfcDataIntent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
62 |
63 | SparseArray resultMap = messages != null ? new SparseArray(messages.length) : new SparseArray();
64 |
65 | if (messages == null) {
66 | return resultMap;
67 | }
68 |
69 | for (Parcelable message : messages) {
70 | for (NdefRecord record : ((NdefMessage) message).getRecords()) {
71 | byte type = retrieveTypeByte(record.getPayload());
72 |
73 | String i = resultMap.get(type);
74 | if (i == null) {
75 | resultMap.put(type, parseAccordingToType(record));
76 | }
77 | }
78 | }
79 |
80 | return resultMap;
81 | }
82 |
83 | /**
84 | * {@inheritDoc}
85 | */
86 | @Override
87 | public Map readFromTagWithMap(Intent nfcDataIntent) {
88 | Map resultMap = new HashMap();
89 | SparseArray sparseArray = readFromTagWithSparseArray(nfcDataIntent);
90 |
91 | for (int i = 0; i < sparseArray.size(); i++) {
92 | resultMap.put((byte) sparseArray.keyAt(i), sparseArray.valueAt(i));
93 | }
94 | return resultMap;
95 | }
96 |
97 | /**
98 | * {@inheritDoc}
99 | */
100 | @Override
101 | public Iterator retrieveMessageTypes(NdefMessage record) {
102 | Collection list = new ArrayList();
103 | for (NdefRecord ndefRecord : record.getRecords()) {
104 | list.add(retrieveTypeByte(ndefRecord.getPayload()));
105 | }
106 | return list.iterator();
107 | }
108 |
109 | /**
110 | * {@inheritDoc}
111 | */
112 | @Override
113 | public String retrieveMessage(NdefMessage message) {
114 | return message.getRecords()[0] != null ? parseAccordingToHeader(message.getRecords()[0].getPayload()) : null;
115 | }
116 |
117 | private byte retrieveTypeByte(byte[] payload) {
118 | if (payload.length > 0) {
119 | return payload[0];
120 | }
121 |
122 | return -1;
123 | }
124 |
125 | private String parseAccordingToHeader(@NotNull byte[] payload) {
126 | return (payload.length > 0) ? new String(payload, 0, payload.length, Charset.forName("US-ASCII")).trim() : "";
127 | }
128 |
129 | private String parseAccordingToType(NdefRecord obj) {
130 | if (Arrays.equals(obj.getType(), NfcType.BLUETOOTH_AAR)) {
131 | byte[] toConvert = obj.getPayload();
132 | StringBuilder result = new StringBuilder();
133 | for (int i = toConvert.length - 1; i >= 2; i--) {
134 | byte temp = toConvert[i];
135 | String tempString = ((temp < 0) ? Integer.toHexString(temp + Byte.MAX_VALUE) : Integer.toHexString(temp));
136 | result.append((tempString.length() < 2) ? "0" + tempString : tempString);
137 | result.append(":");
138 | }
139 | return !(result.length() == 0) ? result.substring(0, result.length() - 1) : result.toString();
140 | }
141 |
142 | return Uri.parse(parseAccordingToHeader(obj.getPayload())).toString();
143 | }
144 |
145 | }
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/sync/WriteUtilityImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * WriteUtilityImpl.java
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | package be.appfoundry.nfclibrary.utilities.sync;
23 |
24 | import android.nfc.FormatException;
25 | import android.nfc.NdefMessage;
26 | import android.nfc.Tag;
27 | import android.nfc.tech.Ndef;
28 | import android.nfc.tech.NdefFormatable;
29 | import android.util.Log;
30 |
31 | import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
32 | import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
33 | import be.appfoundry.nfclibrary.utilities.interfaces.NdefWrite;
34 | import be.appfoundry.nfclibrary.utilities.interfaces.WriteUtility;
35 |
36 | /**
37 | * @author Daneo Van Overloop
38 | * NfcLibrary
39 | * Created on 11/04/14.
40 | */
41 | public class WriteUtilityImpl implements WriteUtility {
42 |
43 | private static final String TAG = WriteUtilityImpl.class.getName();
44 |
45 | private boolean readOnly = false;
46 |
47 | private NdefWrite mNdefWrite;
48 |
49 | public WriteUtilityImpl() {
50 | setNdefWrite(new NdefWriteImpl());
51 | }
52 |
53 | /**
54 | * @param ndefWrite
55 | * used to delegate writing to Tag
56 | *
57 | * @throws java.lang.NullPointerException
58 | * when null
59 | */
60 | public WriteUtilityImpl(NdefWrite ndefWrite) {
61 | if (ndefWrite == null) {
62 | throw new NullPointerException("WriteUtility cannot be null");
63 | }
64 | setNdefWrite(ndefWrite);
65 | }
66 |
67 | private void setNdefWrite(NdefWrite ndefWrite) {
68 | this.mNdefWrite = ndefWrite;
69 | }
70 |
71 | @Override
72 | public boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
73 | return mNdefWrite.writeToNdef(message, ndef);
74 | }
75 |
76 | @Override
77 | public boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException {
78 | return mNdefWrite.writeToNdefAndMakeReadonly(message, ndef);
79 | }
80 |
81 | @Override
82 | public boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException {
83 | return mNdefWrite.writeToNdefFormatable(message, ndefFormatable);
84 | }
85 |
86 | @Override
87 | public boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException {
88 | return mNdefWrite.writeToNdefFormatableAndMakeReadonly(message, ndefFormat);
89 | }
90 |
91 | @Override
92 | public boolean writeSafelyToTag(NdefMessage message, Tag tag) {
93 | try {
94 | writeToTag(message, tag);
95 | } catch (ReadOnlyTagException e) {
96 | Log.d(TAG, "Tag is Read only !", e);
97 | } catch (InsufficientCapacityException e) {
98 | Log.d(TAG, "The tag's capacity is insufficient!", e);
99 | } catch (FormatException e) {
100 | Log.d(TAG, "The message is malformed!", e);
101 | }
102 |
103 | return false;
104 | }
105 |
106 | @Override
107 | public boolean writeToTag(NdefMessage message, Tag tag) throws FormatException, ReadOnlyTagException, InsufficientCapacityException {
108 | Ndef ndef = Ndef.get(tag);
109 | NdefFormatable formatable = NdefFormatable.get(tag);
110 |
111 | boolean result;
112 | if (readOnly) {
113 | result = writeToNdefAndMakeReadonly(message, ndef) || writeToNdefFormatableAndMakeReadonly(message, formatable);
114 | } else {
115 | result = writeToNdef(message, ndef) || writeToNdefFormatable(message, formatable);
116 | }
117 |
118 | readOnly = false;
119 | return result;
120 | }
121 |
122 | public WriteUtility makeOperationReadOnly() {
123 | readOnly = true;
124 | return this;
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/nfclib/src/main/res/xml/nfc_tech.xml:
--------------------------------------------------------------------------------
1 |
21 |
22 |
23 |
24 | android.nfc.tech.NfcA
25 | android.nfc.tech.Ndef
26 |
27 |
28 | android.nfc.tech.NfcB
29 | android.nfc.tech.Ndef
30 |
31 |
32 |
33 | android.nfc.tech.NfcF
34 | android.nfc.tech.NfcV
35 | android.nfc.tech.Ndef
36 |
37 |
38 |
39 | android.nfc.tech.Ndef
40 | android.nfc.tech.NdefFormatable
41 | android.nfc.tech.MifareClassic
42 | android.nfc.tech.MifareUltralight
43 |
44 |
45 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * settings.gradle
3 | * NfcLibrary project.
4 | *
5 | * Created by : Daneo van Overloop - 17/6/2014.
6 | *
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2014 AppFoundry. All rights reserved.
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | */
21 |
22 | include 'nfclib','implementationApp'
23 |
--------------------------------------------------------------------------------