List of usage examples for android.webkit WebSettings setUseWideViewPort
public abstract void setUseWideViewPort(boolean use);
From source file:com.jio.mhood.services.api.settings.LicensesFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override//from w ww .j av a2 s. c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_licenses, container, false); if (mWebView == null) { mWebView = new WebView(view.getContext()); mWebView.setLayoutParams( new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mWebView.setWebChromeClient(new WebChromeClient()); mWebView.setBackgroundColor(0); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setPluginState(PluginState.ON_DEMAND); webSettings.setPluginState(PluginState.ON); webSettings.setBuiltInZoomControls(true); webSettings.setUseWideViewPort(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { webSettings.setDisplayZoomControls(false); } mWebView.loadUrl(URL); } else { mParent.removeView(mWebView); } mParent = view; mParent.addView(mWebView); return mParent; }
From source file:com.github.snowdream.android.app.books.BookFragment.java
private void initUI(View rootview) { webView = (WebView) rootview.findViewById(R.id.webView); // progressbar = (SmoothProgressBar) rootview.findViewById(R.id.progressbar); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setSupportZoom(true);//from w w w .j av a 2s . c om webSettings.setBuiltInZoomControls(true); webSettings.setUseWideViewPort(true); String appCachePath = getActivity().getApplicationContext().getCacheDir().getAbsolutePath(); webSettings.setAppCachePath(appCachePath); webSettings.setAppCacheEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); // progressbar.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // progressbar.setVisibility(View.INVISIBLE); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); // progressbar.setVisibility(View.INVISIBLE); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); // The "loadAdOnCreate" and "testDevices" XML attributes no longer available. AdView adView = (AdView) rootview.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice(TEST_DEVICE_ID).build(); adView.loadAd(adRequest); getView().setFocusableInTouchMode(true); getView().setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (webView.canGoBack() && keyCode == KeyEvent.KEYCODE_BACK) { webView.goBack(); return true; } return false; } }); }
From source file:com.btmura.android.reddit.app.LoginFragment.java
private void setupWebView() { // Clear reddit cookie to present a fresh login form. CookieManager.getInstance().setCookie(".reddit.com", "reddit_session="); WebSettings settings = webView.getSettings(); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setLoadWithOverviewMode(true); settings.setSupportZoom(true);/* www . ja v a2s. c om*/ settings.setUseWideViewPort(true); // Don't save usernames entered into the login forms. settings.setSaveFormData(false); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (progressBar != null) { progressBar.setVisibility(View.VISIBLE); } } @Override public void onPageFinished(WebView view, String url) { if (progressBar != null) { progressBar.setVisibility(View.GONE); } } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // WebView will show an unrecognized scheme error unless we intercept // the OAuth callback URL and fire off an intent instead. return url != null && url.startsWith(Urls.OAUTH_REDIRECT_URL) && handleOAuthRedirectUrl(url); } }); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (progressBar != null) { progressBar.setProgress(newProgress); } } }); }
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 ww .ja v a 2 s . c o m * ?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: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); 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); }// w w w. j a v a 2 s .com // Enable remote debugging via chrome://inspect if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } }
From source file:com.cihon.androidrestart_keven.activity.CarNumActivity.java
/** * webview/*from w ww . j a v a 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: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);/* www. j a v a 2s .c om*/ 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.sonnychen.aviationhk.views.BookingFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override/* www . j a va2 s .com*/ 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 va 2 s. com*/ 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:cn.zy.ef.fragment.WebViewFragment.java
protected void configureWebView(WebSettings settings) { settings.setJavaScriptCanOpenWindowsAutomatically(true);//js??window.open()false settings.setJavaScriptEnabled(true);//??jsfalsetrue????XSS? settings.setSupportZoom(true);//??true settings.setBuiltInZoomControls(false);//?false settings.setUseWideViewPort(true);//??? settings.setLoadWithOverviewMode(true);//setUseWideViewPort(true) settings.setAppCacheEnabled(true);//? settings.setDomStorageEnabled(true);//DOM Storage settings.setCacheMode(WebSettings.LOAD_DEFAULT); }