2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import android.app.Dialog;
20 import android.content.Context;
21 import android.preference.EditTextPreference;
22 import android.text.method.DigitsKeyListener;
23 import android.text.method.PasswordTransformationMethod;
24 import android.util.AttributeSet;
25 import android.view.View;
26 import android.widget.EditText;
29 * TODO: Add a soft dialpad for PIN entry.
31 class EditPinPreference extends EditTextPreference {
33 interface OnPinEnteredListener {
34 void onPinEntered(EditPinPreference preference, boolean positiveResult);
37 private OnPinEnteredListener mPinListener;
39 public EditPinPreference(Context context, AttributeSet attrs) {
40 super(context, attrs);
43 public EditPinPreference(Context context, AttributeSet attrs, int defStyle) {
44 super(context, attrs, defStyle);
47 public void setOnPinEnteredListener(OnPinEnteredListener listener) {
48 mPinListener = listener;
52 protected void onBindDialogView(View view) {
53 super.onBindDialogView(view);
55 final EditText editText = (EditText) view.findViewById(android.R.id.edit);
57 if (editText != null) {
58 editText.setSingleLine(true);
59 editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
60 editText.setKeyListener(DigitsKeyListener.getInstance());
64 public boolean isDialogOpen() {
65 Dialog dialog = getDialog();
66 return dialog != null && dialog.isShowing();
70 protected void onDialogClosed(boolean positiveResult) {
71 super.onDialogClosed(positiveResult);
72 if (mPinListener != null) {
73 mPinListener.onPinEntered(this, positiveResult);
77 public void showPinDialog() {
78 Dialog dialog = getDialog();
79 if (dialog == null || !dialog.isShowing()) {