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

Commit f2fb76cc authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Fix potential NPE if there is no child in HorizontalScrollView

- related to the previous change for saving the scroll position
- also related to bug #9463581 NPE observed while launching News&Weather app from all apps tray

Change-Id: I9f2f8a246e793eefa1cf510e15a56a1058fb9c18
parent fafe88c3
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -1456,14 +1456,22 @@ public class HorizontalScrollView extends FrameLayout {

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        // There is only one child
        final View child = getChildAt(0);
        final int childWidth = child.getMeasuredWidth();
        final LayoutParams childParams = (LayoutParams) child.getLayoutParams();
        int childWidth = 0;
        int childMargins = 0;

        if (getChildCount() > 0) {
            childWidth = getChildAt(0).getMeasuredWidth();
            LayoutParams childParams = (LayoutParams) getChildAt(0).getLayoutParams();
            childMargins = childParams.leftMargin + childParams.rightMargin;
        }

        final int available = r - l - getPaddingLeftWithForeground() -
                getPaddingRightWithForeground() - childParams.leftMargin - childParams.rightMargin;
                getPaddingRightWithForeground() - childMargins;

        final boolean forceLeftGravity = (childWidth > available);

        layoutChildren(l, t, r, b, forceLeftGravity);

        mIsLayoutDirty = false;
        // Give a child focus if it needs it
        if (mChildToScrollTo != null && isViewDescendantOf(mChildToScrollTo, this)) {