Java Code Examples for android.webkit.WebSettings#setLoadsImagesAutomatically()
The following examples show how to use
android.webkit.WebSettings#setLoadsImagesAutomatically() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebActivity.java From Musicoco with Apache License 2.0 | 6 votes |
private void initWebView() { WebSettings webSettings = webView.getSettings(); // webSettings.setJavaScriptEnabled(true); webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小 webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小 webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。 webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放 webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件 webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存 webSettings.setAllowFileAccess(true); //设置可以访问文件 webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口 webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片 webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式 }
Example 2
Source File: WebViewFragment.java From NestedTouchScrollingLayout with MIT License | 6 votes |
private void initWebSettings() { WebSettings settings = this.mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setSupportZoom(false); settings.setDisplayZoomControls(false); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); settings.supportMultipleWindows(); settings.setSupportMultipleWindows(true); settings.setDomStorageEnabled(true); settings.setDatabaseEnabled(true); settings.setAppCacheEnabled(true); settings.setAppCachePath(this.mWebView.getContext().getCacheDir().getAbsolutePath()); settings.setAllowFileAccess(true); settings.setLoadsImagesAutomatically(true); settings.setDefaultTextEncodingName("UTF-8"); }
Example 3
Source File: BrowseActivity.java From AndroidDownload with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setTopBarTitle("详情页面"); Intent getIntent = getIntent(); btUrl=getIntent.getStringExtra("url"); lt = new LoadToast(this); webView.setWebChromeClient(new MyWebChromeClient()); WebSettings webSettings = webView.getSettings(); webSettings.setAppCacheEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.supportMultipleWindows(); webSettings.setAllowContentAccess(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); webSettings.setSavePassword(true); webSettings.setSaveFormData(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setLoadsImagesAutomatically(true); webSettings.setJavaScriptEnabled(false); webView.setWebViewClient(new WebViewClient()); webView.loadUrl(btUrl); lt.setTranslationY(200).setBackgroundColor(getResources().getColor(R.color.colorMain)).setProgressColor(getResources().getColor(R.color.white)); lt.show(); }
Example 4
Source File: CommonWebView.java From ZhuanLan with Apache License 2.0 | 6 votes |
private void init() { if (isInEditMode()) { return; } WebSettings settings = getSettings(); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(false); //设置缓存模式 settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //开启DOM storage API功能 settings.setDomStorageEnabled(true); //开启database storage 功能 settings.setDatabaseEnabled(true); String cacheDir = getContext().getFilesDir().getAbsolutePath() + "web_cache"; settings.setAppCachePath(cacheDir); settings.setAppCacheEnabled(true); settings.setLoadsImagesAutomatically(true); settings.setDefaultTextEncodingName(ENCODING_UTF_8); settings.setBlockNetworkImage(false); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); setHorizontalScrollBarEnabled(false); }
Example 5
Source File: DetailFragment.java From WanAndroid with Apache License 2.0 | 6 votes |
private void loadUrl(String url){ agentWeb = AgentWeb.with(this) .setAgentWebParent(webViewContainer, new FrameLayout.LayoutParams(-1, -1)) .useDefaultIndicator() .createAgentWeb() .ready() .go(url); WebView webView = agentWeb.getWebCreator().getWebView(); WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setUseWideViewPort(true); settings.setLoadsImagesAutomatically(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); }
Example 6
Source File: WebViewFragment.java From Xndroid with GNU General Public License v3.0 | 6 votes |
private void setWebView() { WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true);//如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小 webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小 webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。 webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放 webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件 webSettings.setAllowFileAccess(true); //设置可以访问文件 webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口 webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片 webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式 webSettings.setDomStorageEnabled(true); mWebView.setWebViewClient(new WebViewClient()); }
Example 7
Source File: SubscriptionDetailsFragment.java From redgram-for-reddit with GNU General Public License v3.0 | 5 votes |
private void setupWebViewSettings() { final WebSettings webSettings = subredditDesc.getSettings(); Resources res = getResources(); float fontSize = res.getDimension(R.dimen.web_text); webSettings.setDefaultFontSize((int) fontSize); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); webSettings.setAppCacheEnabled(false); webSettings.setBlockNetworkImage(true); webSettings.setLoadsImagesAutomatically(true); webSettings.setGeolocationEnabled(false); webSettings.setNeedInitialFocus(false); webSettings.setSaveFormData(false); }
Example 8
Source File: PrettifyWebView.java From mvvm-template with GNU General Public License v3.0 | 5 votes |
@SuppressLint("SetJavaScriptEnabled") private void initView(@Nullable AttributeSet attrs) { if (isInEditMode()) return; if (attrs != null) { TypedArray tp = getContext().obtainStyledAttributes(attrs, R.styleable.PrettifyWebView); try { int color = tp.getColor(R.styleable.PrettifyWebView_webview_background, ViewHelper.getWindowBackground(getContext())); setBackgroundColor(color); } finally { tp.recycle(); } } setWebChromeClient(new ChromeClient()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { setWebViewClient(new WebClient()); } else { setWebViewClient(new WebClientCompat()); } WebSettings settings = getSettings(); settings.setJavaScriptEnabled(true); settings.setAppCachePath(getContext().getCacheDir().getPath()); settings.setAppCacheEnabled(true); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); settings.setDefaultTextEncodingName("utf-8"); settings.setLoadsImagesAutomatically(true); settings.setBlockNetworkImage(false); setOnLongClickListener((view) -> { WebView.HitTestResult result = getHitTestResult(); if (hitLinkResult(result) && !InputHelper.isEmpty(result.getExtra())) { AppHelper.copyToClipboard(getContext(), result.getExtra()); return true; } return false; }); }
Example 9
Source File: WebViewFragment.java From Bitocle with Apache License 2.0 | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setContentView(R.layout.webview_fragment); setContentShown(true); View view = getContentView(); webView = (WebView) view.findViewById(R.id.webview_fragment); /* Do something */ WebSettings webSettings = webView.getSettings(); webSettings.setBuiltInZoomControls(true); webSettings.setJavaScriptEnabled(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS.NORMAL); webSettings.setLoadWithOverviewMode(true); webSettings.setLoadsImagesAutomatically(true); webSettings.setSupportMultipleWindows(true); webSettings.setSupportZoom(true); webSettings.setUseWideViewPort(true); SharedPreferences sharedPreferences = getActivity().getSharedPreferences(getString(R.string.login_sp), Context.MODE_PRIVATE); String oAuth = sharedPreferences.getString(getString(R.string.login_sp_oauth), null); gitHubClient = new GitHubClient(); gitHubClient.setOAuth2Token(oAuth); Intent intent = getActivity().getIntent(); repoOwner = intent.getStringExtra(getString(R.string.content_intent_repoowner)); repoName = intent.getStringExtra(getString(R.string.content_intent_reponame)); fileName = intent.getStringExtra(getString(R.string.content_intent_filename)); sha = intent.getStringExtra(getString(R.string.content_intent_sha)); webViewTask = new WebViewTask(WebViewFragment.this); webViewTask.execute(); }
Example 10
Source File: WebViewFragment.java From Bitocle with Apache License 2.0 | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setContentView(R.layout.webview_fragment); setContentEmpty(false); setContentShown(true); View view = getContentView(); webView = (WebView) view.findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setLoadsImagesAutomatically(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS.NORMAL); webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); webSettings.setDisplayZoomControls(false); SharedPreferences preferences = getActivity().getSharedPreferences(getString(R.string.login_sp), Context.MODE_PRIVATE); String OAuth = preferences.getString(getString(R.string.login_sp_oauth), null); client = new GitHubClient(); client.setOAuth2Token(OAuth); Intent intent = getActivity().getIntent(); owner = intent.getStringExtra(getString(R.string.webview_intent_owner)); name = intent.getStringExtra(getString(R.string.webview_intent_name)); sha = intent.getStringExtra(getString(R.string.webview_intent_sha)); filename = intent.getStringExtra(getString(R.string.webview_intent_title)); task = new WebViewTask(WebViewFragment.this); task.execute(); }
Example 11
Source File: WebPageActivity.java From TigerVideo with Apache License 2.0 | 5 votes |
private void configWebView() { WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setLoadsImagesAutomatically(true); mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); mWebView.setWebViewClient(mWebViewClient); mWebView.setWebChromeClient(mWebChromeClient); }
Example 12
Source File: MyWebView.java From DoraemonKit with Apache License 2.0 | 4 votes |
private void init(Context context) { if (!(context instanceof Activity)) { throw new RuntimeException("only support Activity context"); } else { this.mContainerActivity = (Activity) context; WebSettings webSettings = this.getSettings(); webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(false); webSettings.setLoadsImagesAutomatically(true); webSettings.setUseWideViewPort(true); webSettings.setBuiltInZoomControls(false); webSettings.setDefaultTextEncodingName("UTF-8"); webSettings.setDomStorageEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setJavaScriptCanOpenWindowsAutomatically(false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setWebContentsDebuggingEnabled(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webSettings.setMixedContentMode(0); } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { this.removeJavascriptInterface("searchBoxJavaBridge_"); this.removeJavascriptInterface("accessibilityTraversal"); this.removeJavascriptInterface("accessibility"); } mMyWebViewClient = new MyWebViewClient(); this.setWebViewClient(mMyWebViewClient); this.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress < 100) { showLoadProgress(newProgress); } else { hideLoadProgress(); } } }); addProgressView(); } }
Example 13
Source File: KCWebView.java From kerkee_android with GNU General Public License v3.0 | 4 votes |
/** * @param aWebView * **/ public static void setupWebViewAttributes(KCWebView aWebView) { try { WebSettings webSettings = aWebView.getSettings(); setCustomizedUA(webSettings); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } webSettings.setJavaScriptEnabled(true); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); webSettings.setBuiltInZoomControls(false); webSettings.setSupportZoom(true); webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); webSettings.setAppCachePath(aWebView.getWebPath().getRootPath() + "/webcache"); webSettings.setAppCacheEnabled(true); // webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); webSettings.setLoadsImagesAutomatically(true); webSettings.setLightTouchEnabled(false); webSettings.setDomStorageEnabled(true); // supports local storage webSettings.setDatabaseEnabled(true); // supports local storage webSettings.setDatabasePath(aWebView.getWebPath().getRootPath() + "/localstorage"); // we are using ApplicationContext when creaing KCWebView, without disabling the "Save Password" dialog // there will be an exception that would cause crash: "Unable to add window -- token null is not for an application" webSettings.setSavePassword(false); aWebView.setHorizontalScrollBarEnabled(false); // mWebView.setVerticalScrollBarEnabled(false); aWebView.setScrollbarFadingEnabled(true); aWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); } catch (Exception e) { KCLog.e(e); } }
Example 14
Source File: WebPlayerView.java From unity-ads-android with Apache License 2.0 | 4 votes |
public WebPlayerView(Context context, String viewId, JSONObject webSettings, JSONObject webPlayerSettings) { super(context); this.viewId = viewId; WebSettings settings = getSettings(); if(Build.VERSION.SDK_INT >= 16) { settings.setAllowFileAccessFromFileURLs(false); settings.setAllowUniversalAccessFromFileURLs(false); } if (Build.VERSION.SDK_INT >= 19) { try { _evaluateJavascript = WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class); } catch(NoSuchMethodException e) { DeviceLog.exception("Method evaluateJavascript not found", e); _evaluateJavascript = null; } } settings.setAppCacheEnabled(false); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); settings.setDatabaseEnabled(false); settings.setDomStorageEnabled(false); settings.setGeolocationEnabled(false); settings.setJavaScriptEnabled(true); settings.setLoadsImagesAutomatically(true); settings.setPluginState(WebSettings.PluginState.OFF); settings.setRenderPriority(WebSettings.RenderPriority.NORMAL); settings.setSaveFormData(false); settings.setSavePassword(false); setHorizontalScrollBarEnabled(false); setVerticalScrollBarEnabled(false); setInitialScale(0); setBackgroundColor(Color.TRANSPARENT); ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT)); setBackgroundResource(0); setSettings(webSettings, webPlayerSettings); setWebViewClient(new WebPlayerClient()); setWebChromeClient(new WebPlayerChromeClient()); setDownloadListener(new WebPlayerDownloadListener()); addJavascriptInterface(new WebPlayerBridgeInterface(viewId), "webplayerbridge"); WebPlayerViewCache.getInstance().addWebPlayer(viewId, this); this.subscribeOnLayoutChange(); }
Example 15
Source File: WebSettingsCompat.java From Android_Skin_2.0 with Apache License 2.0 | 4 votes |
@Override public void setLoadsImagesAutomatically(WebSettings settings, boolean flag) { settings.setLoadsImagesAutomatically(flag); }
Example 16
Source File: WebViewActivity.java From YCAudioPlayer with Apache License 2.0 | 4 votes |
@SuppressLint("JavascriptInterface") private void initWebView() { WebSettings ws = mWebView.getSettings(); // 网页内容的宽度是否可大于WebView控件的宽度 ws.setLoadWithOverviewMode(false); // 保存表单数据 ws.setSaveFormData(true); // 是否应该支持使用其屏幕缩放控件和手势缩放 ws.setSupportZoom(true); ws.setBuiltInZoomControls(true); ws.setDisplayZoomControls(false); // 启动应用缓存 ws.setAppCacheEnabled(true); // 设置缓存模式 ws.setCacheMode(WebSettings.LOAD_DEFAULT); // setDefaultZoom api19被弃用 // 设置此属性,可任意比例缩放。 ws.setUseWideViewPort(true); // 缩放比例 1 mWebView.setInitialScale(1); // 告诉WebView启用JavaScript执行。默认的是false。 ws.setJavaScriptEnabled(true); //如果启用了JavaScript,要做好安全措施,防止远程执行漏洞 removeJavascriptInterfaces(mWebView); // 页面加载好以后,再放开图片 ws.setBlockNetworkImage(false); // 使用localStorage则必须打开 ws.setDomStorageEnabled(true); //自动加载图片 ws.setLoadsImagesAutomatically(true); // 排版适应屏幕 ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); // WebView是否支持多个窗口。 ws.setSupportMultipleWindows(true); // webView从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } /*设置字体默认缩放大小(改变网页字体大小,setTextSize api14被弃用)*/ ws.setTextZoom(100); //在js中调用本地java方法 jsAppInterface = new JsAppInterface(this, mWebView); jsAppInterface.register(); mWebView.addJavascriptInterface(jsAppInterface, "WebViewJsMethodName"); mWebView.addJavascriptInterface(new JavascriptInterface(this), "injectedObject"); mWebView.setWebViewClient(new MyWebViewClient()); mWebView.setWebChromeClient(webChromeClient = new MyWebChromeClient()); mWebView.setScrollWebListener(new ScrollWebView.OnScrollWebListener() { @Override public void onScroll(int dx, int dy) { //WebView的总高度 float webViewContentHeight = mWebView.getContentHeight() * mWebView.getScale(); //WebView的现高度 float webViewCurrentHeight = (mWebView.getHeight() + mWebView.getScrollY()); LogUtils.e("webViewContentHeight=" + webViewContentHeight); LogUtils.e("webViewCurrentHeight=" + webViewCurrentHeight); if ((webViewContentHeight - webViewCurrentHeight) == 0) { LogUtils.e("WebView滑动到了底端"); } } }); }
Example 17
Source File: BitWebViewFragment.java From tysq-android with GNU General Public License v3.0 | 4 votes |
private void initWebViewSetting(WebSettings settings) { //支持js脚本 settings.setJavaScriptEnabled(true); //支持缩放 settings.setSupportZoom(true); //支持缩放 settings.setBuiltInZoomControls(true); //去除缩放按钮 settings.setDisplayZoomControls(false); //扩大比例的缩放 settings.setUseWideViewPort(true); //自适应屏幕 settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.setLoadWithOverviewMode(true); //多窗口 settings.supportMultipleWindows(); //关闭webview中缓存 settings.setCacheMode(WebSettings.LOAD_NO_CACHE); //设置可以访问文件 settings.setAllowFileAccess(true); //当webview调用requestFocus时为webview设置节点 settings.setNeedInitialFocus(true); //支持通过JS打开新窗口 settings.setJavaScriptCanOpenWindowsAutomatically(true); //支持自动加载图片 settings.setLoadsImagesAutomatically(true); //启用地理定位 // settings.setGeolocationEnabled(true); //设置渲染优先级 settings.setRenderPriority(WebSettings.RenderPriority.HIGH); // 设置支持本地存储 settings.setDatabaseEnabled(true); //设置支持DomStorage settings.setDomStorageEnabled(true); addJavascriptInterface(); }
Example 18
Source File: NoteDetailsActivity.java From DevHeadLine with Apache License 2.0 | 4 votes |
private void initVIew() { Observable.just(getResources().getString(R.string.notedetail_text_name)).map(new Func1<String, SpannableString>() { @Override public SpannableString call(String s) { SpannableString spanabelInfo = new SpannableString(s); int lenth = s.indexOf(getResources().getString(R.string.notedetail_hal)); spanabelInfo.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.colorPrimary)), lenth, lenth + getResources().getString(R.string.notedetail_halgyf).length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spanabelInfo; } }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()). subscribe(new Action1<SpannableString>() { @Override public void call(SpannableString spanableInfo) { textView.setText(spanableInfo); } }); showAnim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.bottom_show); dismissAnim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.bottom_dismiss); WebSettings webSettings = webView.getSettings(); //先加载文字后加载图片 if (Build.VERSION.SDK_INT >= 19) { webSettings.setLoadsImagesAutomatically(true); } else { webSettings.setLoadsImagesAutomatically(false); } webSettings.setJavaScriptEnabled(true); webSettings.setDefaultTextEncodingName("UTF-8"); webSettings.setSupportZoom(false); webSettings.setUseWideViewPort(false); // webSettings.setBlockNetworkImage(true); // if (Build.VERSION.SDK_INT < 19) { // webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); // } webSettings.setLoadWithOverviewMode(true); webView.setWebViewClient(new MyWebViewClient()); webView.setWebChromeClient(new MyWebChromeClient()); loadingUrl = getIntent().getStringExtra(ORIGINAL_URL); webView.loadUrl(loadingUrl); webView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: downY = (int) event.getY(); break; case MotionEvent.ACTION_MOVE: int moveY = (int) event.getY(); offsetY = moveY - downY; downY = moveY; break; case MotionEvent.ACTION_UP: if (offsetY < 0) { onScrollToBottom(); } else { onScrollToTop(); } break; } return false; } }); }
Example 19
Source File: Html5Activity.java From ClassSchedule with Apache License 2.0 | 4 votes |
@SuppressLint("JavascriptInterface") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web); mSmoothProgress = findViewById(R.id.smooth_progress); Bundle bundle = getIntent().getBundleExtra("bundle"); mUrl = bundle.getString("url"); mTitle = bundle.getString("title", ""); mJavaScriptInterface = bundle.getSerializable("javascript"); initBackToolbar(TextUtils.isEmpty(mTitle) ? "加载中" : mTitle); Log.d("Url:", mUrl); Log.d("mTitle:", mTitle); mLayout = (LinearLayout) findViewById(R.id.web_layout); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mWebView = new WebView(getApplicationContext()); mWebView.setLayoutParams(params); mLayout.addView(mWebView); WebSettings mWebSettings = mWebView.getSettings(); mWebSettings.setSupportZoom(true); mWebSettings.setLoadWithOverviewMode(true); mWebSettings.setUseWideViewPort(true); mWebSettings.setDefaultTextEncodingName("utf-8"); mWebSettings.setLoadsImagesAutomatically(true); //调用JS方法.安卓版本大于17,加上注解 @JavascriptInterface mWebSettings.setJavaScriptEnabled(true); if (mJavaScriptInterface != null) { mWebView.addJavascriptInterface(mJavaScriptInterface, "android"); } mWebView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { downloadByBrowser(url); } }); saveData(mWebSettings); newWin(mWebSettings); mWebView.setWebChromeClient(webChromeClient); mWebView.setWebViewClient(webViewClient); mWebView.loadUrl(mUrl); }
Example 20
Source File: MainActivity.java From SlimSocial-for-Facebook with GNU General Public License v2.0 | 4 votes |
private void SetupWebView() { webViewFacebook = findViewById(webView); webViewFacebook.setListener(this, this); webViewFacebook.clearPermittedHostnames(); webViewFacebook.addPermittedHostname("facebook.com"); webViewFacebook.addPermittedHostname("fbcdn.net"); webViewFacebook.addPermittedHostname("fb.com"); webViewFacebook.addPermittedHostname("fb.me"); /* webViewFacebook.addPermittedHostname("m.facebook.com"); webViewFacebook.addPermittedHostname("h.facebook.com"); webViewFacebook.addPermittedHostname("touch.facebook.com"); webViewFacebook.addPermittedHostname("mbasic.facebook.com"); webViewFacebook.addPermittedHostname("touch.facebook.com"); webViewFacebook.addPermittedHostname("messenger.com"); */ webViewFacebook.requestFocus(View.FOCUS_DOWN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//remove the keyboard issue WebSettings settings = webViewFacebook.getSettings(); webViewFacebook.setDesktopMode(true); settings.setUserAgentString("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); settings.setJavaScriptEnabled(true); //set text zoom int zoom = Integer.parseInt(savedPreferences.getString("pref_textSize", "100")); settings.setTextZoom(zoom); //set Geolocation settings.setGeolocationEnabled(savedPreferences.getBoolean("pref_allowGeolocation", true)); // Use WideViewport and Zoom out if there is no viewport defined settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); // better image sizing support settings.setSupportZoom(true); settings.setDisplayZoomControls(false); settings.setBuiltInZoomControls(true); // set caching settings.setAppCachePath(getCacheDir().getAbsolutePath()); settings.setAppCacheEnabled(true); settings.setLoadsImagesAutomatically(!savedPreferences.getBoolean("pref_doNotDownloadImages", false));//to save data settings.setDisplayZoomControls(false); }