cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject cordova-plugin-file git commit: CB-11368 android: Resolve content URLs produced by contacts plugin
Date Tue, 23 Aug 2016 07:26:33 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 47a428f0d -> 9860bbb85


CB-11368 android: Resolve content URLs produced by contacts plugin

This bug was happening because of invalid assignment of null value to variable of primitive
type

 This closes #192


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/9860bbb8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/9860bbb8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/9860bbb8

Branch: refs/heads/master
Commit: 9860bbb8567a7ab8994996a3a66313510a05f64a
Parents: 47a428f
Author: Nikita Matrosov <matrosov.nikita94@gmail.com>
Authored: Mon Aug 22 20:11:24 2016 +0300
Committer: Vladimir Kotikov <kotikov.vladimir@gmail.com>
Committed: Tue Aug 23 10:26:01 2016 +0300

----------------------------------------------------------------------
 src/android/ContentFilesystem.java | 13 +++++----
 tests/plugin.xml                   |  1 +
 tests/tests.js                     | 50 +++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9860bbb8/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 1991b35..6b983c0 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -124,16 +124,19 @@ public class ContentFilesystem extends Filesystem {
         String mimeType = resourceApi.getMimeType(nativeUri);
         Cursor cursor = openCursorForURL(nativeUri);
         try {
-        	if (cursor != null && cursor.moveToFirst()) {
-        		size = resourceSizeForCursor(cursor);
+            if (cursor != null && cursor.moveToFirst()) {
+                Long sizeForCursor = resourceSizeForCursor(cursor);
+                if (sizeForCursor != null) {
+                    size = sizeForCursor.longValue();
+                }
                 Long modified = lastModifiedDateForCursor(cursor);
                 if (modified != null)
                     lastModified = modified.longValue();
-        	} else {
+            } else {
                 // Some content providers don't support cursors at all!
                 CordovaResourceApi.OpenForReadResult offr = resourceApi.openForRead(nativeUri);
-    			size = offr.length;
-        	}
+                size = offr.length;
+            }
         } catch (IOException e) {
             FileNotFoundException fnfe = new FileNotFoundException();
             fnfe.initCause(e);

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9860bbb8/tests/plugin.xml
----------------------------------------------------------------------
diff --git a/tests/plugin.xml b/tests/plugin.xml
index c97f291..cc228be 100644
--- a/tests/plugin.xml
+++ b/tests/plugin.xml
@@ -39,5 +39,6 @@
                 android:exported="false" />
         </config-file>
         <asset src="www/fixtures/asset-test" target="fixtures/asset-test" />
+        <dependency id="cordova-plugin-contacts" />
     </platform>
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9860bbb8/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index e0a8b3b..c57d18b 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -3837,6 +3837,37 @@ exports.defineManualTests = function (contentEl, createActionButton)
{
         }, logError("requestFileSystem"));
     }
 
+    function resolveFsContactImage() {
+        navigator.contacts.pickContact(function(contact) {
+            var logBox = document.getElementById("logContactBox");
+            logBox.innerHTML = "";
+            var resolveResult = document.createElement("p");
+            if (contact.photos) {
+                var photoURL = contact.photos[0].value;
+                resolveLocalFileSystemURL(photoURL, function(entry) {
+                    var contactImage = document.createElement("img");
+                    var contactLabelImage = document.createElement("p");                
      
+                    contactLabelImage.innerHTML = "Result contact image";               
   
+                    contactImage.setAttribute("src", entry.toURL());
+                    resolveResult.innerHTML = "Success resolve\n" + entry.toURL();
+                    logBox.appendChild(contactLabelImage);
+                    logBox.appendChild(contactImage);
+                    logBox.appendChild(resolveResult);
+                }, 
+                function(err) {
+                    console.log("resolve error" + err);
+                }); 
+            }
+            else {
+                resolveResult.innerHTML = "Contact has no photos";
+                logBox.appendChild(resolveResult);
+            }
+        }, 
+        function(err) {
+            console.log("contact pick error" + err);
+        });
+    }    
+
     function clearLog() {
         var log = document.getElementById("info");
         log.innerHTML = "";
@@ -3914,4 +3945,23 @@ exports.defineManualTests = function (contentEl, createActionButton)
{
         'should be successfully resolved. Status box should say Successfully resolved. Both
blue URLs below ' +
         'that should match.'));
     contentEl.appendChild(div);
+
+    div = document.createElement('h2');
+    div.appendChild(document.createTextNode('Resolving content urls'));
+    div.setAttribute("align", "center");
+    contentEl.appendChild(div);
+
+    div = document.createElement('div');
+    div.setAttribute("id", "contactButton");
+    div.setAttribute("align", "center");
+    contentEl.appendChild(div);
+
+    div = document.createElement('div');
+    div.setAttribute("id", "logContactBox");
+    div.setAttribute("align", "center");
+    contentEl.appendChild(div);
+
+    createActionButton('show-contact-image', function () {
+        resolveFsContactImage();
+    }, 'contactButton');    
 };


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message