android_app_NativeActivity.h revision d76b67c340d1564abf8d14d976fdaf83bf2b3320
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _ANDROID_APP_NATIVEACTIVITY_H
18#define _ANDROID_APP_NATIVEACTIVITY_H
19
20#include <ui/InputTransport.h>
21
22#include <android/native_activity.h>
23
24#include "jni.h"
25
26namespace android {
27
28extern void android_NativeActivity_setWindowFormat(
29        ANativeActivity* activity, int32_t format);
30
31extern void android_NativeActivity_setWindowFlags(
32        ANativeActivity* activity, int32_t values, int32_t mask);
33
34extern void android_NativeActivity_showSoftInput(
35        ANativeActivity* activity, int32_t flags);
36
37extern void android_NativeActivity_hideSoftInput(
38        ANativeActivity* activity, int32_t flags);
39
40} // namespace android
41
42
43/*
44 * NDK input queue API.
45 */
46struct AInputQueue {
47public:
48    /* Creates a consumer associated with an input channel. */
49    explicit AInputQueue(const android::sp<android::InputChannel>& channel, int workWrite);
50
51    /* Destroys the consumer and releases its input channel. */
52    ~AInputQueue();
53
54    void attachLooper(ALooper* looper, ALooper_callbackFunc* callback, void* data);
55
56    void detachLooper();
57
58    int32_t hasEvents();
59
60    int32_t getEvent(AInputEvent** outEvent);
61
62    void finishEvent(AInputEvent* event, bool handled);
63
64
65    // ----------------------------------------------------------
66
67    inline android::InputConsumer& getConsumer() { return mConsumer; }
68
69    void dispatchEvent(android::KeyEvent* event);
70
71    android::KeyEvent* consumeUnhandledEvent();
72
73    int mWorkWrite;
74
75private:
76    void doDefaultKey(android::KeyEvent* keyEvent);
77
78    android::InputConsumer mConsumer;
79    android::PreallocatedInputEventFactory mInputEventFactory;
80    android::sp<android::PollLoop> mPollLoop;
81
82    int mDispatchKeyRead;
83    int mDispatchKeyWrite;
84
85    // This is only touched by the event reader thread.  It is the current
86    // key events that came out of the mDispatchingKeys list and are now
87    //�delivered to the app.
88    android::Vector<android::KeyEvent*> mDeliveringKeys;
89
90    android::Mutex mLock;
91    android::Vector<android::KeyEvent*> mPendingKeys;
92    android::Vector<android::KeyEvent*> mDispatchingKeys;
93};
94
95#endif // _ANDROID_APP_NATIVEACTIVITY_H
96