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

Commit ccf3b6bb authored by Katherine Kuan's avatar Katherine Kuan
Browse files

Fix fragment carousel going to wrong scroll position after rotation

- On devices with no physical buttons, there is a status
bar on screen, which triggers an onSizeChanged() method call
which causes the ContactDetailFragmentCarousel to scroll to
the focused view (which was wrongly set as the ListView in the
details page in phone landscape).

- Make sure the right view is focused on and remove the manual
scroll code in onLayout() in ContactDetailFragmentCarousel
because it doesn't do anything because the width of the child
view is not correct (when the page is first launched and doesn't
cause any scroll changes). Instead, when the data is loaded
and we enable/disable swipe, we select the right view to be focused
on, which takes care of scrolling to the right page.

Bug: 5265640
Change-Id: Id3b568b2d1c3af5d4d6cae285038131bb4cb1a45
parent 758da74e
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -30,7 +30,9 @@
        android:id="@+id/about_fragment_container"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1" />
        android:layout_weight="1"
        android:focusable="true"
        android:focusableInTouchMode="true" />

    <!--
      Container for the "Updates" page fragment on the contact card for a contact
@@ -42,6 +44,8 @@
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:visibility="gone" />
        android:visibility="gone"
        android:focusable="true"
        android:focusableInTouchMode="true" />

</LinearLayout>
 No newline at end of file
+8 −31
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.contacts.detail;
import com.android.contacts.R;

import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -88,8 +87,6 @@ public class ContactDetailFragmentCarousel extends HorizontalScrollView implemen
    private View mDetailFragmentView;
    private View mUpdatesFragmentView;

    private boolean mScrollToCurrentPage = false;

    public ContactDetailFragmentCarousel(Context context) {
        this(context, null);
    }
@@ -144,31 +141,9 @@ public class ContactDetailFragmentCarousel extends HorizontalScrollView implemen
                resolveSize(screenHeight, heightMeasureSpec));
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        if (mScrollToCurrentPage) {
            mScrollToCurrentPage = false;
            // Use scrollTo() instead of smoothScrollTo() to prevent a visible flicker to the user
            scrollTo(mCurrentPage == ABOUT_PAGE ? 0 : mAllowedHorizontalScrollLength, 0);
            updateTouchInterceptors();
        }
    }

    /**
     * Set the current page that should be restored when the view is first laid out.
     */
    public void restoreCurrentPage(int pageIndex) {
        setCurrentPage(pageIndex);
        // It is only possible to scroll the view after onMeasure() has been called (where the
        // allowed horizontal scroll length is determined). Hence, set a flag that will be read
        // in onLayout() after the children and this view have finished being laid out.
        mScrollToCurrentPage = true;
    }

    /**
     * Set the current page. This auto-scrolls the carousel to the current page and dims out
     * the non-selected page.
     * Set the current page. This dims out the non-selected page but doesn't do any scrolling of
     * the carousel.
     */
    public void setCurrentPage(int pageIndex) {
        mCurrentPage = pageIndex;
@@ -176,7 +151,6 @@ public class ContactDetailFragmentCarousel extends HorizontalScrollView implemen
        if (mAboutFragment != null && mUpdatesFragment != null) {
            mAboutFragment.setAlphaLayerValue(mCurrentPage == ABOUT_PAGE ? 0 : MAX_ALPHA);
            mUpdatesFragment.setAlphaLayerValue(mCurrentPage == UPDATES_PAGE ? 0 : MAX_ALPHA);
            snapToEdge();
        }
    }

@@ -205,9 +179,12 @@ public class ContactDetailFragmentCarousel extends HorizontalScrollView implemen
            mEnableSwipe = enable;
            if (mUpdatesFragmentView != null) {
                mUpdatesFragmentView.setVisibility(enable ? View.VISIBLE : View.GONE);
                mScrollToCurrentPage = true;
                requestLayout();
                invalidate();
                if (mCurrentPage == ABOUT_PAGE) {
                    mDetailFragmentView.requestFocus();
                } else {
                    mUpdatesFragmentView.requestFocus();
                }
                updateTouchInterceptors();
            }
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ public class ContactDetailLayoutController {

                mFragmentCarousel.setFragmentViews(mDetailFragmentView, mUpdatesFragmentView);
                mFragmentCarousel.setFragments(mDetailFragment, mUpdatesFragment);
                mFragmentCarousel.restoreCurrentPage(currentPageIndex);
                mFragmentCarousel.setCurrentPage(currentPageIndex);
                break;
            }
        }