5

I've been trying to solve a mysterious problem with the SoftKeyboard project I'm working on. The source of the problem from all of the research I've done may be related to the layout file that I've created. Lint complains of too many views beyond 80 and it types fine for my speed but I'm after fact action response from this and can't figure out where the source of the lag is.

I've done all of the Android Manifest tricks and XML tricks I could find, tried converting to the new Constraint Layout Relative Layout made it worse. I don't know how to use Trace View in Android Studio 2.2RC Build so not sure if threads are the issue. But the question I have is how could I make this file more efficient to improve the lag.

Further sometimes when I press a key it fires and others it misses and yet if I randomly toggle all of my fingers super fast across the keypad canvas area like taping my fingers super fast the input seems to keep up with my input events but the output trails behind quite slow like 4-6 seconds behind and it's annoying. For all of the keyboards on Play I see none of them have this issue as I can type super fast and when I stop the input the output stops at the same time.

So I see there are quite a few people who know how to build a great performing keyboard but this one is super slow when trying to type fast. Also if I type a huge amount of data in say like an SMS message it crashes the keyboard and that is the other part really bugging me like there is a buffer limit to this code.

The limit here is 30000 I was only able to paste part of the layout file and since I don't have enough reputation I can't reply..

Can any of the keyboard gurus out here tell me what I'm missing?

            

<?xml version="1.0" encoding="utf-8"?>
<!--suppress ALL -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:clickable="false"
    android:focusableInTouchMode="false"
    android:gravity="bottom">

    <LinearLayout
        android:id="@+id/num_keyLay"
        android:layout_width="match_parent"
        android:layout_height="54.2dp"
        android:orientation="horizontal"
        android:weightSum="10"
        android:baselineAligned="false">

        <LinearLayout
            android:id="@+id/ksOne_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/ksOne_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:background="@drawable/key_drwable_selector"
                android:text="1"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/kstwo_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/kstwo_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="2"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ksthree_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/ksthree_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="3"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ksFour_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/ksFour_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="4"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ksFive_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/ksFive_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="5"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ksSix_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/ksSix_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="6"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ksSeven_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/ksSeven_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="7"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ksEight_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/ksEight_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="8"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ksNine_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/ksNine_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="9"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ksZero_btn_LiLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/ksZero_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="0"
                android:textSize="25sp"
                android:textColor="@android:color/white"
                android:textStyle="bold"
                tools:ignore="ContentDescription" />

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/line_firstLay"
        android:layout_width="match_parent"
        android:layout_height="54.2dp"
        android:orientation="horizontal"
        android:weightSum="10"
        tools:ignore="DisableBaselineAlignment">

        <LinearLayout
            android:id="@+id/q_btn_ReLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/q_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="q"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                tools:ignore="ContentDescription" />

            <Button
                android:id="@+id/Q_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="Q"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                android:visibility="gone"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/w_btn_ReLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/w_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="w"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                tools:ignore="ContentDescription" />

            <Button
                android:id="@+id/W_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="W"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                android:visibility="gone"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/e_btn_ReLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/e_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="e"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                tools:ignore="ContentDescription" />

            <Button
                android:id="@+id/E_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="E"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                android:visibility="gone"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/r_btn_ReLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/r_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="r"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                tools:ignore="ContentDescription" />

            <Button
                android:id="@+id/R_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="R"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                android:visibility="gone"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/t_btn_ReLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/t_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="t"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                tools:ignore="ContentDescription" />

            <Button
                android:id="@+id/T_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="T"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                android:visibility="gone"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/y_btn_ReLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/y_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="y"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                tools:ignore="ContentDescription" />

            <Button
                android:id="@+id/Y_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="Y"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                android:visibility="gone"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/u_btn_ReLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/u_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="u"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                tools:ignore="ContentDescription" />

            <Button
                android:id="@+id/U_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="U"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                android:visibility="gone"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/i_btn_ReLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/i_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="i"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                tools:ignore="ContentDescription" />

            <Button
                android:id="@+id/I_btn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/key_drwable_selector"
                android:text="I"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="bold"
                android:textAllCaps="false"
                android:visibility="gone"
                tools:ignore="ContentDescription" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/o_btn_ReLay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/backgroud_black"
            android:orientation="horizontal" >
  • I've tried changing the selector, attempting to remove nested weights to improve layout performance on inflation. There appears to be a strange problem with all Samsung phones even the Note 5 which has 4Gb of RAM and Octa-Core SOC/CPU and the lag persists. I've tried unsuccessfully to convert this layout to a ConstraintLayout in efforts to reduce lag in inflation yet no luck. This comes from a softkeyboard project seen here: https://android.googlesource.com/platform/development/+/master/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java – Justin Kalis Feb 08 '17 at 16:31
  • The goal is to be able to select a button and press another button on the keyboard and make the first selector die. Take any keyboard and press two buttons at the same time and notice that only one button selector is lit at one time. Trying to figure out how to reproduce this behavior has been a challenge. I thought that reusing buttons would force the next key to lite up and the first key to die but this is a difficult thing to explain. Suspect the lag is EditText consumption lag but not sure. Viewpager is used for emoji and button performance is critical for zero lag. – Justin Kalis Feb 08 '17 at 16:35

2 Answers2

0

I had the simillar problem, turns out, when typing fast, there will be moments when there are two pointers on your touchscreen, you have to deal with that, when yousing onClickListeners the problem arises as the click is registered only when MotionEvent.ACTION_UP occurs, thus if you press one key, and then press another without unpressing the first one, it creates problems, try using onTouchListener instead and overriding MotionEvent.ACTION_DOWN and implementing committext there.

0

if it was me I wouldn't use LinearLayout layout and such I would have used canvas then I would have on ACTION_DOWN so I could handle it and this would automatically solve the problem of killing other events

using canvas would also solve the problem of too many views.

the only problem it will cause is handling the buttons places and that is easily solvable cause all the buttons have fix sizes.

hope this helps

Pouya Danesh
  • 1,557
  • 2
  • 19
  • 36