summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/NativeActivity.java16
-rw-r--r--core/java/android/view/InputChannel.java5
-rw-r--r--core/java/android/view/InputConsumer.java39
-rw-r--r--core/java/android/view/ViewRoot.java24
-rw-r--r--core/java/android/view/Window.java7
5 files changed, 84 insertions, 7 deletions
diff --git a/core/java/android/app/NativeActivity.java b/core/java/android/app/NativeActivity.java
index fd20b71..973ad60 100644
--- a/core/java/android/app/NativeActivity.java
+++ b/core/java/android/app/NativeActivity.java
@@ -6,6 +6,8 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.view.InputChannel;
+import android.view.InputConsumer;
import android.view.SurfaceHolder;
import java.io.File;
@@ -14,7 +16,8 @@ import java.io.File;
* Convenience for implementing an activity that will be implemented
* purely in native code. That is, a game (or game-like thing).
*/
-public class NativeActivity extends Activity implements SurfaceHolder.Callback {
+public class NativeActivity extends Activity implements SurfaceHolder.Callback,
+ InputConsumer.Callback {
public static final String META_DATA_LIB_NAME = "android.app.lib_name";
private int mNativeHandle;
@@ -33,6 +36,8 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback {
private native void onSurfaceChangedNative(int handle, SurfaceHolder holder,
int format, int width, int height);
private native void onSurfaceDestroyedNative(int handle, SurfaceHolder holder);
+ private native void onInputChannelCreatedNative(int handle, InputChannel channel);
+ private native void onInputChannelDestroyedNative(int handle, InputChannel channel);
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -40,6 +45,7 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback {
ActivityInfo ai;
getWindow().takeSurface(this);
+ getWindow().takeInputChannel(this);
try {
ai = getPackageManager().getActivityInfo(
@@ -138,4 +144,12 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback {
public void surfaceDestroyed(SurfaceHolder holder) {
onSurfaceDestroyedNative(mNativeHandle, holder);
}
+
+ public void onInputConsumerCreated(InputConsumer consumer) {
+ onInputChannelCreatedNative(mNativeHandle, consumer.getInputChannel());
+ }
+
+ public void onInputConsumerDestroyed(InputConsumer consumer) {
+ onInputChannelDestroyedNative(mNativeHandle, consumer.getInputChannel());
+ }
}
diff --git a/core/java/android/view/InputChannel.java b/core/java/android/view/InputChannel.java
index e5ebc69..e24c3c9 100644
--- a/core/java/android/view/InputChannel.java
+++ b/core/java/android/view/InputChannel.java
@@ -22,8 +22,9 @@ import android.util.Slog;
/**
* An input channel specifies the file descriptors used to send input events to
- * a window in another process. It is Parcelable so that it can be transmitted
- * to the ViewRoot through a Binder transaction as part of registering the Window.
+ * a window in another process. It is Parcelable so that it can be sent
+ * to the process that is to receive events. Only one thread should be reading
+ * from an InputChannel at a time.
* @hide
*/
public final class InputChannel implements Parcelable {
diff --git a/core/java/android/view/InputConsumer.java b/core/java/android/view/InputConsumer.java
new file mode 100644
index 0000000..63b26c6
--- /dev/null
+++ b/core/java/android/view/InputConsumer.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * Handle for consuming raw input events.
+ */
+public class InputConsumer {
+ public static interface Callback {
+ void onInputConsumerCreated(InputConsumer consumer);
+ void onInputConsumerDestroyed(InputConsumer consumer);
+ }
+
+ final InputChannel mChannel;
+
+ /** @hide */
+ public InputConsumer(InputChannel channel) {
+ mChannel = channel;
+ }
+
+ /** @hide */
+ public InputChannel getInputChannel() {
+ return mChannel;
+ }
+}
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index a41c690..8984b74 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -154,7 +154,9 @@ public final class ViewRoot extends Handler implements ViewParent,
final View.AttachInfo mAttachInfo;
InputChannel mInputChannel;
-
+ InputConsumer.Callback mInputConsumerCallback;
+ InputConsumer mInputConsumer;
+
final Rect mTempRect; // used in the transaction to not thrash the heap.
final Rect mVisRect; // used to retrieve visible rect of focused view.
@@ -555,8 +557,17 @@ public final class ViewRoot extends Handler implements ViewParent,
}
if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) {
- InputQueue.registerInputChannel(mInputChannel, mInputHandler,
- Looper.myQueue());
+ if (view instanceof RootViewSurfaceTaker) {
+ mInputConsumerCallback =
+ ((RootViewSurfaceTaker)view).willYouTakeTheInputConsumer();
+ }
+ if (mInputConsumerCallback != null) {
+ mInputConsumer = new InputConsumer(mInputChannel);
+ mInputConsumerCallback.onInputConsumerCreated(mInputConsumer);
+ } else {
+ InputQueue.registerInputChannel(mInputChannel, mInputHandler,
+ Looper.myQueue());
+ }
}
view.assignParent(this);
@@ -1736,7 +1747,12 @@ public final class ViewRoot extends Handler implements ViewParent,
if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) {
if (mInputChannel != null) {
- InputQueue.unregisterInputChannel(mInputChannel);
+ if (mInputConsumerCallback != null) {
+ mInputConsumerCallback.onInputConsumerDestroyed(mInputConsumer);
+ mInputConsumerCallback = null;
+ } else {
+ InputQueue.unregisterInputChannel(mInputChannel);
+ }
mInputChannel.dispose();
mInputChannel = null;
}
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index 234deba..b00d33d 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -481,6 +481,13 @@ public abstract class Window {
public abstract void takeSurface(SurfaceHolder.Callback callback);
/**
+ * Take ownership of this window's InputChannel. The window will no
+ * longer read and dispatch input events from the channel; it is your
+ * responsibility to do so.
+ */
+ public abstract void takeInputChannel(InputConsumer.Callback callback);
+
+ /**
* Return whether this window is being displayed with a floating style
* (based on the {@link android.R.attr#windowIsFloating} attribute in
* the style/theme).