1 /* 2 * Copyright (C) 2011 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.common.dialpad; 18 19 import android.content.Context; 20 import android.graphics.Paint; 21 import android.graphics.Rect; 22 import android.text.InputType; 23 import android.util.AttributeSet; 24 import android.util.TypedValue; 25 import android.view.MotionEvent; 26 import android.view.ViewGroup; 27 import android.view.inputmethod.InputMethodManager; 28 import android.widget.EditText; 29 30 import com.android.phone.common.R; 31 import com.android.phone.common.widget.ResizingTextEditText; 32 33 /** 34 * EditText which suppresses IME show up. 35 */ 36 public class DigitsEditText extends ResizingTextEditText { 37 DigitsEditText(Context context, AttributeSet attrs)38 public DigitsEditText(Context context, AttributeSet attrs) { 39 super(context, attrs); 40 setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); 41 setShowSoftInputOnFocus(false); 42 } 43 44 @Override onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect)45 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { 46 super.onFocusChanged(focused, direction, previouslyFocusedRect); 47 final InputMethodManager imm = ((InputMethodManager) getContext() 48 .getSystemService(Context.INPUT_METHOD_SERVICE)); 49 if (imm != null && imm.isActive(this)) { 50 imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0); 51 } 52 } 53 54 @Override onTouchEvent(MotionEvent event)55 public boolean onTouchEvent(MotionEvent event) { 56 final boolean ret = super.onTouchEvent(event); 57 // Must be done after super.onTouchEvent() 58 final InputMethodManager imm = ((InputMethodManager) getContext() 59 .getSystemService(Context.INPUT_METHOD_SERVICE)); 60 if (imm != null && imm.isActive(this)) { 61 imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0); 62 } 63 return ret; 64 } 65 } 66