• 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 import android.graphics.drawable.Drawable;
21 import android.text.TextUtils;
22 
23 import com.android.tv.MainActivity;
24 import com.android.tv.R;
25 import com.android.tv.TvOptionsManager;
26 
27 /**
28  * A class to define possible actions from main menu.
29  */
30 public class MenuAction {
31     // Actions in the TV option row.
32     public static final MenuAction SELECT_CLOSED_CAPTION_ACTION =
33             new MenuAction(R.string.options_item_closed_caption,
34                     TvOptionsManager.OPTION_CLOSED_CAPTIONS,
35                     R.drawable.ic_tvoption_cc);
36     public static final MenuAction SELECT_DISPLAY_MODE_ACTION =
37             new MenuAction(R.string.options_item_display_mode, TvOptionsManager.OPTION_DISPLAY_MODE,
38                     R.drawable.ic_tvoption_aspect);
39     public static final MenuAction PIP_IN_APP_ACTION =
40             new MenuAction(R.string.options_item_pip, TvOptionsManager.OPTION_IN_APP_PIP,
41                     R.drawable.ic_tvoption_pip);
42     public static final MenuAction SYSTEMWIDE_PIP_ACTION =
43             new MenuAction(R.string.options_item_pip, TvOptionsManager.OPTION_SYSTEMWIDE_PIP,
44                     R.drawable.ic_pip_option_layout2);
45     public static final MenuAction SELECT_AUDIO_LANGUAGE_ACTION =
46             new MenuAction(R.string.options_item_multi_audio, TvOptionsManager.OPTION_MULTI_AUDIO,
47                     R.drawable.ic_tvoption_multi_track);
48     public static final MenuAction MORE_CHANNELS_ACTION =
49             new MenuAction(R.string.options_item_more_channels,
50                     TvOptionsManager.OPTION_MORE_CHANNELS, R.drawable.ic_store);
51     public static final MenuAction DEV_ACTION =
52             new MenuAction(R.string.options_item_developer,
53                     TvOptionsManager.OPTION_DEVELOPER, R.drawable.ic_developer_mode_tv_white_48dp);
54     // TODO: Change the icon.
55     public static final MenuAction SETTINGS_ACTION =
56             new MenuAction(R.string.options_item_settings, TvOptionsManager.OPTION_SETTINGS,
57                     R.drawable.ic_settings);
58     // Actions in the PIP option row.
59     public static final MenuAction PIP_SELECT_INPUT_ACTION =
60             new MenuAction(R.string.pip_options_item_source, TvOptionsManager.OPTION_PIP_INPUT,
61                     R.drawable.ic_pip_option_input);
62     public static final MenuAction PIP_SWAP_ACTION =
63             new MenuAction(R.string.pip_options_item_swap, TvOptionsManager.OPTION_PIP_SWAP,
64                     R.drawable.ic_pip_option_swap);
65     public static final MenuAction PIP_SOUND_ACTION =
66             new MenuAction(R.string.pip_options_item_sound, TvOptionsManager.OPTION_PIP_SOUND,
67                     R.drawable.ic_pip_option_swap_audio);
68     public static final MenuAction PIP_LAYOUT_ACTION =
69             new MenuAction(R.string.pip_options_item_layout, TvOptionsManager.OPTION_PIP_LAYOUT,
70                     R.drawable.ic_pip_option_layout1);
71     public static final MenuAction PIP_SIZE_ACTION =
72             new MenuAction(R.string.pip_options_item_size, TvOptionsManager.OPTION_PIP_SIZE,
73                     R.drawable.ic_pip_option_size);
74 
75     private final String mActionName;
76     private final int mActionNameResId;
77     private final int mType;
78     private Drawable mDrawable;
79     private int mDrawableResId;
80     private boolean mEnabled = true;
81 
MenuAction(int actionNameResId, int type, int drawableResId)82     public MenuAction(int actionNameResId, int type, int drawableResId) {
83         mActionName = null;
84         mActionNameResId = actionNameResId;
85         mType = type;
86         mDrawable = null;
87         mDrawableResId = drawableResId;
88     }
89 
MenuAction(String actionName, int type, Drawable drawable)90     public MenuAction(String actionName, int type, Drawable drawable) {
91         mActionName = actionName;
92         mActionNameResId = 0;
93         mType = type;
94         mDrawable = drawable;
95         mDrawableResId = 0;
96     }
97 
getActionName(Context context)98     public String getActionName(Context context) {
99         if (!TextUtils.isEmpty(mActionName)) {
100             return mActionName;
101         }
102         return context.getString(mActionNameResId);
103     }
104 
getActionDescription(Context context)105     public String getActionDescription(Context context) {
106         return ((MainActivity) context).getTvOptionsManager().getOptionString(mType);
107     }
108 
getType()109     public int getType() {
110         return mType;
111     }
112 
113     /**
114      * Returns Drawable.
115      */
getDrawable(Context context)116     public Drawable getDrawable(Context context) {
117         if (mDrawable == null) {
118             mDrawable = context.getDrawable(mDrawableResId);
119         }
120         return mDrawable;
121     }
122 
123     /**
124      * Sets drawable resource id.
125      *
126      * @return {@code true} if drawable is changed.
127      */
setDrawableResId(int resId)128     public boolean setDrawableResId(int resId) {
129         if (mDrawableResId == resId) {
130             return false;
131         }
132         mDrawable = null;
133         mDrawableResId = resId;
134         return true;
135     }
136 
isEnabled()137     public boolean isEnabled() {
138         return mEnabled;
139     }
140 
setEnabled(boolean enabled)141     public void setEnabled(boolean enabled) {
142         mEnabled = enabled;
143     }
144 
getActionNameResId()145     public int getActionNameResId() {
146         return mActionNameResId;
147     }
148 }
149