summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220>2015-04-06 21:32:57 +0000
committermdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220>2015-04-06 21:32:57 +0000
commit30bcb605c13b8e73c297e7cbf9de4ac2f01e4546 (patch)
tree86c580335452fabf96cb2b3d6397a18c07f99056
parent3003ca96718c000125fd0c312df1a52871383d93 (diff)
downloadnavit-30bcb605c13b8e73c297e7cbf9de4ac2f01e4546.tar.gz
Add:port_android:Made map and custom navit.xml path user-selectable|Related to #1290. Thank you, jandegr!
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@6050 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/android.c8
-rw-r--r--navit/android/AndroidManifest.xml.in1
-rw-r--r--navit/android/res/drawable-ldpi/dir_up.pngbin0 -> 455 bytes
-rw-r--r--navit/android/res/drawable-ldpi/file_icon.pngbin0 -> 160 bytes
-rw-r--r--navit/android/res/drawable-ldpi/folder_icon.pngbin0 -> 113 bytes
-rw-r--r--navit/android/res/drawable-ldpi/folder_icon_light.pngbin0 -> 226 bytes
-rw-r--r--navit/android/res/drawable-ldpi/ic_launcher.pngbin0 -> 2729 bytes
-rw-r--r--navit/android/res/layout/ua_com_vassiliev_filebrowser_layout.xml84
-rw-r--r--navit/android/res/values/strings.xml1
-rw-r--r--navit/android/src/org/navitproject/navit/FileBrowserActivity.java432
-rw-r--r--navit/android/src/org/navitproject/navit/Navit.java48
-rw-r--r--navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java4
-rw-r--r--navit/android/src/org/navitproject/navit/NavitMapDownloader.java32
-rw-r--r--navit/start_real.c6
-rw-r--r--navit/xslt/map_sdcard_navitmap_bin.xslt2
15 files changed, 591 insertions, 27 deletions
diff --git a/navit/android.c b/navit/android.c
index f1b443868..d35c105cf 100644
--- a/navit/android.c
+++ b/navit/android.c
@@ -74,10 +74,11 @@ 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, int version, jobject display_density_string, jobject path)
+Java_org_navitproject_navit_Navit_NavitMain( JNIEnv* env, jobject thiz, jobject activity, jobject lang, int version, jobject display_density_string, jobject path, jobject map_path)
{
const char *langstr;
const char *displaydensitystr;
+ const char *map_file_path;
android_version=version;
__android_log_print(ANDROID_LOG_ERROR,"test","called");
jnienv=env;
@@ -91,6 +92,11 @@ Java_org_navitproject_navit_Navit_NavitMain( JNIEnv* env, jobject thiz, jobject
dbg(lvl_debug,"*****displaydensity=%s\n",displaydensitystr);
setenv("ANDROID_DENSITY",displaydensitystr,1);
(*env)->ReleaseStringUTFChars(env, display_density_string, displaydensitystr);
+
+ map_file_path=(*env)->GetStringUTFChars(env, map_path, NULL);
+ setenv("NAVIT_USER_DATADIR",map_file_path,1);
+ (*env)->ReleaseStringUTFChars(env, display_density_string, map_file_path);
+
const char *strings=(*env)->GetStringUTFChars(env, path, NULL);
main_real(1, &strings);
(*env)->ReleaseStringUTFChars(env, path, strings);
diff --git a/navit/android/AndroidManifest.xml.in b/navit/android/AndroidManifest.xml.in
index d7868858b..09e8410ff 100644
--- a/navit/android/AndroidManifest.xml.in
+++ b/navit/android/AndroidManifest.xml.in
@@ -25,6 +25,7 @@
<activity android:name=".NavitAddressSearchActivity"></activity>
<activity android:name=".NavitDownloadSelectMapActivity"></activity>
<activity android:name=".NavitAddressResultListActivity"></activity>
+ <activity android:name=".FileBrowserActivity"></activity>
</application>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:resizeable="true" android:anyDensity="true"/>
diff --git a/navit/android/res/drawable-ldpi/dir_up.png b/navit/android/res/drawable-ldpi/dir_up.png
new file mode 100644
index 000000000..a4f295530
--- /dev/null
+++ b/navit/android/res/drawable-ldpi/dir_up.png
Binary files differ
diff --git a/navit/android/res/drawable-ldpi/file_icon.png b/navit/android/res/drawable-ldpi/file_icon.png
new file mode 100644
index 000000000..4fc6a5efe
--- /dev/null
+++ b/navit/android/res/drawable-ldpi/file_icon.png
Binary files differ
diff --git a/navit/android/res/drawable-ldpi/folder_icon.png b/navit/android/res/drawable-ldpi/folder_icon.png
new file mode 100644
index 000000000..00a87a8a6
--- /dev/null
+++ b/navit/android/res/drawable-ldpi/folder_icon.png
Binary files differ
diff --git a/navit/android/res/drawable-ldpi/folder_icon_light.png b/navit/android/res/drawable-ldpi/folder_icon_light.png
new file mode 100644
index 000000000..642e47a2a
--- /dev/null
+++ b/navit/android/res/drawable-ldpi/folder_icon_light.png
Binary files differ
diff --git a/navit/android/res/drawable-ldpi/ic_launcher.png b/navit/android/res/drawable-ldpi/ic_launcher.png
new file mode 100644
index 000000000..99238729d
--- /dev/null
+++ b/navit/android/res/drawable-ldpi/ic_launcher.png
Binary files differ
diff --git a/navit/android/res/layout/ua_com_vassiliev_filebrowser_layout.xml b/navit/android/res/layout/ua_com_vassiliev_filebrowser_layout.xml
new file mode 100644
index 000000000..28bedf592
--- /dev/null
+++ b/navit/android/res/layout/ua_com_vassiliev_filebrowser_layout.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ android:padding="3dp" >
+
+ <!--
+ android:layout_weight="1"
+ android:layout_weight="1"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:layout_width="fill_parent"
+ android:layout_gravity="top"
+ android:background = "#f00"
+ android:background = "#0f0"
+
+ -->
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="0dp"
+ android:gravity="top"
+ android:orientation="horizontal"
+ android:padding="0dp" >
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="0dp"
+ android:layout_weight="1"
+ android:gravity="top"
+ android:orientation="horizontal"
+ android:padding="0dp" >
+
+ <Button
+ android:id="@+id/upDirectoryButton"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top"
+ android:layout_margin="0dp"
+ android:layout_weight="1"
+ android:padding="0dp"
+ android:drawableLeft="@drawable/dir_up"
+ android:text="Up" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="0dp"
+ android:layout_weight="1"
+ android:gravity="top"
+ android:orientation="horizontal"
+ android:padding="0dp" >
+
+ <Button
+ android:id="@+id/selectCurrentDirectoryButton"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top"
+ android:gravity = "center|center_vertical"
+ android:layout_margin="0dp"
+ android:layout_weight="1"
+ android:padding="0dp"
+ android:text="Select" />
+ </LinearLayout>
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/currentDirectoryTextView"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="Current folder: \n/THis/is/a/long/path/to/test/if/this/will/span/multiple/lines" />
+
+ <ListView
+ android:id="@+id/fileListView"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_marginTop="5dp"
+ android:layout_weight="1" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/navit/android/res/values/strings.xml b/navit/android/res/values/strings.xml
index 895e527c1..0aadefa7e 100644
--- a/navit/android/res/values/strings.xml
+++ b/navit/android/res/values/strings.xml
@@ -23,6 +23,7 @@
<string name="optionsmenu_toggle_poi">Toggle POIs</string>
<string name="optionsmenu_exit_navit">Exit Navit</string>
<string name="optionsmenu_backup_restore">Backup / Restore</string>
+ <string name="optionsmenu_set_map_location">Set map location</string>
<!-- POSITION POP-UP -->
<string name="position_popup_title">Position</string>
diff --git a/navit/android/src/org/navitproject/navit/FileBrowserActivity.java b/navit/android/src/org/navitproject/navit/FileBrowserActivity.java
new file mode 100644
index 000000000..ab3c47376
--- /dev/null
+++ b/navit/android/src/org/navitproject/navit/FileBrowserActivity.java
@@ -0,0 +1,432 @@
+package org.navitproject.navit;
+
+//Heavily based on code from
+//https://github.com/mburman/Android-File-Explore
+// Version of Aug 13, 2011
+//Also contributed:
+// Sugan Krishnan (https://github.com/rgksugan) - Jan 2013.
+//
+
+//Project type now is Android library:
+// http://developer.android.com/guide/developing/projects/projects-eclipse.html#ReferencingLibraryProject
+
+//General Java imports
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Collections;
+
+//Android imports
+import android.app.Activity;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.StatFs;
+import android.util.Log;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup.LayoutParams;
+import android.view.*;
+import android.widget.*;
+
+//Import of resources file for file browser
+import org.navitproject.navit.R;
+
+public class FileBrowserActivity extends Activity {
+ // Intent Action Constants
+ public static final String INTENT_ACTION_SELECT_DIR = "ua.com.vassiliev.androidfilebrowser.SELECT_DIRECTORY_ACTION";
+ public static final String INTENT_ACTION_SELECT_FILE = "ua.com.vassiliev.androidfilebrowser.SELECT_FILE_ACTION";
+
+ // Intent parameters names constants
+ public static final String startDirectoryParameter = "ua.com.vassiliev.androidfilebrowser.directoryPath";
+ public static final String returnDirectoryParameter = "ua.com.vassiliev.androidfilebrowser.directoryPathRet";
+ public static final String returnFileParameter = "ua.com.vassiliev.androidfilebrowser.filePathRet";
+ public static final String showCannotReadParameter = "ua.com.vassiliev.androidfilebrowser.showCannotRead";
+ public static final String filterExtension = "ua.com.vassiliev.androidfilebrowser.filterExtension";
+
+ // Stores names of traversed directories
+ ArrayList<String> pathDirsList = new ArrayList<String>();
+
+ // Check if the first level of the directory structure is the one showing
+ // private Boolean firstLvl = true;
+
+ private static final String LOGTAG = "F_PATH";
+
+ private List<Item> fileList = new ArrayList<Item>();
+ private File path = null;
+ private String chosenFile;
+ // private static final int DIALOG_LOAD_FILE = 1000;
+
+ ArrayAdapter<Item> adapter;
+
+ private boolean showHiddenFilesAndDirs = true;
+
+ private boolean directoryShownIsEmpty = false;
+
+ private String filterFileExtension = null;
+
+ // Action constants
+ private static int currentAction = -1;
+ private static final int SELECT_DIRECTORY = 1;
+ private static final int SELECT_FILE = 2;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // In case of
+ // ua.com.vassiliev.androidfilebrowser.SELECT_DIRECTORY_ACTION
+ // Expects com.mburman.fileexplore.directoryPath parameter to
+ // point to the start folder.
+ // If empty or null, will start from SDcard root.
+ setContentView(R.layout.ua_com_vassiliev_filebrowser_layout);
+
+ // Set action for this activity
+ Intent thisInt = this.getIntent();
+ currentAction = SELECT_DIRECTORY;// This would be a default action in
+ // case not set by intent
+ if (thisInt.getAction().equalsIgnoreCase(INTENT_ACTION_SELECT_FILE)) {
+ Log.d(LOGTAG, "SELECT ACTION - SELECT FILE");
+ currentAction = SELECT_FILE;
+ }
+
+ showHiddenFilesAndDirs = thisInt.getBooleanExtra(
+ showCannotReadParameter, true);
+
+ filterFileExtension = thisInt.getStringExtra(filterExtension);
+
+ setInitialDirectory();
+
+ parseDirectoryPath();
+ loadFileList();
+ this.createFileListAdapter();
+ this.initializeButtons();
+ this.initializeFileListView();
+ updateCurrentDirectoryTextView();
+ Log.d(LOGTAG, path.getAbsolutePath());
+ }
+
+ private void setInitialDirectory() {
+ Intent thisInt = this.getIntent();
+ String requestedStartDir = thisInt
+ .getStringExtra(startDirectoryParameter);
+
+ if (requestedStartDir != null && requestedStartDir.length() > 0) {// if(requestedStartDir!=null
+ File tempFile = new File(requestedStartDir);
+ if (tempFile.isDirectory())
+ this.path = tempFile;
+ }// if(requestedStartDir!=null
+
+ if (this.path == null) {// No or invalid directory supplied in intent
+ // parameter
+ if (Environment.getExternalStorageDirectory().isDirectory()
+ && Environment.getExternalStorageDirectory().canRead())
+ path = Environment.getExternalStorageDirectory();
+ else
+ path = new File("/");
+ }// if(this.path==null) {//No or invalid directory supplied in intent
+ // parameter
+ }// private void setInitialDirectory() {
+
+ private void parseDirectoryPath() {
+ pathDirsList.clear();
+ String pathString = path.getAbsolutePath();
+ String[] parts = pathString.split("/");
+ int i = 0;
+ while (i < parts.length) {
+ pathDirsList.add(parts[i]);
+ i++;
+ }
+ }
+
+ private void initializeButtons() {
+ Button upDirButton = (Button) this.findViewById(R.id.upDirectoryButton);
+ upDirButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ Log.d(LOGTAG, "onclick for upDirButton");
+ loadDirectoryUp();
+ loadFileList();
+ adapter.notifyDataSetChanged();
+ updateCurrentDirectoryTextView();
+ }
+ });// upDirButton.setOnClickListener(
+
+ Button selectFolderButton = (Button) this
+ .findViewById(R.id.selectCurrentDirectoryButton);
+ if (currentAction == SELECT_DIRECTORY) {
+ selectFolderButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ Log.d(LOGTAG, "onclick for selectFolderButton");
+ returnDirectoryFinishActivity();
+ }
+ });
+ } else {// if(currentAction == this.SELECT_DIRECTORY) {
+ selectFolderButton.setVisibility(View.GONE);
+ }// } else {//if(currentAction == this.SELECT_DIRECTORY) {
+ }// private void initializeButtons() {
+
+ private void loadDirectoryUp() {
+ // present directory removed from list
+ String s = pathDirsList.remove(pathDirsList.size() - 1);
+ // path modified to exclude present directory
+ path = new File(path.toString().substring(0,
+ path.toString().lastIndexOf(s)));
+ fileList.clear();
+ }
+
+ private void updateCurrentDirectoryTextView() {
+ int i = 0;
+ String curDirString = "";
+ while (i < pathDirsList.size()) {
+ curDirString += pathDirsList.get(i) + "/";
+ i++;
+ }
+ if (pathDirsList.size() == 0) {
+ ((Button) this.findViewById(R.id.upDirectoryButton))
+ .setEnabled(false);
+ curDirString = "/";
+ } else
+ ((Button) this.findViewById(R.id.upDirectoryButton))
+ .setEnabled(true);
+ long freeSpace = getFreeSpace(curDirString);
+ String formattedSpaceString = formatBytes(freeSpace);
+ if (freeSpace == 0) {
+ Log.d(LOGTAG, "NO FREE SPACE");
+ File currentDir = new File(curDirString);
+ if(!currentDir.canWrite())
+ formattedSpaceString = "NON Writable";
+ }
+
+ ((Button) this.findViewById(R.id.selectCurrentDirectoryButton))
+ .setText("Select\n[" + formattedSpaceString
+ + "]");
+
+ ((TextView) this.findViewById(R.id.currentDirectoryTextView))
+ .setText("Current directory: " + curDirString);
+ }// END private void updateCurrentDirectoryTextView() {
+
+ private void showToast(String message) {
+ Toast.makeText(this, message, Toast.LENGTH_LONG).show();
+ }
+
+ private void initializeFileListView() {
+ ListView lView = (ListView) this.findViewById(R.id.fileListView);
+ lView.setBackgroundColor(Color.LTGRAY);
+ LinearLayout.LayoutParams lParam = new LinearLayout.LayoutParams(
+ LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
+ lParam.setMargins(15, 5, 15, 5);
+ lView.setAdapter(this.adapter);
+ lView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ public void onItemClick(AdapterView<?> parent, View view,
+ int position, long id) {
+ chosenFile = fileList.get(position).file;
+ File sel = new File(path + "/" + chosenFile);
+ Log.d(LOGTAG, "Clicked:" + chosenFile);
+ if (sel.isDirectory()) {
+ if (sel.canRead()) {
+ // Adds chosen directory to list
+ pathDirsList.add(chosenFile);
+ path = new File(sel + "");
+ Log.d(LOGTAG, "Just reloading the list");
+ loadFileList();
+ adapter.notifyDataSetChanged();
+ updateCurrentDirectoryTextView();
+ Log.d(LOGTAG, path.getAbsolutePath());
+ } else {// if(sel.canRead()) {
+ showToast("Path does not exist or cannot be read");
+ }// } else {//if(sel.canRead()) {
+ }// if (sel.isDirectory()) {
+ // File picked or an empty directory message clicked
+ else {// if (sel.isDirectory()) {
+ Log.d(LOGTAG, "item clicked");
+ if (!directoryShownIsEmpty) {
+ Log.d(LOGTAG, "File selected:" + chosenFile);
+ returnFileFinishActivity(sel.getAbsolutePath());
+ }
+ }// else {//if (sel.isDirectory()) {
+ }// public void onClick(DialogInterface dialog, int which) {
+ });// lView.setOnClickListener(
+ }// private void initializeFileListView() {
+
+ private void returnDirectoryFinishActivity() {
+ Intent retIntent = new Intent();
+ retIntent.putExtra(returnDirectoryParameter, path.getAbsolutePath());
+ this.setResult(RESULT_OK, retIntent);
+ this.finish();
+ }// END private void returnDirectoryFinishActivity() {
+
+ private void returnFileFinishActivity(String filePath) {
+ Intent retIntent = new Intent();
+ retIntent.putExtra(returnFileParameter, filePath);
+ this.setResult(RESULT_OK, retIntent);
+ this.finish();
+ }// END private void returnDirectoryFinishActivity() {
+
+ private void loadFileList() {
+ try {
+ path.mkdirs();
+ } catch (SecurityException e) {
+ Log.e(LOGTAG, "unable to write on the sd card ");
+ }
+ fileList.clear();
+
+ if (path.exists() && path.canRead()) {
+ FilenameFilter filter = new FilenameFilter() {
+ public boolean accept(File dir, String filename) {
+ File sel = new File(dir, filename);
+ boolean showReadableFile = showHiddenFilesAndDirs
+ || sel.canRead();
+ // Filters based on whether the file is hidden or not
+ if (currentAction == SELECT_DIRECTORY) {
+ return (sel.isDirectory() && showReadableFile);
+ }
+ if (currentAction == SELECT_FILE) {
+
+ // If it is a file check the extension if provided
+ if (sel.isFile() && filterFileExtension != null) {
+ return (showReadableFile && sel.getName().endsWith(
+ filterFileExtension));
+ }
+ return (showReadableFile);
+ }
+ return true;
+ }// public boolean accept(File dir, String filename) {
+ };// FilenameFilter filter = new FilenameFilter() {
+
+ String[] fList = path.list(filter);
+ this.directoryShownIsEmpty = false;
+ for (int i = 0; i < fList.length; i++) {
+ // Convert into file path
+ File sel = new File(path, fList[i]);
+ Log.d(LOGTAG,
+ "File:" + fList[i] + " readable:"
+ + (Boolean.valueOf(sel.canRead())).toString());
+ int drawableID = R.drawable.file_icon;
+ boolean canRead = sel.canRead();
+ // Set drawables
+ if (sel.isDirectory()) {
+ if (canRead) {
+ drawableID = R.drawable.folder_icon;
+ } else {
+ drawableID = R.drawable.folder_icon_light;
+ }
+ }
+ fileList.add(i, new Item(fList[i], drawableID, canRead));
+ }// for (int i = 0; i < fList.length; i++) {
+ if (fileList.size() == 0) {
+ // Log.d(LOGTAG, "This directory is empty");
+ this.directoryShownIsEmpty = true;
+ fileList.add(0, new Item("Directory is empty", -1, true));
+ } else {// sort non empty list
+ Collections.sort(fileList, new ItemFileNameComparator());
+ }
+ } else {
+ Log.e(LOGTAG, "path does not exist or cannot be read");
+ }
+ // Log.d(TAG, "loadFileList finished");
+ }// private void loadFileList() {
+
+ private void createFileListAdapter() {
+ adapter = new ArrayAdapter<Item>(this,
+ android.R.layout.select_dialog_item, android.R.id.text1,
+ fileList) {
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ // creates view
+ View view = super.getView(position, convertView, parent);
+ TextView textView = (TextView) view
+ .findViewById(android.R.id.text1);
+ // put the image on the text view
+ int drawableID = 0;
+ if (fileList.get(position).icon != -1) {
+ // If icon == -1, then directory is empty
+ drawableID = fileList.get(position).icon;
+ }
+ textView.setCompoundDrawablesWithIntrinsicBounds(drawableID, 0,
+ 0, 0);
+
+ textView.setEllipsize(null);
+
+ // add margin between image and text (support various screen
+ // densities)
+ // int dp5 = (int) (5 *
+ // getResources().getDisplayMetrics().density + 0.5f);
+ int dp3 = (int) (3 * getResources().getDisplayMetrics().density + 0.5f);
+ // TODO: change next line for empty directory, so text will be
+ // centered
+ textView.setCompoundDrawablePadding(dp3);
+ textView.setBackgroundColor(Color.LTGRAY);
+ return view;
+ }// public View getView(int position, View convertView, ViewGroup
+ };// adapter = new ArrayAdapter<Item>(this,
+ }// private createFileListAdapter(){
+
+ private class Item {
+ public String file;
+ public int icon;
+ public boolean canRead;
+
+ public Item(String file, Integer icon, boolean canRead) {
+ this.file = file;
+ this.icon = icon;
+ }
+
+ @Override
+ public String toString() {
+ return file;
+ }
+ }// END private class Item {
+
+ private class ItemFileNameComparator implements Comparator<Item> {
+ public int compare(Item lhs, Item rhs) {
+ return lhs.file.toLowerCase().compareTo(rhs.file.toLowerCase());
+ }
+ }
+
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ Log.d(LOGTAG, "ORIENTATION_LANDSCAPE");
+ } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
+ Log.d(LOGTAG, "ORIENTATION_PORTRAIT");
+ }
+ // Layout apparently changes itself, only have to provide good onMeasure
+ // in custom components
+ // TODO: check with keyboard
+ // if(newConfig.keyboard == Configuration.KEYBOARDHIDDEN_YES)
+ }// END public void onConfigurationChanged(Configuration newConfig) {
+
+ public static long getFreeSpace(String path) {
+ StatFs stat = new StatFs(path);
+ long availSize = (long) stat.getAvailableBlocks()
+ * (long) stat.getBlockSize();
+ return availSize;
+ }// END public static long getFreeSpace(String path) {
+
+ public static String formatBytes(long bytes) {
+ // TODO: add flag to which part is needed (e.g. GB, MB, KB or bytes)
+ String retStr = "";
+ // One binary gigabyte equals 1,073,741,824 bytes.
+ if (bytes > 1073741824) {// Add GB
+ long gbs = bytes / 1073741824;
+ retStr += (new Long(gbs)).toString() + "GB ";
+ bytes = bytes - (gbs * 1073741824);
+ }
+ // One MB - 1048576 bytes
+ if (bytes > 1048576) {// Add GB
+ long mbs = bytes / 1048576;
+ retStr += (new Long(mbs)).toString() + "MB ";
+ bytes = bytes - (mbs * 1048576);
+ }
+ if (bytes > 1024) {
+ long kbs = bytes / 1024;
+ retStr += (new Long(kbs)).toString() + "KB";
+ bytes = bytes - (kbs * 1024);
+ } else
+ retStr += (new Long(bytes)).toString() + " bytes";
+ return retStr;
+ }// public static String formatBytes(long bytes){
+
+}// END public class FileBrowserActivity extends Activity {
diff --git a/navit/android/src/org/navitproject/navit/Navit.java b/navit/android/src/org/navitproject/navit/Navit.java
index 873bbb71c..a22dbf934 100644
--- a/navit/android/src/org/navitproject/navit/Navit.java
+++ b/navit/android/src/org/navitproject/navit/Navit.java
@@ -84,13 +84,14 @@ public class Navit extends Activity
public static final int NavitDownloaderSelectMap_id = 967;
public static final int MAP_NUM_PRIMARY = 11;
public static final int NavitAddressSearch_id = 70;
+ public static final int NavitSelectStorage_id = 43;
public static String NavitLanguage;
public static Resources NavitResources = null;
public static final int MAP_NUM_SECONDARY = 12;
static final String NAVIT_PACKAGE_NAME = "org.navitproject.navit";
static final String TAG = "Navit";
- static final String MAP_FILENAME_PATH = Environment.getExternalStorageDirectory().getPath() + "/navit/";
+ static String map_filename_path = null;
static final String NAVIT_DATA_DIR = "/data/data/" + NAVIT_PACKAGE_NAME;
static final String NAVIT_DATA_SHARE_DIR = NAVIT_DATA_DIR + "/share";
static final String FIRST_STARTUP_FILE = NAVIT_DATA_SHARE_DIR + "/has_run_once.txt";
@@ -181,6 +182,7 @@ public class Navit extends Activity
while ((i = resourcestream.read(buf)) != -1) {
resultfilestream.write(buf, 0, i);
}
+ resultfilestream.close();
} catch (Exception e) {
Log.e(TAG, "Exception " + e.getMessage());
return false;
@@ -294,8 +296,11 @@ public class Navit extends Activity
}
Log.e("Navit", "Language " + lang);
+ SharedPreferences prefs = getSharedPreferences(NAVIT_PREFS,MODE_PRIVATE);
+ map_filename_path = prefs.getString("filenamePath", Environment.getExternalStorageDirectory().getPath() + "/navit/");
+
// make sure the new path for the navitmap.bin file(s) exist!!
- File navit_maps_dir = new File(MAP_FILENAME_PATH);
+ File navit_maps_dir = new File(map_filename_path);
navit_maps_dir.mkdirs();
// make sure the share dir exists
@@ -361,7 +366,7 @@ public class Navit extends Activity
// --> dont use android.os.Build.VERSION.SDK_INT, needs API >= 4
Log.e("Navit", "android.os.Build.VERSION.SDK_INT=" + Integer.valueOf(android.os.Build.VERSION.SDK));
- NavitMain(this, NavitLanguage, Integer.valueOf(android.os.Build.VERSION.SDK), my_display_density, NAVIT_DATA_DIR+"/bin/navit");
+ NavitMain(this, NavitLanguage, Integer.valueOf(android.os.Build.VERSION.SDK), my_display_density, NAVIT_DATA_DIR+"/bin/navit",map_filename_path);
showInfos();
@@ -465,13 +470,14 @@ public class Navit extends Activity
menu.clear();
// group-id,item-id,sort order number
- menu.add(1, 1, 100, getString(R.string.optionsmenu_zoom_in)); //TRANS
- menu.add(1, 2, 200, getString(R.string.optionsmenu_zoom_out)); //TRANS
+ //menu.add(1, 1, 100, getString(R.string.optionsmenu_zoom_in)); //TRANS
+ //menu.add(1, 2, 200, getString(R.string.optionsmenu_zoom_out)); //TRANS
menu.add(1, 3, 300, getString(R.string.optionsmenu_download_maps)); //TRANS
menu.add(1, 5, 400, getString(R.string.optionsmenu_toggle_poi)); //TRANS
menu.add(1, 6, 500, getString(R.string.optionsmenu_address_search)); //TRANS
+ menu.add(1, 10, 600, getString(R.string.optionsmenu_set_map_location));
menu.add(1, 99, 900, getString(R.string.optionsmenu_exit_navit)); //TRANS
@@ -571,6 +577,9 @@ public class Navit extends Activity
/* Backup / Restore */
showDialog(NavitDialogs.DIALOG_BACKUP_RESTORE);
break;
+ case 10:
+ setMapLocation();
+ break;
case 99 :
// exit
this.onStop();
@@ -613,6 +622,22 @@ public class Navit extends Activity
msg.sendToTarget();
}
break;
+ case NavitSelectStorage_id :
+ if(resultCode == RESULT_OK) {
+ String newDir = data.getStringExtra(FileBrowserActivity.returnDirectoryParameter);
+ Log.d(TAG, "selected path= "+newDir);
+ if(!newDir.contains("/navit/"))
+ newDir = newDir+"/navit/";
+ else
+ newDir = newDir+"/";
+ SharedPreferences prefs = this.getSharedPreferences(NAVIT_PREFS,MODE_PRIVATE);
+ SharedPreferences.Editor prefs_editor = prefs.edit();
+ prefs_editor.putString("filenamePath", newDir);
+ prefs_editor.commit();
+ Toast.makeText(this, String.format(Navit._("New location set to %s\nRestart Navit to apply the changes."),newDir),Toast.LENGTH_LONG).show();
+ }
+ else Log.w(TAG, "select path failed");
+ break;
default :
//Log.e("Navit", "onActivityResult " + requestCode + " " + resultCode);
ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data);
@@ -640,6 +665,17 @@ public class Navit extends Activity
return true;
}
+ public boolean setMapLocation()
+ {
+ Intent fileExploreIntent = new Intent(this,FileBrowserActivity.class);
+ fileExploreIntent
+ .putExtra(FileBrowserActivity.startDirectoryParameter, "/mnt")
+ .setAction(FileBrowserActivity.INTENT_ACTION_SELECT_DIR);
+ startActivityForResult(fileExploreIntent,NavitSelectStorage_id);
+
+ return true;
+ }
+
@Override
public void onDestroy()
{
@@ -676,7 +712,7 @@ public class Navit extends Activity
finish();
}
- public native void NavitMain(Navit x, String lang, int version, String display_density_string, String path);
+ public native void NavitMain(Navit x, String lang, int version, String display_density_string, String path, String path2);
public native void NavitDestroy();
/*
diff --git a/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java b/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java
index ff1c89042..fd117a376 100644
--- a/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java
+++ b/navit/android/src/org/navitproject/navit/NavitDownloadSelectMapActivity.java
@@ -64,7 +64,7 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
} catch (Exception e) {
Log.e("Navit","Exception "+e.getClass().getName()+" during getFreeSpace, reporting 'no sdcard present'");
NavitDialogs.sendDialogMessage(NavitDialogs.MSG_TOAST_LONG, null,
- Navit._("Please attach your SD card to enable map download."),
+ String.format(Navit._("Current map location %s is not available\nPlease restart Navit after you attach an SD card or select a different map location."),Navit.map_filename_path),
-1, 0, 0);
finish();
}
@@ -72,7 +72,7 @@ public class NavitDownloadSelectMapActivity extends ExpandableListActivity {
protected long getFreeSpace()
{
- StatFs fsInfo = new StatFs(NavitMapDownloader.MAP_FILENAME_PATH);
+ StatFs fsInfo = new StatFs(Navit.map_filename_path);
return (long)fsInfo.getAvailableBlocks() * fsInfo.getBlockSize();
}
diff --git a/navit/android/src/org/navitproject/navit/NavitMapDownloader.java b/navit/android/src/org/navitproject/navit/NavitMapDownloader.java
index ae8087819..0d3ba1c61 100644
--- a/navit/android/src/org/navitproject/navit/NavitMapDownloader.java
+++ b/navit/android/src/org/navitproject/navit/NavitMapDownloader.java
@@ -298,7 +298,7 @@ public class NavitMapDownloader extends Thread
new osm_map_values(Navit._("Venezuela"), "-73.6", "0.4", "-59.7", "12.8", 124001905L, 1)
};
- public static final String MAP_FILENAME_PATH = Navit.MAP_FILENAME_PATH;
+ private String map_filename_path;
public static NavitMap[] getAvailableMaps() {
class filterMaps implements FilenameFilter {
@@ -309,12 +309,12 @@ public class NavitMapDownloader extends Thread
}
}
NavitMap maps[] = new NavitMap[0];
- File map_dir = new File(MAP_FILENAME_PATH);
+ File map_dir = new File(Navit.map_filename_path);
String map_file_names[] = map_dir.list(new filterMaps());
if (map_file_names != null) {
maps = new NavitMap[map_file_names.length];
for (int map_file_index = 0; map_file_index < map_file_names.length; map_file_index++) {
- maps[map_file_index] = new NavitMap(MAP_FILENAME_PATH, map_file_names[map_file_index]);
+ maps[map_file_index] = new NavitMap(Navit.map_filename_path, map_file_names[map_file_index]);
}
}
return maps;
@@ -340,6 +340,7 @@ public class NavitMapDownloader extends Thread
public NavitMapDownloader(int map_id) {
this.map_values = osm_maps[map_id];
this.map_id=map_id;
+ this.map_filename_path=Navit.map_filename_path;
}
public void run() {
@@ -368,7 +369,7 @@ public class NavitMapDownloader extends Thread
if (success || stop_me ) {
NavitDialogs.sendDialogMessage( NavitDialogs.MSG_MAP_DOWNLOAD_FINISHED
- , MAP_FILENAME_PATH + map_values.map_name + ".bin", null, -1, success ? 1 : 0 , map_id );
+ , map_filename_path + map_values.map_name + ".bin", null, -1, success ? 1 : 0 , map_id );
}
}
@@ -384,8 +385,13 @@ public class NavitMapDownloader extends Thread
needed_bytes = MAP_WRITE_FILE_BUFFER;
if (free_space < needed_bytes ) {
- Log.e(TAG, "Not enough free space. Please free at least " + needed_bytes / 1024 /1024 + "Mb.");
- updateProgress(free_space, needed_bytes, Navit._("Error downloading map!") + "\n" + Navit._("Not enough free space"));
+ String msg;
+ Log.e(TAG, "Not enough free space or media not available. Please free at least " + needed_bytes / 1024 /1024 + "Mb.");
+ if(free_space<0)
+ msg=Navit._("Media selected for map storage is not available");
+ else
+ msg=Navit._("Not enough free space");
+ updateProgress(free_space, needed_bytes, Navit._("Error downloading map!") + "\n" + msg);
return false;
}
return true;
@@ -471,7 +477,7 @@ public class NavitMapDownloader extends Thread
}
protected File getDestinationFile() {
- File outputFile = new File(MAP_FILENAME_PATH, map_values.map_name + ".tmp");
+ File outputFile = new File(map_filename_path, map_values.map_name + ".tmp");
outputFile.getParentFile().mkdir();
return outputFile;
}
@@ -512,8 +518,12 @@ public class NavitMapDownloader extends Thread
}
protected long getFreeSpace() {
- StatFs fsInfo = new StatFs(MAP_FILENAME_PATH);
- return (long)fsInfo.getAvailableBlocks() * fsInfo.getBlockSize();
+ try {
+ StatFs fsInfo = new StatFs(map_filename_path);
+ return (long)fsInfo.getAvailableBlocks() * fsInfo.getBlockSize();
+ } catch(Exception e) {
+ return -1;
+ }
}
protected BufferedInputStream getInputStream(URLConnection c) {
@@ -536,11 +546,11 @@ public class NavitMapDownloader extends Thread
}
protected File getMapFile() {
- return new File(MAP_FILENAME_PATH, map_values.map_name + ".bin");
+ return new File(map_filename_path, map_values.map_name + ".bin");
}
protected File getMapInfoFile() {
- return new File(MAP_FILENAME_PATH, map_values.map_name + ".tmp.info");
+ return new File(map_filename_path, map_values.map_name + ".tmp.info");
}
protected BufferedOutputStream getOutputStream(File outputFile, boolean resume) {
diff --git a/navit/start_real.c b/navit/start_real.c
index fbbd5a2ea..ddf88b886 100644
--- a/navit/start_real.c
+++ b/navit/start_real.c
@@ -169,12 +169,6 @@ int main_real(int argc, char * const* argv)
list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL));
list = g_list_append(list,g_strdup("navit.xml.local"));
list = g_list_append(list,g_strdup("navit.xml"));
-#ifdef HAVE_API_ANDROID
- // new preferred location (the new one should have priority over the legacy!)
- list = g_list_append(list,g_strdup("/sdcard/navit/navit.xml"));
- // legacy location, still supported
- list = g_list_append(list,g_strdup("/sdcard/navit.xml"));
-#endif
list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
#ifndef _WIN32
diff --git a/navit/xslt/map_sdcard_navitmap_bin.xslt b/navit/xslt/map_sdcard_navitmap_bin.xslt
index d9a9cded2..ac8835b7d 100644
--- a/navit/xslt/map_sdcard_navitmap_bin.xslt
+++ b/navit/xslt/map_sdcard_navitmap_bin.xslt
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xi="http://www.w3.org/2001/XInclude">
<xsl:template match="/config/navit/mapset/xi:include">
- <maps type="binfile" data="/sdcard/navit/*.bin" />
+ <maps type="binfile" data="$NAVIT_USER_DATADIR/*.bin" />
</xsl:template>
</xsl:transform>