1 /*
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 
17 package com.android.phone.settings.fdn;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.os.Bundle;
23 import android.text.InputType;
24 import android.text.TextUtils;
25 import android.text.method.DigitsKeyListener;
26 import android.util.Log;
27 import android.view.KeyEvent;
28 import android.view.MenuItem;
29 import android.view.View;
30 import android.view.inputmethod.EditorInfo;
31 import android.widget.Button;
32 import android.widget.EditText;
33 import android.widget.TextView;
34 
35 import com.android.phone.PhoneGlobals;
36 import com.android.phone.R;
37 
38 /**
39  * Pin2 entry screen.
40  */
41 public class GetPin2Screen extends Activity implements TextView.OnEditorActionListener {
42     private static final String LOG_TAG = PhoneGlobals.LOG_TAG;
43 
44     private EditText mPin2Field;
45     private Button mOkButton;
46 
47     @Override
onCreate(Bundle icicle)48     protected void onCreate(Bundle icicle) {
49         super.onCreate(icicle);
50 
51         setContentView(R.layout.get_pin2_screen);
52 
53         mPin2Field = (EditText) findViewById(R.id.pin);
54         mPin2Field.setKeyListener(DigitsKeyListener.getInstance());
55         mPin2Field.setMovementMethod(null);
56         mPin2Field.setOnEditorActionListener(this);
57         mPin2Field.setInputType(
58                 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
59         mPin2Field.requestFocus();
60 
61         mOkButton = (Button) findViewById(R.id.ok);
62         mOkButton.setOnClickListener(mClicked);
63     }
64 
65     @Override
onOptionsItemSelected(MenuItem item)66     public boolean onOptionsItemSelected(MenuItem item) {
67         if (item.getItemId() == android.R.id.home) {
68             onBackPressed();
69             return true;
70         }
71         return super.onOptionsItemSelected(item);
72     }
73 
getPin2()74     private String getPin2() {
75         return mPin2Field.getText().toString();
76     }
77 
returnResult()78     private void returnResult() {
79         Bundle map = new Bundle();
80         map.putString("pin2", getPin2());
81 
82         Intent intent = getIntent();
83         Uri uri = intent.getData();
84 
85         Intent action = new Intent();
86         if (uri != null) action.setAction(uri.toString());
87         setResult(RESULT_OK, action.putExtras(map));
88         finish();
89     }
90 
91     @Override
onEditorAction(TextView v, int actionId, KeyEvent event)92     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
93         if (actionId == EditorInfo.IME_ACTION_DONE) {
94             mOkButton.performClick();
95             return true;
96         }
97         return false;
98     }
99 
100     private final View.OnClickListener mClicked = new View.OnClickListener() {
101         @Override
102         public void onClick(View v) {
103             if (TextUtils.isEmpty(mPin2Field.getText())) {
104                 return;
105             }
106 
107             returnResult();
108         }
109     };
110 
log(String msg)111     private void log(String msg) {
112         Log.d(LOG_TAG, "[GetPin2] " + msg);
113     }
114 }
115