Example usage for android.webkit WebSettings setLoadWithOverviewMode

List of usage examples for android.webkit WebSettings setLoadWithOverviewMode

Introduction

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

Prototype

public abstract void setLoadWithOverviewMode(boolean overview);

Source Link

Document

Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on screen by width.

Usage

From source file:com.cihon.androidrestart_keven.activity.CarNumActivity.java

/**
 * webview/*from  ww w  .j a  v a2s  .c  om*/
 */
public void initWebView() {
    MyWebViewClient webViewClient = new MyWebViewClient();
    mWebView.setWebViewClient(webViewClient);
    WebSettings webSettings = mWebView.getSettings();

    //
    webSettings.setLoadWithOverviewMode(true);
    //webview
    webSettings.setUseWideViewPort(true);
    //
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSupportZoom(true);
    webSettings.setJavaScriptEnabled(true);

    //        mWebView.loadUrl("http://webservice.cihon.cn/onStarActive1/reupload.html");
    mWebView.loadUrl("http://123.57.60.91/onStar3/vehicle-License.html");
    //        mWebView.loadUrl("http://wxpay.wxutil.com/mch/pay/h5.v2.php");

    //        jsjava
    mWebView.addJavascriptInterface(new JsInterface(this), "demo");
}

From source file:com.cerema.cloud2.ui.dialog.SamlWebViewDialog.java

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override/*from ww w  .jav a  2 s  .co m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.v(TAG, "onCreateView, savedInsanceState is " + savedInstanceState);

    // Inflate layout of the dialog  
    RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.sso_dialog, container, false); // null parent view because it will go in the dialog layout

    if (mSsoWebView == null) {
        // initialize the WebView
        mSsoWebView = new SsoWebView(getActivity().getApplicationContext());
        mSsoWebView.setFocusable(true);
        mSsoWebView.setFocusableInTouchMode(true);
        mSsoWebView.setClickable(true);

        WebSettings webSettings = mSsoWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setLoadWithOverviewMode(false);
        webSettings.setSavePassword(false);
        webSettings.setUserAgentString(MainApp.getUserAgent());
        webSettings.setSaveFormData(false);

        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeAllCookie();

        mSsoWebView.loadUrl(mInitialUrl);
    }

    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);

    // add the webview into the layout
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    ssoRootView.addView(mSsoWebView, layoutParams);
    ssoRootView.requestLayout();

    return ssoRootView;
}

From source file:com.digitalarx.android.ui.dialog.SamlWebViewDialog.java

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override//ww w . j a  va2  s .co  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.d(TAG, "onCreateView, savedInsanceState is " + savedInstanceState);

    // Inflate layout of the dialog  
    RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.sso_dialog, container, false); // null parent view because it will go in the dialog layout

    if (mSsoWebView == null) {
        // initialize the WebView
        mSsoWebView = new SsoWebView(getSherlockActivity().getApplicationContext());
        mSsoWebView.setFocusable(true);
        mSsoWebView.setFocusableInTouchMode(true);
        mSsoWebView.setClickable(true);

        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeAllCookie();
        mSsoWebView.loadUrl(mInitialUrl);

        WebSettings webSettings = mSsoWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setLoadWithOverviewMode(false);
        webSettings.setSavePassword(false);
        webSettings.setUserAgentString(OwnCloudClient.USER_AGENT);
        webSettings.setSaveFormData(false);
    }

    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);

    // add the webview into the layout
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    ssoRootView.addView(mSsoWebView, layoutParams);
    ssoRootView.requestLayout();

    return ssoRootView;
}

From source file:com.btmura.android.reddit.app.LinkFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void setupWebView(WebView webView) {
    WebSettings settings = webView.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setSupportZoom(true);/*from w w w.j a  v a2s.  c  om*/
    settings.setPluginState(PluginState.ON_DEMAND);
    settings.setUseWideViewPort(true);

    webView.setOnLongClickListener(this);

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (progress != null) {
                progress.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (progress != null) {
                progress.setVisibility(View.GONE);
            }
        }
    });

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (progress != null) {
                progress.setProgress(newProgress);
            }
        }
    });
}

From source file:it.rignanese.leo.slimtwitter.MainActivity.java

private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);/* www.j ava  2  s. com*/
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }

    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
}

From source file:com.sonnychen.aviationhk.views.BookingFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from w w  w  . ja  v  a 2 s .c  o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle bundle = getArguments();
    if (bundle != null && !TextUtils.isEmpty(bundle.getString(BOOKING_TYPE_PARAM))) {
        Log.v("BOOKING-UI", "Argument: " + bundle.getString(BOOKING_TYPE_PARAM));
        bookingType = BookingType.valueOf(bundle.getString(BOOKING_TYPE_PARAM));
    }

    Log.v("BOOKING-UI", "Starting");
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_booking, container, false);
    mProgressBar = ((ProgressBar) view.findViewById(R.id.progress));
    mWebView = ((WebView) view.findViewById(R.id.booking_html));

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccessFromFileURLs(true);
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setBuiltInZoomControls(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.addJavascriptInterface(new JSInterface(getActivity(), mWebView), "Android");
    mWebView.setInitialScale(1);

    // download PDF async
    new DownloadFileTask() {
        @Override
        protected void onPostExecute(Byte[] data) {
            // save data to file
            try {
                FileOutputStream fileOutputStream = getActivity().openFileOutput(
                        bookingType == BookingType.HELICOPTER ? "helicopter.pdf" : "fixedwing.pdf",
                        Context.MODE_PRIVATE);
                fileOutputStream.write(getbytes(data));
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

            displayPDF();
            // unfortunately HAKC does not have a valid SSL certificate
        }
    }.execute(bookingType == BookingType.HELICOPTER ? "http://aviationclub.hk/doc/helicopter_booking2.pdf"
            : "http://aviationclub.hk/doc/fixwing_booking2.pdf");
    return view;
}

From source file:no.digipost.android.gui.metadata.ExternalLinkWebview.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((DigipostApplication) getApplication()).getTracker(DigipostApplication.TrackerName.APP_TRACKER);
    setContentView(R.layout.activity_externallink_webview);
    Bundle bundle = getIntent().getExtras();
    fileUrl = bundle.getString("url", "https://www.digipost.no");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  w  w  w  .  j a v a  2  s.c  o  m
    actionBar = getSupportActionBar();
    if (actionBar != null) {
        setActionBarTitle(fileUrl);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setBackgroundDrawable(new ColorDrawable(0xff2E2E2E));

        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = this.getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(
                    ContextCompat.getColor(this, R.color.metadata_externalbrowser_top_background));
        }
    }

    progressSpinner = (ProgressBar) findViewById(R.id.externallink_spinner);
    webView = (WebView) findViewById(R.id.externallink_webview);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setDomStorageEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setScrollbarFadingEnabled(true);
    enableCookies(webView);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (firstLoad) {
                progressSpinner.setVisibility(View.GONE);
                webView.setVisibility(View.VISIBLE);
                firstLoad = false;
            }
            setActionBarTitle(view.getUrl());
        }
    });

    webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(final String url, final String userAgent, final String content,
                final String mimeType, final long contentLength) {
            fileName = URLUtil.guessFileName(url, content, mimeType);
            fileUrl = url;
            onComplete = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    String action = intent.getAction();
                    if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                        showDownloadSuccessDialog(context);
                    }
                }
            };

            registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
            if (!mimeType.equals("text/html")) {
                if (FileUtilities.isStorageWriteAllowed(getApplicationContext())) {
                    showDownloadDialog(userAgent, content, mimeType, contentLength);
                } else {
                    showMissingPermissionsDialog();
                }
            }
        }
    });

    if (FileUtilities.isStorageWriteAllowed(this)) {
        webView.loadUrl(fileUrl);
    } else {
        showPermissionsDialog();
    }
}

From source file:com.anxpp.blog.fragment.AboutFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void initView() {
    webView = (WebView) getView().findViewById(R.id.webView);
    //      webView.setVisibility(View.GONE);
    webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            Activity activity = getActivity();
            /**//from w w w.j a v  a 2  s .c  om
             * ?Fragment???
             * I am not sure why are you getting this error, 
             * i think it should be something like NullPointerException. 
             * Try next: 
             *     Evert time you calling getActivity() on Fragment instance you should be sure,
             *     that fragment is actually have this Activity. 
             *     Because when your webview is loading you are calling this function:
             * */
            if (activity == null)
                return;
            activity.setTitle("Loading..." + progress + "%");
            activity.setProgress(progress * 100);
            if (progress == 100) {
                activity.setTitle(R.string.app_name);
                webView.setVisibility(View.VISIBLE);
            }
        }
    });
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Toast("shouldOverrideUrlLoading");
            view.loadUrl(url);
            return true;
        }
    });
    //??
    WebSettings webSettings = webView.getSettings();
    //?
    //webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //?js
    webSettings.setJavaScriptEnabled(true);
    //? ?
    webSettings.setUseWideViewPort(false); //??
    webSettings.setLoadWithOverviewMode(true); // ??
    webView.loadUrl("http://anxpp.com");
    //
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //trueWebViewfalse??
            view.loadUrl(url);
            return true; //false?
        }
    });
    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { // ?
                    webView.goBack(); //?
                    return true; //?
                }
            }
            return false;
        }
    });
}

From source file:com.example.administrator.mywebviewdrawsign.SysWebView.java

/**
 * Initialize webview./*w w  w  . ja  va  2  s.  c  o  m*/
 */
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
private void setup() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(true);
    this.setHorizontalScrollBarEnabled(true);
    this.requestFocusFromTouch();
    // Enable JavaScript
    WebSettings settings = this.getSettings();

    settings.setBuiltInZoomControls(false);// ??
    settings.setUseWideViewPort(false);
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    settings.setAllowFileAccess(true);
    settings.setAppCacheMaxSize(1024 * 1024 * 32);
    settings.setAppCachePath(mContext.getFilesDir().getPath() + "/cache");
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    // Set Cache Mode: LOAD_NO_CACHE is noly for debug
    //settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //enablePageCache(settings,5);
    //enableWorkers(settings);

    // Enable database
    settings.setDatabaseEnabled(true);
    String databasePath = mContext.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Improve render performance
    settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

    if (Build.VERSION.SDK_INT >= 21) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
}

From source file:it.rignanese.leo.slimfacebook.MessagesActivity.java

private void SetupMessagesWebView() {
    webViewMessages = (AdvancedWebView) findViewById(R.id.webViewMessages);
    webViewMessages.setListener(this, this);
    webViewMessages.addPermittedHostname("mbasic.facebook.com");

    WebSettings settings = webViewMessages.getSettings();
    webViewMessages.setDesktopMode(false);

    webViewMessages.requestFocus(View.FOCUS_DOWN);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//remove the keyboard issue

    //set text zoom
    int zoom = Integer.parseInt(savedPreferences.getString("pref_textSize", "100"));
    settings.setTextZoom(zoom);/*from ww  w. j  a  v a2s .c om*/

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(false);
    settings.setLoadWithOverviewMode(false);

    // better image sizing support
    settings.setSupportZoom(false);
    settings.setDisplayZoomControls(false);
    settings.setBuiltInZoomControls(false);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }
}