1 /** 2 * Copyright (c) 2014, Google Inc. 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 package com.android.mail.ui; 17 18 import android.app.ActionBar; 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.view.MenuItem; 22 import android.webkit.WebView; 23 24 import com.android.mail.R; 25 import com.android.mail.utils.LogTag; 26 import com.android.mail.utils.LogUtils; 27 28 import org.apache.commons.io.IOUtils; 29 30 import java.io.IOException; 31 import java.io.InputStream; 32 import java.net.URLEncoder; 33 34 /** 35 * This activity displays the Software Licenses of the libraries used by this software. 36 */ 37 public class LicensesActivity extends Activity { 38 39 @Override onCreate(Bundle savedInstanceState)40 protected void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 43 setContentView(R.layout.licenses_activity); 44 45 // Enable back navigation 46 final ActionBar actionBar = getActionBar(); 47 if (actionBar != null) { 48 actionBar.setDisplayHomeAsUpEnabled(true); 49 } 50 51 InputStream input = null; 52 String licenseHTML = null; 53 try { 54 // read the raw license String from the license HTML file 55 input = getResources().openRawResource(R.raw.licenses); 56 final String license = IOUtils.toString(input, "UTF-8"); 57 58 // encode the license string for display as HTML in the webview 59 licenseHTML = URLEncoder.encode(license, "UTF-8").replace("+", "%20"); 60 } catch (IOException e) { 61 LogUtils.e(LogTag.getLogTag(), e, "Error reading licence file"); 62 } finally { 63 if (input != null) { 64 try { 65 input.close(); 66 } catch (IOException ioe) { 67 // best attempt only 68 } 69 } 70 } 71 72 // set the license HTML into the webview 73 final WebView webview = (WebView) findViewById(R.id.webview); 74 webview.loadData(licenseHTML, "text/html", null); 75 } 76 77 @Override onOptionsItemSelected(MenuItem item)78 public boolean onOptionsItemSelected(MenuItem item) { 79 switch (item.getItemId()) { 80 case android.R.id.home: { 81 finish(); 82 return true; 83 } 84 default: return super.onOptionsItemSelected(item); 85 } 86 } 87 }