diff options
Diffstat (limited to 'tools/layoutlib/bridge/src')
15 files changed, 113 insertions, 117 deletions
diff --git a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java b/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java index aabd3f1..f7654ce 100644 --- a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java +++ b/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java @@ -16,7 +16,7 @@ package android.app; -import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import android.content.Context; @@ -30,19 +30,19 @@ import android.os.Bundle; * * The methods being re-implemented are the ones responsible for instantiating Fragment objects. * Because the classes of these objects are found in the project, these methods need access to - * {@link IProjectCallback} object. They are however static methods, so the callback is set - * before the inflation through {@link #setProjectCallback(IProjectCallback)}. + * {@link LayoutlibCallback} object. They are however static methods, so the callback is set + * before the inflation through {@link #setLayoutlibCallback(LayoutlibCallback)}. */ public class Fragment_Delegate { - private static IProjectCallback sProjectCallback; + private static LayoutlibCallback sLayoutlibCallback; /** - * Sets the current {@link IProjectCallback} to be used to instantiate classes coming + * Sets the current {@link LayoutlibCallback} to be used to instantiate classes coming * from the project being rendered. */ - public static void setProjectCallback(IProjectCallback projectCallback) { - sProjectCallback = projectCallback; + public static void setLayoutlibCallback(LayoutlibCallback layoutlibCallback) { + sLayoutlibCallback = layoutlibCallback; } /** @@ -62,17 +62,17 @@ public class Fragment_Delegate { * This is currently just used to get its ClassLoader. * @param fname The class name of the fragment to instantiate. * @param args Bundle of arguments to supply to the fragment, which it - * can retrieve with {@link #getArguments()}. May be null. + * can retrieve with {@link Fragment#getArguments()}. May be null. * @return Returns a new fragment instance. - * @throws InstantiationException If there is a failure in instantiating + * @throws Fragment.InstantiationException If there is a failure in instantiating * the given fragment class. This is a runtime exception; it is not * normally expected to happen. */ @LayoutlibDelegate /*package*/ static Fragment instantiate(Context context, String fname, Bundle args) { try { - if (sProjectCallback != null) { - Fragment f = (Fragment) sProjectCallback.loadView(fname, + if (sLayoutlibCallback != null) { + Fragment f = (Fragment) sLayoutlibCallback.loadView(fname, new Class[0], new Object[0]); if (args != null) { diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java b/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java index a744345..2c2c672 100644 --- a/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java +++ b/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java @@ -16,8 +16,8 @@ package android.content.res; -import com.android.ide.common.rendering.api.IProjectCallback; import com.android.ide.common.rendering.api.LayoutLog; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; @@ -49,7 +49,7 @@ import java.io.InputStream; public final class BridgeResources extends Resources { private BridgeContext mContext; - private IProjectCallback mProjectCallback; + private LayoutlibCallback mLayoutlibCallback; private boolean[] mPlatformResourceFlag = new boolean[1]; private TypedValue mTmpValue = new TypedValue(); @@ -94,12 +94,12 @@ public final class BridgeResources extends Resources { AssetManager assets, DisplayMetrics metrics, Configuration config, - IProjectCallback projectCallback) { + LayoutlibCallback layoutlibCallback) { return Resources.mSystem = new BridgeResources(context, assets, metrics, config, - projectCallback); + layoutlibCallback); } /** @@ -109,16 +109,16 @@ public final class BridgeResources extends Resources { public static void disposeSystem() { if (Resources.mSystem instanceof BridgeResources) { ((BridgeResources)(Resources.mSystem)).mContext = null; - ((BridgeResources)(Resources.mSystem)).mProjectCallback = null; + ((BridgeResources)(Resources.mSystem)).mLayoutlibCallback = null; } Resources.mSystem = null; } private BridgeResources(BridgeContext context, AssetManager assets, DisplayMetrics metrics, - Configuration config, IProjectCallback projectCallback) { + Configuration config, LayoutlibCallback layoutlibCallback) { super(assets, metrics, config); mContext = context; - mProjectCallback = projectCallback; + mLayoutlibCallback = layoutlibCallback; } public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile) { @@ -138,8 +138,8 @@ public final class BridgeResources extends Resources { } // didn't find a match in the framework? look in the project. - if (mProjectCallback != null) { - resourceInfo = mProjectCallback.resolveResourceId(id); + if (mLayoutlibCallback != null) { + resourceInfo = mLayoutlibCallback.resolveResourceId(id); if (resourceInfo != null) { platformResFlag_out[0] = false; @@ -252,7 +252,7 @@ public final class BridgeResources extends Resources { try { // check if the current parser can provide us with a custom parser. if (mPlatformResourceFlag[0] == false) { - parser = mProjectCallback.getParser(value); + parser = mLayoutlibCallback.getParser(value); } // create a new one manually if needed. @@ -687,8 +687,8 @@ public final class BridgeResources extends Resources { Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(id); // if the name is unknown in the framework, get it from the custom view loader. - if (resourceInfo == null && mProjectCallback != null) { - resourceInfo = mProjectCallback.resolveResourceId(id); + if (resourceInfo == null && mLayoutlibCallback != null) { + resourceInfo = mLayoutlibCallback.resolveResourceId(id); } String message = null; diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java index ae2c173..7d4271b 100644 --- a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +++ b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java @@ -646,7 +646,7 @@ public final class BridgeTypedArray extends TypedArray { if (isFrameworkId) { idValue = Bridge.getResourceId(ResourceType.ID, idName); } else { - idValue = mContext.getProjectCallback().getResourceId(ResourceType.ID, idName); + idValue = mContext.getLayoutlibCallback().getResourceId(ResourceType.ID, idName); } return idValue == null ? defValue : idValue; } @@ -666,7 +666,7 @@ public final class BridgeTypedArray extends TypedArray { idValue = Bridge.getResourceId(resValue.getResourceType(), resValue.getName()); } else { - idValue = mContext.getProjectCallback().getResourceId( + idValue = mContext.getLayoutlibCallback().getResourceId( resValue.getResourceType(), resValue.getName()); } diff --git a/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java index 691339e..138b2d5 100644 --- a/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java +++ b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java @@ -69,8 +69,8 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes { // this is not an attribute in the android namespace, we query the customviewloader, if // the namespaces match. - if (mContext.getProjectCallback().getNamespace().equals(ns)) { - Integer v = mContext.getProjectCallback().getResourceId(ResourceType.ATTR, name); + if (mContext.getLayoutlibCallback().getNamespace().equals(ns)) { + Integer v = mContext.getLayoutlibCallback().getResourceId(ResourceType.ATTR, name); if (v != null) { return v.intValue(); } @@ -273,7 +273,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes { if (mPlatformFile || resource.isFramework()) { id = Bridge.getResourceId(resource.getResourceType(), resource.getName()); } else { - id = mContext.getProjectCallback().getResourceId( + id = mContext.getLayoutlibCallback().getResourceId( resource.getResourceType(), resource.getName()); } diff --git a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java index 4acbd1c..5db9556 100644 --- a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java +++ b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java @@ -16,7 +16,7 @@ package android.view; -import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.ide.common.rendering.api.LayoutLog; import com.android.ide.common.rendering.api.MergeCookie; import com.android.ide.common.rendering.api.ResourceReference; @@ -46,7 +46,7 @@ import static com.android.layoutlib.bridge.android.BridgeContext.getBaseContext; */ public final class BridgeInflater extends LayoutInflater { - private final IProjectCallback mProjectCallback; + private final LayoutlibCallback mLayoutlibCallback; private boolean mIsInMerge = false; private ResourceReference mResourceReference; @@ -64,21 +64,21 @@ public final class BridgeInflater extends LayoutInflater { super(original, newContext); newContext = getBaseContext(newContext); if (newContext instanceof BridgeContext) { - mProjectCallback = ((BridgeContext) newContext).getProjectCallback(); + mLayoutlibCallback = ((BridgeContext) newContext).getLayoutlibCallback(); } else { - mProjectCallback = null; + mLayoutlibCallback = null; } } /** - * Instantiate a new BridgeInflater with an {@link IProjectCallback} object. + * Instantiate a new BridgeInflater with an {@link LayoutlibCallback} object. * * @param context The Android application context. - * @param projectCallback the {@link IProjectCallback} object. + * @param layoutlibCallback the {@link LayoutlibCallback} object. */ - public BridgeInflater(Context context, IProjectCallback projectCallback) { + public BridgeInflater(Context context, LayoutlibCallback layoutlibCallback) { super(context); - mProjectCallback = projectCallback; + mLayoutlibCallback = layoutlibCallback; mConstructorArgs[0] = context; } @@ -167,12 +167,13 @@ public final class BridgeInflater extends LayoutInflater { ResourceValue value = null; + @SuppressWarnings("deprecation") Pair<ResourceType, String> layoutInfo = Bridge.resolveResourceId(resource); if (layoutInfo != null) { value = bridgeContext.getRenderResources().getFrameworkResource( ResourceType.LAYOUT, layoutInfo.getSecond()); } else { - layoutInfo = mProjectCallback.resolveResourceId(resource); + layoutInfo = mLayoutlibCallback.resolveResourceId(resource); if (layoutInfo != null) { value = bridgeContext.getRenderResources().getProjectResource( @@ -203,7 +204,7 @@ public final class BridgeInflater extends LayoutInflater { } private View loadCustomView(String name, AttributeSet attrs) throws Exception { - if (mProjectCallback != null) { + if (mLayoutlibCallback != null) { // first get the classname in case it's not the node name if (name.equals("view")) { name = attrs.getAttributeValue(null, "class"); @@ -211,7 +212,7 @@ public final class BridgeInflater extends LayoutInflater { mConstructorArgs[1] = attrs; - Object customView = mProjectCallback.loadView(name, mConstructorSignature, + Object customView = mLayoutlibCallback.loadView(name, mConstructorSignature, mConstructorArgs); if (customView instanceof View) { diff --git a/tools/layoutlib/bridge/src/com/android/internal/policy/PolicyManager.java b/tools/layoutlib/bridge/src/com/android/internal/policy/PolicyManager.java index 0100dc5..6558b6a 100644 --- a/tools/layoutlib/bridge/src/com/android/internal/policy/PolicyManager.java +++ b/tools/layoutlib/bridge/src/com/android/internal/policy/PolicyManager.java @@ -43,7 +43,7 @@ public class PolicyManager { } public static LayoutInflater makeNewLayoutInflater(Context context) { - return new BridgeInflater(context, RenderAction.getCurrentContext().getProjectCallback()); + return new BridgeInflater(context, RenderAction.getCurrentContext().getLayoutlibCallback()); } public static WindowManagerPolicy makeNewWindowManager() { 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 868529e..3f553e7 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 @@ -20,8 +20,8 @@ import android.os.IBinder; import com.android.annotations.Nullable; import com.android.ide.common.rendering.api.AssetRepository; import com.android.ide.common.rendering.api.ILayoutPullParser; -import com.android.ide.common.rendering.api.IProjectCallback; import com.android.ide.common.rendering.api.LayoutLog; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.ide.common.rendering.api.RenderResources; import com.android.ide.common.rendering.api.ResourceReference; import com.android.ide.common.rendering.api.ResourceValue; @@ -113,7 +113,7 @@ public final class BridgeContext extends Context { private final RenderResources mRenderResources; private final Configuration mConfig; private final ApplicationInfo mApplicationInfo; - private final IProjectCallback mProjectCallback; + private final LayoutlibCallback mLayoutlibCallback; private final WindowManager mWindowManager; private final DisplayManager mDisplayManager; @@ -147,13 +147,13 @@ public final class BridgeContext extends Context { public BridgeContext(Object projectKey, DisplayMetrics metrics, RenderResources renderResources, AssetRepository assets, - IProjectCallback projectCallback, + LayoutlibCallback layoutlibCallback, Configuration config, int targetSdkVersion, boolean hasRtlSupport) { mProjectKey = projectKey; mMetrics = metrics; - mProjectCallback = projectCallback; + mLayoutlibCallback = layoutlibCallback; mRenderResources = renderResources; mConfig = config; @@ -172,7 +172,7 @@ public final class BridgeContext extends Context { /** * Initializes the {@link Resources} singleton to be linked to this {@link Context}, its - * {@link DisplayMetrics}, {@link Configuration}, and {@link IProjectCallback}. + * {@link DisplayMetrics}, {@link Configuration}, and {@link LayoutlibCallback}. * * @see #disposeResources() */ @@ -184,7 +184,7 @@ public final class BridgeContext extends Context { assetManager, mMetrics, mConfig, - mProjectCallback); + mLayoutlibCallback); mTheme = mSystemResources.newTheme(); } @@ -223,8 +223,8 @@ public final class BridgeContext extends Context { return mMetrics; } - public IProjectCallback getProjectCallback() { - return mProjectCallback; + public LayoutlibCallback getLayoutlibCallback() { + return mLayoutlibCallback; } public RenderResources getRenderResources() { @@ -283,7 +283,7 @@ public final class BridgeContext extends Context { Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(resid); boolean isFrameworkRes = true; if (resourceInfo == null) { - resourceInfo = mProjectCallback.resolveResourceId(resid); + resourceInfo = mLayoutlibCallback.resolveResourceId(resid); isFrameworkRes = false; } @@ -339,8 +339,8 @@ public final class BridgeContext extends Context { } // didn't find a match in the framework? look in the project. - if (mProjectCallback != null) { - resourceInfo = mProjectCallback.resolveResourceId(id); + if (mLayoutlibCallback != null) { + resourceInfo = mLayoutlibCallback.resolveResourceId(id); if (resourceInfo != null) { return new ResourceReference(resourceInfo.getSecond(), false); @@ -438,9 +438,9 @@ public final class BridgeContext extends Context { private ILayoutPullParser getParser(ResourceReference resource) { ILayoutPullParser parser; if (resource instanceof ResourceValue) { - parser = mProjectCallback.getParser((ResourceValue) resource); + parser = mLayoutlibCallback.getParser((ResourceValue) resource); } else { - parser = mProjectCallback.getParser(resource.getName()); + parser = mLayoutlibCallback.getParser(resource.getName()); } return parser; } @@ -665,7 +665,7 @@ public final class BridgeContext extends Context { boolean isFrameworkRes = true; Pair<ResourceType, String> value = Bridge.resolveResourceId(defStyleRes); if (value == null) { - value = mProjectCallback.resolveResourceId(defStyleRes); + value = mLayoutlibCallback.resolveResourceId(defStyleRes); isFrameworkRes = false; } @@ -703,7 +703,7 @@ public final class BridgeContext extends Context { } } - String appNamespace = mProjectCallback.getNamespace(); + String appNamespace = mLayoutlibCallback.getNamespace(); if (attributeList != null) { for (int index = 0 ; index < attributeList.size() ; index++) { @@ -846,7 +846,7 @@ public final class BridgeContext extends Context { if (resolvedResource != null) { isFramework = true; } else { - resolvedResource = mProjectCallback.resolveResourceId(attr); + resolvedResource = mLayoutlibCallback.resolveResourceId(attr); } if (resolvedResource != null) { @@ -872,7 +872,7 @@ public final class BridgeContext extends Context { return Pair.of(info.getSecond(), Boolean.TRUE); } - info = mProjectCallback.resolveResourceId(attr); + info = mLayoutlibCallback.resolveResourceId(attr); if (info != null) { return Pair.of(info.getSecond(), Boolean.FALSE); } @@ -924,8 +924,8 @@ public final class BridgeContext extends Context { // getResourceId creates a new resource id if an existing resource id isn't found. So, we // check for the existence of the resource before calling it. if (getRenderResources().getProjectResource(resType, resName) != null) { - if (mProjectCallback != null) { - Integer value = mProjectCallback.getResourceId(resType, resName); + if (mLayoutlibCallback != null) { + Integer value = mLayoutlibCallback.getResourceId(resType, resName); if (value != null) { return value; } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java index 1d47333..aac5d33 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java @@ -18,8 +18,8 @@ package com.android.layoutlib.bridge.android.support; import com.android.annotations.NonNull; import com.android.annotations.Nullable; -import com.android.ide.common.rendering.api.IProjectCallback; import com.android.ide.common.rendering.api.LayoutLog; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.ide.common.rendering.api.SessionParams; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.android.BridgeContext; @@ -30,7 +30,6 @@ import android.view.View; import android.widget.LinearLayout; import java.lang.reflect.Method; -import java.util.HashMap; import static com.android.layoutlib.bridge.util.ReflectionUtils.*; @@ -61,7 +60,7 @@ public class RecyclerViewUtil { public static void setAdapter(@NonNull View recyclerView, @NonNull BridgeContext context, @NonNull SessionParams params) { try { - setLayoutManager(recyclerView, context, params.getProjectCallback()); + setLayoutManager(recyclerView, context, params.getLayoutlibCallback()); Object adapter = createAdapter(params); setProperty(recyclerView, CN_ADAPTER, adapter, "setAdapter"); } catch (ReflectionException e) { @@ -71,7 +70,7 @@ public class RecyclerViewUtil { } private static void setLayoutManager(@NonNull View recyclerView, @NonNull BridgeContext context, - @NonNull IProjectCallback callback) throws ReflectionException { + @NonNull LayoutlibCallback callback) throws ReflectionException { Object cookie = context.getCookie(recyclerView); assert cookie == null || cookie instanceof LayoutManagerType || cookie instanceof String; if (!(cookie instanceof LayoutManagerType)) { @@ -90,7 +89,7 @@ public class RecyclerViewUtil { @Nullable private static Object createLayoutManager(@Nullable LayoutManagerType type, - @NonNull Context context, @NonNull IProjectCallback callback) + @NonNull Context context, @NonNull LayoutlibCallback callback) throws ReflectionException { if (type == null) { type = LayoutManagerType.getDefault(); @@ -109,7 +108,7 @@ public class RecyclerViewUtil { return null; } try { - return params.getProjectCallback().loadView(CN_ADAPTER, new Class[0], new Object[0]); + return params.getLayoutlibCallback().loadView(CN_ADAPTER, new Class[0], new Object[0]); } catch (Exception e) { throw new ReflectionException(e); } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java index ee57067..dd1f661 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java @@ -70,7 +70,7 @@ public class AppCompatActionBar extends BridgeActionBar { try { Class[] constructorParams = {View.class}; Object[] constructorArgs = {getDecorContent()}; - mWindowDecorActionBar = params.getProjectCallback().loadView(WINDOW_ACTION_BAR_CLASS, + mWindowDecorActionBar = params.getLayoutlibCallback().loadView(WINDOW_ACTION_BAR_CLASS, constructorParams, constructorArgs); mWindowActionBarClass = mWindowDecorActionBar == null ? null : diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/BridgeActionBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/BridgeActionBar.java index 2a83ea1..3d1a9b9 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/BridgeActionBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/BridgeActionBar.java @@ -51,7 +51,7 @@ public abstract class BridgeActionBar { @NonNull ViewGroup parentView) { mBridgeContext = context; mParams = params; - mCallback = params.getProjectCallback().getActionBarCallback(); + mCallback = params.getLayoutlibCallback().getActionBarCallback(); ResourceValue layoutName = getLayoutResource(context); if (layoutName == null) { throw new RuntimeException("Unable to find the layout for Action Bar."); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java index 127cb72..c708316 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java @@ -16,10 +16,6 @@ package com.android.layoutlib.bridge.impl; -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.SUCCESS; - import com.android.ide.common.rendering.api.HardwareConfig; import com.android.ide.common.rendering.api.LayoutLog; import com.android.ide.common.rendering.api.RenderParams; @@ -43,6 +39,10 @@ import android.view.inputmethod.InputMethodManager_Accessor; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +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.SUCCESS; + /** * Base class for rendering action. * @@ -120,7 +120,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso // build the context mContext = new BridgeContext(mParams.getProjectKey(), metrics, resources, - mParams.getAssets(), mParams.getProjectCallback(), getConfiguration(), + mParams.getAssets(), mParams.getLayoutlibCallback(), getConfiguration(), mParams.getTargetSdkVersion(), mParams.isRtlSupported()); setUp(); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index ff67f65..95576ef 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -16,20 +16,13 @@ package com.android.layoutlib.bridge.impl; -import static com.android.ide.common.rendering.api.Result.Status.ERROR_ANIM_NOT_FOUND; -import static com.android.ide.common.rendering.api.Result.Status.ERROR_INFLATION; -import static com.android.ide.common.rendering.api.Result.Status.ERROR_NOT_INFLATED; -import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN; -import static com.android.ide.common.rendering.api.Result.Status.ERROR_VIEWGROUP_NO_CHILDREN; -import static com.android.ide.common.rendering.api.Result.Status.SUCCESS; - import com.android.annotations.NonNull; import com.android.annotations.Nullable; import com.android.ide.common.rendering.api.AdapterBinding; import com.android.ide.common.rendering.api.HardwareConfig; import com.android.ide.common.rendering.api.IAnimationListener; import com.android.ide.common.rendering.api.ILayoutPullParser; -import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.ide.common.rendering.api.RenderResources; import com.android.ide.common.rendering.api.RenderSession; import com.android.ide.common.rendering.api.ResourceReference; @@ -54,13 +47,13 @@ import com.android.layoutlib.bridge.android.BridgeLayoutParamsMapAttributes; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; import com.android.layoutlib.bridge.android.SessionParamsFlags; import com.android.layoutlib.bridge.android.support.RecyclerViewUtil; -import com.android.layoutlib.bridge.bars.BridgeActionBar; import com.android.layoutlib.bridge.bars.AppCompatActionBar; +import com.android.layoutlib.bridge.bars.BridgeActionBar; import com.android.layoutlib.bridge.bars.Config; +import com.android.layoutlib.bridge.bars.FrameworkActionBar; import com.android.layoutlib.bridge.bars.NavigationBar; import com.android.layoutlib.bridge.bars.StatusBar; import com.android.layoutlib.bridge.bars.TitleBar; -import com.android.layoutlib.bridge.bars.FrameworkActionBar; import com.android.layoutlib.bridge.impl.binding.FakeAdapter; import com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter; import com.android.resources.Density; @@ -116,6 +109,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_ANIM_NOT_FOUND; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_INFLATION; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_NOT_INFLATED; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_VIEWGROUP_NO_CHILDREN; +import static com.android.ide.common.rendering.api.Result.Status.SUCCESS; + /** * Class implementing the render session. * <p/> @@ -219,7 +219,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { WindowManagerGlobal_Delegate.setWindowManagerService(iwm); // build the inflater and parser. - mInflater = new BridgeInflater(context, params.getProjectCallback()); + mInflater = new BridgeInflater(context, params.getLayoutlibCallback()); context.setBridgeInflater(mInflater); mBlockParser = new BridgeXmlBlockParser( @@ -401,7 +401,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { // Sets the project callback (custom view loader) to the fragment delegate so that // it can instantiate the custom Fragment. - Fragment_Delegate.setProjectCallback(params.getProjectCallback()); + Fragment_Delegate.setLayoutlibCallback(params.getLayoutlibCallback()); String rootTag = params.getFlag(SessionParamsFlags.FLAG_KEY_ROOT_TAG); boolean isPreference = "PreferenceScreen".equals(rootTag); @@ -416,13 +416,13 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { // done with the parser, pop it. context.popParser(); - Fragment_Delegate.setProjectCallback(null); + Fragment_Delegate.setLayoutlibCallback(null); // set the AttachInfo on the root view. AttachInfo_Accessor.setAttachInfo(mViewRoot); // post-inflate process. For now this supports TabHost/TabWidget - postInflateProcess(view, params.getProjectCallback(), isPreference ? view : null); + postInflateProcess(view, params.getLayoutlibCallback(), isPreference ? view : null); // get the background drawable if (mWindowBackground != null) { @@ -675,7 +675,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { animationResource = context.getRenderResources().getProjectResource( ResourceType.ANIMATOR, animationName); if (animationResource != null) { - animationId = context.getProjectCallback().getResourceId( + animationId = context.getLayoutlibCallback().getResourceId( ResourceType.ANIMATOR, animationName); } } @@ -1246,17 +1246,17 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { * {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically * based on the content of the {@link FrameLayout}. * @param view the root view to process. - * @param projectCallback callback to the project. + * @param layoutlibCallback callback to the project. * @param skip the view and it's children are not processed. */ @SuppressWarnings("deprecation") // For the use of Pair - private void postInflateProcess(View view, IProjectCallback projectCallback, View skip) + private void postInflateProcess(View view, LayoutlibCallback layoutlibCallback, View skip) throws PostInflateException { if (view == skip) { return; } if (view instanceof TabHost) { - setupTabHost((TabHost) view, projectCallback); + setupTabHost((TabHost) view, layoutlibCallback); } else if (view instanceof QuickContactBadge) { QuickContactBadge badge = (QuickContactBadge) view; badge.setImageToDefault(); @@ -1275,8 +1275,8 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { // if there was no adapter binding, trying to get it from the call back. if (binding == null) { - binding = params.getProjectCallback().getAdapterBinding(listRef, - context.getViewKey(view), view); + binding = layoutlibCallback.getAdapterBinding( + listRef, context.getViewKey(view), view); } if (binding != null) { @@ -1292,7 +1292,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { for (int i = 0; i < count; i++) { Pair<View, Boolean> pair = context.inflateView( binding.getHeaderAt(i), - list, false /*attachToRoot*/, skipCallbackParser); + list, false, skipCallbackParser); if (pair.getFirst() != null) { list.addHeaderView(pair.getFirst()); } @@ -1304,7 +1304,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { for (int i = 0; i < count; i++) { Pair<View, Boolean> pair = context.inflateView( binding.getFooterAt(i), - list, false /*attachToRoot*/, skipCallbackParser); + list, false, skipCallbackParser); if (pair.getFirst() != null) { list.addFooterView(pair.getFirst()); } @@ -1315,17 +1315,14 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { if (view instanceof ExpandableListView) { ((ExpandableListView) view).setAdapter( - new FakeExpandableAdapter( - listRef, binding, params.getProjectCallback())); + new FakeExpandableAdapter(listRef, binding, layoutlibCallback)); } else { ((AbsListView) view).setAdapter( - new FakeAdapter( - listRef, binding, params.getProjectCallback())); + new FakeAdapter(listRef, binding, layoutlibCallback)); } } else if (view instanceof AbsSpinner) { ((AbsSpinner) view).setAdapter( - new FakeAdapter( - listRef, binding, params.getProjectCallback())); + new FakeAdapter(listRef, binding, layoutlibCallback)); } } } @@ -1336,7 +1333,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { final int count = group.getChildCount(); for (int c = 0; c < count; c++) { View child = group.getChildAt(c); - postInflateProcess(child, projectCallback, skip); + postInflateProcess(child, layoutlibCallback, skip); } } } @@ -1360,10 +1357,10 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { /** * Sets up a {@link TabHost} object. * @param tabHost the TabHost to setup. - * @param projectCallback The project callback object to access the project R class. + * @param layoutlibCallback The project callback object to access the project R class. * @throws PostInflateException */ - private void setupTabHost(TabHost tabHost, IProjectCallback projectCallback) + private void setupTabHost(TabHost tabHost, LayoutlibCallback layoutlibCallback) throws PostInflateException { // look for the TabWidget, and the FrameLayout. They have their own specific names View v = tabHost.findViewById(android.R.id.tabs); @@ -1424,7 +1421,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { @SuppressWarnings("ConstantConditions") // child cannot be null. int id = child.getId(); @SuppressWarnings("deprecation") - Pair<ResourceType, String> resource = projectCallback.resolveResourceId(id); + Pair<ResourceType, String> resource = layoutlibCallback.resolveResourceId(id); String name; if (resource != null) { name = resource.getSecond(); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/AdapterHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/AdapterHelper.java index 6c998af..9aab340 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/AdapterHelper.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/AdapterHelper.java @@ -17,7 +17,7 @@ package com.android.layoutlib.bridge.impl.binding; import com.android.ide.common.rendering.api.DataBindingItem; -import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.ide.common.rendering.api.LayoutLog; import com.android.ide.common.rendering.api.ResourceReference; import com.android.ide.common.rendering.api.IProjectCallback.ViewAttribute; @@ -40,7 +40,7 @@ import android.widget.TextView; public class AdapterHelper { static Pair<View, Boolean> getView(AdapterItem item, AdapterItem parentItem, ViewGroup parent, - IProjectCallback callback, ResourceReference adapterRef, boolean skipCallbackParser) { + LayoutlibCallback callback, ResourceReference adapterRef, boolean skipCallbackParser) { // we don't care about recycling here because we never scroll. DataBindingItem dataBindingItem = item.getDataBindingItem(); @@ -65,7 +65,7 @@ public class AdapterHelper { } private static void fillView(BridgeContext context, View view, AdapterItem item, - AdapterItem parentItem, IProjectCallback callback, ResourceReference adapterRef) { + AdapterItem parentItem, LayoutlibCallback callback, ResourceReference adapterRef) { if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; final int count = group.getChildCount(); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/FakeAdapter.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/FakeAdapter.java index 9a13f5a..142eac1 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/FakeAdapter.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/FakeAdapter.java @@ -18,7 +18,7 @@ package com.android.layoutlib.bridge.impl.binding; import com.android.ide.common.rendering.api.AdapterBinding; import com.android.ide.common.rendering.api.DataBindingItem; -import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.ide.common.rendering.api.ResourceReference; import com.android.util.Pair; @@ -37,18 +37,17 @@ import java.util.List; * and {@link SpinnerAdapter}. * */ -@SuppressWarnings("deprecation") public class FakeAdapter extends BaseAdapter { // don't use a set because the order is important. private final List<ResourceReference> mTypes = new ArrayList<ResourceReference>(); - private final IProjectCallback mCallback; + private final LayoutlibCallback mCallback; private final ResourceReference mAdapterRef; private final List<AdapterItem> mItems = new ArrayList<AdapterItem>(); private boolean mSkipCallbackParser = false; public FakeAdapter(ResourceReference adapterRef, AdapterBinding binding, - IProjectCallback callback) { + LayoutlibCallback callback) { mAdapterRef = adapterRef; mCallback = callback; @@ -111,11 +110,11 @@ public class FakeAdapter extends BaseAdapter { public View getView(int position, View convertView, ViewGroup parent) { // we don't care about recycling here because we never scroll. AdapterItem item = mItems.get(position); - Pair<View, Boolean> pair = AdapterHelper.getView(item, null /*parentGroup*/, parent, - mCallback, mAdapterRef, mSkipCallbackParser); + @SuppressWarnings("deprecation") + Pair<View, Boolean> pair = AdapterHelper.getView(item, null, parent, mCallback, + mAdapterRef, mSkipCallbackParser); mSkipCallbackParser = pair.getSecond(); return pair.getFirst(); - } @Override diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/FakeExpandableAdapter.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/FakeExpandableAdapter.java index e539579..344b17e 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/FakeExpandableAdapter.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/binding/FakeExpandableAdapter.java @@ -18,7 +18,7 @@ package com.android.layoutlib.bridge.impl.binding; import com.android.ide.common.rendering.api.AdapterBinding; import com.android.ide.common.rendering.api.DataBindingItem; -import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.ide.common.rendering.api.ResourceReference; import com.android.util.Pair; @@ -34,7 +34,7 @@ import java.util.List; @SuppressWarnings("deprecation") public class FakeExpandableAdapter implements ExpandableListAdapter, HeterogeneousExpandableList { - private final IProjectCallback mCallback; + private final LayoutlibCallback mCallback; private final ResourceReference mAdapterRef; private boolean mSkipCallbackParser = false; @@ -45,7 +45,7 @@ public class FakeExpandableAdapter implements ExpandableListAdapter, Heterogeneo private final List<ResourceReference> mChildrenTypes = new ArrayList<ResourceReference>(); public FakeExpandableAdapter(ResourceReference adapterRef, AdapterBinding binding, - IProjectCallback callback) { + LayoutlibCallback callback) { mAdapterRef = adapterRef; mCallback = callback; |