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

Commit 8ac1a314 authored by Katherine Kuan's avatar Katherine Kuan Committed by Android (Google) Code Review
Browse files

Merge "Coordinate scrolling between two lists on contact card"

parents 5001162c 6c0470e2
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@
    <ListView android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_social_updates"
        android:fadingEdge="none"
        android:divider="@null"/>

+0 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@
    <ListView android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/background_social_updates"
        android:fadingEdge="none"
        android:divider="@null"/>

+2 −1
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@
    android:background="@drawable/bg_people_updates_holo">

    <ImageView android:id="@+id/status_photo"
        android:layout_width="wrap_content"
        android:scaleType="centerCrop"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
+4 −4
Original line number Diff line number Diff line
@@ -20,5 +20,5 @@
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
        android:background="@color/background_social_updates"
    android:background="@color/background_primary"
    android:divider="@null"/>
+41 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.view.animation.AlphaAnimation;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;
@@ -500,4 +501,44 @@ public class ContactDetailDisplayUtils {
            view.setBackgroundColor((int) (alpha * 255) << 24);
        }
    }

    /**
     * Returns the top coordinate of the first item in the {@link ListView}. If the first item
     * in the {@link ListView} is not visible or there are no children in the list, then return
     * Integer.MIN_VALUE. Note that the returned value will be <= 0 because the first item in the
     * list cannot have a positive offset.
     */
    public static int getFirstListItemOffset(ListView listView) {
        if (listView == null || listView.getChildCount() == 0 ||
                listView.getFirstVisiblePosition() != 0) {
            return Integer.MIN_VALUE;
        }
        return listView.getChildAt(0).getTop();
    }

    /**
     * Tries to scroll the first item in the list to the given offset (this can be a no-op if the
     * list is already in the correct position).
     * @param listView that should be scrolled
     * @param offset which should be <= 0
     */
    public static void requestToMoveToOffset(ListView listView, int offset) {
        // We try to offset the list if the first item in the list is showing (which is presumed
        // to have a larger height than the desired offset). If the first item in the list is not
        // visible, then we simply do not scroll the list at all (since it can get complicated to
        // compute how many items in the list will equal the given offset). Potentially
        // some animation elsewhere will make the transition smoother for the user to compensate
        // for this simplification.
        if (listView == null || listView.getChildCount() == 0 ||
                listView.getFirstVisiblePosition() != 0 || offset > 0) {
            return;
        }

        // As an optimization, check if the first item is already at the given offset.
        if (listView.getChildAt(0).getTop() == offset) {
            return;
        }

        listView.setSelectionFromTop(0, offset);
    }
}
Loading