improve for android

This commit is contained in:
xianjimli 2019-08-03 10:53:19 +08:00
parent 181ec11071
commit 7d1d384122
8 changed files with 46 additions and 39 deletions

View File

@ -389,7 +389,7 @@
#include "assets/inc/images/arrow_left_n.data"
#include "assets/inc/images/edit_clear_p.data"
#include "assets/inc/images/battery_2.data"
#endif/*WITH_STB_IMAGE*/
#endif /*WITH_STB_IMAGE*/
#ifdef WITH_VGCANVAS
#include "assets/inc/images/pointer_4.bsvg"
#include "assets/inc/images/ball.bsvg"
@ -397,13 +397,13 @@
#include "assets/inc/images/pointer_1.bsvg"
#include "assets/inc/images/pointer.bsvg"
#include "assets/inc/images/girl.bsvg"
#endif/*WITH_VGCANVAS*/
#endif /*WITH_VGCANVAS*/
#if defined(WITH_STB_FONT) || defined(WITH_FT_FONT)
#include "assets/inc/fonts/default.res"
#else/*WITH_STB_FONT or WITH_FT_FONT*/
#else /*WITH_STB_FONT or WITH_FT_FONT*/
#include "assets/inc/fonts/default.data"
#endif/*WITH_STB_FONT or WITH_FT_FONT*/
#endif/*WITH_FS_RES*/
#endif /*WITH_STB_FONT or WITH_FT_FONT*/
#endif /*WITH_FS_RES*/
ret_t assets_init(void) {
assets_manager_t* rm = assets_manager();
@ -685,7 +685,7 @@ ret_t assets_init(void) {
assets_manager_add(rm, image_pointer_1);
assets_manager_add(rm, image_pointer);
assets_manager_add(rm, image_girl);
#endif/*WITH_VGCANVAS*/
#endif /*WITH_VGCANVAS*/
#endif
tk_init_assets();

View File

@ -32,6 +32,12 @@ ret_t application_init(void);
#ifdef USE_GUI_MAIN
int gui_app_start(int lcd_w, int lcd_h) {
tk_init(lcd_w, lcd_h, APP_MOBILE, NULL, NULL);
#elif defined(MOBILE_APP)
int SDL_main(int argc, char* argv[]) {
int32_t lcd_w = 320;
int32_t lcd_h = 480;
tk_init(lcd_w, lcd_h, APP_MOBILE, "", "");
system_info_set_default_font(system_info(), "default_full");
#else
#if defined(WIN32)
@ -39,10 +45,6 @@ int gui_app_start(int lcd_w, int lcd_h) {
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) {
int32_t lcd_w = 320;
int32_t lcd_h = 480;
#elif defined(ANDROID)
int SDL_main(int argc, char* argv[]) {
int32_t lcd_w = 320;
int32_t lcd_h = 480;
#else
int main(int argc, char* argv[]) {
int32_t lcd_w = 320;

View File

@ -1,14 +1,17 @@
# 最新动态
* 2019/08/03
* 完善Android移植。
* 2019/07/20-8/1
* window manager抽象成接口。
* 引入native\_window接口。
* 2019/07/29
* fix edit clone的问题。
* 2019/08/02
* 禁用label/button/image/hscroll\_label的缓存。
* 2019/07/29
* fix edit clone的问题。
* 2019/07/26
* 完善text edit(感谢智明提供补丁)

View File

@ -178,7 +178,7 @@ ret_t native_window_clear_dirty_rect(native_window_t* win) {
ret_t native_window_preprocess_event(native_window_t* win, event_t* e) {
return_value_if_fail(win != NULL && win->vt != NULL && e != NULL, RET_BAD_PARAMS);
if(win->vt->preprocess_event != NULL) {
if (win->vt->preprocess_event != NULL) {
win->vt->preprocess_event(win, e);
}

View File

@ -22,7 +22,7 @@
#include "base/system_info.h"
#include "input_method_null.inc"
#if !defined(WITH_NULL_IM)
#if !defined(WITH_NULL_IM) && !defined(MOBILE_APP)
#include "input_method_default.inc"
#endif /**/
@ -42,11 +42,15 @@ input_method_t* input_method_create(void) {
#elif defined(AWTK_WEB)
im = input_method_web_create();
#elif defined(WITH_SDL)
if (system_info()->app_type == APP_DESKTOP) {
im = input_method_sdl_create();
} else {
#if defined(MOBILE_APP)
im = input_method_sdl_create();
#else
if (system_info()->app_type == APP_SIMULATOR) {
im = input_method_default_create();
} else {
im = input_method_sdl_create();
}
#endif /*MOBILE_APP*/
#else
im = input_method_default_create();
#endif /*WITH_SDL*/

View File

@ -83,7 +83,7 @@ static ret_t native_window_sdl_resize(native_window_t* win, wh_t w, wh_t h) {
if (w != oldw || h != oldh) {
SDL_SetWindowSize(sdl->window, w, h);
}
#endif/*ANDROID*/
#endif /*ANDROID*/
return RET_OK;
}
@ -150,20 +150,18 @@ static ret_t native_window_sdl_swap_buffer(native_window_t* win) {
static ret_t native_window_sdl_preprocess_event(native_window_t* win, event_t* e) {
#ifdef ANDROID
if(e->type == EVT_POINTER_DOWN
|| e->type == EVT_POINTER_MOVE
|| e->type == EVT_CLICK
|| e->type == EVT_POINTER_UP) {
if (e->type == EVT_POINTER_DOWN || e->type == EVT_POINTER_MOVE || e->type == EVT_CLICK ||
e->type == EVT_POINTER_UP) {
pointer_event_t* evt = pointer_event_cast(e);
evt->x /= win->ratio;
evt->y /= win->ratio;
} else if(e->type == EVT_KEY_DOWN) {
} else if (e->type == EVT_KEY_DOWN) {
key_event_t* evt = key_event_cast(e);
if(evt->key == TK_KEY_AC_BACK) {
if (evt->key == TK_KEY_AC_BACK) {
window_manager_back(window_manager());
}
}
#endif/*ANDROID*/
#endif /*ANDROID*/
return RET_OK;
}
@ -187,12 +185,12 @@ static ret_t native_window_sdl_get_info(native_window_t* win, native_window_info
#ifdef ANDROID
float dpi = 1;
SDL_GetDisplayDPI(0, &dpi, NULL, NULL);
float_t ratio = dpi/160;
float_t ratio = dpi / 160;
info->x = x;
info->y = y;
info->w = ww/ratio;
info->h = wh/ratio;
info->w = ww / ratio;
info->h = wh / ratio;
info->ratio = ratio;
#else
info->x = x;
@ -200,7 +198,7 @@ static ret_t native_window_sdl_get_info(native_window_t* win, native_window_info
info->w = ww;
info->h = wh;
info->ratio = (float_t)fw / (float_t)ww;
#endif/**/
#endif /**/
win->rect.x = info->x;
win->rect.y = info->y;
@ -302,11 +300,11 @@ static native_window_t* native_window_create_internal(const char* title, uint32_
win->handle = sdl->window;
win->vt = &s_native_window_vtable;
if(native_window_get_info(win, &info) == RET_OK) {
w = info.w;
h = info.h;
}
win->rect = rect_init(x, y, w, h);
if (native_window_get_info(win, &info) == RET_OK) {
w = info.w;
h = info.h;
}
win->rect = rect_init(x, y, w, h);
#ifdef WITH_NANOVG_GL
sdl->context = SDL_GL_CreateContext(sdl->window);
SDL_GL_SetSwapInterval(1);

View File

@ -165,7 +165,7 @@ typedef enum _ret_t {
#include "android/log.h"
#define log_debug(...) __android_log_print(ANDROID_LOG_DEBUG, "AWTK", __VA_ARGS__)
#define log_info(...) __android_log_print(ANDROID_LOG_INFO, "AWTK", __VA_ARGS__)
#define log_warn(...) __android_log_print(ANDROID_LOG_WARN, "AWTK", __VA_ARGS__)
#define log_warn(...) __android_log_print(ANDROID_LOG_WARN, "AWTK", __VA_ARGS__)
#define log_error(...) __android_log_print(ANDROID_LOG_ERROR, "AWTK", __VA_ARGS__)
#elif defined(WIN32)
#include <windows.h>

View File

@ -617,7 +617,7 @@ static ret_t window_manager_paint_animation(widget_t* widget, canvas_t* c) {
return RET_OK;
}
#endif/*WITH_WINDOW_ANIMATORS*/
#endif /*WITH_WINDOW_ANIMATORS*/
static ret_t window_manager_default_inc_fps(widget_t* widget) {
window_manager_default_t* wm = WINDOW_MANAGER_DEFAULT(widget);
@ -663,7 +663,7 @@ static ret_t window_manager_default_paint(widget_t* widget) {
}
#else
ret = window_manager_paint_normal(widget, c);
#endif/*WITH_WINDOW_ANIMATORS*/
#endif /*WITH_WINDOW_ANIMATORS*/
return ret;
}
@ -908,7 +908,7 @@ static ret_t window_manager_default_post_init(widget_t* widget, wh_t w, wh_t h)
wm->lcd_h = h;
wm->native_window = native_window_create(widget);
if(native_window_get_info(wm->native_window, &info) == RET_OK) {
if (native_window_get_info(wm->native_window, &info) == RET_OK) {
w = info.w;
h = info.h;
}