diff --git a/docs/html/OPTIONS.html b/docs/html/OPTIONS.html index d4b015358..6089fde73 100644 --- a/docs/html/OPTIONS.html +++ b/docs/html/OPTIONS.html @@ -105,8 +105,26 @@ New Breed Software

Be sure to save it as Plain Text, and make sure the filename doesn't have ".txt" at the end...

- + +

Android Users

+
+

The file you should create is called + "tuxpaint.cfg" and it should be + placed in your external sdcard folder, under the sub-folder: + /mnt/sdcard/Android/data/org.tuxpaint/files/tuxpaint.cfg + +

System-Wide Configuration File +
+

Before this file is read, an internal configuration file is read. + (By default, this configuration has no settings enabled.) It is + located at:

+ +
+ /data/data/org.tuxpaint/files/tuxpaint.cfg/code> +
+
+


Available Options

diff --git a/src/fonts.c b/src/fonts.c index 4c853edd3..5d757bd2c 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -976,6 +976,8 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer loadfonts(screen, texture, renderer, macosx.fontsPath); loadfonts(screen, texture, renderer, "/usr/share/fonts"); loadfonts(screen, texture, renderer, "/usr/X11R6/lib/X11/fonts"); +#elif defined(__ANDROID__) + loadfonts(screen, texture, renderer, "/system/fonts"); #elif defined(__sun__) loadfonts(screen, texture, renderer, "/usr/openwin/lib/X11/fonts"); loadfonts(screen, texture, renderer, "/usr/share/fonts"); diff --git a/src/i18n.c b/src/i18n.c index 0c1a76be2..39eea4c22 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -47,6 +47,29 @@ #include #endif +#ifdef __ANDROID__ +#include "SDL2/SDL.h" +#include "jni.h" +// since setlocale on the Android is not supported well, +// setlocale cannot get current default locale of the device. +// Here, JNI and Java Locale class can get the default locale +// if user has not set locale and lang in the config file yet. +static char * android_locale () +{ + static char android_locale_buf[32]; + JNIEnv *mEnv = Android_JNI_GetEnv(); + jclass mLocaleClass = (*mEnv)->FindClass(mEnv, "java/util/Locale"); + jmethodID mGetDefaultMethod = (*mEnv)->GetStaticMethodID(mEnv, mLocaleClass, "getDefault", "()Ljava/util/Locale;"); + jobject mLocaleObject = (*mEnv)->CallStaticObjectMethod(mEnv, mLocaleClass, mGetDefaultMethod); + jmethodID mToStringMethod = (*mEnv)->GetMethodID(mEnv, mLocaleClass, "toString", "()Ljava/lang/String;"); + jstring mLocaleString = (*mEnv)->CallObjectMethod(mEnv, mLocaleObject, mToStringMethod); + const char* locale = (*mEnv)->GetStringUTFChars(mEnv, mLocaleString, 0); + strcpy(android_locale_buf, locale); + (*mEnv)->ReleaseStringUTFChars(mEnv, mLocaleString, locale); + printf("android locale %s\n", android_locale_buf); + return android_locale_buf; +} +#endif /* Globals: */ @@ -974,7 +997,7 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP loc = setlocale(LC_MESSAGES, NULL); #endif - if (strcmp(oldloc, "") != 0 && strcmp(loc, oldloc) != 0) { + if (oldloc && loc && strcmp(oldloc, "") != 0 && strcmp(loc, oldloc) != 0) { /* System doesn't recognize that locale! Hack, per Albert C., is to set LC_ALL to a valid UTF-8 locale, then set LANGUAGE to the locale we want to force -bjk 2010.10.05 */ /* Albert's comments from December 2009: @@ -1103,14 +1126,21 @@ int setup_i18n(const char *restrict lang, const char *restrict locale) exit(0); } } - else - locale = ""; if(lang) locale = language_to_locale(lang); + #ifdef __APPLE__ patch_i18n(locale); //EP #endif + +#ifdef __ANDROID__ + if(locale == NULL) + locale = android_locale(); +#endif + + if(locale == NULL) + locale = ""; return set_current_language(locale); } diff --git a/src/im.c b/src/im.c index 27b0500ed..4b0587c2e 100644 --- a/src/im.c +++ b/src/im.c @@ -41,9 +41,12 @@ #include #include #include - +#include #include "im.h" +#ifdef __ANDROID__ +#include "android_mbstowcs.h" +#endif /* *************************************************************************** @@ -673,9 +676,9 @@ static int im_event_c(IM_DATA* im, SDL_Event event) /* Handle key stroke */ switch(ks.sym) { - case SDLK_BACKSPACE: im->s[0] = L'\b'; break; - case SDLK_TAB: im->s[0] = L'\t'; break; - case SDLK_RETURN: im->s[0] = L'\r'; break; + case SDLK_BACKSPACE: im->s[0] = L'\b'; im->s[1] = L'\0'; break; + case SDLK_TAB: im->s[0] = L'\t'; im->s[1] = L'\0'; break; + case SDLK_RETURN: im->s[0] = L'\r'; im->s[1] = L'\0'; break; default: mbstowcs(im->s , event.text.text, 16); //default: wcsncpy(im->s , event.text.text, 16); } @@ -960,8 +963,7 @@ static int im_event_zh_tw(IM_DATA* im, SDL_Event event) /* ZH_TW mode */ else { - wchar_t u; - mbtowc(&u, event.text.text, 255); + wchar_t u = event.text.text[0]; im->s[0] = L'\0'; /* Zero-out output string */ wcsncat(im->buf, &u, 1); /* Copy new character */ @@ -1717,7 +1719,7 @@ void im_init(IM_DATA* im, int lang) #ifdef DEBUG assert(0 <= im->lang && im->lang < NUM_LANGS); - if(im_event_fp) printf("Initializing IM for %s...\n", lang_prefixes[im->lang]); + if(im_initialized) printf("Initializing IM for %s...\n", lang_prefixes[im->lang]); #endif /* Initialize the individual IM */ diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 4e76d8933..90361c5b7 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -20127,14 +20127,17 @@ static int do_color_sel(void) done = 0; chose = 0; x = y = 0; +#ifndef __ANDROID__ + /* FIXME: Strangely, this SDL_WarpMouse makes further event.button.x/y to be 0 on Android, thus making the selector unresponsive. + Needs testing on other operating sistems with touchscreen. */ SDL_WarpMouse(r_color_sel.x + r_color_sel.w / 2, r_color_sel.y + r_color_sel.h / 2); - +#endif do { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) - { + { chose = 0; done = 1; } @@ -20162,7 +20165,7 @@ static int do_color_sel(void) } else if (event.type == SDL_MOUSEBUTTONUP && valid_click(event.button.button)) - { + { if (event.button.x >= r_canvas.x && event.button.x < r_canvas.x + r_canvas.w && event.button.y >= r_canvas.y &&