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

Commit 76295431 authored by Josh Guilfoyle's avatar Josh Guilfoyle
Browse files

Safely allow themes to specify no left or right bottom bar.

parent 97425a8b
Loading
Loading
Loading
Loading
+34 −18
Original line number Diff line number Diff line
@@ -77,7 +77,9 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
    
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        if (mBottomLeftStrip != null || mBottomRightStrip != null) {
            mStripMoved = true;
        }
        super.onSizeChanged(w, h, oldw, oldh);
    }

@@ -104,32 +106,44 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {

        View selectedChild = getChildAt(mSelectedTab);
        
        if (mBottomLeftStrip != null) {
            mBottomLeftStrip.setState(selectedChild.getDrawableState());
        }
        if (mBottomRightStrip != null) {
            mBottomRightStrip.setState(selectedChild.getDrawableState());
        }
        
        if (mStripMoved) {
            Rect selBounds = new Rect(); // Bounds of the selected tab indicator
            selBounds.left = selectedChild.getLeft();
            selBounds.right = selectedChild.getRight();
            final int myHeight = getHeight();
            if (mBottomLeftStrip != null) {
                mBottomLeftStrip.setBounds(
                        Math.min(0, selBounds.left 
                                     - mBottomLeftStrip.getIntrinsicWidth()),
                        myHeight - mBottomLeftStrip.getIntrinsicHeight(),
                        selBounds.left,
                        getHeight());
            }
            if (mBottomRightStrip != null) {
                mBottomRightStrip.setBounds(
                        selBounds.right,
                        myHeight - mBottomRightStrip.getIntrinsicHeight(),
                        Math.max(getWidth(), 
                                selBounds.right + mBottomRightStrip.getIntrinsicWidth()),
                        myHeight);
            }
            mStripMoved = false;
        }
        
        if (mBottomLeftStrip != null) {
            mBottomLeftStrip.draw(canvas);
        }
        if (mBottomRightStrip != null) {
            mBottomRightStrip.draw(canvas);
        }
    }

    /**
     * Sets the current tab.
@@ -166,8 +180,10 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        getChildAt(mSelectedTab).setSelected(false);
        mSelectedTab = index;
        getChildAt(mSelectedTab).setSelected(true);
        if (mBottomLeftStrip != null || mBottomRightStrip != null) {
            mStripMoved = true;
        }
    }
    
    /**
     * Sets the current tab and focuses the UI on it.