blob: bf2e170ab3651caffc987f58013a5156f33f7d56 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 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.phone;
18
19import android.app.Activity;
20import android.content.Intent;
21import android.net.Uri;
22import android.os.Bundle;
Santos Cordon4fa29702014-06-03 16:26:17 -070023import android.text.InputType;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.text.TextUtils;
25import android.text.method.DigitsKeyListener;
26import android.util.Log;
27import android.view.KeyEvent;
28import android.view.View;
29import android.view.inputmethod.EditorInfo;
30import android.widget.Button;
31import android.widget.EditText;
32import android.widget.TextView;
33
34/**
35 * Pin2 entry screen.
36 */
37public class GetPin2Screen extends Activity implements TextView.OnEditorActionListener {
38 private static final String LOG_TAG = PhoneGlobals.LOG_TAG;
39
40 private EditText mPin2Field;
41 private Button mOkButton;
42
43 @Override
44 protected void onCreate(Bundle icicle) {
45 super.onCreate(icicle);
46
47 setContentView(R.layout.get_pin2_screen);
48
49 mPin2Field = (EditText) findViewById(R.id.pin);
50 mPin2Field.setKeyListener(DigitsKeyListener.getInstance());
51 mPin2Field.setMovementMethod(null);
52 mPin2Field.setOnEditorActionListener(this);
Santos Cordon4fa29702014-06-03 16:26:17 -070053 mPin2Field.setInputType(
54 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055
56 mOkButton = (Button) findViewById(R.id.ok);
57 mOkButton.setOnClickListener(mClicked);
58 }
59
60 private String getPin2() {
61 return mPin2Field.getText().toString();
62 }
63
64 private void returnResult() {
65 Bundle map = new Bundle();
66 map.putString("pin2", getPin2());
67
68 Intent intent = getIntent();
69 Uri uri = intent.getData();
70
71 Intent action = new Intent();
72 if (uri != null) action.setAction(uri.toString());
73 setResult(RESULT_OK, action.putExtras(map));
74 finish();
75 }
76
77 @Override
78 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
79 if (actionId == EditorInfo.IME_ACTION_DONE) {
80 mOkButton.performClick();
81 return true;
82 }
83 return false;
84 }
85
86 private final View.OnClickListener mClicked = new View.OnClickListener() {
87 @Override
88 public void onClick(View v) {
89 if (TextUtils.isEmpty(mPin2Field.getText())) {
90 return;
91 }
92
93 returnResult();
94 }
95 };
96
97 private void log(String msg) {
98 Log.d(LOG_TAG, "[GetPin2] " + msg);
99 }
100}