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