First stab at attaching native event dispatching.
Provides the basic infrastructure for a NativeActivity's native code to get an object representing its event stream that can be used to read input events. Still work to do, probably some API changes, and reasonable default key handling (so that for example back will still work). Change-Id: I6db891bc35dc9683181d7708eaed552b955a077e
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
39
core/java/android/view/InputConsumer.java
Normal file
39
core/java/android/view/InputConsumer.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -480,6 +480,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
|
||||
|
||||
Reference in New Issue
Block a user