summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2015-02-06 14:50:35 -0800
committerYorke Lee <yorkelee@google.com>2015-02-17 13:48:55 -0800
commit2b94c39bb8e54ae2bd78e582e8161f783c9dc516 (patch)
tree5286346f4956ee4e1805825e39a3a66e29038dd2
parentd9d409a86330c5fde0cc465562c6d3eb96ec10eb (diff)
Remove shortcut cards list view
Remove ListView containing shortcut cards and replace it with a single ShortcutCard card. Rename ShortcutCardAdapter to ShortcutCardManager with slight refactor. Some corresponding logic changes inside ListsFragment. Reduces the number of getView calls at startup from 4 to 1. Change-Id: I11787bdb1d04cc19634c21bfd398b7533c75d339
-rw-r--r--res/layout/lists_fragment.xml9
-rw-r--r--src/com/android/dialer/list/ListsFragment.java32
-rw-r--r--src/com/android/dialer/list/ShortcutCardsManager.java (renamed from src/com/android/dialer/list/ShortcutCardsAdapter.java)111
-rw-r--r--src/com/android/dialer/list/SwipeableShortcutCard.java13
4 files changed, 58 insertions, 107 deletions
diff --git a/res/layout/lists_fragment.xml b/res/layout/lists_fragment.xml
index face20e26..a11c89fef 100644
--- a/res/layout/lists_fragment.xml
+++ b/res/layout/lists_fragment.xml
@@ -21,15 +21,12 @@
android:layout_height="match_parent"
android:animateLayoutChanges="true" >
- <ListView
- android:id="@+id/shortcut_card_list"
+ <com.android.dialer.list.SwipeableShortcutCard
+ android:id="@+id/shortcut_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/action_bar_height_large"
- android:background="@color/actionbar_background_color"
- android:clipToPadding="false"
- android:fadingEdge="none"
- android:divider="@null" />
+ android:background="@color/actionbar_background_color" />
<FrameLayout
android:layout_width="match_parent"
diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java
index e9ce57b85..b303d0011 100644
--- a/src/com/android/dialer/list/ListsFragment.java
+++ b/src/com/android/dialer/list/ListsFragment.java
@@ -76,7 +76,7 @@ public class ListsFragment extends Fragment implements CallLogQueryHandler.Liste
private ViewPager mViewPager;
private ViewPagerTabs mViewPagerTabs;
private ViewPagerAdapter mViewPagerAdapter;
- private ListView mShortcutCardsListView;
+ private SwipeableShortcutCard mShortcutCard;
private RemoveView mRemoveView;
private View mRemoveViewContent;
private SpeedDialFragment mSpeedDialFragment;
@@ -87,7 +87,6 @@ public class ListsFragment extends Fragment implements CallLogQueryHandler.Liste
private String[] mTabTitles;
- private ShortcutCardsAdapter mMergedAdapter;
private CallLogAdapter mCallLogAdapter;
private CallLogQueryHandler mCallLogQueryHandler;
private OverlappingPaneLayout mOverlappingPaneLayout;
@@ -112,16 +111,16 @@ public class ListsFragment extends Fragment implements CallLogQueryHandler.Liste
// edge of the shortcut card, to achieve the animated effect of the shortcut card
// being pushed out of view when the panel is slid upwards. slideOffset is 1 when
// the shortcut card is fully exposed, and 0 when completely hidden.
- float ratioCardHidden = (1 - slideOffset);
- if (mShortcutCardsListView.getChildCount() > 0) {
- final SwipeableShortcutCard v =
- (SwipeableShortcutCard) mShortcutCardsListView.getChildAt(0);
- v.clipCard(ratioCardHidden);
+ if (mShortcutCard.isShown()) {
+ float ratioCardHidden = (1 - slideOffset);
+ mShortcutCard.clipCard(ratioCardHidden);
}
if (mActionBar != null) {
// Amount of available space that is not being hidden by the bottom pane
- final int topPaneHeight = (int) (slideOffset * mShortcutCardsListView.getHeight());
+ final int shortcutCardHeight =
+ mShortcutCard.isShown() ? mShortcutCard.getHeight() : 0;
+ final int topPaneHeight = (int) (slideOffset * shortcutCardHeight);
final int availableActionBarHeight =
Math.min(mActionBar.getHeight(), topPaneHeight);
@@ -250,7 +249,6 @@ public class ListsFragment extends Fragment implements CallLogQueryHandler.Liste
mCallLogAdapter = ObjectFactory.newCallLogAdapter(getActivity(), this,
new ContactInfoHelper(getActivity(), currentCountryIso), null, null, false);
- mMergedAdapter = new ShortcutCardsAdapter(getActivity(), this, mCallLogAdapter);
Trace.endSection();
Trace.endSection();
}
@@ -309,8 +307,8 @@ public class ListsFragment extends Fragment implements CallLogQueryHandler.Liste
mViewPagerTabs.setViewPager(mViewPager);
addOnPageChangeListener(mViewPagerTabs);
- mShortcutCardsListView = (ListView) parentView.findViewById(R.id.shortcut_card_list);
- mShortcutCardsListView.setAdapter(mMergedAdapter);
+ mShortcutCard = (SwipeableShortcutCard) parentView.findViewById(R.id.shortcut_card);
+ new ShortcutCardsManager(getActivity(), this, mCallLogAdapter, mShortcutCard);
mRemoveView = (RemoveView) parentView.findViewById(R.id.remove_view);
mRemoveViewContent = parentView.findViewById(R.id.remove_view_content);
@@ -337,7 +335,6 @@ public class ListsFragment extends Fragment implements CallLogQueryHandler.Liste
}
mCallLogAdapter.changeCursor(cursor);
- mMergedAdapter.notifyDataSetChanged();
// Refresh the overlapping pane to ensure that any changes in the shortcut card height
// are appropriately reflected in the overlap position.
@@ -398,11 +395,12 @@ public class ListsFragment extends Fragment implements CallLogQueryHandler.Liste
mRemoveView.setAlpha(show ? 0 : 1);
mRemoveView.animate().alpha(show ? 1 : 0).start();
- if (mShortcutCardsListView.getChildCount() > 0) {
- View v = mShortcutCardsListView.getChildAt(0);
- v.animate().withLayer()
- .alpha(show ? REMOVE_VIEW_SHOWN_ALPHA : REMOVE_VIEW_HIDDEN_ALPHA)
- .start();
+ if (mShortcutCard.isShown()) {
+ final View child = mShortcutCard.getChildAt(0);
+ if (child != null) {
+ child.animate().withLayer()
+ .alpha(show ? REMOVE_VIEW_SHOWN_ALPHA : REMOVE_VIEW_HIDDEN_ALPHA).start();
+ }
}
}
diff --git a/src/com/android/dialer/list/ShortcutCardsAdapter.java b/src/com/android/dialer/list/ShortcutCardsManager.java
index ad6a61c79..8b8a7ba62 100644
--- a/src/com/android/dialer/list/ShortcutCardsAdapter.java
+++ b/src/com/android/dialer/list/ShortcutCardsManager.java
@@ -17,12 +17,9 @@
package com.android.dialer.list;
import android.content.Context;
-import android.content.res.Resources;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseAdapter;
import com.android.dialer.calllog.CallLogAdapter;
import com.android.dialer.calllog.CallLogNotificationsHelper;
@@ -30,23 +27,26 @@ import com.android.dialer.calllog.CallLogQueryHandler;
import com.android.dialer.list.SwipeHelper.OnItemGestureListener;
/**
- * An adapter that displays call shortcuts from {@link com.android.dialer.calllog.CallLogAdapter}
- * in the form of cards.
+ * Handles the logic that displays call shortcuts from
+ * {@link com.android.dialer.calllog.CallLogAdapter} in the form of cards.
*/
-public class ShortcutCardsAdapter extends BaseAdapter {
+public class ShortcutCardsManager {
private class CustomDataSetObserver extends DataSetObserver {
@Override
public void onChanged() {
- notifyDataSetChanged();
+ updateShortcutCard();
}
}
- private static final String TAG = ShortcutCardsAdapter.class.getSimpleName();
+ private static final String TAG = ShortcutCardsManager.class.getSimpleName();
- private final CallLogAdapter mCallLogAdapter;
+ // The position of the shortcut card within the CallLogAdapter
+ private static final int SHORTCUT_CARD_INDEX = 0;
+ private final CallLogAdapter mCallLogAdapter;
private final ListsFragment mFragment;
+ private final SwipeableShortcutCard mShortcutCard;
private final Context mContext;
@@ -89,92 +89,41 @@ public class ShortcutCardsAdapter extends BaseAdapter {
}
};
- public ShortcutCardsAdapter(Context context,
+ public ShortcutCardsManager(Context context,
ListsFragment fragment,
- CallLogAdapter callLogAdapter) {
- final Resources resources = context.getResources();
+ CallLogAdapter callLogAdapter,
+ SwipeableShortcutCard shortcutCard) {
mContext = context;
mFragment = fragment;
+ mShortcutCard = shortcutCard;
mCallLogAdapter = callLogAdapter;
mObserver = new CustomDataSetObserver();
mCallLogAdapter.registerDataSetObserver(mObserver);
mCallLogQueryHandler = new CallLogQueryHandler(mContext.getContentResolver(),
mCallLogQueryHandlerListener);
+ mShortcutCard.setOnItemSwipeListener(mCallLogOnItemSwipeListener);
}
/**
- * 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.
+ * Updates the contents of the shortcut card with the view provided by the
+ * {@link CallLogAdapter}.
*/
- @Override
- public int getCount() {
- return mCallLogAdapter.getCount();
- }
-
- @Override
- public Object getItem(int position) {
- return mCallLogAdapter.getItem(position);
- }
-
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- @Override
- public boolean hasStableIds() {
- return true;
- }
-
- /**
- * Determine the number of view types present.
- */
- @Override
- public int getViewTypeCount() {
- return mCallLogAdapter.getViewTypeCount();
- }
-
- @Override
- public int getItemViewType(int position) {
- return mCallLogAdapter.getItemViewType(position);
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- final SwipeableShortcutCard wrapper;
- if (convertView == null) {
- wrapper = new SwipeableShortcutCard(mContext);
- wrapper.setOnItemSwipeListener(mCallLogOnItemSwipeListener);
+ private void updateShortcutCard() {
+ final int count = mCallLogAdapter.getCount();
+ final View convertView = mShortcutCard.getChildAt(SHORTCUT_CARD_INDEX);
+ if (count <= SHORTCUT_CARD_INDEX) {
+ if (convertView != null) {
+ convertView.setVisibility(View.GONE);
+ }
} else {
- wrapper = (SwipeableShortcutCard) convertView;
+ mShortcutCard.setVisibility(View.VISIBLE);
+ final View view = mCallLogAdapter.getView(SHORTCUT_CARD_INDEX, convertView,
+ mShortcutCard);
+ mShortcutCard.removeAllViews();
+ mShortcutCard.prepareChildView(view);
+ mShortcutCard.addView(view);
+ view.setVisibility(View.VISIBLE);
}
-
- // 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();
- wrapper.prepareChildView(view);
- wrapper.addView(view);
- wrapper.setVisibility(View.VISIBLE);
- return wrapper;
- }
-
- @Override
- public boolean areAllItemsEnabled() {
- return mCallLogAdapter.areAllItemsEnabled();
- }
-
- @Override
- public boolean isEnabled(int position) {
- return mCallLogAdapter.isEnabled(position);
}
}
diff --git a/src/com/android/dialer/list/SwipeableShortcutCard.java b/src/com/android/dialer/list/SwipeableShortcutCard.java
index 93e9fff10..db2210a47 100644
--- a/src/com/android/dialer/list/SwipeableShortcutCard.java
+++ b/src/com/android/dialer/list/SwipeableShortcutCard.java
@@ -19,6 +19,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.text.TextUtils;
+import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
@@ -56,7 +57,15 @@ public class SwipeableShortcutCard extends FrameLayout implements SwipeHelperCal
private Rect mClipRect = new Rect();
public SwipeableShortcutCard(Context context) {
- super(context);
+ this(context, null);
+ }
+
+ public SwipeableShortcutCard(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public SwipeableShortcutCard(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
final Resources resources = getResources();
final float densityScale =resources.getDisplayMetrics().density;
final float pagingTouchSlop = ViewConfiguration.get(context)
@@ -204,9 +213,7 @@ public class SwipeableShortcutCard extends FrameLayout implements SwipeHelperCal
if (ratioHidden > CLIP_CARD_MOSTLY_HIDDEN_RATIO) {
mClipRect.set(0, 0 , 0, 0);
- setVisibility(View.INVISIBLE);
} else {
- setVisibility(View.VISIBLE);
int newTop = (int) (ratioHidden * height);
mClipRect.set(0, newTop, width, height);