package com.android.contacts.ui;
import com.android.contacts.Collapser;
+import com.android.contacts.ContactPresenceIconUtil;
import com.android.contacts.ContactsUtils;
import com.android.contacts.R;
import com.android.contacts.model.ContactsSource;
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;
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;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.ListView;
+import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
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.onBackPressed();
+ return true;
+ } else {
+ return super.dispatchKeyEventPreIme(event);
+ }
+ }
+ }
+
private final Context mContext;
private final LayoutInflater mInflater;
private final WindowManager mWindowManager;
private ImageView mArrowDown;
private int mMode;
+ private RootLayout mRootView;
private View mHeader;
private HorizontalScrollView mTrackScroll;
private ViewGroup mTrack;
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;
+ mRootView.setFocusable(true);
+ mRootView.setFocusableInTouchMode(true);
+ mRootView.setDescendantFocusability(RootLayout.FOCUS_AFTER_DESCENDANTS);
+
mArrowUp = (ImageView)mWindow.findViewById(R.id.arrow_up);
mArrowDown = (ImageView)mWindow.findViewById(R.id.arrow_down);
android.os.Debug.startMethodTracing(TRACE_TAG);
}
+ // Validate incoming parameters
+ final boolean validMode = (mode == QuickContact.MODE_SMALL
+ || mode == QuickContact.MODE_MEDIUM || mode == QuickContact.MODE_LARGE);
+ if (!validMode) {
+ throw new IllegalArgumentException("Invalid mode, expecting MODE_LARGE, "
+ + "MODE_MEDIUM, or MODE_SMALL");
+ }
+
+ if (anchor == null) {
+ throw new IllegalArgumentException("Missing anchor rectangle");
+ }
+
// Prepare header view for requested mode
mLookupUri = lookupUri;
mAnchor = new Rect(anchor);
resetTrack();
+ // We need to have a focused view inside the QuickContact window so
+ // that the BACK key event can be intercepted
+ mRootView.requestFocus();
+
mHasValidSocial = false;
mDismissed = false;
mQuerying = true;
}
/**
- * Find the presence icon for showing in summary header.
- */
- private Drawable getPresenceIcon(int status) {
- int resId = -1;
- switch (status) {
- case StatusUpdates.AVAILABLE:
- resId = android.R.drawable.presence_online;
- break;
- case StatusUpdates.IDLE:
- case StatusUpdates.AWAY:
- resId = android.R.drawable.presence_away;
- break;
- case StatusUpdates.DO_NOT_DISTURB:
- resId = android.R.drawable.presence_busy;
- break;
- }
- if (resId != -1) {
- return mContext.getResources().getDrawable(resId);
- } else {
- return null;
- }
- }
-
- /**
* Find the QuickContact-specific presence icon for showing in chiclets.
*/
private Drawable getTrackPresenceIcon(int status) {
// Read contact information from last data row
final String name = cursor.getString(DataQuery.DISPLAY_NAME);
final int presence = cursor.getInt(DataQuery.CONTACT_PRESENCE);
- final Drawable statusIcon = getPresenceIcon(presence);
+ final Drawable statusIcon = ContactPresenceIconUtil.getPresenceIcon(mContext, presence);
setHeaderText(R.id.name, name);
setHeaderImage(R.id.presence, statusIcon);
* window, which usually means we should dismiss.
*/
protected void detectEventOutside(MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
+ if (event.getAction() == MotionEvent.ACTION_DOWN && mDecor != null) {
// Only try detecting outside events on down-press
mDecor.getHitRect(mRect);
mRect.top = mRect.top + mShadowTouch;