]> iEval git - fonbot.git/blobdiff - src/ro/ieval/fonbot/Utils.java
Let the user choose which camera to take photos with
[fonbot.git] / src / ro / ieval / fonbot / Utils.java
index 79ff2e1e37236de3b571e246f434415827527ed0..c425420e84013dfa545d55ff2e6633853304d044 100644 (file)
@@ -1,28 +1,6 @@
 package ro.ieval.fonbot;
 
-import static ro.ieval.fonbot.R.string.cannot_parse_count;
-import static ro.ieval.fonbot.R.string.cannot_parse_interval;
-import static ro.ieval.fonbot.R.string.cannot_parse_min_distance;
-import static ro.ieval.fonbot.R.string.cannot_parse_min_time;
-import static ro.ieval.fonbot.R.string.cannot_parse_port;
-import static ro.ieval.fonbot.R.string.cannot_parse_provider_allowed_values_are;
-import static ro.ieval.fonbot.R.string.command_disabled;
-import static ro.ieval.fonbot.R.string.could_not_parse_argument_allowed_values_are;
-import static ro.ieval.fonbot.R.string.could_not_parse_ms;
-import static ro.ieval.fonbot.R.string.error_while_processing_command;
-import static ro.ieval.fonbot.R.string.invalid_length_allowed_values_are;
-import static ro.ieval.fonbot.R.string.invalid_ringer_mode_valid_values_are;
-import static ro.ieval.fonbot.R.string.location_tracking_is_active;
-import static ro.ieval.fonbot.R.string.messagetype_should_be_one_of;
-import static ro.ieval.fonbot.R.string.no_such_command_command_list;
-import static ro.ieval.fonbot.R.string.notification_disabled;
-import static ro.ieval.fonbot.R.string.notification_enabled;
-import static ro.ieval.fonbot.R.string.ringing;
-import static ro.ieval.fonbot.R.string.security_exception;
-import static ro.ieval.fonbot.R.string.the_polling_service_is_running;
-import static ro.ieval.fonbot.R.string.the_second_argument_to_wipe_must_be;
-import static ro.ieval.fonbot.R.string.unknown_command;
-import static ro.ieval.fonbot.R.string.wipetype_should_be_one_of;
+import static ro.ieval.fonbot.R.string.*;
 
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -184,9 +162,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;
@@ -409,29 +385,10 @@ public final class Utils {
        public static URL getServerURL(final Context context, final String path) throws MalformedURLException{
                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("https", hostname, port, path);
+               final URL url=new URL("http", hostname, port, path);
                return url;
        }
 
-       /**
-        * Poll the server for pending commands. This function must not be called from BroadcastReceivers
-        *
-        * @param context Context instance
-        */
-       public static void pollServer(final Context context){
-               new HttpCallExecutableRunnable("/get", null, context, new PollResultCallback(context), false).execute();
-       }
-
-       /**
-        * Poll the server for pending commands from {@link FonBotMainService}. This function should be used from BroadcastReceviers instead of {@link #pollServer}
-        *
-        * @param context Context instance
-        */
-       public static void safePollServer(final Context context){
-               final Intent intent=new Intent(context, FonBotMainService.class);
-               intent.setAction(FonBotMainService.ACTION_TRIGGER_POLL);
-               context.startService(intent);
-       }
        /**
         * Executes a given command
         *
@@ -683,18 +640,27 @@ public final class Utils {
                        break;
 
                case PHOTO:
-                       if(args.length!=2){
+                       if(args.length!=3){
                                Heavy.help(context, replyTo, toNonNull(Command.PHOTO));
                                break;
                        }
+
+                       final int cameraNumber;
+                       try{
+                               cameraNumber=Integer.parseInt(args[0]);
+                       } catch (NumberFormatException e){
+                               sendMessage(context, replyTo, cannot_parse_camera_number);
+                               break;
+                       }
+
                        final int photoPort;
                        try{
-                               photoPort=Integer.parseInt(args[1]);
+                               photoPort=Integer.parseInt(args[2]);
                        } catch (NumberFormatException e){
                                sendMessage(context, replyTo, cannot_parse_port);
                                break;
                        }
-                       Heavy.photo(context, replyTo, toNonNull(args[0]), photoPort);
+                       Heavy.photo(context, replyTo, cameraNumber, toNonNull(args[1]), photoPort);
                        break;
 
                case SETNOTIFICATION:
@@ -907,25 +873,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:
This page took 0.027094 seconds and 4 git commands to generate.