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