diff options
author | Yorke Lee <yorkelee@google.com> | 2013-09-11 16:51:57 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-09-11 16:51:57 -0700 |
commit | f894d67084d58c282ab2b15859a42dd37d504e3e (patch) | |
tree | 2b94feb2f0b2650a4b335fca18477f2565135833 | |
parent | e42f898e7f004d10e9c18e96c97f65da3a7c8311 (diff) | |
parent | 18e7fdd55f67e3636c161462cb54e7f5555a04de (diff) |
am 18e7fdd5: Add no contacts view to Dialer
* commit '18e7fdd55f67e3636c161462cb54e7f5555a04de':
Add no contacts view to Dialer
-rw-r--r-- | res/layout/phone_no_favorites.xml (renamed from res/layout/phone_loading_contacts.xml) | 28 | ||||
-rw-r--r-- | res/layout/show_all_contacts_fragment.xml | 2 | ||||
-rw-r--r-- | src/com/android/dialer/list/PhoneFavoriteFragment.java | 18 | ||||
-rw-r--r-- | src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java | 6 | ||||
-rw-r--r-- | src/com/android/dialer/list/PhoneFavoritesTileAdapter.java | 24 | ||||
-rw-r--r-- | tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java | 4 |
6 files changed, 42 insertions, 40 deletions
diff --git a/res/layout/phone_loading_contacts.xml b/res/layout/phone_no_favorites.xml index afc3322d1..9fa5d4781 100644 --- a/res/layout/phone_loading_contacts.xml +++ b/res/layout/phone_no_favorites.xml @@ -14,27 +14,21 @@ limitations under the License. --> -<!-- "Loading" text with a spinner, which is used in PhoneFavorite screen --> -<LinearLayout +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:minHeight="?android:attr/listPreferredItemHeight" - android:orientation="horizontal" - android:gravity="start|center_vertical"> - - <ProgressBar - android:indeterminate="true" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:id="@+id/progress_spinner"/> + android:minHeight="?android:attr/listPreferredItemHeight"> <TextView android:id="@+id/title" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/contact_list_loading" - android:textAppearance="?android:attr/textAppearanceMedium" - android:layout_marginStart="4dip" /> + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:text="@string/listTotalAllContactsZeroStarred" + android:textAppearance="?android:attr/textAppearanceLarge" + android:textColor="?android:attr/textColorSecondary" + android:layout_marginTop="8dp" + android:layout_marginBottom="8dp"/> -</LinearLayout> +</FrameLayout> diff --git a/res/layout/show_all_contacts_fragment.xml b/res/layout/show_all_contacts_fragment.xml index 14fe340f3..ddc99e84b 100644 --- a/res/layout/show_all_contacts_fragment.xml +++ b/res/layout/show_all_contacts_fragment.xml @@ -23,7 +23,7 @@ <!-- Shown only when an Account filter is set. - paddingTop should be here to show "shade" effect correctly. --> - <!-- TODO {klp} Remove the filter header. --> + <!-- TODO: Remove the filter header. --> <include android:id="@+id/account_filter_header_container" layout="@layout/account_filter_header" /> diff --git a/src/com/android/dialer/list/PhoneFavoriteFragment.java b/src/com/android/dialer/list/PhoneFavoriteFragment.java index d7c387e57..c2a1b03b7 100644 --- a/src/com/android/dialer/list/PhoneFavoriteFragment.java +++ b/src/com/android/dialer/list/PhoneFavoriteFragment.java @@ -144,18 +144,17 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen private CallLogAdapter mCallLogAdapter; private CallLogQueryHandler mCallLogQueryHandler; - private TextView mEmptyView; private PhoneFavoriteListView mListView; + private View mShowAllContactsButton; private final HashMap<Long, Integer> mItemIdTopMap = new HashMap<Long, Integer>(); private final HashMap<Long, Integer> mItemIdLeftMap = new HashMap<Long, Integer>(); /** - * Layout used when contacts load is slower than expected and thus "loading" view should be - * shown. + * Layout used when there are no favorites. */ - private View mLoadingView; + private View mEmptyView; private final ContactTileView.Listener mContactTileAdapterListener = new ContactTileAdapterListener(); @@ -171,7 +170,6 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen // Construct two base adapters which will become part of PhoneFavoriteMergedAdapter. // We don't construct the resultant adapter at this moment since it requires LayoutInflater // that will be available on onCreateView(). - mContactTileAdapter = new PhoneFavoritesTileAdapter(activity, mContactTileAdapterListener, this, getResources().getInteger(R.integer.contact_tile_column_count_in_favorites_new), @@ -214,7 +212,8 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY); mListView.setOnItemSwipeListener(mContactTileAdapter); - mLoadingView = inflater.inflate(R.layout.phone_loading_contacts, mListView, false); + mEmptyView = inflater.inflate(R.layout.phone_no_favorites, mListView, false); + mShowAllContactsButton = inflater.inflate(R.layout.show_all_contact_button, mListView, false); mShowAllContactsButton.setOnClickListener(new OnClickListener() { @@ -224,8 +223,9 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen } }); + mContactTileAdapter.setEmptyView(mEmptyView); mAdapter = new PhoneFavoriteMergedAdapter(getActivity(), mContactTileAdapter, - mCallLogAdapter, mLoadingView, mShowAllContactsButton); + mCallLogAdapter, mShowAllContactsButton); mListView.setAdapter(mAdapter); @@ -233,10 +233,6 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen mListView.setFastScrollEnabled(false); mListView.setFastScrollAlwaysVisible(false); - mEmptyView = (TextView) listLayout.findViewById(R.id.contact_tile_list_empty); - mEmptyView.setText(getString(R.string.listTotalAllContactsZero)); - mListView.setEmptyView(mEmptyView); - return listLayout; } diff --git a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java index 57ae2c147..575ef0a24 100644 --- a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java +++ b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java @@ -52,7 +52,6 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { private static final int ALL_CONTACTS_BUTTON_ITEM_ID = -1; private final PhoneFavoritesTileAdapter mContactTileAdapter; private final CallLogAdapter mCallLogAdapter; - private final View mLoadingView; private final View mShowAllContactsButton; private final int mCallLogPadding; @@ -99,7 +98,6 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { public PhoneFavoriteMergedAdapter(Context context, PhoneFavoritesTileAdapter contactTileAdapter, CallLogAdapter callLogAdapter, - View loadingView, View showAllContactsButton) { final Resources resources = context.getResources(); mContext = context; @@ -109,7 +107,6 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { mObserver = new CustomDataSetObserver(); mCallLogAdapter.registerDataSetObserver(mObserver); mContactTileAdapter.registerDataSetObserver(mObserver); - mLoadingView = loadingView; mShowAllContactsButton = showAllContactsButton; mCallLogQueryHandler = new CallLogQueryHandler(mContext.getContentResolver(), mCallLogQueryHandlerListener); @@ -242,9 +239,6 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { @Override public boolean areAllItemsEnabled() { - // If "all" section is being loaded we'll show mLoadingView, which is not enabled. - // Otherwise check the all the other components in the ListView and return appropriate - // result. return mCallLogAdapter.areAllItemsEnabled() && mContactTileAdapter.areAllItemsEnabled(); } diff --git a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java index 91acc6fe0..966233862 100644 --- a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java +++ b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java @@ -74,6 +74,8 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements private Context mContext; private Resources mResources; + private View mEmptyView; + /** Contact data stored in cache. This is used to populate the associated view. */ protected ArrayList<ContactEntry> mContactEntries = null; /** Back up of the temporarily removed Contact during dragging. */ @@ -367,10 +369,15 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements return mNumFrequents; } + private boolean isEmptyView(int position) { + return position == 0 && (mContactEntries == null || mContactEntries.isEmpty()); + } + @Override public int getCount() { if (mContactEntries == null || mContactEntries.isEmpty()) { - return 0; + // empty view + return 1; } int total = mContactEntries.size(); @@ -493,7 +500,7 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements @Override public boolean isEnabled(int position) { - return true; + return !isEmptyView(position); } @Override @@ -509,8 +516,13 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements if (DEBUG) { Log.v(TAG, "get view for " + String.valueOf(position)); } + int itemViewType = getItemViewType(position); + if (itemViewType == ViewTypes.EMPTY) { + return mEmptyView; + } + ContactTileRow contactTileRowView = (ContactTileRow) convertView; ArrayList<ContactEntry> contactList = getItem(position); @@ -542,6 +554,7 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements @Override public int getItemViewType(int position) { + if (isEmptyView(position)) return ViewTypes.EMPTY; if (position < getRowCount(getMaxContactsInTiles())) { return ViewTypes.TOP; } else { @@ -1129,9 +1142,10 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements } protected static class ViewTypes { - public static final int COUNT = 2; + public static final int COUNT = 3; public static final int FREQUENT = 0; public static final int TOP = 1; + public static final int EMPTY = 2; } @Override @@ -1158,4 +1172,8 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements public boolean isSwipeEnabled() { return !mAwaitingRemove; } + + public void setEmptyView(View emptyView) { + mEmptyView = emptyView; + } } diff --git a/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java b/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java index 3e3cacd07..611b3f1af 100644 --- a/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java +++ b/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java @@ -12,7 +12,7 @@ public class PhoneFavoritesTileAdapterTest extends AndroidTestCase { } /** - * TODO Krelease: Add tests + * TODO: Add tests * * Test cases (various combinations of): * No pinned contacts @@ -26,7 +26,7 @@ public class PhoneFavoritesTileAdapterTest extends AndroidTestCase { } /** - * TODO Krelease: Add tests + * TODO: Add tests * * This method assumes that contacts have already been reordered by * arrangeContactsByPinnedPosition, so we can test it with a less expansive set of test data. |