]> iEval git - fonbot.git/commitdiff
Let the user choose which camera to take photos with
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 27 Jul 2013 15:25:43 +0000 (18:25 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 27 Jul 2013 15:25:43 +0000 (18:25 +0300)
res/values/strings.xml
src/ro/ieval/fonbot/Heavy.java
src/ro/ieval/fonbot/Utils.java

index 235158949278646b2f7a15c699269ac526d78594..2924533d084a51fcd7b6895f25ebffabe3020c3a 100644 (file)
@@ -233,9 +233,10 @@ The help command can be used to get a list of commands and help for them. Exampl
                Example: ring on
     </string>
     <string name="photo_help">
-        Usage: photo hostname port\n
-               Takes a photo and uploads it to &lt;hostname&gt;:&lt;port&gt;\n
-               Example: photo 1.1.1.1 8888
+        Usage: photo camera hostname port\n
+               Takes a photo with the given camera and uploads it to &lt;hostname&gt;:&lt;port&gt;\n
+               The camera is a number, usually 0 for the rear camera and 1 for the front one\n
+               Example: photo 0 1.1.1.1 8888
     </string>
     <string name="nolocation_help">
         Usage: nolocation\n
@@ -464,4 +465,5 @@ The help command can be used to get a list of commands and help for them. Exampl
        </string>
        <string name="toggling_torch_state">Toggling torch stateā€¦</string>
        <string name="device_booted">Your device has been turned on</string>
+       <string name="cannot_parse_camera_number">Cannot parse camera number</string>
 </resources>
index c06234d7ac35a2a9ec1e97ab641d970f91840438..85aff17016325459fb3f1d748f1b169e76ded185 100644 (file)
@@ -640,11 +640,15 @@ final class Heavy {
         * @param context Context instance
         * @param replyTo reply Address
         */
-       private static void startCamera(final Context context, final Address replyTo){
+       private static void startCamera(final Context context, final Address replyTo, final int cameraNumber){
                if(camera!=null)
                        return;
                try{
-                       camera=Camera.open();
+                       try{
+                               camera=Camera.open(cameraNumber);
+                       } catch (Exception ex){
+                               camera=Camera.open();
+                       }
                } catch (Exception e){
                        Utils.sendMessage(context, replyTo, cannot_grab_camera);
                }
@@ -956,7 +960,7 @@ final class Heavy {
         * @param on requested flashlight state
         */
        public static void flash(final Context context, final Address replyTo, final boolean on){
-               startCamera(context, replyTo);
+               startCamera(context, replyTo, 0);
                if(camera==null)
                        return;
                final Camera.Parameters parms=camera.getParameters();
@@ -1103,11 +1107,12 @@ final class Heavy {
         *
         * @param context Context instance
         * @param replyTo reply Address
+        * @param cameraNumber camera to take photo with
         * @param hostname server hostname
         * @param port server port
         */
-       public static void photo(final Context context, final Address replyTo, final String hostname, final int port){
-               startCamera(context, replyTo);
+       public static void photo(final Context context, final Address replyTo, final int cameraNumber, final String hostname, final int port){
+               startCamera(context, replyTo, cameraNumber);
                if(camera==null)
                        return;
                final Camera.Parameters parms=camera.getParameters();
index 8548404aa2b62ae1af196f02287313dfe459c1d1..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;
@@ -662,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:
This page took 0.026003 seconds and 4 git commands to generate.