Merge "Add basic support for simulating older versions." into lmp-preview-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
648a309d9b
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -270,12 +270,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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +329,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) {
|
||||
|
||||
@@ -371,7 +373,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 {
|
||||
@@ -1571,9 +1574,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));
|
||||
|
||||
Reference in New Issue
Block a user