private dd(Context context, ab abVar, boolean z, boolean z2, l lVar, db dbVar) { super(context); this.mg = new Object(); this.pZ = context; this.mF = abVar; this.qb = z; this.nP = lVar; this.mG = dbVar; setBackgroundColor(0); WebSettings settings = getSettings(); settings.setJavaScriptEnabled(true); settings.setSavePassword(false); settings.setSupportMultipleWindows(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); cv.a(context, dbVar.pU, settings); if (VERSION.SDK_INT >= 17) { cx.a(getContext(), settings); } else if (VERSION.SDK_INT >= 11) { cw.a(getContext(), settings); } setDownloadListener(this); if (VERSION.SDK_INT >= 11) { this.pY = new dg(this, z2); } else { this.pY = new de(this, z2); } setWebViewClient(this.pY); if (VERSION.SDK_INT >= 14) { setWebChromeClient(new dh(this)); } else if (VERSION.SDK_INT >= 11) { setWebChromeClient(new df(this)); } bf(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // 保持屏幕亮 // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, // WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); webview = (WebView) super.findViewById(R.id.webView); progress = (ProgressBar) super.findViewById(R.id.progress); // progress.setVisibility(View.GONE); webview.setWebChromeClient(new WebChromeClientImpl(handler)); webview.setWebViewClient(wc); // webview.setInitialScale(25); ws = webview.getSettings(); ws.setJavaScriptCanOpenWindowsAutomatically(true); ws.setJavaScriptEnabled(true); ws.setPluginState(PluginState.ON); ws.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); Log.i("---", "加载"); // ws.setSupportZoom(true); // ws.setBuiltInZoomControls(true);//设置支持缩放 // ws.setUseWideViewPort(true); webview.loadUrl("http://aaaadc.com"); // webview.loadUrl("http://www.oceanthree.hk/apps_shop/app_index.php"); }
@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"); }
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); }*/ }
@SuppressLint("SetJavaScriptEnabled") private void setup() { mScale = mActivity.getResources().getDisplayMetrics().density; mWebView.setOnLongClickListener(this); mWebView.setOnTouchListener(this); final WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); mSelectionController = new TextSelectionController(this); mWebView.addJavascriptInterface(mSelectionController, TextSelectionController.INTERFACE_NAME); createSelectionLayer(mActivity); }
@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); }
@SuppressLint({"JavascriptInterface"}) public JDShopView(Context paramContext) { super(paramContext); setBackgroundColor(17170443); webView = new WebView(paramContext); webView.setWebChromeClient(new WebChromeClient() {}); webView.setWebViewClient(new WebViewClient() {}); WebSettings localWebSettings = webView.getSettings(); localWebSettings.setJavaScriptEnabled(true); localWebSettings.setJavaScriptCanOpenWindowsAutomatically(true); localWebSettings.setAppCacheEnabled(false); localWebSettings.setJavaScriptEnabled(true); addView(webView); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_webview); String title = this.getIntent().getStringExtra("title"); String url = this.getIntent().getStringExtra("url"); backBtn = (Button) this.findViewById(R.id.backBtn); backBtn.setOnClickListener(this); shareBtn = (Button) this.findViewById(R.id.shareBtn); shareBtn.setOnClickListener(this); // 是否显示分享,默认不显示 boolean showShareBtn = this.getIntent().getBooleanExtra("SHOW_SHARE", false); shareBtn.setVisibility(showShareBtn ? View.VISIBLE : View.GONE); titleTextView = (TextView) this.findViewById(R.id.titleTextView); titleTextView.setText(title); webView = (NoZoomControllWebView) this.findViewById(R.id.webview); WebSettings setting = webView.getSettings(); setting.setJavaScriptEnabled(true); setting.setJavaScriptCanOpenWindowsAutomatically(true); setting.setSupportZoom(true); setting.setLoadsImagesAutomatically(true); setting.setBuiltInZoomControls(true); setting.setUseWideViewPort(true); setting.setLoadWithOverviewMode(true); setting.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); webView.loadUrl(url); webView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); }
/** 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; }
public synchronized void initPreferences() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); WebSettings webSettings = getSettings(); webSettings.setLoadWithOverviewMode(true); webSettings.setTextZoom(100); webSettings.setUseWideViewPort(true); webSettings.setBlockNetworkImage(!sp.getBoolean(context.getString(R.string.sp_images), true)); webSettings.setJavaScriptEnabled( sp.getBoolean(context.getString(R.string.sp_javascript), true)); webSettings.setJavaScriptCanOpenWindowsAutomatically( sp.getBoolean(context.getString(R.string.sp_javascript), true)); webSettings.setGeolocationEnabled(sp.getBoolean(context.getString(R.string.sp_location), true)); webSettings.setSupportMultipleWindows( sp.getBoolean(context.getString(R.string.sp_multiple_windows), false)); webSettings.setSaveFormData(sp.getBoolean(context.getString(R.string.sp_passwords), true)); boolean textReflow = sp.getBoolean(context.getString(R.string.sp_text_reflow), true); if (textReflow) { webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); } catch (Exception e) { } } } else { webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); } int userAgent = Integer.valueOf(sp.getString(context.getString(R.string.sp_user_agent), "0")); if (userAgent == 1) { webSettings.setUserAgentString(BrowserUnit.UA_DESKTOP); } else if (userAgent == 2) { webSettings.setUserAgentString( sp.getString(context.getString(R.string.sp_user_agent_custom), userAgentOriginal)); } else { webSettings.setUserAgentString(userAgentOriginal); } int mode = Integer.valueOf(sp.getString(context.getString(R.string.sp_rendering), "0")); initRendering(mode); webViewClient.enableAdBlock(sp.getBoolean(context.getString(R.string.sp_ad_block), true)); }
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"); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setSupportZoom(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setBuiltInZoomControls(true); if (getArguments() != null) { mURL = getArguments().getString("URL"); } if (mURL != null) { mWebView.loadUrl(mURL); } mWebView.setWebViewClient( new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); showProgressBar(); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); hideProgressBar(); } }); mWebView.setWebChromeClient( new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); setProgressBar(newProgress); } }); }
@UiThreadTest public void testWebkitCrashes() throws Exception { // set up the webview mWebView = new WebView(getActivity()); getActivity().setContentView(mWebView); // We need to be able to run JS for most of these tests WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); // Get the url for the test Log.d(LOGTAG, TEST_PATH); String url = "file:///android_asset/" + TEST_PATH; Log.d(LOGTAG, url.toString()); // Run the test assertLoadUrlSuccessfully(url); }
/** 初始化主页面视图 * */ 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 LGameWeb( final LGameAndroid2DActivity activity, final WebProcess webProcess, final String url) { super(activity); this.url = url; this.activity = activity; // 允许显示滚动条 this.setHorizontalScrollBarEnabled(true); // 清空原有的缓存数据 this.clearCache(true); // 隐藏当前View this.setVisible(false); // 不要背景图 this.setBackgroundDrawable(null); // 进行细节设置 webSettings = getSettings(); // 数据库访问权限开启 webSettings.setAllowFileAccess(true); // 密码保存与Form信息不保存 webSettings.setSavePassword(false); webSettings.setSaveFormData(false); // 响应JavaScript事件 webSettings.setJavaScriptEnabled(true); // 允许JavaScript脚本打开新的窗口 webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // 允许自动加载图像资源 webSettings.setLoadsImagesAutomatically(true); // 不支持网页缩放 webSettings.setSupportZoom(false); // 当流程监听存在时 if (webProcess != null) { setWebViewClient( new WebViewClient() { public void onPageStarted(WebView view, String url, Bitmap favicon) { webProcess.onPageStarted(url, favicon); super.onPageStarted(view, url, favicon); } public void onPageFinished(WebView view, String url) { webProcess.onPageFinished(url); super.onPageFinished(view, url); } public void onLoadResource(WebView view, String url) { webProcess.onLoadResource(url); super.onLoadResource(view, url); } public boolean shouldOverrideUrlLoading(WebView view, String url) { webProcess.shouldOverrideUrlLoading(url); return super.shouldOverrideUrlLoading(view, url); } public void onReceivedHttpAuthRequest( WebView view, HttpAuthHandler handler, String host, String realm) { webProcess.onReceivedHttpAuthRequest(handler, host, realm); super.onReceivedHttpAuthRequest(view, handler, host, realm); } }); } // 加载进度条 final ProgressBar progress = new ProgressBar(activity); activity.addView(progress, Location.CENTER); setWebChromeClient( new WebChromeClient() { public void onProgressChanged(final WebView view, final int newProgress) { LSystem.post( new Runnable() { public void run() { progress.setProgress(newProgress); progress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE); if (newProgress == 100) { activity.removeView(progress); } setVisible(newProgress == 100 ? true : false); } }); } }); if (url != null) { loadUrl(url); } }
@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 }
@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; } }
@Override public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate()"); super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); if (fullescreen) { getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); } // This builds the view. We could probably get away with NOT having a // LinearLayout, but I like having a bucket! // Display display = getWindowManager().getDefaultDisplay(); // int width = display.getWidth(); // int height = display.getHeight(); LinearLayout.LayoutParams containerParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0F); LinearLayout.LayoutParams webviewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0F); root = new LinearLayout(this); root.setOrientation(LinearLayout.VERTICAL); root.setBackgroundColor(Color.BLACK); root.setLayoutParams(containerParams); appView = new WebView(this); appView.setLayoutParams(webviewParams); WebViewReflect.checkCompatibility(); /* * This changes the setWebChromeClient to log alerts to LogCat! * Important for Javascript Debugging */ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ECLAIR) { appView.setWebChromeClient(new AppWebChromeClient()); } appView.setWebViewClient(new AppWebViewClient()); appView.setInitialScale(100); appView.setVerticalScrollBarEnabled(false); WebSettings settings = appView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); Package pack = this.getClass().getPackage(); String appPackage = pack.getName(); WebViewReflect.setStorage(settings, true, "/data/data/" + appPackage + "/app_database/"); /* Bind the appView object to the gap class methods */ buildWebView(appView); root.addView(appView); setContentView(root); // If url was passed in to intent, then init webview, which will load // the url Bundle bundle = this.getIntent().getExtras(); if (bundle != null) { String path = bundle.getString("path"); if (path != null) { this.initPath = path; } String surl = bundle.getString("serverUrl"); if (surl != null && surl.length() > 0) { bindServerUrl(surl); } } // Setup the hardware volume controls to handle volume control setVolumeControlStream(AudioManager.STREAM_MUSIC); }
public Web(final Loon activity, final WebProcess webProcess, final String url) { super(activity); this.url = url; this.activity = activity; // 允许显示滚动条 this.setHorizontalScrollBarEnabled(true); // 清空原有的缓存数据 this.clearCache(true); // 隐藏当前View this.setVisible(false); // 不要背景图 java.lang.reflect.Method drawable = null; try { drawable = this.getClass() .getMethod("setBackgroundDrawable", android.graphics.drawable.Drawable.class); drawable.invoke(this, (android.graphics.drawable.Drawable) null); } catch (Exception ex) { try { drawable = this.getClass().getMethod("setBackground", android.graphics.drawable.Drawable.class); drawable.invoke(this, (android.graphics.drawable.Drawable) null); } catch (Exception e) { } } // 进行细节设置 webSettings = getSettings(); // 数据库访问权限开启 webSettings.setAllowFileAccess(true); // 密码保存与Form信息不保存 // webSettings.setSavePassword(false); webSettings.setSaveFormData(false); if (!webSettings.getJavaScriptEnabled()) { // 响应JavaScript事件 webSettings.setJavaScriptEnabled(true); } // 允许JavaScript脚本打开新的窗口 webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // 允许自动加载图像资源 webSettings.setLoadsImagesAutomatically(true); // 不支持网页缩放 webSettings.setSupportZoom(false); // 当流程监听存在时 if (webProcess != null) { setWebViewClient( new android.webkit.WebViewClient() { @Override public void onPageStarted(android.webkit.WebView view, String url, Bitmap favicon) { webProcess.onPageStarted(url, favicon); super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(android.webkit.WebView view, String url) { webProcess.onPageFinished(url); super.onPageFinished(view, url); } @Override public void onLoadResource(android.webkit.WebView view, String url) { webProcess.onLoadResource(url); super.onLoadResource(view, url); } @Override public boolean shouldOverrideUrlLoading(android.webkit.WebView view, String url) { webProcess.shouldOverrideUrlLoading(url); return super.shouldOverrideUrlLoading(view, url); } @Override public void onReceivedHttpAuthRequest( android.webkit.WebView view, android.webkit.HttpAuthHandler handler, String host, String realm) { webProcess.onReceivedHttpAuthRequest(handler, host, realm); super.onReceivedHttpAuthRequest(view, handler, host, realm); } }); } // 加载进度条 final android.widget.ProgressBar progress = new android.widget.ProgressBar(activity); activity.addView(progress, AndroidLocation.CENTER); setWebChromeClient( new android.webkit.WebChromeClient() { @Override public void onProgressChanged( final android.webkit.WebView view, final int newProgress) { Loon.self.runOnUiThread( new Runnable() { @Override public void run() { progress.setProgress(newProgress); progress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE); if (newProgress == 100) { activity.removeView(progress); } setVisible(newProgress == 100 ? true : false); } }); } }); if (url != null) { loadUrl(url); } }
@TargetApi(18) protected void init() { try { this.webView = new MyWebView(this.mContext); WebSettings localWebSettings = this.webView.getSettings(); if (localWebSettings != null) { localWebSettings.setJavaScriptEnabled(true); localWebSettings.setUserAgentString("Android-QingtingFM Mozilla/5.0 (Linux; U; Android 4.4.0; zh-cn; MB200 Build/GRJ22;) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"); localWebSettings.setSupportZoom(true); localWebSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); localWebSettings.setCacheMode(2); localWebSettings.setJavaScriptCanOpenWindowsAutomatically(true); } WebViewPlayer.getInstance().setbackPolicy(null); this.webView.addJavascriptInterface(WebViewPlayer.getInstance(), "QTJsPlayer"); this.webView.addJavascriptInterface(WebViewFunc.getInstance(), "QTJsReserve"); this.webView.setWebChromeClient(new WebChromeClient() { public boolean onJsAlert(WebView paramAnonymousWebView, String paramAnonymousString1, String paramAnonymousString2, JsResult paramAnonymousJsResult) { AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramAnonymousWebView.getContext()); localBuilder.setTitle("蜻蜓提示").setMessage(paramAnonymousString2).setPositiveButton("确定", null); localBuilder.setCancelable(false); localBuilder.create().show(); paramAnonymousJsResult.confirm(); return true; } public void onProgressChanged(WebView paramAnonymousWebView, int paramAnonymousInt) { if (paramAnonymousInt > 70) GroupWebView.this.removeLoading(); } public void onReceivedTitle(WebView paramAnonymousWebView, String paramAnonymousString) { } }); this.webView.setHorizontalScrollBarEnabled(false); this.webView.setVerticalScrollBarEnabled(false); this.webView.setWebViewClient(this.webViewClient); this.webView.loadUrl(getUrl()); this.webView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String paramAnonymousString1, String paramAnonymousString2, String paramAnonymousString3, String paramAnonymousString4, long paramAnonymousLong) { Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramAnonymousString1)); GroupWebView.this.getContext().startActivity(localIntent); } }); WebViewPlayer.getInstance().setWebview(this.webView); WebViewFunc.getInstance().setWebview(this.webView); LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-1, -1); addView(this.webView, localLayoutParams); return; } catch (Exception localException) { } }
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); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); // This builds the view. We could probably get away with NOT having a LinearLayout, but I like // having a bucket! LinearLayout.LayoutParams containerParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0F); LinearLayout.LayoutParams webviewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0F); root = new LinearLayout(this); root.setOrientation(LinearLayout.VERTICAL); root.setBackgroundColor(Color.BLACK); root.setLayoutParams(containerParams); appView = new WebView(this); appView.setLayoutParams(webviewParams); WebViewReflect.checkCompatibility(); if (android.os.Build.VERSION.RELEASE.startsWith("2.")) appView.setWebChromeClient(new EclairClient(this)); else { appView.setWebChromeClient(new GapClient(this)); } appView.setInitialScale(100); appView.setVerticalScrollBarEnabled(false); WebSettings settings = appView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); Package pack = this.getClass().getPackage(); String appPackage = pack.getName(); WebViewReflect.setStorage(settings, true, "/data/data/" + appPackage + "/app_database/"); // Disable cookies CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); // Turn on DOM storage! WebViewReflect.setDomStorage(settings); // Turn off native geolocation object in browser - we use our own :) WebViewReflect.setGeolocationEnabled(settings, true); /* Bind the appView object to the gap class methods */ bindBrowser(appView); if (cupcakeStorage != null) cupcakeStorage.setStorage(appPackage); root.addView(appView); setContentView(root); }
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(); }