Merge branch '1.1.1'
6
.github/ISSUE_TEMPLATE.md
vendored
@ -1,7 +1,7 @@
|
||||
Please fill out the form below before submitting, thank you!
|
||||
|
||||
- [ ] Bug exists Release Version 1.1.0 (Java Repository Master Branch)
|
||||
- [ ] Bug exists in Snapshot Version 1.1.1-SNAPSHOT (Android Service Repository Master Branch)
|
||||
- [ ] Bug exists Release Version 1.1.1 (Java Repository Master Branch)
|
||||
- [ ] Bug exists in Snapshot Version 1.1.2-SNAPSHOT (Android Service Repository Master Branch)
|
||||
- [ ] Bug is just in the Sample Application.
|
||||
|
||||
__Android API Version Bug Seen on:__
|
||||
@ -9,7 +9,7 @@ __Android API Version Bug Seen on:__
|
||||
__Android Version Bug Seen on:__
|
||||
|
||||
|
||||
Please also check that if you have found the bug in the Release version (1.1.0) that you check that it also exists in the Snapshot (1.1.1-SNAPSHOT) before raising a bug.
|
||||
Please also check that if you have found the bug in the Release version (1.1.1) that you check that it also exists in the Snapshot (1.1.2-SNAPSHOT) before raising a bug.
|
||||
|
||||
|
||||
## Description of Bug:
|
||||
|
1
.gitignore
vendored
@ -80,6 +80,7 @@ gradle.properties
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
!gradle-wrapper.jar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
@ -1,10 +1,10 @@
|
||||
language: android
|
||||
jdk: oraclejdk7
|
||||
jdk: oraclejdk8
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- build-tools-23.0.2
|
||||
- android-23
|
||||
- build-tools-23.0.3
|
||||
- android-24
|
||||
- extra-android-support
|
||||
- extra
|
||||
|
||||
@ -18,4 +18,3 @@ script:
|
||||
- ./gradlew clean
|
||||
- ./gradlew org.eclipse.paho.android.sample:assemble paho.mqtt.android.example:assemble
|
||||
# - ./gradlew org.eclipse.paho.android.service:assemble org.eclipse.paho.android.service:connectedCheck
|
||||
|
||||
|
18
README.md
@ -7,14 +7,14 @@ The Paho Android Service is an MQTT client library written in Java for developin
|
||||
## Features
|
||||
| | | | | |
|
||||
|---------------------|--------------------|---|----------------------|--------------------|
|
||||
| MQTT 3.1 | :heavy_check_mark: | | Automatic Reconnect | :heavy_check_mark: (Since 1.1.0) |
|
||||
| MQTT 3.1.1 | :heavy_check_mark: | | Offline Buffering | :heavy_check_mark: (Since 1.1.0) |
|
||||
| LWT | :heavy_check_mark: | | WebSocket Support | :heavy_check_mark: (Since 1.1.0) |
|
||||
| MQTT 3.1 | :heavy_check_mark: | | Automatic Reconnect | :heavy_check_mark: |
|
||||
| MQTT 3.1.1 | :heavy_check_mark: | | Offline Buffering | :heavy_check_mark: |
|
||||
| LWT | :heavy_check_mark: | | WebSocket Support | :heavy_check_mark: |
|
||||
| SSL / TLS | :heavy_check_mark: | | Standard TCP Support | :heavy_check_mark: |
|
||||
| Message Persistence | :heavy_check_mark: | |
|
||||
|
||||
|
||||
To get started, download [Android Studio](http://developer.android.com/tools/studio/index.html). You will also need to download the [Android SDK](https://developer.android.com/sdk/installing/adding-packages.html). Currently you will need the SDK for 19,21 and 22, This will hopefully be simplified soon.
|
||||
To get started, download [Android Studio](http://developer.android.com/tools/studio/index.html). You will also need to download the [Android SDK](https://developer.android.com/sdk/installing/adding-packages.html). Currently you will need the SDK for 24.
|
||||
|
||||
|
||||
## Project description:
|
||||
@ -40,12 +40,12 @@ Paho reflects the inherent physical and cost constraints of device connectivity.
|
||||
|
||||
#### Maven
|
||||
|
||||
Eclipse hosts a Nexus repository for those who want to use Maven to manage their dependencies.
|
||||
Eclipse hosts a Nexus repository for those who want to use Maven to manage their dependencies.
|
||||
|
||||
Add the repository definition and the dependency definition shown below to your pom.xml.
|
||||
|
||||
Replace %REPOURL% with either ``` https://repo.eclipse.org/content/repositories/paho-releases/ ``` for the official releases, or ``` https://repo.eclipse.org/content/repositories/paho-snapshots/ ``` for the nightly snapshots. Replace %VERSION% with the level required .
|
||||
The latest release version is ```1.1.0``` and the current snapshot version is ```1.1.1-SNAPSHOT```.
|
||||
The latest release version is ```1.1.1``` and the current snapshot version is ```1.1.2-SNAPSHOT```.
|
||||
|
||||
```
|
||||
<project ...>
|
||||
@ -74,17 +74,17 @@ If you are using Android Studio and / or Gradle to manage your application depen
|
||||
```
|
||||
repositories {
|
||||
maven {
|
||||
url "https://repo.eclipse.org/content/repositories/paho-releases/"
|
||||
url "https://repo.eclipse.org/content/repositories/paho-snapshots/"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
|
||||
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.0'
|
||||
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
|
||||
}
|
||||
```
|
||||
__Note:__ currently you have to include the `org.eclipse.paho:org.eclipse.paho.client.mqttv3` dependency as well. We are attempting to get the build to produce an Android `AAR` file that contains both the Android service as well as it's dependencies, however this is still experimental. If you wish to try it, remove the `org.eclipse.paho:org.eclipse.paho.client.mqttv3` dependency and append `@aar` to the end of the Android Service dependency. E.g. `org.eclipse.paho:org.eclipse.paho.android.service:1.1.0@aar`
|
||||
__Note:__ currently you have to include the `org.eclipse.paho:org.eclipse.paho.client.mqttv3` dependency as well. We are attempting to get the build to produce an Android `AAR` file that contains both the Android service as well as it's dependencies, however this is still experimental. If you wish to try it, remove the `org.eclipse.paho:org.eclipse.paho.client.mqttv3` dependency and append `@aar` to the end of the Android Service dependency. E.g. `org.eclipse.paho:org.eclipse.paho.android.service:1.1.1@aar`
|
||||
|
||||
If you find that there is functionality missing or bugs in the release version, you may want to try using the snapshot version to see if this helps before raising a feature request or an issue.
|
||||
|
||||
|
14
build.gradle
@ -6,7 +6,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.2.1'
|
||||
classpath 'com.android.tools.build:gradle:2.2.3'
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
@ -14,22 +14,23 @@ buildscript {
|
||||
|
||||
ext{
|
||||
|
||||
compileSdkVersion = 23
|
||||
buildToolsVersion = '23.0.2'
|
||||
compileSdkVersion = 24
|
||||
buildToolsVersion = '23.0.3'
|
||||
|
||||
|
||||
group = 'org.eclipse.paho'
|
||||
|
||||
sampleArchivesBaseName = 'org.eclipse.paho.android.sample'
|
||||
sampleVersion = '1.1.0'
|
||||
sampleVersion = '1.1.1'
|
||||
|
||||
serviceArchivesBaseName = 'org.eclipse.paho.android.service'
|
||||
serviceVersion = '1.1.0'
|
||||
serviceVersion = '1.1.1'
|
||||
|
||||
clientVersion = '1.1.0'
|
||||
|
||||
mavenUrl = "https://repo.eclipse.org/content/repositories/paho-releases/"
|
||||
|
||||
supportLibVersion = '23.3.0'
|
||||
supportLibVersion = '24.2.1'
|
||||
|
||||
}
|
||||
|
||||
@ -43,6 +44,7 @@ def getSdkDirFromLocalProperties() {
|
||||
properties.getProperty('sdk.dir')
|
||||
}
|
||||
|
||||
|
||||
def androidHome = System.env['ANDROID_HOME']
|
||||
|
||||
def androidHomeIsDefined = androidHome?.trim()
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,4 +1,4 @@
|
||||
#Mon Apr 11 13:12:12 BST 2016
|
||||
#Tue Jan 24 11:18:55 GMT 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
46
gradlew
vendored
@ -6,12 +6,30 @@
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
@ -30,6 +48,7 @@ die ( ) {
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
@ -40,26 +59,11 @@ case "`uname`" in
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@ -85,7 +89,7 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
|
8
gradlew.bat
vendored
@ -8,14 +8,14 @@
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
@ -46,7 +46,7 @@ echo location of your Java installation.
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
@ -7,7 +7,7 @@ android {
|
||||
defaultConfig {
|
||||
applicationId rootProject.ext.sampleArchivesBaseName
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 22
|
||||
targetSdkVersion 24
|
||||
versionCode 1
|
||||
versionName "0.1"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":org.eclipse.paho.android.sample" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="org.eclipse.paho" external.system.module.version="1.0.3-SNAPSHOT" type="JAVA_MODULE" version="4">
|
||||
<module external.linked.project.id=":org.eclipse.paho.android.sample" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
@ -32,12 +32,14 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
@ -47,6 +49,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
||||
@ -54,6 +57,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
@ -61,6 +65,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||
@ -68,6 +73,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
@ -75,34 +81,40 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-compat/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-ui/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-utils/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-fragment/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-media-compat/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/24.2.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="jdk" jdkName="Android API 24 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="org.eclipse.paho.client.mqttv3-1.0.3-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-compat-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-media-compat-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="animated-vector-drawable-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-fragment-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-core-ui-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="recyclerview-v7-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-vector-drawable-24.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-core-utils-24.2.1" level="project" />
|
||||
<orderEntry type="module" module-name="org.eclipse.paho.android.service" exported="" />
|
||||
<orderEntry type="library" exported="" name="org.eclipse.paho.client.mqttv3-1.1.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" exported="" name="1_org.eclipse.paho.client.mqttv3-1.1.1-SNAPSHOT" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
</module>
|
@ -9,16 +9,18 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<!--<uses-permission android:name="android.permission.READ_PHONE_STATE" />-->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:allowBackup="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/MaterialTheme">
|
||||
android:theme="@style/MaterialTheme"
|
||||
android:supportsRtl="false"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
@ -11,6 +12,7 @@ import org.eclipse.paho.android.sample.model.Subscription;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.android.service.MqttAndroidClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -51,21 +53,21 @@ public class ActionListener implements IMqttActionListener {
|
||||
* The {@link Action} that is associated with this instance of
|
||||
* <code>ActionListener</code>
|
||||
**/
|
||||
private Action action;
|
||||
private final Action action;
|
||||
/**
|
||||
* The arguments passed to be used for formatting strings
|
||||
**/
|
||||
private String[] additionalArgs;
|
||||
private final String[] additionalArgs;
|
||||
|
||||
private Connection connection;
|
||||
private final Connection connection;
|
||||
/**
|
||||
* Handle of the {@link Connection} this action was being executed on
|
||||
**/
|
||||
private String clientHandle;
|
||||
private final String clientHandle;
|
||||
/**
|
||||
* {@link Context} for performing various operations
|
||||
**/
|
||||
private Context context;
|
||||
private final Context context;
|
||||
|
||||
/**
|
||||
* Creates a generic action listener for actions performed form any activity
|
||||
@ -116,7 +118,7 @@ public class ActionListener implements IMqttActionListener {
|
||||
private void publish() {
|
||||
|
||||
Connection c = Connections.getInstance(context).getConnection(clientHandle);
|
||||
String actionTaken = context.getString(R.string.toast_pub_success,
|
||||
@SuppressLint("StringFormatMatches") String actionTaken = context.getString(R.string.toast_pub_success,
|
||||
(Object[]) additionalArgs);
|
||||
c.addAction(actionTaken);
|
||||
Notify.toast(context, actionTaken, Toast.LENGTH_SHORT);
|
||||
@ -213,7 +215,7 @@ public class ActionListener implements IMqttActionListener {
|
||||
*/
|
||||
private void publish(Throwable exception) {
|
||||
Connection c = Connections.getInstance(context).getConnection(clientHandle);
|
||||
String action = context.getString(R.string.toast_pub_failed,
|
||||
@SuppressLint("StringFormatMatches") String action = context.getString(R.string.toast_pub_failed,
|
||||
(Object[]) additionalArgs);
|
||||
c.addAction(action);
|
||||
Notify.toast(context, action, Toast.LENGTH_SHORT);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
public class ActivityConstants {
|
||||
class ActivityConstants {
|
||||
|
||||
/** Bundle key for passing a connection around by it's name **/
|
||||
public static final String CONNECTION_KEY = "CONNECTION_KEY";
|
||||
@ -20,5 +20,5 @@ public class ActivityConstants {
|
||||
|
||||
|
||||
/** Empty String for comparisons **/
|
||||
static final String empty = new String();
|
||||
static final String empty = "";
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@ -59,7 +60,7 @@ public class Connection {
|
||||
private MqttAndroidClient client = null;
|
||||
|
||||
/** Collection of {@link java.beans.PropertyChangeListener} **/
|
||||
private ArrayList<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
|
||||
private final ArrayList<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
|
||||
|
||||
/** The {@link Context} of the application this object is part of**/
|
||||
private Context context = null;
|
||||
@ -75,11 +76,11 @@ public class Connection {
|
||||
|
||||
|
||||
/** The list of this connection's subscriptions **/
|
||||
private Map<String, Subscription> subscriptions = new HashMap<String, Subscription>();
|
||||
private final Map<String, Subscription> subscriptions = new HashMap<String, Subscription>();
|
||||
|
||||
private ArrayList<ReceivedMessage> messageHistory = new ArrayList<ReceivedMessage>();
|
||||
private final ArrayList<ReceivedMessage> messageHistory = new ArrayList<ReceivedMessage>();
|
||||
|
||||
private ArrayList<IReceivedMessageListener> receivedMessageListeners = new ArrayList<IReceivedMessageListener>();
|
||||
private final ArrayList<IReceivedMessageListener> receivedMessageListeners = new ArrayList<IReceivedMessageListener>();
|
||||
|
||||
/**
|
||||
* Connections status for a connection
|
||||
@ -113,7 +114,7 @@ public class Connection {
|
||||
*/
|
||||
public static Connection createConnection(String clientHandle, String clientId, String host, int port, Context context, boolean tlsConnection){
|
||||
|
||||
String uri = null;
|
||||
String uri;
|
||||
if(tlsConnection) {
|
||||
uri = "ssl://" + host + ":" + port;
|
||||
} else {
|
||||
@ -125,7 +126,7 @@ public class Connection {
|
||||
}
|
||||
|
||||
public void updateConnection(String clientId, String host, int port, boolean tlsConnection){
|
||||
String uri = null;
|
||||
String uri;
|
||||
if(tlsConnection) {
|
||||
uri = "ssl://" + host + ":" + port;
|
||||
} else {
|
||||
@ -136,8 +137,7 @@ public class Connection {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.tlsConnection = tlsConnection;
|
||||
MqttAndroidClient client = new MqttAndroidClient(context, uri, clientId);
|
||||
this.client = client;
|
||||
this.client = new MqttAndroidClient(context, uri, clientId);
|
||||
|
||||
}
|
||||
|
||||
@ -153,8 +153,8 @@ public class Connection {
|
||||
* @param client The MqttAndroidClient which communicates with the service for this connection
|
||||
* @param tlsConnection true if the connection is secured by SSL
|
||||
*/
|
||||
public Connection(String clientHandle, String clientId, String host,
|
||||
int port, Context context, MqttAndroidClient client, boolean tlsConnection) {
|
||||
private Connection(String clientHandle, String clientId, String host,
|
||||
int port, Context context, MqttAndroidClient client, boolean tlsConnection) {
|
||||
//generate the client handle from its hash code
|
||||
this.clientHandle = clientHandle;
|
||||
this.clientId = clientId;
|
||||
@ -164,11 +164,10 @@ public class Connection {
|
||||
this.client = client;
|
||||
this.tlsConnection = tlsConnection;
|
||||
history = new ArrayList<String>();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("Client: ");
|
||||
sb.append(clientId);
|
||||
sb.append(" created");
|
||||
addAction(sb.toString());
|
||||
String sb = "Client: " +
|
||||
clientId +
|
||||
" created";
|
||||
addAction(sb);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,8 +177,8 @@ public class Connection {
|
||||
public void addAction(String action) {
|
||||
|
||||
Object[] args = new String[1];
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(context.getString(R.string.connection_dateFormat));
|
||||
args[0] = sdf.format(new Date());
|
||||
DateFormat dateTimeFormatter = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
args[0] = dateTimeFormatter.format(new Date());
|
||||
|
||||
String timestamp = context.getString(R.string.timestamp, args);
|
||||
history.add(action + timestamp);
|
||||
@ -187,26 +186,6 @@ public class Connection {
|
||||
notifyListeners(new PropertyChangeEvent(this, ActivityConstants.historyProperty, null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an array of Spanned items representing the history of this
|
||||
* connection.
|
||||
*
|
||||
* @return an array of history entries
|
||||
*/
|
||||
public Spanned[] history() {
|
||||
|
||||
int i = 0;
|
||||
Spanned[] array = new Spanned[history.size()];
|
||||
|
||||
for (String s : history) {
|
||||
if (s != null) {
|
||||
array[i] = Html.fromHtml(s);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the client handle for this connection
|
||||
* @return client Handle for this connection
|
||||
@ -271,15 +250,6 @@ public class Connection {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given handle refers to this client
|
||||
* @param handle The handle to compare with this clients handle
|
||||
* @return true if the handles match
|
||||
*/
|
||||
public boolean isHandle(String handle) {
|
||||
return clientHandle.equals(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two connection objects for equality
|
||||
* this only takes account of the client handle
|
||||
@ -315,22 +285,6 @@ public class Connection {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the client is in a state of connecting or connected.
|
||||
* @return if the client is connecting or connected
|
||||
*/
|
||||
public boolean isConnectedOrConnecting() {
|
||||
return (status == ConnectionStatus.CONNECTED) || (status == ConnectionStatus.CONNECTING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Client is currently not in an error state
|
||||
* @return true if the client is in not an error state
|
||||
*/
|
||||
public boolean noError() {
|
||||
return status != ConnectionStatus.ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the client which communicates with the org.eclipse.paho.android.service service.
|
||||
* @return the client which communicates with the org.eclipse.paho.android.service service
|
||||
@ -366,20 +320,9 @@ public class Connection {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a registered {@link PropertyChangeListener}
|
||||
* @param listener A reference to the listener to remove
|
||||
*/
|
||||
public void removeChangeListener(PropertyChangeListener listener)
|
||||
{
|
||||
if (listener != null) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify {@link PropertyChangeListener} objects that the object has been updated
|
||||
* @param propertyChangeEvent
|
||||
* @param propertyChangeEvent - The property Change event
|
||||
*/
|
||||
private void notifyListeners(PropertyChangeEvent propertyChangeEvent)
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTabHost;
|
||||
@ -17,10 +16,9 @@ import java.util.Map;
|
||||
|
||||
|
||||
public class ConnectionFragment extends Fragment {
|
||||
Connection connection;
|
||||
FragmentTabHost mTabHost;
|
||||
Switch connectSwitch;
|
||||
boolean connected;
|
||||
private Connection connection;
|
||||
private FragmentTabHost mTabHost;
|
||||
private Switch connectSwitch;
|
||||
|
||||
public ConnectionFragment() {
|
||||
setHasOptionsMenu(true);
|
||||
@ -32,10 +30,8 @@ public class ConnectionFragment extends Fragment {
|
||||
Map<String, Connection> connections = Connections.getInstance(this.getActivity())
|
||||
.getConnections();
|
||||
connection = connections.get(this.getArguments().getString(ActivityConstants.CONNECTION_KEY));
|
||||
connected = this.getArguments().getBoolean(ActivityConstants.CONNECTED, false);
|
||||
boolean connected = this.getArguments().getBoolean(ActivityConstants.CONNECTED, false);
|
||||
|
||||
|
||||
final String name = connection.getId() + "@" + connection.getHostName() + ":" + connection.getPort();
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@ -62,22 +58,12 @@ public class ConnectionFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
public void changeConnectedState(boolean state){
|
||||
private void changeConnectedState(boolean state){
|
||||
mTabHost.getTabWidget().getChildTabViewAt(1).setEnabled(state);
|
||||
mTabHost.getTabWidget().getChildTabViewAt(2).setEnabled(state);
|
||||
connectSwitch.setChecked(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater){
|
||||
inflater.inflate(R.menu.menu_connection, menu);
|
||||
|
@ -1,13 +1,10 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -20,10 +17,7 @@ import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Switch;
|
||||
|
||||
import org.eclipse.paho.android.sample.R;
|
||||
import org.eclipse.paho.android.sample.components.ITextSelectCallback;
|
||||
import org.eclipse.paho.android.sample.components.TextSelectComponent;
|
||||
import org.eclipse.paho.android.sample.internal.Connections;
|
||||
import org.eclipse.paho.android.sample.model.ConnectionModel;
|
||||
|
||||
@ -33,11 +27,6 @@ import java.util.Random;
|
||||
|
||||
public class EditConnectionFragment extends Fragment {
|
||||
|
||||
private Toolbar mToolbar;
|
||||
|
||||
private ConnectionModel initialFormModel;
|
||||
private ConnectionModel updatedFormModel;
|
||||
|
||||
private EditText clientId;
|
||||
private EditText serverHostname;
|
||||
private EditText serverPort;
|
||||
@ -53,15 +42,12 @@ public class EditConnectionFragment extends Fragment {
|
||||
private Spinner lwtQos;
|
||||
private Switch lwtRetain;
|
||||
|
||||
private String connectionHandle;
|
||||
private ConnectionModel formModel;
|
||||
private boolean newConnection = true;
|
||||
|
||||
private static String TAG = "EditConnectionFragment";
|
||||
|
||||
static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static Random random = new Random();
|
||||
static int length = 8;
|
||||
private static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private static final Random random = new Random();
|
||||
private static final int length = 8;
|
||||
|
||||
public EditConnectionFragment() {
|
||||
// Required empty public constructor
|
||||
@ -356,6 +342,7 @@ public class EditConnectionFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void populateFromConnectionModel(ConnectionModel connectionModel) {
|
||||
clientId.setText(connectionModel.getClientId());
|
||||
serverHostname.setText(connectionModel.getServerHostName());
|
||||
@ -395,15 +382,6 @@ public class EditConnectionFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the Initial state of the form to the current state.
|
||||
* If the form has changed, return true.
|
||||
* @return <code>True</code> if the form has changed.
|
||||
*/
|
||||
private boolean checkFormForChanges(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
@ -426,13 +404,4 @@ public class EditConnectionFragment extends Fragment {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
}
|
@ -25,19 +25,12 @@ import org.eclipse.paho.android.sample.model.NavDrawerItem;
|
||||
|
||||
public class FragmentDrawer extends Fragment {
|
||||
|
||||
private static String TAG = FragmentDrawer.class.getSimpleName();
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private NavigationDrawerAdapter adapter;
|
||||
private View containerView;
|
||||
private static String[] titles = null;
|
||||
private FragmentDrawerListener drawerListener;
|
||||
List<NavDrawerItem> data = new ArrayList<NavDrawerItem>();
|
||||
|
||||
private TextView addConnectionTextView ;
|
||||
private TextView helpTextView;
|
||||
private final List<NavDrawerItem> data = new ArrayList<NavDrawerItem>();
|
||||
|
||||
public FragmentDrawer() {
|
||||
|
||||
@ -93,7 +86,7 @@ public class FragmentDrawer extends Fragment {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public List<NavDrawerItem> getData() {
|
||||
private List<NavDrawerItem> getData() {
|
||||
|
||||
|
||||
|
||||
@ -101,38 +94,30 @@ public class FragmentDrawer extends Fragment {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// drawer labels
|
||||
titles = getActivity().getResources().getStringArray(R.array.nav_drawer_labels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflating view layout
|
||||
View layout = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
|
||||
recyclerView = (RecyclerView) layout.findViewById(R.id.drawerList);
|
||||
RecyclerView recyclerView = (RecyclerView) layout.findViewById(R.id.drawerList);
|
||||
|
||||
addConnectionTextView = (TextView) layout.findViewById(R.id.action_add_connection);
|
||||
TextView addConnectionTextView = (TextView) layout.findViewById(R.id.action_add_connection);
|
||||
|
||||
addConnectionTextView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
drawerListener.onAddConnectionSelected(v);
|
||||
drawerListener.onAddConnectionSelected();
|
||||
mDrawerLayout.closeDrawer(containerView);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
helpTextView = (TextView) layout.findViewById(R.id.action_help);
|
||||
TextView helpTextView = (TextView) layout.findViewById(R.id.action_help);
|
||||
|
||||
helpTextView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
drawerListener.onHelpSelected(v);
|
||||
drawerListener.onHelpSelected();
|
||||
mDrawerLayout.closeDrawer(containerView);
|
||||
}
|
||||
});
|
||||
@ -143,15 +128,15 @@ public class FragmentDrawer extends Fragment {
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), recyclerView, new ClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position) {
|
||||
drawerListener.onDrawerItemSelected(view, position);
|
||||
public void onClick(int position) {
|
||||
drawerListener.onDrawerItemSelected(position);
|
||||
mDrawerLayout.closeDrawer(containerView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongClick(View view, int position) {
|
||||
public void onLongClick(int position) {
|
||||
System.out.println("I want to delete: " + position);
|
||||
drawerListener.onDrawerItemLongSelected(view, position);
|
||||
drawerListener.onDrawerItemLongSelected(position);
|
||||
mDrawerLayout.closeDrawer(containerView);
|
||||
}
|
||||
}));
|
||||
@ -193,16 +178,16 @@ public class FragmentDrawer extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
public static interface ClickListener {
|
||||
public void onClick(View view, int position);
|
||||
public interface ClickListener {
|
||||
void onClick(int position);
|
||||
|
||||
public void onLongClick(View view, int position);
|
||||
void onLongClick(int position);
|
||||
}
|
||||
|
||||
static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
|
||||
|
||||
private GestureDetector gestureDetector;
|
||||
private ClickListener clickListener;
|
||||
private final GestureDetector gestureDetector;
|
||||
private final ClickListener clickListener;
|
||||
|
||||
public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
|
||||
this.clickListener = clickListener;
|
||||
@ -216,7 +201,7 @@ public class FragmentDrawer extends Fragment {
|
||||
public void onLongPress(MotionEvent e) {
|
||||
View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
|
||||
if (child != null && clickListener != null) {
|
||||
clickListener.onLongClick(child, recyclerView.getChildPosition(child));
|
||||
clickListener.onLongClick(recyclerView.getChildPosition(child));
|
||||
|
||||
}
|
||||
}
|
||||
@ -228,7 +213,7 @@ public class FragmentDrawer extends Fragment {
|
||||
|
||||
View child = rv.findChildViewUnder(e.getX(), e.getY());
|
||||
if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
|
||||
clickListener.onClick(child, rv.getChildPosition(child));
|
||||
clickListener.onClick(rv.getChildPosition(child));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -246,9 +231,9 @@ public class FragmentDrawer extends Fragment {
|
||||
}
|
||||
|
||||
public interface FragmentDrawerListener {
|
||||
public void onDrawerItemSelected(View view, int position);
|
||||
public void onDrawerItemLongSelected(View view, int position);
|
||||
public void onAddConnectionSelected(View view);
|
||||
public void onHelpSelected(View view);
|
||||
void onDrawerItemSelected(int position);
|
||||
void onDrawerItemLongSelected(int position);
|
||||
void onAddConnectionSelected();
|
||||
void onHelpSelected();
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
@ -25,10 +24,6 @@ import java.util.Map;
|
||||
|
||||
|
||||
public class HelpFragment extends Fragment {
|
||||
Button websiteButton;
|
||||
Button feedbackButton;
|
||||
Switch enableLoggingSwitch;
|
||||
SharedPreferences preferences;
|
||||
|
||||
private static final String TAG = "HelpFragment";
|
||||
|
||||
@ -47,13 +42,6 @@ public class HelpFragment extends Fragment {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
@ -61,10 +49,10 @@ public class HelpFragment extends Fragment {
|
||||
|
||||
final View rootView = inflater.inflate(R.layout.fragment_help, container, false);
|
||||
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(rootView.getContext());
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(rootView.getContext());
|
||||
|
||||
|
||||
websiteButton = (Button) rootView.findViewById(R.id.websiteButton);
|
||||
Button websiteButton = (Button) rootView.findViewById(R.id.websiteButton);
|
||||
websiteButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -74,7 +62,7 @@ public class HelpFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
feedbackButton = (Button) rootView.findViewById(R.id.feedbackButton);
|
||||
Button feedbackButton = (Button) rootView.findViewById(R.id.feedbackButton);
|
||||
feedbackButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -85,7 +73,7 @@ public class HelpFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
enableLoggingSwitch = (Switch) rootView.findViewById(R.id.enable_logging_switch);
|
||||
Switch enableLoggingSwitch = (Switch) rootView.findViewById(R.id.enable_logging_switch);
|
||||
enableLoggingSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
@ -111,16 +99,6 @@ public class HelpFragment extends Fragment {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
|
||||
private String getDebugInfoForEmail(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@ -21,13 +20,10 @@ import java.util.Map;
|
||||
|
||||
public class HistoryFragment extends Fragment {
|
||||
|
||||
ListView messageHistoryListView;
|
||||
MessageListItemAdapter messageListAdapter;
|
||||
Button clearButton;
|
||||
Connection connection;
|
||||
private MessageListItemAdapter messageListAdapter;
|
||||
|
||||
|
||||
ArrayList<ReceivedMessage> messages;
|
||||
private ArrayList<ReceivedMessage> messages;
|
||||
public HistoryFragment() {
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
@ -39,7 +35,7 @@ public class HistoryFragment extends Fragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
Map<String, Connection> connections = Connections.getInstance(this.getActivity())
|
||||
.getConnections();
|
||||
connection = connections.get(this.getArguments().getString(ActivityConstants.CONNECTION_KEY));
|
||||
Connection connection = connections.get(this.getArguments().getString(ActivityConstants.CONNECTION_KEY));
|
||||
System.out.println("History Fragment: " + connection.getId());
|
||||
setHasOptionsMenu(true);
|
||||
messages = connection.getMessages();
|
||||
@ -66,10 +62,10 @@ public class HistoryFragment extends Fragment {
|
||||
View rootView = inflater.inflate(R.layout.fragment_connection_history, container, false);
|
||||
|
||||
messageListAdapter = new MessageListItemAdapter(getActivity(), messages);
|
||||
messageHistoryListView = (ListView) rootView.findViewById(R.id.history_list_view);
|
||||
ListView messageHistoryListView = (ListView) rootView.findViewById(R.id.history_list_view);
|
||||
messageHistoryListView.setAdapter(messageListAdapter);
|
||||
|
||||
clearButton = (Button) rootView.findViewById(R.id.history_clear_button);
|
||||
Button clearButton = (Button) rootView.findViewById(R.id.history_clear_button);
|
||||
clearButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -86,17 +82,6 @@ public class HistoryFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@ -16,29 +15,13 @@ public class HomeFragment extends Fragment {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
|
||||
|
||||
|
||||
// Inflate the layout for this fragment
|
||||
return rootView;
|
||||
return inflater.inflate(R.layout.fragment_home, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
@ -11,10 +10,9 @@ import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
|
||||
import org.eclipse.paho.android.sample.R;
|
||||
import org.eclipse.paho.android.sample.internal.Connections;
|
||||
import org.eclipse.paho.android.sample.model.ConnectionModel;
|
||||
@ -30,14 +28,13 @@ import java.util.Map;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener{
|
||||
|
||||
private Toolbar mToolbar;
|
||||
private FragmentDrawer drawerFragment;
|
||||
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
private ChangeListener changeListener = new ChangeListener();
|
||||
private final ChangeListener changeListener = new ChangeListener();
|
||||
|
||||
private MainActivity mainActivity = this;
|
||||
private final MainActivity mainActivity = this;
|
||||
|
||||
private ArrayList<String> connectionMap;
|
||||
|
||||
@ -46,7 +43,7 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
|
||||
setSupportActionBar(mToolbar);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
@ -63,11 +60,6 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
populateConnectionList();
|
||||
}
|
||||
|
||||
public Context getThemedContext(){
|
||||
return getSupportActionBar().getThemedContext();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void populateConnectionList(){
|
||||
// Clear drawerFragment
|
||||
@ -104,24 +96,24 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
|
||||
|
||||
@Override
|
||||
public void onDrawerItemSelected(View view, int position){
|
||||
public void onDrawerItemSelected(int position){
|
||||
displayView(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerItemLongSelected(View view, int position){
|
||||
public void onDrawerItemLongSelected(int position){
|
||||
displayDeleteView(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddConnectionSelected(View view) {
|
||||
public void onAddConnectionSelected() {
|
||||
Fragment editConnectionFragment = new EditConnectionFragment();
|
||||
String title = "Edit Connection";
|
||||
displayFragment(editConnectionFragment, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHelpSelected(View view) {
|
||||
public void onHelpSelected() {
|
||||
Fragment helpFragment = new HelpFragment();
|
||||
displayFragment(helpFragment, getString(R.string.help_and_feedback));
|
||||
|
||||
@ -130,7 +122,6 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
private void displayDeleteView(int position){
|
||||
if(position == -1){
|
||||
displayFragment(new HomeFragment(), "Home");
|
||||
return;
|
||||
} else {
|
||||
Fragment fragment = new ManageConnectionFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
@ -139,7 +130,6 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
Map<String, Connection> connections = Connections.getInstance(this)
|
||||
.getConnections();
|
||||
Connection connection = connections.get(connectionMap.get(position));
|
||||
String title = connection.getId();
|
||||
displayFragment(fragment, "");
|
||||
}
|
||||
}
|
||||
@ -147,7 +137,6 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
private void displayView(int position){
|
||||
if(position == -1){
|
||||
displayFragment(new HomeFragment(), "Home");
|
||||
return;
|
||||
} else {
|
||||
Fragment fragment = new ConnectionFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
@ -175,10 +164,6 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
}
|
||||
}
|
||||
|
||||
public void setActionBarTitle(String title){
|
||||
getSupportActionBar().setTitle(title);
|
||||
}
|
||||
|
||||
public void updateAndConnect(ConnectionModel model){
|
||||
Map<String, Connection> connections = Connections.getInstance(this)
|
||||
.getConnections();
|
||||
@ -217,7 +202,7 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
|
||||
|
||||
} catch (MqttException ex){
|
||||
|
||||
Log.e(TAG, "Exception occurred updating connection: " + connections.keySet().toString() + " : " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,7 +210,7 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
/**
|
||||
* Takes a {@link ConnectionModel} and uses it to connect
|
||||
* and then persist.
|
||||
* @param model
|
||||
* @param model - The connection Model
|
||||
*/
|
||||
public void persistAndConnect(ConnectionModel model){
|
||||
Log.i(TAG, "Persisting new connection:" + model.getClientHandle());
|
||||
@ -264,7 +249,7 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
}
|
||||
catch (MqttException e) {
|
||||
Log.e(this.getClass().getCanonicalName(),
|
||||
"MqttException Occured", e);
|
||||
"MqttException occurred", e);
|
||||
}
|
||||
|
||||
}
|
||||
@ -310,7 +295,7 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
}
|
||||
catch (MqttException e) {
|
||||
Log.e(this.getClass().getCanonicalName(),
|
||||
"MqttException Occured", e);
|
||||
"MqttException occurred", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,7 +304,7 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
try {
|
||||
connection.getClient().disconnect();
|
||||
} catch( MqttException ex){
|
||||
Log.e(TAG, "Exception occured during disconnect: " + ex.getMessage());
|
||||
Log.e(TAG, "Exception occurred during disconnect: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,20 +318,7 @@ public class MainActivity extends AppCompatActivity implements FragmentDrawer.Fr
|
||||
ActionListener.Action.PUBLISH, connection, actionArgs);
|
||||
connection.getClient().publish(topic, message.getBytes(), qos, retain, null, callback);
|
||||
} catch( MqttException ex){
|
||||
Log.e(TAG, "Exception occured during publish: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void subscribe(Connection connection, String topic, int qos){
|
||||
|
||||
try {
|
||||
String[] actionArgs = new String[2];
|
||||
actionArgs[1] = topic;
|
||||
final ActionListener callback = new ActionListener(this,
|
||||
ActionListener.Action.SUBSCRIBE, connection, actionArgs);
|
||||
connection.getClient().subscribe(topic, qos);
|
||||
} catch( MqttException ex){
|
||||
Log.e(TAG, "Exception occured during subscribe: " + ex.getMessage());
|
||||
Log.e(TAG, "Exception occurred during publish: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
@ -33,9 +32,9 @@ import java.util.Map;
|
||||
|
||||
|
||||
public class ManageConnectionFragment extends Fragment {
|
||||
Connection connection;
|
||||
Map<String, Connection> connections;
|
||||
String connectionKey;
|
||||
private Connection connection;
|
||||
private Map<String, Connection> connections;
|
||||
private String connectionKey;
|
||||
|
||||
|
||||
public ManageConnectionFragment() {
|
||||
@ -97,13 +96,4 @@ public class ManageConnectionFragment extends Fragment {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@ -16,29 +15,13 @@ public class MessagesFragment extends Fragment {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_publish, container, false);
|
||||
|
||||
|
||||
// Inflate the layout for this fragment
|
||||
return rootView;
|
||||
return inflater.inflate(R.layout.fragment_publish, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
}
|
@ -27,12 +27,12 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
* Handles call backs from the MQTT Client
|
||||
*
|
||||
*/
|
||||
public class MqttCallbackHandler implements MqttCallback {
|
||||
class MqttCallbackHandler implements MqttCallback {
|
||||
|
||||
/** {@link Context} for the application used to format and import external strings**/
|
||||
private Context context;
|
||||
private final Context context;
|
||||
/** Client handle to reference the connection that this handler is attached to**/
|
||||
private String clientHandle;
|
||||
private final String clientHandle;
|
||||
|
||||
private static final String TAG = "MqttCallbackHandler";
|
||||
private static final String activityClass = "org.eclipse.paho.android.sample.activity.MainActivity";
|
||||
|
@ -16,19 +16,19 @@ import android.util.Log;
|
||||
|
||||
import org.eclipse.paho.android.service.MqttTraceHandler;
|
||||
|
||||
public class MqttTraceCallback implements MqttTraceHandler {
|
||||
class MqttTraceCallback implements MqttTraceHandler {
|
||||
|
||||
public void traceDebug(java.lang.String arg0, java.lang.String arg1) {
|
||||
Log.i(arg0, arg1);
|
||||
};
|
||||
}
|
||||
|
||||
public void traceError(java.lang.String arg0, java.lang.String arg1) {
|
||||
Log.e(arg0, arg1);
|
||||
};
|
||||
}
|
||||
|
||||
public void traceException(java.lang.String arg0, java.lang.String arg1,
|
||||
java.lang.Exception arg2) {
|
||||
Log.e(arg0, arg1, arg2);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,13 +22,11 @@ import android.widget.Toast;
|
||||
|
||||
import org.eclipse.paho.android.sample.R;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* Provides static methods for creating and showing notifications to the user.
|
||||
*
|
||||
*/
|
||||
public class Notify {
|
||||
class Notify {
|
||||
|
||||
/** Message ID Counter **/
|
||||
private static int MessageID = 0;
|
||||
@ -46,8 +44,6 @@ public class Notify {
|
||||
String ns = Context.NOTIFICATION_SERVICE;
|
||||
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
|
||||
|
||||
Calendar.getInstance().getTime().toString();
|
||||
|
||||
long when = System.currentTimeMillis();
|
||||
|
||||
//get the notification title from the application's strings.xml file
|
||||
@ -83,7 +79,7 @@ public class Notify {
|
||||
* @param text The text the toast should display
|
||||
* @param duration The amount of time for the toast to appear to the user
|
||||
*/
|
||||
static void toast(Context context, CharSequence text, int duration) {
|
||||
static void toast(Context context, CharSequence text, @SuppressWarnings("SameParameterValue") int duration) {
|
||||
Toast toast = Toast.makeText(context, text, duration);
|
||||
toast.show();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Editable;
|
||||
@ -24,12 +23,12 @@ import java.util.Map;
|
||||
|
||||
public class PublishFragment extends Fragment {
|
||||
|
||||
Connection connection;
|
||||
private Connection connection;
|
||||
|
||||
int selectedQos = 0;
|
||||
boolean retainValue = false;
|
||||
String topic = "/test";
|
||||
String message = "Hello world";
|
||||
private int selectedQos = 0;
|
||||
private boolean retainValue = false;
|
||||
private String topic = "/test";
|
||||
private String message = "Hello world";
|
||||
|
||||
public PublishFragment() {
|
||||
// Required empty public constructor
|
||||
@ -130,15 +129,5 @@ public class PublishFragment extends Fragment {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
package org.eclipse.paho.android.sample.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.LayoutInflater;
|
||||
@ -15,7 +14,6 @@ import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Spinner;
|
||||
@ -33,13 +31,12 @@ import java.util.Map;
|
||||
|
||||
public class SubscriptionFragment extends Fragment {
|
||||
|
||||
int temp_qos_value = 0;
|
||||
ListView subscriptionListView;
|
||||
private int temp_qos_value = 0;
|
||||
// --Commented out by Inspection (12/10/2016, 10:22):ListView subscriptionListView;
|
||||
|
||||
ArrayList<Subscription> subscriptions;
|
||||
SubscriptionListItemAdapter adapter;
|
||||
private ArrayList<Subscription> subscriptions;
|
||||
|
||||
Connection connection;
|
||||
private Connection connection;
|
||||
|
||||
public SubscriptionFragment() {
|
||||
// Required empty public constructor
|
||||
@ -71,7 +68,7 @@ public class SubscriptionFragment extends Fragment {
|
||||
});
|
||||
|
||||
ListView subscriptionListView = (ListView) rootView.findViewById(R.id.subscription_list_view);
|
||||
adapter = new SubscriptionListItemAdapter(this.getActivity(), subscriptions);
|
||||
SubscriptionListItemAdapter adapter = new SubscriptionListItemAdapter(this.getActivity(), subscriptions);
|
||||
|
||||
adapter.addOnUnsubscribeListner(new SubscriptionListItemAdapter.OnUnsubscribeListner() {
|
||||
@Override
|
||||
@ -84,16 +81,16 @@ public class SubscriptionFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
});
|
||||
subscriptionListView.setAdapter(adapter);;
|
||||
subscriptionListView.setAdapter(adapter);
|
||||
|
||||
|
||||
// Inflate the layout for this fragment
|
||||
return rootView;
|
||||
}
|
||||
|
||||
protected void showInputDialog(){
|
||||
private void showInputDialog(){
|
||||
LayoutInflater layoutInflater = (LayoutInflater) this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View promptView = layoutInflater.inflate(R.layout.subscription_dialog, null);
|
||||
@SuppressLint("InflateParams") View promptView = layoutInflater.inflate(R.layout.subscription_dialog, null);
|
||||
final EditText topicText = (EditText) promptView.findViewById(R.id.subscription_topic_edit_text);
|
||||
|
||||
final Spinner qos = (Spinner) promptView.findViewById(R.id.subscription_qos_spinner);
|
||||
@ -134,7 +131,6 @@ public class SubscriptionFragment extends Fragment {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
;
|
||||
}).setNegativeButton(R.string.subscribe_cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
@ -146,13 +142,4 @@ public class SubscriptionFragment extends Fragment {
|
||||
alert.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
}
|
@ -2,10 +2,7 @@ package org.eclipse.paho.android.sample.adapter;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.Image;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
@ -20,9 +17,9 @@ import org.eclipse.paho.android.sample.R;
|
||||
import org.eclipse.paho.android.sample.model.NavDrawerItem;
|
||||
|
||||
public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.MyViewHolder> {
|
||||
List<NavDrawerItem> data = Collections.emptyList();
|
||||
private LayoutInflater inflater;
|
||||
private Context context;
|
||||
private List<NavDrawerItem> data = Collections.emptyList();
|
||||
private final LayoutInflater inflater;
|
||||
private final Context context;
|
||||
|
||||
public NavigationDrawerAdapter(Context context, List<NavDrawerItem> data) {
|
||||
this.context = context;
|
||||
@ -30,22 +27,10 @@ public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDraw
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void delete(int position) {
|
||||
data.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
|
||||
private void setConnected(ImageView image){
|
||||
Drawable doneCloud = ContextCompat.getDrawable(context, R.drawable.ic_cloud_done_dark);
|
||||
Drawable offCloud = ContextCompat.getDrawable(context, R.drawable.ic_cloud_off_dark);
|
||||
image.setImageDrawable(doneCloud);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = inflater.inflate(R.layout.nav_drawer_row, parent, false);
|
||||
MyViewHolder holder = new MyViewHolder(view);
|
||||
return holder;
|
||||
return new MyViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,7 +38,6 @@ public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDraw
|
||||
NavDrawerItem current = data.get(position);
|
||||
holder.title.setText(current.getTitle());
|
||||
Drawable doneCloud = ContextCompat.getDrawable(context, R.drawable.ic_cloud_done_dark);
|
||||
Drawable offCloud = ContextCompat.getDrawable(context, R.drawable.ic_cloud_off_dark);
|
||||
holder.icon.setImageDrawable(doneCloud);
|
||||
}
|
||||
|
||||
@ -63,8 +47,8 @@ public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDraw
|
||||
}
|
||||
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView title;
|
||||
ImageView icon;
|
||||
final TextView title;
|
||||
final ImageView icon;
|
||||
|
||||
public MyViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.eclipse.paho.android.sample.components;
|
||||
|
||||
|
||||
public interface ITextSelectCallback {
|
||||
public void onTextUpdate(String updatedText);
|
||||
interface ITextSelectCallback {
|
||||
void onTextUpdate(String updatedText);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.eclipse.paho.android.sample.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -8,9 +9,9 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.eclipse.paho.android.sample.R;
|
||||
import org.eclipse.paho.android.sample.internal.Persistence;
|
||||
import org.eclipse.paho.android.sample.model.ReceivedMessage;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -19,9 +20,6 @@ public class MessageListItemAdapter extends ArrayAdapter<ReceivedMessage>{
|
||||
|
||||
private final Context context;
|
||||
private final ArrayList<ReceivedMessage> messages;
|
||||
TextView messageTextView;
|
||||
TextView topicTextView;
|
||||
TextView dateTextView;
|
||||
|
||||
public MessageListItemAdapter(Context context, ArrayList<ReceivedMessage> messages){
|
||||
super(context, R.layout.message_list_item, messages);
|
||||
@ -30,18 +28,19 @@ public class MessageListItemAdapter extends ArrayAdapter<ReceivedMessage>{
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent){
|
||||
public View getView(final int position, View convertView, @NonNull ViewGroup parent){
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View rowView = inflater.inflate(R.layout.message_list_item, parent, false);
|
||||
topicTextView = (TextView) rowView.findViewById(R.id.message_topic_text);
|
||||
messageTextView = (TextView) rowView.findViewById(R.id.message_text);
|
||||
dateTextView = (TextView) rowView.findViewById(R.id.message_date_text);
|
||||
TextView topicTextView = (TextView) rowView.findViewById(R.id.message_topic_text);
|
||||
TextView messageTextView = (TextView) rowView.findViewById(R.id.message_text);
|
||||
TextView dateTextView = (TextView) rowView.findViewById(R.id.message_date_text);
|
||||
messageTextView.setText(new String(messages.get(position).getMessage().getPayload()));
|
||||
topicTextView.setText(new String("Topic: " + messages.get(position).getTopic()));
|
||||
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
|
||||
String shortDateStamp = format.format(messages.get(position).getTimestamp());
|
||||
dateTextView.setText("Time: " + shortDateStamp);
|
||||
topicTextView.setText(context.getString(R.string.topic_fmt, messages.get(position).getTopic()));
|
||||
DateFormat dateTimeFormatter = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
String shortDateStamp = dateTimeFormatter.format(messages.get(position).getTimestamp());
|
||||
dateTextView.setText(context.getString(R.string.message_time_fmt, shortDateStamp));
|
||||
return rowView;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.eclipse.paho.android.sample.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -27,8 +28,9 @@ public class SubscriptionListItemAdapter extends ArrayAdapter<Subscription>{
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent){
|
||||
public View getView(final int position, View convertView, @NonNull ViewGroup parent){
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View rowView = inflater.inflate(R.layout.subscription_list_item, parent, false);
|
||||
TextView topicTextView = (TextView) rowView.findViewById(R.id.message_text);
|
||||
@ -61,7 +63,7 @@ public class SubscriptionListItemAdapter extends ArrayAdapter<Subscription>{
|
||||
}
|
||||
|
||||
public interface OnUnsubscribeListner{
|
||||
public void onUnsubscribe(Subscription subscription);
|
||||
void onUnsubscribe(Subscription subscription);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,27 +1,18 @@
|
||||
package org.eclipse.paho.android.sample.components;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.TypedArray;
|
||||
import android.text.InputType;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Layout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
@ -36,36 +27,31 @@ public class TextSelectComponent extends RelativeLayout {
|
||||
|
||||
private static final String TAG = "TextSelectComponent";
|
||||
|
||||
private RelativeLayout textSelectLayout;
|
||||
private TextView mainLabel;
|
||||
private TextView subLabel;
|
||||
|
||||
private String inputTitle;
|
||||
private String defaultText;
|
||||
private final TextView subLabel;
|
||||
|
||||
private final String inputTitle;
|
||||
|
||||
|
||||
private String setText;
|
||||
private boolean numberInput;
|
||||
private final boolean numberInput;
|
||||
|
||||
private ArrayList<ITextSelectCallback> registeredCallbacks = new ArrayList<ITextSelectCallback>();
|
||||
private final ArrayList<ITextSelectCallback> registeredCallbacks = new ArrayList<ITextSelectCallback>();
|
||||
|
||||
Context context;
|
||||
private final Context context;
|
||||
|
||||
public TextSelectComponent(Context context, AttributeSet attr) {
|
||||
super(context, attr);
|
||||
this.context = context;
|
||||
final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater.inflate(R.layout.text_select, this);
|
||||
this.mainLabel = (TextView) findViewById(R.id.mainLabel);
|
||||
TextView mainLabel = (TextView) findViewById(R.id.mainLabel);
|
||||
this.subLabel = (TextView) findViewById(R.id.subLabel);
|
||||
this.textSelectLayout = (RelativeLayout) findViewById(R.id.container);
|
||||
RelativeLayout textSelectLayout = (RelativeLayout) findViewById(R.id.container);
|
||||
final TypedArray attributeArray = context.obtainStyledAttributes(attr, R.styleable.TextSelectComponent);
|
||||
this.mainLabel.setText(attributeArray.getString(R.styleable.TextSelectComponent_main_label));
|
||||
mainLabel.setText(attributeArray.getString(R.styleable.TextSelectComponent_main_label));
|
||||
this.subLabel.setText(attributeArray.getString(R.styleable.TextSelectComponent_default_value));
|
||||
this.inputTitle = attributeArray.getString(R.styleable.TextSelectComponent_input_title);
|
||||
this.defaultText = attributeArray.getString(R.styleable.TextSelectComponent_default_value);
|
||||
setText = this.defaultText;
|
||||
setText = attributeArray.getString(R.styleable.TextSelectComponent_default_value);
|
||||
this.numberInput = attributeArray.getBoolean(R.styleable.TextSelectComponent_number, false);
|
||||
textSelectLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -73,17 +59,18 @@ public class TextSelectComponent extends RelativeLayout {
|
||||
showInputDialog();
|
||||
}
|
||||
});
|
||||
attributeArray.recycle();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void showInputDialog(){
|
||||
private void showInputDialog(){
|
||||
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View promptView = layoutInflater.inflate(R.layout.text_input_dialog, null);
|
||||
@SuppressLint("InflateParams") View promptView = layoutInflater.inflate(R.layout.text_input_dialog, null);
|
||||
TextView promptText = (TextView) promptView.findViewById(R.id.textView);
|
||||
promptText.setText(inputTitle);
|
||||
final EditText promptEditText = (EditText) promptView.findViewById(R.id.edittext);
|
||||
if(this.numberInput == true){
|
||||
if(this.numberInput){
|
||||
Log.i(TAG, "NUMBER INPUT");
|
||||
promptEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
} else {
|
||||
|
@ -61,7 +61,7 @@ public class Connections {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an already initalised instance of <code>Connections</code>, if Connections has yet to be created, it will
|
||||
* Returns an already initialised instance of <code>Connections</code>, if Connections has yet to be created, it will
|
||||
* create and return that instance.
|
||||
* @param context The applications context used to create the <code>Connections</code> object if it is not already initialised
|
||||
* @return <code>Connections</code> instance
|
||||
@ -98,20 +98,21 @@ public class Connections {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fully initialised <code>MqttAndroidClient</code> for the parameters given
|
||||
* @param context The Applications context
|
||||
* @param serverURI The ServerURI to connect to
|
||||
* @param clientId The clientId for this client
|
||||
* @return new instance of MqttAndroidClient
|
||||
*/
|
||||
public MqttAndroidClient createClient(Context context, String serverURI, String clientId){
|
||||
MqttAndroidClient client = new MqttAndroidClient(context, serverURI, clientId);
|
||||
return client;
|
||||
}
|
||||
// --Commented out by Inspection START (12/10/2016, 10:21):
|
||||
// /**
|
||||
// * Create a fully initialised <code>MqttAndroidClient</code> for the parameters given
|
||||
// * @param context The Applications context
|
||||
// * @param serverURI The ServerURI to connect to
|
||||
// * @param clientId The clientId for this client
|
||||
// * @return new instance of MqttAndroidClient
|
||||
// */
|
||||
// public MqttAndroidClient createClient(Context context, String serverURI, String clientId){
|
||||
// return new MqttAndroidClient(context, serverURI, clientId);
|
||||
// }
|
||||
// --Commented out by Inspection STOP (12/10/2016, 10:21)
|
||||
|
||||
/**
|
||||
* Get all the connections assiciated with this <code>Connections</code> object.
|
||||
* Get all the connections associated with this <code>Connections</code> object.
|
||||
* @return <code>Map</code> of connections
|
||||
*/
|
||||
public Map<String, Connection> getConnections(){
|
||||
@ -135,12 +136,7 @@ public class Connections {
|
||||
*/
|
||||
public void updateConnection(Connection connection){
|
||||
connections.put(connection.handle(), connection);
|
||||
try{
|
||||
persistence.updateConnection(connection);
|
||||
} catch(PersistenceException e){
|
||||
// TODO - Handle this update error
|
||||
e.printStackTrace();
|
||||
}
|
||||
persistence.updateConnection(connection);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,10 +2,7 @@ package org.eclipse.paho.android.sample.internal;
|
||||
|
||||
import org.eclipse.paho.android.sample.model.ReceivedMessage;
|
||||
|
||||
/**
|
||||
* Created by james on 12/10/15.
|
||||
*/
|
||||
public interface IReceivedMessageListener {
|
||||
|
||||
public void onMessageReceived(ReceivedMessage message);
|
||||
void onMessageReceived(ReceivedMessage message);
|
||||
}
|
@ -25,64 +25,64 @@ import java.util.List;
|
||||
*/
|
||||
public class Persistence extends SQLiteOpenHelper implements BaseColumns {
|
||||
|
||||
public static final String TAG = "Persistence";
|
||||
private static final String TAG = "Persistence";
|
||||
|
||||
/** The version of the database **/
|
||||
public static final int DATABASE_VERSION = 1;
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
/** The name of the database file **/
|
||||
public static final String DATABASE_NAME = "connections.db";
|
||||
private static final String DATABASE_NAME = "connections.db";
|
||||
|
||||
/** The name of the connections table **/
|
||||
public static final String TABLE_CONNECTIONS = "connections";
|
||||
private static final String TABLE_CONNECTIONS = "connections";
|
||||
|
||||
|
||||
|
||||
/** Table column for client handle **/
|
||||
public static final String COLUMN_CLIENT_HANDLE = "clientHandle";
|
||||
private static final String COLUMN_CLIENT_HANDLE = "clientHandle";
|
||||
|
||||
/** Table column for host **/
|
||||
public static final String COLUMN_HOST = "host";
|
||||
private static final String COLUMN_HOST = "host";
|
||||
/** Table column for client id **/
|
||||
public static final String COLUMN_client_ID = "clientID";
|
||||
private static final String COLUMN_client_ID = "clientID";
|
||||
/** Table column for port **/
|
||||
public static final String COLUMN_port = "port";
|
||||
private static final String COLUMN_port = "port";
|
||||
/** Table column for ssl enabled**/
|
||||
public static final String COLUMN_ssl = "ssl";
|
||||
private static final String COLUMN_ssl = "ssl";
|
||||
|
||||
//connection options
|
||||
/** Table column for client's timeout**/
|
||||
public static final String COLUMN_TIME_OUT = "timeout";
|
||||
private static final String COLUMN_TIME_OUT = "timeout";
|
||||
/** Table column for client's keepalive **/
|
||||
public static final String COLUMN_KEEP_ALIVE = "keepalive";
|
||||
private static final String COLUMN_KEEP_ALIVE = "keepalive";
|
||||
/** Table column for the client's username**/
|
||||
public static final String COLUMN_USER_NAME = "username";
|
||||
private static final String COLUMN_USER_NAME = "username";
|
||||
/** Table column for the client's password**/
|
||||
public static final String COLUMN_PASSWORD = "password";
|
||||
private static final String COLUMN_PASSWORD = "password";
|
||||
/** Table column for clean session **/
|
||||
public static final String COLUMN_CLEAN_SESSION = "cleanSession";
|
||||
private static final String COLUMN_CLEAN_SESSION = "cleanSession";
|
||||
/** Table column for **/
|
||||
|
||||
//last will
|
||||
/** Table column for last will topic **/
|
||||
public static final String COLUMN_TOPIC = "topic";
|
||||
private static final String COLUMN_TOPIC = "topic";
|
||||
/** Table column for the last will message payload **/
|
||||
public static final String COLUMN_MESSAGE = "message";
|
||||
private static final String COLUMN_MESSAGE = "message";
|
||||
/** Table column for the last will message qos **/
|
||||
public static final String COLUMN_QOS = "qos";
|
||||
private static final String COLUMN_QOS = "qos";
|
||||
/** Table column for the retained state of the message **/
|
||||
public static final String COLUMN_RETAINED = "retained";
|
||||
private static final String COLUMN_RETAINED = "retained";
|
||||
|
||||
|
||||
/** The name of the subscriptions table **/
|
||||
public static final String TABLE_SUBSCRIPTIONS = "subscriptions";
|
||||
private static final String TABLE_SUBSCRIPTIONS = "subscriptions";
|
||||
|
||||
/** Table column for subscription topic **/
|
||||
public static final String SUBSCRIPTIONS_COLUMN_TOPIC = "topic";
|
||||
private static final String SUBSCRIPTIONS_COLUMN_TOPIC = "topic";
|
||||
/** Table column for the subscription qos **/
|
||||
public static final String SUBSCRIPTIONS_COLUMN_QOS = "qos";
|
||||
private static final String SUBSCRIPTIONS_COLUMN_QOS = "qos";
|
||||
/** Table column for the subscription enable notification setting **/
|
||||
public static final String SUBSCRIPTIONS_COLUMN_NOTIFY = "notify";
|
||||
private static final String SUBSCRIPTIONS_COLUMN_NOTIFY = "notify";
|
||||
|
||||
|
||||
//sql lite data types
|
||||
@ -182,7 +182,7 @@ public class Persistence extends SQLiteOpenHelper implements BaseColumns {
|
||||
if (newRowId == -1) {
|
||||
throw new PersistenceException("Failed to persist connection: " + connection.handle());
|
||||
}
|
||||
else { //Successfully persisted assigning persistecneID
|
||||
else { //Successfully persisted assigning persistenceID
|
||||
connection.assignPersistenceId(newRowId);
|
||||
}
|
||||
}
|
||||
@ -191,15 +191,15 @@ public class Persistence extends SQLiteOpenHelper implements BaseColumns {
|
||||
* Updates a {@link Connection} in the database
|
||||
* @param connection {@link Connection} to update
|
||||
*/
|
||||
public void updateConnection(Connection connection) throws PersistenceException{
|
||||
public void updateConnection(Connection connection) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String whereClause = _ID + "=?";
|
||||
String[] whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(connection.persistenceId());
|
||||
int rowsUpdated = db.update(TABLE_CONNECTIONS, getValues(connection), whereClause, whereArgs);
|
||||
db.update(TABLE_CONNECTIONS, getValues(connection), whereClause, whereArgs);
|
||||
}
|
||||
|
||||
ContentValues getValues(Connection connection){
|
||||
private ContentValues getValues(Connection connection){
|
||||
MqttConnectOptions conOpts = connection.getConnectionOptions();
|
||||
MqttMessage lastWill = conOpts.getWillMessage();
|
||||
ContentValues values = new ContentValues();
|
||||
@ -248,7 +248,7 @@ public class Persistence extends SQLiteOpenHelper implements BaseColumns {
|
||||
long newRowId = db.insert(TABLE_SUBSCRIPTIONS, null, values);
|
||||
db.close();
|
||||
if(newRowId == -1){
|
||||
throw new PersistenceException("Failed to persist subcription: " + subscription.toString());
|
||||
throw new PersistenceException("Failed to persist subscription: " + subscription.toString());
|
||||
} else {
|
||||
subscription.setPersistenceId(newRowId);
|
||||
return newRowId;
|
||||
@ -318,7 +318,7 @@ public class Persistence extends SQLiteOpenHelper implements BaseColumns {
|
||||
|
||||
Cursor c = db.query(TABLE_CONNECTIONS, connectionColumns, null, null, null, null, sort);
|
||||
ArrayList<Connection> list = new ArrayList<Connection>(c.getCount());
|
||||
Connection connection = null;
|
||||
Connection connection;
|
||||
for (int i = 0; i < c.getCount(); i++) {
|
||||
if (!c.moveToNext()) { //move to the next item throw persistence exception, if it fails
|
||||
throw new PersistenceException("Failed restoring connection - count: " + c.getCount() + "loop iteration: " + i);
|
||||
@ -385,6 +385,7 @@ public class Persistence extends SQLiteOpenHelper implements BaseColumns {
|
||||
Log.d(TAG, "Restoring Subscription: " + sub.toString());
|
||||
subscriptions.add(sub);
|
||||
}
|
||||
sub_c.close();
|
||||
|
||||
connection.setSubscriptions(subscriptions);
|
||||
|
||||
|
@ -1,10 +1,6 @@
|
||||
package org.eclipse.paho.android.sample.model;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import org.eclipse.paho.android.sample.activity.ActivityConstants;
|
||||
import org.eclipse.paho.android.sample.activity.Connection;
|
||||
|
||||
public class ConnectionModel {
|
||||
@ -25,25 +21,23 @@ public class ConnectionModel {
|
||||
private static final String LWT_QOS = "LWT_QOS";
|
||||
private static final String LWT_RETAIN = "LWT_RETAIN";
|
||||
|
||||
private static final String TAG = "ConnectionModel";
|
||||
|
||||
|
||||
private String clientHandle = new String();
|
||||
private String clientHandle = "";
|
||||
private String clientId = "AndroidExampleClient";
|
||||
private String serverHostName = "iot.eclipse.org";
|
||||
private int serverPort = 1883;
|
||||
private boolean cleanSession = true;
|
||||
private String username = new String();
|
||||
private String password = new String();
|
||||
private String username = "";
|
||||
private String password = "";
|
||||
|
||||
|
||||
private boolean tlsConnection = false;
|
||||
private String tlsServerKey = new String();
|
||||
private String tlsClientKey = new String();
|
||||
private String tlsServerKey = "";
|
||||
private String tlsClientKey = "";
|
||||
private int timeout = 80;
|
||||
private int keepAlive = 200;
|
||||
private String lwtTopic = new String();
|
||||
private String lwtMessage = new String();
|
||||
private String lwtTopic = "";
|
||||
private String lwtMessage = "";
|
||||
private int lwtQos = 0;
|
||||
private boolean lwtRetain = false;
|
||||
|
||||
@ -62,14 +56,14 @@ public class ConnectionModel {
|
||||
cleanSession = connection.getConnectionOptions().isCleanSession();
|
||||
|
||||
if(connection.getConnectionOptions().getUserName() == null){
|
||||
username = new String();
|
||||
username = "";
|
||||
}else {
|
||||
username = connection.getConnectionOptions().getUserName();
|
||||
}
|
||||
if(connection.getConnectionOptions().getPassword() != null) {
|
||||
password = new String(connection.getConnectionOptions().getPassword());
|
||||
} else {
|
||||
password = new String();
|
||||
password = "";
|
||||
}
|
||||
tlsServerKey = "--- TODO ---";
|
||||
tlsClientKey = "--- TODO ---";
|
||||
@ -77,7 +71,7 @@ public class ConnectionModel {
|
||||
keepAlive = connection.getConnectionOptions().getKeepAliveInterval();
|
||||
|
||||
if(connection.getConnectionOptions().getWillDestination() == null){
|
||||
lwtTopic = new String();
|
||||
lwtTopic = "";
|
||||
} else {
|
||||
lwtTopic = connection.getConnectionOptions().getWillDestination();
|
||||
}
|
||||
@ -86,56 +80,13 @@ public class ConnectionModel {
|
||||
lwtQos = connection.getConnectionOptions().getWillMessage().getQos();
|
||||
lwtRetain = connection.getConnectionOptions().getWillMessage().isRetained();
|
||||
} else {
|
||||
lwtMessage = new String();
|
||||
lwtMessage = "";
|
||||
lwtQos = 0;
|
||||
lwtRetain = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ConnectionModel(Bundle connectionBundle) {
|
||||
|
||||
clientHandle = connectionBundle.getString(CLIENT_HANDLE);
|
||||
clientId = connectionBundle.getString(CLIENT_ID);
|
||||
serverHostName = connectionBundle.getString(HOST_NAME);
|
||||
serverPort = connectionBundle.getInt(PORT);
|
||||
cleanSession = connectionBundle.getBoolean(CLEAN_SESSION);
|
||||
username = connectionBundle.getString(USERNAME);
|
||||
password = connectionBundle.getString(PASSWORD);
|
||||
tlsServerKey = connectionBundle.getString(TLS_SERVER_KEY);
|
||||
tlsClientKey = connectionBundle.getString(TLS_CLIENT_KEY);
|
||||
timeout = connectionBundle.getInt(TIMEOUT);
|
||||
keepAlive = connectionBundle.getInt(KEEP_ALIVE);
|
||||
lwtTopic = connectionBundle.getString(LWT_TOPIC);
|
||||
lwtMessage = connectionBundle.getString(LWT_MESSAGE);
|
||||
lwtQos = connectionBundle.getInt(LWT_QOS);
|
||||
lwtRetain = connectionBundle.getBoolean(LWT_RETAIN);
|
||||
|
||||
}
|
||||
|
||||
public Bundle getConnectionBundle(){
|
||||
|
||||
Bundle connectionBundle = new Bundle();
|
||||
connectionBundle.putString(CLIENT_HANDLE, clientHandle);
|
||||
connectionBundle.putString(CLIENT_ID, clientId);
|
||||
connectionBundle.putString(HOST_NAME, serverHostName);
|
||||
connectionBundle.putInt(PORT, serverPort);
|
||||
connectionBundle.putBoolean(CLEAN_SESSION, cleanSession);
|
||||
connectionBundle.putString(USERNAME, username);
|
||||
connectionBundle.putString(PASSWORD, password);
|
||||
connectionBundle.putString(TLS_SERVER_KEY, tlsServerKey);
|
||||
connectionBundle.putString(TLS_CLIENT_KEY, tlsClientKey);
|
||||
connectionBundle.putInt(TIMEOUT, timeout);
|
||||
connectionBundle.putInt(KEEP_ALIVE, keepAlive);
|
||||
connectionBundle.putString(LWT_TOPIC, lwtTopic);
|
||||
connectionBundle.putString(LWT_MESSAGE, lwtMessage);
|
||||
connectionBundle.putInt(LWT_QOS, lwtQos);
|
||||
connectionBundle.putBoolean(LWT_RETAIN, lwtRetain);
|
||||
|
||||
return connectionBundle;
|
||||
|
||||
}
|
||||
|
||||
public String getClientHandle() {
|
||||
return clientHandle;
|
||||
}
|
||||
|
@ -6,49 +6,19 @@ import org.eclipse.paho.android.sample.activity.Connection;
|
||||
public class NavDrawerItem {
|
||||
private boolean showNotify;
|
||||
private String title;
|
||||
private String subTitle;
|
||||
private String handle;
|
||||
|
||||
public NavDrawerItem(){
|
||||
|
||||
}
|
||||
|
||||
public NavDrawerItem(Connection connection){
|
||||
this.title = connection.getId();
|
||||
this.subTitle = connection.getHostName();
|
||||
this.handle = connection.handle();
|
||||
if(!connection.isConnected()){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public NavDrawerItem(boolean showNotify, String title){
|
||||
this.showNotify = showNotify;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public boolean isShowNotify(){
|
||||
return showNotify;
|
||||
}
|
||||
|
||||
public void setShowNotify(boolean showNotify){
|
||||
this.showNotify = showNotify;
|
||||
}
|
||||
|
||||
public String getTitle(){
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title){
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
public void setHandle(String handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ public class ReceivedMessage {
|
||||
this.timestamp = new Date();
|
||||
}
|
||||
|
||||
String topic;
|
||||
MqttMessage message;
|
||||
Date timestamp;
|
||||
private final String topic;
|
||||
private final MqttMessage message;
|
||||
private final Date timestamp;
|
||||
|
||||
public String getTopic() {
|
||||
return topic;
|
||||
|
Before Width: | Height: | Size: 526 B |
Before Width: | Height: | Size: 288 B |
Before Width: | Height: | Size: 526 B |
Before Width: | Height: | Size: 894 B |
Before Width: | Height: | Size: 563 B |
Before Width: | Height: | Size: 330 B |
Before Width: | Height: | Size: 194 B |
Before Width: | Height: | Size: 313 B |
Before Width: | Height: | Size: 566 B |
Before Width: | Height: | Size: 374 B |
Before Width: | Height: | Size: 558 B |
Before Width: | Height: | Size: 297 B |
Before Width: | Height: | Size: 751 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 745 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 503 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.2 KiB |
@ -1,295 +0,0 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:paho="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/container_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbar"
|
||||
layout="@layout/toolbar" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container_body"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentStart="true">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- General Settings -->
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_general_label"
|
||||
style="@style/HeaderText"
|
||||
android:id="@+id/generalTextView" />
|
||||
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/client_id_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/generalTextView"
|
||||
paho:main_label="@string/add_connection_client_id_label"
|
||||
paho:input_title="@string/add_connection_client_id_title"
|
||||
paho:default_value="@string/add_connection_client_id_default"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider1"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/client_id_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/server_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider1"
|
||||
paho:main_label="@string/add_connection_server_label"
|
||||
paho:input_title="@string/add_connection_server_title"
|
||||
paho:default_value="@string/add_connection_server_default"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider2"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/server_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/port_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider2"
|
||||
paho:main_label="@string/add_connection_port_label"
|
||||
paho:input_title="@string/add_connection_port_title"
|
||||
paho:default_value="@string/add_connection_port_default"
|
||||
paho:number="true"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider3"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/port_group" />
|
||||
|
||||
|
||||
<Switch
|
||||
android:text="@string/add_connection_clean_session_label"
|
||||
android:id="@+id/clean_session_switch"
|
||||
android:layout_below="@+id/divider3"
|
||||
style="@style/Switch" />
|
||||
|
||||
<!-- Advanced Settings -->
|
||||
<!-- General Settings -->
|
||||
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_advanced_label"
|
||||
style="@style/HeaderText"
|
||||
android:layout_below="@+id/clean_session_switch"
|
||||
android:id="@+id/advancedTextView" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/username_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/advancedTextView"
|
||||
paho:main_label="@string/add_connection_username_label"
|
||||
paho:input_title="@string/add_connection_username_title"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider4"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/username_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/password_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider4"
|
||||
paho:main_label="@string/add_connection_password_label"
|
||||
paho:input_title="@string/add_connection_password_title"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider5"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/password_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/tls_server_key"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider5"
|
||||
paho:main_label="@string/add_connection_tls_server_key_label"
|
||||
paho:input_title="@string/add_connection_tls_server_key_title"
|
||||
paho:default_value=""
|
||||
paho:number="true"/>
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/tls_client_key"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/tls_server_key"
|
||||
paho:main_label="@string/add_connection_tls_client_key_label"
|
||||
paho:input_title="@string/add_connection_tls_client_key_title"
|
||||
paho:default_value=""
|
||||
paho:number="true"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider6"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/tls_client_key" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/timeout_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider6"
|
||||
paho:main_label="@string/add_connection_timeout_label"
|
||||
paho:input_title="@string/add_connection_timeout_title"
|
||||
paho:default_value="@string/add_connection_timeout_default"
|
||||
paho:number="true"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider7"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/timeout_group" />
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/keep_alive_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider7"
|
||||
paho:main_label="@string/add_connection_keepalive_label"
|
||||
paho:input_title="@string/add_connection_keepalive_title"
|
||||
paho:default_value="@string/add_connection_keepalive_default"
|
||||
paho:number="true"/>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Last Will & Testament -->
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_lwt_label"
|
||||
style="@style/HeaderText"
|
||||
android:layout_below="@+id/keep_alive_group"
|
||||
android:id="@+id/lwtTextView" />
|
||||
|
||||
|
||||
<org.eclipse.paho.android.sample.components.TextSelectComponent
|
||||
android:id="@+id/topic_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/lwtTextView"
|
||||
paho:main_label="@string/add_connection_lwt_topic_label"
|
||||
paho:input_title="@string/add_connection_lwt_topic_title"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider8"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/topic_group" />
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lwt_message_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/divider8">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lwt_message_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_message_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:inputType="textMultiLine"
|
||||
android:ems="10"
|
||||
android:lines="4"
|
||||
android:id="@+id/lwt_message"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
<View
|
||||
android:id="@+id/divider9"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/lwt_message_group" />
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lwt_qos_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/divider9">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lwt_qos_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_qos_label"/>
|
||||
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/lwt_qos_spinner"
|
||||
|
||||
android:layout_centerHorizontal="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider10"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/lwt_qos_group" />
|
||||
|
||||
<Switch
|
||||
android:text="@string/add_connection_lwt_retain_label"
|
||||
android:id="@+id/retain_switch"
|
||||
android:layout_below="@+id/divider10"
|
||||
style="@style/Switch" />
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"/>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
||||
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
@ -12,13 +12,14 @@
|
||||
android:layout_height="fill_parent"
|
||||
android:id="@+id/history_list_view"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_above="@+id/history_clear_button"
|
||||
android:choiceMode="singleChoice"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Clear"
|
||||
android:text="@string/connection_clear"
|
||||
android:id="@+id/history_clear_button"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
@ -1,418 +1,430 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="org.eclipse.paho.android.sample.activity.HomeFragment">
|
||||
tools:context="org.eclipse.paho.android.sample.activity.HomeFragment"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_alignParentStart="true">
|
||||
<!-- General Settings -->
|
||||
|
||||
<RelativeLayout
|
||||
<TextView
|
||||
android:text="@string/add_connection_general_label"
|
||||
style="@style/HeaderText"
|
||||
android:id="@+id/generalTextView" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/client_id_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- General Settings -->
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/generalTextView">
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_general_label"
|
||||
style="@style/HeaderText"
|
||||
android:id="@+id/generalTextView" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/client_id_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/client_id_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/generalTextView">
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_client_id_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/client_id_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_client_id_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/client_id"
|
||||
android:text="@string/add_connection_client_id_default"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider1"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/client_id_group" />
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/server_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider1">
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/client_id"
|
||||
android:text="@string/add_connection_client_id_default"
|
||||
android:inputType="text"/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/hostname_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_server_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/hostname"
|
||||
android:text="@string/add_connection_server_default"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider2"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/server_group" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/port_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider2">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_port_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:inputType="number"
|
||||
android:maxLength="5"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/add_connection_port"
|
||||
android:text="@integer/default_port"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider3"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/port_group" />
|
||||
<View
|
||||
android:id="@+id/divider1"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/client_id_group" />
|
||||
|
||||
|
||||
<Switch
|
||||
android:text="@string/add_connection_clean_session_label"
|
||||
android:id="@+id/clean_session_switch"
|
||||
android:layout_below="@+id/divider3"
|
||||
style="@style/Switch" />
|
||||
|
||||
<!-- Advanced Settings -->
|
||||
<!-- General Settings -->
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/server_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider1">
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_advanced_label"
|
||||
style="@style/HeaderText"
|
||||
android:layout_below="@+id/clean_session_switch"
|
||||
android:id="@+id/advancedTextView" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/username_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/hostname_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/advancedTextView">
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_server_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/username_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_username_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/username"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider4"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/username_group" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/password_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider4">
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/hostname"
|
||||
android:text="@string/add_connection_server_default"
|
||||
android:inputType="text"/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/password_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_password_label"/>
|
||||
<View
|
||||
android:id="@+id/divider2"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/server_group" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/password"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider5"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/password_group" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tls_server_key_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider5">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tls_server_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_tls_server_key_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/tls_server_key"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tls_client_key_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/tls_server_key_group">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tls_client_key_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_tls_client_key_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/tls_client_key"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider6"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/tls_client_key_group" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/timeout_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider6">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timeout_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_timeout_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:inputType="number"
|
||||
android:maxLength="5"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/timeout"
|
||||
android:text="@integer/default_timeout"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider7"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/timeout_group" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/keep_alive_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider7">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/keepalive_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_keepalive_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:inputType="number"
|
||||
android:maxLength="5"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/keepalive"
|
||||
android:text="@integer/default_keep_alive"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Last Will & Testament -->
|
||||
<LinearLayout
|
||||
android:id="@+id/port_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider2">
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_lwt_label"
|
||||
style="@style/HeaderText"
|
||||
android:layout_below="@+id/keep_alive_group"
|
||||
android:id="@+id/lwtTextView" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/topic_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/message_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/lwtTextView">
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_port_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/topic_group_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_topic_label"/>
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:inputType="number"
|
||||
android:maxLength="5"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/add_connection_port"
|
||||
android:text="@integer/default_port"/>
|
||||
</LinearLayout>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/lwt_topic"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider8"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/topic_group" />
|
||||
<View
|
||||
android:id="@+id/divider3"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/port_group" />
|
||||
|
||||
|
||||
<Switch
|
||||
android:text="@string/add_connection_clean_session_label"
|
||||
android:id="@+id/clean_session_switch"
|
||||
android:layout_below="@+id/divider3"
|
||||
style="@style/Switch" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lwt_message_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/divider8">
|
||||
<!-- Advanced Settings -->
|
||||
<!-- General Settings -->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lwt_message_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_message_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:inputType="textMultiLine"
|
||||
android:ems="10"
|
||||
android:lines="4"
|
||||
android:id="@+id/lwt_message"/>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:text="@string/add_connection_advanced_label"
|
||||
style="@style/HeaderText"
|
||||
android:layout_below="@+id/clean_session_switch"
|
||||
android:id="@+id/advancedTextView" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/username_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/advancedTextView">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/username_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_username_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/username"
|
||||
android:inputType="text"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider4"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/username_group" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/password_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider4">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/password_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_password_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/password"
|
||||
android:inputType="text"
|
||||
tools:ignore="TextFields" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider5"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/password_group" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tls_server_key_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider5">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tls_server_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_tls_server_key_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/tls_server_key"
|
||||
android:inputType="text"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tls_client_key_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/tls_server_key_group">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tls_client_key_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_tls_client_key_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/tls_client_key"
|
||||
android:inputType="text"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider6"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/tls_client_key_group" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/timeout_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider6">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timeout_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_timeout_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:inputType="number"
|
||||
android:maxLength="5"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/timeout"
|
||||
android:text="@integer/default_timeout"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider7"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/timeout_group" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/keep_alive_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/divider7">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/keepalive_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_keepalive_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:inputType="number"
|
||||
android:maxLength="5"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/keepalive"
|
||||
android:text="@integer/default_keep_alive"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
<View
|
||||
android:id="@+id/divider9"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/lwt_message_group" />
|
||||
<!-- Last Will & Testament -->
|
||||
|
||||
<TextView
|
||||
android:text="@string/add_connection_lwt_label"
|
||||
style="@style/HeaderText"
|
||||
android:layout_below="@+id/keep_alive_group"
|
||||
android:id="@+id/lwtTextView" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/topic_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/lwtTextView">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/topic_group_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_topic_label"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:id="@+id/lwt_topic"
|
||||
android:inputType="text"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider8"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/topic_group" />
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lwt_qos_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/divider9">
|
||||
<LinearLayout
|
||||
android:id="@+id/lwt_message_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/divider8">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lwt_qos_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_qos_label"/>
|
||||
<TextView
|
||||
android:id="@+id/lwt_message_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_message_label"/>
|
||||
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/lwt_qos_spinner"
|
||||
|
||||
android:layout_centerHorizontal="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider10"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/lwt_qos_group" />
|
||||
|
||||
<Switch
|
||||
android:text="@string/add_connection_lwt_retain_label"
|
||||
android:id="@+id/retain_switch"
|
||||
android:layout_below="@+id/divider10"
|
||||
style="@style/Switch" />
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:inputType="textMultiLine"
|
||||
android:ems="10"
|
||||
android:lines="4"
|
||||
android:id="@+id/lwt_message"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"/>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
<View
|
||||
android:id="@+id/divider9"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/lwt_message_group" />
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lwt_qos_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/divider9">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lwt_qos_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/spinnerTextFieldLabel"
|
||||
android:text="@string/add_connection_lwt_qos_label"/>
|
||||
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/lwt_qos_spinner"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider10"
|
||||
style="@style/Divider"
|
||||
android:layout_below="@+id/lwt_qos_group" />
|
||||
|
||||
<Switch
|
||||
android:text="@string/add_connection_lwt_retain_label"
|
||||
android:id="@+id/retain_switch"
|
||||
android:layout_below="@+id/divider10"
|
||||
style="@style/Switch" />
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"/>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
@ -3,7 +3,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="org.eclipse.paho.android.sample.activity.FriendsFragment">
|
||||
tools:context="org.eclipse.paho.android.sample.activity.HelpFragment">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
@ -23,7 +23,9 @@
|
||||
android:text="@string/help_title"
|
||||
android:textStyle="bold"
|
||||
android:layout_alignBottom="@+id/imageView"
|
||||
android:layout_alignParentStart="true" />
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
/>
|
||||
|
||||
|
||||
<Button
|
||||
@ -49,10 +51,9 @@
|
||||
android:text="@string/help_enable_logging"
|
||||
android:id="@+id/enable_logging_switch"
|
||||
android:checked="false"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_below="@+id/feedbackButton"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_margin="10dip" />
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
@ -13,8 +13,8 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="45dp"
|
||||
android:text="No Connections"
|
||||
android:textSize="45sp"
|
||||
android:text="@string/home_no_connections"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView
|
||||
@ -22,9 +22,9 @@
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12dp"
|
||||
android:textSize="12sp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="It looks like you don't have any connections defined yet." />
|
||||
android:text="@string/home_no_cons_message" />
|
||||
|
||||
</RelativeLayout>
|
@ -11,11 +11,12 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="45dp"
|
||||
android:textSize="45sp"
|
||||
android:text="@string/manage_title"
|
||||
android:textStyle="bold"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
@ -41,7 +42,9 @@
|
||||
android:layout_marginTop="26dp"
|
||||
android:layout_below="@+id/delete_button"
|
||||
android:layout_alignStart="@+id/delete_button"
|
||||
android:layout_alignEnd="@+id/delete_button" />
|
||||
android:layout_alignLeft="@+id/delete_button"
|
||||
android:layout_alignEnd="@+id/delete_button"
|
||||
android:layout_alignRight="@+id/delete_button"/>
|
||||
|
||||
|
||||
</RelativeLayout>
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/white"
|
||||
@ -18,7 +19,8 @@
|
||||
android:layout_height="70dp"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
android:scaleType="fitCenter"
|
||||
android:layout_centerInParent="true" />
|
||||
android:layout_centerInParent="true"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -54,6 +56,7 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="40dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:textSize="13sp"
|
||||
@ -68,6 +71,7 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="40dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:textSize="13sp"
|
||||
|
@ -11,8 +11,7 @@
|
||||
android:id="@+id/topic_group"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/title_label">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message_text"
|
||||
@ -93,9 +92,7 @@
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/qos_spinner"
|
||||
|
||||
android:layout_centerHorizontal="true" />
|
||||
android:id="@+id/qos_spinner"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
@ -113,7 +110,7 @@
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Publish"
|
||||
android:text="@string/publish"
|
||||
android:id="@+id/publish_button"
|
||||
android:layout_below="@+id/retain_switch"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
@ -10,8 +10,8 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:id="@+id/subscription_list_view"
|
||||
android:layout_below="@+id/label"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_above="@+id/subscribe_button"
|
||||
android:choiceMode="singleChoice" />
|
||||
|
||||
|
@ -8,12 +8,12 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="26dip"
|
||||
android:ellipsize="marquee"
|
||||
android:singleLine="true"
|
||||
android:text="Topic: "
|
||||
android:text="@string/message_topic"
|
||||
android:textSize="12sp"
|
||||
android:layout_below="@+id/message_text"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
android:layout_alignParentStart="true"
|
||||
android:maxLines="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message_text"
|
||||
@ -23,15 +23,15 @@
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:gravity="center_vertical"
|
||||
android:text="Example application"
|
||||
android:text="@string/placeholder_example"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="100dip"
|
||||
android:layout_height="26dip"
|
||||
android:text="Time:"
|
||||
android:text="@string/message_time"
|
||||
android:id="@+id/message_date_text"
|
||||
android:textSize="12dip"
|
||||
android:textSize="12sp"
|
||||
android:layout_below="@+id/message_text"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
@ -1,27 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="UseCompoundDrawables">
|
||||
<ImageView
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/connection_icon"
|
||||
android:src="@drawable/ic_cloud_off_dark"
|
||||
android:paddingLeft="15dp"/>
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="0dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:textSize="13sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/textColorPrimary"
|
||||
android:text="Hello World"/>
|
||||
android:text="@string/hello_world"/>
|
||||
|
||||
|
||||
|
||||
|
@ -12,20 +12,21 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:id="@+id/textView"
|
||||
android:text="Topic" />
|
||||
android:text="@string/topic_label" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/subscription_topic_edit_text"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp" />
|
||||
android:padding="10dp"
|
||||
android:inputType="text"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:id="@+id/qos_label"
|
||||
android:text="QoS" />
|
||||
android:text="@string/qos_label" />
|
||||
|
||||
<Spinner
|
||||
android:layout_width="match_parent"
|
||||
|
@ -1,4 +1,5 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:padding="6dip" >
|
||||
@ -10,7 +11,8 @@
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginRight="6dip"
|
||||
android:src="@drawable/ic_topic" />
|
||||
android:src="@drawable/ic_topic"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/qos_label"
|
||||
@ -19,9 +21,9 @@
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_toRightOf="@id/icon"
|
||||
android:ellipsize="marquee"
|
||||
android:singleLine="true"
|
||||
android:text="@string/qos_text"
|
||||
android:textSize="12sp" />
|
||||
android:textSize="12sp"
|
||||
android:maxLines="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/show_notifications_label"
|
||||
@ -52,6 +54,8 @@
|
||||
android:layout_marginRight="6dip"
|
||||
android:src="@drawable/ic_delete"
|
||||
android:layout_alignEnd="@+id/message_text"
|
||||
android:layout_alignParentRight="true" />
|
||||
android:layout_alignRight="@+id/message_text"
|
||||
android:layout_alignParentRight="true"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
</RelativeLayout>
|
@ -20,5 +20,6 @@
|
||||
android:ems="10"
|
||||
android:lines="1"
|
||||
android:padding="10dp"
|
||||
android:id="@+id/edittext"/>
|
||||
android:id="@+id/edittext"
|
||||
android:inputType="text"/>
|
||||
</LinearLayout>
|
@ -7,12 +7,12 @@
|
||||
<TextView
|
||||
android:id="@+id/mainLabel"
|
||||
style="@style/textFieldLabel"
|
||||
android:text="Main Label"/>
|
||||
android:text="@string/placeholder_main_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subLabel"
|
||||
style="@style/textfieldSubLabel"
|
||||
android:layout_below="@+id/mainLabel"
|
||||
android:text="Sub Label"/>
|
||||
android:text="@string/placeholder_sub_label"/>
|
||||
</RelativeLayout>
|
||||
</merge>
|
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="Switch">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textColor">@color/textColorPrimary</item>
|
||||
<item name="android:layout_alignParentStart">true</item>
|
||||
<item name="android:paddingLeft">30dp</item>
|
||||
<item name="android:paddingRight">30dp</item>
|
||||
<item name="android:paddingTop">15dp</item>
|
||||
<item name="android:paddingBottom">15dp</item>
|
||||
<item name="android:layout_alignParentEnd">true</item>
|
||||
</style>
|
||||
|
||||
<style name="textFieldLabel">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textColor">@color/textColorPrimary</item>
|
||||
<item name="android:paddingLeft">30dp</item>
|
||||
<item name="android:paddingRight">30dp</item>
|
||||
<item name="android:paddingBottom">5dp</item>
|
||||
<item name="android:layout_alignParentStart">true</item>
|
||||
</style>
|
||||
|
||||
<style name="textfieldSubLabel">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textColor">@color/textColorSecondary</item>
|
||||
<item name="android:paddingLeft">30dp</item>
|
||||
<item name="android:layout_alignParentStart">false</item>
|
||||
<item name="android:textSize">13sp</item>
|
||||
</style>
|
||||
|
||||
<style name="spinnerTextFieldLabel">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textColor">@color/textColorPrimary</item>
|
||||
<item name="android:paddingLeft">30dp</item>
|
||||
<item name="android:paddingRight">30dp</item>
|
||||
<item name="android:paddingTop">15dp</item>
|
||||
<item name="android:paddingBottom">15dp</item>
|
||||
<item name="android:layout_alignParentStart">true</item>
|
||||
</style>
|
||||
</resources>
|
@ -2,5 +2,5 @@
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
<!--<dimen name="activity_horizontal_margin">64dp</dimen>-->
|
||||
</resources>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<resources>
|
||||
<color name="ColorPrimary">#9C27B0</color>
|
||||
<color name="ColorPrimaryDark">#7B1FA2</color>
|
||||
<color name="ColorPrimaryLight">#E1BEE7</color>
|
||||
<!--<color name="ColorPrimaryLight">#E1BEE7</color>-->
|
||||
<color name="textColorPrimary">#212121</color>
|
||||
<color name="textColorSecondary">#727272</color>
|
||||
<color name="dividerColor">#B6B6B6</color>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<!--<dimen name="activity_horizontal_margin">16dp</dimen>-->
|
||||
<!--<dimen name="activity_vertical_margin">16dp</dimen>-->
|
||||
<dimen name="nav_draw_width">260dp</dimen>
|
||||
</resources>
|
||||
|
@ -1,89 +1,45 @@
|
||||
<resources>
|
||||
<string name="app_name">Paho Client</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="action_search">Search</string>
|
||||
<string name="drawer_open">Open</string>
|
||||
<string name="drawer_close">Close</string>
|
||||
|
||||
<string name="nav_item_home">Home</string>
|
||||
<string name="nav_item_friends">Friends</string>
|
||||
<string name="nav_item_notifications">Messages</string>
|
||||
|
||||
<!-- navigation drawer item labels -->
|
||||
<string-array name="nav_drawer_labels">
|
||||
<item>@string/nav_item_home</item>
|
||||
<item>@string/nav_item_friends</item>
|
||||
<item>@string/nav_item_notifications</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="qos_options">
|
||||
<item name="qos_0">0</item>
|
||||
<item name="qos_1">1</item>
|
||||
<item name="qos_2">2</item>
|
||||
</string-array>
|
||||
|
||||
<string name="title_messages">Messages</string>
|
||||
<string name="title_friends">Friends</string>
|
||||
<string name="title_home">Home</string>
|
||||
|
||||
|
||||
<string name="action_add_connection">Add Connection</string>
|
||||
<string name="action_cancel_connection">Cancel</string>
|
||||
<string name="action_edit_connection">Edit </string>
|
||||
<string name="add_connection_general_label">General</string>
|
||||
<string name="add_connection_client_id_label">Client ID</string>
|
||||
<string name="add_connection_client_id_default">AndroidClient</string>
|
||||
<string name="add_connection_client_id_title">Enter Client ID</string>
|
||||
<string name="add_connection_server_label">Server</string>
|
||||
<string name="add_connection_server_default">iot.eclipse.org</string>
|
||||
<string name="add_connection_server_title">Enter Server hostname</string>
|
||||
<string name="add_connection_port_label">Port</string>
|
||||
<string name="add_connection_port_default">1883</string>
|
||||
<string name="add_connection_port_title">Enter Server port</string>
|
||||
<string name="add_connection_port_label">Port</string>
|
||||
<string name="add_connection_clean_session_label">Clean Session</string>
|
||||
<string name="add_connection_advanced_label">Advanced</string>
|
||||
<string name="add_connection_username_label">Username</string>
|
||||
<string name="add_connection_username_title">Enter Username</string>
|
||||
<string name="add_connection_password_label">Password</string>
|
||||
<string name="add_connection_password_title">Enter Password</string>
|
||||
<string name="add_connection_timeout_label">Timeout</string>
|
||||
<string name="add_connection_timeout_default">60</string>
|
||||
<string name="add_connection_timeout_title">Enter Timeout (seconds)</string>
|
||||
<string name="add_connection_keepalive_label">Keepalive</string>
|
||||
<string name="add_connection_keepalive_default">200</string>
|
||||
<string name="add_connection_keepalive_title">Enter Keep Alive (seconds)</string>
|
||||
<string name="add_connection_tls_switch_label">Transport Layer Security (TLS)</string>
|
||||
<string name="add_connection_tls_server_key_label">Server TLS Key</string>
|
||||
<string name="add_connection_tls_server_key_title">Select the Sever Public Key</string>
|
||||
<string name="add_connection_tls_client_key_label">Client TLS Key</string>
|
||||
<string name="add_connection_tls_client_key_title">Select the Client Private Key</string>
|
||||
|
||||
<string name="add_connection_lwt_label">Last Will & Testament</string>
|
||||
<string name="add_connection_lwt_topic_label">Topic</string>
|
||||
<string name="add_connection_lwt_topic_title">Enter Last-Will Topic</string>
|
||||
<string name="add_connection_lwt_message_label">Message</string>
|
||||
<string name="add_connection_lwt_message_title">Enter Last-Will Message</string>
|
||||
<string name="add_connection_lwt_retain_label">Retain</string>
|
||||
<string name="add_connection_lwt_qos_label">QoS</string>
|
||||
<string name="add_connection_lwt_qos_title">Select Last-Will QoS</string>
|
||||
|
||||
|
||||
<string name="settings_general">General</string>
|
||||
<string name="settings_enable_trace">Enable MQTT Trace</string>
|
||||
<string name="settings_default_id">Default Client ID</string>
|
||||
<string name="title_activity_main2">Main2Activity</string>
|
||||
|
||||
<string name="hello_world">Hello world!</string>
|
||||
|
||||
|
||||
|
||||
<string name='connection_dateFormat'>dd/MM/yy \'at\' HH:mm:ss</string>
|
||||
<string name="connection_connected_to">Connected to</string>
|
||||
<string name="connection_disconnected_from">Disconnected from</string>
|
||||
<string name="connection_unknown_status">Unknown connection status to</string>
|
||||
<string name="connection_connecting_to">Connecting to</string>
|
||||
<string name="connection_disconnecting_from">Disconnecting from</string>
|
||||
<string name="connection_error_connecting_to">An error occured connecting to</string>
|
||||
|
||||
<string name="connection_error_connecting_to">An error occurred connecting to</string>
|
||||
<string name="connection_clear">Clear</string>
|
||||
<string name="subscription_new">New Subscription</string>
|
||||
|
||||
|
||||
@ -104,17 +60,14 @@
|
||||
<string name="toast_pub_failed">Failed to publish message: %1$s to topic: %2$s</string>
|
||||
<string name="toast_sub_failed">Failed to subscribe to %1$s</string>
|
||||
<string name="connection_lost">%1$s has lost connection to %2$s</string>
|
||||
<string name="failure_disconnect">Disconnect failed.<br/> <small>Reason: %s</small> </string>
|
||||
<string name="failure_connect">Client failed to connect.<br/> <small>Reason: %s</small></string>
|
||||
<string name="client_connected">Client connected successfully</string>
|
||||
|
||||
<!-- Strings for Subscriptions Fragment -->
|
||||
<string name="topic_label">Topic</string>
|
||||
<string name="qos_label">QoS</string>
|
||||
<string name="notify_label">Show Notifications</string>
|
||||
<string name="subscribe_ok">Ok</string>
|
||||
<string name="subscribe_ok">OK</string>
|
||||
<string name="subscribe_cancel">Cancel</string>
|
||||
<string name="qos_text" >QoS: %1$s</string>
|
||||
<string name="qos_text" >QoS: %1$d</string>
|
||||
<string name="notify_text">Notifications: %1$s</string>
|
||||
|
||||
|
||||
@ -128,7 +81,30 @@
|
||||
<string name="help_enable_logging">Enable Paho Logging</string>
|
||||
|
||||
|
||||
<!-- Home Fragment -->
|
||||
<string name="home_no_connections">No Connections</string>
|
||||
<string name="home_no_cons_message">It looks like there are no connections defined yet.</string>
|
||||
|
||||
|
||||
<!-- messages -->
|
||||
<string name="message_time">Time:</string>
|
||||
<string name="message_time_fmt">Time: %1$s</string>
|
||||
<string name="publish">Publish</string>
|
||||
<string name="topic_fmt">Topic: %1$s</string>
|
||||
|
||||
|
||||
<string name="enabled">Enabled</string>
|
||||
<string name="disabled">Disabled</string>
|
||||
|
||||
|
||||
<!-- placeholders -->
|
||||
<string name="placeholder_main_label">Main Label</string>
|
||||
<string name="placeholder_sub_label">Sub Label</string>
|
||||
<string name="placeholder_example">Example application</string>
|
||||
|
||||
|
||||
<!-- Message List Item -->
|
||||
<string name="message_topic">Topic: </string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
@ -35,12 +35,11 @@
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textColor">@color/textColorPrimary</item>
|
||||
<item name="android:layout_alignParentStart">true</item>
|
||||
<item name="android:layout_alignParentLeft">true</item>
|
||||
<item name="android:paddingLeft">30dp</item>
|
||||
<item name="android:paddingRight">30dp</item>
|
||||
<item name="android:paddingTop">15dp</item>
|
||||
<item name="android:paddingBottom">15dp</item>
|
||||
<item name="android:layout_alignParentEnd">true</item>
|
||||
</style>
|
||||
|
||||
<style name="textfieldContainer">
|
||||
@ -58,7 +57,7 @@
|
||||
<item name="android:paddingLeft">30dp</item>
|
||||
<item name="android:paddingRight">30dp</item>
|
||||
<item name="android:paddingBottom">5dp</item>
|
||||
<item name="android:layout_alignParentStart">true</item>
|
||||
<item name="android:layout_alignParentLeft">true</item>
|
||||
</style>
|
||||
|
||||
<style name="textfieldSubLabel">
|
||||
@ -66,7 +65,7 @@
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textColor">@color/textColorSecondary</item>
|
||||
<item name="android:paddingLeft">30dp</item>
|
||||
<item name="android:layout_alignParentStart">false</item>
|
||||
<item name="android:layout_alignParentLeft">false</item>
|
||||
<item name="android:textSize">13sp</item>
|
||||
</style>
|
||||
|
||||
@ -79,7 +78,7 @@
|
||||
<item name="android:paddingRight">30dp</item>
|
||||
<item name="android:paddingTop">15dp</item>
|
||||
<item name="android:paddingBottom">15dp</item>
|
||||
<item name="android:layout_alignParentStart">true</item>
|
||||
<item name="android:layout_alignParentLeft">true</item>
|
||||
</style>
|
||||
|
||||
|
||||
|
@ -7,7 +7,8 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 22
|
||||
targetSdkVersion 24
|
||||
|
||||
testApplicationId "org.eclipse.paho.android.service.test"
|
||||
}
|
||||
buildTypes {
|
||||
|
@ -6,7 +6,7 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<!--<uses-permission android:name="android.permission.READ_PHONE_STATE" />-->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
@ -1,6 +1,5 @@
|
||||
# This is the server URI which will be set in the constructor of an MQTT Client
|
||||
# The default is "tcp://<localhost>:1883" with <localhost> expressed in IPV4 dotted decimal notation
|
||||
#SERVER_URI=tcp://mbtest1.hursley.ibm.com:1883
|
||||
SERVER_URI=tcp://iot.eclipse.org:1883
|
||||
SERVER_SSL_URI=ssl://iot.eclipse.org:8883
|
||||
CLIENT_KEY_STORE=test.bks
|
||||
|
@ -1,30 +1,15 @@
|
||||
package org.eclipse.paho.android;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.ApplicationTestCase;
|
||||
import android.test.ServiceTestCase;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.paho.android.service.R;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import org.eclipse.paho.android.service.MqttAndroidClient;
|
||||
@ -36,14 +21,13 @@ import android.util.Log;
|
||||
*/
|
||||
public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
private static String TAG = "org.eclipse.paho.android.service.AndroidServiceTest";
|
||||
private static final String TAG = "AndroidServiceTest";
|
||||
|
||||
private String classCanonicalName = this.getClass().getCanonicalName();
|
||||
private final String classCanonicalName = this.getClass().getCanonicalName();
|
||||
|
||||
private String mqttServerURI;
|
||||
private String mqttSSLServerURI;
|
||||
private int waitForCompletionTime;
|
||||
private String clientKeyStore;
|
||||
private String keyStorePwd;
|
||||
|
||||
@Override
|
||||
@ -53,7 +37,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
mqttServerURI = properties.getServerURI();
|
||||
mqttSSLServerURI = properties.getServerSSLURI();
|
||||
waitForCompletionTime = properties.getWaitForCompletionTime();
|
||||
clientKeyStore = properties.getClientKeyStore();
|
||||
String clientKeyStore = properties.getClientKeyStore();
|
||||
keyStorePwd = properties.getClientKeyStorePassword();
|
||||
Log.d(TAG, properties.getServerSSLURI());
|
||||
}
|
||||
@ -249,7 +233,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -304,18 +288,18 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
subToken = mqttSubscriber[i].subscribe(topicNames, topicQos,
|
||||
null, null);
|
||||
Log.i(methodName, "subscribe " + topicNames[0].toString()
|
||||
Log.i(methodName, "subscribe " + topicNames[0]
|
||||
+ " QoS is " + topicQos[0]);
|
||||
subToken.waitForCompletion(waitForCompletionTime);
|
||||
} // for...
|
||||
|
||||
for (int iMessage = 0; iMessage < 2; iMessage++) {
|
||||
byte[] payload = ("Message " + iMessage).getBytes();
|
||||
for (int i = 0; i < mqttPublisher.length; i++) {
|
||||
pubToken = mqttPublisher[i].publish(topicNames[0], payload,
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
pubToken = aMqttPublisher.publish(topicNames[0], payload,
|
||||
0, false, null, null);
|
||||
Log.i(methodName, "publish to " + topicNames[0]
|
||||
+ " payload is " + payload.toString());
|
||||
+ " payload is " + Arrays.toString(payload));
|
||||
|
||||
pubToken.waitForCompletion(waitForCompletionTime);
|
||||
}
|
||||
@ -323,7 +307,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
TimeUnit.MILLISECONDS.sleep(30000);
|
||||
|
||||
for (int i = 0; i < mqttSubscriber.length; i++) {
|
||||
for (int ii = 0; ii < mqttPublisher.length; ii++) {
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
Log.i(methodName,
|
||||
"validate time = " + new Date().toString());
|
||||
boolean ok = mqttV3Receiver[i].validateReceipt(
|
||||
@ -343,17 +327,17 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
+ exception);
|
||||
} finally {
|
||||
try {
|
||||
for (int i = 0; i < mqttPublisher.length; i++) {
|
||||
disconnectToken = mqttPublisher[i].disconnect(null, null);
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
disconnectToken = aMqttPublisher.disconnect(null, null);
|
||||
disconnectToken.waitForCompletion(waitForCompletionTime);
|
||||
mqttPublisher[i].close();
|
||||
aMqttPublisher.close();
|
||||
}
|
||||
for (int i = 0; i < mqttSubscriber.length; i++) {
|
||||
disconnectToken = mqttSubscriber[i].disconnect(null, null);
|
||||
for (IMqttAsyncClient aMqttSubscriber : mqttSubscriber) {
|
||||
disconnectToken = aMqttSubscriber.disconnect(null, null);
|
||||
disconnectToken.waitForCompletion(waitForCompletionTime);
|
||||
mqttSubscriber[i].close();
|
||||
aMqttSubscriber.close();
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -549,7 +533,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -686,7 +670,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -792,7 +776,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -899,7 +883,7 @@ public class AndroidServiceTest extends AndroidTestCase {
|
||||
subToken = mqttClientRetained.subscribe(topicNames, topicQos, null, null);
|
||||
subToken.waitForCompletion();
|
||||
|
||||
Log.i(methodName, "subscribe "+topicNames[0].toString() + " QoS is " + topicQos[0]);
|
||||
Log.i(methodName, "subscribe "+ topicNames[0] + " QoS is " + topicQos[0]);
|
||||
|
||||
TimeUnit.MILLISECONDS.sleep(3000);
|
||||
|
||||
|
@ -36,23 +36,21 @@ import org.eclipse.paho.android.service.MqttAndroidClient;
|
||||
*/
|
||||
public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
|
||||
private IBinder binder;
|
||||
|
||||
private String serverURI;
|
||||
private String mqttSSLServerURI;
|
||||
|
||||
private int waitForCompletionTime;
|
||||
|
||||
private String clientKeyStore;
|
||||
private String keyStorePwd;
|
||||
|
||||
//since we know tokens do not work when an action listener isn't specified
|
||||
private TestCaseNotifier notifier = new TestCaseNotifier();
|
||||
|
||||
private String classCanonicalName = this.getClass().getCanonicalName();
|
||||
private final String classCanonicalName = this.getClass().getCanonicalName();
|
||||
|
||||
|
||||
public AndroidServiceWithActionListenerTest() {
|
||||
//noinspection unchecked
|
||||
super(org.eclipse.paho.android.service.MqttService.class);
|
||||
}
|
||||
|
||||
@ -62,13 +60,13 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
super.setUp();
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName("org.eclipse.paho.android.service", "MqttService");
|
||||
binder = bindService(intent);
|
||||
IBinder binder = bindService(intent);
|
||||
|
||||
TestProperties properties = new TestProperties(this.getContext());
|
||||
serverURI = properties.getServerURI();
|
||||
mqttSSLServerURI = properties.getServerSSLURI();
|
||||
waitForCompletionTime = properties.getWaitForCompletionTime();
|
||||
clientKeyStore = properties.getClientKeyStore();
|
||||
String clientKeyStore = properties.getClientKeyStore();
|
||||
keyStorePwd = properties.getClientKeyStorePassword();
|
||||
|
||||
}
|
||||
@ -99,7 +97,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
String methodName = "testRemoteConnect";
|
||||
IMqttAsyncClient mqttClient = null;
|
||||
|
||||
mqttClient = mqttClient = new MqttAndroidClient(mContext, serverURI, "testRemoteConnect");
|
||||
mqttClient = new MqttAndroidClient(mContext, serverURI, "testRemoteConnect");
|
||||
IMqttToken connectToken = null;
|
||||
IMqttToken subToken = null;
|
||||
IMqttDeliveryToken pubToken = null;
|
||||
@ -198,7 +196,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -246,8 +244,8 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
|
||||
for (int iMessage = 0; iMessage < 2; iMessage++) {
|
||||
byte[] payload = ("Message " + iMessage).getBytes();
|
||||
for (int i = 0; i < mqttPublisher.length; i++) {
|
||||
pubToken = mqttPublisher[i].publish(topicNames[0], payload, 0, false,
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
pubToken = aMqttPublisher.publish(topicNames[0], payload, 0, false,
|
||||
null, new ActionListener(notifier));
|
||||
notifier.waitForCompletion(waitForCompletionTime);
|
||||
}
|
||||
@ -255,7 +253,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
TimeUnit.MILLISECONDS.sleep(30000);
|
||||
|
||||
for (int i = 0; i < mqttSubscriber.length; i++) {
|
||||
for (int ii = 0; ii < mqttPublisher.length; ii++) {
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
boolean ok = mqttV3Receiver[i].validateReceipt(
|
||||
topicNames[0], 0, payload);
|
||||
if (!ok) {
|
||||
@ -266,15 +264,15 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
} // for messages...
|
||||
|
||||
|
||||
for (int i = 0; i < mqttPublisher.length; i++) {
|
||||
disconnectToken = mqttPublisher[i].disconnect(null, null);
|
||||
for (IMqttAsyncClient aMqttPublisher : mqttPublisher) {
|
||||
disconnectToken = aMqttPublisher.disconnect(null, null);
|
||||
disconnectToken.waitForCompletion(waitForCompletionTime);
|
||||
mqttPublisher[i].close();
|
||||
aMqttPublisher.close();
|
||||
}
|
||||
for (int i = 0; i < mqttSubscriber.length; i++) {
|
||||
disconnectToken = mqttSubscriber[i].disconnect(null, null);
|
||||
for (IMqttAsyncClient aMqttSubscriber : mqttSubscriber) {
|
||||
disconnectToken = aMqttSubscriber.disconnect(null, null);
|
||||
disconnectToken.waitForCompletion(waitForCompletionTime);
|
||||
mqttSubscriber[i].close();
|
||||
aMqttSubscriber.close();
|
||||
}
|
||||
|
||||
}
|
||||
@ -523,7 +521,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
|
||||
mqttClient.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -591,7 +589,7 @@ public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
|
||||
subToken = mqttClientRetained.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
|
||||
notifier.waitForCompletion(waitForCompletionTime);
|
||||
|
||||
Log.i(methodName, "subscribe "+topicNames[0].toString() + " QoS is " + topicQos[0]);
|
||||
Log.i(methodName, "subscribe "+ topicNames[0] + " QoS is " + topicQos[0]);
|
||||
|
||||
TimeUnit.MILLISECONDS.sleep(3000);
|
||||
|
||||
|
@ -1,3 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 IBM Corp.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*/
|
||||
package org.eclipse.paho.android;
|
||||
|
||||
import java.io.PrintStream;
|
||||
@ -16,9 +28,6 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Created by james on 19/08/15.
|
||||
*/
|
||||
public class MqttV3Receiver implements MqttCallback{
|
||||
|
||||
private final java.io.PrintStream reportStream;
|
||||
@ -42,7 +51,7 @@ public class MqttV3Receiver implements MqttCallback{
|
||||
}
|
||||
}
|
||||
|
||||
java.util.List<ReceivedMessage> receivedMessages = Collections.synchronizedList(new java.util.ArrayList<ReceivedMessage>());
|
||||
private java.util.List<ReceivedMessage> receivedMessages = Collections.synchronizedList(new java.util.ArrayList<ReceivedMessage>());
|
||||
|
||||
/**
|
||||
* @param mqttClient
|
||||
@ -149,7 +158,7 @@ public class MqttV3Receiver implements MqttCallback{
|
||||
if (!java.util.Arrays.equals(sentBytes,
|
||||
receivedMessage.message.getPayload())) {
|
||||
report("Received invalid payload="
|
||||
+ receivedMessage.message.getPayload() + "\n" + "Sent:"
|
||||
+ Arrays.toString(receivedMessage.message.getPayload()) + "\n" + "Sent:"
|
||||
+ new String(sentBytes) + "\n" + "Received:"
|
||||
+ new String(receivedMessage.message.getPayload()));
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.eclipse.paho.android;
|
||||
|
||||
public class TestCaseNotifier {
|
||||
class TestCaseNotifier {
|
||||
|
||||
private Throwable exception;
|
||||
|
||||
@ -13,7 +13,7 @@ public class TestCaseNotifier {
|
||||
try {
|
||||
wait(timeout);
|
||||
}
|
||||
catch (InterruptedException e) {}
|
||||
catch (InterruptedException ignored) {}
|
||||
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
|
@ -1,3 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 IBM Corp.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*/
|
||||
package org.eclipse.paho.android;
|
||||
|
||||
import android.content.Context;
|
||||
@ -7,25 +19,17 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by james on 18/08/15.
|
||||
*/
|
||||
public class TestProperties {
|
||||
class TestProperties {
|
||||
|
||||
// public int waitForCompletionTime = 6000;
|
||||
// public String serverURI = "tcp://9.125.29.127:1883";
|
||||
// public static String serverURI = "tcp://9.119.156.175:1883";
|
||||
// public static String sslServerURI = "ssl://9.119.156.175:8892";
|
||||
// public String sslServerURI = "ssl://9.125.29.12:8892";
|
||||
|
||||
private final Class<?> cclass = TestProperties.class;
|
||||
private final String className = cclass.getName();
|
||||
|
||||
public final String KEY_SERVER_URI = "SERVER_URI";
|
||||
public final String KEY_CLIENT_KEY_STORE = "CLIENT_KEY_STORE";
|
||||
public final String KEY_CLIENT_KEY_STORE_PASSWORD = "CLIENT_KEY_STORE_PASSWORD";
|
||||
public final String KEY_SERVER_SSL_URI = "SERVER_SSL_URI";
|
||||
public final String KEY_WAIT_FOR_COMPLETION_TIME = "WAIT_FOR_COMPLETION_TIME";
|
||||
private final String KEY_SERVER_URI = "SERVER_URI";
|
||||
private final String KEY_CLIENT_KEY_STORE = "CLIENT_KEY_STORE";
|
||||
private final String KEY_CLIENT_KEY_STORE_PASSWORD = "CLIENT_KEY_STORE_PASSWORD";
|
||||
private final String KEY_SERVER_SSL_URI = "SERVER_SSL_URI";
|
||||
private final String KEY_WAIT_FOR_COMPLETION_TIME = "WAIT_FOR_COMPLETION_TIME";
|
||||
|
||||
private Properties properties = new Properties();
|
||||
|
||||
@ -85,9 +89,8 @@ public class TestProperties {
|
||||
* @param key
|
||||
* @return value
|
||||
*/
|
||||
public String getProperty(String key) {
|
||||
String value = properties.getProperty(key);
|
||||
return value;
|
||||
private String getProperty(String key) {
|
||||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +106,7 @@ public class TestProperties {
|
||||
* @param key
|
||||
* @return value
|
||||
*/
|
||||
public int getIntProperty(String key) {
|
||||
private int getIntProperty(String key) {
|
||||
String value = getProperty(key);
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
@ -114,7 +117,6 @@ public class TestProperties {
|
||||
*/
|
||||
|
||||
public String getClientKeyStore() {
|
||||
|
||||
return getProperty(KEY_CLIENT_KEY_STORE);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import org.eclipse.paho.client.mqttv3.IMqttToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttPingSender;
|
||||
import org.eclipse.paho.client.mqttv3.internal.ClientComms;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
@ -40,7 +41,7 @@ import android.util.Log;
|
||||
*/
|
||||
class AlarmPingSender implements MqttPingSender {
|
||||
// Identifier for Intents, log messages, etc..
|
||||
static final String TAG = "AlarmPingSender";
|
||||
private static final String TAG = "AlarmPingSender";
|
||||
|
||||
// TODO: Add log.
|
||||
private ClientComms comms;
|
||||
@ -81,13 +82,15 @@ class AlarmPingSender implements MqttPingSender {
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
// Cancel Alarm.
|
||||
AlarmManager alarmManager = (AlarmManager) service
|
||||
.getSystemService(Service.ALARM_SERVICE);
|
||||
alarmManager.cancel(pendingIntent);
|
||||
|
||||
Log.d(TAG, "Unregister alarmreceiver to MqttService"+comms.getClient().getClientId());
|
||||
if(hasStarted){
|
||||
if(pendingIntent != null){
|
||||
// Cancel Alarm.
|
||||
AlarmManager alarmManager = (AlarmManager) service.getSystemService(Service.ALARM_SERVICE);
|
||||
alarmManager.cancel(pendingIntent);
|
||||
}
|
||||
|
||||
hasStarted = false;
|
||||
try{
|
||||
service.unregisterReceiver(alarmReceiver);
|
||||
@ -104,7 +107,15 @@ class AlarmPingSender implements MqttPingSender {
|
||||
Log.d(TAG, "Schedule next alarm at " + nextAlarmInMilliseconds);
|
||||
AlarmManager alarmManager = (AlarmManager) service
|
||||
.getSystemService(Service.ALARM_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
|
||||
if(Build.VERSION.SDK_INT >= 23){
|
||||
// In SDK 23 and above, dosing will prevent setExact, setExactAndAllowWhileIdle will force
|
||||
// the device to run this task whilst dosing.
|
||||
Log.d(TAG, "Alarm scheule using setExactAndAllowWhileIdle, next: " + delayInMilliseconds);
|
||||
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextAlarmInMilliseconds,
|
||||
pendingIntent);
|
||||
} else if (Build.VERSION.SDK_INT >= 19) {
|
||||
Log.d(TAG, "Alarm scheule using setExact, delay: " + delayInMilliseconds);
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, nextAlarmInMilliseconds,
|
||||
pendingIntent);
|
||||
} else {
|
||||
@ -118,29 +129,19 @@ class AlarmPingSender implements MqttPingSender {
|
||||
*/
|
||||
class AlarmReceiver extends BroadcastReceiver {
|
||||
private WakeLock wakelock;
|
||||
private String wakeLockTag = MqttServiceConstants.PING_WAKELOCK
|
||||
private final String wakeLockTag = MqttServiceConstants.PING_WAKELOCK
|
||||
+ that.comms.getClient().getClientId();
|
||||
|
||||
@Override
|
||||
@SuppressLint("Wakelock")
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// According to the docs, "Alarm Manager holds a CPU wake lock as
|
||||
// long as the alarm receiver's onReceive() method is executing.
|
||||
// This guarantees that the phone will not sleep until you have
|
||||
// finished handling the broadcast.", but this class still get
|
||||
// a wake lock to wait for ping finished.
|
||||
int count;
|
||||
try {
|
||||
count = intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, -1);
|
||||
} catch (ClassCastException ex){
|
||||
// This is a Motorola Phone (Probably a Moto G or X)
|
||||
// And so Intent.EXTRA_ALARM_COUNT is actually a Long!
|
||||
Long longCount = intent.getLongExtra(Intent.EXTRA_ALARM_COUNT, -1);
|
||||
count = longCount.intValue();
|
||||
}
|
||||
|
||||
Log.d(TAG, "Ping " + count + " times.");
|
||||
|
||||
Log.d(TAG, "Check time :" + System.currentTimeMillis());
|
||||
Log.d(TAG, "Sending Ping at:" + System.currentTimeMillis());
|
||||
|
||||
PowerManager pm = (PowerManager) service
|
||||
.getSystemService(Service.POWER_SERVICE);
|
||||
@ -170,6 +171,7 @@ class AlarmPingSender implements MqttPingSender {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (token == null && wakelock.isHeld()) {
|
||||
wakelock.release();
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
||||
class DatabaseMessageStore implements MessageStore {
|
||||
|
||||
// TAG used for indentify trace data etc.
|
||||
private static String TAG = "DatabaseMessageStore";
|
||||
private static final String TAG = "DatabaseMessageStore";
|
||||
|
||||
// One "private" database column name
|
||||
// The other database column names are defined in MqttServiceConstants
|
||||
@ -57,7 +57,7 @@ class DatabaseMessageStore implements MessageStore {
|
||||
*/
|
||||
private static class MQTTDatabaseHelper extends SQLiteOpenHelper {
|
||||
// TAG used for indentify trace data etc.
|
||||
private static String TAG = "MQTTDatabaseHelper";
|
||||
private static final String TAG = "MQTTDatabaseHelper";
|
||||
|
||||
private static final String DATABASE_NAME = "mqttAndroidService.db";
|
||||
|
||||
@ -141,7 +141,7 @@ class DatabaseMessageStore implements MessageStore {
|
||||
* a context to use for android calls
|
||||
*/
|
||||
public DatabaseMessageStore(MqttService service, Context context) {
|
||||
this.traceHandler = (MqttTraceHandler) service;
|
||||
this.traceHandler = service;
|
||||
|
||||
// Open message database
|
||||
mqttDb = new MQTTDatabaseHelper(traceHandler, context);
|
||||
@ -290,7 +290,7 @@ class DatabaseMessageStore implements MessageStore {
|
||||
return new Iterator<StoredMessage>() {
|
||||
private Cursor c;
|
||||
private boolean hasNext;
|
||||
private String[] selectionArgs = {
|
||||
private final String[] selectionArgs = {
|
||||
clientHandle,
|
||||
};
|
||||
|
||||
@ -321,7 +321,7 @@ class DatabaseMessageStore implements MessageStore {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (hasNext == false){
|
||||
if (!hasNext){
|
||||
c.close();
|
||||
}
|
||||
return hasNext;
|
||||
@ -401,7 +401,6 @@ class DatabaseMessageStore implements MessageStore {
|
||||
}
|
||||
traceHandler.traceDebug(TAG, "clearArrivedMessages: rows affected = "
|
||||
+ rows);
|
||||
return;
|
||||
}
|
||||
|
||||
private class DbStoredData implements StoredMessage {
|
||||
|
@ -36,7 +36,7 @@ interface MessageStore {
|
||||
/**
|
||||
* External representation of a stored message
|
||||
*/
|
||||
public interface StoredMessage {
|
||||
interface StoredMessage {
|
||||
/**
|
||||
* @return the identifier for the message within the store
|
||||
*/
|
||||
@ -67,8 +67,8 @@ interface MessageStore {
|
||||
* message to be stored
|
||||
* @return a unique identifier for it
|
||||
*/
|
||||
public String storeArrived(String clientHandle, String Topic,
|
||||
MqttMessage message);
|
||||
String storeArrived(String clientHandle, String Topic,
|
||||
MqttMessage message);
|
||||
|
||||
/**
|
||||
* Discard a message - called when we are certain that an arrived message
|
||||
@ -79,7 +79,7 @@ interface MessageStore {
|
||||
* @param id
|
||||
* id of message to be discarded
|
||||
*/
|
||||
public boolean discardArrived(String clientHandle, String id);
|
||||
boolean discardArrived(String clientHandle, String id);
|
||||
|
||||
/**
|
||||
* Get all the stored messages, usually for a specific client
|
||||
@ -88,7 +88,7 @@ interface MessageStore {
|
||||
* identifier for the client - if null, then messages for all
|
||||
* clients are returned
|
||||
*/
|
||||
public Iterator<StoredMessage> getAllArrivedMessages(String clientHandle);
|
||||
Iterator<StoredMessage> getAllArrivedMessages(String clientHandle);
|
||||
|
||||
/**
|
||||
* Discard stored messages, usually for a specific client
|
||||
@ -97,7 +97,7 @@ interface MessageStore {
|
||||
* identifier for the client - if null, then messages for all
|
||||
* clients are discarded
|
||||
*/
|
||||
public void clearArrivedMessages(String clientHandle);
|
||||
void clearArrivedMessages(String clientHandle);
|
||||
|
||||
public void close();
|
||||
void close();
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.eclipse.paho.android.service;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyManagementException;
|
||||
@ -65,6 +64,7 @@ import android.util.SparseArray;
|
||||
* Implementation of the MQTT asynchronous client interface {@link IMqttAsyncClient} , using the MQTT
|
||||
* android service to actually interface with MQTT server. It provides android applications a simple programming interface to all features of the MQTT version 3.1
|
||||
* specification including:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>connect
|
||||
* <li>publish
|
||||
@ -72,7 +72,6 @@ import android.util.SparseArray;
|
||||
* <li>unsubscribe
|
||||
* <li>disconnect
|
||||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
IMqttAsyncClient {
|
||||
@ -100,7 +99,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
|
||||
private static final int BIND_SERVICE_FLAG = 0;
|
||||
|
||||
private static ExecutorService pool = Executors.newCachedThreadPool();
|
||||
private static final ExecutorService pool = Executors.newCachedThreadPool();
|
||||
|
||||
/**
|
||||
* ServiceConnection to process when we bind to our service
|
||||
@ -123,7 +122,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
}
|
||||
|
||||
// Listener for when the service is connected or disconnected
|
||||
private MyServiceConnection serviceConnection = new MyServiceConnection();
|
||||
private final MyServiceConnection serviceConnection = new MyServiceConnection();
|
||||
|
||||
// The Android Service which will process our mqtt calls
|
||||
private MqttService mqttService;
|
||||
@ -132,16 +131,16 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
// the service
|
||||
private String clientHandle;
|
||||
|
||||
Context myContext;
|
||||
private Context myContext;
|
||||
|
||||
// We hold the various tokens in a collection and pass identifiers for them
|
||||
// to the service
|
||||
private SparseArray<IMqttToken> tokenMap = new SparseArray<IMqttToken>();
|
||||
private final SparseArray<IMqttToken> tokenMap = new SparseArray<>();
|
||||
private int tokenNumber = 0;
|
||||
|
||||
// Connection data
|
||||
private String serverURI;
|
||||
private String clientId;
|
||||
private final String serverURI;
|
||||
private final String clientId;
|
||||
private MqttClientPersistence persistence = null;
|
||||
private MqttConnectOptions connectOptions;
|
||||
private IMqttToken connectToken;
|
||||
@ -151,7 +150,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
private MqttTraceHandler traceCallback;
|
||||
|
||||
//The acknowledgment that a message has been processed by the application
|
||||
private Ack messageAck;
|
||||
private final Ack messageAck;
|
||||
private boolean traceEnabled = false;
|
||||
|
||||
private volatile boolean receiverRegistered = false;
|
||||
@ -249,11 +248,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
|
||||
if (clientHandle != null && mqttService != null) {
|
||||
return mqttService.isConnected(clientHandle);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return clientHandle != null && mqttService != null && mqttService.isConnected(clientHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -288,20 +283,16 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* Close the client. Releases all resource associated with the client. After
|
||||
* the client has been closed it cannot be reused. For instance attempts to
|
||||
* connect will fail.
|
||||
*
|
||||
* @throws MqttException
|
||||
* if the client is not disconnected.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
if (clientHandle == null) {
|
||||
System.out.println(serverURI);
|
||||
System.out.println(clientId);
|
||||
System.out.println(myContext.getApplicationInfo().packageName);
|
||||
System.out.println(persistence);
|
||||
clientHandle = mqttService.getClient(serverURI, clientId, myContext.getApplicationInfo().packageName,persistence);
|
||||
}
|
||||
mqttService.close(clientHandle);
|
||||
if(mqttService != null){
|
||||
if (clientHandle == null) {
|
||||
clientHandle = mqttService.getClient(serverURI, clientId, myContext.getApplicationInfo().packageName,persistence);
|
||||
}
|
||||
mqttService.close(clientHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -375,15 +366,17 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* connecting in order that messages destined for the client can be accepted
|
||||
* as soon as the client is connected.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The method returns control before the connect completes. Completion can
|
||||
* be tracked by:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>Waiting on the returned token {@link IMqttToken#waitForCompletion()}
|
||||
* or</li>
|
||||
* <li>Passing in a callback {@link IMqttActionListener}</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param options
|
||||
* a set of connection parameters that override the defaults.
|
||||
@ -500,7 +493,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
@Override
|
||||
public IMqttToken disconnect() throws MqttException {
|
||||
IMqttToken token = new MqttTokenAndroid(this, null,
|
||||
(IMqttActionListener) null);
|
||||
null);
|
||||
String activityToken = storeToken(token);
|
||||
mqttService.disconnect(clientHandle, null, activityToken);
|
||||
return token;
|
||||
@ -529,7 +522,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
@Override
|
||||
public IMqttToken disconnect(long quiesceTimeout) throws MqttException {
|
||||
IMqttToken token = new MqttTokenAndroid(this, null,
|
||||
(IMqttActionListener) null);
|
||||
null);
|
||||
String activityToken = storeToken(token);
|
||||
mqttService.disconnect(clientHandle, quiesceTimeout, null,
|
||||
activityToken);
|
||||
@ -588,12 +581,12 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* <p>
|
||||
* The method returns control before the disconnect completes. Completion
|
||||
* can be tracked by:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>Waiting on the returned token {@link IMqttToken#waitForCompletion()}
|
||||
* or</li>
|
||||
* <li>Passing in a callback {@link IMqttActionListener}</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @param quiesceTimeout
|
||||
* the amount of time in milliseconds to allow for existing work
|
||||
@ -738,6 +731,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* In the event the connection fails or the client stops, Messages will be
|
||||
* delivered to the requested quality of service once the connection is
|
||||
* re-established to the server on condition that:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>The connection is re-established with the same clientID
|
||||
* <li>The original connection was made with (@link
|
||||
@ -747,7 +741,6 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* <li>Depending when the failure occurs QoS 0 messages may not be
|
||||
* delivered.
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* When building an application, the design of the topic tree should take
|
||||
@ -764,8 +757,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* <li>A leading "/" creates a distinct topic. For example,
|
||||
* <em>/finance</em> is different from <em>finance</em>. <em>/finance</em>
|
||||
* matches "+/+" and "/+", but not "+".</li>
|
||||
* <li>Do not include the null character (Unicode <samp
|
||||
* class="codeph">\x0000</samp>) in any topic.</li>
|
||||
* <li>Do not include the null character (Unicode <em>\x0000</em>) in any topic.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
@ -779,19 +771,18 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* <li>There can be any number of root nodes; that is, there can be any
|
||||
* number of topic trees.</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
* The method returns control before the publish completes. Completion can
|
||||
* be tracked by:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>Setting an {@link IMqttAsyncClient#setCallback(MqttCallback)} where
|
||||
* the {@link MqttCallback#deliveryComplete(IMqttDeliveryToken)} method will
|
||||
* be called.</li>pu
|
||||
* be called.</li>
|
||||
* <li>Waiting on the returned token {@link MqttToken#waitForCompletion()}
|
||||
* or</li>
|
||||
* <li>Passing in a callback {@link IMqttActionListener} to this method</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @param topic
|
||||
* to deliver the message to, for example "finance/stock/ibm".
|
||||
@ -933,29 +924,29 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* If (@link MqttConnectOptions#setCleanSession(boolean)} was set to true,
|
||||
* when connecting to the server, the subscription remains in place until
|
||||
* either:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>The client disconnects</li>
|
||||
* <li>An unsubscribe method is called to unsubscribe the topic</li> </li>
|
||||
* </p>
|
||||
* <li>An unsubscribe method is called to unsubscribe the topic</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* If (@link MqttConnectOptions#setCleanSession(boolean)} was set to false,
|
||||
* when connecting to the server, the subscription remains in place
|
||||
* until either:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>An unsubscribe method is called to unsubscribe the topic</li>
|
||||
* <li>The next time the client connects with cleanSession set to true
|
||||
* </ul>
|
||||
* </li> With cleanSession set to false the MQTT server will store messages
|
||||
* <p>With cleanSession set to false the MQTT server will store messages
|
||||
* on behalf of the client when the client is not connected. The next time
|
||||
* the client connects with the <bold>same client ID</bold> the server will
|
||||
* the client connects with the <b>same client ID</b> the server will
|
||||
* deliver the stored messages to the client.
|
||||
* </p>
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The "topic filter" string is used when subscription may contain special
|
||||
* characters, which allows you to subscribe to multiple topics at once.
|
||||
* </p>
|
||||
* <p>
|
||||
* <dl>
|
||||
* <dt>Topic level separator</dt>
|
||||
* <dd>The forward slash (/) is used to separate each level within a topic
|
||||
@ -970,12 +961,13 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* levels within a topic. For example, if you subscribe to <span><span
|
||||
* class="filepath">finance/stock/ibm/#</span></span>, you receive messages
|
||||
* on these topics:
|
||||
*
|
||||
* <pre>
|
||||
* finance/stock/ibm<br /> finance/stock/ibm/closingprice<br /> finance/stock/ibm/currentprice
|
||||
* </pre>
|
||||
*
|
||||
* </p>
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li><pre>finance/stock/ibm</pre></li>
|
||||
* <li><pre>finance/stock/ibm/closingprice</pre></li>
|
||||
* <li><pre>finance/stock/ibm/currentprice</pre></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* The multi-level wildcard can represent zero or more levels. Therefore,
|
||||
* <em>finance/#</em> can also match the singular <em>finance</em>, where
|
||||
@ -1016,16 +1008,15 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* </p>
|
||||
* </dd>
|
||||
* </dl>
|
||||
* </p>
|
||||
* <p>
|
||||
* The method returns control before the subscribe completes. Completion can
|
||||
* be tracked by:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>Waiting on the supplied token {@link MqttToken#waitForCompletion()}
|
||||
* or</li>
|
||||
* <li>Passing in a callback {@link IMqttActionListener} to this method</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @param topic
|
||||
* one or more topics to subscribe to, which can include
|
||||
@ -1073,7 +1064,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* null if not required.
|
||||
* @param callback optional listener that will be notified when subscribe
|
||||
* has completed
|
||||
* @param messageListener
|
||||
* @param messageListener a callback to handle incoming messages
|
||||
* @return token used to track and wait for the subscribe to complete. The token
|
||||
* will be passed to callback methods if set.
|
||||
* @throws MqttException if there was an error registering the subscription.
|
||||
@ -1093,7 +1084,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* published at a lower quality of service will be received at the published
|
||||
* QoS. Messages published at a higher quality of service will be received using
|
||||
* the QoS specified on the subscribe.
|
||||
* @param messageListener
|
||||
* @param messageListener a callback to handle incoming messages
|
||||
* @return token used to track and wait for the subscribe to complete. The token
|
||||
* will be passed to callback methods if set.
|
||||
* @throws MqttException if there was an error registering the subscription.
|
||||
@ -1117,7 +1108,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* published at a lower quality of service will be received at the published
|
||||
* QoS. Messages published at a higher quality of service will be received using
|
||||
* the QoS specified on the subscribe.
|
||||
* @param messageListeners
|
||||
* @param messageListeners an array of callbacks to handle incoming messages
|
||||
* @return token used to track and wait for the subscribe to complete. The token
|
||||
* will be passed to callback methods if set.
|
||||
* @throws MqttException if there was an error registering the subscription.
|
||||
@ -1145,7 +1136,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* null if not required.
|
||||
* @param callback optional listener that will be notified when subscribe
|
||||
* has completed
|
||||
* @param messageListeners
|
||||
* @param messageListeners an array of callbacks to handle incoming messages
|
||||
* @return token used to track and wait for the subscribe to complete. The token
|
||||
* will be passed to callback methods if set.
|
||||
* @throws MqttException if there was an error registering the subscription.
|
||||
@ -1240,12 +1231,12 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* <p>
|
||||
* The method returns control before the unsubscribe completes. Completion
|
||||
* can be tracked by:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>Waiting on the returned token {@link MqttToken#waitForCompletion()}
|
||||
* or</li>
|
||||
* <li>Passing in a callback {@link IMqttActionListener} to this method</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @param topic
|
||||
* one or more topics to unsubscribe from. Each topic must match
|
||||
@ -1299,12 +1290,12 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
* <p>
|
||||
* There are a number of events that the listener will be notified about.
|
||||
* These include:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>A new message has arrived and is ready to be processed</li>
|
||||
* <li>The connection to the server has been lost</li>
|
||||
* <li>Delivery of a message to the server has completed</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
* Other events that track the progress of an individual operation such as
|
||||
* connect and subscribe can be tracked using the {@link MqttToken} returned
|
||||
@ -1575,7 +1566,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
String destinationName = data
|
||||
.getString(MqttServiceConstants.CALLBACK_DESTINATION_NAME);
|
||||
|
||||
ParcelableMqttMessage message = (ParcelableMqttMessage) data
|
||||
ParcelableMqttMessage message = data
|
||||
.getParcelable(MqttServiceConstants.CALLBACK_MESSAGE_PARCEL);
|
||||
try {
|
||||
if (messageAck == Ack.AUTO_ACK) {
|
||||
@ -1656,13 +1647,12 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
private synchronized IMqttToken getMqttToken(Bundle data) {
|
||||
String activityToken = data
|
||||
.getString(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN);
|
||||
IMqttToken token = tokenMap.get(Integer.parseInt(activityToken));
|
||||
return token;
|
||||
return tokenMap.get(Integer.parseInt(activityToken));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the DisconnectedBufferOptions for this client
|
||||
* @param bufferOpts
|
||||
* @param bufferOpts the DisconnectedBufferOptions
|
||||
*/
|
||||
public void setBufferOpts(DisconnectedBufferOptions bufferOpts) {
|
||||
mqttService.setBufferOpts(clientHandle, bufferOpts);
|
||||
@ -1714,17 +1704,7 @@ public class MqttAndroidClient extends BroadcastReceiver implements
|
||||
sslSockFactory=ctx.getSocketFactory();
|
||||
return sslSockFactory;
|
||||
|
||||
} catch (KeyStoreException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (CertificateException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (IOException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
} catch (KeyManagementException e) {
|
||||
} catch (KeyStoreException | CertificateException | IOException | NoSuchAlgorithmException | KeyManagementException e) {
|
||||
throw new MqttSecurityException(e);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.eclipse.paho.android.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@ -24,15 +25,12 @@ import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallback;
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
|
||||
import org.eclipse.paho.client.mqttv3.internal.DisconnectedMessageBuffer;
|
||||
import org.eclipse.paho.client.mqttv3.internal.ExceptionHelper;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
|
||||
|
||||
import android.app.Service;
|
||||
@ -120,6 +118,8 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
// our client object - instantiated on connect
|
||||
private MqttAsyncClient myClient = null;
|
||||
|
||||
private AlarmPingSender alarmPingSender = null;
|
||||
|
||||
// our (parent) service object
|
||||
private MqttService service = null;
|
||||
|
||||
@ -133,10 +133,10 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
// Saved sent messages and their corresponding Topics, activityTokens and
|
||||
// invocationContexts, so we can handle "deliveryComplete" callbacks
|
||||
// from the mqttClient
|
||||
private Map<IMqttDeliveryToken, String /* Topic */> savedTopics = new HashMap<IMqttDeliveryToken, String>();
|
||||
private Map<IMqttDeliveryToken, MqttMessage> savedSentMessages = new HashMap<IMqttDeliveryToken, MqttMessage>();
|
||||
private Map<IMqttDeliveryToken, String> savedActivityTokens = new HashMap<IMqttDeliveryToken, String>();
|
||||
private Map<IMqttDeliveryToken, String> savedInvocationContexts = new HashMap<IMqttDeliveryToken, String>();
|
||||
private Map<IMqttDeliveryToken, String /* Topic */> savedTopics = new HashMap<>();
|
||||
private Map<IMqttDeliveryToken, MqttMessage> savedSentMessages = new HashMap<>();
|
||||
private Map<IMqttDeliveryToken, String> savedActivityTokens = new HashMap<>();
|
||||
private Map<IMqttDeliveryToken, String> savedInvocationContexts = new HashMap<>();
|
||||
|
||||
private WakeLock wakelock = null;
|
||||
private String wakeLockTag = null;
|
||||
@ -161,19 +161,19 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
*/
|
||||
MqttConnection(MqttService service, String serverURI, String clientId,
|
||||
MqttClientPersistence persistence, String clientHandle) {
|
||||
this.serverURI = serverURI.toString();
|
||||
this.serverURI = serverURI;
|
||||
this.service = service;
|
||||
this.clientId = clientId;
|
||||
this.persistence = persistence;
|
||||
this.clientHandle = clientHandle;
|
||||
|
||||
StringBuffer buff = new StringBuffer(this.getClass().getCanonicalName());
|
||||
buff.append(" ");
|
||||
buff.append(clientId);
|
||||
buff.append(" ");
|
||||
buff.append("on host ");
|
||||
buff.append(serverURI);
|
||||
wakeLockTag = buff.toString();
|
||||
StringBuilder stringBuilder = new StringBuilder(this.getClass().getCanonicalName());
|
||||
stringBuilder.append(" ");
|
||||
stringBuilder.append(clientId);
|
||||
stringBuilder.append(" ");
|
||||
stringBuilder.append("on host ");
|
||||
stringBuilder.append(serverURI);
|
||||
wakeLockTag = stringBuilder.toString();
|
||||
}
|
||||
|
||||
// The major API implementation follows
|
||||
@ -271,7 +271,6 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
service.traceDebug(TAG,
|
||||
"myClient != null and the client is connecting. Connect return directly.");
|
||||
service.traceDebug(TAG,"Connect return:isConnecting:"+isConnecting+".disconnected:"+disconnected);
|
||||
return;
|
||||
}else if(!disconnected){
|
||||
service.traceDebug(TAG,"myClient != null and the client is connected and notify!");
|
||||
doAfterConnectSuccess(resultBundle);
|
||||
@ -286,8 +285,9 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
|
||||
// if myClient is null, then create a new connection
|
||||
else {
|
||||
alarmPingSender = new AlarmPingSender(service);
|
||||
myClient = new MqttAsyncClient(serverURI, clientId,
|
||||
persistence, new AlarmPingSender(service));
|
||||
persistence, alarmPingSender);
|
||||
myClient.setCallback(this);
|
||||
|
||||
service.traceDebug(TAG,"Do Real connect!");
|
||||
@ -295,6 +295,8 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
myClient.connect(connectOptions, invocationContext, listener);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
service.traceError(TAG, "Exception occurred attempting to connect: " + e.getMessage());
|
||||
setConnectingState(false);
|
||||
handleException(resultBundle, e);
|
||||
}
|
||||
}
|
||||
@ -485,9 +487,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
* @return true if we are connected to an MQTT server
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
if (myClient != null)
|
||||
return myClient.isConnected();
|
||||
return false;
|
||||
return myClient != null && myClient.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -660,7 +660,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
*/
|
||||
public void subscribe(final String[] topic, final int[] qos,
|
||||
String invocationContext, String activityToken) {
|
||||
service.traceDebug(TAG, "subscribe({" + topic + "}," + qos + ",{"
|
||||
service.traceDebug(TAG, "subscribe({" + Arrays.toString(topic) + "}," + Arrays.toString(qos) + ",{"
|
||||
+ invocationContext + "}, {" + activityToken + "}");
|
||||
final Bundle resultBundle = new Bundle();
|
||||
resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION,
|
||||
@ -688,7 +688,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
}
|
||||
|
||||
public void subscribe(String[] topicFilters, int[] qos, String invocationContext, String activityToken, IMqttMessageListener[] messageListeners) {
|
||||
service.traceDebug(TAG, "subscribe({" + topicFilters + "}," + qos + ",{"
|
||||
service.traceDebug(TAG, "subscribe({" + Arrays.toString(topicFilters) + "}," + Arrays.toString(qos) + ",{"
|
||||
+ invocationContext + "}, {" + activityToken + "}");
|
||||
final Bundle resultBundle = new Bundle();
|
||||
resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, MqttServiceConstants.SUBSCRIBE_ACTION);
|
||||
@ -760,7 +760,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
*/
|
||||
void unsubscribe(final String[] topic, String invocationContext,
|
||||
String activityToken) {
|
||||
service.traceDebug(TAG, "unsubscribe({" + topic + "},{"
|
||||
service.traceDebug(TAG, "unsubscribe({" + Arrays.toString(topic) + "},{"
|
||||
+ invocationContext + "}, {" + activityToken + "})");
|
||||
final Bundle resultBundle = new Bundle();
|
||||
resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION,
|
||||
@ -808,19 +808,26 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
service.traceDebug(TAG, "connectionLost(" + why.getMessage() + ")");
|
||||
disconnected = true;
|
||||
try {
|
||||
myClient.disconnect(null, new IMqttActionListener() {
|
||||
if(!this.connectOptions.isAutomaticReconnect()) {
|
||||
myClient.disconnect(null, new IMqttActionListener() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(IMqttToken asyncActionToken) {
|
||||
// No action
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(IMqttToken asyncActionToken) {
|
||||
// No action
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(IMqttToken asyncActionToken,
|
||||
Throwable exception) {
|
||||
// No action
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onFailure(IMqttToken asyncActionToken,
|
||||
Throwable exception) {
|
||||
// No action
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Using the new Automatic reconnect functionality.
|
||||
// We can't force a disconnection, but we can speed one up
|
||||
alarmPingSender.schedule(100);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore it - we've done our best
|
||||
}
|
||||
@ -1010,6 +1017,12 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
* multiple times
|
||||
*/
|
||||
synchronized void reconnect() {
|
||||
|
||||
if (myClient == null) {
|
||||
service.traceError(TAG,"Reconnect myClient = null. Will not do reconnect");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isConnecting) {
|
||||
service.traceDebug(TAG, "The client is connecting. Reconnect return directly.");
|
||||
return ;
|
||||
@ -1021,7 +1034,25 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
return;
|
||||
}
|
||||
|
||||
if (disconnected && !cleanSession) {
|
||||
if(connectOptions.isAutomaticReconnect()){
|
||||
//The Automatic reconnect functionality is enabled here
|
||||
Log.i(TAG, "Requesting Automatic reconnect using New Java AC");
|
||||
final Bundle resultBundle = new Bundle();
|
||||
resultBundle.putString(
|
||||
MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN,
|
||||
reconnectActivityToken);
|
||||
resultBundle.putString(
|
||||
MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, null);
|
||||
resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION,
|
||||
MqttServiceConstants.CONNECT_ACTION);
|
||||
try {
|
||||
myClient.reconnect();
|
||||
} catch (MqttException ex){
|
||||
Log.e(TAG, "Exception occurred attempting to reconnect: " + ex.getMessage());
|
||||
setConnectingState(false);
|
||||
handleException(resultBundle, ex);
|
||||
}
|
||||
} else if (disconnected && !cleanSession) {
|
||||
// use the activityToke the same with action connect
|
||||
service.traceDebug(TAG,"Do Real Reconnect!");
|
||||
final Bundle resultBundle = new Bundle();
|
||||
@ -1067,6 +1098,17 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
service.traceError(TAG, "Cannot reconnect to remote server." + e.getMessage());
|
||||
setConnectingState(false);
|
||||
handleException(resultBundle, e);
|
||||
} catch (Exception e){
|
||||
/* TODO: Added Due to: https://github.com/eclipse/paho.mqtt.android/issues/101
|
||||
For some reason in a small number of cases, myClient is null here and so
|
||||
a NullPointer Exception is thrown. This is a workaround to pass the exception
|
||||
up to the application. myClient should not be null so more investigation is
|
||||
required.
|
||||
*/
|
||||
service.traceError(TAG, "Cannot reconnect to remote server." + e.getMessage());
|
||||
setConnectingState(false);
|
||||
MqttException newEx = new MqttException(MqttException.REASON_CODE_UNEXPECTED_ERROR, e.getCause());
|
||||
handleException(resultBundle, newEx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1075,7 +1117,7 @@ class MqttConnection implements MqttCallbackExtended {
|
||||
*
|
||||
* @param isConnecting
|
||||
*/
|
||||
synchronized void setConnectingState(boolean isConnecting){
|
||||
private synchronized void setConnectingState(boolean isConnecting){
|
||||
this.isConnecting = isConnecting;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.eclipse.paho.android.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -28,10 +27,8 @@ import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttSecurityException;
|
||||
import org.eclipse.paho.client.mqttv3.internal.DisconnectedMessageBuffer;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningTaskInfo;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@ -45,7 +42,6 @@ import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -55,6 +51,7 @@ import android.util.Log;
|
||||
* The main API of MqttService is intended to pretty much mirror the
|
||||
* IMqttAsyncClient with appropriate adjustments for the Android environment.<br>
|
||||
* These adjustments usually consist of adding two parameters to each method :-
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>invocationContext - a string passed from the application to identify the
|
||||
* context of the operation (mainly included for support of the javascript API
|
||||
@ -62,7 +59,6 @@ import android.util.Log;
|
||||
* <li>activityToken - a string passed from the Activity to relate back to a
|
||||
* callback method or other context-specific data</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
* To support multiple client connections, the bulk of the MQTT work is
|
||||
* delegated to MqttConnection objects. These are identified by "client
|
||||
@ -83,7 +79,8 @@ import android.util.Log;
|
||||
* MqttServiceConstants.CALLBACK_TO_ACTIVITY} which allows the Activity to
|
||||
* register a listener with an appropriate IntentFilter.<br>
|
||||
* Further data is provided by "Extra Data" in the Intent, as follows :-
|
||||
* <table border="1">
|
||||
* </p>
|
||||
* <table border="1" summary="">
|
||||
* <tr>
|
||||
* <th align="left">Name</th>
|
||||
* <th align="left">Data Type</th>
|
||||
@ -104,7 +101,7 @@ import android.util.Log;
|
||||
* MqttServiceConstants.CALLBACK_STATUS}</td>
|
||||
* <td align="left" valign="top">Serializable</td>
|
||||
* <td align="left" valign="top">An {@link Status} value indicating success or
|
||||
* otherwise of the operation</td>;
|
||||
* otherwise of the operation</td>
|
||||
* <td align="left" valign="top">All operations</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
@ -129,7 +126,7 @@ import android.util.Log;
|
||||
* MqttServiceConstants.CALLBACK_ACTION}</td>
|
||||
* <td align="left" valign="top">String</td>
|
||||
* <td align="left" valign="top">one of
|
||||
* <table>
|
||||
* <table summary="">
|
||||
* <tr>
|
||||
* <td align="left" valign="top"> {@link MqttServiceConstants#SEND_ACTION
|
||||
* MqttServiceConstants.SEND_ACTION}</td>
|
||||
@ -179,6 +176,7 @@ import android.util.Log;
|
||||
* relevant exception where possible)</td>
|
||||
* <td align="left" valign="top">All failing operations</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td align="left" valign="top">
|
||||
* {@link MqttServiceConstants#CALLBACK_ERROR_NUMBER
|
||||
* MqttServiceConstants.CALLBACK_ERROR_NUMBER}
|
||||
@ -222,9 +220,9 @@ import android.util.Log;
|
||||
* Parcelable format as a {@link ParcelableMqttMessage}</td>
|
||||
* <td align="left" valign="top">The Message Arrived event</td>
|
||||
* </tr>
|
||||
* </table >
|
||||
* </p>
|
||||
* </table>
|
||||
*/
|
||||
@SuppressLint("Registered")
|
||||
public class MqttService extends Service implements MqttTraceHandler {
|
||||
|
||||
// Identifier for Intents, log messages, etc..
|
||||
@ -254,7 +252,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
private MqttServiceBinder mqttServiceBinder;
|
||||
|
||||
// mapping from client handle strings to actual client connections.
|
||||
private Map<String/* clientHandle */, MqttConnection/* client */> connections = new ConcurrentHashMap<String, MqttConnection>();
|
||||
private Map<String/* clientHandle */, MqttConnection/* client */> connections = new ConcurrentHashMap<>();
|
||||
|
||||
public MqttService() {
|
||||
super();
|
||||
@ -296,10 +294,11 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
* @param serverURI specifies the protocol, host name and port to be used to connect to an MQTT server
|
||||
* @param clientId specifies the name by which this connection should be identified to the server
|
||||
* @param contextId specifies the app conext info to make a difference between apps
|
||||
* @param persistence specifies the persistence layer to be used with this client
|
||||
* @return a string to be used by the Activity as a "handle" for this
|
||||
* MqttConnection
|
||||
*/
|
||||
public String getClient(String serverURI, String clientId, String contextId,MqttClientPersistence persistence) {
|
||||
public String getClient(String serverURI, String clientId, String contextId, MqttClientPersistence persistence) {
|
||||
String clientHandle = serverURI + ":" + clientId+":"+contextId;
|
||||
if (!connections.containsKey(clientHandle)) {
|
||||
MqttConnection client = new MqttConnection(this, serverURI,
|
||||
@ -320,14 +319,14 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
* arbitrary data to be passed back to the application
|
||||
* @param activityToken
|
||||
* arbitrary identifier to be passed back to the Activity
|
||||
* @throws MqttSecurityException
|
||||
* @throws MqttException
|
||||
* @throws MqttSecurityException thrown if there is a security exception
|
||||
* @throws MqttException thrown for all other MqttExceptions
|
||||
*/
|
||||
public void connect(String clientHandle, MqttConnectOptions connectOptions,
|
||||
String invocationContext, String activityToken)
|
||||
throws MqttSecurityException, MqttException {
|
||||
MqttConnection client = getConnection(clientHandle);
|
||||
client.connect(connectOptions, invocationContext, activityToken);
|
||||
client.connect(connectOptions, null, activityToken);
|
||||
|
||||
}
|
||||
|
||||
@ -432,8 +431,8 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
* arbitrary data to be passed back to the application
|
||||
* @param activityToken
|
||||
* arbitrary identifier to be passed back to the Activity
|
||||
* @throws MqttPersistenceException
|
||||
* @throws MqttException
|
||||
* @throws MqttPersistenceException when a problem occurs storing the message
|
||||
* @throws MqttException if there was an error publishing the message
|
||||
* @return token for tracking the operation
|
||||
*/
|
||||
public IMqttDeliveryToken publish(String clientHandle, String topic,
|
||||
@ -458,8 +457,8 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
* arbitrary data to be passed back to the application
|
||||
* @param activityToken
|
||||
* arbitrary identifier to be passed back to the Activity
|
||||
* @throws MqttPersistenceException
|
||||
* @throws MqttException
|
||||
* @throws MqttPersistenceException when a problem occurs storing the message
|
||||
* @throws MqttException if there was an error publishing the message
|
||||
* @return token for tracking the operation
|
||||
*/
|
||||
public IMqttDeliveryToken publish(String clientHandle, String topic,
|
||||
@ -522,7 +521,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
* arbitrary data to be passed back to the application
|
||||
* @param activityToken
|
||||
* arbitrary identifier to be passed back to the Activity
|
||||
* @param messageListeners
|
||||
* @param messageListeners a callback to handle incoming messages
|
||||
*/
|
||||
public void subscribe(String clientHandle, String[] topicFilters, int[] qos, String invocationContext, String activityToken, IMqttMessageListener[] messageListeners){
|
||||
MqttConnection client = getConnection(clientHandle);
|
||||
@ -597,6 +596,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
*
|
||||
* @param clientHandle identifier for the client which received the message
|
||||
* @param id identifier for the MQTT message
|
||||
* @return {@link Status}
|
||||
*/
|
||||
public Status acknowledgeMessageArrival(String clientHandle, String id) {
|
||||
if (messageStore.discardArrived(clientHandle, id)) {
|
||||
@ -809,6 +809,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
private class NetworkConnectionIntentReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
@SuppressLint("Wakelock")
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
traceDebug(TAG, "Internal network status receive.");
|
||||
// we protect against the phone switching off
|
||||
@ -838,6 +839,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
public boolean isOnline() {
|
||||
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
||||
//noinspection RedundantIfStatement
|
||||
if (networkInfo != null
|
||||
&& networkInfo.isAvailable()
|
||||
&& networkInfo.isConnected()
|
||||
@ -851,7 +853,7 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
/**
|
||||
* Notify clients we're offline
|
||||
*/
|
||||
public void notifyClientsOffline() {
|
||||
private void notifyClientsOffline() {
|
||||
for (MqttConnection connection : connections.values()) {
|
||||
connection.offline();
|
||||
}
|
||||
@ -884,7 +886,8 @@ public class MqttService extends Service implements MqttTraceHandler {
|
||||
|
||||
/**
|
||||
* Sets the DisconnectedBufferOptions for this client
|
||||
* @param bufferOpts
|
||||
* @param clientHandle identifier for the client
|
||||
* @param bufferOpts the DisconnectedBufferOptions for this client
|
||||
*/
|
||||
public void setBufferOpts(String clientHandle, DisconnectedBufferOptions bufferOpts) {
|
||||
MqttConnection client = getConnection(clientHandle);
|
||||
|
@ -22,78 +22,78 @@ interface MqttServiceConstants {
|
||||
* Version information
|
||||
*/
|
||||
|
||||
static final String VERSION = "v0";
|
||||
String VERSION = "v0";
|
||||
|
||||
/*
|
||||
* Attributes of messages <p> Used for the column names in the database
|
||||
*/
|
||||
static final String DUPLICATE = "duplicate";
|
||||
static final String RETAINED = "retained";
|
||||
static final String QOS = "qos";
|
||||
static final String PAYLOAD = "payload";
|
||||
static final String DESTINATION_NAME = "destinationName";
|
||||
static final String CLIENT_HANDLE = "clientHandle";
|
||||
static final String MESSAGE_ID = "messageId";
|
||||
String DUPLICATE = "duplicate";
|
||||
String RETAINED = "retained";
|
||||
String QOS = "qos";
|
||||
String PAYLOAD = "payload";
|
||||
String DESTINATION_NAME = "destinationName";
|
||||
String CLIENT_HANDLE = "clientHandle";
|
||||
String MESSAGE_ID = "messageId";
|
||||
|
||||
/* Tags for actions passed between the Activity and the Service */
|
||||
static final String SEND_ACTION = "send";
|
||||
static final String UNSUBSCRIBE_ACTION = "unsubscribe";
|
||||
static final String SUBSCRIBE_ACTION = "subscribe";
|
||||
static final String DISCONNECT_ACTION = "disconnect";
|
||||
static final String CONNECT_ACTION = "connect";
|
||||
static final String CONNECT_EXTENDED_ACTION = "connectExtended";
|
||||
static final String MESSAGE_ARRIVED_ACTION = "messageArrived";
|
||||
static final String MESSAGE_DELIVERED_ACTION = "messageDelivered";
|
||||
static final String ON_CONNECTION_LOST_ACTION = "onConnectionLost";
|
||||
static final String TRACE_ACTION = "trace";
|
||||
String SEND_ACTION = "send";
|
||||
String UNSUBSCRIBE_ACTION = "unsubscribe";
|
||||
String SUBSCRIBE_ACTION = "subscribe";
|
||||
String DISCONNECT_ACTION = "disconnect";
|
||||
String CONNECT_ACTION = "connect";
|
||||
String CONNECT_EXTENDED_ACTION = "connectExtended";
|
||||
String MESSAGE_ARRIVED_ACTION = "messageArrived";
|
||||
String MESSAGE_DELIVERED_ACTION = "messageDelivered";
|
||||
String ON_CONNECTION_LOST_ACTION = "onConnectionLost";
|
||||
String TRACE_ACTION = "trace";
|
||||
|
||||
/* Identifies an Intent which calls back to the Activity */
|
||||
static final String CALLBACK_TO_ACTIVITY = MqttService.TAG
|
||||
String CALLBACK_TO_ACTIVITY = MqttService.TAG
|
||||
+ ".callbackToActivity"+"."+VERSION;
|
||||
|
||||
/* Identifiers for extra data on Intents broadcast to the Activity */
|
||||
static final String CALLBACK_ACTION = MqttService.TAG + ".callbackAction";
|
||||
static final String CALLBACK_STATUS = MqttService.TAG + ".callbackStatus";
|
||||
static final String CALLBACK_CLIENT_HANDLE = MqttService.TAG + "."
|
||||
String CALLBACK_ACTION = MqttService.TAG + ".callbackAction";
|
||||
String CALLBACK_STATUS = MqttService.TAG + ".callbackStatus";
|
||||
String CALLBACK_CLIENT_HANDLE = MqttService.TAG + "."
|
||||
+ CLIENT_HANDLE;
|
||||
static final String CALLBACK_ERROR_MESSAGE = MqttService.TAG
|
||||
String CALLBACK_ERROR_MESSAGE = MqttService.TAG
|
||||
+ ".errorMessage";
|
||||
static final String CALLBACK_EXCEPTION_STACK = MqttService.TAG
|
||||
String CALLBACK_EXCEPTION_STACK = MqttService.TAG
|
||||
+ ".exceptionStack";
|
||||
static final String CALLBACK_INVOCATION_CONTEXT = MqttService.TAG + "."
|
||||
String CALLBACK_INVOCATION_CONTEXT = MqttService.TAG + "."
|
||||
+ "invocationContext";
|
||||
static final String CALLBACK_ACTIVITY_TOKEN = MqttService.TAG + "."
|
||||
String CALLBACK_ACTIVITY_TOKEN = MqttService.TAG + "."
|
||||
+ "activityToken";
|
||||
static final String CALLBACK_DESTINATION_NAME = MqttService.TAG + '.'
|
||||
String CALLBACK_DESTINATION_NAME = MqttService.TAG + '.'
|
||||
+ DESTINATION_NAME;
|
||||
static final String CALLBACK_MESSAGE_ID = MqttService.TAG + '.'
|
||||
String CALLBACK_MESSAGE_ID = MqttService.TAG + '.'
|
||||
+ MESSAGE_ID;
|
||||
static final String CALLBACK_RECONNECT = MqttService.TAG + ".reconnect";
|
||||
static final String CALLBACK_SERVER_URI = MqttService.TAG + ".serverURI";
|
||||
static final String CALLBACK_MESSAGE_PARCEL = MqttService.TAG + ".PARCEL";
|
||||
static final String CALLBACK_TRACE_SEVERITY = MqttService.TAG
|
||||
String CALLBACK_RECONNECT = MqttService.TAG + ".reconnect";
|
||||
String CALLBACK_SERVER_URI = MqttService.TAG + ".serverURI";
|
||||
String CALLBACK_MESSAGE_PARCEL = MqttService.TAG + ".PARCEL";
|
||||
String CALLBACK_TRACE_SEVERITY = MqttService.TAG
|
||||
+ ".traceSeverity";
|
||||
static final String CALLBACK_TRACE_TAG = MqttService.TAG + ".traceTag";
|
||||
static final String CALLBACK_TRACE_ID = MqttService.TAG + ".traceId";
|
||||
static final String CALLBACK_ERROR_NUMBER = MqttService.TAG
|
||||
String CALLBACK_TRACE_TAG = MqttService.TAG + ".traceTag";
|
||||
String CALLBACK_TRACE_ID = MqttService.TAG + ".traceId";
|
||||
String CALLBACK_ERROR_NUMBER = MqttService.TAG
|
||||
+ ".ERROR_NUMBER";
|
||||
|
||||
static final String CALLBACK_EXCEPTION = MqttService.TAG + ".exception";
|
||||
String CALLBACK_EXCEPTION = MqttService.TAG + ".exception";
|
||||
|
||||
//Intent prefix for Ping sender.
|
||||
static final String PING_SENDER = MqttService.TAG + ".pingSender.";
|
||||
String PING_SENDER = MqttService.TAG + ".pingSender.";
|
||||
|
||||
//Constant for wakelock
|
||||
static final String PING_WAKELOCK = MqttService.TAG + ".client.";
|
||||
static final String WAKELOCK_NETWORK_INTENT = MqttService.TAG + "";
|
||||
String PING_WAKELOCK = MqttService.TAG + ".client.";
|
||||
String WAKELOCK_NETWORK_INTENT = MqttService.TAG + "";
|
||||
|
||||
//Trace severity levels
|
||||
static final String TRACE_ERROR = "error";
|
||||
static final String TRACE_DEBUG = "debug";
|
||||
static final String TRACE_EXCEPTION = "exception";
|
||||
String TRACE_ERROR = "error";
|
||||
String TRACE_DEBUG = "debug";
|
||||
String TRACE_EXCEPTION = "exception";
|
||||
|
||||
|
||||
//exception code for non MqttExceptions
|
||||
static final int NON_MQTT_EXCEPTION = -1;
|
||||
int NON_MQTT_EXCEPTION = -1;
|
||||
|
||||
}
|