diff options
author | Xavier Ducrohet <xav@android.com> | 2011-09-30 18:08:05 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2011-10-03 09:06:07 -0700 |
commit | f1dee199a009fec5e3a5d1469f654098261f8b06 (patch) | |
tree | d7dd38d33c0b8d99566731240c6e556b236e991f /tools | |
parent | c8f68e5c7ffef3bc6775edf39a251baf79b81f6b (diff) | |
download | frameworks_base-f1dee199a009fec5e3a5d1469f654098261f8b06.zip frameworks_base-f1dee199a009fec5e3a5d1469f654098261f8b06.tar.gz frameworks_base-f1dee199a009fec5e3a5d1469f654098261f8b06.tar.bz2 |
Layoutlib: add support for ITextServicesManager.
This include a fix in layoutlib_create to properly handle
delegating a static method of an inner class (was broken and
only worked on non static method).
Added a few comments here and there to *_Accessor classes so
that it's a bit more obvious what they are for and how they are
used.
Change-Id: Ifc31dd1a006393bb0c08e22b6a17f500dd62e090
Diffstat (limited to 'tools')
10 files changed, 139 insertions, 12 deletions
diff --git a/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java b/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java index 413894b..c9d615c 100644 --- a/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java +++ b/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java @@ -25,7 +25,7 @@ import android.util.AttributeSet; import android.util.TypedValue; /** - * Delegate used to provide new implementation of a select few methods of {@link Theme} + * Delegate used to provide new implementation of a select few methods of {@link Resources$Theme} * * Through the layoutlib_create tool, the original methods of Theme have been replaced * by calls to methods of the same name in this delegate class. diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Accessor.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Accessor.java index 2745770..adad2ac 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Typeface_Accessor.java +++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Accessor.java @@ -16,6 +16,9 @@ package android.graphics; +/** + * Class allowing access to package-protected methods/fields. + */ public class Typeface_Accessor { public static void resetDefaults() { diff --git a/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java b/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java index ad95fcc..2961f97 100644 --- a/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java +++ b/tools/layoutlib/bridge/src/android/os/Looper_Accessor.java @@ -15,6 +15,9 @@ */ package android.os; +/** + * Class allowing access to package-protected methods/fields. + */ public class Looper_Accessor { public static void cleanupThread() { diff --git a/tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java b/tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java index e3778b1..96de51c 100644 --- a/tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java +++ b/tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java @@ -22,6 +22,9 @@ import com.android.layoutlib.bridge.android.BridgeWindowSession; import android.os.Handler; import android.view.View.AttachInfo; +/** + * Class allowing access to package-protected methods/fields. + */ public class AttachInfo_Accessor { public static void setAttachInfo(View view) { diff --git a/tools/layoutlib/bridge/src/android/view/ViewConfiguration_Accessor.java b/tools/layoutlib/bridge/src/android/view/ViewConfiguration_Accessor.java index 01db34e..c3533e0 100644 --- a/tools/layoutlib/bridge/src/android/view/ViewConfiguration_Accessor.java +++ b/tools/layoutlib/bridge/src/android/view/ViewConfiguration_Accessor.java @@ -16,6 +16,9 @@ package android.view; +/** + * Class allowing access to package-protected methods/fields. + */ public class ViewConfiguration_Accessor { public static void clearConfigurations() { diff --git a/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java b/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java index 875336a..7a6e52e 100644 --- a/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java +++ b/tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java @@ -16,6 +16,9 @@ package android.view.inputmethod; +/** + * Class allowing access to package-protected methods/fields. + */ public class InputMethodManager_Accessor { public static void resetInstance() { diff --git a/tools/layoutlib/bridge/src/com/android/internal/textservice/ITextServicesManager_Stub_Delegate.java b/tools/layoutlib/bridge/src/com/android/internal/textservice/ITextServicesManager_Stub_Delegate.java new file mode 100644 index 0000000..9efdcaf --- /dev/null +++ b/tools/layoutlib/bridge/src/com/android/internal/textservice/ITextServicesManager_Stub_Delegate.java @@ -0,0 +1,101 @@ +/* + * 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 com.android.internal.textservice; + +import com.android.tools.layoutlib.annotations.LayoutlibDelegate; + +import android.os.Bundle; +import android.os.IBinder; +import android.os.RemoteException; +import android.view.textservice.SpellCheckerInfo; +import android.view.textservice.SpellCheckerSubtype; + + +/** + * Delegate used to provide new implementation of a select few methods of + * {@link ITextServicesManager$Stub} + * + * Through the layoutlib_create tool, the original methods of Stub have been replaced + * by calls to methods of the same name in this delegate class. + * + */ +public class ITextServicesManager_Stub_Delegate { + + @LayoutlibDelegate + public static ITextServicesManager asInterface(IBinder obj) { + // ignore the obj and return a fake interface implementation + return new FakeTextServicesManager(); + } + + private static class FakeTextServicesManager implements ITextServicesManager { + + public void finishSpellCheckerService(ISpellCheckerSessionListener arg0) + throws RemoteException { + // TODO Auto-generated method stub + + } + + public SpellCheckerInfo getCurrentSpellChecker(String arg0) throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public SpellCheckerSubtype getCurrentSpellCheckerSubtype(String arg0, boolean arg1) + throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public SpellCheckerInfo[] getEnabledSpellCheckers() throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public void getSpellCheckerService(String arg0, String arg1, + ITextServicesSessionListener arg2, ISpellCheckerSessionListener arg3, Bundle arg4) + throws RemoteException { + // TODO Auto-generated method stub + + } + + public boolean isSpellCheckerEnabled() throws RemoteException { + // TODO Auto-generated method stub + return false; + } + + public void setCurrentSpellChecker(String arg0, String arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setCurrentSpellCheckerSubtype(String arg0, int arg1) throws RemoteException { + // TODO Auto-generated method stub + + } + + public void setSpellCheckerEnabled(boolean arg0) throws RemoteException { + // TODO Auto-generated method stub + + } + + public IBinder asBinder() { + // TODO Auto-generated method stub + return 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 0453a5e..fbbcbc1 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 @@ -67,6 +67,7 @@ import android.view.BridgeInflater; import android.view.Surface; import android.view.View; import android.view.ViewGroup; +import android.view.textservice.TextServicesManager; import java.io.File; import java.io.FileInputStream; @@ -414,6 +415,11 @@ public final class BridgeContext extends Context { return mBridgeInflater; } + if (TEXT_SERVICES_MANAGER_SERVICE.equals(service)) { + // we need to return a valid service to avoid NPE + return TextServicesManager.getInstance(); + } + // AutoCompleteTextView and MultiAutoCompleteTextView want a window // service. We don't have any but it's not worth an exception. if (WINDOW_SERVICE.equals(service)) { 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 0a15627..70c8a00 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 @@ -111,7 +111,7 @@ public final class CreateInfo implements ICreateInfo { "android.view.inputmethod.InputMethodManager#getInstance", "android.util.Log#println_native", "com.android.internal.util.XmlUtils#convertValueToInt", - // TODO: comment out once DelegateClass is working + "com.android.internal.textservice.ITextServicesManager$Stub#asInterface", }; /** diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter2.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter2.java index ac4ae6d..89b53ab 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter2.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter2.java @@ -188,20 +188,24 @@ class DelegateMethodAdapter2 implements MethodVisitor { boolean pushedArg0 = false; int maxStack = 0; + // Check if the last segment of the class name has inner an class. + // Right now we only support one level of inner classes. + Type outerType = null; + int slash = mClassName.lastIndexOf('/'); + int dol = mClassName.lastIndexOf('$'); + if (dol != -1 && dol > slash && dol == mClassName.indexOf('$')) { + String outerClass = mClassName.substring(0, dol); + outerType = Type.getObjectType(outerClass); + + // Change a delegate class name to "com/foo/Outer_Inner_Delegate" + delegateClassName = delegateClassName.replace('$', '_'); + } + // For an instance method (e.g. non-static), push the 'this' preceded // by the 'this' of any outer class, if any. if (!mIsStatic) { - // Check if the last segment of the class name has inner an class. - // Right now we only support one level of inner classes. - int slash = mClassName.lastIndexOf('/'); - int dol = mClassName.lastIndexOf('$'); - if (dol != -1 && dol > slash && dol == mClassName.indexOf('$')) { - String outerClass = mClassName.substring(0, dol); - Type outerType = Type.getObjectType(outerClass); - - // Change a delegate class name to "com/foo/Outer_Inner_Delegate" - delegateClassName = delegateClassName.replace('$', '_'); + if (outerType != null) { // The first-level inner class has a package-protected member called 'this$0' // that points to the outer class. @@ -213,6 +217,7 @@ class DelegateMethodAdapter2 implements MethodVisitor { outerType.getDescriptor()); // type of the field maxStack++; paramTypes.add(outerType); + } // Push "this" for the instance method, which is always ALOAD 0 |