diff options
-rw-r--r-- | src/com/android/dialer/list/ListsFragment.java | 48 | ||||
-rw-r--r-- | src/com/android/dialer/list/ShortcutCardsAdapter.java | 55 |
2 files changed, 89 insertions, 14 deletions
diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 477db2711..49d6b3af3 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -9,12 +9,14 @@ import android.content.CursorLoader; import android.content.Loader; import android.content.SharedPreferences; import android.database.Cursor; +import android.graphics.Rect; import android.net.Uri; import android.os.Bundle; import android.provider.CallLog; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -31,6 +33,7 @@ import com.android.dialer.calllog.CallLogFragment; import com.android.dialer.calllog.CallLogQuery; import com.android.dialer.calllog.CallLogQueryHandler; import com.android.dialer.calllog.ContactInfoHelper; +import com.android.dialer.list.ShortcutCardsAdapter.SwipeableShortcutCard; import com.android.dialer.widget.OverlappingPaneLayout; import com.android.dialer.widget.OverlappingPaneLayout.PanelSlideListener; import com.android.dialerbind.ObjectFactory; @@ -227,16 +230,8 @@ public class ListsFragment extends Fragment implements CallLogQueryHandler.Liste (ListView) parentView.findViewById(R.id.shortcut_card_list); shortcutCardsListView.setAdapter(mMergedAdapter); - final OverlappingPaneLayout paneLayout = (OverlappingPaneLayout) parentView; - // TODO: Remove the notion of a capturable view. The entire view be slideable, once - // the framework better supports nested scrolling. - paneLayout.setCapturableView(mViewPagerTabs); - paneLayout.openPane(); + setupPaneLayout((OverlappingPaneLayout) parentView, shortcutCardsListView); - LayoutTransition transition = paneLayout.getLayoutTransition(); - // Turns on animations for all types of layout changes so that they occur for - // height changes. - transition.enableTransitionType(LayoutTransition.CHANGING); return parentView; } @@ -302,4 +297,39 @@ public class ListsFragment extends Fragment implements CallLogQueryHandler.Liste mOnPageChangeListeners.get(i).onPageScrollStateChanged(state); } } + + private void setupPaneLayout(OverlappingPaneLayout paneLayout, + final ListView shortcutCardsListView) { + // TODO: Remove the notion of a capturable view. The entire view be slideable, once + // the framework better supports nested scrolling. + paneLayout.setCapturableView(mViewPagerTabs); + paneLayout.openPane(); + paneLayout.setPanelSlideListener(new PanelSlideListener() { + @Override + public void onPanelSlide(View panel, float slideOffset) { + // For every 2 percent that the panel is slid upwards, clip 3 percent from each edge + // of the shortcut card, to achieve the animated effect of the shortcut card + // rapidly shrinking and disappearing from view when the panel is slid upwards. + float ratioCardHidden = (1 - slideOffset) * 1.5f; + if (shortcutCardsListView.getCount() > 0) { + SwipeableShortcutCard v = + (SwipeableShortcutCard) shortcutCardsListView.getChildAt(0); + v.clipCard(ratioCardHidden); + } + } + + @Override + public void onPanelOpened(View panel) { + } + + @Override + public void onPanelClosed(View panel) { + } + }); + + LayoutTransition transition = paneLayout.getLayoutTransition(); + // Turns on animations for all types of layout changes so that they occur for + // height changes. + transition.enableTransitionType(LayoutTransition.CHANGING); + } } diff --git a/src/com/android/dialer/list/ShortcutCardsAdapter.java b/src/com/android/dialer/list/ShortcutCardsAdapter.java index 0009ee57f..8a1f64c1d 100644 --- a/src/com/android/dialer/list/ShortcutCardsAdapter.java +++ b/src/com/android/dialer/list/ShortcutCardsAdapter.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.res.Resources; import android.database.Cursor; import android.database.DataSetObserver; +import android.graphics.Rect; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; @@ -150,12 +151,12 @@ public class ShortcutCardsAdapter extends BaseAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { - final SwipeableCallLogRow wrapper; + final SwipeableShortcutCard wrapper; if (convertView == null) { - wrapper = new SwipeableCallLogRow(mContext); + wrapper = new SwipeableShortcutCard(mContext); wrapper.setOnItemSwipeListener(mCallLogOnItemSwipeListener); } else { - wrapper = (SwipeableCallLogRow) convertView; + wrapper = (SwipeableShortcutCard) convertView; } // Special case wrapper view for the most recent call log item. This allows @@ -186,11 +187,11 @@ public class ShortcutCardsAdapter extends BaseAdapter { /** * The swipeable call log row. */ - private class SwipeableCallLogRow extends FrameLayout implements SwipeHelperCallback { + class SwipeableShortcutCard extends FrameLayout implements SwipeHelperCallback { private SwipeHelper mSwipeHelper; private OnItemGestureListener mOnItemSwipeListener; - public SwipeableCallLogRow(Context context) { + public SwipeableShortcutCard(Context context) { super(context); final float densityScale = getResources().getDisplayMetrics().density; final float pagingTouchSlop = ViewConfiguration.get(context) @@ -270,5 +271,49 @@ public class ShortcutCardsAdapter extends BaseAdapter { public void setOnItemSwipeListener(OnItemGestureListener listener) { mOnItemSwipeListener = listener; } + + private float mPreviousTranslationZ = 0; + private Rect mClipRect = new Rect(); + + /** + * Clips the card by a specified amount. + * + * @param ratioHidden A float indicating how much of each edge of the card should be + * clipped. If 0, the entire card is displayed. If 0.5f, each edge is hidden + * entirely, thus obscuring the entire card. + */ + public void clipCard(float ratioHidden) { + final View viewToClip = getChildAt(0); + if (viewToClip == null) { + return; + } + int width = viewToClip.getWidth(); + int height = viewToClip.getHeight(); + + if (ratioHidden <= 0.01f) { + viewToClip.setTranslationZ(mPreviousTranslationZ); + } else if (viewToClip.getTranslationZ() != 0){ + mPreviousTranslationZ = viewToClip.getTranslationZ(); + viewToClip.setTranslationZ(0); + } + + if (ratioHidden > 0.5f) { + mClipRect.set(0, 0 , 0, 0); + } else { + int newLeft = (int) (ratioHidden * width); + int newRight = (width - newLeft); + int newTop = (int) (ratioHidden * height); + int newBottom = (height - newTop); + mClipRect.set(newLeft, newTop, newRight, newBottom); + } + viewToClip.setClipBounds(mClipRect); + + // If the view has any children, fade them out of view. + final ViewGroup viewGroup = (ViewGroup) viewToClip; + final int count = viewGroup.getChildCount(); + for (int i = 0; i < count; i++) { + viewGroup.getChildAt(i).setAlpha(Math.max(0, 1 - 4 * ratioHidden)); + } + } } } |