summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-02-06 14:57:22 -0800
committerXavier Ducrohet <xav@android.com>2012-02-06 15:11:12 -0800
commit7396348dfcfb45b7ad055f4c18cabbe5e8270d26 (patch)
tree66b6607b253b5197e19194bd423f2e4cedd2836b /tools
parent0afa7e2d95a1ae047ceddf2ca67f05c67ac30770 (diff)
downloadframeworks_base-7396348dfcfb45b7ad055f4c18cabbe5e8270d26.zip
frameworks_base-7396348dfcfb45b7ad055f4c18cabbe5e8270d26.tar.gz
frameworks_base-7396348dfcfb45b7ad055f4c18cabbe5e8270d26.tar.bz2
Setup ActionBars in layoutlib the same way the platform does it.
Instead of using a simple ImageView for the icon, this uses the platform layout/action_bar_home which uses a custom class to position and resize the icon (and also supports the Up icon that we don't yet support). This ensures that the icon is properly positionned and sized like on devices. Change-Id: I57432afa82d257bb043247001320b368045d7f55
Diffstat (limited to 'tools')
-rw-r--r--tools/layoutlib/bridge/resources/bars/action_bar.xml10
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java4
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java62
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java2
4 files changed, 57 insertions, 21 deletions
diff --git a/tools/layoutlib/bridge/resources/bars/action_bar.xml b/tools/layoutlib/bridge/resources/bars/action_bar.xml
index 51983f2..7adc5af 100644
--- a/tools/layoutlib/bridge/resources/bars/action_bar.xml
+++ b/tools/layoutlib/bridge/resources/bars/action_bar.xml
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
- <ImageView
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"/>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
+ <include layout="@android:layout/action_bar_home" />
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
</merge>
diff --git a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java
index 451edd2..5df2a21 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java
@@ -474,7 +474,7 @@ public final class Matrix_Delegate {
}
Matrix_Delegate other = sManager.getDelegate(other_matrix);
- if (d == null) {
+ if (other == null) {
return false;
}
@@ -570,7 +570,7 @@ public final class Matrix_Delegate {
}
Matrix_Delegate other = sManager.getDelegate(other_matrix);
- if (d == null) {
+ if (other == null) {
return false;
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java
index 72ed351..cd4fbfe 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java
@@ -145,6 +145,14 @@ abstract class CustomBar extends LinearLayout {
}
}
+ 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();
@@ -162,34 +170,64 @@ abstract class CustomBar extends LinearLayout {
if (child instanceof ImageView) {
ImageView imageView = (ImageView) child;
- Drawable drawable = ResourceHelper.getDrawable(
- value, (BridgeContext) mContext);
- if (drawable != null) {
- imageView.setBackgroundDrawable(drawable);
- }
+ return loadIcon(imageView, value);
+ }
- return drawable;
+ 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) {
TextView textView = (TextView) child;
- ResourceValue value = getResourceValue(stringReference);
- if (value != null) {
- textView.setText(value.getValue());
- } else {
- textView.setText(stringReference);
- }
+ setText(textView, stringReference);
+ return textView;
+ }
+
+ 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) {
+ textView.setText(value.getValue());
+ } else {
+ textView.setText(stringReference);
+ }
+ }
+
protected void setStyle(String themeEntryName) {
BridgeContext bridgeContext = (BridgeContext) mContext;
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java
index f6edea4..68f5aba 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/FakeActionBar.java
@@ -34,7 +34,7 @@ public class FakeActionBar extends CustomBar {
// Cannot access the inside items through id because no R.id values have been
// created for them.
// We do know the order though.
- loadIcon(0, icon);
+ loadIconById(android.R.id.home, icon);
mTextView = setText(1, label);
setStyle("actionBarStyle");