The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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; |
| 18 | |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 19 | import android.app.Dialog; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Gilles Debunne | 3207359 | 2012-05-16 16:46:12 +0200 | [diff] [blame] | 21 | import android.text.InputType; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 22 | import android.util.AttributeSet; |
| 23 | import android.view.View; |
| 24 | import android.widget.EditText; |
| 25 | |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 26 | import com.android.settingslib.CustomEditTextPreferenceCompat; |
Juan Lang | 4482812 | 2017-05-10 17:26:02 -0700 | [diff] [blame] | 27 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 28 | /** |
| 29 | * TODO: Add a soft dialpad for PIN entry. |
| 30 | */ |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 31 | class EditPinPreference extends CustomEditTextPreferenceCompat { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 32 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 33 | interface OnPinEnteredListener { |
| 34 | void onPinEntered(EditPinPreference preference, boolean positiveResult); |
| 35 | } |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 36 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 37 | private OnPinEnteredListener mPinListener; |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 38 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 39 | public EditPinPreference(Context context, AttributeSet attrs) { |
| 40 | super(context, attrs); |
| 41 | } |
| 42 | |
| 43 | public EditPinPreference(Context context, AttributeSet attrs, int defStyle) { |
| 44 | super(context, attrs, defStyle); |
| 45 | } |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 46 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 47 | public void setOnPinEnteredListener(OnPinEnteredListener listener) { |
| 48 | mPinListener = listener; |
| 49 | } |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 50 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 51 | @Override |
| 52 | protected void onBindDialogView(View view) { |
| 53 | super.onBindDialogView(view); |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 54 | |
Jason Monk | 5b39710 | 2016-03-30 11:41:45 -0400 | [diff] [blame] | 55 | final EditText editText = (EditText) view.findViewById(android.R.id.edit); |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 56 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 57 | if (editText != null) { |
Gilles Debunne | 3207359 | 2012-05-16 16:46:12 +0200 | [diff] [blame] | 58 | editText.setInputType(InputType.TYPE_CLASS_NUMBER | |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 59 | InputType.TYPE_NUMBER_VARIATION_PASSWORD); |
Doris Ling | 807ee34 | 2018-04-17 16:24:19 -0700 | [diff] [blame] | 60 | editText.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | public boolean isDialogOpen() { |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 65 | Dialog dialog = getDialog(); |
| 66 | return dialog != null && dialog.isShowing(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 67 | } |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 68 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 69 | @Override |
| 70 | protected void onDialogClosed(boolean positiveResult) { |
| 71 | super.onDialogClosed(positiveResult); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 72 | if (mPinListener != null) { |
| 73 | mPinListener.onPinEntered(this, positiveResult); |
| 74 | } |
| 75 | } |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 76 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 77 | public void showPinDialog() { |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 78 | Dialog dialog = getDialog(); |
| 79 | if (dialog == null || !dialog.isShowing()) { |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 80 | onClick(); |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 81 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 82 | } |
| 83 | } |