1 /* 2 * Copyright (C) 2017 The Android Open Source Project 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 17 package com.android.dialer.about; 18 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.support.v4.app.LoaderManager.LoaderCallbacks; 22 import android.support.v4.content.Loader; 23 import android.support.v7.app.AppCompatActivity; 24 import android.view.MenuItem; 25 import android.view.View; 26 import android.widget.AdapterView; 27 import android.widget.AdapterView.OnItemClickListener; 28 import android.widget.ArrayAdapter; 29 import android.widget.ListView; 30 import java.util.ArrayList; 31 import java.util.List; 32 33 /** An Activity listing third party libraries with notice licenses. */ 34 public final class LicenseMenuActivity extends AppCompatActivity 35 implements LoaderCallbacks<List<License>> { 36 37 static final String ARGS_LICENSE = "license"; 38 39 private static final int LOADER_ID = 54321; 40 41 private ArrayAdapter<License> listAdapter; 42 43 @Override 44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 setContentView(R.layout.license_menu_activity); 47 48 if (getSupportActionBar() != null) { 49 getSupportActionBar().setDisplayHomeAsUpEnabled(true); 50 } 51 52 listAdapter = new ArrayAdapter<>(this, R.layout.license, R.id.license, new ArrayList<>()); 53 getSupportLoaderManager().initLoader(LOADER_ID, null, this); 54 ListView listView = (ListView) findViewById(R.id.license_list); 55 listView.setAdapter(listAdapter); 56 listView.setOnItemClickListener( 57 new OnItemClickListener() { 58 @Override 59 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 60 License license = (License) parent.getItemAtPosition(position); 61 Intent licenseIntent = new Intent(LicenseMenuActivity.this, LicenseActivity.class); 62 licenseIntent.putExtra(ARGS_LICENSE, license); 63 startActivity(licenseIntent); 64 } 65 }); 66 } 67 68 @Override 69 public boolean onOptionsItemSelected(MenuItem item) { 70 if (item.getItemId() == android.R.id.home) { 71 // Go back one place in the history stack, if the app icon is clicked. 72 finish(); 73 return true; 74 } 75 return super.onOptionsItemSelected(item); 76 } 77 78 @Override 79 public void onDestroy() { 80 super.onDestroy(); 81 getSupportLoaderManager().destroyLoader(LOADER_ID); 82 } 83 84 @Override 85 public Loader<List<License>> onCreateLoader(int id, Bundle args) { 86 return new LicenseLoader(this); 87 } 88 89 @Override 90 public void onLoadFinished(Loader<List<License>> loader, List<License> licenses) { 91 listAdapter.clear(); 92 listAdapter.addAll(licenses); 93 listAdapter.notifyDataSetChanged(); 94 } 95 96 @Override 97 public void onLoaderReset(Loader<List<License>> loader) { 98 listAdapter.clear(); 99 listAdapter.notifyDataSetChanged(); 100 } 101 } 102