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

Commit 796992a9 authored by Tor Norbye's avatar Tor Norbye Committed by Xavier Ducrohet
Browse files

Allow TabHosts to have no children in the tabcontent widget

Replace the code which throws an exception if there are no children in
the FrameLayout that is the tabcontent, with code to add a single
dummy tab.

This makes the TabHost renderable in those scenarios where the real
tabs are added dynamically rather than via XML.

Change-Id: I72442bd7d40eddd875b3507585c1f372fcae3329
parent 60610d24
Loading
Loading
Loading
Loading
+28 −18
Original line number Diff line number Diff line
@@ -67,8 +67,10 @@ import android.view.View.AttachInfo;
import android.view.View.MeasureSpec;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TabHost.TabSpec;

import java.awt.Color;
import java.awt.Graphics2D;
@@ -918,7 +920,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
    /**
     * Returns the top screen offset. This depends on whether the current theme defines the user
     * of the title and status bars.
     * @param resolver The {@link ResourceResolver}
     * @param resolver The {@link RenderResources}
     * @param metrics The display metrics
     * @return the pixel height offset
     */
@@ -1047,15 +1049,22 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
        // now process the content of the framelayout and dynamically create tabs for it.
        final int count = content.getChildCount();

        if (count == 0) {
            throw new PostInflateException(
                    "The FrameLayout for the TabHost has no content. Rendering failed.\n");
        }

        // this must be called before addTab() so that the TabHost searches its TabWidget
        // and FrameLayout.
        tabHost.setup();

        if (count == 0) {
            // Create a dummy child to get a single tab
            TabSpec spec = tabHost.newTabSpec("tag").setIndicator("Tab Label",
                    tabHost.getResources().getDrawable(android.R.drawable.ic_menu_info_details))
                    .setContent(new TabHost.TabContentFactory() {
                        public View createTabContent(String tag) {
                            return new LinearLayout(mContext);
                        }
                    });
            tabHost.addTab(spec);
            return;
        } else {
            // for each child of the framelayout, add a new TabSpec
            for (int i = 0 ; i < count ; i++) {
                View child = content.getChildAt(i);
@@ -1071,6 +1080,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
                tabHost.addTab(tabHost.newTabSpec(tabSpec).setIndicator(name).setContent(id));
            }
        }
    }


    /**