1 /*
2  * Copyright (C) 2016 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.settings;
18 
19 import android.content.Context;
20 import android.support.v7.preference.Preference;
21 import android.support.v7.preference.PreferenceViewHolder;
22 import android.util.AttributeSet;
23 import android.view.View;
24 
25 public class LongClickPreference extends Preference implements View.OnLongClickListener {
26 
27     public interface OnLongClickListener {
onPreferenceLongClick(Preference preference)28         boolean onPreferenceLongClick(Preference preference);
29     }
30 
31     private OnLongClickListener mLongClickListener;
32 
LongClickPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)33     public LongClickPreference(Context context, AttributeSet attrs,
34             int defStyleAttr, int defStyleRes) {
35         super(context, attrs, defStyleAttr, defStyleRes);
36     }
37 
LongClickPreference(Context context, AttributeSet attrs, int defStyleAttr)38     public LongClickPreference(Context context, AttributeSet attrs,
39             int defStyleAttr) {
40         super(context, attrs, defStyleAttr);
41     }
42 
LongClickPreference(Context context, AttributeSet attrs)43     public LongClickPreference(Context context, AttributeSet attrs) {
44         super(context, attrs);
45     }
46 
LongClickPreference(Context context)47     public LongClickPreference(Context context) {
48         super(context);
49     }
50 
51     @Override
onBindViewHolder(PreferenceViewHolder holder)52     public void onBindViewHolder(PreferenceViewHolder holder) {
53         super.onBindViewHolder(holder);
54         holder.itemView.setLongClickable(true);
55         holder.itemView.setOnLongClickListener(this);
56     }
57 
58     @Override
onLongClick(View v)59     public boolean onLongClick(View v) {
60         return mLongClickListener != null && mLongClickListener.onPreferenceLongClick(this);
61     }
62 
setLongClickListener(OnLongClickListener longClickListener)63     public void setLongClickListener(OnLongClickListener longClickListener) {
64         mLongClickListener = longClickListener;
65     }
66 }
67