1 /*
2  * Copyright (C) 2020 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.settings.widget;
17 
18 import android.content.Context;
19 import android.util.AttributeSet;
20 import android.view.View;
21 
22 import androidx.preference.PreferenceViewHolder;
23 
24 import com.android.settingslib.RestrictedSwitchPreference;
25 
26 /**
27  * This widget with enabled filterTouchesWhenObscured attribute use to replace
28  * the {@link RestrictedSwitchPreference} in the Special access app pages for
29  * security.
30  */
31 public class FilterTouchesRestrictedSwitchPreference extends RestrictedSwitchPreference {
FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)32     public FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs,
33             int defStyleAttr, int defStyleRes) {
34         super(context, attrs, defStyleAttr, defStyleRes);
35     }
36 
FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr)37     public FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs,
38             int defStyleAttr) {
39         super(context, attrs, defStyleAttr);
40     }
41 
FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs)42     public FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs) {
43         super(context, attrs);
44     }
45 
FilterTouchesRestrictedSwitchPreference(Context context)46     public FilterTouchesRestrictedSwitchPreference(Context context) {
47         super(context);
48     }
49 
50     @Override
onBindViewHolder(PreferenceViewHolder holder)51     public void onBindViewHolder(PreferenceViewHolder holder) {
52         super.onBindViewHolder(holder);
53         final View switchView = holder.findViewById(androidx.preference.R.id.switchWidget);
54         if (switchView != null) {
55             final View rootView = switchView.getRootView();
56             rootView.setFilterTouchesWhenObscured(true);
57         }
58     }
59 }
60