Syncing with the android version...

This commit is contained in:
Pere Pujal i Carabantes 2016-10-07 00:15:40 +02:00
parent b6c191fec9
commit ede838caf9
5 changed files with 69 additions and 14 deletions

View file

@ -105,8 +105,26 @@ New Breed Software</p>
Be sure to save it as Plain Text, and make sure the filename
doesn't have ".txt" at the end...</p>
</blockquote>
</blockquote>
<h2>Android Users</h2>
<blockquote>
<p>The file you should create is called
"<code><b>tuxpaint.cfg</b></code>" and it should be
placed in your external sdcard folder, under the sub-folder:
<code>/mnt/sdcard/Android/data/org.tuxpaint/files/tuxpaint.cfg</code>
<h3>System-Wide Configuration File
<blockquote>
<p>Before this file is read, an internal configuration file is read.
(By default, this configuration has no settings enabled.) It is
located at:</p>
<blockquote>
<code>/data/data/org.tuxpaint/files/tuxpaint.cfg/code>
</blockquote>
</blockquote>
</blockquote>
<hr size=2 noshade>
<h1>Available Options</h1>

View file

@ -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");

View file

@ -47,6 +47,29 @@
#include <wctype.h>
#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);
}

View file

@ -41,9 +41,12 @@
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <assert.h>
#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 */

View file

@ -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 &&