diff options
| author | Dianne Hackborn <hackbod@google.com> | 2010-06-29 19:20:40 -0700 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2010-06-30 10:49:40 -0700 |
| commit | 3c80a4a044865bdf1289c7896baffa1c082d835c (patch) | |
| tree | 557c89a685e672e44f90f55660da1f989d00a113 /core/java/android/app/NativeActivity.java | |
| parent | 92dbad8ab0c8e242c4c3e52c339ed3296ae7901c (diff) | |
Implement default key handling for native code.
The native code now maintains a list of all keys that may use
default handling. If the app finishes one of these keys
without handling it, the key will be passed back off to Java
for default treatment.
Change-Id: I6a842a0d728eeafa4de7142fae573f8c11099e18
Diffstat (limited to 'core/java/android/app/NativeActivity.java')
| -rw-r--r-- | core/java/android/app/NativeActivity.java | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/core/java/android/app/NativeActivity.java b/core/java/android/app/NativeActivity.java index 429d16498aa8..d43368b1b1e2 100644 --- a/core/java/android/app/NativeActivity.java +++ b/core/java/android/app/NativeActivity.java @@ -6,9 +6,13 @@ import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; +import android.os.Looper; +import android.os.MessageQueue; import android.view.InputChannel; import android.view.InputQueue; +import android.view.KeyEvent; import android.view.SurfaceHolder; +import android.view.View; import java.io.File; @@ -22,7 +26,12 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback, private int mNativeHandle; - private native int loadNativeCode(String path); + private InputQueue mCurInputQueue; + private SurfaceHolder mCurSurfaceHolder; + + private boolean mDestroyed; + + private native int loadNativeCode(String path, MessageQueue queue); private native void unloadNativeCode(int handle); private native void onStartNative(int handle); @@ -78,7 +87,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback, throw new IllegalArgumentException("Unable to find native library: " + libname); } - mNativeHandle = loadNativeCode(path); + mNativeHandle = loadNativeCode(path, Looper.myQueue()); if (mNativeHandle == 0) { throw new IllegalArgumentException("Unable to load native library: " + path); } @@ -87,6 +96,15 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback, @Override protected void onDestroy() { + mDestroyed = true; + if (mCurSurfaceHolder != null) { + onSurfaceDestroyedNative(mNativeHandle, mCurSurfaceHolder); + mCurSurfaceHolder = null; + } + if (mCurInputQueue != null) { + onInputChannelDestroyedNative(mNativeHandle, mCurInputQueue.getInputChannel()); + mCurInputQueue = null; + } unloadNativeCode(mNativeHandle); super.onDestroy(); } @@ -124,32 +142,58 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback, @Override public void onLowMemory() { super.onLowMemory(); - onLowMemoryNative(mNativeHandle); + if (!mDestroyed) { + onLowMemoryNative(mNativeHandle); + } } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); - onWindowFocusChangedNative(mNativeHandle, hasFocus); + if (!mDestroyed) { + onWindowFocusChangedNative(mNativeHandle, hasFocus); + } } public void surfaceCreated(SurfaceHolder holder) { - onSurfaceCreatedNative(mNativeHandle, holder); + if (!mDestroyed) { + mCurSurfaceHolder = holder; + onSurfaceCreatedNative(mNativeHandle, holder); + } } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - onSurfaceChangedNative(mNativeHandle, holder, format, width, height); + if (!mDestroyed) { + mCurSurfaceHolder = holder; + onSurfaceChangedNative(mNativeHandle, holder, format, width, height); + } } public void surfaceDestroyed(SurfaceHolder holder) { - onSurfaceDestroyedNative(mNativeHandle, holder); + mCurSurfaceHolder = null; + if (!mDestroyed) { + onSurfaceDestroyedNative(mNativeHandle, holder); + } } public void onInputQueueCreated(InputQueue queue) { - onInputChannelCreatedNative(mNativeHandle, queue.getInputChannel()); + if (!mDestroyed) { + mCurInputQueue = queue; + onInputChannelCreatedNative(mNativeHandle, queue.getInputChannel()); + } } public void onInputQueueDestroyed(InputQueue queue) { - onInputChannelDestroyedNative(mNativeHandle, queue.getInputChannel()); + mCurInputQueue = null; + if (!mDestroyed) { + onInputChannelDestroyedNative(mNativeHandle, queue.getInputChannel()); + } + } + + void dispatchUnhandledKeyEvent(KeyEvent event) { + View decor = getWindow().getDecorView(); + if (decor != null) { + decor.dispatchKeyEvent(event); + } } } |
