Skip to content

Commit

Permalink
Merge pull request #2 from sebalagos90/master
Browse files Browse the repository at this point in the history
Se ha adaptado el código para funcionar con Cordova 5.0.
  • Loading branch information
arturokunder committed Jun 8, 2015
2 parents f1fdabd + 8c8557c commit 12a0e58
Showing 1 changed file with 54 additions and 32 deletions.
86 changes: 54 additions & 32 deletions src/android/cl/kunder/webview/WebViewPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,43 @@
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;

import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;

import android.widget.LinearLayout;

import org.apache.cordova.ConfigXmlParser;
import org.apache.cordova.CordovaActivity;
import org.apache.cordova.CordovaChromeClient;
import org.apache.cordova.CordovaInterfaceImpl;
import org.apache.cordova.CordovaPreferences;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaWebViewClient;
import org.apache.cordova.LinearLayoutSoftKeyboardDetect;

import org.apache.cordova.CordovaWebViewImpl;
import org.apache.cordova.PluginEntry;
import org.apache.cordova.Whitelist;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.apache.cordova.LOG;

import org.apache.cordova.engine.*;



public class WebViewPlugin extends CordovaPlugin {

private static final String LOG_TAG = "WebViewPlugin";

private static Dialog webViewDialog;

static SystemWebView webView;

public WebViewPlugin() {

}
Expand Down Expand Up @@ -106,47 +111,64 @@ private void showWebView(final String url) {
public void run() {
Activity activity = plugin.cordova.getActivity();
Context context = activity.getApplicationContext();
//esta es la webView que cargaría la URL
webView = new SystemWebView(context);
CordovaWebView webInterface = new CordovaWebViewImpl(new SystemWebViewEngine(webView));
CordovaInterface systemInterface = new CordovaInterfaceImpl(activity);
CordovaPreferences cordovaPreferences = new CordovaPreferences();


CordovaWebView otherWebView = new CordovaWebView(context);
CordovaWebViewClient client = otherWebView.makeWebViewClient((CordovaActivity)activity);
CordovaChromeClient chrome = otherWebView.makeWebChromeClient((CordovaActivity)activity);
SystemWebViewEngine systemWebViewEngine = new SystemWebViewEngine(webView);

// CordovaWebView otherWebView = new CordovaWebView(context);
// CordovaWebViewClient client = otherWebView.makeWebViewClient((CordovaActivity)activity);
// CordovaChromeClient chrome = otherWebView.makeWebChromeClient((CordovaActivity)activity);

ConfigXmlParser parser = new ConfigXmlParser();
parser.parse((CordovaActivity)activity);
parser.parse(activity);

Whitelist internalWhitelist = parser.getInternalWhitelist();
Whitelist externalWhitelist = parser.getExternalWhitelist();
// Whitelist internalWhitelist = parser.getInternalWhitelist();
// Whitelist externalWhitelist = parser.getExternalWhitelist();
ArrayList<PluginEntry> pluginEntries = parser.getPluginEntries();

otherWebView.init(
(CordovaActivity)activity,
client,
chrome,
pluginEntries,
internalWhitelist,
externalWhitelist,
preferences);
webInterface.init(systemInterface,pluginEntries, parser.getPreferences());

// otherWebView.init(
// (CordovaActivity)activity,
// client,
// chrome,
// pluginEntries,
// internalWhitelist,
// externalWhitelist,
// preferences);

otherWebView.loadUrl("file:///android_asset/www/" + url);
webView.loadUrl("file:///android_asset/www/" + url);
//otherWebView.loadUrl("file:///android_asset/www/" + url);

DisplayMetrics displaymetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);;
int width = displaymetrics.widthPixels;
int height = displaymetrics.heightPixels;

LinearLayout root = new LinearLayoutSoftKeyboardDetect((CordovaActivity)activity, width, height);
LinearLayout root = new LinearLayout(activity);
//LinearLayout root = new LinearLayoutSoftKeyboardDetect((CordovaActivity)activity, width, height);
root.setOrientation(LinearLayout.VERTICAL);
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));

otherWebView.setId(101);
otherWebView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
1.0F));
//webView.setId(101);

webView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
1.0F));
//otherWebView.setId(101);
// otherWebView.setLayoutParams(new LinearLayout.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT,
// 1.0F));

root.addView((View) otherWebView);
root.addView((View) webView);
//root.addView((View) otherWebView);

webViewDialog = new Dialog(activity, android.R.style.Theme_NoTitleBar);
webViewDialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
Expand Down Expand Up @@ -176,7 +198,7 @@ private void hideWebView() {
public void run() {
if(webViewDialog != null && webViewDialog.isShowing()) {
webViewDialog.dismiss();
plugin.webView.destroy();
webView.destroy();
}
}
});
Expand Down

0 comments on commit 12a0e58

Please sign in to comment.