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

Commit 3b90b74c authored by Jerome Gaillard's avatar Jerome Gaillard
Browse files

Create new Navigation Bar for the Theme Editor Preview

The standard navigation bar was not working well in the Theme Editor preview
when in a wide configuration. The bar then did not fit entirely inside the display.
So we created a new Navigation Bar to use in the Theme Editor preview, that fixes
the size problem.

Bug: http://b.android.com/198179
Change-Id: Ifb1fa7b8f399f17392934de89078696337eca3e1
parent 4b0fe7f1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
     */
    private static LayoutLog sCurrentLog = sDefaultLog;

    private static final int LAST_SUPPORTED_FEATURE = Features.CHOREOGRAPHER;
    private static final int LAST_SUPPORTED_FEATURE = Features.THEME_PREVIEW_NAVIGATION_BAR;

    @Override
    public int getApiLevel() {
+9 −23
Original line number Diff line number Diff line
@@ -19,9 +19,6 @@ package com.android.layoutlib.bridge.bars;
import com.android.layoutlib.bridge.android.BridgeContext;
import com.android.resources.Density;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.LinearLayout;
@@ -41,29 +38,18 @@ public class NavigationBar extends CustomBar {
    private static final int WIDTH_DEFAULT = 36;
    private static final int WIDTH_SW360 = 40;
    private static final int WIDTH_SW600 = 48;
    private static final String LAYOUT_XML = "/bars/navigation_bar.xml";
    protected static final String LAYOUT_XML = "/bars/navigation_bar.xml";
    private static final String LAYOUT_600DP_XML = "/bars/navigation_bar600dp.xml";


    /**
     * Constructor to be used when creating the {@link NavigationBar} as a regular control.
     * This is currently used by the theme editor.
     */
    @SuppressWarnings("unused")
    public NavigationBar(Context context, AttributeSet attrs) {
        this((BridgeContext) context,
                Density.getEnum(((BridgeContext) context).getMetrics().densityDpi),
                LinearLayout.HORIZONTAL, // In this mode, it doesn't need to be render vertically
                ((BridgeContext) context).getConfiguration().getLayoutDirection() ==
                        View.LAYOUT_DIRECTION_RTL,
                (context.getApplicationInfo().flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0,
                0);
    }

    public NavigationBar(BridgeContext context, Density density, int orientation, boolean isRtl,
      boolean rtlEnabled, int simulatedPlatformVersion) {
        super(context, orientation, getShortestWidth(context)>= 600 ? LAYOUT_600DP_XML : LAYOUT_XML,
                "navigation_bar.xml", simulatedPlatformVersion);
        this(context, density, orientation, isRtl, rtlEnabled, simulatedPlatformVersion,
          getShortestWidth(context)>= 600 ? LAYOUT_600DP_XML : LAYOUT_XML);
    }

    protected NavigationBar(BridgeContext context, Density density, int orientation, boolean isRtl,
      boolean rtlEnabled, int simulatedPlatformVersion, String layoutPath) {
        super(context, orientation, layoutPath, "navigation_bar.xml", simulatedPlatformVersion);

        int color = getBarColor(ATTR_COLOR, ATTR_TRANSLUCENT);
        setBackgroundColor(color == 0 ? 0xFF000000 : color);
@@ -117,7 +103,7 @@ public class NavigationBar extends CustomBar {
        view.setLayoutParams(layoutParams);
    }

    private static int getSidePadding(float sw) {
    protected int getSidePadding(float sw) {
        if (sw >= 400) {
            return PADDING_WIDTH_SW400;
        }
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.layoutlib.bridge.bars;

import com.android.layoutlib.bridge.android.BridgeContext;
import com.android.resources.Density;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

/**
 * Navigation Bar for the Theme Editor preview.
 *
 * For small bars, it is identical to {@link NavigationBar}.
 * But wide bars from {@link NavigationBar} are too wide for the Theme Editor preview.
 * To solve that problem, {@link ThemePreviewNavigationBar} use the layout for small bars,
 * and have no padding on the sides. That way, they have a similar look as the true ones,
 * and they fit in the Theme Editor preview.
 */
public class ThemePreviewNavigationBar extends NavigationBar {
    private static final int PADDING_WIDTH_SW600 = 0;

    @SuppressWarnings("unused")
    public ThemePreviewNavigationBar(Context context, AttributeSet attrs) {
        super((BridgeContext) context,
                Density.getEnum(((BridgeContext) context).getMetrics().densityDpi),
                LinearLayout.HORIZONTAL, // In this mode, it doesn't need to be render vertically
                ((BridgeContext) context).getConfiguration().getLayoutDirection() ==
                        View.LAYOUT_DIRECTION_RTL,
                (context.getApplicationInfo().flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0,
                0, LAYOUT_XML);
    }

    @Override
    protected int getSidePadding(float sw) {
        if (sw >= 600) {
            return PADDING_WIDTH_SW600;
        }
        return super.getSidePadding(sw);
    }
}