@Override public void initBusiness() { TitleBar bar = new TitleBar(activity).setTitle("宝宝辅食"); bar.iv_back.setVisibility(View.VISIBLE); bar.iv_back.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // WebBackForwardList hisList = web_view.copyBackForwardList(); // if (hisList.getSize() == 1) { // finish(); // } else if (web_view.canGoBack()) { // web_view.goBack(); // } else { // finish(); // } finish(); } }); web_view.getSettings().setJavaScriptEnabled(true); web_view.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); web_view.setScrollContainer(true); web_view.setWebChromeClient(new WebChromeClient()); web_view.getSettings().setJavaScriptEnabled(true); if (AppUtils.checkNet(activity)) { web_view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); } else { web_view.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); } web_view.setWebViewClient(new WebViewClient() {}); web_view.loadUrl(Const.BABY_FOODS); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.event_layout); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); Bundle bundle = getIntent().getExtras(); getSupportActionBar().setTitle(bundle.getString("title")); WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.loadUrl("file:///android_asset/" + bundle.getString("url")); myWebView.setWebViewClient(new CustomWebViewClient(this)); myWebView.setScrollContainer(false); }
@Override protected void onStart() { super.onStart(); try { jsonSrc = FileUtils.readFromAssetsFile(that, "json2.js"); androidJsSrc = FileUtils.readFromAssetsFile(that, "android.js"); } catch (IOException e1) { throw new RuntimeException(e1); } mObserver = new HtmlEventObserver(); // TODO // RpcReceiverManager mFacadeManager = getRpcReceiverManager(); // mFacadeManager.getReceiver(EventFacade.class).addGlobalEventObserver(mObserver); // mAPIWrapperSource = generateAPIWrapper(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, config.getLOG_TAG()); mWebView.setKeepScreenOn(true); mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); mWebView.setScrollbarFadingEnabled(false); mWebView.setVerticalScrollBarEnabled(false); mWebView.setHorizontalScrollBarEnabled(false); mWebView.setScrollContainer(false); WebSettings webSettings = mWebView.getSettings(); webSettings.setSavePassword(false); webSettings.setSaveFormData(false); webSettings.setJavaScriptEnabled(true); webSettings.setPluginsEnabled(true); webSettings.setSupportZoom(false); webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); mWebView.addJavascriptInterface(mWrapper, "_rpc_wrapper"); mWebView.addJavascriptInterface( new Object() { @SuppressWarnings("unused") public void register(String event, int id) { mObserver.register(event, id); } }, "_callback_wrapper"); if (Build.VERSION.SDK_INT >= 5) { try { Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[] {Boolean.TYPE}); m1.invoke(webSettings, Boolean.TRUE); Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[] {Boolean.TYPE}); m2.invoke(webSettings, Boolean.TRUE); Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[] {String.class}); m3.invoke(webSettings, this.getFilesDir().getParent() + "/databases/"); } catch (Exception e) { e.printStackTrace(); } } mWebView.setWebChromeClient(new WebChromeClient() {}); mWebView.setWebViewClient( new WebViewClient() { // public void onReceivedError(WebView view, int errorCode, String description, // String failingUrl) { // Toast.makeText(that, "Error: " + description, Toast.LENGTH_SHORT).show(); // } }); webSettings.setCacheMode(WebSettings.LOAD_NORMAL); if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 14) { mWebView.setSystemUiVisibility(WebView.STATUS_BAR_HIDDEN); } else if (Build.VERSION.SDK_INT >= 14) { mWebView.setSystemUiVisibility(WebView.SYSTEM_UI_FLAG_HIDE_NAVIGATION); } mWebView.loadUrl("javascript:" + jsonSrc); mWebView.loadUrl("javascript:" + androidJsSrc); mWebView.loadUrl("javascript:" + mAPIWrapperSource); Log.d( config.getLOG_TAG(), "Launch Webview: " + "file://" + this.getFilesDir().getAbsolutePath() + "/" + config.getMAIN_SCRIPT_NAME()); mWebView.loadUrl( "file://" + this.getFilesDir().getAbsolutePath() + "/" + config.getMAIN_SCRIPT_NAME()); }