Fix ReflectionInflater
Don't append default package when the tag name itself is qualified (i.e. contains a '.'). Also moved the inflater test cases into test/instrumentation to the same place as other instrumentation tests. (Other tests were moved with the introduction of Robolectric tests) Bug: 34254689 Test: ./gradlew connectedAndroidTest Change-Id: I2f22613f80b4e3a65a73c4a4f8bd084ad3d4654f
This commit is contained in:
parent
0d61ee75de
commit
5ed761c1df
|
@ -83,7 +83,10 @@ public abstract class ReflectionInflater<T> extends SimpleInflater<T> {
|
|||
*/
|
||||
@NonNull
|
||||
public final T createItem(String tagName, String prefix, AttributeSet attrs) {
|
||||
String qualifiedName = prefix != null ? prefix.concat(tagName) : tagName;
|
||||
String qualifiedName = tagName;
|
||||
if (prefix != null && qualifiedName.indexOf('.') == -1) {
|
||||
qualifiedName = prefix.concat(qualifiedName);
|
||||
}
|
||||
Constructor constructor = sConstructorMap.get(qualifiedName);
|
||||
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<!--
|
||||
Copyright (C) 2017 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.
|
||||
-->
|
||||
|
||||
<android.view.animation.AnimationSet
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<ScaleAnimation
|
||||
android:pivotX="0.2" />
|
||||
|
||||
</android.view.animation.AnimationSet>
|
|
@ -52,6 +52,21 @@ public class ReflectionInflaterTest {
|
|||
assertTrue(animations.get(0) instanceof ScaleAnimation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultPackage() {
|
||||
final Context context = InstrumentationRegistry.getContext();
|
||||
TestInflater inflater = new TestInflater(context);
|
||||
inflater.setDefaultPackage("android.view.animation.");
|
||||
final Animation result =
|
||||
inflater.inflate(R.xml.reflection_inflater_test_with_default_package);
|
||||
|
||||
assertTrue(result instanceof AnimationSet);
|
||||
final AnimationSet set = (AnimationSet) result;
|
||||
final List<Animation> animations = set.getAnimations();
|
||||
assertEquals(1, animations.size());
|
||||
assertTrue(animations.get(0) instanceof ScaleAnimation);
|
||||
}
|
||||
|
||||
private static class TestInflater extends ReflectionInflater<Animation> {
|
||||
|
||||
protected TestInflater(@NonNull Context context) {
|
Loading…
Reference in a new issue