Search in sources :

Example 21 with WebViewClient

use of android.webkit.WebViewClient in project platform_frameworks_base by android.

the class LooperAcceleration method makeView.

private View makeView() {
    LinearLayout layout = new LinearLayout(this);
    layout.addView(new IsAcceleratedView(this), LayoutParams.MATCH_PARENT, 60);
    if (INCLUDE_WEBVIEW) {
        WebView wv = new WebView(this);
        wv.setWebViewClient(new WebViewClient());
        wv.setWebChromeClient(new WebChromeClient());
        wv.loadUrl("http://www.webkit.org/blog-files/3d-transforms/poster-circle.html");
        layout.addView(wv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    }
    return layout;
}
Also used : WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) LinearLayout(android.widget.LinearLayout) WebViewClient(android.webkit.WebViewClient)

Example 22 with WebViewClient

use of android.webkit.WebViewClient in project jpHolo by teusink.

the class InAppBrowser method closeDialog.

/**
     * Closes the dialog
     */
public void closeDialog() {
    final WebView childView = this.inAppWebView;
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;
    }
    this.cordova.getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            childView.setWebViewClient(new WebViewClient() {

                // NB: wait for about:blank before dismissing
                public void onPageFinished(WebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            // NB: From SDK 19: "If you call methods on WebView from any thread 
            // other than your app's UI thread, it can cause unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            childView.loadUrl("about:blank");
        }
    });
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", EXIT_EVENT);
        sendUpdate(obj, false);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) CordovaWebView(org.apache.cordova.CordovaWebView) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 23 with WebViewClient

use of android.webkit.WebViewClient in project jpHolo by teusink.

the class InAppBrowser method showWebPage.

/**
     * Display a new browser with the specified URL.
     *
     * @param url           The url to load.
     * @param jsonObject
     */
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }
    final CordovaWebView thatWebView = this.webView;
    // Create dialog in new thread
    Runnable runnable = new Runnable() {

        /**
             * Convert our DIP units to Pixels
             *
             * @return int
             */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics());
            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());
            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);
            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black! 
            toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
            toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);
            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);
            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            /*
                back.setText("<");
                */
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    goBack();
                }
            });
            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            //forward.setText(">");
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                forward.setBackgroundDrawable(fwdIcon);
            } else {
                forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    goForward();
                }
            });
            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            // Will not except input... Makes the text NON-EDITABLE
            edittext.setInputType(InputType.TYPE_NULL);
            edittext.setOnKeyListener(new View.OnKeyListener() {

                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });
            // Close button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            //close.setText(buttonLabel);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                close.setBackgroundDrawable(closeIcon);
            } else {
                close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    closeDialog();
                }
            });
            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);
            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);
            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }
            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();
            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);
            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);
            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }
            // Add our webview to our main view/layout
            main.addView(inAppWebView);
            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;
            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}
Also used : WindowManager(android.view.WindowManager) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) CordovaWebView(org.apache.cordova.CordovaWebView) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) EditText(android.widget.EditText) LayoutParams(android.view.WindowManager.LayoutParams) InAppBrowserDialog(org.apache.cordova.inappbrowser.InAppBrowserDialog) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) CordovaWebView(org.apache.cordova.CordovaWebView) View(android.view.View) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint) WebSettings(android.webkit.WebSettings) RelativeLayout(android.widget.RelativeLayout) LayoutParams(android.view.WindowManager.LayoutParams) CordovaWebView(org.apache.cordova.CordovaWebView) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Example 24 with WebViewClient

use of android.webkit.WebViewClient in project cordova-android-chromeview by thedracle.

the class InAppBrowser method showWebPage.

/**
     * Display a new browser with the specified URL.
     *
     * @param url           The url to load.
     * @param jsonObject
     */
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
    }
    final CordovaWebView thatWebView = this.webView;
    // Create dialog in new thread
    Runnable runnable = new Runnable() {

        /**
             * Convert our DIP units to Pixels
             *
             * @return int
             */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics());
            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", EXIT_EVENT);
                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });
            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);
            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);
            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);
            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setText("<");
            back.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    goBack();
                }
            });
            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            forward.setText(">");
            forward.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    goForward();
                }
            });
            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            // Will not except input... Makes the text NON-EDITABLE
            edittext.setInputType(InputType.TYPE_NULL);
            edittext.setOnKeyListener(new View.OnKeyListener() {

                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });
            // Close button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            close.setText(buttonLabel);
            close.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    closeDialog();
                }
            });
            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            /** 
                 * We need to be careful of this line as a future Android release may deprecate it out of existence.
                 * Can't replace it with the API 8 level call right now as our minimum SDK is 7 until May 2013
                 */
            // @TODO: replace with settings.setPluginState(android.webkit.WebSettings.PluginState.ON)
            settings.setPluginsEnabled(true);
            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);
            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();
            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);
            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);
            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }
            // Add our webview to our main view/layout
            main.addView(inAppWebView);
            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;
            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}
Also used : DialogInterface(android.content.DialogInterface) WindowManager(android.view.WindowManager) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) Dialog(android.app.Dialog) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) EditText(android.widget.EditText) LayoutParams(android.view.WindowManager.LayoutParams) Bundle(android.os.Bundle) JSONException(org.json.JSONException) View(android.view.View) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint) JSONObject(org.json.JSONObject) WebSettings(android.webkit.WebSettings) RelativeLayout(android.widget.RelativeLayout) LayoutParams(android.view.WindowManager.LayoutParams) LinearLayout(android.widget.LinearLayout)

Example 25 with WebViewClient

use of android.webkit.WebViewClient in project baker-android by bakerframework.

the class WebViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.activity = (MagazineActivity) this.getActivity();
    // The last two arguments ensure LayoutParams are inflated
    // properly.
    View rootView = inflater.inflate(R.layout.fragment_collection_object, container, false);
    Bundle args = getArguments();
    customViewContainer = (FrameLayout) this.getActivity().findViewById(R.id.customViewContainer);
    webView = (CustomWebView) rootView.findViewById(R.id.webpage1);
    progressBarContainer = (FrameLayout) rootView.findViewById(R.id.progressBarContainer);
    //Enable javascript
    webView.getSettings().setJavaScriptEnabled(true);
    //Set zoom enabled/disabled
    webView.getSettings().setSupportZoom(true);
    //Support zoom like normal browsers
    webView.getSettings().setUseWideViewPort(true);
    //Disable zoom buttons
    webView.getSettings().setDisplayZoomControls(false);
    //Add zoom controls
    webView.getSettings().setBuiltInZoomControls(true);
    //Load the page on the maximum zoom out available.
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.setWebChromeClient(chromeClient);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String stringUrl) {
            // mailto links will be handled by the OS.
            if (stringUrl.startsWith("mailto:")) {
                Uri uri = Uri.parse(stringUrl);
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
            } else {
                try {
                    URL url = new URL(stringUrl);
                    // We try to remove the referrer string to avoid passing it to the server in case the URL is an external link.
                    String referrer = "";
                    if (url.getQuery() != null) {
                        Map<String, String> variables = Configuration.splitUrlQueryString(url);
                        String finalQueryString = "";
                        for (Map.Entry<String, String> entry : variables.entrySet()) {
                            if (entry.getKey().equals("referrer")) {
                                referrer = entry.getValue();
                            } else {
                                finalQueryString += entry.getKey() + "=" + entry.getValue() + "&";
                            }
                        }
                        if (!finalQueryString.isEmpty()) {
                            finalQueryString = "?" + finalQueryString.substring(0, finalQueryString.length() - 1);
                        }
                        stringUrl = stringUrl.replace("?" + url.getQuery(), finalQueryString);
                    }
                    if (!url.getProtocol().equals("file")) {
                        Log.d("REFERRER>>>", "THE REFERRER IS: " + referrer);
                        if (referrer.equals(WebViewFragment.this.activity.getString(R.string.url_external_referrer))) {
                            Uri uri = Uri.parse(stringUrl);
                            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                            startActivity(intent);
                        } else if (referrer.equals(WebViewFragment.this.activity.getString(R.string.url_gindpubs_referrer))) {
                            WebViewFragment.this.activity.openLinkInModal(stringUrl);
                            return true;
                        } else {
                            // We return false to tell the webview that we are not going to handle the URL override.
                            return false;
                        }
                    } else {
                        stringUrl = url.getPath().substring(url.getPath().lastIndexOf("/") + 1);
                        Log.d(">>>URL_DATA", "FINAL INTERNAL HTML FILENAME = " + stringUrl);
                        int index = activity.getJsonBook().getContents().indexOf(stringUrl);
                        if (index != -1) {
                            Log.d(this.getClass().toString(), "Index to load: " + index + ", page: " + stringUrl);
                            activity.getPager().setCurrentItem(index);
                            view.setVisibility(View.GONE);
                        } else {
                            // If the file DOES NOT exist, we won't load it.
                            File htmlFile = new File(url.getPath());
                            if (htmlFile.exists()) {
                                return false;
                            }
                        }
                    }
                } catch (MalformedURLException ex) {
                    Log.d(">>>URL_DATA", ex.getMessage());
                } catch (UnsupportedEncodingException ex) {
                }
            }
            return true;
        }
    });
    webView.loadUrl(args.getString(ARG_OBJECT));
    return rootView;
}
Also used : MalformedURLException(java.net.MalformedURLException) Bundle(android.os.Bundle) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) View(android.view.View) WebView(android.webkit.WebView) Uri(android.net.Uri) URL(java.net.URL) WebView(android.webkit.WebView) Map(java.util.Map) File(java.io.File) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebViewClient (android.webkit.WebViewClient)109 WebView (android.webkit.WebView)99 WebChromeClient (android.webkit.WebChromeClient)29 View (android.view.View)28 WebSettings (android.webkit.WebSettings)25 Intent (android.content.Intent)23 SuppressLint (android.annotation.SuppressLint)19 Bitmap (android.graphics.Bitmap)18 LinearLayout (android.widget.LinearLayout)9 TextView (android.widget.TextView)9 Uri (android.net.Uri)8 Bundle (android.os.Bundle)8 KeyEvent (android.view.KeyEvent)7 WebResourceRequest (android.webkit.WebResourceRequest)7 JsResult (android.webkit.JsResult)6 DialogInterface (android.content.DialogInterface)4 WebResourceError (android.webkit.WebResourceError)4 WebResourceResponse (android.webkit.WebResourceResponse)4 RelativeLayout (android.widget.RelativeLayout)4 Activity (android.app.Activity)3