diff options
author | Tyler Gunn <tgunn@google.com> | 2014-02-19 15:58:26 -0800 |
---|---|---|
committer | Jay Shrauner <shrauner@google.com> | 2014-03-04 20:26:34 +0000 |
commit | 1a31e3439a23cb2c0ff4658e0bef2d3782825e72 (patch) | |
tree | e9006e114f3478535851d622a766c06bee4a93af /src | |
parent | 27c57f5ec6421d8de15214c09114266b4a917bed (diff) |
Adding "Speed Dial" title to dialer favorites list and moving "All Contacts" affordance.
Bug: 13080167
Change-Id: Id825ef4bfc9de5340d40cae8176bdc13fcfb3ccd
(cherry picked from commit 9a06657538802e0100dc65c6ae0713c996298e1b)
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/list/PhoneFavoriteFragment.java | 43 | ||||
-rw-r--r-- | src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java | 146 |
2 files changed, 97 insertions, 92 deletions
diff --git a/src/com/android/dialer/list/PhoneFavoriteFragment.java b/src/com/android/dialer/list/PhoneFavoriteFragment.java index 027674a96..860f9dc2a 100644 --- a/src/com/android/dialer/list/PhoneFavoriteFragment.java +++ b/src/com/android/dialer/list/PhoneFavoriteFragment.java @@ -25,7 +25,6 @@ import android.content.Context; import android.content.CursorLoader; import android.content.Loader; import android.content.SharedPreferences; -import android.content.res.Resources; import android.database.Cursor; import android.graphics.Rect; import android.net.Uri; @@ -40,6 +39,7 @@ import android.view.ViewTreeObserver; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; +import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; import android.widget.RelativeLayout; @@ -195,8 +195,7 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen private PhoneFavoriteListView mListView; - private View mShowAllContactsButton; - private View mShowAllContactsInEmptyViewButton; + private View mPhoneFavoritesMenu; private View mContactTileFrame; private TileInteractionTeaserView mTileInteractionTeaserView; @@ -288,14 +287,8 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen mEmptyView = mParentView.findViewById(R.id.phone_no_favorites_view); - mShowAllContactsInEmptyViewButton = mParentView.findViewById( - R.id.show_all_contact_button_in_nofav); - prepareAllContactsButton(mShowAllContactsInEmptyViewButton); - - mShowAllContactsButton = inflater.inflate(R.layout.show_all_contact_button, mListView, - false); - - prepareAllContactsButton(mShowAllContactsButton); + mPhoneFavoritesMenu = inflater.inflate(R.layout.phone_favorites_menu, mListView, false); + prepareFavoritesMenu(mPhoneFavoritesMenu); mContactTileFrame = mParentView.findViewById(R.id.contact_tile_frame); @@ -303,7 +296,7 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen R.layout.tile_interactions_teaser_view, mListView, false); mAdapter = new PhoneFavoriteMergedAdapter(getActivity(), this, mContactTileAdapter, - mCallLogAdapter, mShowAllContactsButton, mTileInteractionTeaserView); + mCallLogAdapter, mPhoneFavoritesMenu, mTileInteractionTeaserView); mTileInteractionTeaserView.setAdapter(mAdapter); @@ -666,31 +659,17 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen } /** - * Returns a view that is laid out and styled to look like a regular contact, with the correct - * click behavior (to launch the all contacts activity when it is clicked). + * Prepares the favorites menu which contains the static label "Speed Dial" and the + * "All Contacts" button. Taps anywhere in the view take the user to "All Contacts". + * This emulates how the headers in Play Store work. */ - private View prepareAllContactsButton(View v) { - final ContactListItemView view = (ContactListItemView) v; - view.setOnClickListener(new OnClickListener() { + private void prepareFavoritesMenu(View favoritesMenu) { + // Set the onClick listener for the view to bring up the all contacts view. + favoritesMenu.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { showAllContacts(); } }); - - view.setPhotoPosition(ContactListItemView.PhotoPosition.LEFT); - final Resources resources = getResources(); - view.setBackgroundResource(R.drawable.contact_list_item_background); - - view.setPaddingRelative( - resources.getDimensionPixelSize(R.dimen.favorites_row_start_padding), - resources.getDimensionPixelSize(R.dimen.favorites_row_end_padding), - resources.getDimensionPixelSize(R.dimen.favorites_row_top_padding), - resources.getDimensionPixelSize(R.dimen.favorites_row_bottom_padding)); - - view.setDisplayName(resources.getString(R.string.show_all_contacts_button_text)); - view.setDrawableResource(R.drawable.list_item_avatar_bg, - R.drawable.ic_menu_all_contacts_dk); - return view; } } diff --git a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java index daba39e6d..1c871e82f 100644 --- a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java +++ b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java @@ -49,12 +49,12 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { private static final String TAG = PhoneFavoriteMergedAdapter.class.getSimpleName(); - private static final int TILE_INTERACTION_TEASER_VIEW_POSITION = 2; + private static final int TILE_INTERACTION_TEASER_VIEW_POSITION = 3; private static final int TILE_INTERACTION_TEASER_VIEW_ID = -2; - private static final int ALL_CONTACTS_BUTTON_ITEM_ID = -1; + private static final int FAVORITES_MENU_ITEM_ID = -3; private final PhoneFavoritesTileAdapter mContactTileAdapter; private final CallLogAdapter mCallLogAdapter; - private final View mShowAllContactsButton; + private final View mPhoneFavoritesMenu; private final PhoneFavoriteFragment mFragment; private final TileInteractionTeaserView mTileInteractionTeaserView; @@ -103,7 +103,7 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { PhoneFavoriteFragment fragment, PhoneFavoritesTileAdapter contactTileAdapter, CallLogAdapter callLogAdapter, - View showAllContactsButton, + View phoneFavoritesMenu, TileInteractionTeaserView tileInteractionTeaserView) { final Resources resources = context.getResources(); mContext = context; @@ -114,20 +114,24 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { mObserver = new CustomDataSetObserver(); mCallLogAdapter.registerDataSetObserver(mObserver); mContactTileAdapter.registerDataSetObserver(mObserver); - mShowAllContactsButton = showAllContactsButton; + mPhoneFavoritesMenu = phoneFavoritesMenu; mTileInteractionTeaserView = tileInteractionTeaserView; mCallLogQueryHandler = new CallLogQueryHandler(mContext.getContentResolver(), mCallLogQueryHandlerListener); } + /** + * Determines the number of items in the adapter. + * mCallLogAdapter contains the item for the most recent caller. + * mContactTileAdapter contains the starred contacts. + * The +1 is to account for the presence of the favorites menu. + * + * @return Number of items in the adapter. + */ @Override public int getCount() { - if (mContactTileAdapter.getCount() > 0) { - return mContactTileAdapter.getCount() + mCallLogAdapter.getCount() + 1 + - getTeaserViewCount(); - } else { - return mCallLogAdapter.getCount(); - } + return mContactTileAdapter.getCount() + mCallLogAdapter.getCount() + getTeaserViewCount() + + 1; } @Override @@ -151,9 +155,9 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { * * These are the ranges of IDs reserved for each item type. * - * -(N + 1) to -3: CallLogAdapterItems, where N is equal to the number of call log items + * -4 and lower: CallLogAdapterItems representing most recent call. + * -3: Favorites menu * -2: Teaser - * -1: All contacts button * 0 to (N -1): Rows of tiled contacts, where N is equal to the max rows of tiled contacts * N to infinity: Rows of regular contacts. Their item id is calculated by N + contact_id, * where contact_id is guaranteed to never be negative. @@ -163,17 +167,19 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { final int callLogAdapterCount = mCallLogAdapter.getCount(); if (position < callLogAdapterCount) { // Call log items are not animated, so reusing their position for IDs is fine. - return ALL_CONTACTS_BUTTON_ITEM_ID - 2 - position; + return FAVORITES_MENU_ITEM_ID - 1 - position; } else if (position == TILE_INTERACTION_TEASER_VIEW_POSITION + callLogAdapterCount && - mTileInteractionTeaserView.getShouldDisplayInList()){ + mTileInteractionTeaserView.getShouldDisplayInList()) { return TILE_INTERACTION_TEASER_VIEW_ID; + } else if (position == callLogAdapterCount) { + return FAVORITES_MENU_ITEM_ID; } else if (position < (callLogAdapterCount + mContactTileAdapter.getCount() + - getTeaserViewCount())) { + getTeaserViewCount() + 1)) { return mContactTileAdapter.getItemId( getAdjustedFavoritePosition(position, callLogAdapterCount)); } else { - // All contacts button - return ALL_CONTACTS_BUTTON_ITEM_ID; + // Default fallback. We don't normally get here. + return FAVORITES_MENU_ITEM_ID; } } @@ -182,12 +188,15 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { return true; } + /** + * Determine the number of view types present. + */ @Override public int getViewTypeCount() { return (mContactTileAdapter.getViewTypeCount() + /* Favorite and frequent */ mCallLogAdapter.getViewTypeCount() + /* Recent call log */ getTeaserViewCount() + /* Teaser */ - 1); /* Show all contacts button. */ + 1); /* Favorites menu. */ } @Override @@ -200,60 +209,66 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { return mContactTileAdapter.getViewTypeCount(); } else if (position == TILE_INTERACTION_TEASER_VIEW_POSITION + callLogAdapterCount && mTileInteractionTeaserView.getShouldDisplayInList()) { - // View type of the teaser row is the last view type of the contact tile adapter + 3 + // View type of the teaser row is the last view type of the contact tile adapter +2 return mContactTileAdapter.getViewTypeCount() + 2; - } else if (position < getCount() - 1) { + } else if (position == callLogAdapterCount) { + // View type of the favorites menu is last view type of contact tile adapter +3 + return mContactTileAdapter.getViewTypeCount() + 3; + } else if (position < getCount()) { return mContactTileAdapter.getItemViewType( getAdjustedFavoritePosition(position, callLogAdapterCount)); } else { - // View type of the show all contact button is the last view type of the contact tile - // adapter + 2 - return mContactTileAdapter.getViewTypeCount() + 1; + // Catch-all - we shouldn't get here but if we do use the same as the favorites menu. + return mContactTileAdapter.getViewTypeCount() + 3; } } + /** + * Determines the view for a specified position. + * + * @param position Position for which to retrieve view. + * @return view corresponding to position. + */ @Override public View getView(int position, View convertView, ViewGroup parent) { final int callLogAdapterCount = mCallLogAdapter.getCount(); - if ((position == getCount() - 1) && (mContactTileAdapter.getCount() > 0)) { - return mShowAllContactsButton; - } - - if (mTileInteractionTeaserView.getShouldDisplayInList()) { - if (position == TILE_INTERACTION_TEASER_VIEW_POSITION + callLogAdapterCount) { - return mTileInteractionTeaserView; + // Get the view for the "teaser view" which describes how to re-arrange favorites. + if (mTileInteractionTeaserView.getShouldDisplayInList() + && position == TILE_INTERACTION_TEASER_VIEW_POSITION + callLogAdapterCount) { + return mTileInteractionTeaserView; + } else if (callLogAdapterCount > 0 && position < callLogAdapterCount) { + // Handle case where we are requesting the view for the "most recent caller". + + final SwipeableCallLogRow wrapper; + if (convertView == null) { + wrapper = new SwipeableCallLogRow(mContext); + wrapper.setOnItemSwipeListener(mCallLogOnItemSwipeListener); + } else { + wrapper = (SwipeableCallLogRow) convertView; } - } - if (callLogAdapterCount > 0) { - if (position == 0) { - final SwipeableCallLogRow wrapper; - if (convertView == null) { - wrapper = new SwipeableCallLogRow(mContext); - wrapper.setOnItemSwipeListener(mCallLogOnItemSwipeListener); - } else { - wrapper = (SwipeableCallLogRow) convertView; - } - - // Special case wrapper view for the most recent call log item. This allows - // us to create a card-like effect for the more recent call log item in - // the PhoneFavoriteMergedAdapter, but keep the original look of the item in - // the CallLogAdapter. - final View view = mCallLogAdapter.getView(position, convertView == null ? - null : wrapper.getChildAt(0), parent); - wrapper.removeAllViews(); - final View callLogItem = view.findViewById(R.id.call_log_list_item); - // Reset the internal call log item view if it is being recycled - callLogItem.setTranslationX(0); - callLogItem.setAlpha(1); - wrapper.addView(view); - return wrapper; - } + // Special case wrapper view for the most recent call log item. This allows + // us to create a card-like effect for the more recent call log item in + // the PhoneFavoriteMergedAdapter, but keep the original look of the item in + // the CallLogAdapter. + final View view = mCallLogAdapter.getView(position, convertView == null ? + null : wrapper.getChildAt(0), parent); + wrapper.removeAllViews(); + final View callLogItem = view.findViewById(R.id.call_log_list_item); + // Reset the internal call log item view if it is being recycled + callLogItem.setTranslationX(0); + callLogItem.setAlpha(1); + wrapper.addView(view); + return wrapper; + } else if (position == callLogAdapterCount) { + // If position is just after the entries in the mCallLogAdapter (most recent call), + // return the favorites menu. + return mPhoneFavoritesMenu; } - // Set position to the position of the actual favorite contact in the - // favorites adapter + // Set position to the position of the actual favorite contact in the favorites adapter. + // Adjusts based on the presence of other views, such as the favorites menu. position = getAdjustedFavoritePosition(position, callLogAdapterCount); // Favorites section @@ -285,15 +300,26 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { } } + /** + * Determines the index into the mContactTileAdapter for the current position. + * + * @param position current position in the overall adapter. + * @param callLogAdapterCount number of entries in "last calls" list (ie 0 or 1). + * @return position in the mContactTileAdapter. + */ private int getAdjustedFavoritePosition(int position, int callLogAdapterCount) { if (position - callLogAdapterCount > TILE_INTERACTION_TEASER_VIEW_POSITION && mTileInteractionTeaserView.getShouldDisplayInList()) { - return position - callLogAdapterCount - 1; + return position - callLogAdapterCount - 2; } else { - return position - callLogAdapterCount; + return position - callLogAdapterCount - 1; } } + /** + * Determines the number of teaser views visible. + * @return 1 or 0 depending on if the teaser view is showing. + */ private int getTeaserViewCount() { return (mContactTileAdapter.getCount() > TILE_INTERACTION_TEASER_VIEW_POSITION && mTileInteractionTeaserView.getShouldDisplayInList() ? 1 : 0); |