From 7f9f99ea11051614a7727dfb9f9578b518e76e3c Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Thu, 11 Aug 2011 10:16:17 -0700 Subject: Make some methods/fields package private so that layoutlib can access them. Change-Id: I4aeadfbaf8a4f6a459fa19937c21ac23d9e5fb64 --- .../src/android/animation/AnimationThread.java | 171 +++++++++++++ .../android/content/res/BridgeAssetManager.java | 53 ++++ .../src/android/content/res/BridgeResources.java | 122 +++++---- .../src/android/content/res/BridgeTypedArray.java | 9 - .../android/content/res/TypedArray_Delegate.java | 30 +++ .../src/android/graphics/Bitmap_Delegate.java | 7 +- .../src/android/graphics/Typeface_Accessor.java | 24 ++ .../bridge/src/android/os/Looper_Accessor.java | 24 ++ .../src/android/os/SystemClock_Delegate.java | 24 ++ .../src/android/util/BridgeXmlPullAttributes.java | 128 ++++++++++ .../src/android/view/AttachInfo_Accessor.java | 40 +++ .../bridge/src/android/view/BridgeInflater.java | 272 +++++++++++++++++++++ .../bridge/src/android/view/Display_Delegate.java | 18 +- .../src/android/view/LayoutInflater_Delegate.java | 1 - .../android/view/ViewConfiguration_Accessor.java | 26 ++ .../inputmethod/InputMethodManager_Accessor.java | 24 ++ .../src/com/android/layoutlib/bridge/Bridge.java | 9 +- .../bridge/android/BridgeAssetManager.java | 53 ---- .../layoutlib/bridge/android/BridgeContext.java | 27 +- .../layoutlib/bridge/android/BridgeInflater.java | 270 -------------------- .../layoutlib/bridge/android/BridgeWindow.java | 3 +- .../bridge/android/BridgeWindowManager.java | 2 - .../bridge/android/BridgeXmlBlockParser.java | 6 +- .../bridge/android/BridgeXmlPullAttributes.java | 127 ---------- .../layoutlib/bridge/bars/PhoneSystemBar.java | 3 +- .../layoutlib/bridge/impl/AnimationThread.java | 170 ------------- .../layoutlib/bridge/impl/PlayAnimationThread.java | 1 + .../layoutlib/bridge/impl/RenderAction.java | 7 +- .../layoutlib/bridge/impl/RenderDrawable.java | 16 +- .../layoutlib/bridge/impl/RenderSessionImpl.java | 19 +- .../android/tools/layoutlib/create/CreateInfo.java | 5 +- .../com/android/tools/layoutlib/create/Main.java | 2 + 32 files changed, 939 insertions(+), 754 deletions(-) create mode 100644 tools/layoutlib/bridge/src/android/animation/AnimationThread.java create mode 100644 tools/layoutlib/bridge/src/android/content/res/BridgeAssetManager.java create mode 100644 tools/layoutlib/bridge/src/android/content/res/TypedArray_Delegate.java create mode 100644 tools/layoutlib/bridge/src/android/graphics/Typeface_Accessor.java create mode 100644 tools/layoutlib/bridge/src/android/os/Looper_Accessor.java create mode 100644 tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java create mode 100644 tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java create mode 100644 tools/layoutlib/bridge/src/android/view/BridgeInflater.java create mode 100644 tools/layoutlib/bridge/src/android/view/ViewConfiguration_Accessor.java create mode 100644 tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java delete mode 100644 tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeAssetManager.java delete mode 100644 tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java delete mode 100644 tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java delete mode 100644 tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java (limited to 'tools/layoutlib') diff --git a/tools/layoutlib/bridge/src/android/animation/AnimationThread.java b/tools/layoutlib/bridge/src/android/animation/AnimationThread.java new file mode 100644 index 0000000..2b5e4fa --- /dev/null +++ b/tools/layoutlib/bridge/src/android/animation/AnimationThread.java @@ -0,0 +1,171 @@ +/* + * 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 android.animation; + +import com.android.ide.common.rendering.api.IAnimationListener; +import com.android.ide.common.rendering.api.RenderSession; +import com.android.ide.common.rendering.api.Result; +import com.android.ide.common.rendering.api.Result.Status; +import com.android.layoutlib.bridge.Bridge; +import com.android.layoutlib.bridge.impl.RenderSessionImpl; + +import android.animation.ValueAnimator; +import android.os.Handler; +import android.os.Handler_Delegate; +import android.os.Message; +import android.os.Handler_Delegate.IHandlerCallback; + +import java.util.PriorityQueue; +import java.util.Queue; + +/** + * Abstract animation thread. + *

+ * This does not actually start an animation, instead it fakes a looper that will play whatever + * animation is sending messages to its own {@link Handler}. + *

+ * Classes should implement {@link #preAnimation()} and {@link #postAnimation()}. + *

+ * If {@link #preAnimation()} does not start an animation somehow then the thread doesn't do + * anything. + * + */ +public abstract class AnimationThread extends Thread { + + private static class MessageBundle implements Comparable { + final Handler mTarget; + final Message mMessage; + final long mUptimeMillis; + + MessageBundle(Handler target, Message message, long uptimeMillis) { + mTarget = target; + mMessage = message; + mUptimeMillis = uptimeMillis; + } + + public int compareTo(MessageBundle bundle) { + if (mUptimeMillis < bundle.mUptimeMillis) { + return -1; + } + return 1; + } + } + + private final RenderSessionImpl mSession; + + private Queue mQueue = new PriorityQueue(); + private final IAnimationListener mListener; + + public AnimationThread(RenderSessionImpl scene, String threadName, + IAnimationListener listener) { + super(threadName); + mSession = scene; + mListener = listener; + } + + public abstract Result preAnimation(); + public abstract void postAnimation(); + + @Override + public void run() { + Bridge.prepareThread(); + try { + Handler_Delegate.setCallback(new IHandlerCallback() { + public void sendMessageAtTime(Handler handler, Message msg, long uptimeMillis) { + if (msg.what == ValueAnimator.ANIMATION_START || + msg.what == ValueAnimator.ANIMATION_FRAME) { + mQueue.add(new MessageBundle(handler, msg, uptimeMillis)); + } else { + // just ignore. + } + } + }); + + // call out to the pre-animation work, which should start an animation or more. + Result result = preAnimation(); + if (result.isSuccess() == false) { + mListener.done(result); + } + + // loop the animation + RenderSession session = mSession.getSession(); + do { + // check early. + if (mListener.isCanceled()) { + break; + } + + // get the next message. + MessageBundle bundle = mQueue.poll(); + if (bundle == null) { + break; + } + + // sleep enough for this bundle to be on time + long currentTime = System.currentTimeMillis(); + if (currentTime < bundle.mUptimeMillis) { + try { + sleep(bundle.mUptimeMillis - currentTime); + } catch (InterruptedException e) { + // FIXME log/do something/sleep again? + e.printStackTrace(); + } + } + + // check after sleeping. + if (mListener.isCanceled()) { + break; + } + + // ready to do the work, acquire the scene. + result = mSession.acquire(250); + if (result.isSuccess() == false) { + mListener.done(result); + return; + } + + // process the bundle. If the animation is not finished, this will enqueue + // the next message, so mQueue will have another one. + try { + // check after acquiring in case it took a while. + if (mListener.isCanceled()) { + break; + } + + bundle.mTarget.handleMessage(bundle.mMessage); + if (mSession.render(false /*freshRender*/).isSuccess()) { + mListener.onNewFrame(session); + } + } finally { + mSession.release(); + } + } while (mListener.isCanceled() == false && mQueue.size() > 0); + + mListener.done(Status.SUCCESS.createResult()); + + } catch (Throwable throwable) { + // can't use Bridge.getLog() as the exception might be thrown outside + // of an acquire/release block. + mListener.done(Status.ERROR_UNKNOWN.createResult("Error playing animation", throwable)); + + } finally { + postAnimation(); + Handler_Delegate.setCallback(null); + Bridge.cleanupThread(); + } + } +} diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeAssetManager.java b/tools/layoutlib/bridge/src/android/content/res/BridgeAssetManager.java new file mode 100644 index 0000000..a953918 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/content/res/BridgeAssetManager.java @@ -0,0 +1,53 @@ +/* + * 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.content.res; + +import com.android.layoutlib.bridge.Bridge; + +import android.content.res.AssetManager; + +public class BridgeAssetManager extends AssetManager { + + /** + * This initializes the static field {@link AssetManager#mSystem} which is used + * by methods who get a global asset manager using {@link AssetManager#getSystem()}. + *

+ * They will end up using our bridge asset manager. + *

+ * {@link Bridge} calls this method after setting up a new bridge. + */ + public static AssetManager initSystem() { + if (!(AssetManager.sSystem instanceof BridgeAssetManager)) { + // Note that AssetManager() creates a system AssetManager and we override it + // with our BridgeAssetManager. + AssetManager.sSystem = new BridgeAssetManager(); + AssetManager.sSystem.makeStringBlocks(false); + } + return AssetManager.sSystem; + } + + /** + * Clears the static {@link AssetManager#sSystem} to make sure we don't leave objects + * around that would prevent us from unloading the library. + */ + public static void clearSystem() { + AssetManager.sSystem = null; + } + + private BridgeAssetManager() { + } +} diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java b/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java index 0928ec5..7b672da 100644 --- a/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java +++ b/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java @@ -214,7 +214,15 @@ public final class BridgeResources extends Resources { Pair value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { - return value.getSecond().getValue(); + ResourceValue resValue = value.getSecond(); + + assert resValue != null; + if (resValue != null) { + String v = resValue.getValue(); + if (v != null) { + return v; + } + } } // id was not found or not resolved. Throw a NotFoundException. @@ -318,20 +326,24 @@ public final class BridgeResources extends Resources { Pair value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { - String v = value.getSecond().getValue(); - - if (v != null) { - if (v.equals(BridgeConstants.MATCH_PARENT) || - v.equals(BridgeConstants.FILL_PARENT)) { - return LayoutParams.MATCH_PARENT; - } else if (v.equals(BridgeConstants.WRAP_CONTENT)) { - return LayoutParams.WRAP_CONTENT; - } + ResourceValue resValue = value.getSecond(); + + assert resValue != null; + if (resValue != null) { + String v = resValue.getValue(); + if (v != null) { + if (v.equals(BridgeConstants.MATCH_PARENT) || + v.equals(BridgeConstants.FILL_PARENT)) { + return LayoutParams.MATCH_PARENT; + } else if (v.equals(BridgeConstants.WRAP_CONTENT)) { + return LayoutParams.WRAP_CONTENT; + } - if (ResourceHelper.parseFloatAttribute( - value.getFirst(), v, mTmpValue, true /*requireUnit*/) && - mTmpValue.type == TypedValue.TYPE_DIMENSION) { - return mTmpValue.getDimension(getDisplayMetrics()); + if (ResourceHelper.parseFloatAttribute( + value.getFirst(), v, mTmpValue, true /*requireUnit*/) && + mTmpValue.type == TypedValue.TYPE_DIMENSION) { + return mTmpValue.getDimension(getDisplayMetrics()); + } } } } @@ -348,14 +360,18 @@ public final class BridgeResources extends Resources { Pair value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { - String v = value.getSecond().getValue(); - - if (v != null) { - if (ResourceHelper.parseFloatAttribute( - value.getFirst(), v, mTmpValue, true /*requireUnit*/) && - mTmpValue.type == TypedValue.TYPE_DIMENSION) { - return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, - getDisplayMetrics()); + ResourceValue resValue = value.getSecond(); + + assert resValue != null; + if (resValue != null) { + String v = resValue.getValue(); + if (v != null) { + if (ResourceHelper.parseFloatAttribute( + value.getFirst(), v, mTmpValue, true /*requireUnit*/) && + mTmpValue.type == TypedValue.TYPE_DIMENSION) { + return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, + getDisplayMetrics()); + } } } } @@ -372,14 +388,18 @@ public final class BridgeResources extends Resources { Pair value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { - String v = value.getSecond().getValue(); - - if (v != null) { - if (ResourceHelper.parseFloatAttribute( - value.getFirst(), v, mTmpValue, true /*requireUnit*/) && - mTmpValue.type == TypedValue.TYPE_DIMENSION) { - return TypedValue.complexToDimensionPixelSize(mTmpValue.data, - getDisplayMetrics()); + ResourceValue resValue = value.getSecond(); + + assert resValue != null; + if (resValue != null) { + String v = resValue.getValue(); + if (v != null) { + if (ResourceHelper.parseFloatAttribute( + value.getFirst(), v, mTmpValue, true /*requireUnit*/) && + mTmpValue.type == TypedValue.TYPE_DIMENSION) { + return TypedValue.complexToDimensionPixelSize(mTmpValue.data, + getDisplayMetrics()); + } } } } @@ -395,17 +415,24 @@ public final class BridgeResources extends Resources { public int getInteger(int id) throws NotFoundException { Pair value = getResourceValue(id, mPlatformResourceFlag); - if (value != null && value.getSecond().getValue() != null) { - String v = value.getSecond().getValue(); - int radix = 10; - if (v.startsWith("0x")) { - v = v.substring(2); - radix = 16; - } - try { - return Integer.parseInt(v, radix); - } catch (NumberFormatException e) { - // return exception below + if (value != null) { + ResourceValue resValue = value.getSecond(); + + assert resValue != null; + if (resValue != null) { + String v = resValue.getValue(); + if (v != null) { + int radix = 10; + if (v.startsWith("0x")) { + v = v.substring(2); + radix = 16; + } + try { + return Integer.parseInt(v, radix); + } catch (NumberFormatException e) { + // return exception below + } + } } } @@ -420,9 +447,16 @@ public final class BridgeResources extends Resources { public boolean getBoolean(int id) throws NotFoundException { Pair value = getResourceValue(id, mPlatformResourceFlag); - if (value != null && value.getSecond().getValue() != null) { - String v = value.getSecond().getValue(); - return Boolean.parseBoolean(v); + if (value != null) { + ResourceValue resValue = value.getSecond(); + + assert resValue != null; + if (resValue != null) { + String v = resValue.getValue(); + if (v != null) { + return Boolean.parseBoolean(v); + } + } } // id was not found or not resolved. Throw a NotFoundException. diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java index 9deed32..8fdac02 100644 --- a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +++ b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java @@ -33,9 +33,6 @@ import com.android.resources.ResourceType; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import android.content.res.ColorStateList; -import android.content.res.Resources; -import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.util.TypedValue; @@ -897,12 +894,6 @@ public final class BridgeTypedArray extends TypedArray { } @Override - public boolean getValueAt(int index, TypedValue outValue) { - // pass - return false; - } - - @Override public String toString() { return Arrays.toString(mResourceData); } diff --git a/tools/layoutlib/bridge/src/android/content/res/TypedArray_Delegate.java b/tools/layoutlib/bridge/src/android/content/res/TypedArray_Delegate.java new file mode 100644 index 0000000..0a7899a --- /dev/null +++ b/tools/layoutlib/bridge/src/android/content/res/TypedArray_Delegate.java @@ -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. + */ + +package android.content.res; + +import com.android.tools.layoutlib.annotations.LayoutlibDelegate; + +import android.util.TypedValue; + +public class TypedArray_Delegate { + + @LayoutlibDelegate + public static boolean getValueAt(TypedArray theTypedArray, int index, TypedValue outValue) { + // pass + return false; + } +} diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java index 66e59d8..eadec02 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java @@ -22,7 +22,6 @@ import com.android.layoutlib.bridge.impl.DelegateManager; import com.android.resources.Density; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; -import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.os.Parcel; @@ -149,7 +148,7 @@ public final class Bitmap_Delegate { } public static int getBufferedImageType(int nativeBitmapConfig) { - switch (Config.sConfigs[nativeBitmapConfig]) { + switch (Config.nativeToConfig(nativeBitmapConfig)) { case ALPHA_8: return BufferedImage.TYPE_INT_ARGB; case RGB_565: @@ -210,7 +209,7 @@ public final class Bitmap_Delegate { } // create a delegate with the content of the stream. - Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.sConfigs[nativeConfig]); + Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.nativeToConfig(nativeConfig)); return createBitmap(delegate, mutable, Bitmap.getDefaultDensity()); } @@ -238,7 +237,7 @@ public final class Bitmap_Delegate { image.setRGB(0, 0, width, height, argb, 0, width); // create a delegate with the content of the stream. - Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.sConfigs[nativeConfig]); + Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.nativeToConfig(nativeConfig)); return createBitmap(delegate, isMutable, Bitmap.getDefaultDensity()); } diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Accessor.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Accessor.java new file mode 100644 index 0000000..2745770 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Accessor.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +package android.graphics; + +public class Typeface_Accessor { + + public static void resetDefaults() { + Typeface.sDefaults = null; + } +} diff --git a/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java b/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java new file mode 100644 index 0000000..ad95fcc --- /dev/null +++ b/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +package android.os; + +public class Looper_Accessor { + + public static void cleanupThread() { + // clean up the looper + Looper.sThreadLocal.remove(); + } +} diff --git a/tools/layoutlib/bridge/src/android/os/SystemClock_Delegate.java b/tools/layoutlib/bridge/src/android/os/SystemClock_Delegate.java index 63711a7..bd332a6 100644 --- a/tools/layoutlib/bridge/src/android/os/SystemClock_Delegate.java +++ b/tools/layoutlib/bridge/src/android/os/SystemClock_Delegate.java @@ -68,4 +68,28 @@ public class SystemClock_Delegate { /*package*/ static long currentThreadTimeMillis() { return System.currentTimeMillis(); } + + /** + * Returns microseconds running in the current thread. + * + * @return elapsed microseconds in the thread + * + * @hide + */ + @LayoutlibDelegate + /*package*/ static long currentThreadTimeMicro() { + return System.currentTimeMillis() * 1000; + } + + /** + * Returns current wall time in microseconds. + * + * @return elapsed microseconds in wall time + * + * @hide + */ + @LayoutlibDelegate + /*package*/ static long currentTimeMicro() { + return elapsedRealtime() * 1000; + } } diff --git a/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java new file mode 100644 index 0000000..0a3cdc6 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java @@ -0,0 +1,128 @@ +/* + * 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.util; + +import com.android.ide.common.rendering.api.RenderResources; +import com.android.ide.common.rendering.api.ResourceValue; +import com.android.layoutlib.bridge.Bridge; +import com.android.layoutlib.bridge.BridgeConstants; +import com.android.layoutlib.bridge.android.BridgeContext; +import com.android.resources.ResourceType; + +import org.xmlpull.v1.XmlPullParser; + +import android.util.AttributeSet; +import android.util.XmlPullAttributes; + +/** + * A correct implementation of the {@link AttributeSet} interface on top of a XmlPullParser + */ +public class BridgeXmlPullAttributes extends XmlPullAttributes { + + private final BridgeContext mContext; + private final boolean mPlatformFile; + + public BridgeXmlPullAttributes(XmlPullParser parser, BridgeContext context, + boolean platformFile) { + super(parser); + mContext = context; + mPlatformFile = platformFile; + } + + /* + * (non-Javadoc) + * @see android.util.XmlPullAttributes#getAttributeNameResource(int) + * + * This methods must return com.android.internal.R.attr. matching + * the name of the attribute. + * It returns 0 if it doesn't find anything. + */ + @Override + public int getAttributeNameResource(int index) { + // get the attribute name. + String name = getAttributeName(index); + + // get the attribute namespace + String ns = mParser.getAttributeNamespace(index); + + if (BridgeConstants.NS_RESOURCES.equals(ns)) { + Integer v = Bridge.getResourceId(ResourceType.ATTR, name); + if (v != null) { + return v.intValue(); + } + + return 0; + } + + // 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 (v != null) { + return v.intValue(); + } + } + + return 0; + } + + /* + * (non-Javadoc) + * @see android.util.XmlPullAttributes#getAttributeResourceValue(int, int) + */ + @Override + public int getAttributeResourceValue(int index, int defaultValue) { + String value = getAttributeValue(index); + + return resolveResourceValue(value, defaultValue); + } + + /* + * (non-Javadoc) + * @see android.util.XmlPullAttributes#getAttributeResourceValue(java.lang.String, java.lang.String, int) + */ + @Override + public int getAttributeResourceValue(String namespace, String attribute, int defaultValue) { + String value = getAttributeValue(namespace, attribute); + + return resolveResourceValue(value, defaultValue); + } + + private int resolveResourceValue(String value, int defaultValue) { + // now look for this particular value + RenderResources resources = mContext.getRenderResources(); + ResourceValue resource = resources.resolveResValue( + resources.findResValue(value, mPlatformFile)); + + if (resource != null) { + Integer id = null; + if (mPlatformFile || resource.isFramework()) { + id = Bridge.getResourceId(resource.getResourceType(), resource.getName()); + } else { + id = mContext.getProjectCallback().getResourceId( + resource.getResourceType(), resource.getName()); + } + + if (id != null) { + return id; + } + } + + return defaultValue; + } + +} diff --git a/tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java b/tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java new file mode 100644 index 0000000..e3778b1 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package android.view; + +import com.android.layoutlib.bridge.android.BridgeWindow; +import com.android.layoutlib.bridge.android.BridgeWindowSession; + +import android.os.Handler; +import android.view.View.AttachInfo; + +public class AttachInfo_Accessor { + + public static void setAttachInfo(View view) { + AttachInfo info = new AttachInfo(new BridgeWindowSession(), new BridgeWindow(), + new Handler(), null); + info.mHasWindowFocus = true; + info.mWindowVisibility = View.VISIBLE; + info.mInTouchMode = false; // this is so that we can display selections. + info.mHardwareAccelerated = false; + view.dispatchAttachedToWindow(info, 0); + } + + public static void dispatchOnPreDraw(View view) { + view.mAttachInfo.mTreeObserver.dispatchOnPreDraw(); + } +} diff --git a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java new file mode 100644 index 0000000..941f1ce6 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java @@ -0,0 +1,272 @@ +/* + * 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.view; + +import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.LayoutLog; +import com.android.ide.common.rendering.api.MergeCookie; +import com.android.ide.common.rendering.api.ResourceReference; +import com.android.ide.common.rendering.api.ResourceValue; +import com.android.layoutlib.bridge.Bridge; +import com.android.layoutlib.bridge.android.BridgeContext; +import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; +import com.android.layoutlib.bridge.impl.ParserFactory; +import com.android.resources.ResourceType; +import com.android.util.Pair; + +import org.xmlpull.v1.XmlPullParser; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.InflateException; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.io.File; + +/** + * Custom implementation of {@link LayoutInflater} to handle custom views. + */ +public final class BridgeInflater extends LayoutInflater { + + private final IProjectCallback mProjectCallback; + private boolean mIsInMerge = false; + private ResourceReference mResourceReference; + + /** + * List of class prefixes which are tried first by default. + *

+ * This should match the list in com.android.internal.policy.impl.PhoneLayoutInflater. + */ + private static final String[] sClassPrefixList = { + "android.widget.", + "android.webkit." + }; + + protected BridgeInflater(LayoutInflater original, Context newContext) { + super(original, newContext); + mProjectCallback = null; + } + + /** + * Instantiate a new BridgeInflater with an {@link IProjectCallback} object. + * + * @param context The Android application context. + * @param projectCallback the {@link IProjectCallback} object. + */ + public BridgeInflater(Context context, IProjectCallback projectCallback) { + super(context); + mProjectCallback = projectCallback; + mConstructorArgs[0] = context; + } + + @Override + public View onCreateView(String name, AttributeSet attrs) throws ClassNotFoundException { + View view = null; + + try { + // First try to find a class using the default Android prefixes + for (String prefix : sClassPrefixList) { + try { + view = createView(name, prefix, attrs); + if (view != null) { + break; + } + } catch (ClassNotFoundException e) { + // Ignore. We'll try again using the base class below. + } + } + + // Next try using the parent loader. This will most likely only work for + // fully-qualified class names. + try { + if (view == null) { + view = super.onCreateView(name, attrs); + } + } catch (ClassNotFoundException e) { + // Ignore. We'll try again using the custom view loader below. + } + + // Finally try again using the custom view loader + try { + if (view == null) { + view = loadCustomView(name, attrs); + } + } catch (ClassNotFoundException e) { + // If the class was not found, we throw the exception directly, because this + // method is already expected to throw it. + throw e; + } + } catch (Exception e) { + // Wrap the real exception in a ClassNotFoundException, so that the calling method + // can deal with it. + ClassNotFoundException exception = new ClassNotFoundException("onCreateView", e); + throw exception; + } + + setupViewInContext(view, attrs); + + return view; + } + + @Override + public View createViewFromTag(View parent, String name, AttributeSet attrs) { + View view = null; + try { + view = super.createViewFromTag(parent, name, attrs); + } catch (InflateException e) { + // try to load the class from using the custom view loader + try { + view = loadCustomView(name, attrs); + } catch (Exception e2) { + // Wrap the real exception in an InflateException so that the calling + // method can deal with it. + InflateException exception = new InflateException(); + if (e2.getClass().equals(ClassNotFoundException.class) == false) { + exception.initCause(e2); + } else { + exception.initCause(e); + } + throw exception; + } + } + + setupViewInContext(view, attrs); + + return view; + } + + @Override + public View inflate(int resource, ViewGroup root) { + Context context = getContext(); + if (context instanceof BridgeContext) { + BridgeContext bridgeContext = (BridgeContext)context; + + ResourceValue value = null; + + Pair layoutInfo = Bridge.resolveResourceId(resource); + if (layoutInfo != null) { + value = bridgeContext.getRenderResources().getFrameworkResource( + ResourceType.LAYOUT, layoutInfo.getSecond()); + } else { + layoutInfo = mProjectCallback.resolveResourceId(resource); + + if (layoutInfo != null) { + value = bridgeContext.getRenderResources().getProjectResource( + ResourceType.LAYOUT, layoutInfo.getSecond()); + } + } + + if (value != null) { + File f = new File(value.getValue()); + if (f.isFile()) { + try { + XmlPullParser parser = ParserFactory.create(f); + + BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser( + parser, bridgeContext, false); + + return inflate(bridgeParser, root); + } catch (Exception e) { + Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, + "Failed to parse file " + f.getAbsolutePath(), e, null /*data*/); + + return null; + } + } + } + } + return null; + } + + private View loadCustomView(String name, AttributeSet attrs) throws ClassNotFoundException, + Exception{ + if (mProjectCallback != null) { + // first get the classname in case it's not the node name + if (name.equals("view")) { + name = attrs.getAttributeValue(null, "class"); + } + + mConstructorArgs[1] = attrs; + + Object customView = mProjectCallback.loadView(name, mConstructorSignature, + mConstructorArgs); + + if (customView instanceof View) { + return (View)customView; + } + } + + return null; + } + + private void setupViewInContext(View view, AttributeSet attrs) { + if (getContext() instanceof BridgeContext) { + BridgeContext bc = (BridgeContext) getContext(); + if (attrs instanceof BridgeXmlBlockParser) { + BridgeXmlBlockParser parser = (BridgeXmlBlockParser) attrs; + + // get the view key + Object viewKey = parser.getViewCookie(); + + if (viewKey == null) { + int currentDepth = parser.getDepth(); + + // test whether we are in an included file or in a adapter binding view. + BridgeXmlBlockParser previousParser = bc.getPreviousParser(); + if (previousParser != null) { + // looks like we inside an embedded layout. + // only apply the cookie of the calling node () if we are at the + // top level of the embedded layout. If there is a merge tag, then + // skip it and look for the 2nd level + int testDepth = mIsInMerge ? 2 : 1; + if (currentDepth == testDepth) { + viewKey = previousParser.getViewCookie(); + // if we are in a merge, wrap the cookie in a MergeCookie. + if (viewKey != null && mIsInMerge) { + viewKey = new MergeCookie(viewKey); + } + } + } else if (mResourceReference != null && currentDepth == 1) { + // else if there's a resource reference, this means we are in an adapter + // binding case. Set the resource ref as the view cookie only for the top + // level view. + viewKey = mResourceReference; + } + } + + if (viewKey != null) { + bc.addViewKey(view, viewKey); + } + } + } + } + + public void setIsInMerge(boolean isInMerge) { + mIsInMerge = isInMerge; + } + + public void setResourceReference(ResourceReference reference) { + mResourceReference = reference; + } + + @Override + public LayoutInflater cloneInContext(Context newContext) { + return new BridgeInflater(this, newContext); + } +} diff --git a/tools/layoutlib/bridge/src/android/view/Display_Delegate.java b/tools/layoutlib/bridge/src/android/view/Display_Delegate.java index 83f9cc2..9732530 100644 --- a/tools/layoutlib/bridge/src/android/view/Display_Delegate.java +++ b/tools/layoutlib/bridge/src/android/view/Display_Delegate.java @@ -46,31 +46,17 @@ public class Display_Delegate { } @LayoutlibDelegate - /** @hide Returns the actual screen size, not including any decor. */ - /*package*/ static int getRealWidth(Display theDisplay) { - // always dynamically query for the current window manager - return RenderAction.getCurrentContext().getIWindowManager().getMetrics().widthPixels; - } - - @LayoutlibDelegate - /** @hide Returns the actual screen size, not including any decor. */ - /*package*/ static int getRealHeight(Display theDisplay) { - // always dynamically query for the current window manager - return RenderAction.getCurrentContext().getIWindowManager().getMetrics().heightPixels; - } - - @LayoutlibDelegate /** @hide special for when we are faking the screen size. */ /*package*/ static int getRawWidth(Display theDisplay) { // same as real since we're not faking compatibility mode. - return getRealWidth(theDisplay); + return RenderAction.getCurrentContext().getIWindowManager().getMetrics().widthPixels; } @LayoutlibDelegate /** @hide special for when we are faking the screen size. */ /*package*/ static int getRawHeight(Display theDisplay) { // same as real since we're not faking compatibility mode. - return getRealHeight(theDisplay); + return RenderAction.getCurrentContext().getIWindowManager().getMetrics().heightPixels; } @LayoutlibDelegate diff --git a/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java b/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java index 64efa7e..3db3a1b 100644 --- a/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java +++ b/tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java @@ -16,7 +16,6 @@ package android.view; -import com.android.layoutlib.bridge.android.BridgeInflater; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import org.xmlpull.v1.XmlPullParser; diff --git a/tools/layoutlib/bridge/src/android/view/ViewConfiguration_Accessor.java b/tools/layoutlib/bridge/src/android/view/ViewConfiguration_Accessor.java new file mode 100644 index 0000000..01db34e --- /dev/null +++ b/tools/layoutlib/bridge/src/android/view/ViewConfiguration_Accessor.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package android.view; + +public class ViewConfiguration_Accessor { + + public static void clearConfigurations() { + // clear the stored ViewConfiguration since the map is per density and not per context. + ViewConfiguration.sConfigurations.clear(); + } + +} diff --git a/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java b/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java new file mode 100644 index 0000000..875336a --- /dev/null +++ b/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +package android.view.inputmethod; + +public class InputMethodManager_Accessor { + + public static void resetInstance() { + InputMethodManager.mInstance = null; + } +} diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java index 3ba3257..33bf7bc 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java @@ -26,7 +26,6 @@ import com.android.ide.common.rendering.api.RenderSession; import com.android.ide.common.rendering.api.Result; import com.android.ide.common.rendering.api.SessionParams; import com.android.ide.common.rendering.api.Result.Status; -import com.android.layoutlib.bridge.android.BridgeAssetManager; import com.android.layoutlib.bridge.impl.FontLoader; import com.android.layoutlib.bridge.impl.RenderDrawable; import com.android.layoutlib.bridge.impl.RenderSessionImpl; @@ -36,10 +35,12 @@ import com.android.tools.layoutlib.create.MethodAdapter; import com.android.tools.layoutlib.create.OverrideMethod; import com.android.util.Pair; +import android.content.res.BridgeAssetManager; import android.graphics.Bitmap; -import android.graphics.Typeface; +import android.graphics.Typeface_Accessor; import android.graphics.Typeface_Delegate; import android.os.Looper; +import android.os.Looper_Accessor; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; @@ -295,7 +296,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { BridgeAssetManager.clearSystem(); // dispose of the default typeface. - Typeface.sDefaults = null; + Typeface_Accessor.resetDefaults(); return true; } @@ -429,7 +430,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { */ public static void cleanupThread() { // clean up the looper - Looper.sThreadLocal.remove(); + Looper_Accessor.cleanupThread(); } public static LayoutLog getLog() { diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeAssetManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeAssetManager.java deleted file mode 100644 index a825060..0000000 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeAssetManager.java +++ /dev/null @@ -1,53 +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.android; - -import com.android.layoutlib.bridge.Bridge; - -import android.content.res.AssetManager; - -public class BridgeAssetManager extends AssetManager { - - /** - * This initializes the static field {@link AssetManager#mSystem} which is used - * by methods who get a global asset manager using {@link AssetManager#getSystem()}. - *

- * They will end up using our bridge asset manager. - *

- * {@link Bridge} calls this method after setting up a new bridge. - */ - /*package*/ public static AssetManager initSystem() { - if (!(AssetManager.sSystem instanceof BridgeAssetManager)) { - // Note that AssetManager() creates a system AssetManager and we override it - // with our BridgeAssetManager. - AssetManager.sSystem = new BridgeAssetManager(); - AssetManager.sSystem.makeStringBlocks(false); - } - return AssetManager.sSystem; - } - - /** - * Clears the static {@link AssetManager#sSystem} to make sure we don't leave objects - * around that would prevent us from unloading the library. - */ - public static void clearSystem() { - AssetManager.sSystem = null; - } - - private BridgeAssetManager() { - } -} 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 b38b3b8..0453a5e 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 @@ -33,8 +33,6 @@ import com.android.util.Pair; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import android.app.Activity; -import android.app.Fragment; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; @@ -65,7 +63,7 @@ import android.os.Looper; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.TypedValue; -import android.view.LayoutInflater; +import android.view.BridgeInflater; import android.view.Surface; import android.view.View; import android.view.ViewGroup; @@ -87,7 +85,7 @@ import java.util.concurrent.atomic.AtomicReference; /** * Custom implementation of Context/Activity to handle non compiled resources. */ -public final class BridgeContext extends Activity { +public final class BridgeContext extends Context { private Resources mSystemResources; private final HashMap mViewKeyMap = new HashMap(); @@ -97,9 +95,10 @@ public final class BridgeContext extends Activity { private final Configuration mConfig; private final ApplicationInfo mApplicationInfo; private final IProjectCallback mProjectCallback; - private final BridgeWindowManager mIWindowManager; + private Resources.Theme mTheme; + private final Map> mDefaultPropMaps = new IdentityHashMap>(); @@ -139,9 +138,6 @@ public final class BridgeContext extends Activity { mIWindowManager = new BridgeWindowManager(mConfig, metrics, Surface.ROTATION_0); - mFragments.mCurState = Fragment.CREATED; - mFragments.mActivity = this; - mApplicationInfo = new ApplicationInfo(); mApplicationInfo.targetSdkVersion = targetSdkVersion; } @@ -395,13 +391,6 @@ public final class BridgeContext extends Activity { return Pair.of(null, false); } - // ------------- Activity Methods - - @Override - public LayoutInflater getLayoutInflater() { - return mBridgeInflater; - } - // ------------ Context methods @Override @@ -1275,7 +1264,7 @@ public final class BridgeContext extends Activity { @Override public Context getApplicationContext() { - throw new UnsupportedOperationException(); + return this; } @Override @@ -1288,4 +1277,10 @@ public final class BridgeContext extends Activity { public boolean isRestricted() { return false; } + + @Override + public File getObbDir() { + Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED, "OBB not supported", null); + return null; + } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java deleted file mode 100644 index 4a6393d..0000000 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java +++ /dev/null @@ -1,270 +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.android; - -import com.android.ide.common.rendering.api.IProjectCallback; -import com.android.ide.common.rendering.api.LayoutLog; -import com.android.ide.common.rendering.api.MergeCookie; -import com.android.ide.common.rendering.api.ResourceReference; -import com.android.ide.common.rendering.api.ResourceValue; -import com.android.layoutlib.bridge.Bridge; -import com.android.layoutlib.bridge.impl.ParserFactory; -import com.android.resources.ResourceType; -import com.android.util.Pair; - -import org.xmlpull.v1.XmlPullParser; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.InflateException; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import java.io.File; - -/** - * Custom implementation of {@link LayoutInflater} to handle custom views. - */ -public final class BridgeInflater extends LayoutInflater { - - private final IProjectCallback mProjectCallback; - private boolean mIsInMerge = false; - private ResourceReference mResourceReference; - - /** - * List of class prefixes which are tried first by default. - *

- * This should match the list in com.android.internal.policy.impl.PhoneLayoutInflater. - */ - private static final String[] sClassPrefixList = { - "android.widget.", - "android.webkit." - }; - - protected BridgeInflater(LayoutInflater original, Context newContext) { - super(original, newContext); - mProjectCallback = null; - } - - /** - * Instantiate a new BridgeInflater with an {@link IProjectCallback} object. - * - * @param context The Android application context. - * @param projectCallback the {@link IProjectCallback} object. - */ - public BridgeInflater(Context context, IProjectCallback projectCallback) { - super(context); - mProjectCallback = projectCallback; - mConstructorArgs[0] = context; - } - - @Override - public View onCreateView(String name, AttributeSet attrs) throws ClassNotFoundException { - View view = null; - - try { - // First try to find a class using the default Android prefixes - for (String prefix : sClassPrefixList) { - try { - view = createView(name, prefix, attrs); - if (view != null) { - break; - } - } catch (ClassNotFoundException e) { - // Ignore. We'll try again using the base class below. - } - } - - // Next try using the parent loader. This will most likely only work for - // fully-qualified class names. - try { - if (view == null) { - view = super.onCreateView(name, attrs); - } - } catch (ClassNotFoundException e) { - // Ignore. We'll try again using the custom view loader below. - } - - // Finally try again using the custom view loader - try { - if (view == null) { - view = loadCustomView(name, attrs); - } - } catch (ClassNotFoundException e) { - // If the class was not found, we throw the exception directly, because this - // method is already expected to throw it. - throw e; - } - } catch (Exception e) { - // Wrap the real exception in a ClassNotFoundException, so that the calling method - // can deal with it. - ClassNotFoundException exception = new ClassNotFoundException("onCreateView", e); - throw exception; - } - - setupViewInContext(view, attrs); - - return view; - } - - @Override - public View createViewFromTag(View parent, String name, AttributeSet attrs) { - View view = null; - try { - view = super.createViewFromTag(parent, name, attrs); - } catch (InflateException e) { - // try to load the class from using the custom view loader - try { - view = loadCustomView(name, attrs); - } catch (Exception e2) { - // Wrap the real exception in an InflateException so that the calling - // method can deal with it. - InflateException exception = new InflateException(); - if (e2.getClass().equals(ClassNotFoundException.class) == false) { - exception.initCause(e2); - } else { - exception.initCause(e); - } - throw exception; - } - } - - setupViewInContext(view, attrs); - - return view; - } - - @Override - public View inflate(int resource, ViewGroup root) { - Context context = getContext(); - if (context instanceof BridgeContext) { - BridgeContext bridgeContext = (BridgeContext)context; - - ResourceValue value = null; - - Pair layoutInfo = Bridge.resolveResourceId(resource); - if (layoutInfo != null) { - value = bridgeContext.getRenderResources().getFrameworkResource( - ResourceType.LAYOUT, layoutInfo.getSecond()); - } else { - layoutInfo = mProjectCallback.resolveResourceId(resource); - - if (layoutInfo != null) { - value = bridgeContext.getRenderResources().getProjectResource( - ResourceType.LAYOUT, layoutInfo.getSecond()); - } - } - - if (value != null) { - File f = new File(value.getValue()); - if (f.isFile()) { - try { - XmlPullParser parser = ParserFactory.create(f); - - BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser( - parser, bridgeContext, false); - - return inflate(bridgeParser, root); - } catch (Exception e) { - Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, - "Failed to parse file " + f.getAbsolutePath(), e, null /*data*/); - - return null; - } - } - } - } - return null; - } - - private View loadCustomView(String name, AttributeSet attrs) throws ClassNotFoundException, - Exception{ - if (mProjectCallback != null) { - // first get the classname in case it's not the node name - if (name.equals("view")) { - name = attrs.getAttributeValue(null, "class"); - } - - mConstructorArgs[1] = attrs; - - Object customView = mProjectCallback.loadView(name, mConstructorSignature, - mConstructorArgs); - - if (customView instanceof View) { - return (View)customView; - } - } - - return null; - } - - private void setupViewInContext(View view, AttributeSet attrs) { - if (getContext() instanceof BridgeContext) { - BridgeContext bc = (BridgeContext) getContext(); - if (attrs instanceof BridgeXmlBlockParser) { - BridgeXmlBlockParser parser = (BridgeXmlBlockParser) attrs; - - // get the view key - Object viewKey = parser.getViewCookie(); - - if (viewKey == null) { - int currentDepth = parser.getDepth(); - - // test whether we are in an included file or in a adapter binding view. - BridgeXmlBlockParser previousParser = bc.getPreviousParser(); - if (previousParser != null) { - // looks like we inside an embedded layout. - // only apply the cookie of the calling node () if we are at the - // top level of the embedded layout. If there is a merge tag, then - // skip it and look for the 2nd level - int testDepth = mIsInMerge ? 2 : 1; - if (currentDepth == testDepth) { - viewKey = previousParser.getViewCookie(); - // if we are in a merge, wrap the cookie in a MergeCookie. - if (viewKey != null && mIsInMerge) { - viewKey = new MergeCookie(viewKey); - } - } - } else if (mResourceReference != null && currentDepth == 1) { - // else if there's a resource reference, this means we are in an adapter - // binding case. Set the resource ref as the view cookie only for the top - // level view. - viewKey = mResourceReference; - } - } - - if (viewKey != null) { - bc.addViewKey(view, viewKey); - } - } - } - } - - public void setIsInMerge(boolean isInMerge) { - mIsInMerge = isInMerge; - } - - public void setResourceReference(ResourceReference reference) { - mResourceReference = reference; - } - - @Override - public LayoutInflater cloneInContext(Context newContext) { - return new BridgeInflater(this, newContext); - } -} diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java index a8da377..8e673ad 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindow.java @@ -26,10 +26,9 @@ import android.view.DragEvent; import android.view.IWindow; import android.view.KeyEvent; import android.view.MotionEvent; -import android.view.View.AttachInfo; /** - * Implementation of {@link IWindow} to pass to the {@link AttachInfo}. + * Implementation of {@link IWindow} to pass to the AttachInfo. */ public final class BridgeWindow implements IWindow { diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowManager.java index 5952c37..7d83a9f 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowManager.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeWindowManager.java @@ -456,9 +456,7 @@ public class BridgeWindowManager implements IWindowManager { return null; } - @Override public int getPreferredOptionsPanelGravity() throws RemoteException { return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; } - } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java index 1016b32..f8ed4f7 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java @@ -25,7 +25,7 @@ import org.xmlpull.v1.XmlPullParserException; import android.content.res.XmlResourceParser; import android.util.AttributeSet; -import android.util.XmlPullAttributes; +import android.util.BridgeXmlPullAttributes; import java.io.IOException; import java.io.InputStream; @@ -34,12 +34,12 @@ import java.io.Reader; /** * {@link BridgeXmlBlockParser} reimplements most of android.xml.XmlBlock.Parser. * It delegates to both an instance of {@link XmlPullParser} and an instance of - * {@link XmlPullAttributes} (for the {@link AttributeSet} part). + * XmlPullAttributes (for the {@link AttributeSet} part). */ public class BridgeXmlBlockParser implements XmlResourceParser { private final XmlPullParser mParser; - private final XmlPullAttributes mAttrib; + private final BridgeXmlPullAttributes mAttrib; private final BridgeContext mContext; private final boolean mPlatformFile; diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java deleted file mode 100644 index ba856e0..0000000 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java +++ /dev/null @@ -1,127 +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.android; - -import com.android.ide.common.rendering.api.RenderResources; -import com.android.ide.common.rendering.api.ResourceValue; -import com.android.layoutlib.bridge.Bridge; -import com.android.layoutlib.bridge.BridgeConstants; -import com.android.resources.ResourceType; - -import org.xmlpull.v1.XmlPullParser; - -import android.util.AttributeSet; -import android.util.XmlPullAttributes; - -/** - * A correct implementation of the {@link AttributeSet} interface on top of a XmlPullParser - */ -public class BridgeXmlPullAttributes extends XmlPullAttributes { - - private final BridgeContext mContext; - private final boolean mPlatformFile; - - public BridgeXmlPullAttributes(XmlPullParser parser, BridgeContext context, - boolean platformFile) { - super(parser); - mContext = context; - mPlatformFile = platformFile; - } - - /* - * (non-Javadoc) - * @see android.util.XmlPullAttributes#getAttributeNameResource(int) - * - * This methods must return com.android.internal.R.attr. matching - * the name of the attribute. - * It returns 0 if it doesn't find anything. - */ - @Override - public int getAttributeNameResource(int index) { - // get the attribute name. - String name = getAttributeName(index); - - // get the attribute namespace - String ns = mParser.getAttributeNamespace(index); - - if (BridgeConstants.NS_RESOURCES.equals(ns)) { - Integer v = Bridge.getResourceId(ResourceType.ATTR, name); - if (v != null) { - return v.intValue(); - } - - return 0; - } - - // 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 (v != null) { - return v.intValue(); - } - } - - return 0; - } - - /* - * (non-Javadoc) - * @see android.util.XmlPullAttributes#getAttributeResourceValue(int, int) - */ - @Override - public int getAttributeResourceValue(int index, int defaultValue) { - String value = getAttributeValue(index); - - return resolveResourceValue(value, defaultValue); - } - - /* - * (non-Javadoc) - * @see android.util.XmlPullAttributes#getAttributeResourceValue(java.lang.String, java.lang.String, int) - */ - @Override - public int getAttributeResourceValue(String namespace, String attribute, int defaultValue) { - String value = getAttributeValue(namespace, attribute); - - return resolveResourceValue(value, defaultValue); - } - - private int resolveResourceValue(String value, int defaultValue) { - // now look for this particular value - RenderResources resources = mContext.getRenderResources(); - ResourceValue resource = resources.resolveResValue( - resources.findResValue(value, mPlatformFile)); - - if (resource != null) { - Integer id = null; - if (mPlatformFile || resource.isFramework()) { - id = Bridge.getResourceId(resource.getResourceType(), resource.getName()); - } else { - id = mContext.getProjectCallback().getResourceId( - resource.getResourceType(), resource.getName()); - } - - if (id != null) { - return id; - } - } - - return defaultValue; - } - -} diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/PhoneSystemBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/PhoneSystemBar.java index 5569e06..7521011 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/PhoneSystemBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/PhoneSystemBar.java @@ -32,7 +32,8 @@ public class PhoneSystemBar extends CustomBar { public PhoneSystemBar(Context context, Density density) throws XmlPullParserException { super(context, density, "/bars/phone_system_bar.xml", "phone_system_bar.xml"); - setGravity(mGravity | Gravity.RIGHT); + // FIXME: use FILL_H? + setGravity(Gravity.START | Gravity.TOP | Gravity.RIGHT); setBackgroundColor(0xFF000000); // Cannot access the inside items through id because no R.id values have been diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java deleted file mode 100644 index 4c18656..0000000 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * 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.impl; - -import com.android.ide.common.rendering.api.IAnimationListener; -import com.android.ide.common.rendering.api.RenderSession; -import com.android.ide.common.rendering.api.Result; -import com.android.ide.common.rendering.api.Result.Status; -import com.android.layoutlib.bridge.Bridge; - -import android.animation.ValueAnimator; -import android.os.Handler; -import android.os.Handler_Delegate; -import android.os.Message; -import android.os.Handler_Delegate.IHandlerCallback; - -import java.util.PriorityQueue; -import java.util.Queue; - -/** - * Abstract animation thread. - *

- * This does not actually start an animation, instead it fakes a looper that will play whatever - * animation is sending messages to its own {@link Handler}. - *

- * Classes should implement {@link #preAnimation()} and {@link #postAnimation()}. - *

- * If {@link #preAnimation()} does not start an animation somehow then the thread doesn't do - * anything. - * - */ -public abstract class AnimationThread extends Thread { - - private static class MessageBundle implements Comparable { - final Handler mTarget; - final Message mMessage; - final long mUptimeMillis; - - MessageBundle(Handler target, Message message, long uptimeMillis) { - mTarget = target; - mMessage = message; - mUptimeMillis = uptimeMillis; - } - - public int compareTo(MessageBundle bundle) { - if (mUptimeMillis < bundle.mUptimeMillis) { - return -1; - } - return 1; - } - } - - private final RenderSessionImpl mSession; - - private Queue mQueue = new PriorityQueue(); - private final IAnimationListener mListener; - - public AnimationThread(RenderSessionImpl scene, String threadName, - IAnimationListener listener) { - super(threadName); - mSession = scene; - mListener = listener; - } - - public abstract Result preAnimation(); - public abstract void postAnimation(); - - @Override - public void run() { - Bridge.prepareThread(); - try { - Handler_Delegate.setCallback(new IHandlerCallback() { - public void sendMessageAtTime(Handler handler, Message msg, long uptimeMillis) { - if (msg.what == ValueAnimator.ANIMATION_START || - msg.what == ValueAnimator.ANIMATION_FRAME) { - mQueue.add(new MessageBundle(handler, msg, uptimeMillis)); - } else { - // just ignore. - } - } - }); - - // call out to the pre-animation work, which should start an animation or more. - Result result = preAnimation(); - if (result.isSuccess() == false) { - mListener.done(result); - } - - // loop the animation - RenderSession session = mSession.getSession(); - do { - // check early. - if (mListener.isCanceled()) { - break; - } - - // get the next message. - MessageBundle bundle = mQueue.poll(); - if (bundle == null) { - break; - } - - // sleep enough for this bundle to be on time - long currentTime = System.currentTimeMillis(); - if (currentTime < bundle.mUptimeMillis) { - try { - sleep(bundle.mUptimeMillis - currentTime); - } catch (InterruptedException e) { - // FIXME log/do something/sleep again? - e.printStackTrace(); - } - } - - // check after sleeping. - if (mListener.isCanceled()) { - break; - } - - // ready to do the work, acquire the scene. - result = mSession.acquire(250); - if (result.isSuccess() == false) { - mListener.done(result); - return; - } - - // process the bundle. If the animation is not finished, this will enqueue - // the next message, so mQueue will have another one. - try { - // check after acquiring in case it took a while. - if (mListener.isCanceled()) { - break; - } - - bundle.mTarget.handleMessage(bundle.mMessage); - if (mSession.render(false /*freshRender*/).isSuccess()) { - mListener.onNewFrame(session); - } - } finally { - mSession.release(); - } - } while (mListener.isCanceled() == false && mQueue.size() > 0); - - mListener.done(Status.SUCCESS.createResult()); - - } catch (Throwable throwable) { - // can't use Bridge.getLog() as the exception might be thrown outside - // of an acquire/release block. - mListener.done(Status.ERROR_UNKNOWN.createResult("Error playing animation", throwable)); - - } finally { - postAnimation(); - Handler_Delegate.setCallback(null); - Bridge.cleanupThread(); - } - } -} diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java index 35e5987..7b70180 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java @@ -20,6 +20,7 @@ import com.android.ide.common.rendering.api.IAnimationListener; import com.android.ide.common.rendering.api.Result; import com.android.ide.common.rendering.api.Result.Status; +import android.animation.AnimationThread; import android.animation.Animator; public class PlayAnimationThread extends AnimationThread { 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 d40222f..7323c6a 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 @@ -35,8 +35,9 @@ import android.content.res.Configuration; import android.os.HandlerThread_Delegate; import android.os.Looper; import android.util.DisplayMetrics; -import android.view.ViewConfiguration; +import android.view.ViewConfiguration_Accessor; import android.view.inputmethod.InputMethodManager; +import android.view.inputmethod.InputMethodManager_Accessor; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; @@ -248,10 +249,10 @@ public abstract class RenderAction extends FrameworkReso HandlerThread_Delegate.cleanUp(sCurrentContext); // clear the stored ViewConfiguration since the map is per density and not per context. - ViewConfiguration.sConfigurations.clear(); + ViewConfiguration_Accessor.clearConfigurations(); // remove the InputMethodManager - InputMethodManager.mInstance = null; + InputMethodManager_Accessor.resetInstance(); sCurrentContext = null; diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderDrawable.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderDrawable.java index 953d8cf..8133210 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderDrawable.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderDrawable.java @@ -23,17 +23,13 @@ import com.android.ide.common.rendering.api.ResourceValue; import com.android.ide.common.rendering.api.Result; import com.android.ide.common.rendering.api.Result.Status; import com.android.layoutlib.bridge.android.BridgeContext; -import com.android.layoutlib.bridge.android.BridgeWindow; -import com.android.layoutlib.bridge.android.BridgeWindowSession; import com.android.resources.ResourceType; import android.graphics.Bitmap; import android.graphics.Bitmap_Delegate; import android.graphics.Canvas; import android.graphics.drawable.Drawable; -import android.os.Handler; -import android.view.View; -import android.view.View.AttachInfo; +import android.view.AttachInfo_Accessor; import android.view.View.MeasureSpec; import android.widget.FrameLayout; @@ -82,13 +78,7 @@ public class RenderDrawable extends RenderAction { content.setBackgroundDrawable(d); // set the AttachInfo on the root view. - AttachInfo info = new AttachInfo(new BridgeWindowSession(), new BridgeWindow(), - new Handler(), null); - info.mHasWindowFocus = true; - info.mWindowVisibility = View.VISIBLE; - info.mInTouchMode = false; // this is so that we can display selections. - info.mHardwareAccelerated = false; - content.dispatchAttachedToWindow(info, 0); + AttachInfo_Accessor.setAttachInfo(content); // measure @@ -102,7 +92,7 @@ public class RenderDrawable extends RenderAction { content.layout(0, 0, w, h); // preDraw setup - content.mAttachInfo.mTreeObserver.dispatchOnPreDraw(); + AttachInfo_Accessor.dispatchOnPreDraw(content); // draw into a new image BufferedImage image = getImage(w, h); 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 aa30e29..d5400d7 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 @@ -40,10 +40,7 @@ import com.android.ide.common.rendering.api.SessionParams.RenderingMode; import com.android.internal.util.XmlUtils; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.android.BridgeContext; -import com.android.layoutlib.bridge.android.BridgeInflater; import com.android.layoutlib.bridge.android.BridgeLayoutParamsMapAttributes; -import com.android.layoutlib.bridge.android.BridgeWindow; -import com.android.layoutlib.bridge.android.BridgeWindowSession; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; import com.android.layoutlib.bridge.bars.FakeActionBar; import com.android.layoutlib.bridge.bars.PhoneSystemBar; @@ -57,6 +54,7 @@ import com.android.util.Pair; import org.xmlpull.v1.XmlPullParserException; +import android.animation.AnimationThread; import android.animation.Animator; import android.animation.AnimatorInflater; import android.animation.LayoutTransition; @@ -66,12 +64,12 @@ import android.graphics.Bitmap; import android.graphics.Bitmap_Delegate; import android.graphics.Canvas; import android.graphics.drawable.Drawable; -import android.os.Handler; import android.util.DisplayMetrics; import android.util.TypedValue; +import android.view.AttachInfo_Accessor; +import android.view.BridgeInflater; import android.view.View; import android.view.ViewGroup; -import android.view.View.AttachInfo; import android.view.View.MeasureSpec; import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.MarginLayoutParams; @@ -190,7 +188,6 @@ public class RenderSessionImpl extends RenderAction { // build the inflater and parser. mInflater = new BridgeInflater(context, params.getProjectCallback()); context.setBridgeInflater(mInflater); - mInflater.setFactory2(context); mBlockParser = new BridgeXmlBlockParser( params.getLayoutDescription(), context, false /* platformResourceFlag */); @@ -329,13 +326,7 @@ public class RenderSessionImpl extends RenderAction { Fragment_Delegate.setProjectCallback(null); // set the AttachInfo on the root view. - AttachInfo info = new AttachInfo(new BridgeWindowSession(), new BridgeWindow(), - new Handler(), null); - info.mHasWindowFocus = true; - info.mWindowVisibility = View.VISIBLE; - info.mInTouchMode = false; // this is so that we can display selections. - info.mHardwareAccelerated = false; - mViewRoot.dispatchAttachedToWindow(info, 0); + AttachInfo_Accessor.setAttachInfo(mViewRoot); // post-inflate process. For now this supports TabHost/TabWidget postInflateProcess(view, params.getProjectCallback()); @@ -462,7 +453,7 @@ public class RenderSessionImpl extends RenderAction { mImage = null; mCanvas = null; } else { - mViewRoot.mAttachInfo.mTreeObserver.dispatchOnPreDraw(); + AttachInfo_Accessor.dispatchOnPreDraw(mViewRoot); // draw the views // create the BufferedImage into which the layout will be rendered. diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java index 7c02f7e..0a15627 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java @@ -95,10 +95,11 @@ public final class CreateInfo implements ICreateInfo { /** * The list of methods to rewrite as delegates. */ - private final static String[] DELEGATE_METHODS = new String[] { + public final static String[] DELEGATE_METHODS = new String[] { "android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;", "android.content.res.Resources$Theme#obtainStyledAttributes", "android.content.res.Resources$Theme#resolveAttribute", + "android.content.res.TypedArray#getValueAt", "android.graphics.BitmapFactory#finishDecode", "android.os.Handler#sendMessageAtTime", "android.os.HandlerThread#run", @@ -116,7 +117,7 @@ public final class CreateInfo implements ICreateInfo { /** * The list of classes on which to delegate all native methods. */ - private final static String[] DELEGATE_CLASS_NATIVES = new String[] { + public final static String[] DELEGATE_CLASS_NATIVES = new String[] { "android.animation.PropertyValuesHolder", "android.graphics.AvoidXfermode", "android.graphics.Bitmap", diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java index b027b6a..4b7a348 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java @@ -165,6 +165,8 @@ public class Main { return false; } + sOptions.generatePublicAccess = false; + return true; } } -- cgit v1.1