1 /* 2 * Copyright (C) 2018 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 17 package com.android.settings.biometrics.face; 18 19 import android.content.Context; 20 import android.content.res.TypedArray; 21 import android.util.AttributeSet; 22 import android.view.LayoutInflater; 23 import android.widget.CompoundButton; 24 import android.widget.LinearLayout; 25 import android.widget.Switch; 26 import android.widget.TextView; 27 28 import com.android.settings.R; 29 30 /** 31 * A layout that contains a start-justified title, and an end-justified switch. 32 */ 33 public class FaceEnrollAccessibilityToggle extends LinearLayout { 34 35 private Switch mSwitch; 36 FaceEnrollAccessibilityToggle(Context context)37 public FaceEnrollAccessibilityToggle(Context context) { 38 this(context, null /* attrs */); 39 } 40 FaceEnrollAccessibilityToggle(Context context, AttributeSet attrs)41 public FaceEnrollAccessibilityToggle(Context context, AttributeSet attrs) { 42 this(context, attrs, 0); 43 } 44 FaceEnrollAccessibilityToggle(Context context, AttributeSet attrs, int defStyleAttr)45 public FaceEnrollAccessibilityToggle(Context context, AttributeSet attrs, int defStyleAttr) { 46 super(context, attrs, defStyleAttr); 47 48 LayoutInflater.from(context).inflate(R.layout.face_enroll_accessibility_toggle, 49 this, true /* attachToRoot */); 50 51 final TypedArray a = 52 context.obtainStyledAttributes(attrs, R.styleable.FaceEnrollAccessibilityToggle); 53 try { 54 final CharSequence title = 55 a.getText(R.styleable.FaceEnrollAccessibilityToggle_messageText); 56 final TextView titleTextView = findViewById(R.id.title); 57 titleTextView.setText(title); 58 } finally { 59 a.recycle(); 60 } 61 mSwitch = findViewById(R.id.toggle); 62 mSwitch.setChecked(false); 63 mSwitch.setClickable(false); 64 mSwitch.setFocusable(false); 65 } 66 isChecked()67 public boolean isChecked() { 68 return mSwitch.isChecked(); 69 } 70 setChecked(boolean checked)71 public void setChecked(boolean checked) { 72 mSwitch.setChecked(checked); 73 } 74 setListener(CompoundButton.OnCheckedChangeListener listener)75 public void setListener(CompoundButton.OnCheckedChangeListener listener) { 76 mSwitch.setOnCheckedChangeListener(listener); 77 } 78 getSwitch()79 public Switch getSwitch() { 80 return mSwitch; 81 } 82 } 83