Example usage for android.webkit WebView getSettings

List of usage examples for android.webkit WebView getSettings

Introduction

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

Prototype

public WebSettings getSettings() 

Source Link

Document

Gets the WebSettings object used to control the settings for this WebView.

Usage

From source file:com.wrmndfzzy.atomize.intro.IntroActivity.java

protected void applicenseDialog() {
    final Dialog aLDialog = new Dialog(IntroActivity.this);
    aLDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    aLDialog.setTitle("License Agreement");
    aLDialog.setCancelable(false);/*  w w  w. jav  a2  s  .co m*/
    aLDialog.setCanceledOnTouchOutside(false);
    aLDialog.setContentView(R.layout.app_license_dialog);
    WebView lic = (WebView) aLDialog.findViewById(R.id.atomizeLic);
    Button disagree = (Button) aLDialog.findViewById(R.id.alDialogDisagree);
    Button agree = (Button) aLDialog.findViewById(R.id.alDialogAgree);
    lic.getSettings().setUseWideViewPort(true);
    lic.loadUrl("file:///android_asset/atomizeLicense.html");
    disagree.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            aLDialog.dismiss();
            SharedPreferences.Editor e = getPrefs.edit();
            e.putBoolean("agreedToLicense", false);
            e.apply();
            Intent homeIntent = new Intent(Intent.ACTION_MAIN);
            homeIntent.addCategory(Intent.CATEGORY_HOME);
            homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(homeIntent);
            IntroActivity.this.finish();
            MainActivity.getInstance().finish();
        }
    });
    agree.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences.Editor e = getPrefs.edit();
            e.putBoolean("agreedToLicense", true);
            e.apply();
            aLDialog.dismiss();
        }
    });
    aLDialog.show();
}

From source file:bolts.WebViewAppLinkResolver.java

@Override
public Task<AppLink> getAppLinkFromUrlInBackground(final Uri url) {
    final Capture<String> content = new Capture<String>();
    final Capture<String> contentType = new Capture<String>();
    return Task.callInBackground(new Callable<Void>() {
        @Override/*from w  w w.  j a  v  a  2s. c  o m*/
        public Void call() throws Exception {
            URL currentURL = new URL(url.toString());
            URLConnection connection = null;
            while (currentURL != null) {
                // Fetch the content at the given URL.
                connection = currentURL.openConnection();
                if (connection instanceof HttpURLConnection) {
                    // Unfortunately, this doesn't actually follow redirects if they go from http->https,
                    // so we have to do that manually.
                    ((HttpURLConnection) connection).setInstanceFollowRedirects(true);
                }
                connection.setRequestProperty(PREFER_HEADER, META_TAG_PREFIX);
                connection.connect();

                if (connection instanceof HttpURLConnection) {
                    HttpURLConnection httpConnection = (HttpURLConnection) connection;
                    if (httpConnection.getResponseCode() >= 300 && httpConnection.getResponseCode() < 400) {
                        currentURL = new URL(httpConnection.getHeaderField("Location"));
                        httpConnection.disconnect();
                    } else {
                        currentURL = null;
                    }
                } else {
                    currentURL = null;
                }
            }

            try {
                content.set(readFromConnection(connection));
                contentType.set(connection.getContentType());
            } finally {
                if (connection instanceof HttpURLConnection) {
                    ((HttpURLConnection) connection).disconnect();
                }
            }
            return null;
        }
    }).onSuccessTask(new Continuation<Void, Task<JSONArray>>() {
        @Override
        public Task<JSONArray> then(Task<Void> task) throws Exception {
            // Load the content in a WebView and use JavaScript to extract the meta tags.
            final TaskCompletionSource<JSONArray> tcs = new TaskCompletionSource<>();
            final WebView webView = new WebView(context);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.setNetworkAvailable(false);
            webView.setWebViewClient(new WebViewClient() {
                private boolean loaded = false;

                private void runJavaScript(WebView view) {
                    if (!loaded) {
                        // After the first resource has been loaded (which will be the pre-populated data)
                        // run the JavaScript meta tag extraction script
                        loaded = true;
                        view.loadUrl(TAG_EXTRACTION_JAVASCRIPT);
                    }
                }

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

                @Override
                public void onLoadResource(WebView view, String url) {
                    super.onLoadResource(view, url);
                    runJavaScript(view);
                }
            });
            // Inject an object that will receive the JSON for the extracted JavaScript tags
            webView.addJavascriptInterface(new Object() {
                @JavascriptInterface
                public void setValue(String value) {
                    try {
                        tcs.trySetResult(new JSONArray(value));
                    } catch (JSONException e) {
                        tcs.trySetError(e);
                    }
                }
            }, "boltsWebViewAppLinkResolverResult");
            String inferredContentType = null;
            if (contentType.get() != null) {
                inferredContentType = contentType.get().split(";")[0];
            }
            webView.loadDataWithBaseURL(url.toString(), content.get(), inferredContentType, null, null);
            return tcs.getTask();
        }
    }, Task.UI_THREAD_EXECUTOR).onSuccess(new Continuation<JSONArray, AppLink>() {
        @Override
        public AppLink then(Task<JSONArray> task) throws Exception {
            Map<String, Object> alData = parseAlData(task.getResult());
            AppLink appLink = makeAppLinkFromAlData(alData, url);
            return appLink;
        }
    });
}

From source file:com.hhs.hfnavigator.slidingtabs.tools.CastleFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_webview, null);

    progressWheel = (ProgressWheel) root.findViewById(R.id.webViewProgress);

    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe);
    swipeRefreshLayout.setEnabled(false);
    progressWheel.spin();/*w  ww .j a v a  2s  .c  om*/
    final WebView webView = (WebView) root.findViewById(R.id.webView);
    if (webView != null) {
        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                progressWheel.stopSpinning();
            }
        });
        webView.loadUrl("http://www.castlelearning.com/mobile");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);

    }
    return root;
}

From source file:nirwan.cordova.plugin.printer.Printer.java

private void loadContentAsBitmapIntoPrintController(String content, final Intent intent) {
    Activity ctx = cordova.getActivity();
    final WebView page = new WebView(ctx);
    final Printer self = this;

    page.setVisibility(View.INVISIBLE);
    page.getSettings().setJavaScriptEnabled(false);

    page.setWebViewClient(new WebViewClient() {
        @Override/* w w w . jav  a 2s.  c o  m*/
        public void onPageFinished(final WebView page, String url) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Bitmap screenshot = self.takeScreenshot(page);
                    File tmpFile = self.saveScreenshotToTmpFile(screenshot);
                    ViewGroup vg = (ViewGroup) (page.getParent());

                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tmpFile));

                    vg.removeView(page);
                }
            }, 1000);
        }
    });

    //Set base URI to the assets/www folder
    String baseURL = webView.getUrl();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/') + 1);

    ctx.addContentView(page, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    page.loadDataWithBaseURL(baseURL, content, "text/html", "UTF-8", null);
}

From source file:org.apache.taverna.mobile.ui.DashboardActivity.java

/**
 * @param navigationView Design Support NavigationView  OnClick Listener Event
 *//*from w w w  . j a va2s  .c o m*/
private void setupDrawerContent(final NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            switch (menuItem.getItemId()) {
            case R.id.nav_workflows:

                fragment = new WorkflowFragment();
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), fragment,
                        R.id.frame_container);

                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();
                toolbar.setTitle(R.string.title_nav_all_workflows);

                return true;

            case R.id.nav_my_workflows:

                fragment = new MyWorkflowFragment();
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), fragment,
                        R.id.frame_container);

                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();
                toolbar.setTitle(R.string.title_nav_my_workflows);
                return true;

            case R.id.nav_favourite_workflow:

                fragment = new FavouriteWorkflowsFragment();
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), fragment,
                        R.id.frame_container);

                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();
                toolbar.setTitle(R.string.title_nav_favourite_workflows);
                return true;

            case R.id.nav_announcement:

                fragment = new AnnouncementFragment();
                ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), fragment,
                        R.id.frame_container);

                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();
                toolbar.setTitle(R.string.title_nav_announcement);
                return true;

            case R.id.nav_usage:

                dialog.setCanceledOnTouchOutside(true);
                dialog.setTitle(getString(R.string.title_nav_usage));
                dialog.setContentView(R.layout.usage_layout);
                dialog.show();
                mDrawerLayout.closeDrawers();
                return true;

            case R.id.nav_about:

                TableLayout about = (TableLayout) getLayoutInflater().inflate(R.layout.about, navigationView,
                        false);

                dialog.setCanceledOnTouchOutside(true);
                dialog.setTitle(getString(R.string.title_about));
                dialog.setContentView(about);
                dialog.show();
                mDrawerLayout.closeDrawers();
                return true;

            case R.id.os_licences:

                WebView webView = (WebView) getLayoutInflater().inflate(R.layout.fragment_licence,
                        navigationView, false);

                webView.getSettings().setUseWideViewPort(true);
                webView.loadUrl("file:///android_asset/licences.html");

                AlertDialog alertDialog = new AlertDialog.Builder(DashboardActivity.this,
                        R.style.Theme_Taverna_Dialog).setTitle(getString(R.string.title_nav_os_licences))
                                .setView(webView).setPositiveButton(android.R.string.ok, null).create();

                alertDialog.show();
                mDrawerLayout.closeDrawers();
                return true;

            case R.id.nav_settings:

                startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
                overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);

                mDrawerLayout.closeDrawers();
                return true;

            case R.id.nav_logout:

                mDrawerLayout.closeDrawers();
                dataManager.getPreferencesHelper().setLoggedInFlag(false);

                startActivity(new Intent(getApplicationContext(), LoginActivity.class));
                finish();
                return true;

            }
            return true;
        }
    });
}

From source file:com.vikingbrain.dmt.view.RemoteControlActivity.java

private void configureWebView(WebView webView, WebChromeClient webChromeClient,
        CustomWebViewClient customWebViewClient) {
    //Set the properties      
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true); //Zoom Control on web (You don't need this if ROM supports Multi-Touch       
    webSettings.setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM
    webSettings.setDomStorageEnabled(true);
    webSettings.setPluginsEnabled(true);
    webSettings.setUseWideViewPort(true); //normal viewport (such as a normal desktop browser)

    webView.setWebChromeClient(webChromeClient);
    webView.setWebViewClient(customWebViewClient);
}

From source file:com.mimo.service.api.MimoOauth2Client.java

/**
 * Instantiate a webview and allows the user to login to the Api form within
 * the application/*  w w w .j av  a  2  s  .  c o  m*/
 * 
 * @param p_view
 *            : Calling view
 * 
 * @param p_activity
 *            : Calling Activity reference
 **/

@SuppressLint("SetJavaScriptEnabled")
public void login(View p_view, Activity p_activity) {

    final Activity m_activity;
    m_activity = p_activity;
    String m_url = this.m_api.getAuthUrl();
    WebView m_webview = new WebView(p_view.getContext());
    m_webview.getSettings().setJavaScriptEnabled(true);
    m_webview.setVisibility(View.VISIBLE);
    m_activity.setContentView(m_webview);

    m_webview.requestFocus(View.FOCUS_DOWN);
    /**
     * Open the softkeyboard of the device to input the text in form which
     * loads in webview.
     */
    m_webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View p_v, MotionEvent p_event) {
            switch (p_event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!p_v.hasFocus()) {
                    p_v.requestFocus();
                }
                break;
            }
            return false;
        }
    });

    /**
     * Show the progressbar in the title of the activity untill the page
     * loads the give url.
     */
    m_webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView p_view, int p_newProgress) {
            ((Activity) m_context).setProgress(p_newProgress * 100);
            ((Activity) m_context).setTitle(MimoAPIConstants.DIALOG_TEXT_LOADING);

            if (p_newProgress == 100)
                ((Activity) m_context).setTitle(m_context.getString(R.string.app_name));
        }
    });

    m_webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView p_view, String p_url, Bitmap p_favicon) {
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView p_view, HttpAuthHandler p_handler, String p_url,
                String p_realm) {
            p_handler.proceed(MimoAPIConstants.USERNAME, MimoAPIConstants.PASSWORD);
        }

        public void onPageFinished(WebView p_view, String p_url) {
            if (MimoAPIConstants.DEBUG) {
                Log.d(TAG, "Page Url = " + p_url);
            }
            if (p_url.contains("?code=")) {
                if (p_url.indexOf("code=") != -1) {
                    String[] m_urlSplit = p_url.split("=");

                    String m_tempString1 = m_urlSplit[1];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "TempString1 = " + m_tempString1);
                    }
                    String[] m_urlSplit1 = m_tempString1.split("&");

                    String m_code = m_urlSplit1[0];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "code = " + m_code);
                    }
                    MimoOauth2Client.this.m_code = m_code;
                    Thread m_thread = new Thread() {
                        public void run() {
                            String m_token = requesttoken(MimoOauth2Client.this.m_code);

                            Log.d(TAG, "Token = " + m_token);

                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);

                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);

                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                } else {
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "going in else");
                    }
                }
            } else if (p_url.contains(MimoAPIConstants.URL_KEY_TOKEN)) {
                if (p_url.indexOf(MimoAPIConstants.URL_KEY_TOKEN) != -1) {
                    String[] m_urlSplit = p_url.split("=");
                    final String m_token = m_urlSplit[1];

                    Thread m_thread = new Thread() {
                        public void run() {
                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);
                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);
                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                }
            }
        };
    });

    m_webview.loadUrl(m_url);
}

From source file:com.hhs.hfnavigator.slidingtabs.tools.PortalFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_webview, null);

    progressWheel = (ProgressWheel) root.findViewById(R.id.webViewProgress);

    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe);
    swipeRefreshLayout.setEnabled(false);
    progressWheel.spin();/*from   w w  w.j av  a  2  s .c o  m*/
    final WebView webView = (WebView) root.findViewById(R.id.webView);
    if (webView != null) {
        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                progressWheel.stopSpinning();
            }
        });
        webView.loadUrl("https://harborfieldscsd.esboces.org/campus/portal/harborfields.jsp");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);
    }
    return root;
}

From source file:com.hhs.hfnavigator.slidingtabs.hhs.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_webview, null);

    progressWheel = (ProgressWheel) root.findViewById(R.id.webViewProgress);

    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe);
    swipeRefreshLayout.setEnabled(false);
    progressWheel.spin();//from www .  ja va 2 s  . c  o  m
    final WebView webView = (WebView) root.findViewById(R.id.webView);
    if (webView != null) {
        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                progressWheel.stopSpinning();
            }
        });
        webView.loadUrl("http://www.harborfieldscsd.net/our_schools/harborfields_high_school");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);
    }
    return root;
}

From source file:com.hhs.hfnavigator.slidingtabs.hhs.LibFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_webview, null);

    progressWheel = (ProgressWheel) root.findViewById(R.id.webViewProgress);

    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe);
    swipeRefreshLayout.setEnabled(false);
    progressWheel.spin();//from  w  w w  .  j a  va2 s. c o  m
    final WebView webView = (WebView) root.findViewById(R.id.webView);
    if (webView != null) {
        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                progressWheel.stopSpinning();
            }
        });
        webView.loadUrl("https://hscsd.follettdestiny.com/common/welcome.jsp?context=saas30_3133764");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);

    }
    return root;
}