Skip to content

Commit 6c465bb

Browse files
author
Xavier Ducrohet
committed
Cherry-pick f1dee1 from master for SDK. do not merge.
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: I186ce33236e4de08d0205f75fb8d20d74c92da34
1 parent 8b42fce commit 6c465bb

File tree

10 files changed

+139
-12
lines changed

10 files changed

+139
-12
lines changed

tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import android.util.TypedValue;
2626

2727
/**
28-
* Delegate used to provide new implementation of a select few methods of {@link Theme}
28+
* Delegate used to provide new implementation of a select few methods of {@link Resources$Theme}
2929
*
3030
* Through the layoutlib_create tool, the original methods of Theme have been replaced
3131
* by calls to methods of the same name in this delegate class.

tools/layoutlib/bridge/src/android/graphics/Typeface_Accessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package android.graphics;
1818

19+
/**
20+
* Class allowing access to package-protected methods/fields.
21+
*/
1922
public class Typeface_Accessor {
2023

2124
public static void resetDefaults() {

tools/layoutlib/bridge/src/android/os/Looper_Accessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package android.os;
1717

18+
/**
19+
* Class allowing access to package-protected methods/fields.
20+
*/
1821
public class Looper_Accessor {
1922

2023
public static void cleanupThread() {

tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import android.os.Handler;
2323
import android.view.View.AttachInfo;
2424

25+
/**
26+
* Class allowing access to package-protected methods/fields.
27+
*/
2528
public class AttachInfo_Accessor {
2629

2730
public static void setAttachInfo(View view) {

tools/layoutlib/bridge/src/android/view/ViewConfiguration_Accessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package android.view;
1818

19+
/**
20+
* Class allowing access to package-protected methods/fields.
21+
*/
1922
public class ViewConfiguration_Accessor {
2023

2124
public static void clearConfigurations() {

tools/layoutlib/bridge/src/android/view/inputmethod/InputMethodManager_Accessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package android.view.inputmethod;
1818

19+
/**
20+
* Class allowing access to package-protected methods/fields.
21+
*/
1922
public class InputMethodManager_Accessor {
2023

2124
public static void resetInstance() {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (C) 2011 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.internal.textservice;
18+
19+
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
20+
21+
import android.os.Bundle;
22+
import android.os.IBinder;
23+
import android.os.RemoteException;
24+
import android.view.textservice.SpellCheckerInfo;
25+
import android.view.textservice.SpellCheckerSubtype;
26+
27+
28+
/**
29+
* Delegate used to provide new implementation of a select few methods of
30+
* {@link ITextServicesManager$Stub}
31+
*
32+
* Through the layoutlib_create tool, the original methods of Stub have been replaced
33+
* by calls to methods of the same name in this delegate class.
34+
*
35+
*/
36+
public class ITextServicesManager_Stub_Delegate {
37+
38+
@LayoutlibDelegate
39+
public static ITextServicesManager asInterface(IBinder obj) {
40+
// ignore the obj and return a fake interface implementation
41+
return new FakeTextServicesManager();
42+
}
43+
44+
private static class FakeTextServicesManager implements ITextServicesManager {
45+
46+
public void finishSpellCheckerService(ISpellCheckerSessionListener arg0)
47+
throws RemoteException {
48+
// TODO Auto-generated method stub
49+
50+
}
51+
52+
public SpellCheckerInfo getCurrentSpellChecker(String arg0) throws RemoteException {
53+
// TODO Auto-generated method stub
54+
return null;
55+
}
56+
57+
public SpellCheckerSubtype getCurrentSpellCheckerSubtype(String arg0, boolean arg1)
58+
throws RemoteException {
59+
// TODO Auto-generated method stub
60+
return null;
61+
}
62+
63+
public SpellCheckerInfo[] getEnabledSpellCheckers() throws RemoteException {
64+
// TODO Auto-generated method stub
65+
return null;
66+
}
67+
68+
public void getSpellCheckerService(String arg0, String arg1,
69+
ITextServicesSessionListener arg2, ISpellCheckerSessionListener arg3, Bundle arg4)
70+
throws RemoteException {
71+
// TODO Auto-generated method stub
72+
73+
}
74+
75+
public boolean isSpellCheckerEnabled() throws RemoteException {
76+
// TODO Auto-generated method stub
77+
return false;
78+
}
79+
80+
public void setCurrentSpellChecker(String arg0, String arg1) throws RemoteException {
81+
// TODO Auto-generated method stub
82+
83+
}
84+
85+
public void setCurrentSpellCheckerSubtype(String arg0, int arg1) throws RemoteException {
86+
// TODO Auto-generated method stub
87+
88+
}
89+
90+
public void setSpellCheckerEnabled(boolean arg0) throws RemoteException {
91+
// TODO Auto-generated method stub
92+
93+
}
94+
95+
public IBinder asBinder() {
96+
// TODO Auto-generated method stub
97+
return null;
98+
}
99+
100+
}
101+
}

tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import android.view.Surface;
6868
import android.view.View;
6969
import android.view.ViewGroup;
70+
import android.view.textservice.TextServicesManager;
7071

7172
import java.io.File;
7273
import java.io.FileInputStream;
@@ -414,6 +415,11 @@ public Object getSystemService(String service) {
414415
return mBridgeInflater;
415416
}
416417

418+
if (TEXT_SERVICES_MANAGER_SERVICE.equals(service)) {
419+
// we need to return a valid service to avoid NPE
420+
return TextServicesManager.getInstance();
421+
}
422+
417423
// AutoCompleteTextView and MultiAutoCompleteTextView want a window
418424
// service. We don't have any but it's not worth an exception.
419425
if (WINDOW_SERVICE.equals(service)) {

tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public String[] getDeleteReturns() {
111111
"android.view.inputmethod.InputMethodManager#getInstance",
112112
"android.util.Log#println_native",
113113
"com.android.internal.util.XmlUtils#convertValueToInt",
114-
// TODO: comment out once DelegateClass is working
114+
"com.android.internal.textservice.ITextServicesManager$Stub#asInterface",
115115
};
116116

117117
/**

tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateMethodAdapter2.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,24 @@ public void generateDelegateCode() {
188188
boolean pushedArg0 = false;
189189
int maxStack = 0;
190190

191+
// Check if the last segment of the class name has inner an class.
192+
// Right now we only support one level of inner classes.
193+
Type outerType = null;
194+
int slash = mClassName.lastIndexOf('/');
195+
int dol = mClassName.lastIndexOf('$');
196+
if (dol != -1 && dol > slash && dol == mClassName.indexOf('$')) {
197+
String outerClass = mClassName.substring(0, dol);
198+
outerType = Type.getObjectType(outerClass);
199+
200+
// Change a delegate class name to "com/foo/Outer_Inner_Delegate"
201+
delegateClassName = delegateClassName.replace('$', '_');
202+
}
203+
191204
// For an instance method (e.g. non-static), push the 'this' preceded
192205
// by the 'this' of any outer class, if any.
193206
if (!mIsStatic) {
194-
// Check if the last segment of the class name has inner an class.
195-
// Right now we only support one level of inner classes.
196-
int slash = mClassName.lastIndexOf('/');
197-
int dol = mClassName.lastIndexOf('$');
198-
if (dol != -1 && dol > slash && dol == mClassName.indexOf('$')) {
199-
String outerClass = mClassName.substring(0, dol);
200-
Type outerType = Type.getObjectType(outerClass);
201-
202-
// Change a delegate class name to "com/foo/Outer_Inner_Delegate"
203-
delegateClassName = delegateClassName.replace('$', '_');
204207

208+
if (outerType != null) {
205209
// The first-level inner class has a package-protected member called 'this$0'
206210
// that points to the outer class.
207211

@@ -213,6 +217,7 @@ public void generateDelegateCode() {
213217
outerType.getDescriptor()); // type of the field
214218
maxStack++;
215219
paramTypes.add(outerType);
220+
216221
}
217222

218223
// Push "this" for the instance method, which is always ALOAD 0

0 commit comments

Comments
 (0)