1 /* 2 * Copyright (C) 2015 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.menu; 18 19 import android.content.Context; 20 import android.support.annotation.Nullable; 21 import android.text.TextUtils; 22 import com.android.tv.MainActivity; 23 import com.android.tv.R; 24 import com.android.tv.common.customization.CustomAction; 25 import com.android.tv.common.customization.CustomizationManager; 26 import com.android.tv.ui.TunableTvView; 27 import java.util.List; 28 29 /** A factory class to create menu rows. */ 30 public class MenuRowFactory { 31 private final MainActivity mMainActivity; 32 private final TunableTvView mTvView; 33 private final CustomizationManager mCustomizationManager; 34 35 /** A constructor. */ MenuRowFactory(MainActivity mainActivity, TunableTvView tvView)36 public MenuRowFactory(MainActivity mainActivity, TunableTvView tvView) { 37 mMainActivity = mainActivity; 38 mTvView = tvView; 39 mCustomizationManager = new CustomizationManager(mainActivity); 40 mCustomizationManager.initialize(); 41 } 42 43 /** Creates an object corresponding to the given {@code key}. */ 44 @Nullable createMenuRow(Menu menu, Class<?> key)45 public MenuRow createMenuRow(Menu menu, Class<?> key) { 46 if (PlayControlsRow.class.equals(key)) { 47 return new PlayControlsRow( 48 mMainActivity, mTvView, menu, mMainActivity.getTimeShiftManager()); 49 } else if (ChannelsRow.class.equals(key)) { 50 return new ChannelsRow(mMainActivity, menu, mMainActivity.getProgramDataManager()); 51 } else if (PartnerRow.class.equals(key)) { 52 List<CustomAction> customActions = 53 mCustomizationManager.getCustomActions(CustomizationManager.ID_PARTNER_ROW); 54 String title = mCustomizationManager.getPartnerRowTitle(); 55 if (customActions != null && !TextUtils.isEmpty(title)) { 56 return new PartnerRow(mMainActivity, menu, title, customActions); 57 } 58 return null; 59 } else if (TvOptionsRow.class.equals(key)) { 60 return new TvOptionsRow( 61 mMainActivity, 62 menu, 63 mCustomizationManager.getCustomActions(CustomizationManager.ID_OPTIONS_ROW)); 64 } 65 return null; 66 } 67 68 /** A menu row which represents the TV options row. */ 69 public static class TvOptionsRow extends ItemListRow { 70 /** The ID of the row. */ 71 public static final String ID = TvOptionsRow.class.getName(); 72 TvOptionsRow(Context context, Menu menu, List<CustomAction> customActions)73 private TvOptionsRow(Context context, Menu menu, List<CustomAction> customActions) { 74 super( 75 context, 76 menu, 77 R.string.menu_title_options, 78 R.dimen.action_card_height, 79 new TvOptionsRowAdapter(context, customActions)); 80 } 81 } 82 83 /** A menu row which represents the partner row. */ 84 public static class PartnerRow extends ItemListRow { PartnerRow( Context context, Menu menu, String title, List<CustomAction> customActions)85 private PartnerRow( 86 Context context, Menu menu, String title, List<CustomAction> customActions) { 87 super( 88 context, 89 menu, 90 title, 91 R.dimen.action_card_height, 92 new PartnerOptionsRowAdapter(context, customActions)); 93 } 94 } 95 } 96