Commits

ferron  committed 98a4ab8

Added a new Simple Client extension to make it easier for developers to setup push notifications

  • Participants
  • Parent commits e1e6639

Comments (0)

Files changed (5)

 <classpath>
 	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
 	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
-	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
-	<classpathentry kind="lib" path="G:/kk/workspace/untitled folder/SpikeMe/externaljars/commons-codec-1.4.jar"/>
-	<classpathentry kind="lib" path="G:/kk/workspace/untitled folder/SpikeMe/externaljars/commons-logging-1.1.1.jar"/>
-	<classpathentry kind="lib" path="G:/kk/workspace/untitled folder/SpikeMe/externaljars/httpclient-4.1.jar"/>
-	<classpathentry kind="lib" path="G:/kk/workspace/untitled folder/SpikeMe/externaljars/httpcore-4.1.jar"/>
+	<classpathentry kind="lib" path="E:/kk/workspace/untitled folder/SpikeMe/externaljars/commons-codec-1.4.jar"/>
+	<classpathentry kind="lib" path="E:/kk/workspace/untitled folder/SpikeMe/externaljars/commons-logging-1.1.1.jar"/>
+	<classpathentry kind="lib" path="E:/kk/workspace/untitled folder/SpikeMe/externaljars/httpclient-4.1.jar"/>
+	<classpathentry kind="lib" path="E:/kk/workspace/untitled folder/SpikeMe/externaljars/httpcore-4.1.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 	<classpathentry kind="output" path="target/classes"/>
 </classpath>
 syntax: regexp
 ^target$
 syntax: regexp
-^temp-testng-customsuite\.xml$
+^temp-testng-customsuite\.xml$
+syntax: regexp
+^src/main/java/com/google/gson/reflect$
+syntax: regexp
+^src/main/java/com/google/gson$
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>urbanairship-java</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.maven.ide.eclipse.maven2Builder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.maven.ide.eclipse.maven2Nature</nature>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-	</natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>urbanairship-java</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

File .settings/org.eclipse.jdt.core.prefs

-#Tue Feb 16 21:36:11 PST 2010
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+#Thu Jun 23 02:55:23 EDT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

File src/main/java/urbanairship/UrbanAirShipSimpleClient.java

+package urbanairship;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import urbanairship.UrbanAirshipClient;
+
+//TODO: Comment methods
+
+/***
+ * The following class is used by the sample package to create a UrbanAirship client instance
+ * @author ferron
+ *
+ */
+public class UrbanAirShipSimpleClient extends UrbanAirshipClient {
+	
+	private static ArrayList<String> dToken = new ArrayList<String>(), apiD = new ArrayList<String>();
+
+	public UrbanAirShipSimpleClient(String app_key, String master_key) {
+		super(app_key, master_key);
+	}
+	
+	public UrbanAirShipSimpleClient(String app_key, String master_key, String hostname) {
+		super(app_key, master_key,hostname);
+	}
+		
+	
+	/**
+	 * The following function converts an array to an ArrayList
+	 * @param myArray
+	 * @return
+	 */
+	public List<String> convertArrayToArrayList(String[] myArray) {
+		   List <String> myArrayList = new ArrayList <String>();
+		   for(String var : myArray)
+			   myArrayList.add(var);   
+		   return(myArrayList);
+	}
+
+   /**
+    * The following function checks if a string is a valid device token
+    * @param key device token
+    * @return boolean
+    */
+	public boolean isDeviceToken(String key){
+    	return key.length() == 64 && !key.contains("-");
+    }
+	
+	/**
+	 * The following returns a collection of device tokens
+	 * @return token collection
+	 */
+	public ArrayList<String> getTokens() {
+		return dToken;
+	}
+	
+	/**
+	 * The following function returns a collection of apids
+	 * @return apid collection
+	 */
+	public ArrayList<String> getAPids() {
+		return apiD;
+	}
+	
+
+	/**
+	 * The following function sorts collection apid/token into it's correct Collection
+	 * @param Collection of apid/token
+	 */
+	public void tokenSort(String [] val) {
+		for(String v : val)
+			tokenSort(v);
+	}
+	
+	/**
+	 * The following function sorts collection apid/token into it's correct Collection
+	 * @param Collection of apid/token
+	 */
+	public void tokenSort(List<String> val) {
+		for(String v : val)
+			tokenSort(v);
+	}
+	
+	/**
+	 * The following function sorts apid/token into it's correct Collection
+	 * @param apid/token
+	 */
+	public void tokenSort(String val) {
+		if(isDeviceToken(val))
+			dToken.add(val);
+		else apiD.add(val);
+	}
+	
+	/**
+	 * The following function return a count of tokens
+	 * @return token count
+	 */
+	public int tokAmt() {
+		return dToken.size();
+	}
+	
+	/**
+	 * The following function return a count of apid
+	 * @return apid count
+	 */
+	public int apidAmt() {
+		return apiD.size();
+	}
+	
+	/**
+	 * The following function return true if apid exists
+	 * @return boolean
+	 */
+	public boolean hasApid() {
+		return apiD.size() > 0;
+	}
+	
+	/**
+	 * The following function adds a device to a specific specific array
+	 * @param device
+	 */
+	public void addDevice(String device) {
+		tokenSort(device);
+	}
+	
+	/**
+	 * The following function adds a devices to a specific array
+	 * @param device
+	 */
+	public void addDevice(String [] device) {
+		tokenSort(device);
+	}
+	
+	/**
+	 * The following function send notifications to all devices
+	 * @param alert
+	 */
+	public void broadcastNotifications(String alert) {
+		Push droid = createAndroidPush(alert);
+		Push iOs = createIOSPush(alert);
+		Push merge = merge(droid,iOs);
+		if(merge != null)
+			this.sendPushNotifications(merge);
+	}
+	
+	/**
+	 * The following function sends notification to all android devices listed
+	 * @param alert
+	 */
+	public void notifyAndroidDevices(String alert) {
+		this.sendPushNotifications(createAndroidPush(alert));
+	}
+	
+	/**
+	 * The following function sends notifications to all iOS devices listed
+	 * @param alert
+	 */
+	public void notifyIOSDevices(String alert) {
+		this.sendPushNotifications(createIOSPush(alert));
+	}
+	
+	/**
+	 * The following function merge droid and iOs push iOS push object
+	 * @param droid - droid push object
+	 * @param iOs - iOs push object
+	 * @return merged push object
+	 */
+	private Push merge(Push droid, Push iOs) {
+		if(droid == null || iOs == null) 
+			return null;
+		
+		iOs.setApids(droid.getApids());
+		iOs.setAndroid(droid.getAndroid());
+		return iOs;
+	}
+	
+	/**
+	 * The following function creates an Android push object
+	 * @see Push#setAndroid(Android)
+	 * @param alert - message to send
+	 * @return Android push object
+	 */
+	private Push createAndroidPush(String alert) {
+		Push push = createPush(alert);
+		push.setApids(apiD);
+		Android android = new Android();
+		android.setAlert(alert);
+		push.setAndroid(android);
+		return push;
+	}
+	
+	/**
+	 * The following function creates an IOS push object
+	 * @param alert - message to send
+	 * @return iOS push object
+	 */
+	private Push createIOSPush(String alert) {
+		Push push = createPush(alert);
+		push.setDeviceTokens(dToken);
+		return push;
+	}
+	
+	/**
+	 * Generic push object
+	 * @param alert
+	 * @return
+	 */
+	private Push createPush(String alert) {
+		APS aps = new APS();
+		aps.setAlert(alert);
+		Push push = new Push();
+		push.setAps(aps);
+        return push;
+	}
+}