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.tv.license;
18 
19 import android.content.Context;
20 import com.android.tv.R;
21 import com.android.tv.ui.sidepanel.ActionItem;
22 import com.android.tv.ui.sidepanel.SideFragment;
23 import java.util.ArrayList;
24 import java.util.List;
25 
26 /** Opens a dialog showing open source licenses. */
27 public final class LicenseSideFragment extends SideFragment {
28 
29     public static final String TRACKER_LABEL = "Open Source Licenses";
30 
31     public class LicenseActionItem extends ActionItem {
32         private final License license;
33 
LicenseActionItem(License license)34         public LicenseActionItem(License license) {
35             super(license.getLibraryName());
36             this.license = license;
37         }
38 
39         @Override
onSelected()40         protected void onSelected() {
41             LicenseDialogFragment dialog = LicenseDialogFragment.newInstance(license);
42             getMainActivity()
43                     .getOverlayManager()
44                     .showDialogFragment(LicenseDialogFragment.DIALOG_TAG, dialog, true);
45         }
46     }
47 
48     private List<LicenseActionItem> licenses;
49 
50     @Override
onAttach(Context context)51     public void onAttach(Context context) {
52         super.onAttach(context);
53         licenses = toActionItems(Licenses.getLicenses(context));
54     }
55 
toActionItems(ArrayList<License> licenses)56     private List<LicenseActionItem> toActionItems(ArrayList<License> licenses) {
57         List<LicenseActionItem> items = new ArrayList<>(licenses.size());
58         for (License license : licenses) {
59             items.add(new LicenseActionItem(license));
60         }
61         return items;
62     }
63 
64     @Override
getTitle()65     protected String getTitle() {
66         return getResources().getString(R.string.settings_menu_licenses);
67     }
68 
69     @Override
getTrackerLabel()70     public String getTrackerLabel() {
71         return TRACKER_LABEL;
72     }
73 
74     @Override
getItemList()75     protected List<LicenseActionItem> getItemList() {
76         return licenses;
77     }
78 }
79