Java Code Examples for android.webkit.WebView#setLayerType()
The following examples show how to use
android.webkit.WebView#setLayerType() .
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: AboutActivity.java From QuranAndroid with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); getSupportActionBar().setTitle(getString(R.string.about)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); progressBar = (ProgressBar) findViewById(R.id.progress); progressBar.getIndeterminateDrawable() .setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN); info_web = (WebView) findViewById(R.id.webview_company_info); info_web.setBackgroundColor(Color.TRANSPARENT); info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null); info_web.setWebViewClient(new myWebClient()); info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); info_web.getSettings().setJavaScriptEnabled(true); String infoText = getString(R.string.company_info_web); info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null); }
Example 2
Source File: AboutActivity.java From QuranAndroid with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); getSupportActionBar().setTitle(getString(R.string.about)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); progressBar = (ProgressBar) findViewById(R.id.progress); progressBar.getIndeterminateDrawable() .setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN); info_web = (WebView) findViewById(R.id.webview_company_info); info_web.setBackgroundColor(Color.TRANSPARENT); info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null); info_web.setWebViewClient(new myWebClient()); info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); info_web.getSettings().setJavaScriptEnabled(true); String infoText = getString(R.string.company_info_web); info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null); }
Example 3
Source File: AboutActivity.java From MuslimMateAndroid with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); getSupportActionBar().setTitle(getString(R.string.about)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); progressBar = (ProgressBar) findViewById(R.id.progress); progressBar.getIndeterminateDrawable() .setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN); info_web = (WebView) findViewById(R.id.webview_company_info); info_web.setBackgroundColor(Color.TRANSPARENT); info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null); info_web.setWebViewClient(new myWebClient()); info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); info_web.getSettings().setJavaScriptEnabled(true); info_web.getSettings().setDefaultFontSize((int) getResources().getDimension(R.dimen.about_text_size)); String infoText = getString(R.string.company_info_web); info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null); }
Example 4
Source File: MainActivity.java From Android-File-Chooser with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); verifyStoragePermissions(this); webView = (WebView) findViewById(R.id.webView); webSettings = webView.getSettings(); webSettings.setAppCacheEnabled(true); webSettings.setCacheMode(webSettings.LOAD_CACHE_ELSE_NETWORK); webSettings.setJavaScriptEnabled(true); webSettings.setLoadWithOverviewMode(true); webSettings.setAllowFileAccess(true); webView.setWebViewClient(new PQClient()); webView.setWebChromeClient(new PQChromeClient()); //if SDK version is greater of 19 then activate hardware acceleration otherwise activate software acceleration if (Build.VERSION.SDK_INT >= 19) { webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } else if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 19) { webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } webView.loadUrl("https://en.imgbb.com/"); }
Example 5
Source File: WebViewCache.java From tysq-android with GNU General Public License v3.0 | 5 votes |
public WebViewCache(Context context, String url, int size) { mWebViewList = new ArrayList<>(size); int width = ScreenAdapterUtils.getScreenWidth(); int height = ScreenAdapterUtils.getAdHeight(); for (int i = 0; i < DEFAULT_WEBVIEW_NUM; i++){ WebView webView = new WebView(context); webView.loadUrl(url); ViewGroup.LayoutParams layoutParams = webView.getLayoutParams(); if (layoutParams == null){ layoutParams = new ViewGroup.LayoutParams(width, height); } else { layoutParams.width = width; layoutParams.height = height; } webView.setLayoutParams(layoutParams); webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); webView.addJavascriptInterface(new TyJavaScriptInterface(context), "android"); mWebViewList.add(webView); } }
Example 6
Source File: Web3WebviewManager.java From react-native-web3-webview with MIT License | 5 votes |
@Override public void onPageFinished(WebView webView, String url) { super.onPageFinished(webView, url); if (!mLastLoadFailed) { Web3Webview Web3Webview = (Web3Webview) webView; Web3Webview.callInjectedJavaScript(); Web3Webview.setVerticalScrollBarEnabled(true); Web3Webview.setHorizontalScrollBarEnabled(true); webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); emitFinishEvent(webView, url); Web3Webview.linkBridge(); } }
Example 7
Source File: AboutDialog.java From UpdogFarmer with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final WebView webView = (WebView) LayoutInflater.from(getActivity()).inflate(R.layout.about_dialog, null); final String lang = Locale.getDefault().getLanguage(); String uri = "file:///android_asset/about.html"; try { // Load language-specific version of the about page if available. final List<String> assets = Arrays.asList(getResources().getAssets().list("")); if (assets.contains(String.format("about-%s.html", lang))) { uri = String.format("file:///android_asset/about-%s.html", lang); } } catch (IOException e) { e.printStackTrace(); } if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { // Getting Chromium crashes on certain KitKat devices. Might be caused by hardware acceleration webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } webView.loadUrl(uri); webView.setBackgroundColor(Color.TRANSPARENT); return new AlertDialog.Builder(getActivity()) .setTitle(R.string.about) .setView(webView) .setPositiveButton(R.string.ok, null) .create(); }
Example 8
Source File: BaseWebActivity.java From FwdPortForwardingApp with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.base_web_activity); // Set up toolbar final Toolbar toolbar = getActionBarToolbar(); setSupportActionBar(toolbar); toolbar.setNavigationIcon(R.drawable.ic_close_24dp); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); final WebView webView = (WebView) findViewById(R.id.help_webview); webView.setBackgroundColor(Color.TRANSPARENT); webView.setWebViewClient(new MyWebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAppCacheEnabled(false); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); // Hardware acceleration for web view webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); webView.loadUrl(url); }
Example 9
Source File: PersonInfoFinishedActivity.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
private void a() { WebView webview = (WebView)findViewById(0x7f0a0174); WebSettings websettings = webview.getSettings(); websettings.setUseWideViewPort(true); websettings.setLoadWithOverviewMode(true); webview.setLayerType(1, null); webview.loadUrl("file:///android_asset/set_finish.gif"); a.postDelayed(new j(this, webview), 1000L); }
Example 10
Source File: LoginActivity.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
private void c() { WebView webview = (WebView)findViewById(0x7f0a003b); WebSettings websettings = webview.getSettings(); websettings.setUseWideViewPort(true); websettings.setLoadWithOverviewMode(true); webview.setLayerType(1, null); webview.setBackgroundColor(0); webview.setInitialScale((100 * getResources().getDisplayMetrics().densityDpi) / 480); webview.loadUrl("file:///android_asset/startup.gif"); (new Handler()).postDelayed(new b(this), 4800L); C.setEnabled(false); r.setEnabled(false); s.setEnabled(false); }
Example 11
Source File: AbsAgentWebSettings.java From AgentWeb with Apache License 2.0 | 4 votes |
private void settings(WebView webView) { mWebSettings = webView.getSettings(); mWebSettings.setJavaScriptEnabled(true); mWebSettings.setSupportZoom(true); mWebSettings.setBuiltInZoomControls(false); mWebSettings.setSavePassword(false); if (AgentWebUtils.checkNetwork(webView.getContext())) { //根据cache-control获取数据。 mWebSettings.setCacheMode(WebSettings.LOAD_DEFAULT); } else { //没网,则从本地获取,即离线加载 mWebSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //适配5.0不允许http和https混合使用情况 mWebSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } mWebSettings.setTextZoom(100); mWebSettings.setDatabaseEnabled(true); mWebSettings.setAppCacheEnabled(true); mWebSettings.setLoadsImagesAutomatically(true); mWebSettings.setSupportMultipleWindows(false); // 是否阻塞加载网络图片 协议http or https mWebSettings.setBlockNetworkImage(false); // 允许加载本地文件html file协议 mWebSettings.setAllowFileAccess(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // 通过 file url 加载的 Javascript 读取其他的本地文件 .建议关闭 mWebSettings.setAllowFileAccessFromFileURLs(false); // 允许通过 file url 加载的 Javascript 可以访问其他的源,包括其他的文件和 http,https 等其他的源 mWebSettings.setAllowUniversalAccessFromFileURLs(false); } mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); } else { mWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); } mWebSettings.setLoadWithOverviewMode(false); mWebSettings.setUseWideViewPort(false); mWebSettings.setDomStorageEnabled(true); mWebSettings.setNeedInitialFocus(true); mWebSettings.setDefaultTextEncodingName("utf-8");//设置编码格式 mWebSettings.setDefaultFontSize(16); mWebSettings.setMinimumFontSize(12);//设置 WebView 支持的最小字体大小,默认为 8 mWebSettings.setGeolocationEnabled(true); String dir = AgentWebConfig.getCachePath(webView.getContext()); LogUtils.i(TAG, "dir:" + dir + " appcache:" + AgentWebConfig.getCachePath(webView.getContext())); //设置数据库路径 api19 已经废弃,这里只针对 webkit 起作用 mWebSettings.setGeolocationDatabasePath(dir); mWebSettings.setDatabasePath(dir); mWebSettings.setAppCachePath(dir); //缓存文件最大值 mWebSettings.setAppCacheMaxSize(Long.MAX_VALUE); mWebSettings.setUserAgentString(getWebSettings() .getUserAgentString() .concat(USERAGENT_AGENTWEB) .concat(USERAGENT_UC) ); LogUtils.i(TAG, "UserAgentString : " + mWebSettings.getUserAgentString()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { // 安卓9.0后不允许多进程使用同一个数据目录,需设置前缀来区分 // 参阅 https://blog.csdn.net/lvshuchangyin/article/details/89446629 Context context = webView.getContext(); String processName = ProcessUtils.getCurrentProcessName(context); if (!context.getApplicationContext().getPackageName().equals(processName)) { WebView.setDataDirectorySuffix(processName); } } }
Example 12
Source File: AzkarActivity.java From MuslimMateAndroid with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_azkar_view, container, false); zekerContainer = (WebView) rootView.findViewById(R.id.webView); zekerContainer.getSettings().setTextSize(WebSettings.TextSize.NORMAL); count = (ImageView) rootView.findViewById(R.id.time); share = (ImageView) rootView.findViewById(R.id.share); countDown = (TextView) rootView.findViewById(R.id.countDown); count.setOnClickListener(this); share.setOnClickListener(this); countDown.setText(NumbersLocal.convertNumberType(getContext() , String.valueOf(getArguments().getInt(REPEAT)))); if (getArguments().getInt(REPEAT) == 1) { count.setScaleType(ImageView.ScaleType.CENTER_INSIDE); count.setImageResource(R.drawable.ic_move_next); } content = (getArguments().getString(CONTENT)); fadl = (getArguments().getString(FADL)) == null || (getArguments().getString(FADL)).trim().equals("") ? "الراوى غير متوفر" : (getArguments().getString(FADL)).trim(); type = getArguments().getString(TYPE); if (Build.VERSION.SDK_INT >= 19) { // chromium, enable hardware acceleration zekerContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); } else { // older android version, disable hardware acceleration zekerContainer.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } zekerContainer.setBackgroundColor(Color.TRANSPARENT); zekerContainer.loadDataWithBaseURL("file:///android_asset/fonts/", String.format("<head> <style>@font-face" + " {font-family: 'font' ;src: url('simple.otf');}div" + " { font-family: 'font'; word-spacing: 1px;} </style></head>" + "<body align='justify'" + " dir='rtl' style='line-height:1.4em ; font-size:x-large'> <div>" + " <span style='color:#3E686A'>%s</span> <br><font size='5.5'>%s</font> </div> </body>" , fadl, content), "text/html", "utf8", ""); return rootView; }
Example 13
Source File: ImagesSliderAdapter.java From matrix-android-console with Apache License 2.0 | 4 votes |
@Override public Object instantiateItem(ViewGroup container, final int position) { View view = mLayoutInflater.inflate(R.layout.activity_image_web_view, null, false); // hide the pie chart final PieFractionView pieFractionView = (PieFractionView)view.findViewById(R.id.download_zoomed_image_piechart); pieFractionView.setVisibility(View.GONE); final WebView webView = (WebView)view.findViewById(R.id.image_webview); // black background view.setBackgroundColor(0xFF000000); webView.setBackgroundColor(0xFF000000); final SlidableImageInfo imageInfo = mListImageMessages.get(position); String mediaUrl = imageInfo.mImageUrl; final int rotationAngle = imageInfo.mRotationAngle; final String mimeType = imageInfo.mMimeType; final MXMediasCache mediasCache = Matrix.getInstance(this.context).getMediasCache(); File mediaFile = mediasCache.mediaCacheFile(mediaUrl, mimeType); // is the high picture already downloaded ? if (null != mediaFile) { if (mHighResMediaIndex.indexOf(position) < 0) { mHighResMediaIndex.add(position); } } else { // try to retrieve the thumbnail mediaFile = mediasCache.mediaCacheFile(mediaUrl, mMaxImageWidth, mMaxImageHeight, null); } // the thumbnail is not yet downloaded if (null == mediaFile) { // display nothing container.addView(view, 0); return view; } String mediaUri = "file://" + mediaFile.getPath(); String css = computeCss(mediaUri, mMaxImageWidth, mMaxImageHeight, rotationAngle); final String viewportContent = "width=640"; webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setBuiltInZoomControls(true); loadImage(webView, Uri.parse(mediaUri), viewportContent, css); container.addView(view, 0); return view; }
Example 14
Source File: LargePictureFragment.java From iBeebo with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.gallery_large_layout, container, false); final WebView large = (WebView) view.findViewById(R.id.large); large.setBackgroundColor(getResources().getColor(R.color.transparent)); large.setVisibility(View.INVISIBLE); large.setOverScrollMode(View.OVER_SCROLL_NEVER); if (SettingUtils.allowClickToCloseGallery()) { large.setOnTouchListener(new LargeOnTouchListener(large)); } LongClickListener longClickListener = ((BigPicContainerFragment) getParentFragment()).getLongClickListener(); large.setOnLongClickListener(longClickListener); final String path = getArguments().getString("path"); large.getSettings().setJavaScriptEnabled(true); large.getSettings().setUseWideViewPort(true); large.getSettings().setLoadWithOverviewMode(true); large.getSettings().setBuiltInZoomControls(true); large.getSettings().setDisplayZoomControls(false); large.setVerticalScrollBarEnabled(false); large.setHorizontalScrollBarEnabled(false); large.setLayerType(View.LAYER_TYPE_SOFTWARE, null); boolean animateIn = getArguments().getBoolean("animationIn"); if (animateIn) { showContent(path, large); } else { /** * webview will influence other imageview animation performance */ new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { showContent(path, large); } }, GeneralPictureFragment.ANIMATION_DURATION + 300); } return view; }
Example 15
Source File: LargePictureFragment.java From iBeebo with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.gallery_large_layout, container, false); final WebView large = (WebView) view.findViewById(R.id.large); large.setBackgroundColor(getResources().getColor(R.color.transparent)); large.setVisibility(View.INVISIBLE); large.setOverScrollMode(View.OVER_SCROLL_NEVER); if (SettingUtils.allowClickToCloseGallery()) { large.setOnTouchListener(new LargeOnTouchListener(large)); } LongClickListener longClickListener = ((BigPicContainerFragment) getParentFragment()).getLongClickListener(); large.setOnLongClickListener(longClickListener); final String path = getArguments().getString("path"); large.getSettings().setJavaScriptEnabled(true); large.getSettings().setUseWideViewPort(true); large.getSettings().setLoadWithOverviewMode(true); large.getSettings().setBuiltInZoomControls(true); large.getSettings().setDisplayZoomControls(false); large.setVerticalScrollBarEnabled(false); large.setHorizontalScrollBarEnabled(false); large.setLayerType(View.LAYER_TYPE_SOFTWARE, null); boolean animateIn = getArguments().getBoolean("animationIn"); if (animateIn) { showContent(path, large); } else { /** * webview will influence other imageview animation performance */ new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { showContent(path, large); } }, GeneralPictureFragment.ANIMATION_DURATION + 300); } return view; }