Skip to content

Commit

Permalink
Lots of small fixes and linter improvements to the sample and example…
Browse files Browse the repository at this point in the history
… projects (eclipse-paho#134)

Signed-off-by: James Sutton <[email protected]>
  • Loading branch information
jpwsutton authored Oct 12, 2016
1 parent ea36ad1 commit b2c7766
Show file tree
Hide file tree
Showing 69 changed files with 847 additions and 1,183 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ jdk: oraclejdk8
android:
components:
- tools
- build-tools-24.0.1
- android-23
- build-tools-23.0.3
- android-24
- extra-android-support
- extra

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
42 changes: 30 additions & 12 deletions org.eclipse.paho.android.sample/org.eclipse.paho.android.sample.iml
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,51 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<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/animated-vector-drawable/23.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.3.0/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/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<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/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<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/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.3.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.3.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.3.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-23.3.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-23.3.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.3.0" 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" />
Expand Down
6 changes: 4 additions & 2 deletions org.eclipse.paho.android.sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@


<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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +12,7 @@
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;

Expand Down Expand Up @@ -51,21 +53,21 @@ enum Action {
* 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
Expand Down Expand Up @@ -116,7 +118,7 @@ public void onSuccess(IMqttToken asyncActionToken) {
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);
Expand Down Expand Up @@ -213,7 +215,7 @@ public void onFailure(IMqttToken token, Throwable exception) {
*/
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -20,5 +20,5 @@ public class ActivityConstants {


/** Empty String for comparisons **/
static final String empty = new String();
static final String empty = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -113,7 +114,7 @@ public enum ConnectionStatus {
*/
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 {
Expand All @@ -125,7 +126,7 @@ public static Connection createConnection(String clientHandle, String clientId,
}

public void updateConnection(String clientId, String host, int port, boolean tlsConnection){
String uri = null;
String uri;
if(tlsConnection) {
uri = "ssl://" + host + ":" + port;
} else {
Expand All @@ -136,8 +137,7 @@ public void updateConnection(String clientId, String host, int port, boolean tls
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);

}

Expand All @@ -153,8 +153,8 @@ public void updateConnection(String clientId, String host, int port, boolean tls
* @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;
Expand All @@ -164,11 +164,10 @@ public Connection(String clientHandle, String clientId, String host,
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);
}

/**
Expand All @@ -178,35 +177,15 @@ public Connection(String clientHandle, String clientId, String host,
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);

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
Expand Down Expand Up @@ -271,15 +250,6 @@ public String toString() {
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
Expand Down Expand Up @@ -315,22 +285,6 @@ public String getHostName() {
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
Expand Down Expand Up @@ -366,20 +320,9 @@ public void registerChangeListener(PropertyChangeListener listener)
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)
{
Expand Down
Loading

0 comments on commit b2c7766

Please sign in to comment.