• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         getWindow().addSystemFlags(
52                 android.view.WindowManager.LayoutParams
53                         .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
54 
55         setContentView(R.layout.get_pin2_screen);
56 
57         mPin2Field = (EditText) findViewById(R.id.pin);
58         mPin2Field.setKeyListener(DigitsKeyListener.getInstance());
59         mPin2Field.setMovementMethod(null);
60         mPin2Field.setOnEditorActionListener(this);
61         mPin2Field.setInputType(
62                 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
63         mPin2Field.requestFocus();
64 
65         mOkButton = (Button) findViewById(R.id.ok);
66         mOkButton.setOnClickListener(mClicked);
67     }
68 
69     @Override
onOptionsItemSelected(MenuItem item)70     public boolean onOptionsItemSelected(MenuItem item) {
71         if (item.getItemId() == android.R.id.home) {
72             onBackPressed();
73             return true;
74         }
75         return super.onOptionsItemSelected(item);
76     }
77 
getPin2()78     private String getPin2() {
79         return mPin2Field.getText().toString();
80     }
81 
returnResult()82     private void returnResult() {
83         Bundle map = new Bundle();
84         map.putString("pin2", getPin2());
85 
86         Intent intent = getIntent();
87         Uri uri = intent.getData();
88 
89         Intent action = new Intent();
90         if (uri != null) action.setAction(uri.toString());
91         setResult(RESULT_OK, action.putExtras(map));
92         finish();
93     }
94 
95     @Override
onEditorAction(TextView v, int actionId, KeyEvent event)96     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
97         if (actionId == EditorInfo.IME_ACTION_DONE) {
98             mOkButton.performClick();
99             return true;
100         }
101         return false;
102     }
103 
104     private final View.OnClickListener mClicked = new View.OnClickListener() {
105         @Override
106         public void onClick(View v) {
107             if (TextUtils.isEmpty(mPin2Field.getText())) {
108                 return;
109             }
110 
111             returnResult();
112         }
113     };
114 
log(String msg)115     private void log(String msg) {
116         Log.d(LOG_TAG, "[GetPin2] " + msg);
117     }
118 }
119