CB-9148 (android) Add Support for input[type=file] File Chooser

This commit is contained in:
박관영 2017-01-03 14:39:25 +09:00 committed by Joe Bowser
parent 2a383a66c5
commit 26f7ef3c67

View File

@ -29,6 +29,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -41,6 +42,8 @@ import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.CookieSyncManager; import android.webkit.CookieSyncManager;
import android.webkit.HttpAuthHandler; import android.webkit.HttpAuthHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
@ -68,10 +71,6 @@ import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import android.util.Log;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
public class InAppBrowser extends CordovaPlugin { public class InAppBrowser extends CordovaPlugin {
@ -107,7 +106,6 @@ public class InAppBrowser extends CordovaPlugin {
private boolean mediaPlaybackRequiresUserGesture = false; private boolean mediaPlaybackRequiresUserGesture = false;
private boolean shouldPauseInAppBrowser = false; private boolean shouldPauseInAppBrowser = false;
private boolean useWideViewPort = true; private boolean useWideViewPort = true;
private ValueCallback<Uri> mUploadCallback; private ValueCallback<Uri> mUploadCallback;
private ValueCallback<Uri[]> mUploadCallbackLollipop; private ValueCallback<Uri[]> mUploadCallbackLollipop;
private final static int FILECHOOSER_REQUESTCODE = 1; private final static int FILECHOOSER_REQUESTCODE = 1;
@ -409,7 +407,7 @@ public class InAppBrowser extends CordovaPlugin {
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName()); intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
this.cordova.getActivity().startActivity(intent); this.cordova.getActivity().startActivity(intent);
return ""; return "";
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
} catch (java.lang.RuntimeException e) { } catch (java.lang.RuntimeException e) {
LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString()); LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
return e.toString(); return e.toString();
@ -571,7 +569,7 @@ public class InAppBrowser extends CordovaPlugin {
} }
Boolean wideViewPort = features.get(USER_WIDE_VIEW_PORT); Boolean wideViewPort = features.get(USER_WIDE_VIEW_PORT);
if (wideViewPort != null ) { if (wideViewPort != null ) {
useWideViewPort = wideViewPort.booleanValue(); useWideViewPort = wideViewPort.booleanValue();
} }
} }
@ -586,8 +584,8 @@ public class InAppBrowser extends CordovaPlugin {
*/ */
private int dpToPixels(int dipValue) { private int dpToPixels(int dipValue) {
int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,
(float) dipValue, (float) dipValue,
cordova.getActivity().getResources().getDisplayMetrics() cordova.getActivity().getResources().getDisplayMetrics()
); );
return value; return value;
@ -695,8 +693,8 @@ public class InAppBrowser extends CordovaPlugin {
public boolean onKey(View v, int keyCode, KeyEvent event) { public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button // If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
navigate(edittext.getText().toString()); navigate(edittext.getText().toString());
return true; return true;
} }
return false; return false;
} }
@ -731,8 +729,7 @@ public class InAppBrowser extends CordovaPlugin {
inAppWebView = new WebView(cordova.getActivity()); inAppWebView = new WebView(cordova.getActivity());
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
inAppWebView.setId(Integer.valueOf(6)); inAppWebView.setId(Integer.valueOf(6));
// File Chooser Implemented ChromeClient
// File Chooser Implemented ChromeClient
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView) { inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView) {
// For Android 5.0+ // For Android 5.0+
public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
@ -783,7 +780,6 @@ public class InAppBrowser extends CordovaPlugin {
} }
}); });
WebViewClient client = new InAppBrowserClient(thatWebView, edittext); WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
inAppWebView.setWebViewClient(client); inAppWebView.setWebViewClient(client);
WebSettings settings = inAppWebView.getSettings(); WebSettings settings = inAppWebView.getSettings();
@ -1035,7 +1031,7 @@ public class InAppBrowser extends CordovaPlugin {
// Update the UI if we haven't already // Update the UI if we haven't already
if (!newloc.equals(edittext.getText().toString())) { if (!newloc.equals(edittext.getText().toString())) {
edittext.setText(newloc); edittext.setText(newloc);
} }
try { try {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
@ -1048,6 +1044,7 @@ public class InAppBrowser extends CordovaPlugin {
} }
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url); super.onPageFinished(view, url);