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; |
| 21 | import android.preference.EditTextPreference; |
Gilles Debunne | 3207359 | 2012-05-16 16:46:12 +0200 | [diff] [blame^] | 22 | import android.text.InputType; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 23 | import android.util.AttributeSet; |
| 24 | import android.view.View; |
| 25 | import android.widget.EditText; |
| 26 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 27 | /** |
| 28 | * TODO: Add a soft dialpad for PIN entry. |
| 29 | */ |
| 30 | class EditPinPreference extends EditTextPreference { |
| 31 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 32 | interface OnPinEnteredListener { |
| 33 | void onPinEntered(EditPinPreference preference, boolean positiveResult); |
| 34 | } |
| 35 | |
| 36 | private OnPinEnteredListener mPinListener; |
| 37 | |
| 38 | public EditPinPreference(Context context, AttributeSet attrs) { |
| 39 | super(context, attrs); |
| 40 | } |
| 41 | |
| 42 | public EditPinPreference(Context context, AttributeSet attrs, int defStyle) { |
| 43 | super(context, attrs, defStyle); |
| 44 | } |
| 45 | |
| 46 | public void setOnPinEnteredListener(OnPinEnteredListener listener) { |
| 47 | mPinListener = listener; |
| 48 | } |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 49 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 50 | @Override |
| 51 | protected void onBindDialogView(View view) { |
| 52 | super.onBindDialogView(view); |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 53 | |
Gilles Debunne | 3207359 | 2012-05-16 16:46:12 +0200 | [diff] [blame^] | 54 | final EditText editText = getEditText(); |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 55 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 56 | if (editText != null) { |
Gilles Debunne | 3207359 | 2012-05-16 16:46:12 +0200 | [diff] [blame^] | 57 | editText.setInputType(InputType.TYPE_CLASS_NUMBER | |
| 58 | InputType.TYPE_NUMBER_VARIATION_PASSWORD); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | public boolean isDialogOpen() { |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 63 | Dialog dialog = getDialog(); |
| 64 | return dialog != null && dialog.isShowing(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 65 | } |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 66 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 67 | @Override |
| 68 | protected void onDialogClosed(boolean positiveResult) { |
| 69 | super.onDialogClosed(positiveResult); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 70 | if (mPinListener != null) { |
| 71 | mPinListener.onPinEntered(this, positiveResult); |
| 72 | } |
| 73 | } |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 74 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 75 | public void showPinDialog() { |
Amith Yamasani | 11cd8c5 | 2009-08-28 15:36:52 -0700 | [diff] [blame] | 76 | Dialog dialog = getDialog(); |
| 77 | if (dialog == null || !dialog.isShowing()) { |
| 78 | showDialog(null); |
| 79 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 80 | } |
| 81 | } |