Merge change I3d6cf8aa into eclair
* changes:
Fix for bug 2158794. Hide MediaPlayer.invoke() and MediaPlayer.newRequest(), and Fix bad links in ToneGenerator documentation.
diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java
index b619fee..e5e6db9 100644
--- a/core/java/android/net/MobileDataStateTracker.java
+++ b/core/java/android/net/MobileDataStateTracker.java
@@ -42,7 +42,7 @@
public class MobileDataStateTracker extends NetworkStateTracker {
private static final String TAG = "MobileDataStateTracker";
- private static final boolean DBG = false;
+ private static final boolean DBG = true;
private Phone.DataState mMobileDataState;
private ITelephony mPhoneService;
@@ -142,11 +142,6 @@
boolean unavailable = intent.getBooleanExtra(Phone.NETWORK_UNAVAILABLE_KEY,
false);
- if (DBG) Log.d(TAG, mApnType + " Received " + intent.getAction() +
- " broadcast - state = " + state + ", oldstate = " + mMobileDataState +
- ", unavailable = " + unavailable + ", reason = " +
- (reason == null ? "(unspecified)" : reason) +
- ", apnTypeList = " + apnTypeList);
// set this regardless of the apnTypeList. It's all the same radio/network
// underneath
@@ -166,14 +161,17 @@
" for " + mApnType);
mInterfaceName = intent.getStringExtra(Phone.DATA_IFACE_NAME_KEY);
}
- if (DBG) Log.d(TAG, " dropped - mEnabled = false");
return;
}
} else {
- if (DBG) Log.d(TAG, " dropped - wrong Apn");
return;
}
+ if (DBG) Log.d(TAG, mApnType + " Received state= " + state + ", old= " +
+ mMobileDataState + ", reason= " +
+ (reason == null ? "(unspecified)" : reason) +
+ ", apnTypeList= " + apnTypeList);
+
if (mMobileDataState != state) {
mMobileDataState = state;
switch (state) {
diff --git a/core/java/com/android/internal/widget/RotarySelector.java b/core/java/com/android/internal/widget/RotarySelector.java
index 0998744..e103a5b 100644
--- a/core/java/com/android/internal/widget/RotarySelector.java
+++ b/core/java/com/android/internal/widget/RotarySelector.java
@@ -48,6 +48,7 @@
private static final String LOG_TAG = "RotarySelector";
private static final boolean DBG = false;
+ private static final boolean VISUAL_DEBUG = false;
// Listener for onDialTrigger() callbacks.
private OnDialTriggerListener mOnDialTriggerListener;
@@ -290,10 +291,12 @@
final int width = getWidth();
- // DEBUG: draw bounding box around widget
-// mPaint.setColor(Color.RED);
-// mPaint.setStyle(Paint.Style.STROKE);
-// canvas.drawRect(0, 0, width, getHeight(), mPaint);
+ if (VISUAL_DEBUG) {
+ // draw bounding box around widget
+ mPaint.setColor(0xffff0000);
+ mPaint.setStyle(Paint.Style.STROKE);
+ canvas.drawRect(0, 0, width, getHeight(), mPaint);
+ }
final int height = getHeight();
@@ -336,21 +339,18 @@
final int bgTop = isHoriz() ?
height - bgHeight:
width - bgHeight;
- // DEBUG: draw circle bounding arc drawable: good sanity check we're doing the math
- // correctly
-// float or = OUTER_ROTARY_RADIUS_DIP * mDensity;
-// final int vOffset = mBackgroundWidth - height;
-// final int midX = isHoriz() ?
-// width / 2 :
-// mBackgroundWidth / 2 - vOffset;
-// if (isHoriz()) {
-// canvas.drawCircle(midX, or + bgTop, or, mPaint);
-// } else {
-// canvas.drawCircle(or + bgTop, midX, or, mPaint);
-// }
- // dimple selection
- Bitmap dimpleBitmap = mGrabbedState == NOTHING_GRABBED ? mDimple : mDimpleDim;
+ if (VISUAL_DEBUG) {
+ // draw circle bounding arc drawable: good sanity check we're doing the math correctly
+ float or = OUTER_ROTARY_RADIUS_DIP * mDensity;
+ final int vOffset = mBackgroundWidth - height;
+ final int midX = isHoriz() ? width / 2 : mBackgroundWidth / 2 - vOffset;
+ if (isHoriz()) {
+ canvas.drawCircle(midX, or + bgTop, or, mPaint);
+ } else {
+ canvas.drawCircle(or + bgTop, midX, or, mPaint);
+ }
+ }
// left dimple / icon
{
@@ -360,17 +360,13 @@
mInnerRadius,
mOuterRadius,
xOffset);
- if (isHoriz()) {
- drawCentered(dimpleBitmap, canvas, xOffset, drawableY + bgTop);
- if (mGrabbedState != RIGHT_HANDLE_GRABBED) {
- drawCentered(mLeftHandleIcon, canvas, xOffset, drawableY + bgTop);
- }
+ final int x = isHoriz() ? xOffset : drawableY + bgTop;
+ final int y = isHoriz() ? drawableY + bgTop : height - xOffset;
+ if (mGrabbedState != RIGHT_HANDLE_GRABBED) {
+ drawCentered(mDimple, canvas, x, y);
+ drawCentered(mLeftHandleIcon, canvas, x, y);
} else {
- // vertical
- drawCentered(dimpleBitmap, canvas, drawableY + bgTop, height - xOffset);
- if (mGrabbedState != RIGHT_HANDLE_GRABBED) {
- drawCentered(mLeftHandleIcon, canvas, drawableY + bgTop, height - xOffset);
- }
+ drawCentered(mDimpleDim, canvas, x, y);
}
}
@@ -386,10 +382,10 @@
xOffset);
if (isHoriz()) {
- drawCentered(dimpleBitmap, canvas, xOffset, drawableY + bgTop);
+ drawCentered(mDimpleDim, canvas, xOffset, drawableY + bgTop);
} else {
// vertical
- drawCentered(dimpleBitmap, canvas, drawableY + bgTop, height - xOffset);
+ drawCentered(mDimpleDim, canvas, drawableY + bgTop, height - xOffset);
}
}
@@ -402,17 +398,13 @@
mOuterRadius,
xOffset);
- if (isHoriz()) {
- drawCentered(dimpleBitmap, canvas, xOffset, drawableY + bgTop);
- if (mGrabbedState != LEFT_HANDLE_GRABBED) {
- drawCentered(mRightHandleIcon, canvas, xOffset, drawableY + bgTop);
- }
+ final int x = isHoriz() ? xOffset : drawableY + bgTop;
+ final int y = isHoriz() ? drawableY + bgTop : height - xOffset;
+ if (mGrabbedState != LEFT_HANDLE_GRABBED) {
+ drawCentered(mDimple, canvas, x, y);
+ drawCentered(mRightHandleIcon, canvas, x, y);
} else {
- // vertical
- drawCentered(dimpleBitmap, canvas, drawableY + bgTop, height - xOffset);
- if (mGrabbedState != LEFT_HANDLE_GRABBED) {
- drawCentered(mRightHandleIcon, canvas, drawableY + bgTop, height - xOffset);
- }
+ drawCentered(mDimpleDim, canvas, x, y);
}
}
@@ -427,9 +419,9 @@
dimpleLeft);
if (isHoriz()) {
- drawCentered(dimpleBitmap, canvas, dimpleLeft, drawableY + bgTop);
+ drawCentered(mDimpleDim, canvas, dimpleLeft, drawableY + bgTop);
} else {
- drawCentered(dimpleBitmap, canvas, drawableY + bgTop, height - dimpleLeft);
+ drawCentered(mDimpleDim, canvas, drawableY + bgTop, height - dimpleLeft);
}
dimpleLeft -= mDimpleSpacing;
}
@@ -445,9 +437,9 @@
dimpleRight);
if (isHoriz()) {
- drawCentered(dimpleBitmap, canvas, dimpleRight, drawableY + bgTop);
+ drawCentered(mDimpleDim, canvas, dimpleRight, drawableY + bgTop);
} else {
- drawCentered(dimpleBitmap, canvas, drawableY + bgTop, height - dimpleRight);
+ drawCentered(mDimpleDim, canvas, drawableY + bgTop, height - dimpleRight);
}
dimpleRight += mDimpleSpacing;
}
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index 6a8d692..78215b0 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -53,7 +53,7 @@
*/
public class ConnectivityService extends IConnectivityManager.Stub {
- private static final boolean DBG = false;
+ private static final boolean DBG = true;
private static final String TAG = "ConnectivityService";
// Event log tags (must be in sync with event-log-tags)
@@ -740,7 +740,6 @@
++numConnectedNets;
}
}
- if (DBG) Log.d(TAG, "numConnectedNets returning "+numConnectedNets);
return numConnectedNets;
}
@@ -766,10 +765,6 @@
private void handleDisconnect(NetworkInfo info) {
int prevNetType = info.getType();
- if (DBG) {
- Log.v(TAG, "Handle DISCONNECT for " + info.getTypeName() +
- (mNetAttributes[prevNetType].isDefault() ? ", a default network" : ""));
- }
mNetTrackers[prevNetType].setTeardownRequested(false);
/*
@@ -878,11 +873,6 @@
// do this before we broadcast the change
handleConnectivityChange();
- if (DBG) Log.v(TAG, "Sending DISCONNECT bcast for " +
- info.getTypeName() +
- (newNet == null || !newNet.isAvailable() ? "" : " other=" +
- newNet.getNetworkInfo().getTypeName()));
-
sendStickyBroadcast(intent);
/*
* If the failover network is already connected, then immediately send
@@ -975,8 +965,6 @@
}
private void handleConnect(NetworkInfo info) {
- if (DBG) Log.d(TAG, "Handle CONNECT for " + info.getTypeName());
-
int type = info.getType();
// snapshot isFailover, because sendConnectedBroadcast() resets it
@@ -986,7 +974,6 @@
// if this is a default net and other default is running
// kill the one not preferred
if (mNetAttributes[type].isDefault()) {
- if (DBG) Log.d(TAG, "connecting to a default network");
if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
if ((type != mNetworkPreference &&
mNetAttributes[mActiveDefaultNetwork].mPriority >
@@ -1016,7 +1003,6 @@
mActiveDefaultNetwork = type;
}
thisNet.setTeardownRequested(false);
- if (DBG) Log.d(TAG, "Sending CONNECT bcast for " + info.getTypeName());
thisNet.updateNetworkSettings();
handleConnectivityChange();
sendConnectedBroadcast(info);
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/AndroidGraphicsTests.java b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/AndroidGraphicsTests.java
index ac144e7..6e14e82 100644
--- a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/AndroidGraphicsTests.java
+++ b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/AndroidGraphicsTests.java
@@ -24,7 +24,7 @@
import junit.framework.TestCase;
/**
- *
+ *
*/
public class AndroidGraphicsTests extends TestCase {
@@ -40,24 +40,24 @@
public void testMatrix() {
Matrix m1 = new Matrix();
-
- assertFalse(m1.isIdentity());
-
+
+ assertTrue(m1.isIdentity());
+
m1.setValues(new float[] { 1,0,0, 0,1,0, 0,0,1 });
assertTrue(m1.isIdentity());
-
+
Matrix m2 = new Matrix(m1);
-
+
float[] v1 = new float[9];
float[] v2 = new float[9];
m1.getValues(v1);
m2.getValues(v2);
-
+
for (int i = 0 ; i < 9; i++) {
assertEquals(v1[i], v2[i]);
}
}
-
+
public void testPaint() {
_Original_Paint o = new _Original_Paint();
assertNotNull(o);
@@ -65,7 +65,7 @@
Paint p = new Paint();
assertNotNull(p);
}
-
+
public void textTextPaint() {
TextPaint p = new TextPaint();
assertNotNull(p);
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/BridgeTest.java b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/BridgeTest.java
deleted file mode 100644
index c66ae37..0000000
--- a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/BridgeTest.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Copyright (C) 2008 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;
-
-import com.android.layoutlib.api.ILayoutResult;
-import com.android.layoutlib.api.IResourceValue;
-import com.android.layoutlib.api.IStyleResourceValue;
-import com.android.layoutlib.api.IXmlPullParser;
-import com.android.layoutlib.api.ILayoutResult.ILayoutViewInfo;
-
-import org.kxml2.io.KXmlParser;
-import org.xmlpull.v1.XmlPullParser;
-
-import java.io.File;
-import java.io.FileReader;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-public class BridgeTest extends TestCase {
-
- /** the class being tested */
- private Bridge mBridge;
- /** the path to the sample layout.xml file */
- private String mLayoutXml1Path;
- private String mTextOnlyXmlPath;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- mBridge = new Bridge();
-
- // FIXME: need some fonts somewhere.
- mBridge.init(null /* fontOsLocation */, getAttributeValues());
-
- URL url = this.getClass().getClassLoader().getResource("data/layout1.xml");
- mLayoutXml1Path = url.getFile();
-
- url = this.getClass().getClassLoader().getResource("data/textonly.xml");
- mTextOnlyXmlPath = url.getFile();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- // ---------------
-
- /**
- * Test parser that implements {@link IXmlPullParser}.
- */
- private static class TestParser extends KXmlParser implements IXmlPullParser {
- public Object getViewKey() {
- return null;
- }
- }
-
- /**
- * Mock implementation of {@link IStyleResourceValue}.
- */
- private static class StyleResourceValueMock extends ResourceValue
- implements IStyleResourceValue {
-
- private String mParentStyle = null;
- private HashMap<String, IResourceValue> mItems = new HashMap<String, IResourceValue>();
-
- StyleResourceValueMock(String name) {
- super(name);
- }
-
- StyleResourceValueMock(String name, String parentStyle) {
- super(name);
- mParentStyle = parentStyle;
- }
-
- public String getParentStyle() {
- return mParentStyle;
- }
-
- public IResourceValue findItem(String name) {
- return mItems.get(name);
- }
-
- public void addItem(IResourceValue value) {
- mItems.put(value.getName(), value);
- }
-
- @Override
- public void replaceWith(ResourceValue value) {
- super.replaceWith(value);
-
- if (value instanceof StyleResourceValueMock) {
- mItems.clear();
- mItems.putAll(((StyleResourceValueMock)value).mItems);
- }
- }
- }
-
-
- public void testComputeLayout() throws Exception {
-
- TestParser parser = new TestParser();
- parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- parser.setInput(new FileReader(new File(mLayoutXml1Path)));
-
- Map<String, Map<String, IResourceValue>> projectResources = getProjectResources();
-
- Map<String, Map<String, IResourceValue>> frameworkResources = getFrameworkResources();
-
- int screenWidth = 320;
- int screenHeight = 480;
-
- // FIXME need a dummy font for the tests!
- ILayoutResult result = mBridge.computeLayout(parser, new Integer(1) /* projectKey */,
- screenWidth, screenHeight, false /* full render */,
- 160, 160f, 160f,
- "Theme", false /* is project theme */,
- projectResources, frameworkResources, null, null);
-
- display(result.getRootView(), "");
- }
-
- private Map<String, Map<String, Integer>> getAttributeValues() {
- Map<String, Map<String, Integer>> attributeValues =
- new HashMap<String, Map<String,Integer>>();
-
- // lets create a map for the orientation attribute
- Map<String, Integer> attributeMap = new HashMap<String, Integer>();
-
- attributeMap.put("horizontal", Integer.valueOf(0));
- attributeMap.put("vertical", Integer.valueOf(1));
-
- attributeValues.put("orientation", attributeMap);
-
- return attributeValues;
- }
-
- private Map<String, Map<String, IResourceValue>> getFrameworkResources() {
- Map<String, Map<String, IResourceValue>> frameworkResources =
- new HashMap<String, Map<String, IResourceValue>>();
-
- // create the style map
- Map<String, IResourceValue> styleMap = new HashMap<String, IResourceValue>();
- frameworkResources.put("style", styleMap);
-
- // create a button style.
- IStyleResourceValue style = createStyle("Widget.Button",
- "background", "@android:drawable/something",
- "focusable", "true",
- "clickable", "true",
- "textAppearance", "?android:attr/textAppearanceSmallInverse",
- "textColor", "?android:attr/textColorBrightInverseNoDisable",
- "gravity", "center_vertical|center_horizontal"
- );
- styleMap.put(style.getName(), style);
-
- // create the parent style of button style
- style = createStyle("Widget",
- "textAppearance", "?textAppearance");
- styleMap.put(style.getName(), style);
-
- // link the buttonStyle info in the default theme.
- style = createStyle("Theme",
- BridgeConstants.RES_STYLE, "buttonStyle", "@android:style/Widget.Button",
- BridgeConstants.RES_STYLE, "textAppearance", "@android:style/TextAppearance",
- BridgeConstants.RES_STYLE, "textAppearanceSmallInverse", "@android:style/TextAppearance.Small.Inverse",
- BridgeConstants.RES_COLOR, "textColorBrightInverseNoDisable", "@android:color/bright_text_light_nodisable"
- );
- styleMap.put(style.getName(), style);
-
- // create a dummy drawable to go with it
- Map<String, IResourceValue> drawableMap = new HashMap<String, IResourceValue>();
- frameworkResources.put("drawable", drawableMap);
-
- // get the 9 patch test location
- URL url = this.getClass().getClassLoader().getResource("data/button.9.png");
-
- IResourceValue drawable = new ResourceValue(BridgeConstants.RES_DRAWABLE, "something",
- url.getPath());
- drawableMap.put(drawable.getName(), drawable);
- return frameworkResources;
- }
-
- private Map<String, Map<String, IResourceValue>> getProjectResources() {
- Map<String, Map<String, IResourceValue>> projectResources =
- new HashMap<String, Map<String, IResourceValue>>();
-
- // create the style map (even empty there should be one)
- Map<String, IResourceValue> styleMap = new HashMap<String, IResourceValue>();
- projectResources.put("style", styleMap);
-
- return projectResources;
- }
-
-
- private void display(ILayoutViewInfo result, String offset) {
-
- String msg = String.format("%s%s L:%d T:%d R:%d B:%d",
- offset,
- result.getName(),
- result.getLeft(), result.getTop(), result.getRight(), result.getBottom());
-
- System.out.println(msg);
- ILayoutViewInfo[] children = result.getChildren();
- if (children != null) {
- offset += "+-";
- for (ILayoutViewInfo child : children) {
- display(child, offset);
- }
- }
- }
-
- /**
- * Creates a {@link IStyleResourceValue} based on the given values.
- * @param styleName the name of the style.
- * @param items An array of Strings. Even indices contain a style item name, and odd indices
- * a style item value. If the number of string in the array is not even, an exception is thrown.
- */
- private IStyleResourceValue createStyle(String styleName, String... items) {
- StyleResourceValueMock value = new StyleResourceValueMock(styleName);
-
- if (items.length % 3 == 0) {
- for (int i = 0 ; i < items.length;) {
- value.addItem(new ResourceValue(items[i++], items[i++], items[i++]));
- }
- } else {
- throw new IllegalArgumentException("Need a multiple of 3 for the number of strings");
- }
-
- return value;
- }
-
- // ---------------
-
- public void testTextLayout() throws Exception {
-
- TestParser parser = new TestParser();
- parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- parser.setInput(new FileReader(new File(mTextOnlyXmlPath)));
-
- Map<String, Map<String, IResourceValue>> projectResources = getProjectResources();
- Map<String, Map<String, IResourceValue>> frameworkResources = getFrameworkResources();
-
- int screenWidth = 320;
- int screenHeight = 480;
-
- // FIXME need a dummy font for the tests!
- ILayoutResult result = mBridge.computeLayout(parser, new Integer(1) /* projectKey */,
- screenWidth, screenHeight, false /* full render */,
- 160, 160f, 160f,
- "Theme", false /* is project theme */,
- projectResources, frameworkResources, null, null);
-
- display(result.getRootView(), "");
- }
-
-}
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/BridgeXmlBlockParserTest.java b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/BridgeXmlBlockParserTest.java
index ef7442c..9e2987a 100644
--- a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/BridgeXmlBlockParserTest.java
+++ b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/BridgeXmlBlockParserTest.java
@@ -17,33 +17,18 @@
package com.android.layoutlib.bridge;
import org.kxml2.io.KXmlParser;
-import org.w3c.dom.Document;
import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.net.URL;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
+import java.io.InputStream;
import junit.framework.TestCase;
public class BridgeXmlBlockParserTest extends TestCase {
- private String mXmlPath;
- private Document mDoc;
-
@Override
protected void setUp() throws Exception {
super.setUp();
- URL url = this.getClass().getClassLoader().getResource("layout1.xml");
- mXmlPath = url.getFile();
- mDoc = getXmlDocument(mXmlPath);
}
@Override
@@ -54,7 +39,10 @@
public void testXmlBlockParser() throws Exception {
XmlPullParser parser = new KXmlParser();
parser = new BridgeXmlBlockParser(parser, null, false /* platformResourceFlag */);
- parser.setInput(new FileReader(new File(mXmlPath)));
+
+ InputStream input = this.getClass().getClassLoader().getResourceAsStream(
+ "/com/android/layoutlib/testdata/layout1.xml");
+ parser.setInput(input, null /*encoding*/);
assertEquals(XmlPullParser.START_DOCUMENT, parser.next());
@@ -85,24 +73,8 @@
assertEquals(XmlPullParser.END_TAG, parser.next());
assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
}
-
- //------------
-
- private Document getXmlDocument(String xmlFilePath)
- throws ParserConfigurationException, SAXException, IOException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-
- // keep comments
- factory.setIgnoringComments(false);
- // don't validate our bogus DTD
- factory.setValidating(false);
- // we want namespaces
- factory.setNamespaceAware(true);
-
- DocumentBuilder builder = factory.newDocumentBuilder();
- return builder.parse(new File(xmlFilePath));
- }
+ //------------
/**
* Quick'n'dirty debug helper that dumps an XML structure to stdout.
@@ -126,7 +98,7 @@
"DOCUMENT_FRAGMENT_NODE",
"NOTATION_NODE"
};
-
+
String s = String.format("%s<%s> %s %s",
prefix,
types[node.getNodeType()],
@@ -134,7 +106,7 @@
node.getNodeValue() == null ? "" : node.getNodeValue().trim());
System.out.println(s);
-
+
n = node.getFirstChild();
if (n != null) {
dump(n, prefix + "- ");
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/NinePatchTest.java b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/NinePatchTest.java
index e667472..5314976 100644
--- a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/NinePatchTest.java
+++ b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/NinePatchTest.java
@@ -7,20 +7,21 @@
import junit.framework.TestCase;
public class NinePatchTest extends TestCase {
-
+
private NinePatch mPatch;
@Override
protected void setUp() throws Exception {
- URL url = this.getClass().getClassLoader().getResource("button.9.png");
+ URL url = this.getClass().getClassLoader().getResource(
+ "/com/android/layoutlib/testdata/button.9.png");
mPatch = NinePatch.load(url, false /* convert */);
}
-
+
public void test9PatchLoad() throws Exception {
assertNotNull(mPatch);
}
-
+
public void test9PatchMinSize() {
int[] padding = new int[4];
mPatch.getPadding(padding);
@@ -28,8 +29,8 @@
assertEquals(3, padding[1]);
assertEquals(13, padding[2]);
assertEquals(4, padding[3]);
- assertEquals(38, mPatch.getWidth());
- assertEquals(27, mPatch.getHeight());
+ assertEquals(36, mPatch.getWidth());
+ assertEquals(25, mPatch.getHeight());
}
}
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestClassReplacement.java b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestClassReplacement.java
new file mode 100644
index 0000000..e0dc55f
--- /dev/null
+++ b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestClassReplacement.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2009 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;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+public class TestClassReplacement extends TestCase {
+
+ public void testClassReplacements() {
+ // TODO: we want to test all the classes. For now only Paint passes the tests.
+// final String[] classes = CreateInfo.RENAMED_CLASSES;
+ final String[] classes = new String[] {
+ "android.graphics.Paint", "android.graphics._Original_Paint"
+ };
+ final int count = classes.length;
+ for (int i = 0 ; i < count ; i += 2) {
+ loadAndCompareClasses(classes[i], classes[i+1]);
+ }
+ }
+
+ private void loadAndCompareClasses(String newClassName, String oldClassName) {
+ // load the classes
+ try {
+ Class<?> newClass = TestClassReplacement.class.getClassLoader().loadClass(newClassName);
+ Class<?> oldClass = TestClassReplacement.class.getClassLoader().loadClass(oldClassName);
+
+ compare(newClass, oldClass);
+ } catch (ClassNotFoundException e) {
+ fail("Failed to load class: " + e.getMessage());
+ }
+ }
+
+ private void compare(Class<?> newClass, Class<?> oldClass) {
+ // first compare the methods.
+ Method[] newClassMethods = newClass.getDeclaredMethods();
+ Method[] oldClassMethods = oldClass.getDeclaredMethods();
+
+ for (Method oldMethod : oldClassMethods) {
+ // we ignore anything that starts with native
+ if (oldMethod.getName().startsWith("native")) {
+ continue;
+ }
+ boolean found = false;
+ for (Method newMethod : newClassMethods) {
+ if (compareMethods(newClass, newMethod, oldClass, oldMethod)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (found == false) {
+ fail(String.format("Unable to find %1$s", oldMethod.toGenericString()));
+ }
+ }
+
+ // TODO: check (somehow?) that the methods that were removed from the original class
+ // have been put back in the new class!
+ // For this we need the original unmodified class (ie renamed, but w/o the methods removed)
+ }
+
+ private boolean compareMethods(Class<?> newClass, Method newMethod,
+ Class<?> oldClass, Method oldMethod) {
+ // first check the name of the method
+ if (newMethod.getName().equals(oldMethod.getName()) == false) {
+ return false;
+ }
+
+ // check the return value
+ Class<?> oldReturnType = oldMethod.getReturnType();
+ // if it's the old class, or if it's a inner class of the oldclass, we need to change this.
+ oldReturnType = adapt(oldReturnType, newClass, oldClass);
+
+ // compare the return types
+ Class<?> newReturnType = newMethod.getReturnType();
+ if (newReturnType.equals(oldReturnType) == false) {
+ return false;
+ }
+
+ // now check the parameters type.
+ Class<?>[] oldParameters = oldMethod.getParameterTypes();
+ Class<?>[] newParemeters = newMethod.getParameterTypes();
+ if (oldParameters.length != newParemeters.length) {
+ return false;
+ }
+
+ for (int i = 0 ; i < oldParameters.length ; i++) {
+ if (newParemeters[i].equals(adapt(oldParameters[i], newClass, oldClass)) == false) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Adapts a class to deal with renamed classes.
+ * <p/>For instance if old class is <code>android.graphics._Original_Paint</code> and the
+ * new class is <code>android.graphics.Paint</code> and the class to adapt is
+ * <code>android.graphics._Original_Paint$Cap</code>, then the method will return a
+ * {@link Class} object representing <code>android.graphics.Paint$Cap</code>.
+ * <p/>
+ * This method will also ensure that all renamed classes contains all the proper inner classes
+ * that they should be declaring.
+ * @param theClass the class to adapt
+ * @param newClass the new class object
+ * @param oldClass the old class object
+ * @return the adapted class.
+ * @throws ClassNotFoundException
+ */
+ private Class<?> adapt(Class<?> theClass, Class<?> newClass, Class<?> oldClass) {
+ // only look for a new class if it's not primitive as Class.forName() would fail otherwise.
+ if (theClass.isPrimitive() == false) {
+ String n = theClass.getName().replace(oldClass.getName(), newClass.getName());
+ try {
+ return Class.forName(n);
+ } catch (ClassNotFoundException e) {
+ fail("Missing class: " + n);
+ }
+ }
+
+ return theClass;
+ }
+}
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/button.9.png b/tools/layoutlib/bridge/tests/com/android/layoutlib/testdata/button.9.png
similarity index 100%
rename from tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/button.9.png
rename to tools/layoutlib/bridge/tests/com/android/layoutlib/testdata/button.9.png
Binary files differ
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/layout1.xml b/tools/layoutlib/bridge/tests/com/android/layoutlib/testdata/layout1.xml
similarity index 100%
rename from tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/layout1.xml
rename to tools/layoutlib/bridge/tests/com/android/layoutlib/testdata/layout1.xml