OSDN Git Service

Preventing QuickContact from hiding soft keyboard
authorDmitri Plotnikov <dplotnikov@google.com>
Wed, 24 Mar 2010 05:49:43 +0000 (22:49 -0700)
committerDmitri Plotnikov <dplotnikov@google.com>
Wed, 24 Mar 2010 05:49:43 +0000 (22:49 -0700)
Thanks, Dianne, for the suggestion.

Bug: 2520397
Change-Id: Ia33e89fa22dfb68188a3db24d1c6067d15102817

AndroidManifest.xml
res/layout-finger/quickcontact.xml
src/com/android/contacts/ui/QuickContactWindow.java

index a0ca083..94fedf1 100644 (file)
             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" />
index a895a54..340ca3f 100644 (file)
      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"
         android:visibility="invisible"
         android:src="@drawable/quickcontact_arrow_down" />
 
-</RelativeLayout>
+</view>
index 4ac787c..4247830 100644 (file)
@@ -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;