Fix:Android:Various issues
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 31 Dec 2010 18:00:54 +0000 (18:00 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 31 Dec 2010 18:00:54 +0000 (18:00 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3843 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/android.c
navit/navit/android.h
navit/navit/android/AndroidManifest.xml.in
navit/navit/android/src/org/navitproject/navit/Navit.java
navit/navit/android/src/org/navitproject/navit/NavitActivityResult.java [new file with mode: 0644]
navit/navit/android/src/org/navitproject/navit/NavitGraphics.java
navit/navit/android/src/org/navitproject/navit/NavitSpeech.java
navit/navit/android/src/org/navitproject/navit/NavitSpeech2.java [new file with mode: 0644]
navit/navit/speech/android/speech_android.c

index b44acb3..c7eafda 100644 (file)
@@ -9,6 +9,7 @@
 JNIEnv *jnienv;
 jobject *android_activity;
 struct callback_list *android_activity_cbl;
+int android_version;
 
 
 int
@@ -46,17 +47,18 @@ android_find_static_method(jclass class, char *name, char *args, jmethodID *ret)
 }
 
 JNIEXPORT void JNICALL
-Java_org_navitproject_navit_Navit_NavitMain( JNIEnv* env, jobject thiz, jobject activity, jobject lang)
+Java_org_navitproject_navit_Navit_NavitMain( JNIEnv* env, jobject thiz, jobject activity, jobject lang, int version)
 {
        char *strings[]={"/data/data/org.navitproject.navit/bin/navit",NULL};
        char *langstr;
+       android_version=version;
        __android_log_print(ANDROID_LOG_ERROR,"test","called");
        android_activity_cbl=callback_list_new();
        jnienv=env;
        android_activity=activity;
        (*jnienv)->NewGlobalRef(jnienv, activity);
        langstr=(*env)->GetStringUTFChars(env, lang, NULL);
-       dbg(0,"enter env=%p thiz=%p activity=%p lang=%s\n",env,thiz,activity,langstr);
+       dbg(0,"enter env=%p thiz=%p activity=%p lang=%s version=%d\n",env,thiz,activity,langstr,version);
        setenv("LANG",langstr,1);
        (*env)->ReleaseStringUTFChars(env, lang, langstr);
        main_real(1, strings);
index 83432a2..6fefd4b 100644 (file)
@@ -2,6 +2,7 @@
 extern JNIEnv *jnienv;
 extern jobject *android_activity;
 extern struct callback_list *android_activity_cbl;
+extern int android_version;
 int android_find_class_global(char *name, jclass *ret);
 int android_find_method(jclass class, char *name, char *args, jmethodID *ret);
 int android_find_static_method(jclass class, char *name, char *args, jmethodID *ret);
index 060f63e..1e361ab 100644 (file)
@@ -1,9 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="org.navitproject.navit"
+      android:sharedUserId="org.navitproject.navit"
       android:versionCode="1"
       android:versionName="1.0">
     <uses-sdk android:minSdkVersion="3" />
+    <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.INTERNET" />
index d182a9f..3e9c790 100644 (file)
@@ -27,6 +27,7 @@ import android.os.Message;
 import android.os.Handler;
 import android.os.PowerManager;
 import android.content.Context;
+import android.content.Intent;
 import android.content.res.Resources;
 import android.util.Log;
 import java.util.Locale;
@@ -40,6 +41,7 @@ public class Navit extends Activity implements Handler.Callback
 {
     public Handler handler;
     private PowerManager.WakeLock wl;
+    private NavitActivityResult ActivityResults[];
     private boolean extractRes(String resname, String result)
     {
        int slash=-1;
@@ -124,6 +126,7 @@ public class Navit extends Activity implements Handler.Callback
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
+        ActivityResults=new NavitActivityResult[16];
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);  
        wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen"); 
        Locale locale=java.util.Locale.getDefault();
@@ -148,7 +151,7 @@ public class Navit extends Activity implements Handler.Callback
                Log.e("Navit","Failed to extract navit.xml");
        }
        // Debug.startMethodTracing("calc");
-        NavitMain(this, langu);
+        NavitMain(this, langu, android.os.Build.VERSION.SDK_INT);
        NavitActivity(3);
     }
     @Override public void onStart()
@@ -188,6 +191,17 @@ public class Navit extends Activity implements Handler.Callback
        NavitActivity(-3);
     }
 
+    protected void onActivityResult(int requestCode, int resultCode, Intent data)
+    {
+       Log.e("Navit","onActivityResult "+requestCode+" "+resultCode);
+       ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data);
+    }
+    public void setActivityResult(int requestCode, NavitActivityResult ActivityResult) 
+    {
+        ActivityResults[requestCode]=ActivityResult;
+    }
+
+
     public void disableSuspend()
     {
        wl.acquire();
@@ -208,7 +222,7 @@ public class Navit extends Activity implements Handler.Callback
      * 'hello-jni' native library, which is packaged
      * with this application.
      */
-    public native void NavitMain(Navit x, String lang);
+    public native void NavitMain(Navit x, String lang, int version);
     public native void NavitActivity(int activity);
 
     /* this is used to load the 'hello-jni' library on application
diff --git a/navit/navit/android/src/org/navitproject/navit/NavitActivityResult.java b/navit/navit/android/src/org/navitproject/navit/NavitActivityResult.java
new file mode 100644 (file)
index 0000000..63b4e79
--- /dev/null
@@ -0,0 +1,6 @@
+package org.navitproject.navit;
+import android.content.Intent;
+
+public interface NavitActivityResult {
+    public void onActivityResult(int requestCode, int resultCode, Intent data);
+};
index 6af1c86..f343a6d 100644 (file)
@@ -296,6 +296,7 @@ public class NavitGraphics {
                float fy=y;
                // Log.e("NavitGraphics","Text size "+size + " vs " + paint.getTextSize());
                paint.setTextSize((float)size/15);
+               paint.setStyle(Paint.Style.FILL);
                if (dx == 0x10000 && dy == 0) {
                        draw_canvas.drawText(text, fx, fy, paint);
                } else {
index 71b0314..543fa33 100644 (file)
@@ -37,13 +37,13 @@ public class NavitSpeech implements Runnable {
        private String what;
        private Thread thread;
 
-       NavitSpeech(Context context) 
+       NavitSpeech(Navit navit) 
        {
                ttsInitListener = new TTS.InitListener() {
                        public void onInit(int version) {
                        }
                };
-               tts=new TTS(context, ttsInitListener, true);
+               tts=new TTS(navit, ttsInitListener, true);
        }
        public void run()
        {
diff --git a/navit/navit/android/src/org/navitproject/navit/NavitSpeech2.java b/navit/navit/android/src/org/navitproject/navit/NavitSpeech2.java
new file mode 100644 (file)
index 0000000..b8f6191
--- /dev/null
@@ -0,0 +1,78 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+package org.navitproject.navit;
+
+import java.lang.Thread;
+import android.app.Activity;
+import android.widget.TextView;
+import android.os.Bundle;
+import android.os.Debug;
+import android.os.Message;
+import android.os.Handler;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+import android.speech.tts.TextToSpeech;
+
+
+public class NavitSpeech2 implements TextToSpeech.OnInitListener, NavitActivityResult {
+       private TextToSpeech mTts;
+       private Navit navit;
+       int MY_DATA_CHECK_CODE=1;
+
+
+       public void onInit(int status)
+       {
+               Log.e("NavitSpeech2","Status "+status);
+       }
+
+       public void onActivityResult(int requestCode, int resultCode, Intent data)
+       {
+               Log.e("NavitSpeech2","onActivityResult "+requestCode+" "+resultCode);
+               if (requestCode == MY_DATA_CHECK_CODE) {
+                       if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
+                               // success, create the TTS instance
+                               mTts = new TextToSpeech(navit, this);
+                       } else {
+                               // missing data, install it
+                               Intent installIntent = new Intent();
+                               installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
+                               navit.startActivity(installIntent);
+                       }
+               }
+       }
+
+       NavitSpeech2(Navit navit)
+       {
+               this.navit=navit;
+               navit.setActivityResult(1, this);
+               Log.e("NavitSpeech2","Create");
+               Intent checkIntent = new Intent();
+               checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
+               navit.startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
+       }
+       public void say(String what)
+       {
+               if (mTts != null) {
+                       mTts.speak(what, TextToSpeech.QUEUE_FLUSH, null);
+               }
+       }
+}
+
index d1c4f96..8debfe9 100644 (file)
@@ -30,6 +30,7 @@ struct speech_priv {
        jclass NavitSpeechClass;
        jobject NavitSpeech;
        jmethodID NavitSpeech_say;
+       int flags;
 };
 
 static int 
@@ -39,34 +40,36 @@ speech_android_say(struct speech_priv *this, const char *text)
        jstring string;
        int i;
 
-       for (i = 0 ; i < strlen(str) ; i++) {
-               if (str[i] == 0xc3 && str[i+1] == 0x84) {
-                       str[i]='A';
-                       str[i+1]='e';
-               }
-               if (str[i] == 0xc3 && str[i+1] == 0x96) {
-                       str[i]='O';
-                       str[i+1]='e';
-               }
-               if (str[i] == 0xc3 && str[i+1] == 0x9c) {
-                       str[i]='U';
-                       str[i+1]='e';
-               }
-               if (str[i] == 0xc3 && str[i+1] == 0xa4) {
-                       str[i]='a';
-                       str[i+1]='e';
-               }
-               if (str[i] == 0xc3 && str[i+1] == 0xb6) {
-                       str[i]='o';
-                       str[i+1]='e';
-               }
-               if (str[i] == 0xc3 && str[i+1] == 0xbc) {
-                       str[i]='u';
-                       str[i+1]='e';
-               }
-               if (str[i] == 0xc3 && str[i+1] == 0x9f) {
-                       str[i]='s';
-                       str[i+1]='s';
+       if (this->flags & 2) {
+               for (i = 0 ; i < strlen(str) ; i++) {
+                       if (str[i] == 0xc3 && str[i+1] == 0x84) {
+                               str[i]='A';
+                               str[i+1]='e';
+                       }
+                       if (str[i] == 0xc3 && str[i+1] == 0x96) {
+                               str[i]='O';
+                               str[i+1]='e';
+                       }
+                       if (str[i] == 0xc3 && str[i+1] == 0x9c) {
+                               str[i]='U';
+                               str[i+1]='e';
+                       }
+                       if (str[i] == 0xc3 && str[i+1] == 0xa4) {
+                               str[i]='a';
+                               str[i+1]='e';
+                       }
+                       if (str[i] == 0xc3 && str[i+1] == 0xb6) {
+                               str[i]='o';
+                               str[i+1]='e';
+                       }
+                       if (str[i] == 0xc3 && str[i+1] == 0xbc) {
+                               str[i]='u';
+                               str[i+1]='e';
+                       }
+                       if (str[i] == 0xc3 && str[i+1] == 0x9f) {
+                               str[i]='s';
+                               str[i+1]='s';
+                       }
                }
        }
        string = (*jnienv)->NewStringUTF(jnienv, str);
@@ -92,11 +95,17 @@ static int
 speech_android_init(struct speech_priv *ret)
 {
        jmethodID cid;
+       char *class="org/navitproject/navit/NavitSpeech2";
 
-       if (!android_find_class_global("org/navitproject/navit/NavitSpeech", &ret->NavitSpeechClass))
+       if (ret->flags & 1) 
+               class="org/navitproject/navit/NavitSpeech";
+
+       if (!android_find_class_global(class, &ret->NavitSpeechClass)) {
+               dbg(0,"No class found\n");
                 return 0;
+       }
         dbg(0,"at 3\n");
-        cid = (*jnienv)->GetMethodID(jnienv, ret->NavitSpeechClass, "<init>", "(Landroid/content/Context;)V");
+        cid = (*jnienv)->GetMethodID(jnienv, ret->NavitSpeechClass, "<init>", "(Lorg/navitproject/navit/Navit;)V");
         if (cid == NULL) {
                 dbg(0,"no method found\n");
                 return 0; /* exception thrown */
@@ -114,15 +123,20 @@ speech_android_init(struct speech_priv *ret)
 }
 
 static struct speech_priv *
-speech_android_new(struct speech_methods *meth, struct attr **attrs) {
+speech_android_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent) {
        struct speech_priv *this;
+       struct attr *flags;
        *meth=speech_android_meth;
        this=g_new(struct speech_priv,1);
        if (!speech_android_init(this)) {
                g_free(this);
                this=NULL;
        }
-       speech_android_say(this, "Demnächst der Straße folgen");
+       if (android_version < 4)
+               this->flags=3;
+       if ((flags = attr_search(attrs, NULL, attr_flags)))
+               this->flags=flags->u.num;
+       
        return this;
 }