2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 package org.navitproject.navit;
22 import android.app.Activity;
23 import android.widget.TextView;
24 import android.os.Bundle;
25 import android.os.Debug;
26 import android.os.Message;
27 import android.os.Handler;
28 import android.os.PowerManager;
29 import android.content.Context;
30 import android.content.res.Resources;
31 import android.util.Log;
32 import java.util.Locale;
34 import java.io.FileInputStream;
35 import java.io.FileOutputStream;
36 import java.io.InputStream;
39 public class Navit extends Activity implements Handler.Callback
41 public Handler handler;
42 private PowerManager.WakeLock wl;
43 private boolean extractRes(String resname, String result)
46 boolean needs_update=false;
48 Resources res=getResources();
49 Log.e("Navit","Res Name " + resname);
50 Log.e("Navit","result " + result);
51 int id=res.getIdentifier(resname,"raw","org.navitproject.navit");
52 Log.e("Navit","Res ID " + id);
55 while ((slash=result.indexOf("/",slash+1)) != -1) {
57 Log.e("Navit","Checking "+result.substring(0,slash));
58 resultfile=new File(result.substring(0,slash));
59 if (!resultfile.exists()) {
60 Log.e("Navit","Creating dir");
61 if (!resultfile.mkdir())
67 resultfile=new File(result);
68 if (!resultfile.exists())
72 InputStream resourcestream=res.openRawResource(id);
73 FileInputStream resultfilestream=new FileInputStream(resultfile);
74 byte[] resourcebuf = new byte[1024];
75 byte[] resultbuf = new byte[1024];
77 while ((i = resourcestream.read(resourcebuf)) != -1) {
78 if (resultfilestream.read(resultbuf) != i) {
79 Log.e("Navit","Result is too short");
83 for (int j = 0 ; j < i ; j++) {
84 if (resourcebuf[j] != resultbuf[j]) {
85 Log.e("Navit","Result is different");
93 if (!needs_update && resultfilestream.read(resultbuf) != -1) {
94 Log.e("Navit","Result is too long");
99 Log.e("Navit","Exception "+e.getMessage());
104 Log.e("Navit","Extracting resource");
107 InputStream resourcestream=res.openRawResource(id);
108 FileOutputStream resultfilestream=new FileOutputStream(resultfile);
109 byte[] buf = new byte[1024];
111 while ((i = resourcestream.read(buf)) != -1) {
112 resultfilestream.write(buf, 0, i);
115 catch (Exception e) {
116 Log.e("Navit","Exception "+e.getMessage());
122 /** Called when the activity is first created. */
124 public void onCreate(Bundle savedInstanceState)
126 super.onCreate(savedInstanceState);
127 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
128 wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen");
129 Locale locale=java.util.Locale.getDefault();
130 String lang=locale.getLanguage();
133 int pos=langu.indexOf('_');
135 langc=langu.substring(0, pos);
136 langu=langc + langu.substring(pos).toUpperCase(locale);
138 String country=locale.getCountry();
139 Log.e("Navit","Country "+country);
140 langu=langc + "_" + country.toUpperCase(locale);
142 Log.e("Navit","Language " + lang);
144 if (!extractRes(langc,"/data/data/org.navitproject.navit/locale/"+langc+"/LC_MESSAGES/navit.mo")) {
145 Log.e("Navit","Failed to extract language resource "+langc);
147 if (!extractRes("navit","/data/data/org.navitproject.navit/share/navit.xml")) {
148 Log.e("Navit","Failed to extract navit.xml");
150 // Debug.startMethodTracing("calc");
151 NavitMain(this, langu);
154 @Override public void onStart()
157 Log.e("Navit","OnStart");
160 @Override public void onRestart()
163 Log.e("Navit","OnRestart");
166 @Override public void onResume()
169 Log.e("Navit","OnResume");
172 @Override public void onPause()
175 Log.e("Navit","OnPause");
178 @Override public void onStop()
181 Log.e("Navit","OnStop");
184 @Override public void onDestroy()
187 Log.e("Navit","OnDestroy");
191 public void disableSuspend()
202 public boolean handleMessage(Message m) {
203 Log.e("Navit","Handler received message");
207 /* A native method that is implemented by the
208 * 'hello-jni' native library, which is packaged
209 * with this application.
211 public native void NavitMain(Navit x, String lang);
212 public native void NavitActivity(int activity);
214 /* this is used to load the 'hello-jni' library on application
215 * startup. The library has already been unpacked into
216 * /data/data/com.example.Navit/lib/libhello-jni.so at
217 * installation time by the package manager.
220 System.loadLibrary("navit");