1 /*
2  * Copyright (C) 2019 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 package com.android.settingslib.wifi;
17 
18 import android.content.Context;
19 
20 import androidx.fragment.app.Fragment;
21 import androidx.preference.PreferenceViewHolder;
22 
23 import com.android.wifitrackerlib.WifiEntry;
24 
25 /**
26  * WifiEntryPreference that can be long pressed.
27  */
28 public class LongPressWifiEntryPreference extends WifiEntryPreference {
29 
30     private final Fragment mFragment;
31 
LongPressWifiEntryPreference(Context context, WifiEntry wifiEntry, Fragment fragment)32     public LongPressWifiEntryPreference(Context context, WifiEntry wifiEntry, Fragment fragment) {
33         super(context, wifiEntry);
34         mFragment = fragment;
35     }
36 
37     @Override
onBindViewHolder(final PreferenceViewHolder view)38     public void onBindViewHolder(final PreferenceViewHolder view) {
39         super.onBindViewHolder(view);
40         if (mFragment != null) {
41             view.itemView.setOnCreateContextMenuListener(mFragment);
42             view.itemView.setTag(this);
43             view.itemView.setLongClickable(true);
44         }
45     }
46 }
47