am aa729889: Don\'t keep LayoutlibCallback reference. [DO NOT MERGE]
* commit 'aa72988955789be6e790c344daba3ef17abfcd98': Don't keep LayoutlibCallback reference. [DO NOT MERGE]
This commit is contained in:
@@ -19,7 +19,6 @@ package com.android.layoutlib.bridge.impl;
|
|||||||
|
|
||||||
import com.android.annotations.NonNull;
|
import com.android.annotations.NonNull;
|
||||||
import com.android.annotations.Nullable;
|
import com.android.annotations.Nullable;
|
||||||
import com.android.ide.common.rendering.api.LayoutlibCallback;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
@@ -44,10 +43,11 @@ public class ParserFactory {
|
|||||||
|
|
||||||
// Used to get a new XmlPullParser from the client.
|
// Used to get a new XmlPullParser from the client.
|
||||||
@Nullable
|
@Nullable
|
||||||
private static LayoutlibCallback sLayoutlibCallback;
|
private static com.android.ide.common.rendering.api.ParserFactory sParserFactory;
|
||||||
|
|
||||||
public static void setLayoutlibCallback(@Nullable LayoutlibCallback callback) {
|
public static void setParserFactory(
|
||||||
sLayoutlibCallback = callback;
|
@Nullable com.android.ide.common.rendering.api.ParserFactory parserFactory) {
|
||||||
|
sParserFactory = parserFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -77,10 +77,10 @@ public class ParserFactory {
|
|||||||
@NonNull
|
@NonNull
|
||||||
public static XmlPullParser instantiateParser(@Nullable String name)
|
public static XmlPullParser instantiateParser(@Nullable String name)
|
||||||
throws XmlPullParserException {
|
throws XmlPullParserException {
|
||||||
if (sLayoutlibCallback == null) {
|
if (sParserFactory == null) {
|
||||||
throw new XmlPullParserException("ParserFactory not initialized.");
|
throw new XmlPullParserException("ParserFactory not initialized.");
|
||||||
}
|
}
|
||||||
XmlPullParser parser = sLayoutlibCallback.createParser(name);
|
XmlPullParser parser = sParserFactory.createParser(name);
|
||||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ import android.view.inputmethod.InputMethodManager_Accessor;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import javax.swing.text.html.parser.Parser;
|
|
||||||
|
|
||||||
import static com.android.ide.common.rendering.api.Result.Status.ERROR_LOCK_INTERRUPTED;
|
import static com.android.ide.common.rendering.api.Result.Status.ERROR_LOCK_INTERRUPTED;
|
||||||
import static com.android.ide.common.rendering.api.Result.Status.ERROR_TIMEOUT;
|
import static com.android.ide.common.rendering.api.Result.Status.ERROR_TIMEOUT;
|
||||||
import static com.android.ide.common.rendering.api.Result.Status.SUCCESS;
|
import static com.android.ide.common.rendering.api.Result.Status.SUCCESS;
|
||||||
@@ -102,7 +100,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup the ParserFactory
|
// setup the ParserFactory
|
||||||
ParserFactory.setLayoutlibCallback(mParams.getLayoutlibCallback());
|
ParserFactory.setParserFactory(mParams.getLayoutlibCallback().getParserFactory());
|
||||||
|
|
||||||
HardwareConfig hardwareConfig = mParams.getHardwareConfig();
|
HardwareConfig hardwareConfig = mParams.getHardwareConfig();
|
||||||
|
|
||||||
@@ -276,7 +274,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
|
|||||||
mContext.getRenderResources().setFrameworkResourceIdProvider(null);
|
mContext.getRenderResources().setFrameworkResourceIdProvider(null);
|
||||||
mContext.getRenderResources().setLogger(null);
|
mContext.getRenderResources().setLogger(null);
|
||||||
}
|
}
|
||||||
ParserFactory.setLayoutlibCallback(null);
|
ParserFactory.setParserFactory(null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,15 +17,7 @@
|
|||||||
package com.android.layoutlib.bridge.android;
|
package com.android.layoutlib.bridge.android;
|
||||||
|
|
||||||
import com.android.annotations.NonNull;
|
import com.android.annotations.NonNull;
|
||||||
import com.android.ide.common.rendering.api.ActionBarCallback;
|
|
||||||
import com.android.ide.common.rendering.api.AdapterBinding;
|
|
||||||
import com.android.ide.common.rendering.api.ILayoutPullParser;
|
|
||||||
import com.android.ide.common.rendering.api.LayoutlibCallback;
|
|
||||||
import com.android.ide.common.rendering.api.ResourceReference;
|
|
||||||
import com.android.ide.common.rendering.api.ResourceValue;
|
|
||||||
import com.android.layoutlib.bridge.impl.ParserFactory;
|
import com.android.layoutlib.bridge.impl.ParserFactory;
|
||||||
import com.android.resources.ResourceType;
|
|
||||||
import com.android.util.Pair;
|
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
@@ -40,8 +32,8 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class BridgeXmlBlockParserTest {
|
public class BridgeXmlBlockParserTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public void setUp() {
|
public static void setUp() {
|
||||||
ParserFactory.setLayoutlibCallback(new LayoutlibTestCallback());
|
ParserFactory.setParserFactory(new ParserFactoryImpl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -128,79 +120,17 @@ public class BridgeXmlBlockParserTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public void tearDown() {
|
public static void tearDown() {
|
||||||
ParserFactory.setLayoutlibCallback(null);
|
ParserFactory.setParserFactory(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LayoutlibTestCallback extends LayoutlibCallback {
|
private static class ParserFactoryImpl
|
||||||
|
extends com.android.ide.common.rendering.api.ParserFactory {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public XmlPullParser createParser(String displayName) throws XmlPullParserException {
|
public XmlPullParser createParser(String displayName) throws XmlPullParserException {
|
||||||
return new KXmlParser();
|
return new KXmlParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supports(int ideFeature) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object loadView(String name, Class[] constructorSignature, Object[] constructorArgs)
|
|
||||||
throws Exception {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNamespace() {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public Pair<ResourceType, String> resolveResourceId(int id) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String resolveResourceId(int[] id) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer getResourceId(ResourceType type, String name) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public ILayoutPullParser getParser(String layoutName) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ILayoutPullParser getParser(ResourceValue layoutResource) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getAdapterItemValue(ResourceReference adapterView, Object adapterCookie,
|
|
||||||
ResourceReference itemRef, int fullPosition, int positionPerType,
|
|
||||||
int fullParentPosition, int parentPositionPerType, ResourceReference viewRef,
|
|
||||||
ViewAttribute viewAttribute, Object defaultValue) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AdapterBinding getAdapterBinding(ResourceReference adapterViewRef,
|
|
||||||
Object adapterCookie,
|
|
||||||
Object viewObject) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionBarCallback getActionBarCallback() {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user