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

Commit acdef59d authored by Bjorn Bringert's avatar Bjorn Bringert
Browse files

Fix TabHost NPE when there are no tabs

Fixes http://b/issue?id=2318588

Change-Id: If90ee7e2b777e4c77fdd0ae768d1ececa792ee1b
parent 159f0015
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -279,6 +279,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
        if (!handled
                && (event.getAction() == KeyEvent.ACTION_DOWN)
                && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP)
                && (mCurrentView != null)
                && (mCurrentView.isRootNamespace())
                && (mCurrentView.hasFocus())
                && (mCurrentView.findFocus().focusSearch(View.FOCUS_UP) == null)) {
@@ -292,8 +293,10 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");

    @Override
    public void dispatchWindowFocusChanged(boolean hasFocus) {
        if (mCurrentView != null){
            mCurrentView.dispatchWindowFocusChanged(hasFocus);
        }
    }

    public void setCurrentTab(int index) {
        if (index < 0 || index >= mTabSpecs.size()) {
+5 −2
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {

    @Override
    public void childDrawableStateChanged(View child) {
        if (child == getChildTabViewAt(mSelectedTab)) {
        if (getTabCount() > 0 && child == getChildTabViewAt(mSelectedTab)) {
            // To make sure that the bottom strip is redrawn
            invalidate();
        }
@@ -194,6 +194,9 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
    public void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);

        // Do nothing if there are no tabs.
        if (getTabCount() == 0) return;

        // If the user specified a custom view for the tab indicators, then
        // do not draw the bottom strips.
        if (!mDrawBottomStrips) {
@@ -347,7 +350,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
    }

    public void onFocusChange(View v, boolean hasFocus) {
        if (v == this && hasFocus) {
        if (v == this && hasFocus && getTabCount() > 0) {
            getChildTabViewAt(mSelectedTab).requestFocus();
            return;
        }