1 package name.gumartinm.weather.information.activity;
3 import android.app.ActionBar;
4 import android.app.Activity;
5 import android.os.Bundle;
6 import android.util.Log;
7 import android.webkit.WebView;
9 import com.google.android.gms.common.GooglePlayServicesUtil;
10 import name.gumartinm.weather.information.R;
12 import java.io.BufferedReader;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.io.InputStreamReader;
16 import java.io.UnsupportedEncodingException;
17 import java.nio.charset.Charset;
19 public class LicensesActivity extends Activity {
20 private static final String TAG = "LicensesActivity";
21 private WebView mWebView;
25 public void onCreate(final Bundle savedInstanceState) {
26 super.onCreate(savedInstanceState);
27 setContentView(R.layout.weather_licenses);
29 mWebView = (WebView) this.findViewById(R.id.weather_licenses);
33 public void onResume() {
36 final ActionBar actionBar = this.getActionBar();
37 actionBar.setTitle(this.getString(R.string.weather_licenses_title));
39 final String googlePlayServices = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this.getApplicationContext());
41 final StringBuilder stringBuilder = this.loadData();
42 stringBuilder.append(googlePlayServices).append("</pre>").append("</body>").append("</html>");
43 mWebView.loadDataWithBaseURL(null, stringBuilder.toString(), "text/html", "UTF-8", null);
44 } catch (final UnsupportedEncodingException e) {
45 Log.e(TAG, "Load data error", e);
46 } catch (final IOException e) {
47 Log.e(TAG, "Load data error", e);
51 private StringBuilder loadData() throws UnsupportedEncodingException, IOException {
52 final InputStream inputStream = this.getResources().openRawResource(R.raw.licenses);
54 final InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
56 final BufferedReader reader = new BufferedReader(inputStreamReader);
58 final StringBuilder stringBuilder = new StringBuilder();
60 while ((line = reader.readLine()) != null) {
61 stringBuilder.append(line);
62 stringBuilder.append("\n");
69 inputStreamReader.close();