d929950cc42c107297811619dd53be6df93d8d1c
[JavaForFun] /
1 package name.gumartinm.weather.information.activity;
2
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;
8
9 import com.google.android.gms.common.GooglePlayServicesUtil;
10 import name.gumartinm.weather.information.R;
11
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;
18
19 public class LicensesActivity extends Activity {
20     private static final String TAG = "LicensesActivity";
21     private WebView mWebView;
22
23
24     @Override
25     public void onCreate(final Bundle savedInstanceState) {
26         super.onCreate(savedInstanceState);
27         setContentView(R.layout.weather_licenses);
28
29         mWebView = (WebView) this.findViewById(R.id.weather_licenses);
30     }
31
32     @Override
33     public void onResume() {
34         super.onResume();
35
36         final ActionBar actionBar = this.getActionBar();
37         actionBar.setTitle(this.getString(R.string.weather_licenses_title));
38
39         final String googlePlayServices = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this.getApplicationContext());
40         try {
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);
48         }
49     }
50
51     private StringBuilder loadData() throws UnsupportedEncodingException, IOException {
52         final InputStream inputStream = this.getResources().openRawResource(R.raw.licenses);
53         try {
54             final InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
55             try {
56                 final BufferedReader reader = new BufferedReader(inputStreamReader);
57                 try {
58                     final StringBuilder stringBuilder = new StringBuilder();
59                     String line;
60                     while ((line = reader.readLine()) != null) {
61                         stringBuilder.append(line);
62                         stringBuilder.append("\n");
63                     }
64                     return stringBuilder;
65                 } finally {
66                     reader.close();
67                 }
68             } finally {
69                 inputStreamReader.close();
70             }
71         } finally {
72             inputStream.close();
73         }
74     }
75 }