Search in sources :

Example 1 with TitleBar

use of com.android.layoutlib.bridge.bars.TitleBar in project android_frameworks_base by ParanoidAndroid.

the class RenderSessionImpl method inflate.

/**
     * Inflates the layout.
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #init(long)} was not called.
     */
public Result inflate() {
    checkLock();
    try {
        SessionParams params = getParams();
        HardwareConfig hardwareConfig = params.getHardwareConfig();
        BridgeContext context = getContext();
        // the view group that receives the window background.
        ViewGroup backgroundView = null;
        if (mWindowIsFloating || params.isForceNoDecor()) {
            backgroundView = mViewRoot = mContentRoot = new FrameLayout(context);
        } else {
            if (hasSoftwareButtons() && mNavigationBarOrientation == LinearLayout.VERTICAL) {
                /*
                     * This is a special case where the navigation bar is on the right.
                       +-------------------------------------------------+---+
                       | Status bar (always)                             |   |
                       +-------------------------------------------------+   |
                       | (Layout with background drawable)               |   |
                       | +---------------------------------------------+ |   |
                       | | Title/Action bar (optional)                 | |   |
                       | +---------------------------------------------+ |   |
                       | | Content, vertical extending                 | |   |
                       | |                                             | |   |
                       | +---------------------------------------------+ |   |
                       +-------------------------------------------------+---+

                       So we create a horizontal layout, with the nav bar on the right,
                       and the left part is the normal layout below without the nav bar at
                       the bottom
                     */
                LinearLayout topLayout = new LinearLayout(context);
                mViewRoot = topLayout;
                topLayout.setOrientation(LinearLayout.HORIZONTAL);
                try {
                    NavigationBar navigationBar = new NavigationBar(context, hardwareConfig.getDensity(), LinearLayout.VERTICAL);
                    navigationBar.setLayoutParams(new LinearLayout.LayoutParams(mNavigationBarSize, LayoutParams.MATCH_PARENT));
                    topLayout.addView(navigationBar);
                } catch (XmlPullParserException e) {
                }
            }
            /*
                 * we're creating the following layout
                 *
                   +-------------------------------------------------+
                   | Status bar (always)                             |
                   +-------------------------------------------------+
                   | (Layout with background drawable)               |
                   | +---------------------------------------------+ |
                   | | Title/Action bar (optional)                 | |
                   | +---------------------------------------------+ |
                   | | Content, vertical extending                 | |
                   | |                                             | |
                   | +---------------------------------------------+ |
                   +-------------------------------------------------+
                   | Navigation bar for soft buttons, maybe see above|
                   +-------------------------------------------------+

                 */
            LinearLayout topLayout = new LinearLayout(context);
            topLayout.setOrientation(LinearLayout.VERTICAL);
            // if we don't already have a view root this is it
            if (mViewRoot == null) {
                mViewRoot = topLayout;
            } else {
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
                layoutParams.weight = 1;
                topLayout.setLayoutParams(layoutParams);
                // this is the case of soft buttons + vertical bar.
                // this top layout is the first layout in the horizontal layout. see above)
                mViewRoot.addView(topLayout, 0);
            }
            if (mStatusBarSize > 0) {
                // system bar
                try {
                    StatusBar systemBar = new StatusBar(context, hardwareConfig.getDensity());
                    systemBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mStatusBarSize));
                    topLayout.addView(systemBar);
                } catch (XmlPullParserException e) {
                }
            }
            LinearLayout backgroundLayout = new LinearLayout(context);
            backgroundView = backgroundLayout;
            backgroundLayout.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            layoutParams.weight = 1;
            backgroundLayout.setLayoutParams(layoutParams);
            topLayout.addView(backgroundLayout);
            // if the theme says no title/action bar, then the size will be 0
            if (mActionBarSize > 0) {
                try {
                    FakeActionBar actionBar = new FakeActionBar(context, hardwareConfig.getDensity(), params.getAppLabel(), params.getAppIcon());
                    actionBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mActionBarSize));
                    backgroundLayout.addView(actionBar);
                } catch (XmlPullParserException e) {
                }
            } else if (mTitleBarSize > 0) {
                try {
                    TitleBar titleBar = new TitleBar(context, hardwareConfig.getDensity(), params.getAppLabel());
                    titleBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mTitleBarSize));
                    backgroundLayout.addView(titleBar);
                } catch (XmlPullParserException e) {
                }
            }
            // content frame
            mContentRoot = new FrameLayout(context);
            layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            layoutParams.weight = 1;
            mContentRoot.setLayoutParams(layoutParams);
            backgroundLayout.addView(mContentRoot);
            if (mNavigationBarOrientation == LinearLayout.HORIZONTAL && mNavigationBarSize > 0) {
                // system bar
                try {
                    NavigationBar navigationBar = new NavigationBar(context, hardwareConfig.getDensity(), LinearLayout.HORIZONTAL);
                    navigationBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mNavigationBarSize));
                    topLayout.addView(navigationBar);
                } catch (XmlPullParserException e) {
                }
            }
        }
        // Sets the project callback (custom view loader) to the fragment delegate so that
        // it can instantiate the custom Fragment.
        Fragment_Delegate.setProjectCallback(params.getProjectCallback());
        View view = mInflater.inflate(mBlockParser, mContentRoot);
        // done with the parser, pop it.
        context.popParser();
        Fragment_Delegate.setProjectCallback(null);
        // set the AttachInfo on the root view.
        AttachInfo_Accessor.setAttachInfo(mViewRoot);
        // post-inflate process. For now this supports TabHost/TabWidget
        postInflateProcess(view, params.getProjectCallback());
        // get the background drawable
        if (mWindowBackground != null && backgroundView != null) {
            Drawable d = ResourceHelper.getDrawable(mWindowBackground, context);
            backgroundView.setBackground(d);
        }
        return SUCCESS.createResult();
    } catch (PostInflateException e) {
        return ERROR_INFLATION.createResult(e.getMessage(), e);
    } catch (Throwable e) {
        // get the real cause of the exception.
        Throwable t = e;
        while (t.getCause() != null) {
            t = t.getCause();
        }
        return ERROR_INFLATION.createResult(t.getMessage(), t);
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.view.ViewGroup.LayoutParams) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) StatusBar(com.android.layoutlib.bridge.bars.StatusBar) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) NavigationBar(com.android.layoutlib.bridge.bars.NavigationBar) FrameLayout(android.widget.FrameLayout) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) LinearLayout(android.widget.LinearLayout) FakeActionBar(com.android.layoutlib.bridge.bars.FakeActionBar) TitleBar(com.android.layoutlib.bridge.bars.TitleBar)

Example 2 with TitleBar

use of com.android.layoutlib.bridge.bars.TitleBar in project platform_frameworks_base by android.

the class Layout method createTitleBar.

@NonNull
private TitleBar createTitleBar(BridgeContext context, String title, int simulatedPlatformVersion) {
    TitleBar titleBar = new TitleBar(context, title, simulatedPlatformVersion);
    LayoutParams params = createLayoutParams(MATCH_PARENT, mBuilder.mTitleBarSize);
    if (mBuilder.hasStatusBar() && mBuilder.solidBars()) {
        params.addRule(BELOW, getId(ID_STATUS_BAR));
    }
    if (mBuilder.isNavBarVertical() && mBuilder.solidBars()) {
        params.addRule(START_OF, getId(ID_NAV_BAR));
    }
    titleBar.setLayoutParams(params);
    titleBar.setId(getId(ID_TITLE_BAR));
    return titleBar;
}
Also used : TitleBar(com.android.layoutlib.bridge.bars.TitleBar) NonNull(android.annotation.NonNull)

Example 3 with TitleBar

use of com.android.layoutlib.bridge.bars.TitleBar in project android_frameworks_base by ResurrectionRemix.

the class Layout method createTitleBar.

@NonNull
private TitleBar createTitleBar(BridgeContext context, String title, int simulatedPlatformVersion) {
    TitleBar titleBar = new TitleBar(context, title, simulatedPlatformVersion);
    LayoutParams params = createLayoutParams(MATCH_PARENT, mBuilder.mTitleBarSize);
    if (mBuilder.hasStatusBar() && mBuilder.solidBars()) {
        params.addRule(BELOW, getId(ID_STATUS_BAR));
    }
    if (mBuilder.isNavBarVertical() && mBuilder.solidBars()) {
        params.addRule(START_OF, getId(ID_NAV_BAR));
    }
    titleBar.setLayoutParams(params);
    titleBar.setId(getId(ID_TITLE_BAR));
    return titleBar;
}
Also used : TitleBar(com.android.layoutlib.bridge.bars.TitleBar) NonNull(android.annotation.NonNull)

Example 4 with TitleBar

use of com.android.layoutlib.bridge.bars.TitleBar in project android_frameworks_base by AOSPA.

the class Layout method createTitleBar.

@NonNull
private TitleBar createTitleBar(BridgeContext context, String title, int simulatedPlatformVersion) {
    TitleBar titleBar = new TitleBar(context, title, simulatedPlatformVersion);
    LayoutParams params = createLayoutParams(MATCH_PARENT, mBuilder.mTitleBarSize);
    if (mBuilder.hasStatusBar() && mBuilder.solidBars()) {
        params.addRule(BELOW, getId(ID_STATUS_BAR));
    }
    if (mBuilder.isNavBarVertical() && mBuilder.solidBars()) {
        params.addRule(START_OF, getId(ID_NAV_BAR));
    }
    titleBar.setLayoutParams(params);
    titleBar.setId(getId(ID_TITLE_BAR));
    return titleBar;
}
Also used : TitleBar(com.android.layoutlib.bridge.bars.TitleBar) NonNull(android.annotation.NonNull)

Example 5 with TitleBar

use of com.android.layoutlib.bridge.bars.TitleBar in project android_frameworks_base by DirtyUnicorns.

the class Layout method createTitleBar.

@NonNull
private TitleBar createTitleBar(BridgeContext context, String title, int simulatedPlatformVersion) {
    TitleBar titleBar = new TitleBar(context, title, simulatedPlatformVersion);
    LayoutParams params = createLayoutParams(MATCH_PARENT, mBuilder.mTitleBarSize);
    if (mBuilder.hasStatusBar() && mBuilder.solidBars()) {
        params.addRule(BELOW, getId(ID_STATUS_BAR));
    }
    if (mBuilder.isNavBarVertical() && mBuilder.solidBars()) {
        params.addRule(START_OF, getId(ID_NAV_BAR));
    }
    titleBar.setLayoutParams(params);
    titleBar.setId(getId(ID_TITLE_BAR));
    return titleBar;
}
Also used : TitleBar(com.android.layoutlib.bridge.bars.TitleBar) NonNull(android.annotation.NonNull)

Aggregations

TitleBar (com.android.layoutlib.bridge.bars.TitleBar)6 NonNull (android.annotation.NonNull)5 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ExpandableListView (android.widget.ExpandableListView)1 FrameLayout (android.widget.FrameLayout)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 HardwareConfig (com.android.ide.common.rendering.api.HardwareConfig)1 SessionParams (com.android.ide.common.rendering.api.SessionParams)1 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)1 FakeActionBar (com.android.layoutlib.bridge.bars.FakeActionBar)1 NavigationBar (com.android.layoutlib.bridge.bars.NavigationBar)1 StatusBar (com.android.layoutlib.bridge.bars.StatusBar)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1