Example usage for android.webkit WebViewClient WebViewClient

List of usage examples for android.webkit WebViewClient WebViewClient

Introduction

In this page you can find the example usage for android.webkit WebViewClient WebViewClient.

Prototype

WebViewClient

Source Link

Usage

From source file:terse.a1.TerseActivity.java

private void viewPath9display(String path, LayoutParams widgetParams) {
    String explain;//from  w  ww  .  j  ava2 s  .  co m
    if (terp_error != null) {
        explain = "terp_error = " + terp_error;
    } else {
        try {
            terp.say("Sending to terp: %s", path);
            final Dict d = terp.handleUrl(path, taQuery);
            explain = "DEFAULT EXPLANATION:\n\n" + d.toString();

            Str TYPE = d.cls.terp.newStr("type");
            Str VALUE = d.cls.terp.newStr("value");
            Str TITLE = d.cls.terp.newStr("title");
            Str type = (Str) d.dict.get(TYPE);
            Ur value = d.dict.get(VALUE);
            Ur title = d.dict.get(TITLE);

            // {
            // double ticks = Static.floatAt(d, "ticks", -1);
            // double nanos = Static.floatAt(d, "nanos", -1);
            // Toast.makeText(
            // getApplicationContext(),
            // Static.fmt("%d ticks, %.3f secs", (long) ticks,
            // (double) nanos / 1e9), Toast.LENGTH_SHORT)
            // .show();
            // }

            if (type.str.equals("list") && value instanceof Vec) {
                final ArrayList<Ur> v = ((Vec) value).vec;
                final ArrayList<String> labels = new ArrayList<String>();
                final ArrayList<String> links = new ArrayList<String>();
                for (int i = 0; i < v.size(); i++) {
                    Ur item = v.get(i);
                    String label = item instanceof Str ? ((Str) item).str : item.toString();
                    if (item instanceof Vec && ((Vec) item).vec.size() == 2) {
                        // OLD STYLE
                        label = ((Vec) item).vec.get(0).toString();
                        Matcher m = LINK_P.matcher(label);
                        if (m.lookingAt()) {
                            label = m.group(2) + " " + m.group(3);
                        }
                        label += "    [" + ((Vec) item).vec.get(1).toString().length() + "]";
                        links.add(null); // Use old style, not links.
                    } else {
                        // NEW STYLE
                        label = item.toString();
                        if (label.charAt(0) == '/') {
                            String link = Terp.WHITE_PLUS.split(label, 2)[0];
                            links.add(link);
                        } else {
                            links.add("");
                        }
                    }
                    labels.add(label);
                }
                if (labels.size() != links.size())
                    terp.toss("lables#%d links#%d", labels.size(), links.size());

                ListView listv = new ListView(this);
                listv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, labels));
                listv.setLayoutParams(widgetParams);
                listv.setTextFilterEnabled(true);

                listv.setOnItemClickListener(new OnItemClickListener() {
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        // When clicked, show a toast with the TextView text
                        // Toast.makeText(getApplicationContext(),
                        // ((TextView) view).getText(),
                        // Toast.LENGTH_SHORT).show();
                        String toast_text = ((TextView) view).getText().toString();
                        // if (v.get(position) instanceof Vec) {
                        if (links.get(position) == null) {
                            // OLD STYLE
                            Vec pair = (Vec) v.get(position);
                            if (pair.vec.size() == 2) {
                                if (pair.vec.get(0) instanceof Str) {
                                    String[] words = ((Str) pair.vec.get(0)).str.split("\\|");
                                    Log.i("TT-WORDS", terp.arrayToString(words));
                                    toast_text += "\n\n" + Static.arrayToString(words);
                                    if (words[1].equals("link")) {
                                        Uri uri = new Uri.Builder().scheme("terse").path(words[2]).build();
                                        Intent intent = new Intent("android.intent.action.MAIN", uri);
                                        intent.setClass(getApplicationContext(), TerseActivity.class);

                                        startActivity(intent);
                                    }
                                }
                            }
                        } else {
                            // NEW STYLE
                            terp.say("NEW STYLE LIST SELECT #%d link=<%s> label=<%s>", position,
                                    links.get(position), labels.get(position));
                            if (links.get(position).length() > 0) {
                                Uri uri = new Uri.Builder().scheme("terse").path(links.get(position)).build();
                                Intent intent = new Intent("android.intent.action.MAIN", uri);
                                intent.setClass(getApplicationContext(), TerseActivity.class);

                                startActivity(intent);
                            }
                        }
                        // }
                        // Toast.makeText(getApplicationContext(),
                        // ((TextView) view).getText(),
                        // Toast.LENGTH_SHORT).show();
                    }
                });
                setContentView(listv);
                return;
            } else if (type.str.equals("edit") && value instanceof Str) {
                final EditText ed = new EditText(this);

                ed.setText(taSaveMe == null ? value.toString() : taSaveMe);

                ed.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
                        | InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
                ed.setLayoutParams(widgetParams);
                // ed.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
                ed.setTextAppearance(this, R.style.teletype);
                ed.setBackgroundColor(Color.BLACK);
                ed.setGravity(Gravity.TOP);
                ed.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
                ed.setVerticalFadingEdgeEnabled(true);
                ed.setVerticalScrollBarEnabled(true);
                ed.setOnKeyListener(new 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)) {
                        // // Perform action on key press
                        // Toast.makeText(TerseActivity.this, ed.getText(),
                        // Toast.LENGTH_SHORT).show();
                        // return true;
                        // }
                        return false;
                    }
                });

                Button btn = new Button(this);
                btn.setText("Save");
                btn.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        // Perform action on clicks
                        String text = ed.getText().toString();
                        text = Parser.charSubsts(text);
                        Toast.makeText(TerseActivity.this, text, Toast.LENGTH_SHORT).show();
                        String action = stringAt(d, "action");
                        String query = "";

                        String f1 = stringAt(d, "field1");
                        String v1 = stringAt(d, "value1");
                        String f2 = stringAt(d, "field2");
                        String v2 = stringAt(d, "value2");
                        f1 = (f1 == null) ? "f1null" : f1;
                        v1 = (v1 == null) ? "v1null" : v1;
                        f2 = (f2 == null) ? "f2null" : f2;
                        v2 = (v2 == null) ? "v2null" : v2;

                        startTerseActivity(action, query, stringAt(d, "field1"), stringAt(d, "value1"),
                                stringAt(d, "field2"), stringAt(d, "value2"), "text", text);
                    }
                });

                LinearLayout linear = new LinearLayout(this);
                linear.setOrientation(LinearLayout.VERTICAL);
                linear.addView(btn);
                linear.addView(ed);
                setContentView(linear);
                return;

            } else if (type.str.equals("draw") && value instanceof Vec) {
                Vec v = ((Vec) value);
                DrawView dv = new DrawView(this, v.vec, d);
                dv.setLayoutParams(widgetParams);
                setContentView(dv);
                return;
            } else if (type.str.equals("live")) {
                Blk blk = value.mustBlk();
                Blk event = Static.urAt(d, "event").asBlk();
                TerseSurfView tsv = new TerseSurfView(this, blk, event);
                setContentView(tsv);
                return;
            } else if (type.str.equals("fnord")) {
                Blk blk = value.mustBlk();
                Blk event = Static.urAt(d, "event").asBlk();
                FnordView fnord = new FnordView(this, blk, event);
                setContentView(fnord);
                return;
            } else if (type.str.equals("world") && value instanceof Str) {
                String newWorld = value.toString();
                if (Terp.WORLD_P.matcher(newWorld).matches()) {
                    world = newWorld;
                    resetTerp();
                    explain = Static.fmt("Switching to world <%s>\nUse menu to go Home.", world);
                    Toast.makeText(getApplicationContext(), explain, Toast.LENGTH_LONG).show();
                } else {
                    terp.toss("Bad world syntax (must be 3 letters then 0 to 3 digits: <%s>", newWorld);
                }
                // Fall thru for explainv.setText(explain).
            } else if (type.str.equals("text")) {
                explain = "<<< " + title + " >>>\n\n" + value.toString();
                // Fall thru for explainv.setText(explain).
            } else if (type.str.equals("html")) {
                final WebView webview = new WebView(this);
                // webview.loadData(value.toString(), "text/html", null);
                webview.loadDataWithBaseURL("terse://terse", value.toString(), "text/html", "UTF-8", null);
                webview.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        // terp.say("WebView UrlLoading: url=%s", url);
                        URI uri = URI.create("" + url);
                        // terp.say("WebView UrlLoading: URI=%s", uri);
                        terp.say("WebView UrlLoading: getPath=%s", uri.getPath());
                        terp.say("WebView UrlLoading: getQuery=%s", uri.getQuery());

                        // Toast.makeText(getApplicationContext(),
                        // uri.toASCIIString(), Toast.LENGTH_SHORT)
                        // .show();
                        // webview.invalidate();
                        //
                        // TextView quick = new
                        // TextView(TerseActivity.this);
                        // quick.setText(uri.toASCIIString());
                        // quick.setBackgroundColor(Color.BLACK);
                        // quick.setTextColor(Color.WHITE);
                        // setContentView(quick);

                        startTerseActivity(uri.getPath(), uri.getQuery());

                        return true;
                    }
                });

                // webview.setWebChromeClient(new WebChromeClient());
                webview.getSettings().setBuiltInZoomControls(true);
                // webview.getSettings().setJavaScriptEnabled(true);
                webview.getSettings().setDefaultFontSize(18);
                webview.getSettings().setNeedInitialFocus(true);
                webview.getSettings().setSupportZoom(true);
                webview.getSettings().setSaveFormData(true);
                setContentView(webview);

                // ScrollView scrollv = new ScrollView(this);
                // scrollv.addView(webview);
                // setContentView(scrollv);
                return;
            } else {
                explain = "Unknown page type: " + type.str + " with vaule type: " + value.cls
                        + "\n\n##############\n\n";
                explain += value.toString();
                // Fall thru for explainv.setText(explain).
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            explain = Static.describe(ex);
        }
    }

    TextView explainv = new TextView(this);
    explainv.setText(explain);
    explainv.setBackgroundColor(Color.BLACK);
    explainv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
    explainv.setTextColor(Color.YELLOW);

    SetContentViewWithHomeButtonAndScroll(explainv);
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

public void loadComicImage(Uri uri) {
    webview.clearView();//  w w  w. j a v  a  2  s  .  c om
    final ProgressDialog pd = ProgressDialog.show(this, getStringAppName(), "Loading comic image...", false,
            true, new OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    webview.stopLoading();
                    webview.requestFocus();
                }
            });
    pd.setProgress(0);
    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            pd.dismiss();
            webview.requestFocus();
        }
    });
    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            pd.setProgress(newProgress * 100);
        }
    });
    if ("".equals(uri.toString())) {
        failed("Couldn't identify image in post");
        webview.loadUrl("about:blank");
    } else {
        webview.loadUrl(uri.toString());
    }
}

From source file:com.openatk.planting.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.main_menu_add) {
        // Check if have an operation
        if (operationsList.isEmpty()) {
            // Show dialog to create operation
            createOperation(new Callable<Void>() {
                public Void call() {
                    return addFieldMapView();
                }/* w  w w  . ja v  a  2s. c o m*/
            });
        } else {
            addFieldMapView();
        }
    } else if (item.getItemId() == R.id.main_menu_current_location) {
        Location myLoc = map.getMyLocation();
        if (myLoc == null) {
            Toast.makeText(this, "Still searching for your location", Toast.LENGTH_SHORT).show();
        } else {
            CameraPosition oldPos = map.getCameraPosition();
            CameraPosition newPos = new CameraPosition(new LatLng(myLoc.getLatitude(), myLoc.getLongitude()),
                    map.getMaxZoomLevel(), oldPos.tilt, oldPos.bearing);
            map.animateCamera(CameraUpdateFactory.newCameraPosition(newPos));
        }
    } else if (item.getItemId() == R.id.main_menu_layers) {
        MenuItem layers = menu.findItem(R.id.main_menu_layers);
        if (showingHazards == false) {
            showingHazards = true;
            layers.setTitle("Hide Hazards");
        } else {
            showingHazards = false;
            layers.setTitle("Show Hazards");
        }
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("showingHazards", showingHazards);
        editor.commit();
        drawHazards();
    } else if (item.getItemId() == R.id.main_menu_list_view) {
        if (mCurrentState == STATE_LIST_VIEW) {
            // Show map view
            Log.d("MainActivity", "Showing map view");
            setState(STATE_DEFAULT);
            //item.setIcon(R.drawable.list_view);
            this.invalidateOptionsMenu();
        } else {
            // Show list view
            Log.d("MainActivity", "Showing list view");
            setState(STATE_LIST_VIEW);
            //item.setIcon(R.drawable.map_view);
            this.invalidateOptionsMenu();
        }
    } else if (item.getItemId() == R.id.main_menu_help) {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("Help");
        WebView wv = new WebView(this);
        wv.loadUrl("file:///android_asset/Help.html");
        wv.getSettings().setSupportZoom(true);
        wv.getSettings().setBuiltInZoomControls(true);
        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        alert.setView(wv);
        alert.setNegativeButton("Close", null);
        alert.show();
    } else if (item.getItemId() == R.id.main_menu_legal) {
        CharSequence licence = "The MIT License (MIT)\n" + "\n" + "Copyright (c) 2013 Purdue University\n"
                + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy "
                + "of this software and associated documentation files (the \"Software\"), to deal "
                + "in the Software without restriction, including without limitation the rights "
                + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell "
                + "copies of the Software, and to permit persons to whom the Software is "
                + "furnished to do so, subject to the following conditions:" + "\n"
                + "The above copyright notice and this permission notice shall be included in "
                + "all copies or substantial portions of the Software.\n" + "\n"
                + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR "
                + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
                + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
                + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
                + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, "
                + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN "
                + "THE SOFTWARE.\n";
        new AlertDialog.Builder(this).setTitle("Legal").setMessage(licence)
                .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton("Close", null).show();
    }
    return true;
}

From source file:de.mkrtchyan.recoverytools.RecoveryTools.java

private void showChangelog() {
    if (version_changed) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(R.string.changelog);
        WebView changes = new WebView(mContext);
        changes.setWebViewClient(new WebViewClient());
        changes.loadUrl("http://forum.xda-developers.com/showpost.php?p=42839595&postcount=3");
        dialog.setView(changes);/*from w  ww  . ja v a  2s .  c om*/
        dialog.show();
    }
}

From source file:com.intel.xdk.device.Device.java

public void showRemoteSite(final String strURL, final int closeX_pt, final int closeY_pt, final int closeX_ls,
        final int closeY_ls, final int closeW, final int closeH, final String closeImage) {
    if (strURL == null || strURL.length() == 0)
        return;//from ww w .ja  v  a2s.co  m

    remoteCloseXPort = closeX_pt;
    remoteCloseYPort = closeY_pt;
    remoteCloseXLand = closeX_ls;
    remoteCloseYLand = closeY_ls;

    //hack to adjust image size
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    remoteCloseW = (int) ((float) closeW * dm.density);
    remoteCloseH = (int) ((float) closeH * dm.density);

    //Set position, width, height of closeImage according to currentOrientation
    if (this.getOrientation() == 0 || this.getOrientation() == 180) {
        //Portrait
        AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(
                remoteCloseW == 0 ? 48 : remoteCloseW, remoteCloseH == 0 ? 48 : remoteCloseH, remoteCloseXPort,
                remoteCloseYPort);
        remoteClose.setLayoutParams(params);
    } else {
        AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(
                remoteCloseW == 0 ? 48 : remoteCloseW, remoteCloseH == 0 ? 48 : remoteCloseH, remoteCloseXLand,
                remoteCloseYLand);
        remoteClose.setLayoutParams(params);
    }

    activity.runOnUiThread(new Runnable() {

        public void run() {

            if (remoteView == null) {

                remoteView = new WebView(activity);
                remoteView.setInitialScale(0);
                remoteView.setVerticalScrollBarEnabled(false);
                remoteView.setWebViewClient(new WebViewClient());
                final WebSettings settings = remoteView.getSettings();
                settings.setJavaScriptEnabled(true);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);

                remoteLayout.addView(remoteView,
                        new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER));

                remoteView.requestFocusFromTouch();

                remoteView.setOnKeyListener(new View.OnKeyListener() {
                    @Override
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        if (event.getAction() != KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
                            remoteClose.performClick();
                            return true;
                        } else {
                            return false;
                        }
                    }
                });
            }
            // load the url
            remoteView.loadUrl(strURL);
            // show the view
            remoteLayout.setVisibility(View.VISIBLE);
            // set the flag
            isShowingRemoteSite = true;
            // isShowingRemoteSite = true;
            // get focus
            remoteView.requestFocus(View.FOCUS_DOWN);
            remoteClose.bringToFront();
        }
    });

}

From source file:com.baidu.cafe.local.record.WebElementRecorder.java

public void setHookedWebViewClient(final WebView webView, final String javaScript) {
    webView.post(new Runnable() {
        // @Override
        public void run() {
            final WebViewClient orginalWebViewClient = getOriginalWebViewClient(webView);
            if (orginalWebViewClient != null) {
                webView.setWebViewClient(new WebViewClient() {

                    HashMap<String, Boolean> invoke = new HashMap<String, Boolean>();

                    @Override/*from w  w w .j  a  va  2s .  com*/
                    public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
                        orginalWebViewClient.doUpdateVisitedHistory(view, url, isReload);
                    }

                    @Override
                    public void onFormResubmission(WebView view, Message dontResend, Message resend) {
                        orginalWebViewClient.onFormResubmission(view, dontResend, resend);
                    }

                    @Override
                    public void onLoadResource(WebView view, String url) {
                        String funcName = new Throwable().getStackTrace()[1].getMethodName();
                        if (invoke.get(funcName) == null || !invoke.get(funcName)) {
                            invoke.put(funcName, true);
                            orginalWebViewClient.onLoadResource(view, url);
                            invoke.put(funcName, false);
                        }
                    }

                    @Override
                    public void onPageFinished(WebView view, String url) {
                        String funcName = new Throwable().getStackTrace()[1].getMethodName();
                        if (invoke.get(funcName) == null || !invoke.get(funcName)) {
                            invoke.put(funcName, true);
                            orginalWebViewClient.onPageFinished(view, url);
                            if (url != null) {
                                hookWebElements(view, javaScript);
                            }
                            invoke.put(funcName, false);
                        }
                    }

                    @Override
                    public void onPageStarted(WebView view, String url, Bitmap favicon) {
                        String funcName = new Throwable().getStackTrace()[1].getMethodName();
                        if (invoke.get(funcName) == null || !invoke.get(funcName)) {
                            invoke.put(funcName, true);
                            orginalWebViewClient.onPageStarted(view, url, favicon);
                            invoke.put(funcName, false);
                        }
                    }

                    @Override
                    public void onReceivedError(WebView view, int errorCode, String description,
                            String failingUrl) {
                        orginalWebViewClient.onReceivedError(view, errorCode, description, failingUrl);
                    }

                    @Override
                    public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host,
                            String realm) {
                        orginalWebViewClient.onReceivedHttpAuthRequest(view, handler, host, realm);
                    }

                    public void onReceivedLoginRequest(WebView view, String realm, String account,
                            String args) {
                        // do support onReceivedLoginRequest since the
                        // version 4.0
                        if (Build.VERSION.SDK_INT >= 14) {
                            orginalWebViewClient.onReceivedLoginRequest(view, realm, account, args);
                        }
                    }

                    @Override
                    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                        orginalWebViewClient.onReceivedSslError(view, handler, error);
                    }

                    @Override
                    public void onScaleChanged(WebView view, float oldScale, float newScale) {
                        orginalWebViewClient.onScaleChanged(view, oldScale, newScale);
                    }

                    @Override
                    public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) {
                        orginalWebViewClient.onTooManyRedirects(view, cancelMsg, continueMsg);
                    }

                    @Override
                    public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
                        orginalWebViewClient.onUnhandledKeyEvent(view, event);
                    }

                    @Override
                    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
                        if (Build.VERSION.SDK_INT >= 14) {
                            return orginalWebViewClient.shouldInterceptRequest(view, url);
                        } else {
                            return null;
                        }
                    }

                    @Override
                    public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
                        return orginalWebViewClient.shouldOverrideKeyEvent(view, event);
                    }

                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        boolean ret = false;
                        String funcName = new Throwable().getStackTrace()[1].getMethodName();
                        if (invoke.get(funcName) == null || !invoke.get(funcName)) {
                            invoke.put(funcName, true);
                            ret = orginalWebViewClient.shouldOverrideUrlLoading(view, url);
                            invoke.put(funcName, false);
                        }
                        return ret;
                    }

                });
            } else {
                // set hook WebViewClient
                webView.setWebViewClient(new WebViewClient() {

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#doUpdateVisitedHistory(android.webkit.WebView, java.lang.String, boolean)
                     */
                    @Override
                    public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
                        // TODO Auto-generated method stub
                        super.doUpdateVisitedHistory(view, url, isReload);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onFormResubmission(android.webkit.WebView, android.os.Message, android.os.Message)
                     */
                    @Override
                    public void onFormResubmission(WebView view, Message dontResend, Message resend) {
                        // TODO Auto-generated method stub
                        super.onFormResubmission(view, dontResend, resend);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onLoadResource(android.webkit.WebView, java.lang.String)
                     */
                    @Override
                    public void onLoadResource(WebView view, String url) {
                        // TODO Auto-generated method stub
                        super.onLoadResource(view, url);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onPageStarted(android.webkit.WebView, java.lang.String, android.graphics.Bitmap)
                     */
                    @Override
                    public void onPageStarted(WebView view, String url, Bitmap favicon) {
                        // TODO Auto-generated method stub
                        super.onPageStarted(view, url, favicon);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onReceivedError(android.webkit.WebView, int, java.lang.String, java.lang.String)
                     */
                    @Override
                    public void onReceivedError(WebView view, int errorCode, String description,
                            String failingUrl) {
                        // TODO Auto-generated method stub
                        super.onReceivedError(view, errorCode, description, failingUrl);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onReceivedHttpAuthRequest(android.webkit.WebView, android.webkit.HttpAuthHandler, java.lang.String, java.lang.String)
                     */
                    @Override
                    public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host,
                            String realm) {
                        // TODO Auto-generated method stub
                        super.onReceivedHttpAuthRequest(view, handler, host, realm);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onReceivedLoginRequest(android.webkit.WebView, java.lang.String, java.lang.String, java.lang.String)
                     */
                    @Override
                    public void onReceivedLoginRequest(WebView view, String realm, String account,
                            String args) {
                        // TODO Auto-generated method stub
                        super.onReceivedLoginRequest(view, realm, account, args);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onReceivedSslError(android.webkit.WebView, android.webkit.SslErrorHandler, android.net.http.SslError)
                     */
                    @Override
                    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                        // TODO Auto-generated method stub
                        super.onReceivedSslError(view, handler, error);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onScaleChanged(android.webkit.WebView, float, float)
                     */
                    @Override
                    public void onScaleChanged(WebView view, float oldScale, float newScale) {
                        // TODO Auto-generated method stub
                        super.onScaleChanged(view, oldScale, newScale);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onTooManyRedirects(android.webkit.WebView, android.os.Message, android.os.Message)
                     */
                    @Override
                    public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) {
                        // TODO Auto-generated method stub
                        super.onTooManyRedirects(view, cancelMsg, continueMsg);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#onUnhandledKeyEvent(android.webkit.WebView, android.view.KeyEvent)
                     */
                    @Override
                    public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
                        // TODO Auto-generated method stub
                        super.onUnhandledKeyEvent(view, event);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#shouldInterceptRequest(android.webkit.WebView, java.lang.String)
                     */
                    @Override
                    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
                        // TODO Auto-generated method stub
                        return super.shouldInterceptRequest(view, url);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#shouldOverrideKeyEvent(android.webkit.WebView, android.view.KeyEvent)
                     */
                    @Override
                    public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
                        // TODO Auto-generated method stub
                        return super.shouldOverrideKeyEvent(view, event);
                    }

                    /* (non-Javadoc)
                     * @see android.webkit.WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String)
                     */
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        // TODO Auto-generated method stub
                        return super.shouldOverrideUrlLoading(view, url);
                    }

                    @Override
                    public void onPageFinished(WebView view, String url) {
                        super.onPageFinished(webView, url);
                        // print("webView onPageFinished: " + url);
                        if (url != null) {
                            hookWebElements(view, javaScript);
                        }
                    }
                });
            }
        }
    });
}

From source file:app.clirnet.com.clirnetapp.activity.LoginActivity.java

private void showDialog12() {

    final View checkBoxView = View.inflate(this, R.layout.alert_checkbox, null);
    final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkBox);
    final WebView wv = (WebView) checkBoxView.findViewById(R.id.webview);

    //  checkBox.setText("Yes, I accept the terms and condition");
    final AlertDialog.Builder ad = new AlertDialog.Builder(this)
            // .setMessage(termsnconditiomessage)
            .setView(checkBoxView).setIcon(R.drawable.info).setTitle("Terms of Service");

    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override//from   w w w  . j a va2s.  com
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (isChecked) {
                //Method will send radio button checked status to yes button for further process of redirection
                checkedStatus(true);

            } else {

                checkedStatus(false);
                Toast.makeText(getApplicationContext(), "Please accept the terms and condition to proceed ",
                        Toast.LENGTH_LONG).show();
            }

        }

    });

    wv.setVisibility(View.VISIBLE);
    wv.loadUrl("http://doctor.clirnet.com/doctor/patientcentral/termsandcondition");
    wv.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);

            return true;
        }
    });

    ad.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            //Toast.makeText(mContext.getApplicationContext(), "You have accepted the TOS. Welcom to the site", Toast.LENGTH_SHORT).show();
            if (responceCheck) {
                rememberTermsCondition("Yes");
                Intent intent = new Intent(getApplicationContext(), SplashActivity.class);
                startActivity(intent);
                new AppController().showToastMsg(getApplicationContext(), "Login Successful");
                startService();

            } else {
                new AppController().showToastMsg(getApplicationContext(),
                        "Please accept the terms and condition to proceed");
                // Toast.makeText(mContext.getApplicationContext(), "Please accept the terms and condition to proceed", Toast.LENGTH_SHORT).show();

            }

        }
    });
    ad.setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getApplicationContext(), "You have denied the TOS. You may not access the site",
                    Toast.LENGTH_SHORT).show();
            rememberTermsCondition("No");
        }
    });

    ad.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getApplicationContext(), "Please select yes or no", Toast.LENGTH_SHORT).show();
            rememberTermsCondition("No");
        }
    });

    ad.setCancelable(false);
    ad.setView(checkBoxView);
    ad.show();

}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

private void optionChangelog() {
    WebView webview = new WebView(this);
    webview.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            int userId = Util.getUserId(Process.myUid());
            Version currentVersion = new Version(Util.getSelfVersionName(ActivityMain.this));
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingChangelog, currentVersion.toString());
        }/*from  ww w .ja v  a  2  s . com*/
    });
    webview.loadUrl("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md");

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(R.string.menu_changelog);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(webview);
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:com.ichi2.anki.AbstractFlashcardViewer.java

@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
// because of setDisplayZoomControls.
private WebView createWebView() {
    WebView webView = new MyWebView(this);
    webView.setWillNotCacheDrawing(true);
    webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    if (CompatHelper.isHoneycomb()) {
        // Disable the on-screen zoom buttons for API > 11
        webView.getSettings().setDisplayZoomControls(false);
    }/*  w  w w.ja  v a  2s.  c om*/
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setSupportZoom(true);
    // Start at the most zoomed-out level
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebChromeClient(new AnkiDroidWebChromeClient());
    // Problems with focus and input tags is the reason we keep the old type answer mechanism for old Androids.
    webView.setFocusableInTouchMode(mUseInputTag);
    webView.setScrollbarFadingEnabled(true);
    Timber.d("Focusable = %s, Focusable in touch mode = %s", webView.isFocusable(),
            webView.isFocusableInTouchMode());

    webView.setWebViewClient(new WebViewClient() {
        // Filter any links using the custom "playsound" protocol defined in Sound.java.
        // We play sounds through these links when a user taps the sound icon.
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("playsound:")) {
                // Send a message that will be handled on the UI thread.
                Message msg = Message.obtain();
                String soundPath = url.replaceFirst("playsound:", "");
                msg.obj = soundPath;
                mHandler.sendMessage(msg);
                return true;
            }
            if (url.startsWith("file") || url.startsWith("data:")) {
                return false; // Let the webview load files, i.e. local images.
            }
            if (url.startsWith("typeblurtext:")) {
                // Store the text the javascript has send us
                mTypeInput = URLDecoder.decode(url.replaceFirst("typeblurtext:", ""));
                //  and show the SHOW ANSWER? button again.
                mFlipCardLayout.setVisibility(View.VISIBLE);
                return true;
            }
            if (url.startsWith("typeentertext:")) {
                // Store the text the javascript has send us
                mTypeInput = URLDecoder.decode(url.replaceFirst("typeentertext:", ""));
                //  and show the answer.
                mFlipCardLayout.performClick();
                return true;
            }
            if (url.equals("signal:typefocus")) {
                // Hide the SHOW ANSWER? button when the input has focus. The soft keyboard takes up enough space
                // by itself.
                mFlipCardLayout.setVisibility(View.GONE);
                return true;
            }
            Timber.d("Opening external link \"%s\" with an Intent", url);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            try {
                startActivityWithoutAnimation(intent);
            } catch (ActivityNotFoundException e) {
                e.printStackTrace(); // Don't crash if the intent is not handled
            }
            return true;
        }

        // Run any post-load events in javascript that rely on the window being completely loaded.
        @Override
        public void onPageFinished(WebView view, String url) {
            Timber.d("onPageFinished triggered");
            view.loadUrl("javascript:onPageFinished();");
        }
    });
    // Set transparent color to prevent flashing white when night mode enabled
    webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
    return webView;
}