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 60 mOkButton = (Button) findViewById(R.id.ok); 61 mOkButton.setOnClickListener(mClicked); 62 } 63 64 @Override onOptionsItemSelected(MenuItem item)65 public boolean onOptionsItemSelected(MenuItem item) { 66 if (item.getItemId() == android.R.id.home) { 67 onBackPressed(); 68 return true; 69 } 70 return super.onOptionsItemSelected(item); 71 } 72 getPin2()73 private String getPin2() { 74 return mPin2Field.getText().toString(); 75 } 76 returnResult()77 private void returnResult() { 78 Bundle map = new Bundle(); 79 map.putString("pin2", getPin2()); 80 81 Intent intent = getIntent(); 82 Uri uri = intent.getData(); 83 84 Intent action = new Intent(); 85 if (uri != null) action.setAction(uri.toString()); 86 setResult(RESULT_OK, action.putExtras(map)); 87 finish(); 88 } 89 90 @Override onEditorAction(TextView v, int actionId, KeyEvent event)91 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 92 if (actionId == EditorInfo.IME_ACTION_DONE) { 93 mOkButton.performClick(); 94 return true; 95 } 96 return false; 97 } 98 99 private final View.OnClickListener mClicked = new View.OnClickListener() { 100 @Override 101 public void onClick(View v) { 102 if (TextUtils.isEmpty(mPin2Field.getText())) { 103 return; 104 } 105 106 returnResult(); 107 } 108 }; 109 log(String msg)110 private void log(String msg) { 111 Log.d(LOG_TAG, "[GetPin2] " + msg); 112 } 113 } 114