• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.dialer.speeddial;
18 
19 import android.support.annotation.StringRes;
20 import android.support.v7.widget.RecyclerView;
21 import android.view.View;
22 import android.view.View.OnClickListener;
23 import android.widget.Button;
24 import android.widget.TextView;
25 
26 /** ViewHolder for headers in {@link SpeedDialFragment}. */
27 public class HeaderViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
28 
29   private final SpeedDialHeaderListener listener;
30   private final TextView headerText;
31   private final Button addButton;
32 
HeaderViewHolder(View view, SpeedDialHeaderListener listener)33   public HeaderViewHolder(View view, SpeedDialHeaderListener listener) {
34     super(view);
35     this.listener = listener;
36     headerText = view.findViewById(R.id.speed_dial_header_text);
37     addButton = view.findViewById(R.id.speed_dial_add_button);
38     addButton.setOnClickListener(this);
39   }
40 
setHeaderText(@tringRes int header)41   public void setHeaderText(@StringRes int header) {
42     headerText.setText(header);
43   }
44 
showAddButton(boolean show)45   public void showAddButton(boolean show) {
46     addButton.setVisibility(show ? View.VISIBLE : View.GONE);
47   }
48 
49   @Override
onClick(View v)50   public void onClick(View v) {
51     listener.onAddFavoriteClicked();
52   }
53 
54   /** Listener/Callback for {@link HeaderViewHolder} parents. */
55   public interface SpeedDialHeaderListener {
56 
57     /** Called when the user wants to add a contact to their favorites. */
onAddFavoriteClicked()58     void onAddFavoriteClicked();
59   }
60 }
61