M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/layoutlib_bridge"/>
<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/kxml2/kxml2-2.3.0.jar" sourcepath="/ANDROID_PLAT_SRC/dalvik/libcore/xml/src/main/java"/>
<classpathentry kind="var" path="ANDROID_PLAT_SRC/out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar" sourcepath="/ANDROID_PLAT_SRC/frameworks/base"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>layoutlib_bridge-tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,30 @@
# Copyright (C) 2011 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.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Only compile source java files in this lib.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_MODULE := layoutlib-tests
LOCAL_MODULE_TAGS := optional
LOCAL_JAVA_LIBRARIES := layoutlib kxml2-2.3.0 junit
include $(BUILD_HOST_JAVA_LIBRARY)
# Build all sub-directories
include $(call all-makefiles-under,$(LOCAL_PATH))

View File

@ -0,0 +1,58 @@
/*
* 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 android.graphics;
import junit.framework.TestCase;
/**
*
*/
public class Matrix_DelegateTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
public void testIdentity() {
Matrix m1 = new Matrix();
assertTrue(m1.isIdentity());
m1.setValues(new float[] { 1,0,0, 0,1,0, 0,0,1 });
assertTrue(m1.isIdentity());
}
public void testCopyConstructor() {
Matrix m1 = new Matrix();
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]);
}
}
}

View File

@ -0,0 +1,197 @@
/*
* 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;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import com.android.tools.layoutlib.create.CreateInfo;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
/**
* Tests that native delegate classes implement all the required methods.
*
* This looks at {@link CreateInfo#DELEGATE_CLASS_NATIVES} to get the list of classes that
* have their native methods reimplemented through a delegate.
*
* Since the reimplemented methods are not native anymore, we look for the annotation
* {@link LayoutlibDelegate}, and look for a matching method in the delegate (named the same
* as the modified class with _Delegate added as a suffix).
* If the original native method is not static, then we make sure the delegate method also
* include the original class as first parameter (to access "this").
*
*/
public class TestDelegates extends TestCase {
public void testNativeDelegates() {
final String[] classes = CreateInfo.DELEGATE_CLASS_NATIVES;
final int count = classes.length;
for (int i = 0 ; i < count ; i++) {
loadAndCompareClasses(classes[i], classes[i] + "_Delegate");
}
}
public void testMethodDelegates() {
final String[] methods = CreateInfo.DELEGATE_METHODS;
final int count = methods.length;
for (int i = 0 ; i < count ; i++) {
String methodName = methods[i];
// extract the class name
String className = methodName.substring(0, methodName.indexOf('#'));
String targetClassName = className.replace('$', '_') + "_Delegate";
loadAndCompareClasses(className, targetClassName);
}
}
private void loadAndCompareClasses(String originalClassName, String delegateClassName) {
// load the classes
try {
ClassLoader classLoader = TestDelegates.class.getClassLoader();
Class<?> originalClass = classLoader.loadClass(originalClassName);
Class<?> delegateClass = classLoader.loadClass(delegateClassName);
compare(originalClass, delegateClass);
} catch (ClassNotFoundException e) {
fail("Failed to load class: " + e.getMessage());
} catch (SecurityException e) {
fail("Failed to load class: " + e.getMessage());
}
}
private void compare(Class<?> originalClass, Class<?> delegateClass) throws SecurityException {
List<Method> checkedDelegateMethods = new ArrayList<Method>();
// loop on the methods of the original class, and for the ones that are annotated
// with @LayoutlibDelegate, look for a matching method in the delegate class.
// The annotation is automatically added by layoutlib_create when it replace a method
// by a call to a delegate
Method[] originalMethods = originalClass.getDeclaredMethods();
for (Method originalMethod : originalMethods) {
// look for methods that are delegated: they have the LayoutlibDelegate annotation
if (originalMethod.getAnnotation(LayoutlibDelegate.class) == null) {
continue;
}
// get the signature.
Class<?>[] parameters = originalMethod.getParameterTypes();
// if the method is not static, then the class is added as the first parameter
// (for "this")
if ((originalMethod.getModifiers() & Modifier.STATIC) == 0) {
Class<?>[] newParameters = new Class<?>[parameters.length + 1];
newParameters[0] = originalClass;
System.arraycopy(parameters, 0, newParameters, 1, parameters.length);
parameters = newParameters;
}
// if the original class is an inner class that's not static, then
// we add this on the enclosing class at the beginning
if (originalClass.getEnclosingClass() != null &&
(originalClass.getModifiers() & Modifier.STATIC) == 0) {
Class<?>[] newParameters = new Class<?>[parameters.length + 1];
newParameters[0] = originalClass.getEnclosingClass();
System.arraycopy(parameters, 0, newParameters, 1, parameters.length);
parameters = newParameters;
}
try {
// try to load the method with the given parameter types.
Method delegateMethod = delegateClass.getDeclaredMethod(originalMethod.getName(),
parameters);
// check that the method has the annotation
assertNotNull(
String.format(
"Delegate method %1$s for class %2$s does not have the @LayoutlibDelegate annotation",
delegateMethod.getName(),
originalClass.getName()),
delegateMethod.getAnnotation(LayoutlibDelegate.class));
// check that the method is static
assertTrue(
String.format(
"Delegate method %1$s for class %2$s is not static",
delegateMethod.getName(),
originalClass.getName()),
(delegateMethod.getModifiers() & Modifier.STATIC) == Modifier.STATIC);
// add the method as checked.
checkedDelegateMethods.add(delegateMethod);
} catch (NoSuchMethodException e) {
String name = getMethodName(originalMethod, parameters);
fail(String.format("Missing %1$s.%2$s", delegateClass.getName(), name));
}
}
// look for dead (delegate) code.
// This looks for all methods in the delegate class, and if they have the
// @LayoutlibDelegate annotation, make sure they have been previously found as a
// match for a method in the original class.
// If not, this means the method is a delegate for a method that either doesn't exist
// anymore or is not delegated anymore.
Method[] delegateMethods = delegateClass.getDeclaredMethods();
for (Method delegateMethod : delegateMethods) {
// look for methods that are delegates: they have the LayoutlibDelegate annotation
if (delegateMethod.getAnnotation(LayoutlibDelegate.class) == null) {
continue;
}
assertTrue(
String.format(
"Delegate method %1$s.%2$s is not used anymore and must be removed",
delegateClass.getName(),
getMethodName(delegateMethod)),
checkedDelegateMethods.contains(delegateMethod));
}
}
private String getMethodName(Method method) {
return getMethodName(method, method.getParameterTypes());
}
private String getMethodName(Method method, Class<?>[] parameters) {
// compute a full class name that's long but not too long.
StringBuilder sb = new StringBuilder(method.getName() + "(");
for (int j = 0; j < parameters.length; j++) {
Class<?> theClass = parameters[j];
sb.append(theClass.getName());
int dimensions = 0;
while (theClass.isArray()) {
dimensions++;
theClass = theClass.getComponentType();
}
for (int i = 0; i < dimensions; i++) {
sb.append("[]");
}
if (j < (parameters.length - 1)) {
sb.append(",");
}
}
sb.append(")");
return sb.toString();
}
}

View File

@ -0,0 +1,124 @@
/*
* 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.android;
import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
import org.kxml2.io.KXmlParser;
import org.w3c.dom.Node;
import org.xmlpull.v1.XmlPullParser;
import java.io.InputStream;
import junit.framework.TestCase;
public class BridgeXmlBlockParserTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
public void testXmlBlockParser() throws Exception {
XmlPullParser parser = new KXmlParser();
parser = new BridgeXmlBlockParser(parser, null, false /* platformResourceFlag */);
InputStream input = this.getClass().getClassLoader().getResourceAsStream(
"com/android/layoutlib/testdata/layout1.xml");
parser.setInput(input, "UTF-8"); //$NON-NLS-1$
assertEquals(XmlPullParser.START_DOCUMENT, parser.next());
assertEquals(XmlPullParser.START_TAG, parser.next());
assertEquals("LinearLayout", parser.getName());
assertEquals(XmlPullParser.TEXT, parser.next());
assertEquals(XmlPullParser.START_TAG, parser.next());
assertEquals("Button", parser.getName());
assertEquals(XmlPullParser.TEXT, parser.next());
assertEquals(XmlPullParser.END_TAG, parser.next());
assertEquals(XmlPullParser.TEXT, parser.next());
assertEquals(XmlPullParser.START_TAG, parser.next());
assertEquals("View", parser.getName());
assertEquals(XmlPullParser.END_TAG, parser.next());
assertEquals(XmlPullParser.TEXT, parser.next());
assertEquals(XmlPullParser.START_TAG, parser.next());
assertEquals("TextView", parser.getName());
assertEquals(XmlPullParser.END_TAG, parser.next());
assertEquals(XmlPullParser.TEXT, parser.next());
assertEquals(XmlPullParser.END_TAG, parser.next());
assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
}
//------------
/**
* Quick'n'dirty debug helper that dumps an XML structure to stdout.
*/
@SuppressWarnings("unused")
private void dump(Node node, String prefix) {
Node n;
String[] types = {
"unknown",
"ELEMENT_NODE",
"ATTRIBUTE_NODE",
"TEXT_NODE",
"CDATA_SECTION_NODE",
"ENTITY_REFERENCE_NODE",
"ENTITY_NODE",
"PROCESSING_INSTRUCTION_NODE",
"COMMENT_NODE",
"DOCUMENT_NODE",
"DOCUMENT_TYPE_NODE",
"DOCUMENT_FRAGMENT_NODE",
"NOTATION_NODE"
};
String s = String.format("%s<%s> %s %s",
prefix,
types[node.getNodeType()],
node.getNodeName(),
node.getNodeValue() == null ? "" : node.getNodeValue().trim());
System.out.println(s);
n = node.getFirstChild();
if (n != null) {
dump(n, prefix + "- ");
}
n = node.getNextSibling();
if (n != null) {
dump(n, prefix);
}
}
}

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:id="@+id/bouton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="My Button Text"
>
</Button>
<View
android:id="@+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
/>
<TextView
android:id="@+id/status"
android:paddingLeft="2dip"
android:layout_weight="0"
android:background="@drawable/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:gravity="center_vertical|center_horizontal"
android:text="My TextView Text"
/>
</LinearLayout>