blob: 1877d43af02e381ea0307aafe83430585851547e [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;
Gilles Debunne32073592012-05-16 16:46:12 +020022import android.text.InputType;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080023import android.util.AttributeSet;
24import android.view.View;
25import android.widget.EditText;
26
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080027/**
28 * TODO: Add a soft dialpad for PIN entry.
29 */
30class EditPinPreference extends EditTextPreference {
31
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080032 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 Yamasani11cd8c52009-08-28 15:36:52 -070049
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080050 @Override
51 protected void onBindDialogView(View view) {
52 super.onBindDialogView(view);
Amith Yamasani11cd8c52009-08-28 15:36:52 -070053
Gilles Debunne32073592012-05-16 16:46:12 +020054 final EditText editText = getEditText();
Amith Yamasani11cd8c52009-08-28 15:36:52 -070055
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080056 if (editText != null) {
Gilles Debunne32073592012-05-16 16:46:12 +020057 editText.setInputType(InputType.TYPE_CLASS_NUMBER |
58 InputType.TYPE_NUMBER_VARIATION_PASSWORD);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080059 }
60 }
61
62 public boolean isDialogOpen() {
Amith Yamasani11cd8c52009-08-28 15:36:52 -070063 Dialog dialog = getDialog();
64 return dialog != null && dialog.isShowing();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080065 }
Amith Yamasani11cd8c52009-08-28 15:36:52 -070066
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080067 @Override
68 protected void onDialogClosed(boolean positiveResult) {
69 super.onDialogClosed(positiveResult);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080070 if (mPinListener != null) {
71 mPinListener.onPinEntered(this, positiveResult);
72 }
73 }
Amith Yamasani11cd8c52009-08-28 15:36:52 -070074
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080075 public void showPinDialog() {
Amith Yamasani11cd8c52009-08-28 15:36:52 -070076 Dialog dialog = getDialog();
77 if (dialog == null || !dialog.isShowing()) {
78 showDialog(null);
79 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080 }
81}