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
17package com.android.phone.common.dialpad;
18
19import android.content.Context;
20import android.graphics.Paint;
21import android.graphics.Rect;
22import android.text.InputType;
23import android.util.AttributeSet;
24import android.util.TypedValue;
25import android.view.MotionEvent;
26import android.view.ViewGroup;
27import android.view.inputmethod.InputMethodManager;
28import android.widget.EditText;
29
30import com.android.phone.common.R;
31import com.android.phone.common.widget.ResizingTextEditText;
32
33/**
34 * EditText which suppresses IME show up.
35 */
36public class DigitsEditText extends ResizingTextEditText {
37
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
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
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