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