diff options
author | Xavier Ducrohet <xav@android.com> | 2011-08-11 10:16:17 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2011-08-11 12:57:51 -0700 |
commit | 7f9f99ea11051614a7727dfb9f9578b518e76e3c (patch) | |
tree | d39b916bb092a717e028345813b53f6bcfa12f61 /tools/layoutlib | |
parent | 7277f3b9b26f0011475b39da1298484a510aca29 (diff) | |
download | frameworks_base-7f9f99ea11051614a7727dfb9f9578b518e76e3c.zip frameworks_base-7f9f99ea11051614a7727dfb9f9578b518e76e3c.tar.gz frameworks_base-7f9f99ea11051614a7727dfb9f9578b518e76e3c.tar.bz2 |
Make some methods/fields package private so that layoutlib can access them.
Change-Id: I4aeadfbaf8a4f6a459fa19937c21ac23d9e5fb64
Diffstat (limited to 'tools/layoutlib')
28 files changed, 324 insertions, 139 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java b/tools/layoutlib/bridge/src/android/animation/AnimationThread.java index 4c18656..2b5e4fa 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java +++ b/tools/layoutlib/bridge/src/android/animation/AnimationThread.java @@ -14,13 +14,14 @@ * limitations under the License. */ -package com.android.layoutlib.bridge.impl; +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; diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeAssetManager.java b/tools/layoutlib/bridge/src/android/content/res/BridgeAssetManager.java index a825060..a953918 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeAssetManager.java +++ b/tools/layoutlib/bridge/src/android/content/res/BridgeAssetManager.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.layoutlib.bridge.android; +package android.content.res; import com.android.layoutlib.bridge.Bridge; @@ -30,7 +30,7 @@ public class BridgeAssetManager extends AssetManager { * <p/> * {@link Bridge} calls this method after setting up a new bridge. */ - /*package*/ public static AssetManager initSystem() { + public static AssetManager initSystem() { if (!(AssetManager.sSystem instanceof BridgeAssetManager)) { // Note that AssetManager() creates a system AssetManager and we override it // with our 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<String, ResourceValue> 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<String, ResourceValue> 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<String, ResourceValue> 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<String, ResourceValue> 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<String, ResourceValue> 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<String, ResourceValue> 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/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java index ba856e0..0a3cdc6 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java +++ b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package com.android.layoutlib.bridge.android; +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; 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/com/android/layoutlib/bridge/android/BridgeInflater.java b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java index 4a6393d..941f1ce6 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java +++ b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.layoutlib.bridge.android; +package android.view; import com.android.ide.common.rendering.api.IProjectCallback; import com.android.ide.common.rendering.api.LayoutLog; @@ -22,6 +22,8 @@ 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; 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/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<View, Object> mViewKeyMap = new HashMap<View, Object>(); @@ -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<Object, Map<String, String>> mDefaultPropMaps = new IdentityHashMap<Object, Map<String,String>>(); @@ -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/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/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/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<T extends RenderParams> 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<DrawableParams> { 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<DrawableParams> { 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<SessionParams> { // 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<SessionParams> { 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<SessionParams> { 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; } } |