Example usage for android.webkit WebSettings setSupportZoom

List of usage examples for android.webkit WebSettings setSupportZoom

Introduction

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

Prototype

public abstract void setSupportZoom(boolean support);

Source Link

Document

Sets whether the WebView should support zooming using its on-screen zoom controls and gestures.

Usage

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);
    settings.setPluginState(PluginState.ON_DEMAND);
    settings.setUseWideViewPort(true);/*from   w ww.java  2  s. c o m*/

    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:com.cihon.androidrestart_keven.activity.CarNumActivity.java

/**
 * webview//from  www  . j ava 2s  . 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:org.jsharkey.oilcan.BrowserActivity.java

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    requestWindowFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.act_browse);

    scriptdb = new ScriptDatabase(this);
    scriptdb.onUpgrade(scriptdb.getWritableDatabase(), -10, 10);

    webview = (WebView) findViewById(R.id.browse_webview);

    WebSettings settings = webview.getSettings();
    settings.setSavePassword(false);//  w  ww  . j a  v  a2 s .c o  m
    settings.setSaveFormData(false);
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

    FrameLayout zoomholder = (FrameLayout) this.findViewById(R.id.browse_zoom);
    zoomholder.addView(webview.getZoomControls());
    webview.getZoomControls().setVisibility(View.GONE);

    webview.setWebViewClient(new OilCanClient());
    webview.setWebChromeClient(new OilCanChrome());

    webview.addJavascriptInterface(new IntentHelper(), "intentHelper");

    // load the last-viewed page into browser
    String url = "http://m.half.com/";
    if (icicle != null && icicle.containsKey(LAST_VIEWED))
        url = icicle.getString(LAST_VIEWED);

    // or watch for incoming requested urls
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey(SearchManager.QUERY))
        url = getIntent().getStringExtra(SearchManager.QUERY);

    webview.loadUrl(url);

}

From source file:net.evecom.androidecssp.base.BaseWebActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    temp = HttpUtil.getPageSize(this);
    setContentView(R.layout.message_post_web);
    // dialog = ProgressDialog.show(BaseWebActivity.this, null,
    // "..");//from  ww w  .j  av a2  s.  c  om
    // dialog.setCancelable(true);

    lineProgressBar = (ProgressBar) findViewById(R.id.webview_progress_id);
    imageView = (ImageView) findViewById(R.id.image_view_at_web);
    webView = (WebView) this.findViewById(R.id.wv_oauth_message);
    CookieSyncManager.createInstance(this);
    CookieSyncManager.getInstance().startSync();
    CookieManager.getInstance().removeSessionCookie();

    webView.setWebViewClient(new BaseWebViewClient((BaseWebActivity) instance));
    webView.setWebChromeClient(new BaseChromeClient((BaseWebActivity) instance));

    // 
    webView.setDownloadListener(new MyWebViewDownLoadListener());
    WebSettings webSettings = webView.getSettings();
    webSettings.setSupportZoom(true);
    // WebViewJavaScript
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setBuiltInZoomControls(true);// support zoom
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    /**  */
    // //
    webSettings.setDatabaseEnabled(true);
    String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    // 
    webSettings.setGeolocationEnabled(true);
    // 
    webSettings.setGeolocationDatabasePath(dir);
    // 
    webSettings.setDomStorageEnabled(true);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int mDensity = metrics.densityDpi;
    if (mDensity == 240) {
        webSettings.setDefaultZoom(ZoomDensity.FAR);
    } else if (mDensity == 160) {
        webSettings.setDefaultZoom(ZoomDensity.MEDIUM);
    } else if (mDensity == 120) {
        webSettings.setDefaultZoom(ZoomDensity.CLOSE);
        // }else if(mDensity == DisplayMetrics..DENSITY_XHIGH){
        // webSettings.setDefaultZoom(ZoomDensity.FAR);
    } else if (mDensity == DisplayMetrics.DENSITY_HIGH) {
        webSettings.setDefaultZoom(ZoomDensity.FAR);
    }

    dialogPress = new AlertDialog.Builder(this).setTitle("").setMessage(":0/0")
            .setPositiveButton("", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();

    webView.addJavascriptInterface(new JsInterface(getApplicationContext()), "androidbase");
    String url = HttpUtil.getPCURL() + "jfs/mobile/androidIndex/jqmobileTest";
    // post
    // webView.postUrl(url, postData) postDatabyte[] 
    // EncodingUtils.getBytes("&pwd=888", charset)
    webView.postUrl(url, EncodingUtils.getBytes("", "BASE64"));

}

From source file:com.antew.redditinpictures.library.ui.ImageViewerFragment.java

public void initializeWebView() {
    assert mWebView != null : "WebView should not be null!";

    WebSettings settings = mWebView.getSettings();
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);/*from  w w  w.  j  a  v  a 2  s. c  om*/
    settings.setDisplayZoomControls(false);
    // Before loading the actual content, let's let the WebView initialize everything.
    mWebView.loadData("<html></html>", "text/html", "utf-8");

    mWebView.setBackgroundColor(Color.BLACK);
    mWebView.setWebViewClient(new WebViewClient() {
        /**
         * Notify the host application that a page has finished loading. This method
         * is called only for main frame. When onPageFinished() is called, the
         * rendering picture may not be updated yet. To get the notification for the
         * new Picture, use {@link android.webkit.WebView.PictureListener#onNewPicture}.
         *
         * @param view
         *     The WebView that is initiating the callback.
         * @param url
         *     The url of the page.
         */
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            // We first initialize the webview with mostly blank HTML content, so don't want to show it until we get to the image.
            if (mWebView != null && mWebViewInitialized) {
                mWebView.setVisibility(View.VISIBLE);
            } else if (!mWebViewInitialized) {
                mWebViewInitialized = true;
            }
        }
    });
    mWebView.setOnTouchListener(getWebViewOnTouchListener());
}

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 . ja va 2s . c om
    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:au.com.wallaceit.reddinator.TabCommentsFragment.java

@SuppressLint({ "SetJavaScriptEnabled", "AddJavascriptInterface" })
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this.getActivity();
    SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    global = (GlobalObjects) mContext.getApplicationContext();
    final boolean load = getArguments().getBoolean("load");

    // get needed activity values
    articleId = getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_ID);
    permalink = getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_PERMALINK);

    ll = new LinearLayout(mContext);
    ll.setLayoutParams(new WebView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 0, 0));
    // fixes for webview not taking keyboard input on some devices
    mWebView = new WebView(mContext);
    mWebView.setLayoutParams(new WebView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 0, 0));
    ll.addView(mWebView);//from   w ww  .  j  av a  2 s.c  o m
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true); // enable ecmascript
    webSettings.setDomStorageEnabled(true); // some video sites require dom storage
    webSettings.setSupportZoom(false);
    webSettings.setBuiltInZoomControls(false);
    webSettings.setDisplayZoomControls(false);
    int fontSize = Integer.parseInt(mSharedPreferences.getString("commentfontpref", "18"));
    webSettings.setDefaultFontSize(fontSize);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    mSharedPreferences.getString("titlefontpref", "16");

    final String themeStr = global.mThemeManager.getActiveTheme("appthemepref").getValuesString();
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            boolean redditLink = false;
            System.out.println(url);
            if (url.indexOf("file://") == 0) { // fix for short sub and user links
                url = url.replace("file://", "https://www.reddit.com") + "/.compact";
                redditLink = true;
            }
            if (redditLink || url.indexOf("https://www.reddit.com/") == 0) {
                Intent i = new Intent(mContext, WebViewActivity.class);
                i.putExtra("url", url);
                startActivity(i);
            } else {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(i);
            }
            return true; // always override url
        }

        public void onPageFinished(WebView view, String url) {
            mWebView.loadUrl("javascript:init(\"" + StringEscapeUtils.escapeJavaScript(themeStr) + "\", \""
                    + global.mRedditData.getUsername() + "\")");
            if (load)
                load();
        }
    });
    mWebView.setWebChromeClient(new WebChromeClient());

    mWebView.requestFocus(View.FOCUS_DOWN);
    WebInterface webInterface = new WebInterface(mContext);
    mWebView.addJavascriptInterface(webInterface, "Reddinator");

    mWebView.loadUrl("file:///android_asset/comments.html#" + articleId);
}

From source file:com.owncloud.android.ui.activity.ExternalSiteWebView.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log_OC.v(TAG, "onCreate() start");

    Bundle extras = getIntent().getExtras();
    String title = extras.getString(EXTRA_TITLE);
    String url = extras.getString(EXTRA_URL);
    menuItemId = extras.getInt(EXTRA_MENU_ITEM_ID);
    showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR);

    // show progress
    getWindow().requestFeature(Window.FEATURE_PROGRESS);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.externalsite_webview);

    WebView webview = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = webview.getSettings();

    webview.setFocusable(true);//from   w  ww.  j ava 2  s . c  om
    webview.setFocusableInTouchMode(true);
    webview.setClickable(true);

    // setup toolbar
    setupToolbar();

    // setup drawer
    setupDrawer(menuItemId);

    if (!showSidebar) {
        setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }

    getSupportActionBar().setTitle(title);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // enable zoom
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    // Non-responsive webs are zoomed out when loaded
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);

    // user agent
    webSettings.setUserAgentString(MainApp.getUserAgent());

    // no private data storing
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);

    // disable local file access
    webSettings.setAllowFileAccess(false);

    // enable javascript
    webview.getSettings().setJavaScriptEnabled(true);

    final Activity activity = this;
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);

    webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            progressBar.setProgress(progress * 1000);
        }
    });

    webview.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, getString(R.string.webview_error) + ": " + description, Toast.LENGTH_SHORT)
                    .show();
        }
    });

    webview.loadUrl(url);
}

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 w  ww  .j a  v a 2  s  .co m

    // 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);
    }
}

From source file:net.evecom.android.web.Web5Activity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    temp = HttpUtil.getPageSize(this);
    setContentView(R.layout.message_post_web);
    imageView = (ImageView) findViewById(R.id.image_view_at_web);
    webView = (WebView) this.findViewById(R.id.wv_oauth_message);
    CookieSyncManager.createInstance(this);
    CookieSyncManager.getInstance().startSync();
    CookieManager.getInstance().removeSessionCookie();
    /**//from  ww w.  j  av  a2s  . c  o m
     * WebViewJavaScript
     */
    webView.getSettings().setJavaScriptEnabled(true);

    /**
     * loadUrl()
     */
    webView.setWebViewClient(new HelloWebViewClient());
    dialog = ProgressDialog.show(Web5Activity.this, null, "..");
    dialog.setCancelable(true);
    // http://harlan-pc/fzaj/emergency/mobileWebApp/publicInfo/login.do?userName=zf1&userPwd=1
    // webView.loadUrl("http://www.baidu.com");
    // String url = HttpUtil.BASE_PC_URL
    // + "/buildingController/login"; http://harlan-pc/gssms/mobile/
    // String url =HttpUtil.BASE_PC_URL+"/loginController/countLogin";
    String url = HttpUtil.BASE_PC_URL + "mobile/loginController/countLogin";
    // post
    // String postDate = "loginname=sysadmin&pwd=888888";
    String postDate = "loginname=" + ShareUtil.getString(getApplicationContext(), "SESSION", "USERNAME", "")
            + "&pwd=" + ShareUtil.getString(getApplicationContext(), "SESSION", "PASSWORD", "") + "&pageSize="
            + temp;
    // EncodingUtils.getBytes(data, charset)
    webView.postUrl(url, EncodingUtils.getBytes(postDate, "BASE64"));
    // 
    webView.setDownloadListener(new MyWebViewDownLoadListener());
    WebSettings webSettings = webView.getSettings();
    webSettings.setSupportZoom(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setBuiltInZoomControls(true);// support zoom
    // webSettings.setPluginsEnabled(true);//support flash
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    // webSettings.setPluginsEnabled(true); //(flash)

    /**  */
    // //
    webSettings.setDatabaseEnabled(true);
    String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    // 
    webSettings.setGeolocationEnabled(true);
    // 
    webSettings.setGeolocationDatabasePath(dir);
    // 
    webSettings.setDomStorageEnabled(true);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int mDensity = metrics.densityDpi;
    // DebugLog.d(TAG, "densityDpi = " + mDensity);
    if (mDensity == 240) {
        webSettings.setDefaultZoom(ZoomDensity.FAR);
    } else if (mDensity == 160) {
        webSettings.setDefaultZoom(ZoomDensity.MEDIUM);
    } else if (mDensity == 120) {
        webSettings.setDefaultZoom(ZoomDensity.CLOSE);
        // }else if(mDensity == DisplayMetrics..DENSITY_XHIGH){
        // webSettings.setDefaultZoom(ZoomDensity.FAR);
    } else if (mDensity == DisplayMetrics.DENSITY_HIGH) {
        webSettings.setDefaultZoom(ZoomDensity.FAR);
    }
    webView.setWebChromeClient(m_chromeClient);// (flash)

    dialogPress = new AlertDialog.Builder(this).setTitle("").setMessage(":0/0")
            .setPositiveButton("", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
}