blob: 362bed1bd69b99a9e94eb9ac201bd5fd6b3d54a2 [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
Amith Yamasani11cd8c52009-08-28 15:36:52 -070019import android.app.Dialog;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080020import android.content.Context;
21import android.preference.EditTextPreference;
22import android.text.method.DigitsKeyListener;
23import android.text.method.PasswordTransformationMethod;
24import android.util.AttributeSet;
25import android.view.View;
26import android.widget.EditText;
27
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080028/**
29 * TODO: Add a soft dialpad for PIN entry.
30 */
31class EditPinPreference extends EditTextPreference {
32
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080033 interface OnPinEnteredListener {
34 void onPinEntered(EditPinPreference preference, boolean positiveResult);
35 }
36
37 private OnPinEnteredListener mPinListener;
38
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 }
46
47 public void setOnPinEnteredListener(OnPinEnteredListener listener) {
48 mPinListener = listener;
49 }
Amith Yamasani11cd8c52009-08-28 15:36:52 -070050
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080051 @Override
52 protected void onBindDialogView(View view) {
53 super.onBindDialogView(view);
Amith Yamasani11cd8c52009-08-28 15:36:52 -070054
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080055 final EditText editText = (EditText) view.findViewById(android.R.id.edit);
Amith Yamasani11cd8c52009-08-28 15:36:52 -070056
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080057 if (editText != null) {
58 editText.setSingleLine(true);
59 editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
60 editText.setKeyListener(DigitsKeyListener.getInstance());
61 }
62 }
63
64 public boolean isDialogOpen() {
Amith Yamasani11cd8c52009-08-28 15:36:52 -070065 Dialog dialog = getDialog();
66 return dialog != null && dialog.isShowing();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080067 }
Amith Yamasani11cd8c52009-08-28 15:36:52 -070068
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080069 @Override
70 protected void onDialogClosed(boolean positiveResult) {
71 super.onDialogClosed(positiveResult);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080072 if (mPinListener != null) {
73 mPinListener.onPinEntered(this, positiveResult);
74 }
75 }
Amith Yamasani11cd8c52009-08-28 15:36:52 -070076
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080077 public void showPinDialog() {
Amith Yamasani11cd8c52009-08-28 15:36:52 -070078 Dialog dialog = getDialog();
79 if (dialog == null || !dialog.isShowing()) {
80 showDialog(null);
81 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082 }
83}