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