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