• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.car.settings.suggestions;
18 
19 import android.graphics.drawable.Drawable;
20 import android.view.View;
21 
22 import com.android.car.list.ActionIconButtonLineItem;
23 
24 /**
25  * Represents suggestion list item.
26  */
27 public class SuggestionLineItem extends ActionIconButtonLineItem {
28 
29     private final CharSequence mSummary;
30     private final View.OnClickListener mOnClickListener;
31     private final ActionListener mActionListener;
32 
33     /**
34      * Creates a {@link SuggestionLineItem} with title, summary, icons, and click handlers.
35      */
SuggestionLineItem( CharSequence title, CharSequence summary, Drawable iconDrawable, CharSequence primaryAction, CharSequence secondaryAction, View.OnClickListener onClickListener, ActionListener actionListener)36     public SuggestionLineItem(
37             CharSequence title,
38             CharSequence summary,
39             Drawable iconDrawable,
40             CharSequence primaryAction,
41             CharSequence secondaryAction,
42             View.OnClickListener onClickListener,
43             ActionListener actionListener) {
44         super(title, primaryAction, secondaryAction, iconDrawable);
45         mSummary = summary;
46         mOnClickListener = onClickListener;
47         mActionListener = actionListener;
48     }
49 
50     @Override
getDesc()51     public CharSequence getDesc() {
52         return mSummary;
53     }
54 
55     @Override
isExpandable()56     public boolean isExpandable() {
57         return true;
58     }
59 
60     @Override
onClick(View view)61     public void onClick(View view) {
62         mOnClickListener.onClick(view);
63     }
64 
65     @Override
onSecondaryActionButtonClick(int adapterPosition)66     public void onSecondaryActionButtonClick(int adapterPosition) {
67         mActionListener.onSuggestionItemDismissed(adapterPosition);
68     }
69 
70     @Override
onPrimaryActionButtonClick(View view)71     public void onPrimaryActionButtonClick(View view) {
72         onClick(view);
73     }
74 
75     /**
76      * Interface that surfaces events on the suggestion.
77      */
78     public interface ActionListener {
79 
80         /**
81          * Invoked when a suggestions item is dismissed.
82          *
83          * @param adapterPosition the position of the suggestion item in it's adapter.
84          */
onSuggestionItemDismissed(int adapterPosition)85         void onSuggestionItemDismissed(int adapterPosition);
86     }
87 }
88