]> iEval git - fonbot.git/blobdiff - src/ro/ieval/fonbot/Utils.java
Replace GCM and polling with long polling
[fonbot.git] / src / ro / ieval / fonbot / Utils.java
index 117c528f6408d8cea153b5f665544009935329c0..8548404aa2b62ae1af196f02287313dfe459c1d1 100644 (file)
@@ -86,7 +86,8 @@ public final class Utils {
                NEXT, PREV, BATT, CALLLOG, SMSLOG,
                LS, RM, CONTACTS, DISABLE, ENABLE,
                POLL, HANGUP, ANSWER, LAUNCH, DATA,
-               GPS, GLOCATION, REBOOT, SHUTDOWN, NOTIFY
+               GPS, GLOCATION, REBOOT, NOTIFY, SCREENCAP,
+               TORCH
        }
 
        /**
@@ -109,7 +110,9 @@ public final class Utils {
                /** Fine battery status notifications */
                BATTERY_CHANGED,
                /** Headset plug/unplug notifications */
-               HEADSET
+               HEADSET,
+               /** Phone booted notifications */
+               BOOT,
        }
 
        /**
@@ -181,9 +184,7 @@ public final class Utils {
                /** Location tracking is active. Registered by {@link Command#LOCATION}, unregistered by {@link Command#NOLOCATION} */
                LOCATION(location_tracking_is_active),
                /** The phone is ringing. Registered/unregistered by {@link Command#RING} */
-               RING(ringing),
-               /** The polling alarm is on. Registered/unregistered by {@link Command#POLL} */
-               POLL(the_polling_service_is_running);
+               RING(ringing);
 
                /** String resource: the event description */
                public final int resource;
@@ -316,8 +317,8 @@ public final class Utils {
        public static void sendMessage(final Context context, final Address address, final String message){
                switch(address.protocol){
                case HTTP:
-                       new SendHttpMessageAsyncTask(toNonNull(Arrays.asList(
-                                       new Header("X-Action", "SEND "+address.data))), context).execute(message);
+                       new HttpCallExecutableRunnable("/send", toNonNull(Arrays.asList(
+                                       new Header("X-Destination", toNonNull(address.data)))), context, null, true, message).execute();
                        break;
 
                case SMS:
@@ -335,19 +336,6 @@ public final class Utils {
                }
        }
 
-       /**
-        * Parses a HTTP response message of the form <code>(part1) part2</code>, returning <code>part2</code>.
-        *
-        * @param message the raw HTTP response message
-        * @return the extracted part
-        */
-       public static String parseHttpMessage(final String message){
-               final int indexOfParen=message.indexOf(')');
-               if(indexOfParen==-1)
-                       return message;
-               return toNonNull(message.substring(indexOfParen+2));
-       }
-
        /**
         * Splits a string into words.
         *
@@ -417,8 +405,8 @@ public final class Utils {
         * @throws MalformedURLException if the user preferences create an invalid URL
         */
        public static URL getServerURL(final Context context, final String path) throws MalformedURLException{
-               final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "ieval.ro");
-               final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "7777"));
+               final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "fonbot.ieval.ro");
+               final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "443"));
                final URL url=new URL("http", hostname, port, path);
                return url;
        }
@@ -433,7 +421,7 @@ public final class Utils {
         */
        private static void processCommand(final Context context, final Command cmd,final String[] args,final Address replyTo){
                if(Heavy.isCommandDisabled(context, cmd)){
-                       sendMessage(context, replyTo, command_disabled);
+                       sendMessage(context, replyTo, command_disabled, cmd.toString());
                        return;
                }
 
@@ -898,25 +886,7 @@ public final class Utils {
                        break;
 
                case POLL:
-                       if(args.length>1){
-                               Heavy.help(context, replyTo, toNonNull(Command.POLL));
-                               break;
-                       }
-
-                       if(args.length==0){
-                               Heavy.poll(context, replyTo);
-                               break;
-                       }
-
-                       final long interval;
-                       try{
-                               interval=Long.parseLong(args[0]);
-                       } catch(NumberFormatException e){
-                               sendMessage(context, replyTo, cannot_parse_interval);
-                               break;
-                       }
-
-                       Heavy.poll(context, replyTo, interval);
+                       Heavy.poll(context, replyTo);
                        break;
 
                case HANGUP:
@@ -997,13 +967,10 @@ public final class Utils {
                        Heavy.reboot(context, replyTo, args.length==0?null:args[0]);
                        break;
 
-               case SHUTDOWN:
-                       //TODO: implement command
-                       break;
-
                case NOTIFY:
                        if(args.length!=1 && args.length!=3){
                                Heavy.help(context, replyTo, toNonNull(Command.NOTIFY));
+                               return;
                        }
 
                        final int id;
@@ -1019,6 +986,19 @@ public final class Utils {
                        else
                                Heavy.notify(context, replyTo, id, toNonNull(args[1]), toNonNull(args[2]));
                        break;
+
+               case SCREENCAP:
+                       if(args.length != 1){
+                               Heavy.help(context, replyTo, toNonNull(Command.SCREENCAP));
+                               return;
+                       }
+
+                       Heavy.screencap(context, replyTo, args[0]);
+                       break;
+
+               case TORCH:
+                       Heavy.torch(context, replyTo);
+                       break;
                }
 
        }
This page took 0.030774 seconds and 4 git commands to generate.