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