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 17 package com.android.car.developeroptions.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.car.developeroptions.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 } 64 isChecked()65 public boolean isChecked() { 66 return mSwitch.isChecked(); 67 } 68 setChecked(boolean checked)69 public void setChecked(boolean checked) { 70 mSwitch.setChecked(checked); 71 } 72 setListener(CompoundButton.OnCheckedChangeListener listener)73 public void setListener(CompoundButton.OnCheckedChangeListener listener) { 74 mSwitch.setOnCheckedChangeListener(listener); 75 } 76 getSwitch()77 public Switch getSwitch() { 78 return mSwitch; 79 } 80 } 81