blob: e53a2bfe8c38ce7ef5fadfba277501cd7ce7ec60 [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;
Gilles Debunne32073592012-05-16 16:46:12 +020021import android.text.InputType;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080022import android.util.AttributeSet;
23import android.view.View;
24import android.widget.EditText;
25
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080026/**
27 * TODO: Add a soft dialpad for PIN entry.
28 */
Jason Monk39b46742015-09-10 15:52:51 -040029class EditPinPreference extends CustomEditTextPreference {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080030
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080031 interface OnPinEnteredListener {
32 void onPinEntered(EditPinPreference preference, boolean positiveResult);
33 }
34
35 private OnPinEnteredListener mPinListener;
36
37 public EditPinPreference(Context context, AttributeSet attrs) {
38 super(context, attrs);
39 }
40
41 public EditPinPreference(Context context, AttributeSet attrs, int defStyle) {
42 super(context, attrs, defStyle);
43 }
44
45 public void setOnPinEnteredListener(OnPinEnteredListener listener) {
46 mPinListener = listener;
47 }
Amith Yamasani11cd8c52009-08-28 15:36:52 -070048
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080049 @Override
50 protected void onBindDialogView(View view) {
51 super.onBindDialogView(view);
Amith Yamasani11cd8c52009-08-28 15:36:52 -070052
Gilles Debunne32073592012-05-16 16:46:12 +020053 final EditText editText = getEditText();
Amith Yamasani11cd8c52009-08-28 15:36:52 -070054
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080055 if (editText != null) {
Gilles Debunne32073592012-05-16 16:46:12 +020056 editText.setInputType(InputType.TYPE_CLASS_NUMBER |
Jason Monk39b46742015-09-10 15:52:51 -040057 InputType.TYPE_NUMBER_VARIATION_PASSWORD);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080058 }
59 }
60
61 public boolean isDialogOpen() {
Amith Yamasani11cd8c52009-08-28 15:36:52 -070062 Dialog dialog = getDialog();
63 return dialog != null && dialog.isShowing();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080064 }
Amith Yamasani11cd8c52009-08-28 15:36:52 -070065
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080066 @Override
67 protected void onDialogClosed(boolean positiveResult) {
68 super.onDialogClosed(positiveResult);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080069 if (mPinListener != null) {
70 mPinListener.onPinEntered(this, positiveResult);
71 }
72 }
Amith Yamasani11cd8c52009-08-28 15:36:52 -070073
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080074 public void showPinDialog() {
Amith Yamasani11cd8c52009-08-28 15:36:52 -070075 Dialog dialog = getDialog();
76 if (dialog == null || !dialog.isShowing()) {
Jason Monk39b46742015-09-10 15:52:51 -040077 onClick();
Amith Yamasani11cd8c52009-08-28 15:36:52 -070078 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080079 }
80}