Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d939e45 authored by Brian Attwell's avatar Brian Attwell
Browse files

When view's expand, scroll them onto screen

Do this for views at the top and bottom of the list.

Bug: 17410384
Change-Id: I5506909ae93658dea4e86b4a541eefbec28c15e4
parent d688f64c
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -26,13 +26,14 @@ import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.database.Cursor;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract;
import android.provider.VoicemailContract.Status;
import android.util.Log;
import android.util.MutableInt;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -595,7 +596,16 @@ public class CallLogFragment extends AnalyticsListFragment
                ValueAnimator animator = isExpand ? ValueAnimator.ofFloat(0f, 1f)
                        : ValueAnimator.ofFloat(1f, 0f);

                // Figure out how much scrolling is needed to make the view fully visible.
                final Rect localVisibleRect = new Rect();
                view.getLocalVisibleRect(localVisibleRect);
                final int scrollingNeeded = localVisibleRect.top > 0 ? -localVisibleRect.top
                        : view.getMeasuredHeight() - localVisibleRect.height();

                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    private int mCurrentScroll = 0;

                    @Override
                    public void onAnimationUpdate(ValueAnimator animator) {
                        Float value = (Float) animator.getAnimatedValue();
@@ -606,6 +616,12 @@ public class CallLogFragment extends AnalyticsListFragment
                        viewHolder.callLogEntryView.setTranslationZ(z);
                        view.setTranslationZ(z); // WAR
                        view.requestLayout();

                        if (isExpand) {
                            int scrollBy = (int) (value * scrollingNeeded) - mCurrentScroll;
                            getListView().smoothScrollBy(scrollBy, /* duration = */ 0);
                            mCurrentScroll += scrollBy;
                        }
                    }
                });
                // Set everything to their final values when the animation's done.