• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 /**
22  * A base class of the item which will be displayed in the main menu. It contains the data such as
23  * title to represent a row. This is an abstract class and the sub-class could have it's own data
24  * for the row.
25  */
26 public abstract class MenuRow {
27     private final Context mContext;
28     private final String mTitle;
29     private final int mHeight;
30     private final Menu mMenu;
31 
32     private MenuRowView mMenuRowView;
33 
34     // TODO: Check if the heightResId is really necessary.
MenuRow(Context context, Menu menu, int titleResId, int heightResId)35     public MenuRow(Context context, Menu menu, int titleResId, int heightResId) {
36         this(context, menu, context.getString(titleResId), heightResId);
37     }
38 
MenuRow(Context context, Menu menu, String title, int heightResId)39     public MenuRow(Context context, Menu menu, String title, int heightResId) {
40         mContext = context;
41         mTitle = title;
42         mMenu = menu;
43         mHeight = context.getResources().getDimensionPixelSize(heightResId);
44     }
45 
46     /** Returns the context. */
getContext()47     protected Context getContext() {
48         return mContext;
49     }
50 
51     /** Returns the menu object. */
getMenu()52     public Menu getMenu() {
53         return mMenu;
54     }
55 
56     /** Returns the title of this row. */
getTitle()57     public String getTitle() {
58         return mTitle;
59     }
60 
61     /** Returns the height of this row. */
getHeight()62     public int getHeight() {
63         return mHeight;
64     }
65 
66     /** Sets the menu row view. */
setMenuRowView(MenuRowView menuRowView)67     public void setMenuRowView(MenuRowView menuRowView) {
68         mMenuRowView = menuRowView;
69     }
70 
71     /** Returns the menu row view. */
getMenuRowView()72     protected MenuRowView getMenuRowView() {
73         return mMenuRowView;
74     }
75 
76     /** Updates the contents in this row. This method is called only by the menu when necessary. */
update()77     public abstract void update();
78 
79     /** Indicates whether this row is shown in the menu. */
isVisible()80     public boolean isVisible() {
81         return true;
82     }
83 
84     /**
85      * Releases all the resources which need to be released. This method is called when the main
86      * menu is not available any more.
87      */
release()88     public void release() {}
89 
90     /** Returns the ID of the layout resource for this row. */
getLayoutResId()91     public abstract int getLayoutResId();
92 
93     /** Returns the ID of this row. This ID is used to select the row in the main menu. */
getId()94     public abstract String getId();
95 
96     /** This method is called when recent channels are changed. */
onRecentChannelsChanged()97     public void onRecentChannelsChanged() {}
98 
99     /** Returns whether to hide the title when the row is selected. */
hideTitleWhenSelected()100     public boolean hideTitleWhenSelected() {
101         return false;
102     }
103 }
104