Example usage for android.webkit WebView setWebViewClient

List of usage examples for android.webkit WebView setWebViewClient

Introduction

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

Prototype

public void setWebViewClient(WebViewClient client) 

Source Link

Document

Sets the WebViewClient that will receive various notifications and requests.

Usage

From source file:com.zuluindia.watchpresenter.MainActivity.java

public void showGestureExperimental() {
    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.html_dialog, null);
    WebView mainWebView = (WebView) dialogLayout.findViewById(R.id.mainWebView);
    mainWebView.setWebViewClient(new MailtoWebView(this));
    mainWebView.loadUrl("file:///android_asset/gestures_experimental.html");
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(dialogLayout);/*w  ww .  jav  a2  s .  c o m*/
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    builder.setTitle(getString(R.string.experimentalFeature));
    builder.show();
}

From source file:edu.cscie71.imm.slacker.plugin.Slacker.java

private void closeAuthScreen() {
    final WebView childView = this.inAppWebView;
    // The JS protects against multiple calls, so this should happen only when
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;/*from  ww  w  . j  a v  a 2 s.  c o m*/
    }
    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");
        }
    });
}

From source file:com.robandjen.comicsapp.FullscreenActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*  w w w. j a  v a  2  s  . c om*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_fullscreen);

    final WebView v = (WebView) findViewById(R.id.fullscreen_content);
    v.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            updateShare(url);
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            setProgressBarIndeterminateVisibility(false);
            super.onPageFinished(view, url);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            setProgressBarIndeterminateVisibility(true);
            super.onPageStarted(view, url, favicon);
        }
    });

    final WebSettings settings = v.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.open_drawer,
            R.string.close_drawer);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    if (mComicList == null) {

        try {
            InputStream is = openFileInput(COMICFILE);
            if (!loadXml(is)) {
                Log.w(TAG, "Downloaded list not parseable, defaulting to built-in");
            }
        } catch (FileNotFoundException e) {
            Log.i(TAG, "Downloaded list not found, defaulting to built-in");

        }
    }

    if (mComicList == null) {
        loadDefaultXML();
    }

    if (savedInstanceState != null) {
        mCurComic = savedInstanceState.getInt(CURCOMICKEY, 0);
        final String url = savedInstanceState.getString(CURURLKEY);
        showCurrentComic(url);
    } else {
        do {
            if (!bSkipOther || !mComicList.get(mCurComic).getOther()) {
                break;
            }

            ++mCurComic;
            mCurComic %= mComicList.size();
        } while (mCurComic != 0);
        showCurrentComic();
    }

}

From source file:com.sahildave.snackbar.SnackBar.java

private View addLargeContainer(MessageType messageType, String inputUrl) {
    View v = activity.getLayoutInflater().inflate(R.layout.usb_large_container, null);
    WebView webView = (WebView) v.findViewById(R.id.snackWebview);
    webView.getSettings().setJavaScriptEnabled(true);

    webView.setWebViewClient(new WebViewClient() {

        @Override/*w ww  .  j a va  2s.  co m*/
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

    webView.loadUrl(inputUrl);

    v.setTag(messageType);
    addToView(v);

    return v;

}

From source file:net.basov.ticketinfo.UI.java

public void displayHelpScreen(String title, final WebView wv) {

    setHelp("h_header", title);
    setHelp("h_storage", FileIO.getFilesDir(wv.getContext()).getAbsolutePath());

    wv.setWebViewClient(new MyWebViewClient() {
        @Override/*from w ww .j a  v a  2 s  .com*/
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(wv, url);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                view.evaluateJavascript("javascript:jreplace('" + help_json.toString() + "')", null);
            } else {
                view.loadUrl("javascript:jreplace('" + help_json.toString() + "')");
            }
            wv.clearCache(true);
        }
    });
    Context c = wv.getContext();
    wv.loadUrl("file:///android_asset/" + c.getString(R.string.help_ui_file));

}

From source file:ph.com.globe.connect.AuthenticationActivity.java

/**
 * On activity create process./*w  w  w.j  a  va2  s.c om*/
 *
 * @param savedInstanceState instance state
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    // call base create
    super.onCreate(savedInstanceState);

    // initialize web view
    final WebView webview = new WebView(this);

    // set content view of the activity
    setContentView(webview);

    // get the app id from intent
    final String appId = getIntent().getStringExtra("app_id");
    // get the app secret from intent
    final String appSecret = getIntent().getStringExtra("app_secret");

    // set web view client
    webview.setWebViewClient(new WebViewClient() {
        /**
         * Let's catch all url changes.
         *
         * @param view current view
         * @param url current url
         * @return boolean
         */
        @SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // parse the uri
            final Uri uri = Uri.parse(url);

            // are we still on globe labs?
            if (uri.toString().indexOf(ROOT_URL) != 0) {
                // get the code
                String code = uri.getQueryParameter("code");

                // get access token request
                try {
                    getAccessToken(appId, appSecret, code);
                } catch (ApiException | HttpRequestException e) {
                    e.printStackTrace();
                }

                return false;
            }

            // load uri
            view.loadUrl(uri.toString());

            return false;
        }

        /**
         * Let's catch all url changes.
         *
         * @param view current view
         * @param request web resource request
         * @return boolean
         */
        @TargetApi(Build.VERSION_CODES.N)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            // parse the uri
            final Uri uri = Uri.parse(request.getUrl().toString());

            // are we still on globe labs?
            if (uri.toString().indexOf(ROOT_URL) != 0) {
                // get the code
                String code = uri.getQueryParameter("code");

                // get access token request
                try {
                    getAccessToken(appId, appSecret, code);
                } catch (ApiException | HttpRequestException e) {
                    e.printStackTrace();
                }

                return false;
            }

            // load uri
            view.loadUrl(uri.toString());

            return false;
        }
    });

    try {
        // set dialog url
        String DIALOG_URL = this.buildUrl(this.DIALOG_URL, appId);

        // load the url
        webview.loadUrl(DIALOG_URL);
    } catch (ApiException e) {
        e.printStackTrace();
    }
}

From source file:org.safegees.safegees.gui.view.MainActivity.java

private void start() {
    if (DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)) != null
            && DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)).length() > 0) {
        shareDataWithServer();/*  w  w  w  .j  a  va  2 s .com*/
    } else {

        /* TEST
        if(DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)) != null && DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)).length()>0){
        launchMainActivity();
        }else{
        //Start the loggin for result
        Intent loginInt = new Intent(this, LoginActivity.class);
        startActivityForResult(loginInt, 1);
        }*/

        if (Connectivity.isNetworkAvaiable(this) || StoredDataQuequesManager.getAppUsersMap(this).size() != 0) {

            final MainActivity mainActivity = this;

            //Download data
            this.adviceUser.setText(getResources().getString(R.string.splash_advice_download_info_hub));

            //Test
            //Not here at final
            final WebView webView = (WebView) this.findViewById(R.id.webview_info_pre_cache);
            final ArrayList<String> infoWebUrls = WebViewInfoWebDownloadController.getInfoUrlsArrayList();
            webView.setWebViewClient(new WebViewClient() {

                @Override
                public void onPageFinished(WebView view, String url) {
                    if (infoWebUrls.size() > 0) {
                        String nextUrl = infoWebUrls.get(0);
                        infoWebUrls.remove(nextUrl);
                        webView.loadUrl(nextUrl);
                    } else {
                        //Only one time
                        DATA_STORAGE.putBoolean(mainActivity.getResources().getString(R.string.KEY_INFO_WEB),
                                true);
                        //Start the loggin for result
                        Intent loginInt = new Intent(mainActivity, LoginActivity.class);
                        startActivityForResult(loginInt, 1);
                    }
                }
            });

            String nextUrl = infoWebUrls.get(0);
            infoWebUrls.remove(nextUrl);
            webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.setWebChromeClient(new WebChromeClient());

            if (StoredDataQuequesManager.getAppUsersMap(mainActivity).size() == 0
                    && !DATA_STORAGE.getBoolean(getResources().getString(R.string.KEY_INFO_WEB))) {
                webView.loadUrl(nextUrl);
            } else {
                if (DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)) != null
                        && DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL))
                                .length() > 0) {
                    launchMainActivity();
                } else {
                    //Start the loggin for result
                    Intent loginInt = new Intent(mainActivity, LoginActivity.class);
                    startActivityForResult(loginInt, 1);
                }
            }

        } else {
            setNoInternetAdvice(this);
        }
    }
}

From source file:com.gh4a.FileViewerActivity.java

private void fillData(boolean highlight) {
    String data = new String(EncodingUtils.fromBase64(mContent.getContent()));
    WebView webView = (WebView) findViewById(R.id.web_view);

    WebSettings s = webView.getSettings();
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    s.setAllowFileAccess(true);//from w  ww.  j a  v  a 2s . com
    s.setBuiltInZoomControls(true);
    s.setLightTouchEnabled(true);
    s.setLoadsImagesAutomatically(true);
    s.setPluginsEnabled(false);
    s.setSupportZoom(true);
    s.setSupportMultipleWindows(true);
    s.setJavaScriptEnabled(true);
    s.setUseWideViewPort(true);

    webView.setWebViewClient(webViewClient);
    if (FileUtils.isImage(mName)) {
        String htmlImage = StringUtils.highlightImage(
                "https://github.com/" + mRepoOwner + "/" + mRepoName + "/raw/" + mRef + "/" + mPath);
        webView.loadDataWithBaseURL("file:///android_asset/", htmlImage, "text/html", "utf-8", "");
    } else {
        String highlighted = StringUtils.highlightSyntax(data, highlight, mName);
        webView.loadDataWithBaseURL("file:///android_asset/", highlighted, "text/html", "utf-8", "");
    }
}

From source file:com.gorillalogic.fonemonkey.web.WebViewClientWrapper.java

public WebViewClientWrapper(WebView view) {
    Method meth;/*from  w  ww .  jav  a 2s  . c  om*/
    try {
        // recorder = new WebViewRecorder(webView);
        // webView.addJavascriptInterface(recorder, "mtrecorder");

        meth = WebView.class.getDeclaredMethod("getWebViewClient", (Class<?>[]) null);
        this.client = (WebViewClient) meth.invoke(view, (Object[]) null);
        if (client == null) {
            client = new WebViewClient();
        }
    } catch (Exception e) {
        throw new IllegalStateException("Error getting WebViewClient: " + e.getMessage(), e);
    }
    view.setWebViewClient(this);
    // view.loadUrl("javascript:window.webdriver = {resultMethod: function(result) {window.location = \"http://mtdummy?monkeytalkresult=\" + result}}");

}

From source file:com.almunt.jgcaap.systemupdater.MainActivity.java

public void LicencesDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Open Source Licenses");
    WebView wv = new WebView(this);
    wv.loadUrl("file:///android_asset/open_source_licenses.html");
    wv.setWebViewClient(new WebViewClient() {
        @Override//  www  .  j  a v  a2s  . c  om
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    alert.setView(wv);
    alert.setPositiveButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    alert.show();
}