1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.layoutlib.bridge.bars;
18
19import com.android.layoutlib.bridge.android.BridgeContext;
20import com.android.resources.Density;
21
22import android.content.Context;
23import android.content.pm.ApplicationInfo;
24import android.util.AttributeSet;
25import android.view.View;
26import android.widget.LinearLayout;
27
28/**
29 * Navigation Bar for the Theme Editor preview.
30 *
31 * For small bars, it is identical to {@link NavigationBar}.
32 * But wide bars from {@link NavigationBar} are too wide for the Theme Editor preview.
33 * To solve that problem, {@link ThemePreviewNavigationBar} use the layout for small bars,
34 * and have no padding on the sides. That way, they have a similar look as the true ones,
35 * and they fit in the Theme Editor preview.
36 */
37public class ThemePreviewNavigationBar extends NavigationBar {
38    private static final int PADDING_WIDTH_SW600 = 0;
39
40    @SuppressWarnings("unused")
41    public ThemePreviewNavigationBar(Context context, AttributeSet attrs) {
42        super((BridgeContext) context,
43                Density.getEnum(((BridgeContext) context).getMetrics().densityDpi),
44                LinearLayout.HORIZONTAL, // In this mode, it doesn't need to be render vertically
45                ((BridgeContext) context).getConfiguration().getLayoutDirection() ==
46                        View.LAYOUT_DIRECTION_RTL,
47                (context.getApplicationInfo().flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0,
48                0, LAYOUT_XML);
49    }
50
51    @Override
52    protected int getSidePadding(float sw) {
53        if (sw >= 600) {
54            return PADDING_WIDTH_SW600;
55        }
56        return super.getSidePadding(sw);
57    }
58}
59