private synchronized void initWebSettings() { if (android.os.Build.VERSION.SDK_INT >= 21) WebView.enableSlowWholeDocumentDraw(); WebSettings webSettings = getSettings(); userAgentOriginal = webSettings.getUserAgentString(); webSettings.setAllowContentAccess(true); webSettings.setAllowFileAccess(true); webSettings.setAllowFileAccessFromFileURLs(true); webSettings.setAllowUniversalAccessFromFileURLs(true); webSettings.setAppCacheEnabled(true); webSettings.setAppCachePath(context.getCacheDir().toString()); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setGeolocationDatabasePath(context.getFilesDir().toString()); webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setDefaultTextEncodingName(BrowserUnit.URL_ENCODING); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { webSettings.setLoadsImagesAutomatically(true); } else { webSettings.setLoadsImagesAutomatically(false); } }
@SuppressLint({"NewApi", "SetJavaScriptEnabled"}) private void loadWebView() { // 实例化WebView对象 // webview = new MyWebView(WebViewActivity.this); LogUtil.i(TAG, "loadWebView===实例化WebView==="); webview = (MyWebView) findViewById(R.id.id_webview); new MobclickAgentJSInterface(this, webview); WebSettings webSettings = webview.getSettings(); // 设置WebView属性,能够执行Javascript脚本 webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // webSettings.setUseWideViewPort(true); // 关键点 webSettings.setLoadWithOverviewMode(true); webSettings.setAppCacheEnabled(true); webSettings.setAppCacheMaxSize(8 * 1024 * 1024); // 8MB // webSettings.setAppCachePath(Constants.WEBVIEW_CACHE_DIR ); String appCacheDir = this.getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath(); webSettings.setAppCachePath(appCacheDir); webSettings.setAllowFileAccess(true); webSettings.setDomStorageEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // js调用安卓方法 webview.addJavascriptInterface(this, "RedirectListner"); }
/** * 初始化内容控件 */ private void initWeb() { // TODO Auto-generated method stub String release = android.os.Build.VERSION.RELEASE; release = release.substring(0, 3); if ("4.4".equals(release)) { web_content.setWebViewClient(new MyWebViewClient()); } else { web_content.setVisibility(View.VISIBLE); WebSettings ws = web_content.getSettings(); ws.setJavaScriptEnabled(true); ws.setAllowFileAccess(true); ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); ws.setDefaultTextEncodingName("utf-8"); ws.setTextSize(TextSize.NORMAL); ws.setAppCacheEnabled(false); ws.setDomStorageEnabled(true); if (android.os.Build.VERSION.SDK_INT >= 8) { ws.setPluginState(PluginState.ON); } ws.setRenderPriority(RenderPriority.HIGH); web_content.setWebViewClient(new WebViewClientDemo()); web_content.setWebChromeClient(new WebViewChromeClientDemo()); web_content.loadDataWithBaseURL("", unit.getIntroduce(), "text/html", "utf-8", null); } }
public static void initializeSettings(WebSettings settings, Context context) { settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setUserAgentString(settings.getUserAgentString() + DB.USER_AGENT); settings.setSupportMultipleWindows(true); settings.setSaveFormData(false); settings.setSavePassword(false); // 设置为true,系统会弹出AlertDialog确认框 if (API < 18) { settings.setAppCacheMaxSize(Long.MAX_VALUE); } if (API < 17) { settings.setEnableSmoothTransition(true); } if (API < 19) { settings.setDatabasePath(context.getFilesDir().getAbsolutePath() + "/databases"); } settings.setDomStorageEnabled(true); settings.setAppCachePath(context.getCacheDir().toString()); settings.setAppCacheEnabled(true); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); settings.setGeolocationDatabasePath(context.getCacheDir().getAbsolutePath()); settings.setAllowFileAccess(true); settings.setDatabaseEnabled(true); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setAllowContentAccess(true); settings.setDefaultTextEncodingName("utf-8"); /*if (API > 16) { settings.setAllowFileAccessFromFileURLs(false); settings.setAllowUniversalAccessFromFileURLs(false); }*/ }
public void initWebview(WebView paramWebView) { WebSettings localWebSettings = paramWebView.getSettings(); localWebSettings.setJavaScriptEnabled(true); if (Build.VERSION.SDK_INT > 7) localWebSettings.setPluginState(WebSettings.PluginState.ON); localWebSettings.setSupportZoom(true); localWebSettings.setBuiltInZoomControls(true); localWebSettings.setAllowFileAccess(true); localWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); localWebSettings.setUseWideViewPort(true); if (Build.VERSION.SDK_INT >= 8) { localWebSettings.setLoadWithOverviewMode(true); localWebSettings.setDatabaseEnabled(true); localWebSettings.setDomStorageEnabled(true); localWebSettings.setGeolocationEnabled(true); localWebSettings.setAppCacheEnabled(true); } if (Build.VERSION.SDK_INT >= 11) ; try { Class[] arrayOfClass = new Class[1]; arrayOfClass[0] = Boolean.TYPE; Method localMethod = WebSettings.class.getDeclaredMethod("setDisplayZoomControls", arrayOfClass); localMethod.setAccessible(true); Object[] arrayOfObject = new Object[1]; arrayOfObject[0] = Boolean.valueOf(false); localMethod.invoke(localWebSettings, arrayOfObject); return; } catch (Exception localException) { com.taobao.newxp.common.Log.e(ExchangeConstants.LOG_TAG, "", localException); } }
/** * 初始化 * * @param web_view * @param activity * @return */ public static WebView WebSettingInit(WebView web_view, final Activity activity) { WebSettings ws = web_view.getSettings(); ws.setJavaScriptEnabled(true); // 支持js ws.setBuiltInZoomControls(false); // 支持缩放按钮 ws.setUseWideViewPort(true); // 设置此属性,可任意比例缩放 将图片调整到适合webview的大小 ws.setLoadWithOverviewMode(true); // 缩放至屏幕的大小 ws.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); ws.setSupportZoom(false); // 支持缩放 // 设置 缓存模式 ws.setCacheMode(WebSettings.LOAD_NO_CACHE); // 关闭webview中缓存 web_view.clearCache(true); web_view.setTag(true); // 开启 DOM storage API 功能 ws.setDomStorageEnabled(true); ws.setRenderPriority(RenderPriority.HIGH); // 开启 database storage API 功能 ws.setDatabaseEnabled(false); web_view.setWebChromeClient( new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); return web_view; }
@SuppressLint("SetJavaScriptEnabled") public void configureSetting(WebViewBridge webViewBridge) { WebSettings settings = webViewBridge.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setGeolocationEnabled(true); settings.setDomStorageEnabled(true); File databasePath = new File(mContext.getCacheDir(), "webstorage"); settings.setDatabasePath(databasePath.toString()); settings.setAppCacheEnabled(true); settings.setAppCacheMaxSize(1024 * 1024 * 4); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null) .show(); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); // WebView mwebView = (WebView) findViewById(R.id.myWebView); WebSettings webSettings = mwebView.getSettings(); webSettings.setJavaScriptEnabled(true); // improve webView performance mwebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); mwebView.getSettings().setAppCacheEnabled(true); mwebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webSettings.setDomStorageEnabled(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSettings.setUseWideViewPort(true); webSettings.setSavePassword(true); webSettings.setSaveFormData(true); webSettings.setEnableSmoothTransition(true); mwebView.loadUrl("http://www.newsweek.com"); // force links open in webview only mwebView.setWebViewClient(new MyWebviewClient()); }
private void initializeSettings(WebSettings settings) { settings.setJavaScriptEnabled(true); // configure local storage apis and their database paths. settings.setAppCachePath(getDir("appcache", 0).getPath()); settings.setGeolocationDatabasePath(getDir("geolocation", 0).getPath()); settings.setDatabasePath(getDir("databases", 0).getPath()); settings.setAppCacheEnabled(true); settings.setGeolocationEnabled(true); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home); // -------------------------------TabView toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); // -------------------------------------- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); // WebView mwebView = (WebView) findViewById(R.id.myWebView); WebSettings webSettings = mwebView.getSettings(); webSettings.setJavaScriptEnabled(true); // improve webView performance mwebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); mwebView.getSettings().setAppCacheEnabled(true); mwebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webSettings.setDomStorageEnabled(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSettings.setUseWideViewPort(true); webSettings.setSavePassword(true); webSettings.setSaveFormData(true); webSettings.setEnableSmoothTransition(true); mwebView.loadUrl("http://www.newsweek.com"); // force links open in webview only mwebView.setWebViewClient(new MyWebviewClient()); }
private void setWebView() { WebSettings settings = wvIt.getSettings(); settings.setDomStorageEnabled(true); settings.setAppCacheEnabled(true); settings.setJavaScriptEnabled(true); settings.setPluginState(WebSettings.PluginState.ON); settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); settings.setDomStorageEnabled(true); settings.setDatabaseEnabled(true); settings.setAppCachePath(getCacheDir().getAbsolutePath() + "/webViewCache"); settings.setAppCacheEnabled(true); settings.setLoadWithOverviewMode(true); wvIt.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); wvIt.setWebChromeClient( new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (pbWeb != null) { // 修复未加载完成,用户返回会崩溃 if (newProgress == 100) { pbWeb.setVisibility(View.GONE); } else { if (pbWeb.getVisibility() == View.GONE) { pbWeb.setVisibility(View.VISIBLE); } pbWeb.setProgress(newProgress); } } super.onProgressChanged(view, newProgress); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_innerweb); ButterKnife.bind(this); StatusBarHelper.setStatusBar(this); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); WebSettings webSettings = wbInnerweb.getSettings(); webSettings.setBuiltInZoomControls(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); webSettings.setSaveFormData(true); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); wbInnerweb.requestFocus(); wbInnerweb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); wbInnerweb.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.indexOf("tel:") < 0) { view.loadUrl(url); } return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { pbLoading.setVisibility(View.VISIBLE); super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(WebView view, String url) { pbLoading.setVisibility(View.GONE); wbInnerweb.setVisibility(View.VISIBLE); super.onPageFinished(view, url); } }); mUrl = getIntent().getStringExtra(PARAM_WEB_URL); wbInnerweb.loadUrl(mUrl); }
/** Create and initialize web container. */ public void init() { LOG.d(TAG, "DroidGap.init()"); // Create web container this.appView = new WebView(DroidGap.this); this.appView.setId(100); this.appView.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0F)); this.appView.setWebChromeClient(new CordovaChromeClient(DroidGap.this)); this.setWebViewClient(this.appView, new CordovaWebViewClient(this)); this.appView.setInitialScale(0); this.appView.setVerticalScrollBarEnabled(false); this.appView.requestFocusFromTouch(); // Enable JavaScript WebSettings settings = this.appView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); // Set the nav dump for HTC settings.setNavDump(true); // Enable database settings.setDatabaseEnabled(true); String databasePath = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); // Enable DOM storage settings.setDomStorageEnabled(true); // Enable built-in geolocation settings.setGeolocationEnabled(true); // Add web view but make it invisible while loading URL this.appView.setVisibility(View.INVISIBLE); root.addView(this.appView); setContentView(root); // Clear cancel flag this.cancelLoadUrl = false; }
void initWebView() { navigation = (RelativeLayout) findViewById(MResource.getIdByName(getApplication(), "id", "navigation")); view = (WebView) findViewById(MResource.getIdByName(getApplication(), "id", "wv_main")); query_pro = (ProgressBar) findViewById(MResource.getIdByName(getApplication(), "id", "query_pro")); left_finish = (RelativeLayout) findViewById(MResource.getIdByName(getApplication(), "id", "left_finish")); tv_title = (TextView) findViewById(MResource.getIdByName(getApplication(), "id", "center_text_string")); tv_title.setMovementMethod(ScrollingMovementMethod.getInstance()); tv_title.setSelected(true); left_text_string = (TextView) findViewById(MResource.getIdByName(getApplication(), "id", "left_text_string")); left_finish.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (view.canGoBack()) { view.goBack(); } else { SdkPreferences.clear(); finish(); } } }); WebSettings wSettings = view.getSettings(); wSettings.setJavaScriptCanOpenWindowsAutomatically(true); wSettings.setDomStorageEnabled(true); wSettings.setDisplayZoomControls(true); wSettings.setSupportZoom(true); wSettings.setBuiltInZoomControls(true); wSettings.setJavaScriptEnabled(true); wSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); view.requestFocusFromTouch(); view.addJavascriptInterface(new JavaScriptinterface(this), "android"); view.setWebViewClient(mWebViewClient); view.setWebChromeClient(mChromeClient); // view.loadUrl("file:///android_asset/index.html"); }
void init() { setWebViewClient(new LoveClient()); setWebChromeClient(new Chrome()); WebSettings webSettings = getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setSaveFormData(false); webSettings.setAppCacheEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setLoadWithOverviewMode(false); webSettings.setUseWideViewPort(true); /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); } }*/ }
/** * Construct a new {@link ScriptResolver} * * @param id the id of this {@link ScriptResolver} * @param tomahawkApp referenced {@link TomahawkApp}, needed to report our results in the {@link * PipeLine} * @param scriptPath {@link String} containing the path to our javascript file */ public ScriptResolver(int id, TomahawkApp tomahawkApp, String scriptPath) { mReady = false; mStopped = true; mId = id; mTomahawkApp = tomahawkApp; mScriptEngine = new WebView(mTomahawkApp); WebSettings settings = mScriptEngine.getSettings(); settings.setJavaScriptEnabled(true); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); mScriptEngine.setWebChromeClient(new TomahawkWebChromeClient()); mScriptEngine.setWebViewClient(new ScriptEngine(this)); final ScriptInterface scriptInterface = new ScriptInterface(this); mScriptEngine.addJavascriptInterface(scriptInterface, SCRIPT_INTERFACE_NAME); String[] tokens = scriptPath.split("/"); mName = tokens[tokens.length - 1]; mIcon = mTomahawkApp.getResources().getDrawable(R.drawable.ic_resolver_default); mScriptFilePath = scriptPath; init(); }
/** * Have to be called from WebView.WebViewClient.onPageFinished ex : mWebView.setWebViewClient(new * WebViewClient() { onPageFinished(WebView view, String url) { [HERE] }}); Inject a header to a * webview : add a margin-top="**dpx" Had to have a transparent background with a placeholder on * top So inject js for placeholder and setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); for * transparency TODO : inject JavaScript for Pre-Lolipop with loadUrl("js:...") * * @param webView * @param withAnimation if true, disapear with a fadein */ public static void injectHeader(final WebView webView, boolean withAnimation) { if (webView != null) { MaterialViewPagerAnimator animator = MaterialViewPagerHelper.getAnimator(webView.getContext()); if (animator != null) { WebSettings webSettings = webView.getSettings(); webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); // transparent background webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); { // inject margin top final int marginTop = animator.getHeaderHeight() + 10; final String js = String.format("document.body.style.marginTop= \"%dpx\"", marginTop); webView.evaluateJavascript(js, null); } { final String js = "document.body.style.backround-color= white"; webView.evaluateJavascript(js, null); } if (withAnimation) webView.postDelayed( new Runnable() { @Override public void run() { webView.setVisibility(View.VISIBLE); ObjectAnimator.ofFloat(webView, "alpha", 0, 1).start(); } }, 400); } } }
/** Initialize the WebView options to the ones define by user. */ public void initializeOptions() { WebSettings settings = getSettings(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); settings.setJavaScriptEnabled( prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_JAVASCRIPT, true)); settings.setLoadsImagesAutomatically( prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_IMAGES, true)); settings.setSaveFormData( prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_FORM_DATA, true)); settings.setSavePassword( prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_PASSWORDS, true)); settings.setDefaultZoom( ZoomDensity.valueOf( prefs.getString( Constants.PREFERENCES_BROWSER_DEFAULT_ZOOM_LEVEL, ZoomDensity.MEDIUM.toString()))); settings.setUserAgentString( prefs.getString(Constants.PREFERENCES_BROWSER_USER_AGENT, Constants.USER_AGENT_DEFAULT)); settings.setPluginState( PluginState.valueOf( prefs.getString( Constants.PREFERENCES_BROWSER_ENABLE_PLUGINS, PluginState.ON_DEMAND.toString()))); CookieManager.getInstance() .setAcceptCookie(prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_COOKIES, true)); // Technical settings // settings.setUseWideViewPort(true); settings.setSupportMultipleWindows(true); setLongClickable(true); setScrollbarFadingEnabled(true); setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); setDrawingCacheEnabled(true); settings.setAppCacheEnabled(true); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); }
@SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"}) private void initWebView() { mWebContent = (WebView) findViewById(R.id.news_detail_content); customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer); mWebViewClient = new CustomWebViewClient(); mWebContent.setWebViewClient(mWebViewClient); mWebChromeClient = new MyWebChromeClient(); mWebContent.addJavascriptInterface(new JavascriptCallBack(), "Android"); mWebContent.setWebChromeClient(mWebChromeClient); WebSettings settings = mWebContent.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setAppCachePath(AppUtils.getWebCachePath(this)); settings.setAllowFileAccess(true); settings.setAppCacheEnabled(true); settings.setCacheMode(WebSettings.LOAD_DEFAULT); settings.setDefaultTextEncodingName("UTF-8"); settings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); settings.setCacheMode(WebSettings.LOAD_DEFAULT); mWebContent.loadUrl(url); }
public void init(Context context) { WebSettings settings = this.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setAllowFileAccess(true); settings.setAppCacheEnabled(true); final HybridInterface hybridInterface = new HybridInterface(this); this.addJavascriptInterface(hybridInterface, "hybridAndroid"); HybridWebViewClient hybridWebViewClient = new HybridWebViewClient(); hybridWebViewClient.setHybridWebView(this); this.setWebViewClient(hybridWebViewClient); this.setWebChromeClient(new HybridWebChromeClient()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (context.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } }
@SuppressLint({"NewApi", "SetJavaScriptEnabled"}) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.refund_view); ImageView backBtn = (ImageView) findViewById(R.id.btn_back); backBtn.setOnClickListener(this); try { Intent intent = this.getIntent(); tbOrderId = intent.getExtras().getString("tbOrderId"); refund = Integer.parseInt(intent.getExtras().getString("refund")); WebView web = (WebView) findViewById(R.id.refundView); if (StrUtils.isNotEmpty(tbOrderId) && refund != null) { // 获取webView控件 TbUtil.setWebView(web); WebSettings webSettings = TbUtil.getWebView().getSettings(); // 允许使用JavaScript webSettings.setJavaScriptEnabled(true); // 设置支持缩放 webSettings.setBuiltInZoomControls(true); // 设置默认字体大小 webSettings.setDefaultFontSize(5); // 设置允许自动加载图片 webSettings.setLoadsImagesAutomatically(true); // 设置JS能自动打开新窗口 webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // 设置DOM树是否能更新(缓存页面是否能更新) webSettings.setDomStorageEnabled(true); // 设置滚动条样式 TbUtil.getWebView().setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // 绑定webview接口 TbUtil.getWebView().addJavascriptInterface(new InJavaScriptLocalObj(), "localObj"); // 网页链接不以浏览器方式打开 TbUtil.getWebView() .setWebViewClient( new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); } @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { return super.shouldInterceptRequest(view, url); } @Override public void onPageFinished(WebView view, String url) { // 设置webview头部显示url TextView showVurl = (TextView) findViewById(R.id.refund_url); showVurl.setText(url); super.onPageFinished(view, url); // TbUtil.setWebView(view); // 给卖家留言设置订单编号和数量 if (url.indexOf("h5.m.taobao.com/gaia/apply.html") > -1) { // 加载js StringBuffer jsStringBuffer = new StringBuffer(); jsStringBuffer.append("javascript:$(document).ready(function(){"); // jsStringBuffer.append("setTimeout(function(){"); jsStringBuffer .append("$('.money').eq(0).html('") .append(refund) .append("');"); // jsStringBuffer.append("$('.money').eq(2).text('").append(refund) // .append("');"); jsStringBuffer .append("$('input[name=refundFee]').eq(0).attr('value','") .append(refund) .append("');"); jsStringBuffer .append("$('input[name=refundFee]').eq(1).attr('value','") .append(refund) .append("');"); // jsStringBuffer.append("},1000);"); jsStringBuffer.append("});"); view.loadUrl(jsStringBuffer.toString()); // view.loadUrl("javascript:window.localObj.showSource(document.body.innerHTML);"); } else if (url.indexOf("http://login.m.taobao.com/login.htm") > -1) { // 设置首页按钮不显示 StringBuffer jsStringBuffer = new StringBuffer(); jsStringBuffer.append("javascript:$(document).ready(function(){"); jsStringBuffer.append("$('.back').eq(0).css('display','none');"); jsStringBuffer.append("});"); } } @Override public void onReceivedError( WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); } }); TbUtil.getWebView() .loadUrl("http://h5.m.taobao.com/gaia/apply.html?spm=0.0.0.0&bizOrderId=" + tbOrderId); } else { Toast.makeText(this, "淘宝订单号或退款金额为空!", Toast.LENGTH_SHORT).show(); setResult(RESULT_CANCELED, null); finish(); } } catch (Exception e) { Toast.makeText(this, "淘宝订单号或退款金额为空!", Toast.LENGTH_SHORT).show(); setResult(RESULT_CANCELED, null); finish(); return; } }
@SuppressLint("SetJavaScriptEnabled") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { // get url and navigatio preference (default true) final String url = getIntent().getStringExtra(getPackageName() + ".URL"); final boolean navigation = getIntent().getBooleanExtra(getPackageName() + ".NAVIGATION", true); setContentView(R.layout.webviewnav); // if we want navigation bar and not hide it, make it visible. Make it invisible if not. if (navigation && !hideNavigationBar) { findViewById(R.id.webBottomBar).setVisibility(View.VISIBLE); } else { findViewById(R.id.webBottomBar).setVisibility(View.GONE); } mButtonBack = (ImageButton) findViewById(R.id.buttonWebBack); mButtonForward = (ImageButton) findViewById(R.id.buttonWebForward); mButtonStop = (ImageButton) findViewById(R.id.buttonWebStop); mProgressView = (ProgressBar) findViewById(R.id.progressBar); mProgressView.setIndeterminate(true); // init webview mWebView = (WebView) findViewById(R.id.webView); // disable hw accel as it creates flickering pages, html5 video won't work with this if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 16) mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); // This hides white bar on the right mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); WebSettings settings = mWebView.getSettings(); // enable plugins before java script settings.setPluginState(PluginState.ON); // TODO test these two settings with a big webpage (cafe lotty?) settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); // enable javascript and zoom controls settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); settings.setGeolocationEnabled(true); settings.setDatabaseEnabled(true); String databasePath = getDir("database_ext", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setGeolocationDatabasePath(databasePath); settings.setDomStorageEnabled(true); settings.setAppCacheEnabled(true); // allow XMLHttpRequests if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) settings.setAllowUniversalAccessFromFileURLs(true); MetaioWebViewClient client = new MetaioWebViewClient(); mWebView.setWebViewClient(client); mWebView.setWebChromeClient(new MetaioWebChromeClient()); registerForContextMenu(mWebView); if (savedInstanceState != null) { mWebView.restoreState(savedInstanceState); } else { // if we don't have to override the url, load it in the webview if (!client.shouldOverrideUrlLoading(mWebView, url)) mWebView.loadUrl(url); } } catch (Exception e) { MetaioCloudPlugin.log(Log.ERROR, "WebViewActivity.onCreate", e); } }
// 封装WebView public static void wrapWebView(Context context, WebView webView, WebViewClient webclient) { WebSettings webSettings = webView.getSettings(); webSettings.setSavePassword(false); webSettings.setSaveFormData(false); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setSupportZoom(false); // 设置定位可用 if (context != null) { webSettings.setDatabaseEnabled(true); String dir = context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); // 启用地理定位 webSettings.setGeolocationEnabled(true); // 设置定位的数据库路径 webSettings.setGeolocationDatabasePath(dir); // 最重要的方法,一定要设置,这就是出不来的主要原因 webSettings.setDomStorageEnabled(true); } // webView.setWebChromeClient( new WebChromeClient() { @Override public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) { callback.invoke(origin, true, false); super.onGeolocationPermissionsShowPrompt(origin, callback); } }); webView.setWebViewClient(webclient); // webView.setWebViewClient(new WebViewClient() { // // // 加载链接 // @Override // public boolean shouldOverrideUrlLoading(WebView view, String url) { // view.loadUrl(url); // return true; // } // // // 链接开始加载时 // @Override // public void onPageStarted(WebView view, String url, Bitmap favicon) { // super.onPageStarted(view, url, favicon); // if (progress != null) { // progress.setVisibility(View.VISIBLE); // } // } // // // 链接加载完成 // @Override // public void onPageFinished(WebView view, String url) { // super.onPageFinished(view, url); // if (progress != null) { // progress.setVisibility(View.GONE); // } // } // // @Override // public void onReceivedSslError(WebView view, SslErrorHandler handler, // SslError error) { // super.onReceivedSslError(view, handler, error); // } // // // webview无网络情况下的人性化处理 // @Override // public void onReceivedError(WebView view, int errorCode, String // description, String failingUrl) { // super.onReceivedError(view, errorCode, description, failingUrl); // view.loadData("", "text/html", "utf-8"); // Toast.makeText(view.getContext(), "网络不给力", // android.widget.Toast.LENGTH_LONG).show(); // } // }); }
/** 初始化主页面视图 * */ private void initContentWebView() { contentWebView = (WebView) this.findViewById(R.id.webView1); contentWebView.setWebChromeClient(new WebChromeClientEx(PortalActivity.this)); contentWebView.setWebViewClient(new WebViewClientEx(this)); contentWebView.setInitialScale(0); contentWebView.setScrollBarStyle(0); // 滚动条风格,为0就是不给滚动条留空间,滚动条覆盖在网页上 contentWebView.setVerticalScrollBarEnabled(false); contentWebView.requestFocusFromTouch(); // Enable JavaScript WebSettings settings = contentWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); // Set the nav dump for HTC settings.setNavDump(true); // 支持html5的localStorage settings.setDatabaseEnabled(true); String databasePath = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDomStorageEnabled(true); // Enable built-in geolocation settings.setGeolocationEnabled(true); // Clear cancel flag this.cancelLoadUrl = false; String version = android.os.Build.VERSION.RELEASE; if (version != null && version.indexOf("4.0") != -1) { this.clearCache(); } contentWebView.addJavascriptInterface( new Object() { @SuppressWarnings("unused") public void eventHandle(String params) { appEventHandle(new AppEvent(params)); } @SuppressWarnings("unused") public String getAndroidVersion() { return android.os.Build.VERSION.RELEASE; } @SuppressWarnings("unused") public void openAppSetting() { openSettingDlg(); } @SuppressWarnings("unused") public void checkPage(String success) { if ("true".equalsIgnoreCase(success)) { loadSuccess = true; spinnerStop(); } else { PortalActivity me = PortalActivity.this; me.runOnUiThread( new Runnable() { public void run() { showErrorTip("连接超时,似乎加载的页面不正常!请检查网络和配置"); openSettingDlg(); } }); } } }, "nativeApp"); contentWebView.addJavascriptInterface( new Object() { @SuppressWarnings("unused") public void testCall() { injectJSObject(); } }, "justepApp"); contentWebView.setDownloadListener(new JustepAppWebViewDownLoadListener()); /** * contentWebView.setWebViewClient(new WebViewClient() { * * <p>}); */ }
public TiUIWebView(TiViewProxy proxy) { super(proxy); this.isFocusable = true; TiWebView webView = isHTCSenseDevice() ? new TiWebView(proxy.getActivity()) : new NonHTCWebView(proxy.getActivity()); webView.setVerticalScrollbarOverlay(true); WebSettings settings = webView.getSettings(); settings.setUseWideViewPort(true); settings.setJavaScriptEnabled(true); settings.setSupportMultipleWindows(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setAllowFileAccess(true); settings.setDomStorageEnabled( true); // Required by some sites such as Twitter. This is in our iOS WebView too. File path = TiApplication.getInstance().getFilesDir(); if (path != null) { settings.setDatabasePath(path.getAbsolutePath()); settings.setDatabaseEnabled(true); } File cacheDir = TiApplication.getInstance().getCacheDir(); if (cacheDir != null) { settings.setAppCacheEnabled(true); settings.setAppCachePath(cacheDir.getAbsolutePath()); } // enable zoom controls by default boolean enableZoom = true; if (proxy.hasProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) { enableZoom = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)); } settings.setBuiltInZoomControls(enableZoom); settings.setSupportZoom(enableZoom); if (TiC.JELLY_BEAN_OR_GREATER) { settings.setAllowUniversalAccessFromFileURLs( true); // default is "false" for JellyBean, TIMOB-13065 } // We can only support webview settings for plugin/flash in API 8 and higher. if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR_MR1) { initializePluginAPI(webView); } boolean enableJavascriptInterface = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_JAVASCRIPT_INTERFACE), true); chromeClient = new TiWebChromeClient(this); webView.setWebChromeClient(chromeClient); client = new TiWebViewClient(this, webView); webView.setWebViewClient(client); if (Build.VERSION.SDK_INT > 16 || enableJavascriptInterface) { client.getBinding().addJavascriptInterfaces(); } webView.client = client; if (proxy instanceof WebViewProxy) { WebViewProxy webProxy = (WebViewProxy) proxy; String username = webProxy.getBasicAuthenticationUserName(); String password = webProxy.getBasicAuthenticationPassword(); if (username != null && password != null) { setBasicAuthentication(username, password); } webProxy.clearBasicAuthentication(); } TiCompositeLayout.LayoutParams params = getLayoutParams(); params.autoFillsHeight = true; params.autoFillsWidth = true; setNativeView(webView); }
private void initView() { // findViewById(R.id.btn_return).setOnClickListener(this); webView = (WebView) findViewById(R.id.webview); btn_showOwner = (Button) findViewById(R.id.btn_showOwner); btn_collect = (ImageButton) findViewById(R.id.btn_collectPost); btn_reply = (ImageButton) findViewById(R.id.btn_replyPost); btn_reward = (ImageButton) findViewById(R.id.btn_rewardPost); btn_return = (ImageView) findViewById(R.id.btn_left); btn_share = (ImageButton) findViewById(R.id.btn_sharePost); reply_layout = (RelativeLayout) findViewById(R.id.rl_reply); post_layout = (RelativeLayout) findViewById(R.id.rl_post); edt_content = (EditText) findViewById(R.id.edt_reply_Content); btn_pic = (ImageButton) findViewById(R.id.btn_addPic); mpics = (LinearLayout) findViewById(R.id.ll_piclayer); btn_showOwner.setVisibility(View.VISIBLE); btn_reward.setOnClickListener(this); btn_showOwner.setOnClickListener(this); btn_collect.setOnClickListener(this); btn_reply.setOnClickListener(this); btn_return.setOnClickListener(this); btn_share.setOnClickListener(this); btn_pic.setOnClickListener(this); edt_content.addTextChangedListener(this); tv_title = (TextView) findViewById(R.id.tv_title); tv_hint = (TextView) findViewById(R.id.tv_lengthHint); reply_layout = (RelativeLayout) findViewById(R.id.rl_reply); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setUseWideViewPort(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setSupportMultipleWindows(true); webView.setWebChromeClient( new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { // TODO Auto-generated method stub super.onProgressChanged(view, newProgress); if (0 == newProgress) { popupLoadingToast(getString(R.string.onloading_hint)); } if (100 == newProgress) { if (null != webView) { mHandler.sendMessage(mHandler.obtainMessage(6)); getParams(); } runOnUiThread( new Runnable() { @Override public void run() { // TODO Auto-generated method stub cancleLodingToast(true); } }); } } }); webView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // TODO Auto-generated method stub // 返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器 Log.e(TAG, "url= " + url); view.loadUrl(url); return true; } }); webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); addInterface(); }
@SuppressLint("SetJavaScriptEnabled") @SuppressWarnings("deprecation") private void initWebViewSettings() { this.setInitialScale(0); this.setVerticalScrollBarEnabled(false); // TODO: The Activity is the one that should call requestFocus(). if (shouldRequestFocusOnInit()) { this.requestFocusFromTouch(); } this.setInitialScale(0); this.setVerticalScrollBarEnabled(false); if (shouldRequestFocusOnInit()) { this.requestFocusFromTouch(); } // Enable JavaScript final WebSettings settings = this.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean // 4.2) try { Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] {boolean.class}); String manufacturer = android.os.Build.MANUFACTURER; Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB && android.os.Build.MANUFACTURER.contains("HTC")) { gingerbread_getMethod.invoke(settings, true); } } catch (NoSuchMethodException e) { Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8"); } catch (IllegalArgumentException e) { Log.d(TAG, "Doing the NavDump failed with bad arguments"); } catch (IllegalAccessException e) { Log.d( TAG, "This should never happen: IllegalAccessException means this isn't Android anymore"); } catch (InvocationTargetException e) { Log.d( TAG, "This should never happen: InvocationTargetException means this isn't Android anymore."); } // We don't save any form data in the application settings.setSaveFormData(false); settings.setSavePassword(false); // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist // while we do this if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { Level16Apis.enableUniversalAccess(settings); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { Level17Apis.setMediaPlaybackRequiresUserGesture(settings, false); } // Enable database // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16 String databasePath = getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabaseEnabled(true); settings.setDatabasePath(databasePath); // Determine whether we're in debug or release mode, and turn on Debugging! ApplicationInfo appInfo = getContext().getApplicationContext().getApplicationInfo(); if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { enableRemoteDebugging(); } settings.setGeolocationDatabasePath(databasePath); // Enable DOM storage settings.setDomStorageEnabled(true); // Enable built-in geolocation settings.setGeolocationEnabled(true); // Enable AppCache // Fix for CB-2282 settings.setAppCacheMaxSize(5 * 1048576); settings.setAppCachePath(databasePath); settings.setAppCacheEnabled(true); // Fix for CB-1405 // Google issue 4641 settings.getUserAgentString(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { settings.getUserAgentString(); } }; getContext().registerReceiver(this.receiver, intentFilter); } // end CB-1405 }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); linearLayout = (LinearLayout) findViewById(R.id.linearLayout); linearLayout.setBackgroundColor(Color.BLACK); // Navbar setup navbar = (LinearLayout) findViewById(R.id.navbar); goButton = (Button) findViewById(R.id.go_button); urlField = (EditText) findViewById(R.id.url); goButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { doNav(); } }); urlField.setOnEditorActionListener( new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_GO) { doNav(); handled = true; } return handled; } }); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); String lastUrl = settings.getString("lastUrl", ""); urlField.setText(lastUrl); // Navbar animation settings AnimationListener slideListener = new AnimationListener() { @Override public void onAnimationEnd(Animation animation) { if (animation.equals(slideUp)) { navbar.setVisibility(View.GONE); } } @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationStart(Animation animation) { if (animation.equals(slideDown)) { navbar.setVisibility(View.VISIBLE); } } }; slideUp = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f); slideUp.setDuration(500); slideUp.setAnimationListener(slideListener); slideDown = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f); slideDown.setDuration(500); slideDown.setAnimationListener(slideListener); // WebView setup webView = (WebView) findViewById(R.id.webView); WebSettings webSettings = webView.getSettings(); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient( new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { Log.d("scale", view.getScale() + ""); Log.d("pageFinished", url); view.setInitialScale(70); if (url.equalsIgnoreCase(HOME_PAGE)) { // navbar.setVisibility(View.VISIBLE); navbar.startAnimation(slideDown); } } @Override public void onScaleChanged(WebView view, float oldScale, float newScale) { Log.d("scale changed", oldScale + " - " + newScale); if (newScale > 0.7) { Log.d("scale", "reset"); // view.setInitialScale(70); } } }); webView.setInitialScale(70); webView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); webView.setVerticalScrollBarEnabled(false); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setSupportZoom(true); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setDatabasePath( "/data/data/" + webView.getContext().getPackageName() + "/databases/"); webSettings.setSaveFormData(false); webSettings.setLightTouchEnabled(false); webSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); webSettings.setRenderPriority(RenderPriority.HIGH); webSettings.setUserAgentString( "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV"); final Intent intent = getIntent(); if ((intent.getAction() == Intent.ACTION_VIEW) && (intent.getData() != null)) { final String url = intent.getDataString(); urlField.setText(url); webView.loadUrl(url); navbar.setVisibility(View.GONE); } else { webView.loadUrl(HOME_PAGE); } webView.requestFocus(); }
static void b_(WebSettings webSettings, boolean z) { webSettings.setDomStorageEnabled(z); }
@Override protected void layoutInit(LayoutInflater inflater, Bundle savedInstanceSate) { super.layoutInit(inflater, savedInstanceSate); BaseActivity activity = (BaseActivity) getActivity(); activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); activity.getSupportActionBar().setTitle(R.string.title_login); setHasOptionsMenu(true); progressBar.setIndeterminate(true); editAccount = textinputAccount.getEditText(); editAccount.addTextChangedListener(new MTextWatcher(textinputAccount)); editPassword = textinputPassword.getEditText(); editPassword.addTextChangedListener(new MTextWatcher(textinputPassword)); if (getArguments() != null) { editAccount.setText(getArguments().getString("account")); editPassword.setText(getArguments().getString("password")); } WebSettings setting = webView.getSettings(); setting.setJavaScriptEnabled(true); setting.setDomStorageEnabled(true); setting.setAppCacheEnabled(true); setting.setDefaultTextEncodingName("utf-8"); webView.addJavascriptInterface(new LoginJavaScriptInterface(), "loginjs"); webView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, final String url) { if (url.startsWith(SettingUtility.getStringSetting("callback_url"))) webView.loadUrl("javascript:getAccount()"); view.loadUrl(url); Logger.d(TAG, "load url = " + url); // 是否授权成功 if (accountTask == null && url != null && url.startsWith(SettingUtility.getStringSetting("callback_url"))) { Params params = ParamsUtil.deCodeUrl(url); String code = params.getParameter("code"); Logger.d(TAG, "授权成功, code = " + code); if (getActivity() == null) return true; accountTask = new AccountTask(); accountTask.execute(code); } return true; } }); webView.setWebChromeClient( new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress < 100) { progressBar.setVisibility(View.VISIBLE); } else if (newProgress == 100) { progressBar.setVisibility(View.GONE); } if (newProgress < 100) { } else if (newProgress == 100) { Logger.d(TAG, String.format("progress = 100 , url = %s", view.getUrl())); if (!accountFilled && !TextUtils.isEmpty(view.getUrl()) && view.getUrl().equalsIgnoreCase("about:blank")) { webView.loadUrl("javascript:fillAccount()"); accountFilled = true; } // 是否授权成功 if (accountTask == null && webView.getUrl() != null && webView.getUrl().startsWith(SettingUtility.getStringSetting("callback_url"))) { Params params = ParamsUtil.deCodeUrl(webView.getUrl()); String code = params.getParameter("code"); Logger.d(TAG, "授权成功, code = " + code); if (getActivity() == null) return; accountTask = new AccountTask(); accountTask.execute(code); } } if (webView.getUrl() != null && webView.getUrl().startsWith(SettingUtility.getStringSetting("callback_url"))) { webView.setVisibility(View.GONE); } super.onProgressChanged(view, newProgress); } }); if (!TextUtils.isEmpty(editAccount.getText().toString()) && !TextUtils.isEmpty(editPassword.getText().toString())) { new Handler() .postDelayed( new Runnable() { @Override public void run() { doLogin(); } }, 500); } }