cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [1/2] android commit: Initial input type=file support
Date Fri, 18 Jan 2013 01:01:28 GMT
Initial input type=file support


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/a1206146
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/a1206146
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/a1206146

Branch: refs/heads/master
Commit: a120614617bc8f859eab5c8d2182c7cf0a5630a0
Parents: 0311f0d
Author: Simon MacDonald <simon.macdonald@gmail.com>
Authored: Sat Dec 22 10:02:54 2012 -0500
Committer: Simon MacDonald <simon.macdonald@gmail.com>
Committed: Thu Jan 17 10:10:02 2013 -0500

----------------------------------------------------------------------
 .../org/apache/cordova/CordovaChromeClient.java    |   26 +++++++++++++++
 .../src/org/apache/cordova/CordovaWebView.java     |    4 ++
 framework/src/org/apache/cordova/DroidGap.java     |   20 ++++++++++-
 3 files changed, 48 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a1206146/framework/src/org/apache/cordova/CordovaChromeClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaChromeClient.java b/framework/src/org/apache/cordova/CordovaChromeClient.java
index 9f6ffd9..315025f 100755
--- a/framework/src/org/apache/cordova/CordovaChromeClient.java
+++ b/framework/src/org/apache/cordova/CordovaChromeClient.java
@@ -24,8 +24,12 @@ import org.json.JSONArray;
 import org.json.JSONException;
 
 import android.annotation.TargetApi;
+import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.Uri;
+import android.util.Log;
 import android.view.Gravity;
 import android.view.KeyEvent;
 import android.view.View;
@@ -33,6 +37,7 @@ import android.view.ViewGroup.LayoutParams;
 import android.webkit.ConsoleMessage;
 import android.webkit.JsPromptResult;
 import android.webkit.JsResult;
+import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient;
 import android.webkit.WebStorage;
 import android.webkit.WebView;
@@ -47,6 +52,8 @@ import android.widget.RelativeLayout;
  */
 public class CordovaChromeClient extends WebChromeClient {
 
+    public static final int FILECHOOSER_RESULTCODE = 5173;
+    private static final String LOG_TAG = "CordovaChromeClient";
     private String TAG = "CordovaLog";
     private long MAX_QUOTA = 100 * 1024 * 1024;
     private CordovaInterface cordova;
@@ -55,6 +62,9 @@ public class CordovaChromeClient extends WebChromeClient {
     // the video progress view
     private View mVideoProgressView;
     
+    // File Chooser
+    public ValueCallback<Uri> mUploadMessage;
+    
     /**
      * Constructor.
      *
@@ -369,5 +379,21 @@ public class CordovaChromeClient extends WebChromeClient {
 	    }
     return mVideoProgressView; 
     }
+    
+    public void openFileChooser(ValueCallback<Uri> uploadMsg) {
+        this.openFileChooser(uploadMsg, "*/*");
+    }
 
+    public void openFileChooser( ValueCallback<Uri> uploadMsg, String acceptType )
{
+        mUploadMessage = uploadMsg;
+        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
+        i.addCategory(Intent.CATEGORY_OPENABLE);
+        i.setType("*/*");
+        this.cordova.getActivity().startActivityForResult(Intent.createChooser(i, "File Browser"),
+                FILECHOOSER_RESULTCODE);
+    }
+    
+    public ValueCallback<Uri> getValueCallback() {
+        return this.mUploadMessage;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a1206146/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index 547a450..44c9299 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -333,6 +333,10 @@ public class CordovaWebView extends WebView {
         this.chromeClient = client;
         super.setWebChromeClient(client);
     }
+    
+    public CordovaChromeClient getWebChromeClient() {
+        return this.chromeClient;
+    }
 
     /**
      * Load the url into the webview.

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a1206146/framework/src/org/apache/cordova/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java
index bd1cf79..2299fb7 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -38,6 +38,7 @@ import android.content.Intent;
 import android.content.res.Configuration;
 import android.graphics.Color;
 import android.media.AudioManager;
+import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
 import android.util.Log;
@@ -49,6 +50,8 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
+import android.webkit.ValueCallback;
+import android.webkit.WebView;
 import android.webkit.WebViewClient;
 import android.widget.LinearLayout;
 
@@ -190,6 +193,7 @@ public class DroidGap extends Activity implements CordovaInterface {
 
     private String initCallbackClass;
 
+    private Object LOG_TAG;
 
     /**
     * Sets the authentication token.
@@ -818,6 +822,19 @@ public class DroidGap extends Activity implements CordovaInterface {
     protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
         LOG.d(TAG, "Incoming Result");
         super.onActivityResult(requestCode, resultCode, intent);
+        Log.d(TAG, "Request code = " + requestCode);
+        ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback();
+        if (requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) {
+            Log.d(TAG, "did we get here?");
+            if (null == mUploadMessage)
+                return;
+            Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
+            Log.d(TAG, "result = " + result);
+//            Uri filepath = Uri.parse("file://" + FileUtils.getRealPathFromURI(result, this));
+//            Log.d(TAG, "result = " + filepath);
+            mUploadMessage.onReceiveValue(result);
+            mUploadMessage = null;
+        }
         CordovaPlugin callback = this.activityResultCallback;
         if(callback == null)
         {
@@ -869,8 +886,7 @@ public class DroidGap extends Activity implements CordovaInterface {
             final boolean exit = !(errorCode == WebViewClient.ERROR_HOST_LOOKUP);
             me.runOnUiThread(new Runnable() {
                 public void run() {
-                    if (exit)
-                    {
+                    if (exit) {
                         me.appView.setVisibility(View.GONE);
                         me.displayError("Application Error", description + " (" + failingUrl
+ ")", "OK", exit);
                     }


Mime
View raw message