Back to project page guides.
The source code is released under:
GNU General Public License
If you think the Android project guides listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
// Guidebook is an Android application that reads audioguides using Text-to-Speech services. // Copyright (C) 2013 Adrin Romero Corchado ////from w w w . j a va 2 s . c o m // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. package com.adrguides; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; import android.view.Window; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ProgressBar; /** * Created by adrian on 9/10/13. */ public class WebViewActivity extends Activity { public final static String EXTRA_URL = "EXTRA_URL"; public final static String EXTRA_TITLE = "EXTRA_TITLE"; private WebView mWebView; private ProgressBar webprogress; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_webview); getActionBar().setDisplayHomeAsUpEnabled(true); mWebView = (WebView) findViewById(R.id.webView); webprogress = (ProgressBar) findViewById(R.id.webProgress); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.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) { webprogress.setProgress(0); webprogress.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { webprogress.setVisibility(View.INVISIBLE); } }); mWebView.setWebChromeClient(new WebChromeClient(){ public void onProgressChanged(WebView view, int progress) { webprogress.setProgress(progress); } }); if (savedInstanceState == null) { mWebView.loadUrl(getIntent().getStringExtra(EXTRA_URL)); } else { mWebView.restoreState(savedInstanceState); } getActionBar().setTitle(getIntent().getStringExtra(EXTRA_TITLE)); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mWebView.saveState(outState); } @Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) { mWebView.goBack(); return true; } return super.onKeyDown(keyCode, event); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar's Up/Home button case android.R.id.home: this.finish(); return true; } return super.onOptionsItemSelected(item); } }