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
17package com.android.tv.ui.sidepanel;
18
19import android.view.View;
20import android.widget.ImageView;
21import android.widget.TextView;
22
23import com.android.tv.R;
24
25public abstract class ActionItem extends Item {
26    private final String mTitle;
27    private final String mDescription;
28    private final int mIconId;
29
30    public ActionItem(String title) {
31        this(title, null, 0);
32    }
33
34    public ActionItem(String title, String description) {
35        this(title, description, 0);
36    }
37
38    public ActionItem(String title, int iconId) {
39        this(title, null, iconId);
40    }
41
42    public ActionItem(String title, String description, int iconId) {
43        mTitle = title;
44        mDescription = description;
45        mIconId = iconId;
46    }
47
48    @Override
49    protected int getResourceId() {
50        return R.layout.option_item_action;
51    }
52
53    @Override
54    protected void onBind(View view) {
55        super.onBind(view);
56        TextView titleView = (TextView) view.findViewById(R.id.title);
57        titleView.setText(mTitle);
58        TextView descriptionView = (TextView) view.findViewById(R.id.description);
59        if (mDescription != null) {
60            descriptionView.setVisibility(View.VISIBLE);
61            descriptionView.setText(mDescription);
62        } else {
63            descriptionView.setVisibility(View.GONE);
64        }
65        ImageView iconView = (ImageView) view.findViewById(R.id.icon);
66        if (mIconId != 0) {
67            iconView.setVisibility(View.VISIBLE);
68            iconView.setImageResource(mIconId);
69        } else {
70            iconView.setVisibility(View.GONE);
71        }
72    }
73}