diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index c69a29be66..e2dd3670d0 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:debuggable="true" android:name=".activities.OsmandApplication"> diff --git a/OsmAnd/res/layout-port/menu.xml b/OsmAnd/res/layout-port/menu.xml index 06dfe77598..2e439f3de2 100644 --- a/OsmAnd/res/layout-port/menu.xml +++ b/OsmAnd/res/layout-port/menu.xml @@ -48,11 +48,11 @@ - - + --> diff --git a/OsmAnd/res/layout/menu.xml b/OsmAnd/res/layout/menu.xml index 335c2df948..adaa252677 100644 --- a/OsmAnd/res/layout/menu.xml +++ b/OsmAnd/res/layout/menu.xml @@ -49,12 +49,12 @@ - - + --> diff --git a/OsmAnd/res/values-ru-rRU/strings.xml b/OsmAnd/res/values-ru-rRU/strings.xml index a8f8bba489..4d76cd34bb 100644 --- a/OsmAnd/res/values-ru-rRU/strings.xml +++ b/OsmAnd/res/values-ru-rRU/strings.xml @@ -1,14 +1,16 @@ + Перезагрузить индексы с SD + Обновить индексы Использовать интернет для расчета маршрута Online маршрутизация Указать пароль для работы с OSM Пароль Упраление слоем open street bugs, установка osm логина Включение мониторинга, установка интервала сохранения - Настройка параметров поиска + Настройка данных : язык, обновление данных Настройка источника, параметров карты, доступа в Интернет - Поиск + Данные Osm Автоматически изменять масштаб карты при изменении скорости Масштаб diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ba6fae0e8a..69ae81f0e8 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,14 +1,16 @@ + Reload data indexes from SD + Reload indexes Use internet to calculate route Use online routing Input osm password User password Specify osm settings: show bugs, osm login Specify monitor settings : save track - Specify search settings + Specify data settings : language, update data Specify map settings : rotation, poi filter - Search + Data Osm Auto zoom map according to the speed Auto zoom map diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index 64f353b332..da7b6efb9e 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -15,8 +15,9 @@ - + + diff --git a/OsmAnd/src/com/osmand/OsmandSettings.java b/OsmAnd/src/com/osmand/OsmandSettings.java index ef67bb9f71..ced7992374 100644 --- a/OsmAnd/src/com/osmand/OsmandSettings.java +++ b/OsmAnd/src/com/osmand/OsmandSettings.java @@ -108,6 +108,8 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public static final String SAVE_CURRENT_TRACK = "save_current_track"; //$NON-NLS-1$ + + public static final String RELOAD_INDEXES = "reload_indexes"; //$NON-NLS-1$ // this value string is synchronized with settings_pref.xml preference name public static final String SAVE_TRACK_TO_GPX = "save_track_to_gpx"; //$NON-NLS-1$ diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index ec6cee6400..07486db235 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -174,6 +174,15 @@ public class ResourceManager { } ////////////////////////////////////////////// Working with indexes //////////////////////////////////////////////// + + public List reloadIndexes(IProgress progress){ + close(); + List warnings = new ArrayList(); + warnings.addAll(indexingPoi(progress)); + warnings.addAll(indexingAddresses(progress)); + return warnings; + } + // POI INDEX // public List indexingPoi(final IProgress progress) { File file = new File(Environment.getExternalStorageDirectory(), POI_PATH); diff --git a/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java b/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java index 959c24809a..17ff522bcf 100644 --- a/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java +++ b/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java @@ -46,6 +46,7 @@ import android.widget.EditText; import android.widget.Toast; import com.osmand.AmenityIndexRepository; +import com.osmand.Base64; import com.osmand.LogUtil; import com.osmand.OsmandSettings; import com.osmand.R; @@ -58,7 +59,6 @@ import com.osmand.osm.EntityInfo; import com.osmand.osm.Node; import com.osmand.osm.OSMSettings.OSMTagKey; import com.osmand.osm.io.OsmBaseStorage; -import com.osmand.util.Base64; import com.osmand.views.OsmandMapTileView; public class EditingPOIActivity { diff --git a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java index efd01b58b6..dbe585ea06 100644 --- a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java +++ b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java @@ -7,14 +7,10 @@ import java.io.FileWriter; import java.io.PrintStream; import java.lang.Thread.UncaughtExceptionHandler; import java.text.MessageFormat; -import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.AlertDialog; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; import android.app.ProgressDialog; import android.app.AlertDialog.Builder; import android.content.Intent; @@ -33,7 +29,6 @@ import com.osmand.LogUtil; import com.osmand.ProgressDialogImplementation; import com.osmand.R; import com.osmand.ResourceManager; -import com.osmand.Version; import com.osmand.activities.search.SearchActivity; public class MainMenuActivity extends Activity { @@ -43,12 +38,11 @@ public class MainMenuActivity extends Activity { private static final String EXCEPTION_FILE_SIZE = "/osmand/exception.log"; //$NON-NLS-1$ private Button showMap; - private Button exitButton; private Button settingsButton; private Button searchButton; private Button favouritesButton; - private NotificationManager mNotificationManager; - private int APP_NOTIFICATION_ID; + + @@ -61,9 +55,7 @@ public class MainMenuActivity extends Activity { @Override public void run() { try { - List warnings = new ArrayList(); - warnings.addAll(ResourceManager.getResourceManager().indexingPoi(impl)); - warnings.addAll(ResourceManager.getResourceManager().indexingAddresses(impl)); + List warnings = ResourceManager.getResourceManager().reloadIndexes(impl); SavingTrackHelper helper = new SavingTrackHelper(MainMenuActivity.this); if (helper.hasDataToSave()) { impl.startTask("Saving gpx tracks to SD...", -1); @@ -107,17 +99,6 @@ public class MainMenuActivity extends Activity { requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.menu); - mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - - Intent notificationIndent = new Intent(MainMenuActivity.this, MapActivity.class); - notificationIndent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - Notification notification = new Notification(R.drawable.icon, "", //$NON-NLS-1$ - System.currentTimeMillis()); - notification.setLatestEventInfo(MainMenuActivity.this, Version.APP_NAME, - "OsmAnd is running in background", PendingIntent.getActivity( - this.getBaseContext(), 0, notificationIndent, - PendingIntent.FLAG_UPDATE_CURRENT)); - mNotificationManager.notify(APP_NOTIFICATION_ID, notification); showMap = (Button) findViewById(R.id.MapButton); showMap.setOnClickListener(new OnClickListener() { @@ -156,14 +137,14 @@ public class MainMenuActivity extends Activity { }); - exitButton = (Button) findViewById(R.id.ExitButton); +// exitButton = (Button) findViewById(R.id.ExitButton); // exitButton.setVisibility(View.INVISIBLE); - exitButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - finishApplication(); - } - }); +// exitButton.setOnClickListener(new OnClickListener() { +// @Override +// public void onClick(View v) { +// finishApplication(); +// } +// }); startApplication(); } @@ -191,7 +172,6 @@ public class MainMenuActivity extends Activity { } protected void finishApplication(){ - mNotificationManager.cancel(APP_NOTIFICATION_ID); ResourceManager.getResourceManager().close(); applicationAlreadyStarted = false; MainMenuActivity.this.finish(); diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 5cfb48b21a..e67320f05d 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -4,6 +4,9 @@ import java.text.MessageFormat; import android.app.Activity; import android.app.AlertDialog; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.Intent; @@ -39,6 +42,7 @@ import com.osmand.LogUtil; import com.osmand.OsmandSettings; import com.osmand.R; import com.osmand.ResourceManager; +import com.osmand.Version; import com.osmand.activities.FavouritesActivity.FavouritePoint; import com.osmand.activities.FavouritesActivity.FavouritesDbHelper; import com.osmand.activities.search.SearchActivity; @@ -77,6 +81,8 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat private MenuItem navigateToPointMenu; + private NotificationManager mNotificationManager; + private int APP_NOTIFICATION_ID; @@ -85,6 +91,18 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat return OsmandSettings.isMapSyncToGpsLocation(this); } + private Notification getNotification(){ + Intent notificationIndent = new Intent(this, MapActivity.class); + notificationIndent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + Notification notification = new Notification(R.drawable.icon, "", //$NON-NLS-1$ + System.currentTimeMillis()); + notification.setLatestEventInfo(this, Version.APP_NAME, + "Go back to OsmAnd map", PendingIntent.getActivity( + this.getBaseContext(), 0, notificationIndent, + PendingIntent.FLAG_UPDATE_CURRENT)); + return notification; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -94,6 +112,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat // WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); + mapView = (OsmandMapTileView) findViewById(R.id.MapView); MapTileDownloader.getInstance().addDownloaderCallback(mapView); mapView.setMapLocationListener(this); @@ -231,10 +250,24 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat return super.onTrackballEvent(event); } + @Override + protected void onStart() { + super.onStart(); + + } + + @Override + protected void onStop() { + mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + mNotificationManager.notify(APP_NOTIFICATION_ID, getNotification()); + super.onStop(); + } + @Override protected void onDestroy() { super.onDestroy(); savingTrackHelper.close(); + mNotificationManager.cancel(APP_NOTIFICATION_ID); MapTileDownloader.getInstance().removeDownloaderCallback(mapView); } diff --git a/OsmAnd/src/com/osmand/activities/OsmandApplication.java b/OsmAnd/src/com/osmand/activities/OsmandApplication.java new file mode 100644 index 0000000000..1cfbe85bd2 --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/OsmandApplication.java @@ -0,0 +1,14 @@ +package com.osmand.activities; + +import android.app.Application; + +public class OsmandApplication extends Application { + + @Override + public void onLowMemory() { + super.onLowMemory(); + } + + + +} diff --git a/OsmAnd/src/com/osmand/activities/SettingsActivity.java b/OsmAnd/src/com/osmand/activities/SettingsActivity.java index 8ce2f126b5..6d842ecf9a 100644 --- a/OsmAnd/src/com/osmand/activities/SettingsActivity.java +++ b/OsmAnd/src/com/osmand/activities/SettingsActivity.java @@ -2,6 +2,7 @@ package com.osmand.activities; import java.util.List; +import android.app.ProgressDialog; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; @@ -14,14 +15,18 @@ import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.Preference.OnPreferenceClickListener; +import android.widget.Toast; import com.osmand.OsmandSettings; +import com.osmand.ProgressDialogImplementation; import com.osmand.R; +import com.osmand.ResourceManager; import com.osmand.OsmandSettings.ApplicationMode; import com.osmand.map.TileSourceManager; import com.osmand.map.TileSourceManager.TileSourceTemplate; -public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener { +public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnPreferenceClickListener { private CheckBoxPreference showPoiOnMap; private CheckBoxPreference useInternetToDownloadTiles; @@ -39,6 +44,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference private CheckBoxPreference autoZoom; private EditTextPreference userPassword; private CheckBoxPreference useInternetToCalculateRoute; + private Preference reloadIndexes; @Override public void onCreate(Bundle savedInstanceState) { @@ -66,6 +72,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference useEnglishNames =(CheckBoxPreference) screen.findPreference(OsmandSettings.USE_ENGLISH_NAMES); useEnglishNames.setOnPreferenceChangeListener(this); + reloadIndexes =(Preference) screen.findPreference(OsmandSettings.RELOAD_INDEXES); + reloadIndexes.setOnPreferenceClickListener(this); + userName = (EditTextPreference) screen.findPreference(OsmandSettings.USER_NAME); userName.setOnPreferenceChangeListener(this); userPassword = (EditTextPreference) screen.findPreference(OsmandSettings.USER_PASSWORD); @@ -76,7 +85,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference saveTrackInterval =(ListPreference) screen.findPreference(OsmandSettings.SAVE_TRACK_INTERVAL); saveTrackInterval.setOnPreferenceChangeListener(this); saveCurrentTrack =(Preference) screen.findPreference(OsmandSettings.SAVE_CURRENT_TRACK); - saveCurrentTrack.setOnPreferenceChangeListener(this); + saveCurrentTrack.setOnPreferenceClickListener(this); + positionOnMap =(ListPreference) screen.findPreference(OsmandSettings.POSITION_ON_MAP); positionOnMap.setOnPreferenceChangeListener(this); @@ -181,10 +191,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } else if(preference == saveTrackToGpx){ edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, (Boolean) newValue); edit.commit(); - } else if(preference == saveCurrentTrack){ - SavingTrackHelper helper = new SavingTrackHelper(this); - helper.saveDataToGpx(); - helper.close(); } else if(preference == saveTrackInterval){ edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, Integer.parseInt(newValue.toString())); edit.commit(); @@ -216,6 +222,44 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } return true; } + + public void reloadIndexes(){ + final ProgressDialog dlg = ProgressDialog.show(this, "Loading data", "Reading indices...", true); + final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg); + impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$ + @Override + public void run() { + try { + showWarnings(ResourceManager.getResourceManager().reloadIndexes(impl)); + } finally { + dlg.dismiss(); + } + } + }); + impl.run(); + + } + protected void showWarnings(List warnings) { + if (!warnings.isEmpty()) { + final StringBuilder b = new StringBuilder(); + boolean f = true; + for (String w : warnings) { + if(f){ + f = false; + } else { + b.append('\n'); + } + b.append(w); + } + runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(SettingsActivity.this, b.toString(), Toast.LENGTH_LONG).show(); + + } + }); + } + } public void setAppMode(ApplicationMode preset, Editor edit){ if(preset == ApplicationMode.CAR){ @@ -279,4 +323,18 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } } + @Override + public boolean onPreferenceClick(Preference preference) { + if(preference == reloadIndexes){ + reloadIndexes(); + return true; + } else if(preference == saveCurrentTrack){ + SavingTrackHelper helper = new SavingTrackHelper(this); + helper.saveDataToGpx(); + helper.close(); + return true; + } + return false; + } + } diff --git a/OsmAnd/src/com/osmand/util/Base64.java b/OsmAnd/src/com/osmand/util/Base64.java deleted file mode 100644 index df1f1cc890..0000000000 --- a/OsmAnd/src/com/osmand/util/Base64.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.osmand.util; - -/** - * @source http://www.javaworld.com/javaworld/javatips/jw-javatip47.html -- 24.11.2008, (mb) - */ -public class Base64 { - /******************************************************************************************************************* - * BASE 64 encoding of a String or an array of bytes. See also RFC 1421. - * - * @author Unknown - * @author David W. Croft - * @version 1998-06-08 - ******************************************************************************************************************/ - - ////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////// - public static final char[] alphabet = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7 - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15 - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23 - 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31 - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39 - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47 - 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55 - '4', '5', '6', '7', '8', '9', '+', '/' }; // 56 to 63 - - ////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////// - - public static String encode(final String s) - ////////////////////////////////////////////////////////////////////// - { - return encode(s.getBytes()); - } - - public static String encode(final byte[] octetString) - ////////////////////////////////////////////////////////////////////// - { - int bits24; - int bits6; - - final char[] out = new char[((octetString.length - 1) / 3 + 1) * 4]; - - int outIndex = 0; - int i = 0; - - while ((i + 3) <= octetString.length) { - // store the octets - bits24 = (octetString[i++] & 0xFF) << 16; - bits24 |= (octetString[i++] & 0xFF) << 8; - bits24 |= (octetString[i++] & 0xFF) << 0; - - bits6 = (bits24 & 0x00FC0000) >> 18; - out[outIndex++] = alphabet[bits6]; - bits6 = (bits24 & 0x0003F000) >> 12; - out[outIndex++] = alphabet[bits6]; - bits6 = (bits24 & 0x00000FC0) >> 6; - out[outIndex++] = alphabet[bits6]; - bits6 = (bits24 & 0x0000003F); - out[outIndex++] = alphabet[bits6]; - } - - if (octetString.length - i == 2) { - // store the octets - bits24 = (octetString[i] & 0xFF) << 16; - bits24 |= (octetString[i + 1] & 0xFF) << 8; - - bits6 = (bits24 & 0x00FC0000) >> 18; - out[outIndex++] = alphabet[bits6]; - bits6 = (bits24 & 0x0003F000) >> 12; - out[outIndex++] = alphabet[bits6]; - bits6 = (bits24 & 0x00000FC0) >> 6; - out[outIndex++] = alphabet[bits6]; - - // padding - out[outIndex++] = '='; - } else if (octetString.length - i == 1) { - // store the octets - bits24 = (octetString[i] & 0xFF) << 16; - - bits6 = (bits24 & 0x00FC0000) >> 18; - out[outIndex++] = alphabet[bits6]; - bits6 = (bits24 & 0x0003F000) >> 12; - out[outIndex++] = alphabet[bits6]; - - // padding - out[outIndex++] = '='; - out[outIndex++] = '='; - } - - return new String(out); - } - -} \ No newline at end of file