Update to new native activity APIs.
Change-Id: Id2a32fd0ed0de39b2f266216d5b3d903156fb761
This commit is contained in:
@@ -125,8 +125,8 @@ enum {
|
|||||||
* Input events are opaque structures. Use the provided accessors functions to
|
* Input events are opaque structures. Use the provided accessors functions to
|
||||||
* read their properties.
|
* read their properties.
|
||||||
*/
|
*/
|
||||||
struct input_event_t;
|
struct AInputEvent;
|
||||||
typedef struct input_event_t input_event_t;
|
typedef struct AInputEvent AInputEvent;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Input event types.
|
* Input event types.
|
||||||
@@ -319,7 +319,7 @@ enum {
|
|||||||
/*** Accessors for all input events. ***/
|
/*** Accessors for all input events. ***/
|
||||||
|
|
||||||
/* Get the input event type. */
|
/* Get the input event type. */
|
||||||
int32_t input_event_get_type(const input_event_t* event);
|
int32_t AInputEvent_getType(const AInputEvent* event);
|
||||||
|
|
||||||
/* Get the id for the device that an input event came from.
|
/* Get the id for the device that an input event came from.
|
||||||
*
|
*
|
||||||
@@ -331,128 +331,128 @@ int32_t input_event_get_type(const input_event_t* event);
|
|||||||
* other numbers are arbitrary and you shouldn't depend on the values.
|
* other numbers are arbitrary and you shouldn't depend on the values.
|
||||||
* Use the provided input device query API to obtain information about input devices.
|
* Use the provided input device query API to obtain information about input devices.
|
||||||
*/
|
*/
|
||||||
int32_t input_event_get_device_id(const input_event_t* event);
|
int32_t AInputEvent_getDeviceId(const AInputEvent* event);
|
||||||
|
|
||||||
/* Get the input event nature. */
|
/* Get the input event nature. */
|
||||||
int32_t input_event_get_nature(const input_event_t* event);
|
int32_t AInputEvent_getNature(const AInputEvent* event);
|
||||||
|
|
||||||
/*** Accessors for key events only. ***/
|
/*** Accessors for key events only. ***/
|
||||||
|
|
||||||
/* Get the key event action. */
|
/* Get the key event action. */
|
||||||
int32_t key_event_get_action(const input_event_t* key_event);
|
int32_t AKeyEvent_getAction(const AInputEvent* key_event);
|
||||||
|
|
||||||
/* Get the key event flags. */
|
/* Get the key event flags. */
|
||||||
int32_t key_event_get_flags(const input_event_t* key_event);
|
int32_t AKeyEvent_getFlags(const AInputEvent* key_event);
|
||||||
|
|
||||||
/* Get the key code of the key event.
|
/* Get the key code of the key event.
|
||||||
* This is the physical key that was pressed, not the Unicode character. */
|
* This is the physical key that was pressed, not the Unicode character. */
|
||||||
int32_t key_event_get_key_code(const input_event_t* key_event);
|
int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event);
|
||||||
|
|
||||||
/* Get the hardware key id of this key event.
|
/* Get the hardware key id of this key event.
|
||||||
* These values are not reliable and vary from device to device. */
|
* These values are not reliable and vary from device to device. */
|
||||||
int32_t key_event_get_scan_code(const input_event_t* key_event);
|
int32_t AKeyEvent_getScanCode(const AInputEvent* key_event);
|
||||||
|
|
||||||
/* Get the meta key state. */
|
/* Get the meta key state. */
|
||||||
int32_t key_event_get_meta_state(const input_event_t* key_event);
|
int32_t AKeyEvent_getMetaState(const AInputEvent* key_event);
|
||||||
|
|
||||||
/* Get the repeat count of the event.
|
/* Get the repeat count of the event.
|
||||||
* For both key up an key down events, this is the number of times the key has
|
* For both key up an key down events, this is the number of times the key has
|
||||||
* repeated with the first down starting at 0 and counting up from there. For
|
* repeated with the first down starting at 0 and counting up from there. For
|
||||||
* multiple key events, this is the number of down/up pairs that have occurred. */
|
* multiple key events, this is the number of down/up pairs that have occurred. */
|
||||||
int32_t key_event_get_repeat_count(const input_event_t* key_event);
|
int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event);
|
||||||
|
|
||||||
/* Get the time of the most recent key down event, in the
|
/* Get the time of the most recent key down event, in the
|
||||||
* java.lang.System.nanoTime() time base. If this is a down event,
|
* java.lang.System.nanoTime() time base. If this is a down event,
|
||||||
* this will be the same as eventTime.
|
* this will be the same as eventTime.
|
||||||
* Note that when chording keys, this value is the down time of the most recently
|
* Note that when chording keys, this value is the down time of the most recently
|
||||||
* pressed key, which may not be the same physical key of this event. */
|
* pressed key, which may not be the same physical key of this event. */
|
||||||
int64_t key_event_get_down_time(const input_event_t* key_event);
|
int64_t AKeyEvent_getDownTime(const AInputEvent* key_event);
|
||||||
|
|
||||||
/* Get the time this event occurred, in the
|
/* Get the time this event occurred, in the
|
||||||
* java.lang.System.nanoTime() time base. */
|
* java.lang.System.nanoTime() time base. */
|
||||||
int64_t key_event_get_event_time(const input_event_t* key_event);
|
int64_t AKeyEvent_getEventTime(const AInputEvent* key_event);
|
||||||
|
|
||||||
/*** Accessors for motion events only. ***/
|
/*** Accessors for motion events only. ***/
|
||||||
|
|
||||||
/* Get the combined motion event action code and pointer index. */
|
/* Get the combined motion event action code and pointer index. */
|
||||||
int32_t motion_event_get_action(const input_event_t* motion_event);
|
int32_t AMotionEvent_getAction(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the state of any meta / modifier keys that were in effect when the
|
/* Get the state of any meta / modifier keys that were in effect when the
|
||||||
* event was generated. */
|
* event was generated. */
|
||||||
int32_t motion_event_get_meta_state(const input_event_t* motion_event);
|
int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get a bitfield indicating which edges, if any, were touched by this motion event.
|
/* Get a bitfield indicating which edges, if any, were touched by this motion event.
|
||||||
* For touch events, clients can use this to determine if the user's finger was
|
* For touch events, clients can use this to determine if the user's finger was
|
||||||
* touching the edge of the display. */
|
* touching the edge of the display. */
|
||||||
int32_t motion_event_get_edge_flags(const input_event_t* motion_event);
|
int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the time when the user originally pressed down to start a stream of
|
/* Get the time when the user originally pressed down to start a stream of
|
||||||
* position events, in the java.lang.System.nanoTime() time base. */
|
* position events, in the java.lang.System.nanoTime() time base. */
|
||||||
int64_t motion_event_get_down_time(const input_event_t* motion_event);
|
int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the time when this specific event was generated,
|
/* Get the time when this specific event was generated,
|
||||||
* in the java.lang.System.nanoTime() time base. */
|
* in the java.lang.System.nanoTime() time base. */
|
||||||
int64_t motion_event_get_event_time(const input_event_t* motion_event);
|
int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the X coordinate offset.
|
/* Get the X coordinate offset.
|
||||||
* For touch events on the screen, this is the delta that was added to the raw
|
* For touch events on the screen, this is the delta that was added to the raw
|
||||||
* screen coordinates to adjust for the absolute position of the containing windows
|
* screen coordinates to adjust for the absolute position of the containing windows
|
||||||
* and views. */
|
* and views. */
|
||||||
float motion_event_get_x_offset(const input_event_t* motion_event);
|
float AMotionEvent_getXOffset(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the precision of the Y coordinates being reported.
|
/* Get the precision of the Y coordinates being reported.
|
||||||
* For touch events on the screen, this is the delta that was added to the raw
|
* For touch events on the screen, this is the delta that was added to the raw
|
||||||
* screen coordinates to adjust for the absolute position of the containing windows
|
* screen coordinates to adjust for the absolute position of the containing windows
|
||||||
* and views. */
|
* and views. */
|
||||||
float motion_event_get_y_offset(const input_event_t* motion_event);
|
float AMotionEvent_getYOffset(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the precision of the X coordinates being reported.
|
/* Get the precision of the X coordinates being reported.
|
||||||
* You can multiply this number with an X coordinate sample to find the
|
* You can multiply this number with an X coordinate sample to find the
|
||||||
* actual hardware value of the X coordinate. */
|
* actual hardware value of the X coordinate. */
|
||||||
float motion_event_get_x_precision(const input_event_t* motion_event);
|
float AMotionEvent_getXPrecision(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the precision of the Y coordinates being reported.
|
/* Get the precision of the Y coordinates being reported.
|
||||||
* You can multiply this number with a Y coordinate sample to find the
|
* You can multiply this number with a Y coordinate sample to find the
|
||||||
* actual hardware value of the Y coordinate. */
|
* actual hardware value of the Y coordinate. */
|
||||||
float motion_event_get_y_precision(const input_event_t* motion_event);
|
float AMotionEvent_getYPrecision(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the number of pointers of data contained in this event.
|
/* Get the number of pointers of data contained in this event.
|
||||||
* Always >= 1. */
|
* Always >= 1. */
|
||||||
size_t motion_event_get_pointer_count(const input_event_t* motion_event);
|
size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the pointer identifier associated with a particular pointer
|
/* Get the pointer identifier associated with a particular pointer
|
||||||
* data index is this event. The identifier tells you the actual pointer
|
* data index is this event. The identifier tells you the actual pointer
|
||||||
* number associated with the data, accounting for individual pointers
|
* number associated with the data, accounting for individual pointers
|
||||||
* going up and down since the start of the current gesture. */
|
* going up and down since the start of the current gesture. */
|
||||||
int32_t motion_event_get_pointer_id(const input_event_t* motion_event, size_t pointer_index);
|
int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index);
|
||||||
|
|
||||||
/* Get the original raw X coordinate of this event.
|
/* Get the original raw X coordinate of this event.
|
||||||
* For touch events on the screen, this is the original location of the event
|
* For touch events on the screen, this is the original location of the event
|
||||||
* on the screen, before it had been adjusted for the containing window
|
* on the screen, before it had been adjusted for the containing window
|
||||||
* and views. */
|
* and views. */
|
||||||
float motion_event_get_raw_x(const input_event_t* motion_event, size_t pointer_index);
|
float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index);
|
||||||
|
|
||||||
/* Get the original raw X coordinate of this event.
|
/* Get the original raw X coordinate of this event.
|
||||||
* For touch events on the screen, this is the original location of the event
|
* For touch events on the screen, this is the original location of the event
|
||||||
* on the screen, before it had been adjusted for the containing window
|
* on the screen, before it had been adjusted for the containing window
|
||||||
* and views. */
|
* and views. */
|
||||||
float motion_event_get_raw_y(const input_event_t* motion_event, size_t pointer_index);
|
float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index);
|
||||||
|
|
||||||
/* Get the current X coordinate of this event for the given pointer index.
|
/* Get the current X coordinate of this event for the given pointer index.
|
||||||
* Whole numbers are pixels; the value may have a fraction for input devices
|
* Whole numbers are pixels; the value may have a fraction for input devices
|
||||||
* that are sub-pixel precise. */
|
* that are sub-pixel precise. */
|
||||||
float motion_event_get_x(const input_event_t* motion_event, size_t pointer_index);
|
float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index);
|
||||||
|
|
||||||
/* Get the current Y coordinate of this event for the given pointer index.
|
/* Get the current Y coordinate of this event for the given pointer index.
|
||||||
* Whole numbers are pixels; the value may have a fraction for input devices
|
* Whole numbers are pixels; the value may have a fraction for input devices
|
||||||
* that are sub-pixel precise. */
|
* that are sub-pixel precise. */
|
||||||
float motion_event_get_y(const input_event_t* motion_event, size_t pointer_index);
|
float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index);
|
||||||
|
|
||||||
/* Get the current pressure of this event for the given pointer index.
|
/* Get the current pressure of this event for the given pointer index.
|
||||||
* The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
|
* The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
|
||||||
* however values higher than 1 may be generated depending on the calibration of
|
* however values higher than 1 may be generated depending on the calibration of
|
||||||
* the input device. */
|
* the input device. */
|
||||||
float motion_event_get_pressure(const input_event_t* motion_event, size_t pointer_index);
|
float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index);
|
||||||
|
|
||||||
/* Get the current scaled value of the approximate size for the given pointer index.
|
/* Get the current scaled value of the approximate size for the given pointer index.
|
||||||
* This represents some approximation of the area of the screen being
|
* This represents some approximation of the area of the screen being
|
||||||
@@ -460,17 +460,17 @@ float motion_event_get_pressure(const input_event_t* motion_event, size_t pointe
|
|||||||
* touch is normalized with the device specific range of values
|
* touch is normalized with the device specific range of values
|
||||||
* and scaled to a value between 0 and 1. The value of size can be used to
|
* and scaled to a value between 0 and 1. The value of size can be used to
|
||||||
* determine fat touch events. */
|
* determine fat touch events. */
|
||||||
float motion_event_get_size(const input_event_t* motion_event, size_t pointer_index);
|
float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index);
|
||||||
|
|
||||||
/* Get the number of historical points in this event. These are movements that
|
/* Get the number of historical points in this event. These are movements that
|
||||||
* have occurred between this event and the previous event. This only applies
|
* have occurred between this event and the previous event. This only applies
|
||||||
* to MOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
|
* to MOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
|
||||||
* Historical samples are indexed from oldest to newest. */
|
* Historical samples are indexed from oldest to newest. */
|
||||||
size_t motion_event_get_history_size(const input_event_t* motion_event);
|
size_t AMotionEvent_get_history_size(const AInputEvent* motion_event);
|
||||||
|
|
||||||
/* Get the time that a historical movement occurred between this event and
|
/* Get the time that a historical movement occurred between this event and
|
||||||
* the previous event, in the java.lang.System.nanoTime() time base. */
|
* the previous event, in the java.lang.System.nanoTime() time base. */
|
||||||
int64_t motion_event_get_historical_event_time(input_event_t* motion_event,
|
int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event,
|
||||||
size_t history_index);
|
size_t history_index);
|
||||||
|
|
||||||
/* Get the historical raw X coordinate of this event for the given pointer index that
|
/* Get the historical raw X coordinate of this event for the given pointer index that
|
||||||
@@ -480,7 +480,7 @@ int64_t motion_event_get_historical_event_time(input_event_t* motion_event,
|
|||||||
* and views.
|
* and views.
|
||||||
* Whole numbers are pixels; the value may have a fraction for input devices
|
* Whole numbers are pixels; the value may have a fraction for input devices
|
||||||
* that are sub-pixel precise. */
|
* that are sub-pixel precise. */
|
||||||
float motion_event_get_historical_raw_x(const input_event_t* motion_event, size_t pointer_index);
|
float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index);
|
||||||
|
|
||||||
/* Get the historical raw Y coordinate of this event for the given pointer index that
|
/* Get the historical raw Y coordinate of this event for the given pointer index that
|
||||||
* occurred between this event and the previous motion event.
|
* occurred between this event and the previous motion event.
|
||||||
@@ -489,20 +489,20 @@ float motion_event_get_historical_raw_x(const input_event_t* motion_event, size_
|
|||||||
* and views.
|
* and views.
|
||||||
* Whole numbers are pixels; the value may have a fraction for input devices
|
* Whole numbers are pixels; the value may have a fraction for input devices
|
||||||
* that are sub-pixel precise. */
|
* that are sub-pixel precise. */
|
||||||
float motion_event_get_historical_raw_y(const input_event_t* motion_event, size_t pointer_index);
|
float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index);
|
||||||
|
|
||||||
/* Get the historical X coordinate of this event for the given pointer index that
|
/* Get the historical X coordinate of this event for the given pointer index that
|
||||||
* occurred between this event and the previous motion event.
|
* occurred between this event and the previous motion event.
|
||||||
* Whole numbers are pixels; the value may have a fraction for input devices
|
* Whole numbers are pixels; the value may have a fraction for input devices
|
||||||
* that are sub-pixel precise. */
|
* that are sub-pixel precise. */
|
||||||
float motion_event_get_historical_x(input_event_t* motion_event, size_t pointer_index,
|
float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index,
|
||||||
size_t history_index);
|
size_t history_index);
|
||||||
|
|
||||||
/* Get the historical Y coordinate of this event for the given pointer index that
|
/* Get the historical Y coordinate of this event for the given pointer index that
|
||||||
* occurred between this event and the previous motion event.
|
* occurred between this event and the previous motion event.
|
||||||
* Whole numbers are pixels; the value may have a fraction for input devices
|
* Whole numbers are pixels; the value may have a fraction for input devices
|
||||||
* that are sub-pixel precise. */
|
* that are sub-pixel precise. */
|
||||||
float motion_event_get_historical_y(input_event_t* motion_event, size_t pointer_index,
|
float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index,
|
||||||
size_t history_index);
|
size_t history_index);
|
||||||
|
|
||||||
/* Get the historical pressure of this event for the given pointer index that
|
/* Get the historical pressure of this event for the given pointer index that
|
||||||
@@ -510,7 +510,7 @@ float motion_event_get_historical_y(input_event_t* motion_event, size_t pointer_
|
|||||||
* The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
|
* The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
|
||||||
* however values higher than 1 may be generated depending on the calibration of
|
* however values higher than 1 may be generated depending on the calibration of
|
||||||
* the input device. */
|
* the input device. */
|
||||||
float motion_event_get_historical_pressure(input_event_t* motion_event, size_t pointer_index,
|
float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index,
|
||||||
size_t history_index);
|
size_t history_index);
|
||||||
|
|
||||||
/* Get the current scaled value of the approximate size for the given pointer index that
|
/* Get the current scaled value of the approximate size for the given pointer index that
|
||||||
@@ -520,7 +520,7 @@ float motion_event_get_historical_pressure(input_event_t* motion_event, size_t p
|
|||||||
* touch is normalized with the device specific range of values
|
* touch is normalized with the device specific range of values
|
||||||
* and scaled to a value between 0 and 1. The value of size can be used to
|
* and scaled to a value between 0 and 1. The value of size can be used to
|
||||||
* determine fat touch events. */
|
* determine fat touch events. */
|
||||||
float motion_event_get_historical_size(input_event_t* motion_event, size_t pointer_index,
|
float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index,
|
||||||
size_t history_index);
|
size_t history_index);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -529,8 +529,8 @@ float motion_event_get_historical_size(input_event_t* motion_event, size_t point
|
|||||||
* An input queue is the facility through which you retrieve input
|
* An input queue is the facility through which you retrieve input
|
||||||
* events.
|
* events.
|
||||||
*/
|
*/
|
||||||
struct input_queue_t;
|
struct AInputQueue;
|
||||||
typedef struct input_queue_t input_queue_t;
|
typedef struct AInputQueue AInputQueue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a file descriptor for the queue, which you
|
* Return a file descriptor for the queue, which you
|
||||||
@@ -538,26 +538,26 @@ typedef struct input_queue_t input_queue_t;
|
|||||||
* is typically used with select() or poll() to multiplex
|
* is typically used with select() or poll() to multiplex
|
||||||
* with other kinds of events.
|
* with other kinds of events.
|
||||||
*/
|
*/
|
||||||
int input_queue_get_fd(input_queue_t* queue);
|
int AInputQueue_getFd(AInputQueue* queue);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns true if there are one or more events available in the
|
* Returns true if there are one or more events available in the
|
||||||
* input queue. Returns 1 if the queue has events; 0 if
|
* input queue. Returns 1 if the queue has events; 0 if
|
||||||
* it does not have events; and a negative value if there is an error.
|
* it does not have events; and a negative value if there is an error.
|
||||||
*/
|
*/
|
||||||
int input_queue_has_events(input_queue_t* queue);
|
int AInputQueue_hasEvents(AInputQueue* queue);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the next available event from the queue. Returns a negative
|
* Returns the next available event from the queue. Returns a negative
|
||||||
* value if no events are available or an error has occurred.
|
* value if no events are available or an error has occurred.
|
||||||
*/
|
*/
|
||||||
int32_t input_queue_get_event(input_queue_t* queue, input_event_t** outEvent);
|
int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Report that dispatching has finished with the given event.
|
* Report that dispatching has finished with the given event.
|
||||||
* This must be called after receiving an event with input_queue_get_event().
|
* This must be called after receiving an event with AInputQueue_get_event().
|
||||||
*/
|
*/
|
||||||
void input_queue_finish_event(input_queue_t* queue, input_event_t* event, int handled);
|
void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,27 +30,34 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Temporary until native surface API is defined.
|
// Temporary until native surface API is defined.
|
||||||
struct android_surface_t;
|
struct ASurfaceHolder;
|
||||||
typedef struct android_surface_t android_surface_t;
|
typedef struct ASurfaceHolder ASurfaceHolder;
|
||||||
|
|
||||||
struct android_activity_callbacks_t;
|
struct ANativeActivityCallbacks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This structure defines the native side of an android.app.NativeActivity.
|
* This structure defines the native side of an android.app.NativeActivity.
|
||||||
* It is created by the framework, and handed to the application's native
|
* It is created by the framework, and handed to the application's native
|
||||||
* code as it is being launched.
|
* code as it is being launched.
|
||||||
*/
|
*/
|
||||||
typedef struct android_activity_t {
|
typedef struct ANativeActivity {
|
||||||
/**
|
/**
|
||||||
* Pointer to the callback function table of the native application.
|
* Pointer to the callback function table of the native application.
|
||||||
* You can set the functions here to your own callbacks. The callbacks
|
* You can set the functions here to your own callbacks. The callbacks
|
||||||
* pointer itself here should not be changed; it is allocated and managed
|
* pointer itself here should not be changed; it is allocated and managed
|
||||||
* for you by the framework.
|
* for you by the framework.
|
||||||
*/
|
*/
|
||||||
struct android_activity_callbacks_t* callbacks;
|
struct ANativeActivityCallbacks* callbacks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JNI context for the main thread of the app.
|
* The global handle on the process's Java VM.
|
||||||
|
*/
|
||||||
|
JavaVM* vm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JNI context for the main thread of the app. Note that this field
|
||||||
|
* can ONLY be used from the main thread of the process; that is, the
|
||||||
|
* thread that calls into the ANativeActivityCallbacks.
|
||||||
*/
|
*/
|
||||||
JNIEnv* env;
|
JNIEnv* env;
|
||||||
|
|
||||||
@@ -65,7 +72,7 @@ typedef struct android_activity_t {
|
|||||||
* state.
|
* state.
|
||||||
*/
|
*/
|
||||||
void* instance;
|
void* instance;
|
||||||
} android_activity_t;
|
} ANativeActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These are the callbacks the framework makes into a native application.
|
* These are the callbacks the framework makes into a native application.
|
||||||
@@ -73,18 +80,18 @@ typedef struct android_activity_t {
|
|||||||
* By default, all callbacks are NULL; set to a pointer to your own function
|
* By default, all callbacks are NULL; set to a pointer to your own function
|
||||||
* to have it called.
|
* to have it called.
|
||||||
*/
|
*/
|
||||||
typedef struct android_activity_callbacks_t {
|
typedef struct ANativeActivityCallbacks {
|
||||||
/**
|
/**
|
||||||
* NativeActivity has started. See Java documentation for Activity.onStart()
|
* NativeActivity has started. See Java documentation for Activity.onStart()
|
||||||
* for more information.
|
* for more information.
|
||||||
*/
|
*/
|
||||||
void (*onStart)(android_activity_t* activity);
|
void (*onStart)(ANativeActivity* activity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeActivity has resumed. See Java documentation for Activity.onResume()
|
* NativeActivity has resumed. See Java documentation for Activity.onResume()
|
||||||
* for more information.
|
* for more information.
|
||||||
*/
|
*/
|
||||||
void (*onResume)(android_activity_t* activity);
|
void (*onResume)(ANativeActivity* activity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Framework is asking NativeActivity to save its current instance state.
|
* Framework is asking NativeActivity to save its current instance state.
|
||||||
@@ -95,38 +102,38 @@ typedef struct android_activity_callbacks_t {
|
|||||||
* saved state will be persisted, so it can not contain any active
|
* saved state will be persisted, so it can not contain any active
|
||||||
* entities (pointers to memory, file descriptors, etc).
|
* entities (pointers to memory, file descriptors, etc).
|
||||||
*/
|
*/
|
||||||
void* (*onSaveInstanceState)(android_activity_t* activity, size_t* outSize);
|
void* (*onSaveInstanceState)(ANativeActivity* activity, size_t* outSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeActivity has paused. See Java documentation for Activity.onPause()
|
* NativeActivity has paused. See Java documentation for Activity.onPause()
|
||||||
* for more information.
|
* for more information.
|
||||||
*/
|
*/
|
||||||
void (*onPause)(android_activity_t* activity);
|
void (*onPause)(ANativeActivity* activity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeActivity has stopped. See Java documentation for Activity.onStop()
|
* NativeActivity has stopped. See Java documentation for Activity.onStop()
|
||||||
* for more information.
|
* for more information.
|
||||||
*/
|
*/
|
||||||
void (*onStop)(android_activity_t* activity);
|
void (*onStop)(ANativeActivity* activity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeActivity is being destroyed. See Java documentation for Activity.onDestroy()
|
* NativeActivity is being destroyed. See Java documentation for Activity.onDestroy()
|
||||||
* for more information.
|
* for more information.
|
||||||
*/
|
*/
|
||||||
void (*onDestroy)(android_activity_t* activity);
|
void (*onDestroy)(ANativeActivity* activity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Focus has changed in this NativeActivity's window. This is often used,
|
* Focus has changed in this NativeActivity's window. This is often used,
|
||||||
* for example, to pause a game when it loses input focus.
|
* for example, to pause a game when it loses input focus.
|
||||||
*/
|
*/
|
||||||
void (*onWindowFocusChanged)(android_activity_t* activity, int hasFocus);
|
void (*onWindowFocusChanged)(ANativeActivity* activity, int hasFocus);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The drawing surface for this native activity has been created. You
|
* The drawing surface for this native activity has been created. You
|
||||||
* can use the given surface object to start drawing. NOTE: surface
|
* can use the given surface object to start drawing. NOTE: surface
|
||||||
* drawing API is not yet defined.
|
* drawing API is not yet defined.
|
||||||
*/
|
*/
|
||||||
void (*onSurfaceCreated)(android_activity_t* activity, android_surface_t* surface);
|
void (*onSurfaceCreated)(ANativeActivity* activity, ASurfaceHolder* surface);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The drawing surface for this native activity has changed. The surface
|
* The drawing surface for this native activity has changed. The surface
|
||||||
@@ -134,7 +141,7 @@ typedef struct android_activity_callbacks_t {
|
|||||||
* onSurfaceCreated. This is simply to inform you about interesting
|
* onSurfaceCreated. This is simply to inform you about interesting
|
||||||
* changed to that surface.
|
* changed to that surface.
|
||||||
*/
|
*/
|
||||||
void (*onSurfaceChanged)(android_activity_t* activity, android_surface_t* surface,
|
void (*onSurfaceChanged)(ANativeActivity* activity, ASurfaceHolder* surface,
|
||||||
int format, int width, int height);
|
int format, int width, int height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,28 +152,28 @@ typedef struct android_activity_callbacks_t {
|
|||||||
* properly synchronize with the other thread to stop its drawing before
|
* properly synchronize with the other thread to stop its drawing before
|
||||||
* returning from here.
|
* returning from here.
|
||||||
*/
|
*/
|
||||||
void (*onSurfaceDestroyed)(android_activity_t* activity, android_surface_t* surface);
|
void (*onSurfaceDestroyed)(ANativeActivity* activity, ASurfaceHolder* surface);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The input queue for this native activity's window has been created.
|
* The input queue for this native activity's window has been created.
|
||||||
* You can use the given input queue to start retrieving input events.
|
* You can use the given input queue to start retrieving input events.
|
||||||
*/
|
*/
|
||||||
void (*onInputQueueCreated)(android_activity_t* activity, input_queue_t* queue);
|
void (*onInputQueueCreated)(ANativeActivity* activity, AInputQueue* queue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The input queue for this native activity's window is being destroyed.
|
* The input queue for this native activity's window is being destroyed.
|
||||||
* You should no longer try to reference this object upon returning from this
|
* You should no longer try to reference this object upon returning from this
|
||||||
* function.
|
* function.
|
||||||
*/
|
*/
|
||||||
void (*onInputQueueDestroyed)(android_activity_t* activity, input_queue_t* queue);
|
void (*onInputQueueDestroyed)(ANativeActivity* activity, AInputQueue* queue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The system is running low on memory. Use this callback to release
|
* The system is running low on memory. Use this callback to release
|
||||||
* resources you do not need, to help the system avoid killing more
|
* resources you do not need, to help the system avoid killing more
|
||||||
* important processes.
|
* important processes.
|
||||||
*/
|
*/
|
||||||
void (*onLowMemory)(android_activity_t* activity);
|
void (*onLowMemory)(ANativeActivity* activity);
|
||||||
} android_activity_callbacks_t;
|
} ANativeActivityCallbacks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the function that must be in the native code to instantiate the
|
* This is the function that must be in the native code to instantiate the
|
||||||
@@ -174,14 +181,14 @@ typedef struct android_activity_callbacks_t {
|
|||||||
* above); if the code is being instantiated from a previously saved instance,
|
* above); if the code is being instantiated from a previously saved instance,
|
||||||
* the savedState will be non-NULL and point to the saved data.
|
* the savedState will be non-NULL and point to the saved data.
|
||||||
*/
|
*/
|
||||||
typedef void android_activity_create_t(android_activity_t* activity,
|
typedef void ANativeActivity_createFunc(ANativeActivity* activity,
|
||||||
void* savedState, size_t savedStateSize);
|
void* savedState, size_t savedStateSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the function that NativeInstance looks for when launching its
|
* The name of the function that NativeInstance looks for when launching its
|
||||||
* native code.
|
* native code.
|
||||||
*/
|
*/
|
||||||
extern android_activity_create_t android_onCreateActivity;
|
extern ANativeActivity_createFunc ANativeActivity_onCreate;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
};
|
};
|
||||||
|
|||||||
Binary file not shown.
@@ -37,12 +37,12 @@ struct engine {
|
|||||||
int msgwrite;
|
int msgwrite;
|
||||||
int msgpipe[2];
|
int msgpipe[2];
|
||||||
|
|
||||||
android_activity_t* activity;
|
ANativeActivity* activity;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
|
||||||
int running;
|
int running;
|
||||||
int destroyed;
|
int destroyed;
|
||||||
input_queue_t* inputQueue;
|
AInputQueue* inputQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -51,7 +51,8 @@ enum {
|
|||||||
ENGINE_CMD_DESTROY,
|
ENGINE_CMD_DESTROY,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int engine_entry(struct engine* engine) {
|
static void* engine_entry(void* param) {
|
||||||
|
struct engine* engine = (struct engine*)param;
|
||||||
struct pollfd pfd[2];
|
struct pollfd pfd[2];
|
||||||
int numfd;
|
int numfd;
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ static int engine_entry(struct engine* engine) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
if (engine->inputQueue != NULL) {
|
if (engine->inputQueue != NULL) {
|
||||||
numfd = 2;
|
numfd = 2;
|
||||||
pfd[1].fd = input_queue_get_fd(engine->inputQueue);
|
pfd[1].fd = AInputQueue_getFd(engine->inputQueue);
|
||||||
pfd[1].events = POLLIN;
|
pfd[1].events = POLLIN;
|
||||||
} else {
|
} else {
|
||||||
numfd = 1;
|
numfd = 1;
|
||||||
@@ -78,7 +79,7 @@ static int engine_entry(struct engine* engine) {
|
|||||||
|
|
||||||
pfd[0].revents = 0;
|
pfd[0].revents = 0;
|
||||||
pfd[1].revents = 0;
|
pfd[1].revents = 0;
|
||||||
int nfd = poll(&pfd, numfd, -1);
|
int nfd = poll(pfd, numfd, -1);
|
||||||
if (nfd <= 0) {
|
if (nfd <= 0) {
|
||||||
LOGI("Engine error in poll: %s\n", strerror(errno));
|
LOGI("Engine error in poll: %s\n", strerror(errno));
|
||||||
// Should cleanly exit!
|
// Should cleanly exit!
|
||||||
@@ -106,17 +107,17 @@ static int engine_entry(struct engine* engine) {
|
|||||||
pthread_cond_broadcast(&engine->cond);
|
pthread_cond_broadcast(&engine->cond);
|
||||||
pthread_mutex_unlock(&engine->mutex);
|
pthread_mutex_unlock(&engine->mutex);
|
||||||
// Can't touch engine object after this.
|
// Can't touch engine object after this.
|
||||||
return 0; // EXIT THREAD
|
return NULL; // EXIT THREAD
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOGI("Failure reading engine cmd: %s\n", strerror(errno));
|
LOGI("Failure reading engine cmd: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (pfd[1].revents == POLLIN) {
|
} else if (pfd[1].revents == POLLIN) {
|
||||||
input_event_t* event = NULL;
|
AInputEvent* event = NULL;
|
||||||
if (input_queue_get_event(engine->inputQueue, &event) >= 0) {
|
if (AInputQueue_getEvent(engine->inputQueue, &event) >= 0) {
|
||||||
LOGI("New input event: type=%d\n", input_event_get_type(event));
|
LOGI("New input event: type=%d\n", AInputEvent_getType(event));
|
||||||
input_queue_finish_event(engine->inputQueue, event, 0);
|
AInputQueue_finishEvent(engine->inputQueue, event, 0);
|
||||||
} else {
|
} else {
|
||||||
LOGI("Failure reading next input event: %s\n", strerror(errno));
|
LOGI("Failure reading next input event: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
@@ -124,7 +125,7 @@ static int engine_entry(struct engine* engine) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct engine* engine_create(android_activity_t* activity) {
|
static struct engine* engine_create(ANativeActivity* activity) {
|
||||||
struct engine* engine = (struct engine*)malloc(sizeof(struct engine));
|
struct engine* engine = (struct engine*)malloc(sizeof(struct engine));
|
||||||
memset(engine, 0, sizeof(struct engine));
|
memset(engine, 0, sizeof(struct engine));
|
||||||
engine->activity = activity;
|
engine->activity = activity;
|
||||||
@@ -160,7 +161,7 @@ static void engine_write_cmd(struct engine* engine, int8_t cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void engine_set_input(struct engine* engine, input_queue_t* inputQueue) {
|
static void engine_set_input(struct engine* engine, AInputQueue* inputQueue) {
|
||||||
pthread_mutex_lock(&engine->mutex);
|
pthread_mutex_lock(&engine->mutex);
|
||||||
engine->inputQueue = inputQueue;
|
engine->inputQueue = inputQueue;
|
||||||
engine_write_cmd(engine, ENGINE_CMD_GAIN_INPUT);
|
engine_write_cmd(engine, ENGINE_CMD_GAIN_INPUT);
|
||||||
@@ -190,78 +191,78 @@ static void engine_destroy(struct engine* engine) {
|
|||||||
pthread_mutex_destroy(&engine->mutex);
|
pthread_mutex_destroy(&engine->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onDestroy(android_activity_t* activity)
|
static void onDestroy(ANativeActivity* activity)
|
||||||
{
|
{
|
||||||
LOGI("Destroy: %p\n", activity);
|
LOGI("Destroy: %p\n", activity);
|
||||||
engine_destroy((struct engine*)activity->instance);
|
engine_destroy((struct engine*)activity->instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onStart(android_activity_t* activity)
|
static void onStart(ANativeActivity* activity)
|
||||||
{
|
{
|
||||||
LOGI("Start: %p\n", activity);
|
LOGI("Start: %p\n", activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onResume(android_activity_t* activity)
|
static void onResume(ANativeActivity* activity)
|
||||||
{
|
{
|
||||||
LOGI("Resume: %p\n", activity);
|
LOGI("Resume: %p\n", activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* onSaveInstanceState(android_activity_t* activity, size_t* outLen)
|
static void* onSaveInstanceState(ANativeActivity* activity, size_t* outLen)
|
||||||
{
|
{
|
||||||
LOGI("SaveInstanceState: %p\n", activity);
|
LOGI("SaveInstanceState: %p\n", activity);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onPause(android_activity_t* activity)
|
static void onPause(ANativeActivity* activity)
|
||||||
{
|
{
|
||||||
LOGI("Pause: %p\n", activity);
|
LOGI("Pause: %p\n", activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onStop(android_activity_t* activity)
|
static void onStop(ANativeActivity* activity)
|
||||||
{
|
{
|
||||||
LOGI("Stop: %p\n", activity);
|
LOGI("Stop: %p\n", activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onLowMemory(android_activity_t* activity)
|
static void onLowMemory(ANativeActivity* activity)
|
||||||
{
|
{
|
||||||
LOGI("LowMemory: %p\n", activity);
|
LOGI("LowMemory: %p\n", activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onWindowFocusChanged(android_activity_t* activity, int focused)
|
static void onWindowFocusChanged(ANativeActivity* activity, int focused)
|
||||||
{
|
{
|
||||||
LOGI("WindowFocusChanged: %p -- %d\n", activity, focused);
|
LOGI("WindowFocusChanged: %p -- %d\n", activity, focused);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onSurfaceCreated(android_activity_t* activity, android_surface_t* surface)
|
static void onSurfaceCreated(ANativeActivity* activity, ASurfaceHolder* surface)
|
||||||
{
|
{
|
||||||
LOGI("SurfaceCreated: %p -- %p\n", activity, surface);
|
LOGI("SurfaceCreated: %p -- %p\n", activity, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onSurfaceChanged(android_activity_t* activity, android_surface_t* surface,
|
static void onSurfaceChanged(ANativeActivity* activity, ASurfaceHolder* surface,
|
||||||
int format, int width, int height)
|
int format, int width, int height)
|
||||||
{
|
{
|
||||||
LOGI("SurfaceChanged: %p -- %p fmt=%d w=%d h=%d\n", activity, surface,
|
LOGI("SurfaceChanged: %p -- %p fmt=%d w=%d h=%d\n", activity, surface,
|
||||||
format, width, height);
|
format, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onSurfaceDestroyed(android_activity_t* activity, android_surface_t* surface)
|
static void onSurfaceDestroyed(ANativeActivity* activity, ASurfaceHolder* surface)
|
||||||
{
|
{
|
||||||
LOGI("SurfaceDestroyed: %p -- %p\n", activity, surface);
|
LOGI("SurfaceDestroyed: %p -- %p\n", activity, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onInputQueueCreated(android_activity_t* activity, input_queue_t* queue)
|
static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue)
|
||||||
{
|
{
|
||||||
LOGI("InputQueueCreated: %p -- %p\n", activity, queue);
|
LOGI("InputQueueCreated: %p -- %p\n", activity, queue);
|
||||||
engine_set_input((struct engine*)activity->instance, queue);
|
engine_set_input((struct engine*)activity->instance, queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onInputQueueDestroyed(android_activity_t* activity, input_queue_t* queue)
|
static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue)
|
||||||
{
|
{
|
||||||
LOGI("InputQueueDestroyed: %p -- %p\n", activity, queue);
|
LOGI("InputQueueDestroyed: %p -- %p\n", activity, queue);
|
||||||
engine_clear_input((struct engine*)activity->instance);
|
engine_clear_input((struct engine*)activity->instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void android_onCreateActivity(android_activity_t* activity,
|
void ANativeActivity_onCreate(ANativeActivity* activity,
|
||||||
void* savedState, size_t savedStateSize)
|
void* savedState, size_t savedStateSize)
|
||||||
{
|
{
|
||||||
LOGI("Creating: %p\n", activity);
|
LOGI("Creating: %p\n", activity);
|
||||||
|
|||||||
Reference in New Issue
Block a user