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

Commit ad3bd440 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Preventing QuickContact from hiding soft keyboard

Thanks, Dianne, for the suggestion.

Bug: 2520397
Change-Id: Ia33e89fa22dfb68188a3db24d1c6067d15102817
parent d128adca
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -286,7 +286,9 @@
            android:theme="@style/FullyTranslucent.QuickContact"
            android:launchMode="singleTop"
            android:excludeFromRecents="true"
            android:taskAffinity="android.task.quickcontact">
            android:taskAffinity="android.task.quickcontact"
            android:windowSoftInputMode="stateUnchanged"
            >

            <intent-filter>
                <action android:name="com.android.contacts.action.QUICK_CONTACT" />
+4 −2
Original line number Diff line number Diff line
@@ -14,8 +14,10 @@
     limitations under the License.
-->

<RelativeLayout
<view
    xmlns:android="http://schemas.android.com/apk/res/android"
    class="com.android.contacts.ui.QuickContactWindow$RootLayout"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/quickcontact_shadow_horiz"
@@ -145,4 +147,4 @@
        android:visibility="invisible"
        android:src="@drawable/quickcontact_arrow_down" />

</RelativeLayout>
</view>
+42 −1
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import android.content.ActivityNotFoundException;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.EntityIterator;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
@@ -59,6 +58,7 @@ import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.CommonDataKinds.Website;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
@@ -85,6 +85,7 @@ import android.widget.CompoundButton;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

@@ -114,6 +115,32 @@ public class QuickContactWindow implements Window.Callback,
        public void onDismiss(QuickContactWindow dialog);
    }

    /**
     * Custom layout the sole purpose of which is to intercept the BACK key and
     * close QC even when the soft keyboard is open.
     */
    public static class RootLayout extends RelativeLayout {

        QuickContactWindow mQuickContactWindow;

        public RootLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        /**
         * Intercepts the BACK key event and dismisses QuickContact window.
         */
        @Override
        public boolean dispatchKeyEventPreIme(KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                mQuickContactWindow.dismiss();
                return true;
            } else {
                return super.dispatchKeyEventPreIme(event);
            }
        }
    }

    private final Context mContext;
    private final LayoutInflater mInflater;
    private final WindowManager mWindowManager;
@@ -148,6 +175,8 @@ public class QuickContactWindow implements Window.Callback,
    private ImageView mArrowDown;

    private int mMode;
    private RootLayout mRootView;
    private View mHeaderView;
    private View mHeader;
    private HorizontalScrollView mTrackScroll;
    private ViewGroup mTrack;
@@ -236,9 +265,17 @@ public class QuickContactWindow implements Window.Callback,
        mWindow = PolicyManager.makeNewWindow(mContext);
        mWindow.setCallback(this);
        mWindow.setWindowManager(mWindowManager, null, null);
        mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);

        mWindow.setContentView(R.layout.quickcontact);

        mRootView = (RootLayout)mWindow.findViewById(R.id.root);
        mRootView.mQuickContactWindow = this;

        mHeaderView = mWindow.findViewById(R.id.header);
        mHeaderView.setFocusable(true);
        mHeaderView.setFocusableInTouchMode(true);

        mArrowUp = (ImageView)mWindow.findViewById(R.id.arrow_up);
        mArrowDown = (ImageView)mWindow.findViewById(R.id.arrow_down);

@@ -353,6 +390,10 @@ public class QuickContactWindow implements Window.Callback,

        resetTrack();

        // We need to have a focused view inside the QuickContact window so
        // that the BACK key event can be delivered to the RootLayout
        mHeaderView.requestFocus();

        mHasValidSocial = false;
        mDismissed = false;
        mQuerying = true;