summaryrefslogtreecommitdiff
path: root/java/com/android/contacts
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-03-15 14:41:07 -0700
committerEric Erfanian <erfanian@google.com>2017-03-15 16:24:23 -0700
commitd5e47f6da5b08b13ecdfa7f1edc7e12aeb83fab9 (patch)
treeb54abbb51fb7d66e7755a1fbb5db023ff601090b /java/com/android/contacts
parent30436e7e6d3f2c8755a91b2b6222b74d465a9e87 (diff)
Update Dialer source from latest green build.
* Refactor voicemail component * Add new enriched calling components Test: treehugger, manual aosp testing Change-Id: I521a0f86327d4b42e14d93927c7d613044ed5942
Diffstat (limited to 'java/com/android/contacts')
-rw-r--r--java/com/android/contacts/common/ContactPhotoManager.java1
-rw-r--r--java/com/android/contacts/common/lettertiles/LetterTileDrawable.java70
-rw-r--r--java/com/android/contacts/common/list/ContactEntryListFragment.java74
-rw-r--r--java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java18
4 files changed, 89 insertions, 74 deletions
diff --git a/java/com/android/contacts/common/ContactPhotoManager.java b/java/com/android/contacts/common/ContactPhotoManager.java
index 834471047..0f65a6c56 100644
--- a/java/com/android/contacts/common/ContactPhotoManager.java
+++ b/java/com/android/contacts/common/ContactPhotoManager.java
@@ -40,6 +40,7 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
public static final int TYPE_BUSINESS = LetterTileDrawable.TYPE_BUSINESS;
public static final int TYPE_VOICEMAIL = LetterTileDrawable.TYPE_VOICEMAIL;
public static final int TYPE_DEFAULT = LetterTileDrawable.TYPE_DEFAULT;
+ public static final int TYPE_GENERIC_AVATAR = LetterTileDrawable.TYPE_GENERIC_AVATAR;
/** Scale and offset default constants used for default letter images */
public static final float SCALE_DEFAULT = 1.0f;
diff --git a/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java b/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java
index 7e1839c1e..ca12f1812 100644
--- a/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java
+++ b/java/com/android/contacts/common/lettertiles/LetterTileDrawable.java
@@ -19,6 +19,7 @@ package com.android.contacts.common.lettertiles;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
+import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
@@ -48,13 +49,18 @@ public class LetterTileDrawable extends Drawable {
* #TYPE_BUSINESS}, and voicemail contacts should use {@link #TYPE_VOICEMAIL}.
*/
@Retention(RetentionPolicy.SOURCE)
- @IntDef({TYPE_PERSON, TYPE_BUSINESS, TYPE_VOICEMAIL})
+ @IntDef({TYPE_PERSON, TYPE_BUSINESS, TYPE_VOICEMAIL, TYPE_GENERIC_AVATAR})
public @interface ContactType {}
/** Contact type constants */
public static final int TYPE_PERSON = 1;
public static final int TYPE_BUSINESS = 2;
public static final int TYPE_VOICEMAIL = 3;
+ /**
+ * A generic avatar that features the default icon, default color, and no letter. Useful for
+ * situations where a contact is anonymous.
+ */
+ public static final int TYPE_GENERIC_AVATAR = 4;
@ContactType public static final int TYPE_DEFAULT = TYPE_PERSON;
/**
@@ -87,7 +93,6 @@ public class LetterTileDrawable extends Drawable {
private static Bitmap sDefaultPersonAvatar;
private static Bitmap sDefaultBusinessAvatar;
private static Bitmap sDefaultVoicemailAvatar;
- private static final String TAG = LetterTileDrawable.class.getSimpleName();
private final Paint mPaint;
private int mContactType = TYPE_DEFAULT;
private float mScale = 1.0f;
@@ -97,7 +102,7 @@ public class LetterTileDrawable extends Drawable {
private int mColor;
private Character mLetter = null;
- private boolean mAvatarWasVoicemailOrBusiness = false;
+ @ContactType private int mAvatarType = TYPE_DEFAULT;
private String mDisplayName;
public LetterTileDrawable(final Resources res) {
@@ -130,6 +135,7 @@ public class LetterTileDrawable extends Drawable {
case TYPE_VOICEMAIL:
return sDefaultVoicemailAvatar;
case TYPE_PERSON:
+ case TYPE_GENERIC_AVATAR:
default:
return sDefaultPersonAvatar;
}
@@ -149,6 +155,14 @@ public class LetterTileDrawable extends Drawable {
drawLetterTile(canvas);
}
+ public Bitmap getBitmap(int width, int height) {
+ Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
+ this.setBounds(0, 0, width, height);
+ Canvas canvas = new Canvas(bitmap);
+ this.draw(canvas);
+ return bitmap;
+ }
+
/**
* Draw the bitmap onto the canvas at the current bounds taking into account the current scale.
*/
@@ -231,7 +245,9 @@ public class LetterTileDrawable extends Drawable {
/** Returns a deterministic color based on the provided contact identifier string. */
private int pickColor(final String identifier) {
- if (TextUtils.isEmpty(identifier) || mContactType == TYPE_VOICEMAIL) {
+ if (mContactType == TYPE_VOICEMAIL
+ || mContactType == TYPE_BUSINESS
+ || TextUtils.isEmpty(identifier)) {
return sDefaultColor;
}
// String.hashCode() implementation is not supposed to change across java versions, so
@@ -329,6 +345,10 @@ public class LetterTileDrawable extends Drawable {
return this;
}
+ public boolean tileIsCircular() {
+ return this.mIsCircle;
+ }
+
/**
* Creates a canonical letter tile for use across dialer fragments.
*
@@ -344,39 +364,37 @@ public class LetterTileDrawable extends Drawable {
@Nullable final String identifierForTileColor,
@Shape final int shape,
final int contactType) {
- setContactType(contactType);
+
+ this.setIsCircular(shape == SHAPE_CIRCLE);
+
/**
- * During hangup, we lose the call state for special types of contacts, like voicemail. To help
- * callers avoid extraneous LetterTileDrawable allocations, we keep track of the special case
- * until we encounter a new display name.
+ * We return quickly under the following conditions: 1. We are asked to draw a default tile, and
+ * no coloring information is provided, meaning no further initialization is necessary OR 2.
+ * We've already invoked this method before, set mDisplayName, and found that it has not
+ * changed. This is useful during events like hangup, when we lose the call state for special
+ * types of contacts, like voicemail. We keep track of the special case until we encounter a new
+ * display name.
*/
- if (contactType == TYPE_VOICEMAIL || contactType == TYPE_BUSINESS) {
- this.mAvatarWasVoicemailOrBusiness = true;
- } else if (displayName != null && !displayName.equals(mDisplayName)) {
- this.mAvatarWasVoicemailOrBusiness = false;
+ if (contactType == TYPE_DEFAULT
+ && ((displayName == null && identifierForTileColor == null)
+ || (displayName != null && displayName.equals(mDisplayName)))) {
+ return this;
}
+
this.mDisplayName = displayName;
- if (shape == SHAPE_CIRCLE) {
- this.setIsCircular(true);
- } else {
- this.setIsCircular(false);
- }
+ this.mAvatarType = contactType;
+ setContactType(this.mAvatarType);
- /**
- * To preserve style, we don't use contactType to set the tile icon. In the future, when all
- * callers surface this detail, we can use this to better style the tile icon.
- */
- if (mAvatarWasVoicemailOrBusiness) {
- this.setLetterAndColorFromContactDetails(null, displayName);
- return this;
+ // Special contact types receive default color and no letter tile, but special iconography.
+ if (this.mAvatarType != TYPE_PERSON) {
+ this.setLetterAndColorFromContactDetails(null, null);
} else {
if (identifierForTileColor != null) {
this.setLetterAndColorFromContactDetails(displayName, identifierForTileColor);
- return this;
} else {
this.setLetterAndColorFromContactDetails(displayName, displayName);
- return this;
}
}
+ return this;
}
}
diff --git a/java/com/android/contacts/common/list/ContactEntryListFragment.java b/java/com/android/contacts/common/list/ContactEntryListFragment.java
index a8d9b55ba..278175c0b 100644
--- a/java/com/android/contacts/common/list/ContactEntryListFragment.java
+++ b/java/com/android/contacts/common/list/ContactEntryListFragment.java
@@ -16,7 +16,6 @@
package com.android.contacts.common.list;
-import android.app.Activity;
import android.app.Fragment;
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
@@ -29,8 +28,8 @@ import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.provider.ContactsContract.Directory;
+import android.support.annotation.Nullable;
import android.text.TextUtils;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -42,12 +41,13 @@ import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
-import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import com.android.common.widget.CompositeCursorAdapter.Partition;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.preference.ContactsPreferences;
import com.android.contacts.common.util.ContactListViewUtils;
+import com.android.dialer.common.LogUtil;
+import java.lang.ref.WeakReference;
import java.util.Locale;
/** Common base class for various contact-related list fragments. */
@@ -56,9 +56,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
OnScrollListener,
OnFocusChangeListener,
OnTouchListener,
- OnItemLongClickListener,
LoaderCallbacks<Cursor> {
- private static final String TAG = "ContactEntryListFragment";
private static final String KEY_LIST_STATE = "liststate";
private static final String KEY_SECTION_HEADER_DISPLAY_ENABLED = "sectionHeaderDisplayEnabled";
private static final String KEY_PHOTO_LOADER_ENABLED = "photoLoaderEnabled";
@@ -130,15 +128,27 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
private LoaderManager mLoaderManager;
- private Handler mDelayedDirectorySearchHandler =
- new Handler() {
- @Override
- public void handleMessage(Message msg) {
- if (msg.what == DIRECTORY_SEARCH_MESSAGE) {
- loadDirectoryPartition(msg.arg1, (DirectoryPartition) msg.obj);
- }
- }
- };
+ private Handler mDelayedDirectorySearchHandler;
+
+ private static class DelayedDirectorySearchHandler extends Handler {
+ private final WeakReference<ContactEntryListFragment<?>> contactEntryListFragmentRef;
+
+ private DelayedDirectorySearchHandler(ContactEntryListFragment<?> contactEntryListFragment) {
+ this.contactEntryListFragmentRef = new WeakReference<>(contactEntryListFragment);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ ContactEntryListFragment<?> contactEntryListFragment = contactEntryListFragmentRef.get();
+ if (contactEntryListFragment == null) {
+ return;
+ }
+ if (msg.what == DIRECTORY_SEARCH_MESSAGE) {
+ contactEntryListFragment.loadDirectoryPartition(msg.arg1, (DirectoryPartition) msg.obj);
+ }
+ }
+ }
+
private ContactsPreferences.ChangeListener mPreferencesChangeListener =
new ContactsPreferences.ChangeListener() {
@Override
@@ -148,6 +158,10 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
}
};
+ protected ContactEntryListFragment() {
+ mDelayedDirectorySearchHandler = new DelayedDirectorySearchHandler(this);
+ }
+
protected abstract View inflateView(LayoutInflater inflater, ViewGroup container);
protected abstract T createListAdapter();
@@ -158,18 +172,10 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
*/
protected abstract void onItemClick(int position, long id);
- /**
- * @param position Please note that the position is already adjusted for header views, so "0"
- * means the first list item below header views.
- */
- protected boolean onItemLongClick(int position, long id) {
- return false;
- }
-
@Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- setContext(activity);
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ setContext(context);
setLoaderManager(super.getLoaderManager());
}
@@ -343,7 +349,9 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
} catch (RuntimeException e) {
// We don't even know what the projection should be, so no point trying to
// return an empty MatrixCursor with the correct projection here.
- Log.w(TAG, "RuntimeException while trying to query ContactsProvider.");
+ LogUtil.w(
+ "ContactEntryListFragment.onLoadInBackground",
+ "RuntimeException while trying to query ContactsProvider.");
return null;
}
}
@@ -441,6 +449,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
}
public boolean isLoading() {
+ //noinspection SimplifiableIfStatement
if (mAdapter != null && mAdapter.isLoading()) {
return true;
}
@@ -511,7 +520,6 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
if (mListView != null) {
mListView.setFastScrollEnabled(hasScrollbar);
- mListView.setFastScrollAlwaysVisible(hasScrollbar);
mListView.setVerticalScrollbarPosition(mVerticalScrollbarPosition);
mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
}
@@ -573,6 +581,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
}
}
+ @Nullable
public final String getQueryString() {
return mQueryString;
}
@@ -694,7 +703,6 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
}
mListView.setOnItemClickListener(this);
- mListView.setOnItemLongClickListener(this);
mListView.setOnFocusChangeListener(this);
mListView.setOnTouchListener(this);
mListView.setFastScrollEnabled(!isSearchMode());
@@ -779,16 +787,6 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
}
}
- @Override
- public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
- int adjPosition = position - mListView.getHeaderViewsCount();
-
- if (adjPosition >= 0) {
- return onItemLongClick(adjPosition, id);
- }
- return false;
- }
-
private void hideSoftKeyboard() {
// Hide soft keyboard, if visible
InputMethodManager inputMethodManager =
diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
index 63f8ca580..8156d97cf 100644
--- a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
+++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
@@ -59,8 +59,6 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
private static final String ARG_LISTENER = "listener";
private static final String ARG_CALL_ID = "call_id";
- private int mTitleResId;
- private boolean mCanSetDefault;
private List<PhoneAccountHandle> mAccountHandles;
private boolean mIsSelected;
private boolean mIsDefaultChecked;
@@ -126,8 +124,8 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
- mTitleResId = getArguments().getInt(ARG_TITLE_RES_ID);
- mCanSetDefault = getArguments().getBoolean(ARG_CAN_SET_DEFAULT);
+ int titleResId = getArguments().getInt(ARG_TITLE_RES_ID);
+ boolean canSetDefault = getArguments().getBoolean(ARG_CAN_SET_DEFAULT);
mAccountHandles = getArguments().getParcelableArrayList(ARG_ACCOUNT_HANDLES);
mListener = getArguments().getParcelable(ARG_LISTENER);
if (savedInstanceState != null) {
@@ -167,11 +165,11 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
AlertDialog dialog =
builder
- .setTitle(mTitleResId)
+ .setTitle(titleResId)
.setAdapter(selectAccountListAdapter, selectionListener)
.create();
- if (mCanSetDefault) {
+ if (canSetDefault) {
// Generate custom checkbox view, lint suppressed since no appropriate parent (is dialog)
@SuppressLint("InflateParams")
LinearLayout checkboxLayout =
@@ -190,13 +188,13 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
}
@Override
- public void onStop() {
+ public void onCancel(DialogInterface dialog) {
if (!mIsSelected && mListener != null) {
Bundle result = new Bundle();
result.putString(SelectPhoneAccountListener.EXTRA_CALL_ID, getCallId());
mListener.onReceiveResult(SelectPhoneAccountListener.RESULT_DISMISSED, result);
}
- super.onStop();
+ super.onCancel(dialog);
}
@Nullable
@@ -213,7 +211,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
static final String EXTRA_SET_DEFAULT = "extra_set_default";
static final String EXTRA_CALL_ID = "extra_call_id";
- public SelectPhoneAccountListener() {
+ protected SelectPhoneAccountListener() {
super(new Handler());
}
@@ -239,7 +237,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
private int mResId;
- public SelectAccountListAdapter(
+ SelectAccountListAdapter(
Context context, int resource, List<PhoneAccountHandle> accountHandles) {
super(context, resource, accountHandles);
mResId = resource;