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.tv.dialog.picker; 17 18 import static android.content.Context.ACCESSIBILITY_SERVICE; 19 20 import android.content.Context; 21 import androidx.leanback.widget.picker.PinPicker; 22 import android.util.AttributeSet; 23 import android.view.accessibility.AccessibilityManager; 24 25 /** 4 digit picker */ 26 public final class TvPinPicker extends PinPicker { 27 28 private boolean mSkipPerformClick = true; 29 private boolean mIsAccessibilityEnabled = false; 30 TvPinPicker(Context context, AttributeSet attributeSet)31 public TvPinPicker(Context context, AttributeSet attributeSet) { 32 this(context, attributeSet, 0); 33 } 34 TvPinPicker(Context context, AttributeSet attributeSet, int defStyleAttr)35 public TvPinPicker(Context context, AttributeSet attributeSet, int defStyleAttr) { 36 super(context, attributeSet, defStyleAttr); 37 setActivated(true); 38 AccessibilityManager am = 39 (AccessibilityManager) context.getSystemService(ACCESSIBILITY_SERVICE); 40 mIsAccessibilityEnabled = am.isEnabled(); 41 } 42 43 @Override performClick()44 public boolean performClick() { 45 // (b/120096347) Skip first click when talkback is enabled 46 if (mSkipPerformClick && mIsAccessibilityEnabled) { 47 mSkipPerformClick = false; 48 /* Force focus to next value */ 49 setColumnValue(getSelectedColumn(), 1, true); 50 return false; 51 } 52 return super.performClick(); 53 } 54 } 55