cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [19/19] git commit: CB-5407: Fixes for ContentFilesystem
Date Fri, 13 Dec 2013 16:19:01 GMT
CB-5407: Fixes for ContentFilesystem


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/a2b90737
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/a2b90737
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/a2b90737

Branch: refs/heads/dev
Commit: a2b90737e6e1fcf089a4fe12a12f07426091577a
Parents: 83a867c
Author: Ian Clelland <iclelland@chromium.org>
Authored: Fri Dec 13 10:52:20 2013 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Fri Dec 13 11:16:37 2013 -0500

----------------------------------------------------------------------
 src/android/ContentFilesystem.java | 24 ++++++++++++++++++++----
 src/android/FileUtils.java         |  7 ++++++-
 2 files changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a2b90737/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 4e5175b..b1d397e 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -9,6 +9,7 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import android.content.ContentResolver;
 import android.database.Cursor;
 import android.provider.MediaStore;
 
@@ -108,9 +109,24 @@ public class ContentFilesystem implements Filesystem {
         throw new NoModificationAllowedException("Couldn't truncate file given its content
URI");
 	}
 
-	@Override
-	public String filesystemPathForURL(LocalFilesystemURL url) {
-		return null;
-	}
+    @Override
+    public String filesystemPathForURL(LocalFilesystemURL url) {
+        final String[] LOCAL_FILE_PROJECTION = { MediaStore.Images.Media.DATA };
 
+        ContentResolver contentResolver = this.cordova.getActivity().getContentResolver();
+        Cursor cursor = contentResolver.query(url.URL, LOCAL_FILE_PROJECTION, null, null,
null);
+        if (cursor != null) {
+            try {
+                int columnIndex = cursor.getColumnIndex(LOCAL_FILE_PROJECTION[0]);
+                if (columnIndex != -1 && cursor.getCount() > 0) {
+                    cursor.moveToFirst();
+                    String path = cursor.getString(columnIndex);
+                    return path;
+                }
+            } finally {
+                cursor.close();
+            }
+        }
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a2b90737/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 7e852b5..1ae7d0c 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -97,6 +97,7 @@ public class FileUtils extends CordovaPlugin {
     	fp.mkdirs();
     	this.filesystems.add(new LocalFilesystem(cordova, "temporary", tempRoot));
     	this.filesystems.add(new LocalFilesystem(cordova, "persistent", persistentRoot));
+    	this.filesystems.add(null);
     	this.filesystems.add(new ContentFilesystem(cordova));
 
     	// Initialize static plugin reference for deprecated getEntry method
@@ -121,7 +122,11 @@ public class FileUtils extends CordovaPlugin {
         	if (fs == null) {
         		return null;
         	}
-        	return Uri.parse("file:///" + fs.filesystemPathForURL(inputURL));
+        	String path = fs.filesystemPathForURL(inputURL);
+        	if (path != null) {
+        		return Uri.parse("file:///" + fs.filesystemPathForURL(inputURL));
+        	}
+        	return null;
         } catch (IllegalArgumentException e) {
         	return null;
         }


Mime
View raw message