cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [07/13] cordova-plugin-file git commit: android: Move CordovaResourceApi into Filesystem base class
Date Wed, 11 Mar 2015 15:35:18 GMT
android: Move CordovaResourceApi into Filesystem base class


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

Branch: refs/heads/master
Commit: bad4242a304ad883144856417d81d972669a42ba
Parents: 81ea13c
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Mon Mar 9 14:22:04 2015 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Mar 11 11:35:07 2015 -0400

----------------------------------------------------------------------
 src/android/ContentFilesystem.java | 33 +++++++--------------------------
 src/android/FileUtils.java         |  2 +-
 src/android/Filesystem.java        |  5 ++++-
 src/android/LocalFilesystem.java   |  5 +----
 4 files changed, 13 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/bad4242a/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index f577054..3e967f3 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -36,6 +36,7 @@ import org.json.JSONException;
 import org.json.JSONObject;
 
 import android.content.ContentResolver;
+import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
 import android.provider.MediaStore;
@@ -43,31 +44,11 @@ import android.provider.OpenableColumns;
 
 public class ContentFilesystem extends Filesystem {
 
-	private CordovaInterface cordova;
-	private CordovaResourceApi resourceApi;
-	
-	public ContentFilesystem(CordovaInterface cordova, CordovaWebView webView) {
-		super(Uri.parse("content://"), "content");
-		this.cordova = cordova;
+    private final Context context;
 
-		Class webViewClass = webView.getClass();
-		PluginManager pm = null;
-		try {
-			Method gpm = webViewClass.getMethod("getPluginManager");
-			pm = (PluginManager) gpm.invoke(webView);
-		} catch (NoSuchMethodException e) {
-		} catch (IllegalAccessException e) {
-		} catch (InvocationTargetException e) {
-		}
-		if (pm == null) {
-			try {
-				Field pmf = webViewClass.getField("pluginManager");
-				pm = (PluginManager)pmf.get(webView);
-			} catch (NoSuchFieldException e) {
-			} catch (IllegalAccessException e) {
-			}
-		}
-		this.resourceApi = new CordovaResourceApi(webView.getContext(), pm);
+	public ContentFilesystem(Context context, CordovaResourceApi resourceApi) {
+		super(Uri.parse("content://"), "content", resourceApi);
+        this.context = context;
 	}
 	
 	@Override
@@ -130,7 +111,7 @@ public class ContentFilesystem extends Filesystem {
 		String filePath = filesystemPathForURL(inputURL);
 		File file = new File(filePath);
 		try {
-			this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
+            context.getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
 					MediaStore.Images.Media.DATA + " = ?",
 					new String[] { filePath });
 		} catch (UnsupportedOperationException t) {
@@ -246,7 +227,7 @@ public class ContentFilesystem extends Filesystem {
 	}
 
 	protected Cursor openCursorForURL(LocalFilesystemURL url) {
-        ContentResolver contentResolver = this.cordova.getActivity().getContentResolver();
+        ContentResolver contentResolver = context.getContentResolver();
         Cursor cursor = contentResolver.query(url.URL, null, null, null, null);
         return cursor;
 	}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/bad4242a/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 0063b43..043bdca 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -194,7 +194,7 @@ public class FileUtils extends CordovaPlugin {
     		// per spec.
     		this.registerFilesystem(new LocalFilesystem("temporary", webView.getContext(), webView.getResourceApi(),
tempRoot));
     		this.registerFilesystem(new LocalFilesystem("persistent", webView.getContext(), webView.getResourceApi(),
persistentRoot));
-    		this.registerFilesystem(new ContentFilesystem(cordova, webView));
+    		this.registerFilesystem(new ContentFilesystem(webView.getContext(), webView.getResourceApi()));
 
             registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity));
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/bad4242a/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index c4a0f8a..d1cbc27 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.cordova.CordovaResourceApi;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -34,12 +35,14 @@ import org.json.JSONObject;
 public abstract class Filesystem {
 
     protected final Uri rootUri;
+    protected final CordovaResourceApi resourceApi;
     public final String name;
     private final JSONObject rootEntry;
 
-    public Filesystem(Uri rootUri, String name) {
+    public Filesystem(Uri rootUri, String name, CordovaResourceApi resourceApi) {
         this.rootUri = rootUri;
         this.name = name;
+        this.resourceApi = resourceApi;
         rootEntry = makeEntryForPath("/", name, true, rootUri.toString());
     }
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/bad4242a/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 884771c..544663d 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -44,17 +44,14 @@ import android.content.Intent;
 import android.app.Activity;
 
 public class LocalFilesystem extends Filesystem {
-
-    private final CordovaResourceApi resourceApi;
     private final Context context;
 
     public LocalFilesystem(String name, Context context, CordovaResourceApi resourceApi,
String rootPath) {
         this(name, context, resourceApi, Uri.fromFile(new File(rootPath)));
     }
 	public LocalFilesystem(String name, Context context, CordovaResourceApi resourceApi, Uri
rootUri) {
-        super(rootUri, name);
+        super(rootUri, name, resourceApi);
 		this.context = context;
-        this.resourceApi = resourceApi;
 	}
 
     public String filesystemPathForFullPath(String fullPath) {


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


Mime
View raw message