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.customization;
18
19import android.content.Intent;
20import android.graphics.drawable.Drawable;
21import android.support.annotation.NonNull;
22
23/**
24 * Describes a custom option defined in customization package.
25 * This will be added to main menu.
26 */
27public class CustomAction implements Comparable<CustomAction> {
28    private static final int POSITION_THRESHOLD = 100;
29
30    private final int mPositionPriority;
31    private final String mTitle;
32    private final Drawable mIconDrawable;
33    private final Intent mIntent;
34
35    public CustomAction(int positionPriority, String title, Drawable iconDrawable, Intent intent) {
36        mPositionPriority = positionPriority;
37        mTitle = title;
38        mIconDrawable = iconDrawable;
39        mIntent = intent;
40    }
41
42    /**
43     * Returns if this option comes before the existing items.
44     * Note that custom options can only be placed at the front or back.
45     * (i.e. cannot be added in the middle of existing options.)
46     * @return {@code true} if it goes to the beginning. {@code false} if it goes to the end.
47     */
48    public boolean isFront() {
49        return mPositionPriority < POSITION_THRESHOLD;
50    }
51
52    @Override
53    public int compareTo(@NonNull CustomAction another) {
54        return mPositionPriority - another.mPositionPriority;
55    }
56
57    /**
58     * Returns title.
59     */
60    public String getTitle() {
61        return mTitle;
62    }
63
64    /**
65     * Returns icon drawable.
66     */
67    public Drawable getIconDrawable() {
68        return mIconDrawable;
69    }
70
71    /**
72     * Returns intent to launch when this option is clicked.
73     */
74    public Intent getIntent() {
75        return mIntent;
76    }
77}
78