summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-12-02 18:54:11 -0800
committerXavier Ducrohet <xav@android.com>2010-12-02 18:58:25 -0800
commit01811aa86279af1b341a4fff344d66c0ebdd63da (patch)
tree9ae7d13d12ed22fdec5b527f4bdb3a78eba2b7df /tools
parent3c78f2de353df3e287444dd9f9fbab3bd4456217 (diff)
downloadframeworks_base-01811aa86279af1b341a4fff344d66c0ebdd63da.zip
frameworks_base-01811aa86279af1b341a4fff344d66c0ebdd63da.tar.gz
frameworks_base-01811aa86279af1b341a4fff344d66c0ebdd63da.tar.bz2
LayoutLib: Create new layoutparams when moving a child
Change-Id: Ie2183490e8d26ef194030a9d87fe7745f24f1d83
Diffstat (limited to 'tools')
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java2
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java2
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java29
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeLayoutParamsMapAttributes.java142
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java8
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java23
6 files changed, 184 insertions, 22 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index 392717e..7aa0e3c 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -175,7 +175,7 @@ public final class Bridge extends LayoutBridge {
public boolean init(String fontOsLocation, Map<String, Map<String, Integer>> enumValueMap) {
sEnumValueMap = enumValueMap;
- // don't use EnumSet.allOf(), because the bridge doesn't come with it's specific version
+ // don't use EnumSet.allOf(), because the bridge doesn't come with its specific version
// of layoutlib_api. It is provided by the client which could have a more recent version
// with newer, unsupported capabilities.
mCapabilities = EnumSet.of(
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java
index a491901..f43559f 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java
@@ -132,7 +132,7 @@ public class BridgeLayoutScene extends LayoutScene {
mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
if (mLastResult.isSuccess()) {
mLastResult = mScene.moveChild((ViewGroup) parentView, (View) childView, index,
- listener);
+ layoutParams, listener);
}
} finally {
mScene.release();
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index 2ddabdf..688f240 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -319,18 +319,14 @@ public final class BridgeContext extends Activity {
public TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs,
int defStyleAttr, int defStyleRes) {
+ Map<String, String> defaultPropMap = null;
+ boolean isPlatformFile = true;
+
// Hint: for XmlPullParser, attach source //DEVICE_SRC/dalvik/libcore/xml/src/java
- BridgeXmlBlockParser parser = null;
if (set instanceof BridgeXmlBlockParser) {
+ BridgeXmlBlockParser parser = null;
parser = (BridgeXmlBlockParser)set;
- } else if (set != null) { // null parser is ok
- // really this should not be happening since its instantiated in Bridge
- mLogger.error("Parser is not a BridgeXmlBlockParser!");
- return null;
- }
- Map<String, String> defaultPropMap = null;
- if (parser != null) {
Object key = parser.getViewKey();
if (key != null) {
defaultPropMap = mDefaultPropMaps.get(key);
@@ -339,21 +335,28 @@ public final class BridgeContext extends Activity {
mDefaultPropMaps.put(key, defaultPropMap);
}
}
+
+ } else if (set instanceof BridgeLayoutParamsMapAttributes) {
+ // good, nothing to do.
+ } else if (set != null) { // null parser is ok
+ // really this should not be happening since its instantiated in Bridge
+ mLogger.error("Parser is not a BridgeXmlBlockParser!");
+ return null;
}
boolean[] frameworkAttributes = new boolean[1];
TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes);
BridgeTypedArray ta = ((BridgeResources) mResources).newTypeArray(attrs.length,
- parser != null ? parser.isPlatformFile() : true);
+ isPlatformFile);
// resolve the defStyleAttr value into a IStyleResourceValue
IStyleResourceValue defStyleValues = null;
// look for a custom style.
String customStyle = null;
- if (parser != null) {
- customStyle = parser.getAttributeValue(null /* namespace*/, "style");
+ if (set != null) {
+ customStyle = set.getAttributeValue(null /* namespace*/, "style");
}
if (customStyle != null) {
IResourceValue item = findResValue(customStyle, false /*forceFrameworkOnly*/);
@@ -406,8 +409,8 @@ public final class BridgeContext extends Activity {
String name = styleAttribute.getValue();
String value = null;
- if (parser != null) {
- value = parser.getAttributeValue(namespace, name);
+ if (set != null) {
+ value = set.getAttributeValue(namespace, name);
}
// if there's no direct value for this attribute in the XML, we look for default
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeLayoutParamsMapAttributes.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeLayoutParamsMapAttributes.java
new file mode 100644
index 0000000..d208408
--- /dev/null
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeLayoutParamsMapAttributes.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2010 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.android;
+
+import com.android.layoutlib.bridge.BridgeConstants;
+
+import android.util.AttributeSet;
+
+import java.util.Map;
+
+/**
+ * An implementation of the {@link AttributeSet} interface on top of a map of attribute in the form
+ * of (name, value).
+ *
+ * This is meant to be called only from {@link BridgeContext#obtainStyledAttributes(AttributeSet, int[], int, int)}
+ * in the case of LayoutParams and therefore isn't a full implementation.
+ */
+public class BridgeLayoutParamsMapAttributes implements AttributeSet {
+
+ private final Map<String, String> mAttributes;
+
+ public BridgeLayoutParamsMapAttributes(Map<String, String> attributes) {
+ mAttributes = attributes;
+ }
+
+ public String getAttributeValue(String namespace, String name) {
+ if (BridgeConstants.NS_RESOURCES.equals(namespace)) {
+ return mAttributes.get(name);
+ }
+
+ return null;
+ }
+
+ // ---- the following methods are not called from
+ // BridgeContext#obtainStyledAttributes(AttributeSet, int[], int, int)
+ // Should they ever be called, we'll just implement them on a need basis.
+
+ public int getAttributeCount() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getAttributeName(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getAttributeValue(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getPositionDescription() {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getAttributeNameResource(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getAttributeListValue(String namespace, String attribute,
+ String[] options, int defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean getAttributeBooleanValue(String namespace, String attribute,
+ boolean defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getAttributeResourceValue(String namespace, String attribute,
+ int defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getAttributeIntValue(String namespace, String attribute,
+ int defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getAttributeUnsignedIntValue(String namespace, String attribute,
+ int defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public float getAttributeFloatValue(String namespace, String attribute,
+ float defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getAttributeListValue(int index,
+ String[] options, int defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean getAttributeBooleanValue(int index, boolean defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getAttributeResourceValue(int index, int defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getAttributeIntValue(int index, int defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getAttributeUnsignedIntValue(int index, int defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public float getAttributeFloatValue(int index, float defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getIdAttribute() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getClassAttribute() {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getIdAttributeResourceValue(int defaultValue) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getStyleAttribute() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java
index c3d0b14..73bee96 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java
@@ -36,13 +36,13 @@ import java.io.Reader;
*/
public class BridgeXmlBlockParser implements XmlResourceParser {
- private XmlPullParser mParser;
- private XmlPullAttributes mAttrib;
+ private final XmlPullParser mParser;
+ private final XmlPullAttributes mAttrib;
+ private final BridgeContext mContext;
+ private final boolean mPlatformFile;
private boolean mStarted = false;
private int mEventType = START_DOCUMENT;
- private final boolean mPlatformFile;
- private final BridgeContext mContext;
/**
* Builds a {@link BridgeXmlBlockParser}.
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java
index 74e7fb2..3c8e8cd 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java
@@ -38,6 +38,7 @@ import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.android.BridgeContext;
import com.android.layoutlib.bridge.android.BridgeInflater;
+import com.android.layoutlib.bridge.android.BridgeLayoutParamsMapAttributes;
import com.android.layoutlib.bridge.android.BridgeWindow;
import com.android.layoutlib.bridge.android.BridgeWindowSession;
import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
@@ -58,6 +59,7 @@ import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.View.AttachInfo;
import android.view.View.MeasureSpec;
+import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
@@ -568,9 +570,10 @@ public class LayoutSceneImpl {
}
public SceneResult moveChild(ViewGroup parentView, View childView, int index,
- IAnimationListener listener) {
+ Map<String, String> layoutParamsMap, IAnimationListener listener) {
checkLock();
+ LayoutParams layoutParams = null;
try {
ViewParent parent = childView.getParent();
if (parent instanceof ViewGroup) {
@@ -579,7 +582,16 @@ public class LayoutSceneImpl {
}
// add it to the parentView in the correct location
- parentView.addView(childView, index);
+
+ if (layoutParamsMap != null) {
+ // need to create a new LayoutParams object for the new parent.
+ layoutParams = parentView.generateLayoutParams(
+ new BridgeLayoutParamsMapAttributes(layoutParamsMap));
+
+ parentView.addView(childView, index, layoutParams);
+ } else {
+ parentView.addView(childView, index);
+ }
} catch (UnsupportedOperationException e) {
// looks like this is a view class that doesn't support children manipulation!
return new SceneResult(SceneStatus.ERROR_VIEWGROUP_NO_CHILDREN);
@@ -587,7 +599,12 @@ public class LayoutSceneImpl {
invalidateRenderingSize();
- return render();
+ SceneResult result = render();
+ if (layoutParams != null && result.isSuccess()) {
+ result.setData(layoutParams);
+ }
+
+ return result;
}
public SceneResult removeChild(View childView, IAnimationListener listener) {