blob: ee3143c3942f10b92f66c45f61a7871449bc0f56 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
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
17package com.android.settings;
18
19import android.content.Context;
20import android.preference.EditTextPreference;
21import android.text.method.DigitsKeyListener;
22import android.text.method.PasswordTransformationMethod;
23import android.util.AttributeSet;
24import android.view.View;
25import android.widget.EditText;
26
27import java.util.Map;
28
29/**
30 * TODO: Add a soft dialpad for PIN entry.
31 */
32class EditPinPreference extends EditTextPreference {
33
34 private boolean mDialogOpen;
35
36 interface OnPinEnteredListener {
37 void onPinEntered(EditPinPreference preference, boolean positiveResult);
38 }
39
40 private OnPinEnteredListener mPinListener;
41
42 public EditPinPreference(Context context, AttributeSet attrs) {
43 super(context, attrs);
44 }
45
46 public EditPinPreference(Context context, AttributeSet attrs, int defStyle) {
47 super(context, attrs, defStyle);
48 }
49
50 public void setOnPinEnteredListener(OnPinEnteredListener listener) {
51 mPinListener = listener;
52 }
53
54 @Override
55 protected void onBindDialogView(View view) {
56 super.onBindDialogView(view);
57
58 final EditText editText = (EditText) view.findViewById(android.R.id.edit);
59
60 if (editText != null) {
61 editText.setSingleLine(true);
62 editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
63 editText.setKeyListener(DigitsKeyListener.getInstance());
64 }
65 }
66
67 public boolean isDialogOpen() {
68 return mDialogOpen;
69 }
70
71 @Override
72 protected void onDialogClosed(boolean positiveResult) {
73 super.onDialogClosed(positiveResult);
74 mDialogOpen = false;
75 if (mPinListener != null) {
76 mPinListener.onPinEntered(this, positiveResult);
77 }
78 }
79
80 public void showPinDialog() {
81 mDialogOpen = true;
82 showDialog(null);
83 }
84}