Merge branch 'develop' into videoInstandUploads
authormasensio <masensio@solidgear.es>
Tue, 8 Apr 2014 10:50:50 +0000 (12:50 +0200)
committermasensio <masensio@solidgear.es>
Tue, 8 Apr 2014 10:50:50 +0000 (12:50 +0200)
AndroidManifest.xml
res/values/strings.xml
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

index 3067a40..48d5b0c 100644 (file)
                 <data android:mimeType="image/*" />
             </intent-filter>
             <intent-filter>
+                <action android:name="android.hardware.action.NEW_VIDEO" />
+                <data android:mimeType="video/*" />
+            </intent-filter>
+            <intent-filter>
                 <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
             </intent-filter>
         </receiver>
index 8d243fc..39ea260 100644 (file)
@@ -19,7 +19,7 @@
     <string name="prefs_pincode">App PIN</string>
     <string name="prefs_pincode_summary">Protect your client</string>
     <string name="prefs_instant_upload">Enable instant uploads</string>
-    <string name="prefs_instant_upload_summary">Instantly upload photos taken by camera</string>
+    <string name="prefs_instant_upload_summary">Instantly upload media taken by camera</string>
     <string name="prefs_log_title">Enable Logging</string>
     <string name="prefs_log_summary">This is used to log problems</string>
     <string name="prefs_log_title_history">Logging History</string>
index 1943d32..ee004b2 100644 (file)
@@ -1,6 +1,6 @@
 /* ownCloud Android client application
  *   Copyright (C) 2012  Bartek Przybylski
- *   Copyright (C) 2012-2013 ownCloud Inc.
+ *   Copyright (C) 2012-2014 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License version 2,
@@ -37,18 +37,20 @@ import android.database.Cursor;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo.State;
 import android.preference.PreferenceManager;
-import android.provider.MediaStore.Images.Media;
+import android.provider.MediaStore.*;
 import android.webkit.MimeTypeMap;
 
 
 public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
     private static String TAG = "InstantUploadBroadcastReceiver";
-    private static final String[] CONTENT_PROJECTION = { Media.DATA, Media.DISPLAY_NAME, Media.MIME_TYPE, Media.SIZE };
+   // private static final String[] CONTENT_PROJECTION = { Media.DATA, Media.DISPLAY_NAME, Media.MIME_TYPE, Media.SIZE };
     //Unofficial action, works for most devices but not HTC. See: https://github.com/owncloud/android/issues/6
     private static String NEW_PHOTO_ACTION_UNOFFICIAL = "com.android.camera.NEW_PICTURE";
     //Officially supported action since SDK 14: http://developer.android.com/reference/android/hardware/Camera.html#ACTION_NEW_PICTURE
     private static String NEW_PHOTO_ACTION = "android.hardware.action.NEW_PICTURE";
+    // Video action
+    private static String NEW_VIDEO_ACTION = "android.hardware.action.NEW_VIDEO";
 
     @Override
     public void onReceive(Context context, Intent intent) {
@@ -56,11 +58,13 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
             handleConnectivityAction(context, intent);
         }else if (intent.getAction().equals(NEW_PHOTO_ACTION_UNOFFICIAL)) {
-            handleNewPhotoAction(context, intent);
+            handleNewMediaAction(context, intent); //handleNewPhotoAction(context, intent);
             Log_OC.d(TAG, "UNOFFICIAL processed: com.android.camera.NEW_PICTURE");
         } else if (intent.getAction().equals(NEW_PHOTO_ACTION)) {
-            handleNewPhotoAction(context, intent);
+            handleNewMediaAction(context, intent); //handleNewPhotoAction(context, intent);
             Log_OC.d(TAG, "OFFICIAL processed: android.hardware.action.NEW_PICTURE");
+        } else if (intent.getAction().equals(NEW_PHOTO_ACTION) || intent.getAction().equals(NEW_VIDEO_ACTION)) {
+            handleNewMediaAction(context, intent);
         } else if (intent.getAction().equals(FileUploader.getUploadFinishMessage())) {
             handleUploadFinished(context, intent);
         } else {
@@ -82,7 +86,12 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         */
     }
 
-    private void handleNewPhotoAction(Context context, Intent intent) {
+    private void handleNewMediaAction(Context context, Intent intent) {
+        Cursor c = null;
+        String file_path = null;
+        String file_name = null;
+        String mime_type = null;
+
         if (!instantUploadEnabled(context)) {
             Log_OC.d(TAG, "Instant upload disabled, aborting uploading");
             return;
@@ -94,19 +103,36 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
             return;
         }
 
-        Cursor c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
-
-        if (!c.moveToFirst()) {
-            Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
-            return;
+        if (intent.getAction().equals(NEW_PHOTO_ACTION)) {
+            String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE, Images.Media.SIZE };
+            c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
+            if (!c.moveToFirst()) {
+                Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
+                return;
+            }
+            file_path = c.getString(c.getColumnIndex(Images.Media.DATA));
+            file_name = c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));
+            mime_type = c.getString(c.getColumnIndex(Images.Media.MIME_TYPE));
+            Log_OC.w(TAG, "New photo received");
+        }
+        else if (intent.getAction().equals(NEW_VIDEO_ACTION)) {
+            if (!isConnectedViaWiFi(context)) {
+                Log_OC.e(TAG, "No Wifi available .. Video instant upload only possible if WiFi is on");
+                return;
+            }
+            String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE, Video.Media.SIZE };
+            c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
+            if (!c.moveToFirst()) {
+                Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
+                return;
+            } 
+            file_path = c.getString(c.getColumnIndex(Video.Media.DATA));
+            file_name = c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));
+            mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE));
+            Log_OC.w(TAG, "New video received");
         }
-
-        String file_path = c.getString(c.getColumnIndex(Media.DATA));
-        String file_name = c.getString(c.getColumnIndex(Media.DISPLAY_NAME));
-        String mime_type = c.getString(c.getColumnIndex(Media.MIME_TYPE));
-
         c.close();
-        Log_OC.e(TAG, file_path + "");
+        Log_OC.d(TAG, file_path + "");
 
         // same always temporally the picture to upload
         DbHandler db = new DbHandler(context);