• 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     private boolean mIsReselected = false;
35 
36     // TODO: Check if the heightResId is really necessary.
MenuRow(Context context, Menu menu, int titleResId, int heightResId)37     public MenuRow(Context context, Menu menu, int titleResId, int heightResId) {
38         this(context, menu, context.getString(titleResId), heightResId);
39     }
40 
MenuRow(Context context, Menu menu, String title, int heightResId)41     public MenuRow(Context context, Menu menu, String title, int heightResId) {
42         mContext = context;
43         mTitle = title;
44         mMenu = menu;
45         mHeight = context.getResources().getDimensionPixelSize(heightResId);
46     }
47 
48     /** Returns the context. */
getContext()49     protected Context getContext() {
50         return mContext;
51     }
52 
53     /** Returns the menu object. */
getMenu()54     public Menu getMenu() {
55         return mMenu;
56     }
57 
58     /** Returns the title of this row. */
getTitle()59     public String getTitle() {
60         return mTitle;
61     }
62 
63     /** Returns the height of this row. */
getHeight()64     public int getHeight() {
65         return mHeight;
66     }
67 
68     /** Sets the menu row view. */
setMenuRowView(MenuRowView menuRowView)69     public void setMenuRowView(MenuRowView menuRowView) {
70         mMenuRowView = menuRowView;
71     }
72 
73     /** Returns the menu row view. */
getMenuRowView()74     protected MenuRowView getMenuRowView() {
75         return mMenuRowView;
76     }
77 
78     /** Updates the contents in this row. This method is called only by the menu when necessary. */
update()79     public abstract void update();
80 
81     /** Indicates whether this row is shown in the menu. */
isVisible()82     public boolean isVisible() {
83         return true;
84     }
85 
86     /**
87      * Releases all the resources which need to be released. This method is called when the main
88      * menu is not available any more.
89      */
release()90     public void release() {}
91 
92     /** Returns the ID of the layout resource for this row. */
getLayoutResId()93     public abstract int getLayoutResId();
94 
95     /** Returns the ID of this row. This ID is used to select the row in the main menu. */
getId()96     public abstract String getId();
97 
98     /** This method is called when recent channels are changed. */
onRecentChannelsChanged()99     public void onRecentChannelsChanged() {}
100 
101     /** Returns whether to hide the title when the row is selected. */
hideTitleWhenSelected()102     public boolean hideTitleWhenSelected() {
103         return false;
104     }
105 
106     /**
107      * Sets if menu row is reselected.
108      *
109      * @param isReselected {@code true} if row is reselected;
110      * else {@code false}.
111      */
setIsReselected(boolean isReselected)112     public void setIsReselected(boolean isReselected) {
113         mIsReselected = isReselected;
114     }
115 
116     /** Returns true if row is reselected. */
isReselected()117     public boolean isReselected() {
118         return mIsReselected;
119     }
120 }
121