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.view.View; 21 22 /** 23 * A base class of the item which will be displayed in the main menu. 24 * It contains the data such as title to represent a row. 25 * This is an abstract class and the sub-class could have it's own data for 26 * the row. 27 */ 28 public abstract class MenuRow { 29 private final Context mContext; 30 private final String mTitle; 31 private final int mHeight; 32 private final Menu mMenu; 33 34 private MenuRowView mMenuRowView; 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 /** 49 * Returns the context. 50 */ getContext()51 protected Context getContext() { 52 return mContext; 53 } 54 55 /** 56 * Returns the menu object. 57 */ getMenu()58 public Menu getMenu() { 59 return mMenu; 60 } 61 62 /** 63 * Returns the title of this row. 64 */ getTitle()65 public String getTitle() { 66 return mTitle; 67 } 68 69 /** 70 * Returns the height of this row. 71 */ getHeight()72 public int getHeight() { 73 return mHeight; 74 } 75 76 /** 77 * Sets the menu row view. 78 */ setMenuRowView(MenuRowView menuRowView)79 public void setMenuRowView(MenuRowView menuRowView) { 80 mMenuRowView = menuRowView; 81 } 82 83 /** 84 * Returns the menu row view. 85 */ getMenuRowView()86 protected MenuRowView getMenuRowView() { 87 return mMenuRowView; 88 } 89 90 /** 91 * Updates the contents in this row. 92 * This method is called only by the menu when necessary. 93 */ update()94 abstract public void update(); 95 96 /** 97 * Indicates whether this row is shown in the menu. 98 */ isVisible()99 public boolean isVisible() { 100 return true; 101 } 102 103 /** 104 * Releases all the resources which need to be released. 105 * This method is called when the main menu is not available any more. 106 */ release()107 public void release() { 108 } 109 110 /** 111 * Returns the ID of the layout resource for this row. 112 */ getLayoutResId()113 abstract public int getLayoutResId(); 114 115 /** 116 * Returns the ID of this row. This ID is used to select the row in the main menu. 117 */ getId()118 abstract public String getId(); 119 120 /** 121 * This method is called when recent channels are changed. 122 */ onRecentChannelsChanged()123 public void onRecentChannelsChanged() { } 124 125 /** 126 * Returns whether to hide the title when the row is selected. 127 */ hideTitleWhenSelected()128 public boolean hideTitleWhenSelected() { 129 return false; 130 } 131 } 132