2 * Copyright 2014 Gustavo Martin Morcuende
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package name.gumartinm.weather.information.activity;
18 import android.app.ActionBar;
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.util.Log;
22 import android.webkit.WebView;
24 import com.google.android.gms.common.GooglePlayServicesUtil;
25 import name.gumartinm.weather.information.R;
27 import java.io.BufferedReader;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.InputStreamReader;
31 import java.io.UnsupportedEncodingException;
32 import java.nio.charset.Charset;
34 public class LicensesActivity extends Activity {
35 private static final String TAG = "LicensesActivity";
36 private WebView mWebView;
40 public void onCreate(final Bundle savedInstanceState) {
41 super.onCreate(savedInstanceState);
42 setContentView(R.layout.weather_licenses);
44 mWebView = (WebView) this.findViewById(R.id.weather_licenses);
48 public void onResume() {
51 final ActionBar actionBar = this.getActionBar();
52 actionBar.setTitle(this.getString(R.string.weather_licenses_title));
54 final String googlePlayServices = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this.getApplicationContext());
56 final StringBuilder stringBuilder = this.loadData();
57 stringBuilder.append(googlePlayServices).append("</pre>").append("</body>").append("</html>");
58 mWebView.loadDataWithBaseURL(null, stringBuilder.toString(), "text/html", "UTF-8", null);
59 } catch (final UnsupportedEncodingException e) {
60 Log.e(TAG, "Load data error", e);
61 } catch (final IOException e) {
62 Log.e(TAG, "Load data error", e);
66 private StringBuilder loadData() throws UnsupportedEncodingException, IOException {
67 final InputStream inputStream = this.getResources().openRawResource(R.raw.licenses);
69 final InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
71 final BufferedReader reader = new BufferedReader(inputStreamReader);
73 final StringBuilder stringBuilder = new StringBuilder();
75 while ((line = reader.readLine()) != null) {
76 stringBuilder.append(line);
77 stringBuilder.append("\n");
84 inputStreamReader.close();