am 04703acd: Merge "Add navigtaion bar icons to simulate older platforms." into lmp-preview-dev

* commit '04703acdd214cd17aaf5757da75a862fb1797d1e':
  Add navigtaion bar icons to simulate older platforms.
This commit is contained in:
Deepanshu Gupta
2014-06-24 10:33:33 +00:00
committed by Android Git Automerger
32 changed files with 48 additions and 95 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 904 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 617 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 836 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 591 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 749 B

View File

@@ -26,7 +26,6 @@ import com.android.layoutlib.bridge.impl.ParserFactory;
import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.resources.Density;
import com.android.resources.LayoutDirection;
import com.android.resources.ResourceType;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -59,11 +58,14 @@ import java.io.InputStream;
*/
abstract class CustomBar extends LinearLayout {
private final int mSimulatedPlatformVersion;
protected abstract TextView getStyleableTextView();
protected CustomBar(Context context, Density density, int orientation, String layoutPath,
String name) throws XmlPullParserException {
protected CustomBar(Context context, int orientation, String layoutPath,
String name, int simulatedPlatformVersion) throws XmlPullParserException {
super(context);
mSimulatedPlatformVersion = simulatedPlatformVersion;
setOrientation(orientation);
if (orientation == LinearLayout.HORIZONTAL) {
setGravity(Gravity.CENTER_VERTICAL);
@@ -100,7 +102,8 @@ abstract class CustomBar extends LinearLayout {
pathOut[0] = "/bars/" + density.getResourceValue() + "/" + iconName;
}
InputStream stream = getClass().getResourceAsStream(pathOut[0]);
// TODO: Change this with a more generic method.
InputStream stream = getIconWithApi(pathOut, iconName);
if (stream == null && tryOtherDensities) {
for (Density d : Density.values()) {
if (d != density) {
@@ -121,6 +124,19 @@ abstract class CustomBar extends LinearLayout {
return stream;
}
private InputStream getIconWithApi(String[] pathOut, String iconName) {
if (mSimulatedPlatformVersion == 0) {
String path = pathOut[0];
String dirName = path.substring(0, path.lastIndexOf('/'));
pathOut[0] = dirName + "-v21" + "/" + iconName;
InputStream stream = getClass().getResourceAsStream(pathOut[0]);
if (stream != null) {
return stream;
}
}
return getClass().getResourceAsStream(pathOut[0]);
}
protected void loadIcon(int index, String iconName, Density density) {
loadIcon(index, iconName, density, false);
}
@@ -158,65 +174,6 @@ abstract class CustomBar extends LinearLayout {
}
}
protected void loadIcon(int index, String iconReference) {
ResourceValue value = getResourceValue(iconReference);
if (value != null) {
loadIcon(index, value);
}
}
protected void loadIconById(int id, String iconReference) {
ResourceValue value = getResourceValue(iconReference);
if (value != null) {
loadIconById(id, value);
}
}
protected Drawable loadIcon(int index, ResourceType type, String name) {
BridgeContext bridgeContext = (BridgeContext) mContext;
RenderResources res = bridgeContext.getRenderResources();
// find the resource
ResourceValue value = res.getFrameworkResource(type, name);
// resolve it if needed
value = res.resolveResValue(value);
return loadIcon(index, value);
}
private Drawable loadIcon(int index, ResourceValue value) {
View child = getChildAt(index);
if (child instanceof ImageView) {
ImageView imageView = (ImageView) child;
return loadIcon(imageView, value);
}
return null;
}
private Drawable loadIconById(int id, ResourceValue value) {
View child = findViewById(id);
if (child instanceof ImageView) {
ImageView imageView = (ImageView) child;
return loadIcon(imageView, value);
}
return null;
}
private Drawable loadIcon(ImageView imageView, ResourceValue value) {
Drawable drawable = ResourceHelper.getDrawable(value, (BridgeContext) mContext);
if (drawable != null) {
imageView.setImageDrawable(drawable);
}
return drawable;
}
protected TextView setText(int index, String stringReference) {
View child = getChildAt(index);
if (child instanceof TextView) {
@@ -228,17 +185,6 @@ abstract class CustomBar extends LinearLayout {
return null;
}
protected TextView setTextById(int id, String stringReference) {
View child = findViewById(id);
if (child instanceof TextView) {
TextView textView = (TextView) child;
setText(textView, stringReference);
return textView;
}
return null;
}
private void setText(TextView textView, String stringReference) {
ResourceValue value = getResourceValue(stringReference);
if (value != null) {
@@ -256,7 +202,7 @@ abstract class CustomBar extends LinearLayout {
ResourceValue value = res.findItemInTheme(themeEntryName, true /*isFrameworkAttr*/);
value = res.resolveResValue(value);
if (value instanceof StyleResourceValue == false) {
if (!(value instanceof StyleResourceValue)) {
return;
}

View File

@@ -27,8 +27,9 @@ import android.widget.TextView;
public class NavigationBar extends CustomBar {
public NavigationBar(Context context, Density density, int orientation, boolean isRtl,
boolean rtlEnabled) throws XmlPullParserException {
super(context, density, orientation, "/bars/navigation_bar.xml", "navigation_bar.xml");
boolean rtlEnabled, int simulatedPlatformVersion) throws XmlPullParserException {
super(context, orientation, "/bars/navigation_bar.xml", "navigation_bar.xml",
simulatedPlatformVersion);
setBackgroundColor(0xFF000000);
@@ -44,8 +45,11 @@ public class NavigationBar extends CustomBar {
recent = 1;
}
//noinspection SpellCheckingInspection
loadIcon(back, "ic_sysbar_back.png", density, isRtl);
//noinspection SpellCheckingInspection
loadIcon(2, "ic_sysbar_home.png", density, isRtl);
//noinspection SpellCheckingInspection
loadIcon(recent, "ic_sysbar_recent.png", density, isRtl);
}

View File

@@ -18,13 +18,10 @@ package com.android.layoutlib.bridge.bars;
import com.android.layoutlib.bridge.impl.Config;
import com.android.resources.Density;
import com.android.resources.ResourceType;
import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LevelListDrawable;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -34,7 +31,8 @@ public class StatusBar extends CustomBar {
public StatusBar(Context context, Density density, int direction, boolean RtlEnabled,
int simulatedPlatformVersion) 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");
super(context, LinearLayout.HORIZONTAL, "/bars/status_bar.xml", "status_bar.xml",
simulatedPlatformVersion);
// FIXME: use FILL_H?
setGravity(Gravity.START | Gravity.TOP | Gravity.RIGHT);

View File

@@ -16,8 +16,6 @@
package com.android.layoutlib.bridge.bars;
import com.android.resources.Density;
import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
@@ -28,9 +26,10 @@ public class TitleBar extends CustomBar {
private TextView mTextView;
public TitleBar(Context context, Density density, String label)
public TitleBar(Context context, String label, int simulatedPlatformVersion)
throws XmlPullParserException {
super(context, density, LinearLayout.HORIZONTAL, "/bars/title_bar.xml", "title_bar.xml");
super(context, LinearLayout.HORIZONTAL, "/bars/title_bar.xml", "title_bar.xml",
simulatedPlatformVersion);
// Cannot access the inside items through id because no R.id values have been
// created for them.

View File

@@ -247,6 +247,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
backgroundView = mViewRoot = mContentRoot = new FrameLayout(context);
mViewRoot.setLayoutDirection(layoutDirection);
} else {
int simulatedPlatformVersion = params.getSimulatedPlatformVersion();
if (hasSoftwareButtons() && mNavigationBarOrientation == LinearLayout.VERTICAL) {
/*
* This is a special case where the navigation bar is on the right.
@@ -271,10 +272,11 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
mViewRoot = topLayout;
topLayout.setOrientation(LinearLayout.HORIZONTAL);
if (Config.showOnScreenNavBar(params.getSimulatedPlatformVersion())) {
if (Config.showOnScreenNavBar(simulatedPlatformVersion)) {
try {
NavigationBar navigationBar = createNavigationBar(context,
hardwareConfig.getDensity(), isRtl, params.isRtlSupported());
hardwareConfig.getDensity(), isRtl, params.isRtlSupported(),
simulatedPlatformVersion);
topLayout.addView(navigationBar);
} catch (XmlPullParserException ignored) {
}
@@ -331,7 +333,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
try {
StatusBar statusBar = createStatusBar(context, hardwareConfig.getDensity(),
layoutDirection, params.isRtlSupported(),
params.getSimulatedPlatformVersion());
simulatedPlatformVersion);
topLayout.addView(statusBar);
} catch (XmlPullParserException ignored) {
@@ -357,7 +359,8 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
} else if (mTitleBarSize > 0) {
try {
TitleBar titleBar = createTitleBar(context,
hardwareConfig.getDensity(), params.getAppLabel());
params.getAppLabel(),
simulatedPlatformVersion);
backgroundLayout.addView(titleBar);
} catch (XmlPullParserException ignored) {
@@ -374,13 +377,14 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
backgroundLayout.addView(mContentRoot);
}
if (Config.showOnScreenNavBar(params.getSimulatedPlatformVersion()) &&
if (Config.showOnScreenNavBar(simulatedPlatformVersion) &&
mNavigationBarOrientation == LinearLayout.HORIZONTAL &&
mNavigationBarSize > 0) {
// system bar
try {
NavigationBar navigationBar = createNavigationBar(context,
hardwareConfig.getDensity(), isRtl, params.isRtlSupported());
hardwareConfig.getDensity(), isRtl, params.isRtlSupported(),
simulatedPlatformVersion);
topLayout.addView(navigationBar);
} catch (XmlPullParserException ignored) {
@@ -1592,10 +1596,11 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
* is RTL aware.
*/
private NavigationBar createNavigationBar(BridgeContext context, Density density,
boolean isRtl, boolean isRtlSupported) throws XmlPullParserException {
boolean isRtl, boolean isRtlSupported, int simulatedPlatformVersion)
throws XmlPullParserException {
NavigationBar navigationBar = new NavigationBar(context,
density, mNavigationBarOrientation, isRtl,
isRtlSupported);
isRtlSupported, simulatedPlatformVersion);
if (mNavigationBarOrientation == LinearLayout.VERTICAL) {
navigationBar.setLayoutParams(new LinearLayout.LayoutParams(mNavigationBarSize,
LayoutParams.MATCH_PARENT));
@@ -1606,9 +1611,10 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
return navigationBar;
}
private TitleBar createTitleBar(BridgeContext context, Density density, String title)
private TitleBar createTitleBar(BridgeContext context, String title,
int simulatedPlatformVersion)
throws XmlPullParserException {
TitleBar titleBar = new TitleBar(context, density, title);
TitleBar titleBar = new TitleBar(context, title, simulatedPlatformVersion);
titleBar.setLayoutParams(
new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mTitleBarSize));
return titleBar;