• 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 import com.android.tv.R;
23 import com.android.tv.TvOptionsManager;
24 import com.android.tv.TvOptionsManager.OptionType;
25 
26 /** A class to define possible actions from main menu. */
27 public class MenuAction {
28     // Actions in the TV option row.
29     public static final MenuAction SELECT_CLOSED_CAPTION_ACTION =
30             new MenuAction(
31                     R.string.options_item_closed_caption,
32                     TvOptionsManager.OPTION_CLOSED_CAPTIONS,
33                     R.drawable.ic_tvoption_cc);
34     public static final MenuAction SELECT_DISPLAY_MODE_ACTION =
35             new MenuAction(
36                     R.string.options_item_display_mode,
37                     TvOptionsManager.OPTION_DISPLAY_MODE,
38                     R.drawable.ic_tvoption_aspect);
39     public static final MenuAction SYSTEMWIDE_PIP_ACTION =
40             new MenuAction(
41                     R.string.options_item_pip,
42                     TvOptionsManager.OPTION_SYSTEMWIDE_PIP,
43                     R.drawable.ic_tvoption_pip);
44     public static final MenuAction SELECT_AUDIO_LANGUAGE_ACTION =
45             new MenuAction(
46                     R.string.options_item_multi_audio,
47                     TvOptionsManager.OPTION_MULTI_AUDIO,
48                     R.drawable.ic_tvoption_multi_track);
49     public static final MenuAction MORE_CHANNELS_ACTION =
50             new MenuAction(
51                     R.string.options_item_more_channels,
52                     TvOptionsManager.OPTION_MORE_CHANNELS,
53                     R.drawable.ic_app_store);
54     public static final MenuAction DEV_ACTION =
55             new MenuAction(
56                     R.string.options_item_developer,
57                     TvOptionsManager.OPTION_DEVELOPER,
58                     R.drawable.quantum_ic_developer_mode_tv_white_48);
59     public static final MenuAction SETTINGS_ACTION =
60             new MenuAction(
61                     R.string.options_item_settings,
62                     TvOptionsManager.OPTION_SETTINGS,
63                     R.drawable.ic_settings);
64 
65     private final String mActionName;
66     private final int mActionNameResId;
67     @OptionType private final int mType;
68     private String mActionDescription;
69     private Drawable mDrawable;
70     private int mDrawableResId;
71     private boolean mEnabled = true;
72 
73     /** Sets the action description. Returns {@code trye} if the description is changed. */
setActionDescription(MenuAction action, String actionDescription)74     public static boolean setActionDescription(MenuAction action, String actionDescription) {
75         String oldDescription = action.mActionDescription;
76         action.mActionDescription = actionDescription;
77         return !TextUtils.equals(action.mActionDescription, oldDescription);
78     }
79 
80     /** Enables or disables the action. Returns {@code true} if the value is changed. */
setEnabled(MenuAction action, boolean enabled)81     public static boolean setEnabled(MenuAction action, boolean enabled) {
82         boolean changed = action.mEnabled != enabled;
83         action.mEnabled = enabled;
84         return changed;
85     }
86 
MenuAction(int actionNameResId, int type, int drawableResId)87     public MenuAction(int actionNameResId, int type, int drawableResId) {
88         mActionName = null;
89         mActionNameResId = actionNameResId;
90         mType = type;
91         mDrawable = null;
92         mDrawableResId = drawableResId;
93     }
94 
MenuAction(String actionName, int type, Drawable drawable)95     public MenuAction(String actionName, int type, Drawable drawable) {
96         mActionName = actionName;
97         mActionNameResId = 0;
98         mType = type;
99         mDrawable = drawable;
100         mDrawableResId = 0;
101     }
102 
getActionName(Context context)103     public String getActionName(Context context) {
104         if (!TextUtils.isEmpty(mActionName)) {
105             return mActionName;
106         }
107         return context.getString(mActionNameResId);
108     }
109 
getActionDescription()110     public String getActionDescription() {
111         return mActionDescription;
112     }
113 
114     @OptionType
getType()115     public int getType() {
116         return mType;
117     }
118 
119     /** Returns Drawable. */
getDrawable(Context context)120     public Drawable getDrawable(Context context) {
121         if (mDrawable == null) {
122             mDrawable = context.getDrawable(mDrawableResId);
123         }
124         return mDrawable;
125     }
126 
isEnabled()127     public boolean isEnabled() {
128         return mEnabled;
129     }
130 
getActionNameResId()131     public int getActionNameResId() {
132         return mActionNameResId;
133     }
134 }
135