From 071dee288ca726c7c15754c2559403b9cbf950bd Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Thu, 11 Nov 2010 14:19:29 -0800 Subject: [PATCH] Misc fix in layoutlib bridge + View.isIneditMode as delegate. Change-Id: Ideab29167e933203da99d4270cebcb777726201f --- .../src/android/view/View_Delegate.java | 31 +++++++++++++++++++ .../com/android/layoutlib/bridge/Bridge.java | 14 --------- .../bridge/android/BridgeContext.java | 23 +++++--------- .../bridge/android/BridgeTypedArray.java | 2 -- .../bridge/android/BridgeWindow.java | 3 +- .../bridge/impl/TempResourceValue.java | 4 +-- ...NativeDelegate.java => TestDelegates.java} | 19 ++++++++++-- .../tools/layoutlib/create/CreateInfo.java | 4 +-- 8 files changed, 61 insertions(+), 39 deletions(-) create mode 100644 tools/layoutlib/bridge/src/android/view/View_Delegate.java rename tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/{TestNativeDelegate.java => TestDelegates.java} (88%) diff --git a/tools/layoutlib/bridge/src/android/view/View_Delegate.java b/tools/layoutlib/bridge/src/android/view/View_Delegate.java new file mode 100644 index 0000000000000..ee6694c843c67 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/view/View_Delegate.java @@ -0,0 +1,31 @@ +/* + * 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.view; + +/** + * Delegate used to provide new implementation of a select few methods of {@link View} + * + * Through the layoutlib_create tool, the original methods of View have been replaced + * by calls to methods of the same name in this delegate class. + * + */ +public class View_Delegate { + + /*package*/ static boolean isInEditMode(View thisView) { + return true; + } +} 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 d2092d1141cee..53da2ca0cbf1f 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java @@ -157,20 +157,6 @@ public final class Bridge extends LayoutBridge { }); } - // Override View.isInEditMode to return true. - // - // This allows custom views that are drawn in the Graphical Layout Editor to adapt their - // rendering for preview. Most important this let custom views know that they can't expect - // the rest of their activities to be alive. - OverrideMethod.setMethodListener("android.view.View#isInEditMode()Z", - new MethodAdapter() { - @Override - public int onInvokeI(String signature, boolean isNative, Object caller) { - return 1; - } - } - ); - // load the fonts. FontLoader fontLoader = FontLoader.create(fontOsLocation); if (fontLoader != null) { 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 2fa97a3862788..79aecffab3a00 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 @@ -1111,25 +1111,20 @@ public final class BridgeContext extends Activity { } - @SuppressWarnings("unused") @Override - public FileInputStream openFileInput(String arg0) - throws FileNotFoundException { - // TODO Auto-generated method stub - return null; - } - - @SuppressWarnings("unused") - @Override - public FileOutputStream openFileOutput(String arg0, int arg1) - throws FileNotFoundException { + public FileInputStream openFileInput(String arg0) throws FileNotFoundException { // TODO Auto-generated method stub return null; } @Override - public SQLiteDatabase openOrCreateDatabase(String arg0, int arg1, - CursorFactory arg2) { + public FileOutputStream openFileOutput(String arg0, int arg1) throws FileNotFoundException { + // TODO Auto-generated method stub + return null; + } + + @Override + public SQLiteDatabase openOrCreateDatabase(String arg0, int arg1, CursorFactory arg2) { // TODO Auto-generated method stub return null; } @@ -1217,14 +1212,12 @@ public final class BridgeContext extends Activity { } - @SuppressWarnings("unused") @Override public void setWallpaper(Bitmap arg0) throws IOException { // TODO Auto-generated method stub } - @SuppressWarnings("unused") @Override public void setWallpaper(InputStream arg0) throws IOException { // TODO Auto-generated method stub diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java index c3ab461762f8e..c8dc9e6274819 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java @@ -43,10 +43,8 @@ import java.util.Map; */ public final class BridgeTypedArray extends TypedArray { - @SuppressWarnings("hiding") private BridgeResources mResources; private BridgeContext mContext; - @SuppressWarnings("hiding") private IResourceValue[] mData; private String[] mNames; private final boolean mPlatformFile; 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 c04c9e8670691..4a7ab58de8ebd 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 @@ -49,7 +49,8 @@ public final class BridgeWindow implements IWindow { // pass for now. } - public void dispatchTrackball(MotionEvent arg0, long arg1, boolean arg2) throws RemoteException { + public void dispatchTrackball(MotionEvent arg0, long arg1, boolean arg2) + throws RemoteException { // pass for now. } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/TempResourceValue.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/TempResourceValue.java index 4ab98ce5afc00..a3c5826241204 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/TempResourceValue.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/TempResourceValue.java @@ -16,14 +16,14 @@ package com.android.layoutlib.bridge.impl; -import com.android.layoutlib.api.ILayoutBridge; import com.android.layoutlib.api.IResourceValue; +import com.android.layoutlib.api.LayoutBridge; /** * Basic implementation of IResourceValue for when it is needed to dynamically make a new * {@link IResourceValue} object. * - * Most of the time, implementations of IResourceValue come through the {@link ILayoutBridge} + * Most of the time, implementations of IResourceValue come through the {@link LayoutBridge} * API. */ public class TempResourceValue implements IResourceValue { diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestNativeDelegate.java b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestDelegates.java similarity index 88% rename from tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestNativeDelegate.java rename to tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestDelegates.java index a86b5c91bb02d..23b7e9414a419 100644 --- a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestNativeDelegate.java +++ b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestDelegates.java @@ -37,9 +37,9 @@ import junit.framework.TestCase; * include the original class as first parameter (to access "this"). * */ -public class TestNativeDelegate extends TestCase { +public class TestDelegates extends TestCase { - public void testNativeDelegates() { + public void testNativeDelegates() { final String[] classes = CreateInfo.DELEGATE_CLASS_NATIVES; final int count = classes.length; @@ -48,10 +48,23 @@ public class TestNativeDelegate extends TestCase { } } + public void testMethodDelegates() { + final String[] methods = CreateInfo.DELEGATE_METHODS; + final int count = methods.length; + for (int i = 0 ; i < count ; i++) { + String methodName = methods[i]; + + // extract the class name + String className = methodName.substring(0, methodName.indexOf('#')); + + loadAndCompareClasses(className, className + "_Delegate"); + } + } + private void loadAndCompareClasses(String originalClassName, String delegateClassName) { // load the classes try { - ClassLoader classLoader = TestNativeDelegate.class.getClassLoader(); + ClassLoader classLoader = TestDelegates.class.getClassLoader(); Class originalClass = classLoader.loadClass(originalClassName); Class delegateClass = classLoader.loadClass(delegateClassName); 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 1c95400dbc053..b9c711337f41b 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,8 +95,8 @@ public final class CreateInfo implements ICreateInfo { */ private final static String[] DELEGATE_METHODS = new String[] { "android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;", + "android.view.View#isInEditMode", // TODO: comment out once DelegateClass is working - // "android.view.View#isInEditMode", // "android.content.res.Resources$Theme#obtainStyledAttributes", }; @@ -126,7 +126,6 @@ public final class CreateInfo implements ICreateInfo { */ private final static String[] OVERRIDDEN_METHODS = new String[] { // TODO: remove once DelegateClass is working - "android.view.View#isInEditMode", "android.content.res.Resources$Theme#obtainStyledAttributes", }; @@ -141,6 +140,7 @@ public final class CreateInfo implements ICreateInfo { "android.os.ServiceManager", "android.os._Original_ServiceManager", "android.view.SurfaceView", "android.view._Original_SurfaceView", "android.view.accessibility.AccessibilityManager", "android.view.accessibility._Original_AccessibilityManager", + "android.webkit.WebView", "android.webkit._Original_WebView", }; /**