Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 122E710A08 for ; Mon, 19 Jan 2015 21:34:28 +0000 (UTC) Received: (qmail 42897 invoked by uid 500); 19 Jan 2015 21:34:30 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 42789 invoked by uid 500); 19 Jan 2015 21:34:30 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 42559 invoked by uid 99); 19 Jan 2015 21:34:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Jan 2015 21:34:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3F1BAE0383; Mon, 19 Jan 2015 21:34:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Date: Mon, 19 Jan 2015 21:34:32 -0000 Message-Id: In-Reply-To: <960855a3e1e044a69ee25dfe10b9b8dc@git.apache.org> References: <960855a3e1e044a69ee25dfe10b9b8dc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/6] android commit: CB-8017 Add support for `` for Lollipop CB-8017 Add support for `` for Lollipop Also refactors a bit to remove related special-case code from CordovaActivity Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/62c1c5f3 Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/62c1c5f3 Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/62c1c5f3 Branch: refs/heads/4.0.x Commit: 62c1c5f38bcb9118a3984df9a96a449c2ea50e30 Parents: 56204c5 Author: Andrew Grieve Authored: Mon Jan 19 16:15:25 2015 -0500 Committer: Andrew Grieve Committed: Mon Jan 19 16:15:25 2015 -0500 ---------------------------------------------------------------------- .../src/org/apache/cordova/CordovaActivity.java | 17 +----- .../org/apache/cordova/CordovaChromeClient.java | 57 ++++++++++++++------ 2 files changed, 43 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-android/blob/62c1c5f3/framework/src/org/apache/cordova/CordovaActivity.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 6a3c70b..69a96f0 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -36,7 +36,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.media.AudioManager; -import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.Display; @@ -48,7 +47,6 @@ import android.view.ViewGroup; import android.view.ViewParent; import android.view.Window; import android.view.WindowManager; -import android.webkit.ValueCallback; import android.webkit.WebViewClient; import android.widget.LinearLayout; @@ -697,23 +695,12 @@ public class CordovaActivity extends Activity implements CordovaInterface { * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). - * @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). + * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { - LOG.d(TAG, "Incoming Result"); + LOG.d(TAG, "Incoming Result. Request code = " + requestCode); super.onActivityResult(requestCode, resultCode, intent); - Log.d(TAG, "Request code = " + requestCode); - if (appView != null && requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) { - ValueCallback mUploadMessage = this.appView.getWebChromeClient().getValueCallback(); - 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); - mUploadMessage.onReceiveValue(result); - mUploadMessage = null; - } CordovaPlugin callback = this.activityResultCallback; if(callback == null && initCallbackClass != null) { // The application was restarted, but had defined an initial callback http://git-wip-us.apache.org/repos/asf/cordova-android/blob/62c1c5f3/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 ff0c0f2..31759d0 100755 --- a/framework/src/org/apache/cordova/CordovaChromeClient.java +++ b/framework/src/org/apache/cordova/CordovaChromeClient.java @@ -22,10 +22,14 @@ import org.apache.cordova.CordovaInterface; import org.apache.cordova.LOG; import android.annotation.TargetApi; +import android.app.Activity; import android.app.AlertDialog; +import android.content.ActivityNotFoundException; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; +import android.os.Build; +import android.util.Log; import android.view.Gravity; import android.view.KeyEvent; import android.view.View; @@ -67,10 +71,7 @@ public class CordovaChromeClient extends WebChromeClient { //Keep track of last AlertDialog showed private AlertDialog lastHandledDialog; - - // File Chooser - public ValueCallback mUploadMessage; - + @Deprecated public CordovaChromeClient(CordovaInterface cordova) { this.cordova = cordova; @@ -309,7 +310,10 @@ public class CordovaChromeClient extends WebChromeClient { } return mVideoProgressView; } - + + // support: + // openFileChooser() is for pre KitKat and in KitKat mr1 (it's known broken in KitKat). + // For Lollipop, we use onShowFileChooser(). public void openFileChooser(ValueCallback uploadMsg) { this.openFileChooser(uploadMsg, "*/*"); } @@ -318,20 +322,41 @@ public class CordovaChromeClient extends WebChromeClient { this.openFileChooser(uploadMsg, acceptType, null); } - public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) + public void openFileChooser(final ValueCallback uploadMsg, String acceptType, String capture) { - 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); + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("*/*"); + cordova.startActivityForResult(new CordovaPlugin() { + @Override + public void onActivityResult(int requestCode, int resultCode, Intent intent) { + Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData(); + Log.d(TAG, "Receive file chooser URL: " + result); + uploadMsg.onReceiveValue(result); + } + }, intent, FILECHOOSER_RESULTCODE); } - - public ValueCallback getValueCallback() { - return this.mUploadMessage; + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + @Override + public boolean onShowFileChooser(WebView webView, final ValueCallback filePathsCallback, final WebChromeClient.FileChooserParams fileChooserParams) { + Intent intent = fileChooserParams.createIntent(); + try { + cordova.startActivityForResult(new CordovaPlugin() { + @Override + public void onActivityResult(int requestCode, int resultCode, Intent intent) { + Uri[] result = WebChromeClient.FileChooserParams.parseResult(resultCode, intent); + Log.d(TAG, "Receive file chooser URL: " + result); + filePathsCallback.onReceiveValue(result); + } + }, intent, FILECHOOSER_RESULTCODE); + } catch (ActivityNotFoundException e) { + Log.w("No activity found to handle file chooser intent.", e); + filePathsCallback.onReceiveValue(null); + } + return true; } - + public void destroyLastDialog(){ if(lastHandledDialog != null){ lastHandledDialog.cancel(); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org