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