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

Commit 64c031c7 authored by Andrew Lee's avatar Andrew Lee Committed by Android (Google) Code Review
Browse files

Merge "Remove expand/collapse animations in the Call Log."

parents ff6adf9a c6fde8d1
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -27,16 +27,4 @@
    <dimen name="min_swipe">0dip</dimen>
    <dimen name="min_vert">10dip</dimen>
    <dimen name="min_lock">20dip</dimen>

    <!-- Expand/collapse of call log entry duration. -->
    <integer name="call_log_expand_collapse_duration">200</integer>

    <!-- Start delay for the fade in of the call log actions. -->
    <integer name="call_log_actions_fade_start">150</integer>

    <!-- Duration of the fade in of the call log actions. -->
    <integer name="call_log_actions_fade_in_duration">50</integer>

    <!-- Duration of the fade out of the call log actions. -->
    <integer name="call_log_actions_fade_out_duration">20</integer>
</resources>
+4 −38
Original line number Diff line number Diff line
@@ -94,12 +94,6 @@ public class CallLogAdapter extends GroupingListAdapter

    protected ContactInfoCache mContactInfoCache;

    /**
     * Tracks the call log row which was previously expanded.  Used so that the closure of a
     * previously expanded call log entry can be animated on rebind.
     */
    private long mPreviouslyExpanded = NONE_EXPANDED;

    /**
     * Tracks the currently expanded call log row.
     */
@@ -192,15 +186,16 @@ public class CallLogAdapter extends GroupingListAdapter
        return true;
    }

    public CallLogAdapter(Context context, CallFetcher callFetcher,
            ContactInfoHelper contactInfoHelper, CallItemExpandedListener callItemExpandedListener,
    public CallLogAdapter(
            Context context,
            CallFetcher callFetcher,
            ContactInfoHelper contactInfoHelper,
            OnReportButtonClickListener onReportButtonClickListener) {
        super(context);

        mContext = context;
        mCallFetcher = callFetcher;
        mContactInfoHelper = contactInfoHelper;
        mCallItemExpandedListener = callItemExpandedListener;

        mOnReportButtonClickListener = onReportButtonClickListener;

@@ -499,14 +494,10 @@ public class CallLogAdapter extends GroupingListAdapter
    private boolean toggleExpansion(long rowId) {
        if (rowId == mCurrentlyExpanded) {
            // Collapsing currently expanded row.
            mPreviouslyExpanded = NONE_EXPANDED;
            mCurrentlyExpanded = NONE_EXPANDED;

            return false;
        } else {
            // Expanding a row (collapsing current expanded one).

            mPreviouslyExpanded = mCurrentlyExpanded;
            mCurrentlyExpanded = rowId;
            return true;
        }
@@ -670,30 +661,5 @@ public class CallLogAdapter extends GroupingListAdapter
                mActionListener,
                mPhoneNumberUtilsWrapper,
                mCallLogViewsHelper);

        // Animate the expansion or collapse.
        if (mCallItemExpandedListener != null) {
            if (animate) {
                mCallItemExpandedListener.onItemExpanded(view);
            }

            // Animate the collapse of the previous item if it is still visible on screen.
            if (mPreviouslyExpanded != NONE_EXPANDED) {
                View previousItem = mCallItemExpandedListener.getViewForCallId(mPreviouslyExpanded);

                if (previousItem != null) {
                    ((CallLogListItemViews) previousItem.getTag()).expandOrCollapseActions(
                            false /* isExpanded */,
                            mOnReportButtonClickListener,
                            mActionListener,
                            mPhoneNumberUtilsWrapper,
                            mCallLogViewsHelper);
                    if (animate) {
                        mCallItemExpandedListener.onItemExpanded(previousItem);
                    }
                }
                mPreviouslyExpanded = NONE_EXPANDED;
            }
        }
    }
}
+2 −151
Original line number Diff line number Diff line
@@ -62,8 +62,7 @@ import java.util.List;
 */
public class CallLogFragment extends ListFragment
        implements CallLogQueryHandler.Listener, CallLogAdapter.OnReportButtonClickListener,
        CallLogAdapter.CallFetcher,
        CallLogAdapter.CallItemExpandedListener {
        CallLogAdapter.CallFetcher {
    private static final String TAG = "CallLogFragment";

    private static final String REPORT_DIALOG_TAG = "report_dialog";
@@ -97,12 +96,6 @@ public class CallLogFragment extends ListFragment
    private boolean mCallLogFetched;
    private boolean mVoicemailStatusFetched;

    private float mExpandedItemTranslationZ;
    private int mFadeInDuration;
    private int mFadeInStartDelay;
    private int mFadeOutDuration;
    private int mExpandCollapseDuration;

    private final Handler mHandler = new Handler();

    private class CustomContentObserver extends ContentObserver {
@@ -186,7 +179,7 @@ public class CallLogFragment extends ListFragment

        String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity());
        mAdapter = ObjectFactory.newCallLogAdapter(getActivity(), this,
                new ContactInfoHelper(getActivity(), currentCountryIso), this, this);
                new ContactInfoHelper(getActivity(), currentCountryIso), this);
        setListAdapter(mAdapter);
        mCallLogQueryHandler = new CallLogQueryHandler(getActivity().getContentResolver(),
                this, mLogLimit);
@@ -200,14 +193,6 @@ public class CallLogFragment extends ListFragment
                Status.CONTENT_URI, true, mVoicemailStatusObserver);
        setHasOptionsMenu(true);
        fetchCalls();

        mExpandedItemTranslationZ =
                getResources().getDimension(R.dimen.call_log_expanded_translation_z);
        mFadeInDuration = getResources().getInteger(R.integer.call_log_actions_fade_in_duration);
        mFadeInStartDelay = getResources().getInteger(R.integer.call_log_actions_fade_start);
        mFadeOutDuration = getResources().getInteger(R.integer.call_log_actions_fade_out_duration);
        mExpandCollapseDuration = getResources().getInteger(
                R.integer.call_log_expand_collapse_duration);
    }

    /** Called by the CallLogQueryHandler when the list of calls has been fetched or updated. */
@@ -521,140 +506,6 @@ public class CallLogFragment extends ListFragment
        ViewUtil.addBottomPaddingToListViewForFab(listView, getResources());
    }

    @Override
    public void onItemExpanded(final View view) {
        final int startingHeight = view.getHeight();
        final CallLogListItemViews viewHolder = (CallLogListItemViews) view.getTag();
        final ViewTreeObserver observer = getListView().getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                // We don't want to continue getting called for every draw.
                if (observer.isAlive()) {
                    observer.removeOnPreDrawListener(this);
                }
                // Calculate some values to help with the animation.
                final int endingHeight = view.getHeight();
                final int distance = Math.abs(endingHeight - startingHeight);
                final int baseHeight = Math.min(endingHeight, startingHeight);
                final boolean isExpand = endingHeight > startingHeight;

                // Set the views back to the start state of the animation
                view.getLayoutParams().height = startingHeight;
                if (!isExpand) {
                    viewHolder.actionsView.setVisibility(View.VISIBLE);
                }
                viewHolder.expandVoicemailTranscriptionView(!isExpand);

                // Set up the fade effect for the action buttons.
                if (isExpand) {
                    // Start the fade in after the expansion has partly completed, otherwise it
                    // will be mostly over before the expansion completes.
                    viewHolder.actionsView.setAlpha(0f);
                    viewHolder.actionsView.animate()
                            .alpha(1f)
                            .setStartDelay(mFadeInStartDelay)
                            .setDuration(mFadeInDuration)
                            .start();
                } else {
                    viewHolder.actionsView.setAlpha(1f);
                    viewHolder.actionsView.animate()
                            .alpha(0f)
                            .setDuration(mFadeOutDuration)
                            .start();
                }
                view.requestLayout();

                // Set up the animator to animate the expansion and shadow depth.
                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();
                final ListView listView = getListView();
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    private int mCurrentScroll = 0;

                    @Override
                    public void onAnimationUpdate(ValueAnimator animator) {
                        Float value = (Float) animator.getAnimatedValue();

                        // For each value from 0 to 1, animate the various parts of the layout.
                        view.getLayoutParams().height = (int) (value * distance + baseHeight);
                        float z = mExpandedItemTranslationZ * value;
                        viewHolder.callLogEntryView.setTranslationZ(z);
                        view.setTranslationZ(z); // WAR
                        view.requestLayout();

                        if (isExpand) {
                            if (listView != null) {
                                int scrollBy = (int) (value * scrollingNeeded) - mCurrentScroll;
                                listView.smoothScrollBy(scrollBy, /* duration = */ 0);
                                mCurrentScroll += scrollBy;
                            }
                        }
                    }
                });
                // Set everything to their final values when the animation's done.
                animator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        view.getLayoutParams().height = LayoutParams.WRAP_CONTENT;

                        if (!isExpand) {
                            viewHolder.actionsView.setVisibility(View.GONE);
                        } else {
                            // This seems like it should be unnecessary, but without this, after
                            // navigating out of the activity and then back, the action view alpha
                            // is defaulting to the value (0) at the start of the expand animation.
                            viewHolder.actionsView.setAlpha(1);
                        }
                        viewHolder.expandVoicemailTranscriptionView(isExpand);
                    }
                });

                animator.setDuration(mExpandCollapseDuration);
                animator.start();

                // Return false so this draw does not occur to prevent the final frame from
                // being drawn for the single frame before the animations start.
                return false;
            }
        });
    }

    /**
     * Retrieves the call log view for the specified call Id.  If the view is not currently
     * visible, returns null.
     *
     * @param callId The call Id.
     * @return The call log view.
     */
    @Override
    public View getViewForCallId(long callId) {
        ListView listView = getListView();

        int firstPosition = listView.getFirstVisiblePosition();
        int lastPosition = listView.getLastVisiblePosition();

        for (int position = 0; position <= lastPosition - firstPosition; position++) {
            View view = listView.getChildAt(position);

            if (view != null) {
                final CallLogListItemViews viewHolder = (CallLogListItemViews) view.getTag();
                if (viewHolder != null && viewHolder.rowId == callId) {
                    return view;
                }
            }
        }

        return null;
    }

    public void onBadDataReported(String number) {
        if (number == null) {
            return;
+6 −6
Original line number Diff line number Diff line
@@ -42,15 +42,15 @@ public class ObjectFactory {
     * @param context The context to use.
     * @param callFetcher Instance of call fetcher to use.
     * @param contactInfoHelper Instance of contact info helper class to use.
     * @param isCallLog Is this call log adapter being used on the call log?
     * @return Instance of CallLogAdapter.
     */
    public static CallLogAdapter newCallLogAdapter(Context context,
            CallFetcher callFetcher, ContactInfoHelper contactInfoHelper,
            CallItemExpandedListener callItemExpandedListener,
    public static CallLogAdapter newCallLogAdapter(
            Context context,
            CallFetcher callFetcher,
            ContactInfoHelper contactInfoHelper,
            OnReportButtonClickListener onReportButtonClickListener) {
        return new CallLogAdapter(context, callFetcher, contactInfoHelper,
                callItemExpandedListener, onReportButtonClickListener);
        return new CallLogAdapter(
                context, callFetcher, contactInfoHelper, onReportButtonClickListener);
    }

    public static DialogFragment getReportDialogFragment(String number) {
+1 −1
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ public class CallLogAdapterTest extends AndroidTestCase {
    private static final class TestCallLogAdapter extends CallLogAdapter {
        public TestCallLogAdapter(Context context, CallFetcher callFetcher,
                ContactInfoHelper contactInfoHelper) {
            super(context, callFetcher, contactInfoHelper, null, null);
            super(context, callFetcher, contactInfoHelper, null);
            mContactInfoCache = new TestContactInfoCache(
                    contactInfoHelper, mOnContactInfoChangedListener);
        }