Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de15823d authored by Daisuke Miyakawa's avatar Daisuke Miyakawa
Browse files

Implement custom EditText to correctly suppress IME

Also use stateAlwaysHidden to ask the Activity itself to
show up IME on the first boot.

Bug: 5032146
Bug: 5171943
Change-Id: Ie763cca52ca6a4d0db48ab240a39cb8f03ebbc03
parent b59500de
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -117,7 +117,9 @@
            </intent-filter>
        </activity>

        <!-- Tab container for all tabs -->
        <!-- The entrance point for Phone UI.
             stateAlwaysHidden is set to suppress keyboard show up on
             dialpad screen. -->
        <activity android:name=".activities.DialtactsActivity"
            android:label="@string/launcherDialer"
            android:theme="@style/DialtactsTheme"
@@ -128,7 +130,7 @@
            android:screenOrientation="nosensor"
            android:enabled="@*android:bool/config_voice_capable"
            android:taskAffinity="android.task.contacts.phone"
        >
            android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="android.intent.action.DIAL" />
                <category android:name="android.intent.category.DEFAULT" />
+2 −1
Original line number Diff line number Diff line
@@ -35,7 +35,8 @@
             in the java code.

             Background drawable can be controlled programatically. -->
        <EditText android:id="@+id/digits"
        <com.android.contacts.dialpad.DigitsEditText
            android:id="@+id/digits"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
+1 −4
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.net.Uri;
@@ -298,12 +297,10 @@ public class DialpadFragment extends Fragment
        mDialpad = fragmentView.findViewById(R.id.dialpad);  // This is null in landscape mode.

        // In landscape we put the keyboard in phone mode.
        // In portrait we prevent the soft keyboard to show since the
        // dialpad acts as one already.
        if (null == mDialpad) {
            mDigits.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
        } else {
            mDigits.setInputType(android.text.InputType.TYPE_NULL);
            mDigits.setCursorVisible(false);
        }

        // Set up the "dialpad chooser" UI; see showDialpadChooser().
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.contacts.dialpad;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

/**
 * EditText which suppresses IME show up.
 */
public class DigitsEditText extends EditText {
    public DigitsEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        setSuggestionsEnabled(false);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        final InputMethodManager imm = ((InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE));
        if (imm != null && imm.isActive(this)) {
            imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        final boolean ret = super.onTouchEvent(event);
        // Must be done after super.onTouchEvent()
        final InputMethodManager imm = ((InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE));
        if (imm != null && imm.isActive(this)) {
            imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
        }
        return ret;
    }
}
 No newline at end of file