YSTest: Android.cpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

Android.cpp
浏览该文件的文档.
1 /*
2 © 2014-2015 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
29 #include "YCLib/YModules.h"
30 #include YFM_YCLib_Platform
31 #if YCL_Android
32 # include YFM_Android_YCLib_Android
33 # include <android/native_activity.h>
34 # include <android/configuration.h>
35 #endif
36 #include "YSLib/Service/YModules.h"
37 #include YFM_YCLib_Input // for platform::SaveInput;
38 #include YFM_YSLib_Core_YCoreUtilities // for YSLib::CheckPositiveScalar;
39
40 using namespace YSLib;
41 using namespace Drawing;
42
43 namespace platform_ex
44 {
45
46 #if YCL_Android
47
48 namespace Android
49 {
50
51 InputQueue::InputQueue(::ALooper& looper, ::AInputQueue& input_queue)
52 : queue_ref(input_queue)
53 {
54 YTraceDe(Debug, "Attaching input queue to looper.");
55 ::AInputQueue_attachLooper(&input_queue, &looper, ALOOPER_POLL_CALLBACK,
56 [](int, int, void* p_data){
57 auto& q(Deref(static_cast<InputQueue*>(p_data)));
58 ::AInputEvent* p_evt{};
59 const auto p_queue(&q.queue_ref.get());
60
61 while(::AInputQueue_getEvent(p_queue, &p_evt) >= 0)
62 {
63 YTraceDe(Debug, "New input event: type = %d.",
64 ::AInputEvent_getType(Nonnull(p_evt)));
65 if(::AInputQueue_preDispatchEvent(p_queue, p_evt))
66 continue;
67 SaveInput(*p_evt);
68 ::AInputQueue_finishEvent(p_queue, p_evt,
69 ::AInputEvent_getType(p_evt) == AINPUT_EVENT_TYPE_MOTION);
70 }
71 return 1;
72 }, this);
73 }
74 InputQueue::~InputQueue()
75 {
76 ::AInputQueue_detachLooper(&queue_ref.get());
77 }
78
79
80 ::ALooper&
81 FetchNativeLooper(bool allow_non_callbacks)
82 {
83 const auto p(::ALooper_prepare(allow_non_callbacks
84 ? ALOOPER_PREPARE_ALLOW_NON_CALLBACKS : 0));
85
86 if(YB_LIKELY(p))
87 return *p;
88 throw std::runtime_error("Failed get native looper pointer.");
89 }
90
91 void
92 TraceConfiguration(::AConfiguration& cfg, platform::Logger::Level lv)
93 {
94 char lang[2], country[2];
95
96 ::AConfiguration_getLanguage(&cfg, lang);
97 ::AConfiguration_getCountry(&cfg, country);
98 YTraceDe(lv, "Configuration: MCC = %d, MNC = %d, language code = %c%c,"
99 " country = %c%c, orientation = %d, touch screen = %d, density = %d, "
100 " keyboard = %d, navigation = %d, keysHidden = %d, navHidden = %d,"
101 " SDK version = %d, screen size = %d, screen long = %d,"
102 " UI mode type = %d, UI mode night = %d.",
103 int(::AConfiguration_getMcc(&cfg)), int(::AConfiguration_getMnc(&cfg)),
104 lang[0], lang[1], country[0], country[1],
105 int(::AConfiguration_getOrientation(&cfg)),
106 int(::AConfiguration_getTouchscreen(&cfg)),
107 int(::AConfiguration_getDensity(&cfg)),
108 int(::AConfiguration_getKeyboard(&cfg)),
109 int(::AConfiguration_getNavigation(&cfg)),
110 int(::AConfiguration_getKeysHidden(&cfg)),
111 int(::AConfiguration_getNavHidden(&cfg)),
112 int(::AConfiguration_getSdkVersion(&cfg)),
113 int(::AConfiguration_getScreenSize(&cfg)),
114 int(::AConfiguration_getScreenLong(&cfg)),
115 int(::AConfiguration_getUiModeType(&cfg)),
116 int(::AConfiguration_getUiModeNight(&cfg)));
117 }
118
119 } // namespace Android;
120
121 #endif
122
123 } // namespace platform_ex;
124
platform_ex::Android::TraceConfiguration
YF_API void TraceConfiguration(::AConfiguration &, platform::Logger::Level=platform::Descriptions::Notice)
platform::p
while p p
Definition: YCLib/FileSystem.h:225
YSLib::lv
RecordLevel lv
Definition: YException.cpp:58
platform::Nonnull
_type && Nonnull(_type &&p) ynothrow
断言并返回非空指针。
Definition: Debug.h:411
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
platform_ex::Android::FetchNativeLooper
YF_API::ALooper & FetchNativeLooper(bool)
取当前线程的本机消息循环。
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:305
YModules.h
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:440
platform_ex
平台扩展命名空间。
Definition: Android.h:45
Drawing
YModules.h
platform::Descriptions::Debug
Definition: YCommon.h:160
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:437
platform::Descriptions::RecordLevel
RecordLevel
记录等级。
Definition: YCommon.h:151