diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-07-15 17:44:53 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-07-15 22:05:33 -0700 |
commit | 2c6081ce3593712f30dacd990a97209c791d6ced (patch) | |
tree | 4808bc521c207ea11ec0daceb98f77a6b47b00a0 /core/java | |
parent | c5ed5910c9ef066cec6a13bbb404ec57b1e92637 (diff) | |
download | frameworks_base-2c6081ce3593712f30dacd990a97209c791d6ced.zip frameworks_base-2c6081ce3593712f30dacd990a97209c791d6ced.tar.gz frameworks_base-2c6081ce3593712f30dacd990a97209c791d6ced.tar.bz2 |
Implement native key pre-dispatching to IMEs.
This significantly re-works the native key dispatching code to
allow events to be pre-dispatched to the current IME before
being processed by native code. It introduces one new public
API, which must be called after retrieving an event if the app
wishes for it to be pre-dispatched.
Currently the native code will only do pre-dispatching of
system keys, to avoid significant overhead for gaming input.
This should be improved to be smarted, filtering for only
keys that the IME is interested in. Unfortunately IMEs don't
currently provide this information. :p
Change-Id: Ic1c7aeec8b348164957f2cd88119eb5bd85c2a9f
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/app/NativeActivity.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/java/android/app/NativeActivity.java b/core/java/android/app/NativeActivity.java index 3238b82..eaf0675 100644 --- a/core/java/android/app/NativeActivity.java +++ b/core/java/android/app/NativeActivity.java @@ -1,5 +1,8 @@ package android.app; +import com.android.internal.view.IInputMethodCallback; +import com.android.internal.view.IInputMethodSession; + import dalvik.system.PathClassLoader; import android.content.Context; @@ -25,6 +28,7 @@ import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.inputmethod.InputMethodManager; import java.io.File; +import java.lang.ref.WeakReference; /** * Convenience for implementing an activity that will be implemented @@ -36,6 +40,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2, private NativeContentView mNativeContentView; private InputMethodManager mIMM; + private InputMethodCallback mInputMethodCallback; private int mNativeHandle; @@ -73,6 +78,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2, private native void onInputChannelDestroyedNative(int handle, InputChannel channel); private native void onContentRectChangedNative(int handle, int x, int y, int w, int h); private native void dispatchKeyEventNative(int handle, KeyEvent event); + private native void finishPreDispatchKeyEventNative(int handle, int seq, boolean handled); static class NativeContentView extends View { NativeActivity mActivity; @@ -86,12 +92,34 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2, } } + static class InputMethodCallback extends IInputMethodCallback.Stub { + WeakReference<NativeActivity> mNa; + + InputMethodCallback(NativeActivity na) { + mNa = new WeakReference<NativeActivity>(na); + } + + @Override + public void finishedEvent(int seq, boolean handled) { + NativeActivity na = mNa.get(); + if (na != null) { + na.finishPreDispatchKeyEventNative(na.mNativeHandle, seq, handled); + } + } + + @Override + public void sessionCreated(IInputMethodSession session) { + // Stub -- not for use in the client. + } + } + @Override protected void onCreate(Bundle savedInstanceState) { String libname = "main"; ActivityInfo ai; mIMM = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); + mInputMethodCallback = new InputMethodCallback(this); getWindow().takeSurface(this); getWindow().takeInputQueue(this); @@ -292,6 +320,11 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2, } } + void preDispatchKeyEvent(KeyEvent event, int seq) { + mIMM.dispatchKeyEvent(this, seq, event, + mInputMethodCallback); + } + void setWindowFlags(int flags, int mask) { getWindow().setFlags(flags, mask); } |