NavigationBar.java revision e5afc3117be394fdd92496b39e9bad248972902a
1/*
2 * Copyright (C) 2011 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;
27import android.widget.TextView;
28
29public class NavigationBar extends CustomBar {
30
31    /** Navigation bar background color attribute name. */
32    private static final String ATTR_COLOR = "navigationBarColor";
33
34    /**
35     * Constructor to be used when creating the {@link NavigationBar} as a regular control.
36     * This is currently used by the theme editor.
37     */
38    @SuppressWarnings("unused")
39    public NavigationBar(Context context, AttributeSet attrs) {
40        this((BridgeContext) context,
41                Density.getEnum(((BridgeContext) context).getMetrics().densityDpi),
42                LinearLayout.HORIZONTAL, // In this mode, it doesn't need to be render vertically
43                ((BridgeContext) context).getConfiguration().getLayoutDirection() ==
44                        View.LAYOUT_DIRECTION_RTL,
45                (context.getApplicationInfo().flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0,
46                context.getApplicationInfo().targetSdkVersion);
47    }
48
49    public NavigationBar(BridgeContext context, Density density, int orientation, boolean isRtl,
50            boolean rtlEnabled, int simulatedPlatformVersion) {
51        super(context, orientation, "/bars/navigation_bar.xml", "navigation_bar.xml",
52                simulatedPlatformVersion);
53
54        int color = getThemeAttrColor(ATTR_COLOR, true);
55        setBackgroundColor(color == 0 ? 0xFF000000 : color);
56
57        // Cannot access the inside items through id because no R.id values have been
58        // created for them.
59        // We do know the order though.
60        // 0 is a spacer.
61        int back = 1;
62        int recent = 3;
63        if (orientation == LinearLayout.VERTICAL || (isRtl && !rtlEnabled)) {
64            // If RTL is enabled, then layoutlib mirrors the layout for us.
65            back = 3;
66            recent = 1;
67        }
68
69        //noinspection SpellCheckingInspection
70        loadIcon(back,   "ic_sysbar_back.png",   density, isRtl);
71        //noinspection SpellCheckingInspection
72        loadIcon(2,      "ic_sysbar_home.png",   density, isRtl);
73        //noinspection SpellCheckingInspection
74        loadIcon(recent, "ic_sysbar_recent.png", density, isRtl);
75    }
76
77    @Override
78    protected TextView getStyleableTextView() {
79        return null;
80    }
81}
82