Skip to content

Implement hide method. #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 101 additions & 1 deletion src/android/ThemeableBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Expand All @@ -66,9 +68,11 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.LOG;
import org.apache.cordova.PluginManager;
import org.apache.cordova.PluginResult;
import org.apache.cordova.Whitelist;
import org.apache.cordova.inappbrowser.InAppBrowser;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -109,6 +113,11 @@ public class ThemeableBrowser extends CordovaPlugin {
private EditText edittext;
private CallbackContext callbackContext;

private ValueCallback<Uri> mUploadCallback;
private ValueCallback<Uri[]> mUploadCallbackLollipop;
private final static int FILECHOOSER_REQUESTCODE = 1;
private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2;

/**
* Executes the request and returns PluginResult.
*
Expand Down Expand Up @@ -242,6 +251,17 @@ public void run() {
pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult);
}
else if (action.equals("hide")) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.hide();
}
});
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult);
}
else if (action.equals("reload")) {
if (inAppWebView != null) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -757,7 +777,51 @@ public void onNothingSelected(
((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
}
inAppWebView.setLayoutParams(inAppWebViewParams);
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
// File Chooser Implemented ChromeClient
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView) {
// For Android 5.0
public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
{
LOG.d(LOG_TAG, "File Chooser 5.0 ");
// If callback exists, finish it.
if(mUploadCallbackLollipop != null) {
mUploadCallbackLollipop.onReceiveValue(null);
}
mUploadCallbackLollipop = filePathCallback;

// Create File Chooser Intent
Intent content = new Intent(Intent.ACTION_GET_CONTENT);
content.addCategory(Intent.CATEGORY_OPENABLE);
content.setType("*/*");

// Run cordova startActivityForResult
cordova.startActivityForResult(ThemeableBrowser.this, Intent.createChooser(content, "Select File"), FILECHOOSER_REQUESTCODE_LOLLIPOP);
return true;
}

// For Android 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
{
LOG.d(LOG_TAG, "File Chooser 4.1 ");
// Call file chooser for Android 3.0
openFileChooser(uploadMsg, acceptType);
}

// For Android 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
{
LOG.d(LOG_TAG, "File Chooser 3.0 ");
mUploadCallback = uploadMsg;
Intent content = new Intent(Intent.ACTION_GET_CONTENT);
content.addCategory(Intent.CATEGORY_OPENABLE);

// run startActivityForResult
cordova.startActivityForResult(ThemeableBrowser.this, Intent.createChooser(content, "Select File"), FILECHOOSER_REQUESTCODE);
}

});


WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {
@Override
public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
Expand Down Expand Up @@ -1184,6 +1248,42 @@ public void onPageFinished(String url, boolean canGoBack,
boolean canGoForward);
}

/**
* Receive File Data from File Chooser
*
* @param requestCode the requested code from chromeclient
* @param resultCode the result code returned from android system
* @param intent the data from android file chooser
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
// For Android >= 5.0
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
LOG.d(LOG_TAG, "onActivityResult (For Android >= 5.0)");
// If RequestCode or Callback is Invalid
if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) {
super.onActivityResult(requestCode, resultCode, intent);
return;
}
mUploadCallbackLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
mUploadCallbackLollipop = null;
}
// For Android < 5.0
else {
LOG.d(LOG_TAG, "onActivityResult (For Android < 5.0)");
// If RequestCode or Callback is Invalid
if(requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null) {
super.onActivityResult(requestCode, resultCode, intent);
return;
}

if (null == mUploadCallback) return;
Uri result = intent == null || resultCode != cordova.getActivity().RESULT_OK ? null : intent.getData();

mUploadCallback.onReceiveValue(result);
mUploadCallback = null;
}
}

/**
* The webview client receives notifications about appView
*/
Expand Down
1 change: 1 addition & 0 deletions src/ios/CDVThemeableBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
- (void)show:(CDVInvokedUrlCommand*)command;
- (void)show:(CDVInvokedUrlCommand*)command withAnimation:(BOOL)animated;
- (void)hide:(CDVInvokedUrlCommand*)command;
- (void)reload:(CDVInvokedUrlCommand*)command;

@end
Expand Down
Loading