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