diff options
3 files changed, 50 insertions, 13 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/StatusBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/StatusBar.java index 1498044d4262..8aaaaba5c4cf 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/StatusBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/StatusBar.java @@ -16,6 +16,7 @@ package com.android.layoutlib.bridge.bars; +import com.android.layoutlib.bridge.impl.Config; import com.android.resources.Density; import com.android.resources.ResourceType; @@ -30,14 +31,14 @@ import android.widget.TextView; public class StatusBar extends CustomBar { - public StatusBar(Context context, Density density, int direction, boolean RtlEnabled) - throws XmlPullParserException { + public StatusBar(Context context, Density density, int direction, boolean RtlEnabled, + int simulatePlatformVersion) throws XmlPullParserException { // FIXME: if direction is RTL but it's not enabled in application manifest, mirror this bar. super(context, density, LinearLayout.HORIZONTAL, "/bars/status_bar.xml", "status_bar.xml"); // FIXME: use FILL_H? setGravity(Gravity.START | Gravity.TOP | Gravity.RIGHT); - setBackgroundColor(0xFF000000); + setBackgroundColor(Config.getStatusBarColor(simulatePlatformVersion)); // Cannot access the inside items through id because no R.id values have been // created for them. diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Config.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Config.java new file mode 100644 index 000000000000..e8bc292282d8 --- /dev/null +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Config.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2014 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.impl; + +/** + * Various helper methods to simulate older versions of platform. + */ +public class Config { + + public static boolean showOnScreenNavBar(int platformVersion) { + // return true if ICS or later. + return platformVersion >= 14 || platformVersion == 0; + } + + public static int getStatusBarColor(int platformVersion) { + // return white for froyo and earlier; black otherwise. + return platformVersion >= 9 || platformVersion == 0 ? 0xFF000000 : 0xFFFFFFFF; + } +} diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index 56d7d12c09db..c4f9136dd8fa 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -271,12 +271,13 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { mViewRoot = topLayout; topLayout.setOrientation(LinearLayout.HORIZONTAL); - try { - NavigationBar navigationBar = createNavigationBar(context, - hardwareConfig.getDensity(), isRtl, params.isRtlSupported()); - topLayout.addView(navigationBar); - } catch (XmlPullParserException ignored) { - + if (Config.showOnScreenNavBar(params.getSimulatePlatformVersion())) { + try { + NavigationBar navigationBar = createNavigationBar(context, + hardwareConfig.getDensity(), isRtl, params.isRtlSupported()); + topLayout.addView(navigationBar); + } catch (XmlPullParserException ignored) { + } } } @@ -329,7 +330,8 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { // system bar try { StatusBar statusBar = createStatusBar(context, hardwareConfig.getDensity(), - layoutDirection, params.isRtlSupported()); + layoutDirection, params.isRtlSupported(), + params.getSimulatePlatformVersion()); topLayout.addView(statusBar); } catch (XmlPullParserException ignored) { @@ -372,7 +374,8 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { backgroundLayout.addView(mContentRoot); } - if (mNavigationBarOrientation == LinearLayout.HORIZONTAL && + if (Config.showOnScreenNavBar(params.getSimulatePlatformVersion()) && + mNavigationBarOrientation == LinearLayout.HORIZONTAL && mNavigationBarSize > 0) { // system bar try { @@ -1572,9 +1575,9 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { * Creates the status bar with wifi and battery icons. */ private StatusBar createStatusBar(BridgeContext context, Density density, int direction, - boolean isRtlSupported) throws XmlPullParserException { + boolean isRtlSupported, int platformVersion) throws XmlPullParserException { StatusBar statusBar = new StatusBar(context, density, - direction, isRtlSupported); + direction, isRtlSupported, platformVersion); statusBar.setLayoutParams( new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, mStatusBarSize)); |