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