Merge branch 'r3.7' of github.com:osmandapp/Osmand into r3.7

This commit is contained in:
Victor Shcherb 2020-05-20 17:28:51 +02:00
commit ae10663f55
11 changed files with 427 additions and 460 deletions

View file

@ -203,8 +203,7 @@ public class MapPoiTypes {
public Map<String, PoiType> getAllTranslatedNames(boolean skipNonEditable) {
Map<String, PoiType> translation = new HashMap<String, PoiType>();
for (int i = 0; i < categories.size(); i++) {
PoiCategory pc = categories.get(i);
for (PoiCategory pc : categories) {
if (skipNonEditable && pc.isNotEditableOsm()) {
continue;
}
@ -298,12 +297,18 @@ public class MapPoiTypes {
if (!lastCategory.getKeyName().equals("Other")) {
lastCategory.setTopVisible(true);
}
categories.add(lastCategory);
addCategory(lastCategory);
return lastCategory;
}
return otherCategory;
}
private void addCategory(PoiCategory category) {
List<PoiCategory> copy = new ArrayList<>(categories);
copy.add(category);
categories = copy;
}
public PoiTranslator getPoiTranslator() {
return poiTranslator;
}
@ -348,7 +353,7 @@ public class MapPoiTypes {
final Map<String, PoiType> allTypes = new LinkedHashMap<String, PoiType>();
final Map<String, List<PoiType>> categoryPoiAdditionalMap = new LinkedHashMap<String, List<PoiType>>();
final Map<AbstractPoiType, Set<String>> abstractTypeAdditionalCategories = new LinkedHashMap<AbstractPoiType, Set<String>>();
this.categories.clear();
List<PoiCategory> categoriesList = new ArrayList<>();
try {
XmlPullParser parser = PlatformUtil.newXMLPullParser();
int tok;
@ -364,7 +369,7 @@ public class MapPoiTypes {
if (tok == XmlPullParser.START_TAG) {
String name = parser.getName();
if (name.equals("poi_category")) {
lastCategory = new PoiCategory(this, parser.getAttributeValue("", "name"), categories.size());
lastCategory = new PoiCategory(this, parser.getAttributeValue("", "name"), categoriesList.size());
lastCategory.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top")));
lastCategory.setNotEditableOsm("true".equals(parser.getAttributeValue("", "no_edit")));
lastCategory.setDefaultTag(parser.getAttributeValue("", "default_tag"));
@ -375,7 +380,7 @@ public class MapPoiTypes {
lastCategory.addExcludedPoiAdditionalCategories(parser.getAttributeValue("", "excluded_poi_additional_category").split(","));
lastCategoryPoiAdditionalsCategories.removeAll(lastCategory.getExcludedPoiAdditionalCategories());
}
categories.add(lastCategory);
categoriesList.add(lastCategory);
} else if (name.equals("poi_filter")) {
PoiFilter tp = new PoiFilter(this, lastCategory, parser.getAttributeValue("", "name"));
tp.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top")));
@ -477,6 +482,7 @@ public class MapPoiTypes {
}
}
}
categories = categoriesList;
is.close();
} catch (IOException e) {
log.error("Unexpected error", e); //$NON-NLS-1$

View file

@ -90,9 +90,11 @@ public class Algorithms {
return def;
}
public static String getFileNameWithoutExtension(File f) {
String name = f.getName();
return getFileNameWithoutExtension(f.getName());
}
public static String getFileNameWithoutExtension(String name) {
int i = name.indexOf('.');
if (i >= 0) {
name = name.substring(0, i);
@ -250,6 +252,32 @@ public class Algorithms {
return test == 0x504b0304;
}
/**
* Checks, whether the child directory is a subdirectory of the parent
* directory.
*
* @param parent the parent directory.
* @param child the suspected child directory.
* @return true if the child is a subdirectory of the parent directory.
*/
public static boolean isSubDirectory(File parent, File child) {
try {
parent = parent.getCanonicalFile();
child = child.getCanonicalFile();
File dir = child;
while (dir != null) {
if (parent.equals(dir)) {
return true;
}
dir = dir.getParentFile();
}
} catch (IOException e) {
return false;
}
return false;
}
private static int readInt(InputStream in) throws IOException {
int ch1 = in.read();
int ch2 = in.read();

View file

@ -1,19 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<inset>
<shape android:shape="oval" >
<solid android:color="@color/feature_purchased_bg" />
</shape>
</inset>
</item>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/ic_action_marker_passed" />
</item>
<item>
<inset>
<shape android:shape="oval">
<solid android:color="@color/feature_purchased_bg" />
</shape>
</inset>
</item>
<item android:drawable="@drawable/ic_action_marker_passed" />
</layer-list>

View file

@ -1,23 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/color_transparent"/>
<size
android:width="28dp"
android:height="28dp"/>
</shape>
</item>
<item
android:id="@+id/placeholder_icon"
android:bottom="2dp"
android:drawable="@drawable/ic_action_history"
android:left="2dp"
android:right="2dp"
android:top="2dp">
android:top="2dp" />
<bitmap
android:gravity="center"
android:src="@drawable/ic_action_history"
android:tint="@color/icon_color_default_light"/>
</item>
</layer-list>
</layer-list>

View file

@ -2,22 +2,20 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/color_transparent"/>
<solid android:color="@color/color_transparent" />
<size
android:width="28dp"
android:height="28dp"/>
android:height="28dp" />
</shape>
</item>
<item
android:id="@+id/placeholder_icon"
android:bottom="2dp"
android:drawable="@drawable/ic_action_placeholder_city"
android:left="2dp"
android:right="2dp"
android:top="2dp">
android:tint="@color/icon_color_default_light"
android:top="2dp" />
<bitmap
android:gravity="center"
android:src="@drawable/ic_action_placeholder_city"
android:tint="@color/icon_color_default_light"/>
</item>
</layer-list>
</layer-list>

View file

@ -10,7 +10,9 @@
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
Thx - Hardy
--> <string name="index_item_world_basemap_detailed">World overview map (detailed)</string>
-->
<string name="unsupported_type_error">Unsupported type</string>
<string name="index_item_world_basemap_detailed">World overview map (detailed)</string>
<string name="profiles_for_action_not_found">Could not find any such profiles.</string>
<string name="change_application_profile">Change app profile</string>
<string name="shared_string_add_profile">Add profile</string>

View file

@ -101,7 +101,7 @@ import net.osmand.plus.firstusage.FirstUsageWizardFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.DiscountHelper;
import net.osmand.plus.helpers.ImportHelper;
import net.osmand.plus.helpers.ImportHelper.ImportGpxBottomSheetDialogFragment;
import net.osmand.plus.dialogs.ImportGpxBottomSheetDialogFragment;
import net.osmand.plus.helpers.IntentHelper;
import net.osmand.plus.helpers.LockHelper;
import net.osmand.plus.helpers.LockHelper.LockUIAdapter;

View file

@ -0,0 +1,94 @@
package net.osmand.plus.dialogs;
import android.os.Bundle;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.helpers.ImportHelper;
public class ImportGpxBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = "ImportGpxBottomSheetDialogFragment";
private ImportHelper importHelper;
private GPXFile gpxFile;
private String fileName;
private boolean save;
private boolean useImportDir;
public void setImportHelper(ImportHelper importHelper) {
this.importHelper = importHelper;
}
public void setGpxFile(GPXFile gpxFile) {
this.gpxFile = gpxFile;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public void setSave(boolean save) {
this.save = save;
}
public void setUseImportDir(boolean useImportDir) {
this.useImportDir = useImportDir;
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
items.add(new TitleItem(getString(R.string.import_file)));
int nameColor = getResolvedColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light);
int descrColor = getResolvedColor(nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light);
String descr = getString(R.string.import_gpx_file_description);
if (!descr.contains("%s")) {
descr = "%s " + descr;
}
CharSequence txt = AndroidUtils.getStyledString(descr, fileName, new ForegroundColorSpan(descrColor),
new ForegroundColorSpan(nameColor));
items.add(new ShortDescriptionItem(txt));
BaseBottomSheetItem asFavoritesItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_favorite))
.setTitle(getString(R.string.import_as_favorites))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
importHelper.importFavoritesFromGpx(gpxFile, fileName);
dismiss();
}
})
.create();
items.add(asFavoritesItem);
items.add(new DividerHalfItem(getContext()));
BaseBottomSheetItem asGpxItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
.setTitle(getString(R.string.import_as_gpx))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
importHelper.handleGpxImport(gpxFile, fileName, save, useImportDir);
dismiss();
}
})
.create();
items.add(asGpxItem);
}
}

View file

@ -12,8 +12,6 @@ import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.provider.OpenableColumns;
import android.provider.Settings;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
@ -33,14 +31,17 @@ import net.osmand.PlatformUtil;
import net.osmand.data.FavouritePoint;
import net.osmand.data.FavouritePoint.BackgroundType;
import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.CustomOsmandPlugin;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.ActivityResultListener;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.dialogs.ImportGpxBottomSheetDialogFragment;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.settings.backend.SettingsHelper;
import net.osmand.plus.settings.backend.SettingsHelper.CheckDuplicatesListener;
import net.osmand.plus.settings.backend.SettingsHelper.PluginSettingsItem;
@ -48,22 +49,14 @@ import net.osmand.plus.settings.backend.SettingsHelper.ProfileSettingsItem;
import net.osmand.plus.settings.backend.SettingsHelper.SettingsCollectListener;
import net.osmand.plus.settings.backend.SettingsHelper.SettingsImportListener;
import net.osmand.plus.settings.backend.SettingsHelper.SettingsItem;
import net.osmand.plus.activities.ActivityResultListener;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.settings.fragments.ImportSettingsFragment;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -109,7 +102,8 @@ public class ImportHelper {
public enum ImportType {
SETTINGS(OSMAND_SETTINGS_FILE_EXT),
ROUTING(ROUTING_FILE_EXT);
ROUTING(ROUTING_FILE_EXT),
RENDERING(RENDERER_INDEX_EXT);
ImportType(String extension) {
this.extension = extension;
@ -141,21 +135,29 @@ public class ImportHelper {
handleFileImport(contentUri, name, extras, useImportDir);
}
public void importFavoritesFromGpx(final GPXFile gpxFile, final String fileName) {
importFavoritesImpl(gpxFile, fileName, false);
}
public void handleGpxImport(GPXFile result, String name, boolean save, boolean useImportDir) {
handleResult(result, name, save, useImportDir, false);
}
public boolean handleGpxImport(final Uri contentUri, final boolean useImportDir) {
String name = getNameFromContentUri(app, contentUri);
boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(contentUri.getPath()));
boolean isOsmandSubdir = Algorithms.isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(contentUri.getPath()));
if (!isOsmandSubdir && name != null) {
String nameLC = name.toLowerCase();
if (nameLC.endsWith(GPX_FILE_EXT)) {
name = name.substring(0, name.length() - 4) + GPX_FILE_EXT;
name = name.substring(0, name.length() - GPX_FILE_EXT.length()) + GPX_FILE_EXT;
handleGpxImport(contentUri, name, true, useImportDir);
return true;
} else if (nameLC.endsWith(KML_SUFFIX)) {
name = name.substring(0, name.length() - 4) + KML_SUFFIX;
name = name.substring(0, name.length() - KML_SUFFIX.length()) + KML_SUFFIX;
handleKmlImport(contentUri, name, true, useImportDir);
return true;
} else if (nameLC.endsWith(KMZ_SUFFIX)) {
name = name.substring(0, name.length() - 4) + KMZ_SUFFIX;
name = name.substring(0, name.length() - KMZ_SUFFIX.length()) + KMZ_SUFFIX;
handleKmzImport(contentUri, name, true, useImportDir);
return true;
}
@ -167,7 +169,7 @@ public class ImportHelper {
String scheme = uri.getScheme();
boolean isFileIntent = "file".equals(scheme);
boolean isContentIntent = "content".equals(scheme);
boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(uri.getPath()));
boolean isOsmandSubdir = Algorithms.isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(uri.getPath()));
final boolean saveFile = !isFileIntent || !isOsmandSubdir;
String fileName = "";
if (isFileIntent) {
@ -180,7 +182,7 @@ public class ImportHelper {
public void handleFileImport(Uri intentUri, String fileName, Bundle extras, boolean useImportDir) {
final boolean isFileIntent = "file".equals(intentUri.getScheme());
final boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(intentUri.getPath()));
final boolean isOsmandSubdir = Algorithms.isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(intentUri.getPath()));
final boolean saveFile = !isFileIntent || !isOsmandSubdir;
@ -194,10 +196,8 @@ public class ImportHelper {
handleSqliteTileImport(intentUri, fileName);
} else if (fileName != null && fileName.endsWith(OSMAND_SETTINGS_FILE_EXT)) {
handleOsmAndSettingsImport(intentUri, fileName, extras, null);
} else if (fileName != null && fileName.endsWith(RENDERER_INDEX_EXT)) {
handleRenderingFileImport(intentUri, fileName);
} else if (fileName != null && fileName.endsWith(ROUTING_FILE_EXT)) {
handleRoutingFileImport(intentUri, fileName, null);
handleXmlFileImport(intentUri, fileName, null);
} else {
handleFavouritesImport(intentUri, fileName, saveFile, useImportDir, false);
}
@ -338,58 +338,45 @@ public class ImportHelper {
@SuppressLint("StaticFieldLeak")
private void importFavoritesImpl(final GPXFile gpxFile, final String fileName, final boolean forceImportFavourites) {
if(!app.isApplicationInitializing()) {
new AsyncTask<Void, Void, GPXFile>() {
ProgressDialog progress = null;
final AsyncTask<Void, Void, GPXFile> favoritesImportTask = new AsyncTask<Void, Void, GPXFile>() {
ProgressDialog progress = null;
@Override
protected void onPreExecute() {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""),
app.getString(R.string.loading_data));
}
@Override
protected void onPreExecute() {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""),
app.getString(R.string.loading_data));
}
}
@Override
protected GPXFile doInBackground(Void... nothing) {
final List<FavouritePoint> favourites = asFavourites(gpxFile.getPoints(),
@Override
protected GPXFile doInBackground(Void... nothing) {
final List<FavouritePoint> favourites = asFavourites(gpxFile.getPoints(),
fileName, forceImportFavourites);
final FavouritesDbHelper favoritesHelper = app.getFavorites();
for (final FavouritePoint favourite : favourites) {
favoritesHelper.deleteFavourite(favourite, false);
favoritesHelper.addFavourite(favourite, false);
}
favoritesHelper.sortAll();
favoritesHelper.saveCurrentPointsIntoFile();
return null;
final FavouritesDbHelper favoritesHelper = app.getFavorites();
for (final FavouritePoint favourite : favourites) {
favoritesHelper.deleteFavourite(favourite, false);
favoritesHelper.addFavourite(favourite, false);
}
favoritesHelper.sortAll();
favoritesHelper.saveCurrentPointsIntoFile();
return null;
}
@Override
protected void onPostExecute(GPXFile result) {
if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) {
progress.dismiss();
}
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG)
.show();
final Intent newIntent = new Intent(activity,
@Override
protected void onPostExecute(GPXFile result) {
if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) {
progress.dismiss();
}
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG).show();
final Intent newIntent = new Intent(activity,
app.getAppCustomization().getFavoritesActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra(TAB_ID, FAV_TAB);
activity.startActivity(newIntent);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
app.getAppInitializer().addListener(new AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, InitEvents event) {}
@Override
public void onFinish(AppInitializer init) {
importFavoritesImpl(gpxFile, fileName, forceImportFavourites);
}
});
}
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra(TAB_ID, FAV_TAB);
activity.startActivity(newIntent);
}
};
executeImportTask(favoritesImportTask);
}
@SuppressLint("StaticFieldLeak")
@ -660,7 +647,7 @@ public class ImportHelper {
if (importType.equals(ImportType.SETTINGS)) {
handleOsmAndSettingsImport(data, fileName, resultData.getExtras(), callback);
} else if (importType.equals(ImportType.ROUTING)){
handleRoutingFileImport(data, fileName, callback);
handleXmlFileImport(data, fileName, callback);
}
} else {
app.showToastMessage(app.getString(R.string.not_support_file_type_with_ext,
@ -674,81 +661,6 @@ public class ImportHelper {
mapActivity.startActivityForResult(intent, IMPORT_FILE_REQUEST);
}
@SuppressLint("StaticFieldLeak")
private void handleRoutingFileImport(final Uri uri, final String fileName, final CallbackWithObject<RoutingConfiguration.Builder> callback) {
final AsyncTask<Void, Void, String> routingImportTask = new AsyncTask<Void, Void, String>() {
String mFileName;
ProgressDialog progress;
@Override
protected void onPreExecute() {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
}
mFileName = fileName;
}
@Override
protected String doInBackground(Void... voids) {
File routingDir = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
if (!routingDir.exists()) {
routingDir.mkdirs();
}
File dest = new File(routingDir, mFileName);
while (dest.exists()) {
mFileName = AndroidUtils.createNewFileName(mFileName);
dest = new File(routingDir, mFileName);
}
return copyFile(app, dest, uri, true);
}
@Override
protected void onPostExecute(String error) {
File routingDir = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
final File file = new File(routingDir, mFileName);
if (error == null && file.exists()) {
loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
@Override
public void onRoutingFilesLoaded() {
if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) {
progress.dismiss();
}
RoutingConfiguration.Builder builder = app.getCustomRoutingConfig(mFileName);
if (builder != null) {
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, mFileName));
if (callback != null) {
callback.processResult(builder);
}
} else {
app.showToastMessage(app.getString(R.string.file_does_not_contain_routing_rules, mFileName));
}
}
});
} else {
if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) {
progress.dismiss();
}
app.showShortToastMessage(app.getString(R.string.file_import_error, mFileName, error));
}
}
};
if (app.isApplicationInitializing()) {
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
}
@Override
public void onFinish(AppInitializer init) {
routingImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
} else {
routingImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
private void handleOsmAndSettingsImport(Uri intentUri, String fileName, Bundle extras, CallbackWithObject<List<SettingsItem>> callback) {
if (extras != null && extras.containsKey(SettingsHelper.SETTINGS_VERSION_KEY) && extras.containsKey(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY)) {
int version = extras.getInt(SettingsHelper.SETTINGS_VERSION_KEY, -1);
@ -824,20 +736,7 @@ public class ImportHelper {
}
}
};
if (app.isApplicationInitializing()) {
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
}
@Override
public void onFinish(AppInitializer init) {
settingsImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
} else {
settingsImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
executeImportTask(settingsImportTask);
}
private void handlePluginImport(final PluginSettingsItem pluginItem, final File file) {
@ -896,63 +795,141 @@ public class ImportHelper {
}
@SuppressLint("StaticFieldLeak")
private void handleRenderingFileImport(final Uri intentUri, final String fileName) {
private void handleXmlFileImport(final Uri intentUri, final String fileName,
final CallbackWithObject routingCallback) {
final AsyncTask<Void, Void, String> renderingImportTask = new AsyncTask<Void, Void, String>() {
String mFileName;
ProgressDialog progress;
private String destFileName;
private ImportType importType;
private ProgressDialog progress;
@Override
protected void onPreExecute() {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
}
mFileName = fileName;
destFileName = fileName;
}
@Override
protected String doInBackground(Void... voids) {
File renderingDir = app.getAppPath(IndexConstants.RENDERERS_DIR);
if (!renderingDir.exists()) {
renderingDir.mkdirs();
checkImportType();
if (importType != null) {
File dest = getDestinationFile();
if (dest != null) {
return copyFile(app, dest, intentUri, true);
}
}
File dest = new File(renderingDir, mFileName);
while (dest.exists()) {
mFileName = AndroidUtils.createNewFileName(mFileName);
dest = new File(renderingDir, mFileName);
}
return copyFile(app, dest, intentUri, true);
return app.getString(R.string.file_import_error, destFileName, app.getString(R.string.unsupported_type_error));
}
@Override
protected void onPostExecute(String error) {
File renderingDir = app.getAppPath(IndexConstants.RENDERERS_DIR);
File file = new File(renderingDir, mFileName);
File destDir = getDestinationDir();
File file = new File(destDir, destFileName);
if (error == null && file.exists()) {
app.getRendererRegistry().updateExternalRenderers();
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, mFileName));
if (importType == ImportType.RENDERING) {
app.getRendererRegistry().updateExternalRenderers();
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, destFileName));
hideProgress();
} else if (importType == ImportType.ROUTING) {
loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
@Override
public void onRoutingFilesLoaded() {
hideProgress();
RoutingConfiguration.Builder builder = app.getCustomRoutingConfig(destFileName);
if (builder != null) {
if (routingCallback != null) {
routingCallback.processResult(builder);
}
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, destFileName));
} else {
app.showToastMessage(app.getString(R.string.file_does_not_contain_routing_rules, destFileName));
}
}
});
}
} else {
app.showShortToastMessage(app.getString(R.string.file_import_error, mFileName, error));
hideProgress();
app.showShortToastMessage(app.getString(R.string.file_import_error, destFileName, error));
}
}
private void hideProgress() {
if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) {
progress.dismiss();
}
}
};
if (app.isApplicationInitializing()) {
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
}
@Override
public void onFinish(AppInitializer init) {
renderingImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
private File getDestinationDir() {
if (importType == ImportType.ROUTING) {
return app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
} else if (importType == ImportType.RENDERING) {
return app.getAppPath(IndexConstants.RENDERERS_DIR);
}
});
} else {
renderingImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
return null;
}
private File getDestinationFile() {
File destDir = getDestinationDir();
if (destDir != null) {
if (!destDir.exists()) {
destDir.mkdirs();
}
if (importType == ImportType.RENDERING && !destFileName.endsWith(RENDERER_INDEX_EXT)) {
String fileName = Algorithms.getFileNameWithoutExtension(destFileName);
destFileName = fileName + RENDERER_INDEX_EXT;
}
File destFile = new File(destDir, destFileName);
while (destFile.exists()) {
destFileName = AndroidUtils.createNewFileName(destFileName);
destFile = new File(destDir, destFileName);
}
return destFile;
}
return null;
}
private void checkImportType() {
InputStream is = null;
try {
final ParcelFileDescriptor pFD = app.getContentResolver().openFileDescriptor(intentUri, "r");
if (pFD != null) {
is = new FileInputStream(pFD.getFileDescriptor());
XmlPullParser parser = PlatformUtil.newXMLPullParser();
parser.setInput(is, "UTF-8");
int tok;
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (tok == XmlPullParser.START_TAG) {
String name = parser.getName();
if ("osmand_routing_config".equals(name)) {
importType = ImportType.ROUTING;
} else if ("renderingStyle".equals(name)) {
importType = ImportType.RENDERING;
}
break;
}
}
try {
pFD.close();
} catch (IOException e) {
log.error(e);
}
}
} catch (FileNotFoundException | XmlPullParserException e) {
log.error(e);
} catch (IOException e) {
log.error(e);
} finally {
if (is != null) try {
is.close();
} catch (IOException e) {
log.error(e);
}
}
}
};
executeImportTask(renderingImportTask);
}
private void handleResult(final GPXFile result, final String name, final boolean save,
@ -1198,107 +1175,21 @@ public class ImportHelper {
return favourites;
}
/**
* Checks, whether the child directory is a subdirectory of the parent
* directory.
*
* @param parent the parent directory.
* @param child the suspected child directory.
* @return true if the child is a subdirectory of the parent directory.
*/
public boolean isSubDirectory(File parent, File child) {
try {
parent = parent.getCanonicalFile();
child = child.getCanonicalFile();
File dir = child;
while (dir != null) {
if (parent.equals(dir)) {
return true;
@SuppressWarnings("unchecked")
private <P> void executeImportTask(final AsyncTask<P, ?, ?> importTask, final P... requests) {
if (app.isApplicationInitializing()) {
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
}
dir = dir.getParentFile();
}
} catch (IOException e) {
return false;
}
return false;
}
public static class ImportGpxBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = "ImportGpxBottomSheetDialogFragment";
private ImportHelper importHelper;
private GPXFile gpxFile;
private String fileName;
private boolean save;
private boolean useImportDir;
public void setImportHelper(ImportHelper importHelper) {
this.importHelper = importHelper;
}
public void setGpxFile(GPXFile gpxFile) {
this.gpxFile = gpxFile;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public void setSave(boolean save) {
this.save = save;
}
public void setUseImportDir(boolean useImportDir) {
this.useImportDir = useImportDir;
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
items.add(new TitleItem(getString(R.string.import_file)));
int nameColor = getResolvedColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light);
int descrColor = getResolvedColor(nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light);
String descr = getString(R.string.import_gpx_file_description);
if(!descr.contains("%s")) {
descr = "%s " +descr;
}
CharSequence txt = AndroidUtils.getStyledString(descr, fileName, new ForegroundColorSpan(descrColor),
new ForegroundColorSpan(nameColor));
items.add(new ShortDescriptionItem(txt));
BaseBottomSheetItem asFavoritesItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_favorite))
.setTitle(getString(R.string.import_as_favorites))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
importHelper.importFavoritesImpl(gpxFile, fileName, false);
dismiss();
}
})
.create();
items.add(asFavoritesItem);
items.add(new DividerHalfItem(getContext()));
BaseBottomSheetItem asGpxItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
.setTitle(getString(R.string.import_as_gpx))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
importHelper.handleResult(gpxFile, fileName, save, useImportDir, false);
dismiss();
}
})
.create();
items.add(asGpxItem);
@Override
public void onFinish(AppInitializer init) {
importTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests);
}
});
} else {
importTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, requests);
}
}
}
}

View file

@ -915,9 +915,6 @@ public class RoutingHelper {
public static String formatStreetName(String name, String ref, String destination, String towards) {
//Hardy, 2016-08-05:
//Now returns: (ref) + ((" ")+name) + ((" ")+"toward "+dest) or ""
String formattedStreetName = "";
if (ref != null && ref.length() > 0) {
formattedStreetName = ref;
@ -938,56 +935,78 @@ public class RoutingHelper {
}
// protected boolean isDistanceLess(float currentSpeed, double dist, double etalon, float defSpeed){
// if(dist < etalon || ((dist / currentSpeed) < (etalon / defSpeed))){
// return true;
// }
// return false;
// }
public synchronized String getCurrentName(TurnType[] next, NextDirectionInfo n){
public static class CurrentStreetName {
public String text;
public TurnType turnType;
public boolean showMarker; // turn type has priority over showMarker
public RouteDataObject shieldObject;
public String exitRef;
}
public synchronized CurrentStreetName getCurrentName(NextDirectionInfo n){
CurrentStreetName streetName = new CurrentStreetName();
Location l = lastFixedLocation;
float speed = 0;
if(l != null && l.hasSpeed()) {
if (l != null && l.hasSpeed()) {
speed = l.getSpeed();
}
if(next != null && n.directionInfo != null) {
next[0] = n.directionInfo.getTurnType();
}
if(n.distanceTo > 0 && n.directionInfo != null && !n.directionInfo.getTurnType().isSkipToSpeak() &&
boolean isSet = false;
// 1. turn is imminent
if (n.distanceTo > 0 && n.directionInfo != null && !n.directionInfo.getTurnType().isSkipToSpeak() &&
voiceRouter.isDistanceLess(speed, n.distanceTo, voiceRouter.PREPARE_DISTANCE * 0.75f)) {
String nm = n.directionInfo.getStreetName();
String rf = n.directionInfo.getRef();
String dn = n.directionInfo.getDestinationName();
return formatStreetName(nm, null, dn, "»");
}
RouteSegmentResult rs = getCurrentSegmentResult();
if(rs != null) {
String name = getRouteSegmentStreetName(rs);
if (!Algorithms.isEmpty(name)) {
return name;
isSet = !(Algorithms.isEmpty(nm) && Algorithms.isEmpty(rf) && Algorithms.isEmpty(dn));
streetName.text = formatStreetName(nm, null, dn, "»");
streetName.turnType = n.directionInfo.getTurnType();
streetName.shieldObject = n.directionInfo.getRouteDataObject();
if (streetName.turnType == null) {
streetName.turnType = TurnType.valueOf(TurnType.C, false);
}
}
rs = getNextStreetSegmentResult();
if(rs != null) {
String name = getRouteSegmentStreetName(rs);
if (!Algorithms.isEmpty(name)) {
if(next != null) {
next[0] = TurnType.valueOf(TurnType.C, false);
if (n.directionInfo.getExitInfo() != null) {
streetName.exitRef = n.directionInfo.getExitInfo().getRef();
if (!Algorithms.isEmpty(n.directionInfo.getExitInfo().getExitStreetName())) {
streetName.text = n.directionInfo.getExitInfo().getExitStreetName();
}
return name;
}
}
return null;
// 2. display current road street name
if (!isSet) {
RouteSegmentResult rs = getCurrentSegmentResult();
if (rs != null) {
streetName.text = getRouteSegmentStreetName(rs, false);
if (Algorithms.isEmpty(streetName.text)) {
isSet = !Algorithms.isEmpty(getRouteSegmentStreetName(rs, true));
} else {
isSet = true;
}
streetName.showMarker = true;
streetName.shieldObject = rs.getObject();
}
}
// 3. display next road street name if this one empty
if (!isSet) {
RouteSegmentResult rs = getNextStreetSegmentResult();
if (rs != null) {
streetName.text = getRouteSegmentStreetName(rs, false);
streetName.turnType = TurnType.valueOf(TurnType.C, false);
streetName.shieldObject = rs.getObject();
}
}
if (streetName.turnType == null) {
streetName.showMarker = true;
}
return streetName;
}
private String getRouteSegmentStreetName(RouteSegmentResult rs) {
private String getRouteSegmentStreetName(RouteSegmentResult rs, boolean includeRef) {
String nm = rs.getObject().getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get());
// String rf = rs.getObject().getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
String rf = rs.getObject().getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
String dn = rs.getObject().getDestinationName(settings.MAP_PREFERRED_LOCALE.get(),
settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
return formatStreetName(nm, null, dn, "»");
return formatStreetName(nm, includeRef ? rf : null, dn, "»");
}
public RouteSegmentResult getCurrentSegmentResult() {

View file

@ -931,11 +931,11 @@ public class MapInfoWidgetsFactory {
private View waypointInfoBar;
private LocationPointWrapper lastPoint;
private TurnDrawable turnDrawable;
private boolean showMarker;
private int shadowRad;
RouteCalculationResult.NextDirectionInfo calc1;
private static final Log LOG = PlatformUtil.getLog(TopTextView.class);
private boolean showMarker;
public TopTextView(OsmandApplication app, MapActivity map) {
turnDrawable = new NextTurnInfoWidget.TurnDrawable(map, true);
@ -981,138 +981,80 @@ public class MapInfoWidgetsFactory {
}
public boolean updateInfo(DrawSettings d) {
String text = null;
TurnType[] type = new TurnType[1];
boolean showNextTurn = false;
boolean showMarker = this.showMarker;
boolean showExitInfo = false;
boolean showShield = false;
boolean imminentTurn = false;
ExitInfo exitInfo = null;
RouteDataObject object = null;
public boolean updateInfo(DrawSettings d) {
RoutingHelper.CurrentStreetName streetName = null;
boolean showClosestWaypointFirstInAddress = true;
if (routingHelper != null && routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) {
if (routingHelper.isFollowingMode()) {
if (settings.SHOW_STREET_NAME.get()) {
RouteCalculationResult.NextDirectionInfo nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc1, true);
text = routingHelper.getCurrentName(type, nextDirInfo);
if (text == null) {
text = "";
} else {
if (type[0] == null) {
showMarker = true;
} else {
turnDrawable.setColor(R.color.nav_arrow);
}
}
RouteDirectionInfo directionInfo = nextDirInfo.directionInfo;
if (nextDirInfo.imminent >= 0) {
imminentTurn = true;
} else {
imminentTurn = false;
}
if (directionInfo != null && directionInfo.getExitInfo() != null) {
exitInfo = directionInfo.getExitInfo();
showExitInfo = true;
} else {
showExitInfo = false;
}
if (showExitInfo) {
if(!Algorithms.isEmpty(exitInfo.getExitStreetName())) {
text = exitInfo.getExitStreetName();
}
}
if (directionInfo != null && directionInfo.getRouteDataObject() != null) {
object = directionInfo.getRouteDataObject();
showShield = true;
}
streetName = routingHelper.getCurrentName(nextDirInfo);
turnDrawable.setColor(R.color.nav_arrow);
}
} else {
int di = MapRouteInfoMenu.getDirectionInfo();
if (di >= 0 && map.getMapRouteInfoMenu().isVisible() &&
di < routingHelper.getRouteDirections().size()) {
showNextTurn = true;
if (di >= 0 && map.getMapRouteInfoMenu().isVisible() && di < routingHelper.getRouteDirections().size()) {
showClosestWaypointFirstInAddress = false;
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
type[0] = next.getTurnType();
streetName = routingHelper.getCurrentName(routingHelper.getNextRouteDirectionInfo(calc1, true));
turnDrawable.setColor(R.color.nav_arrow_distant);
text = RoutingHelper.formatStreetName(next.getStreetName(), null, next.getDestinationName(), "»");
if (text == null) {
text = "";
}
} else {
text = null;
}
}
} else if (map.getMapViewTrackingUtilities().isMapLinkedToLocation() &&
settings.SHOW_STREET_NAME.get()) {
streetName = new RoutingHelper.CurrentStreetName();
RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
if (rt != null) {
Location lastKnownLocation = locationProvider.getLastKnownLocation();
text = RoutingHelper.formatStreetName(
streetName.text = RoutingHelper.formatStreetName(
rt.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()),
rt.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)),
rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)),
"»");
}
if (text == null) {
text = "";
} else {
Location lastKnownLocation = locationProvider.getLastKnownLocation();
if (!Algorithms.isEmpty(text) && lastKnownLocation != null) {
double dist =
CurrentPositionHelper.getOrthogonalDistance(rt, lastKnownLocation);
if (!Algorithms.isEmpty(streetName.text) && lastKnownLocation != null) {
double dist = CurrentPositionHelper.getOrthogonalDistance(rt, lastKnownLocation);
if (dist < 50) {
showMarker = true;
streetName.showMarker = true;
} else {
text = map.getResources().getString(R.string.shared_string_near) + " " + text;
streetName.text = map.getResources().getString(R.string.shared_string_near) + " " + streetName.text;
}
}
}
}
if (map.isTopToolbarActive() || !map.getContextMenu().shouldShowTopControls() || MapRouteInfoMenu.chooseRoutesVisible || MapRouteInfoMenu.waypointsVisible) {
updateVisibility(false);
} else if (!showNextTurn && updateWaypoint()) {
} else if (!showClosestWaypointFirstInAddress && updateWaypoint()) {
updateVisibility(true);
AndroidUiHelper.updateVisibility(addressText, false);
AndroidUiHelper.updateVisibility(addressTextShadow, false);
} else if (text == null) {
} else if (streetName == null) {
updateVisibility(false);
} else {
updateVisibility(true);
AndroidUiHelper.updateVisibility(waypointInfoBar, false);
AndroidUiHelper.updateVisibility(addressText, true);
AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0);
boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker;
this.showMarker = showMarker;
if (showShield && setRoadShield(shieldIcon, object)) {
if (streetName.shieldObject != null && setRoadShield(shieldIcon, streetName.shieldObject)) {
AndroidUiHelper.updateVisibility(shieldIcon, true);
} else {
AndroidUiHelper.updateVisibility(shieldIcon, false);
}
if (showExitInfo) {
String exitRef = exitInfo.getRef();
if (!Algorithms.isEmpty(exitRef) && imminentTurn) {
exitRefText.setText(exitRef);
AndroidUiHelper.updateVisibility(exitRefText, true);
} else {
AndroidUiHelper.updateVisibility(exitRefText, false);
}
if (!Algorithms.isEmpty(streetName.exitRef) ) {
exitRefText.setText(streetName.exitRef);
AndroidUiHelper.updateVisibility(exitRefText, true);
} else {
AndroidUiHelper.updateVisibility(exitRefText, false);
}
if (update) {
if (type[0] != null) {
if (turnDrawable.setTurnType(streetName.turnType) || streetName.showMarker != this.showMarker) {
this.showMarker = streetName.showMarker;
if (streetName.turnType != null) {
turnIcon.invalidateDrawable(turnDrawable);
turnIcon.setImageDrawable(turnDrawable);
AndroidUiHelper.updateVisibility(turnIcon, true);
} else if (showMarker) {
} else if (streetName.showMarker) {
Drawable marker = map.getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_start_navigation, R.color.color_myloc_distance);
turnIcon.setImageDrawable(marker);
AndroidUiHelper.updateVisibility(turnIcon, true);
@ -1120,9 +1062,12 @@ public class MapInfoWidgetsFactory {
AndroidUiHelper.updateVisibility(turnIcon, false);
}
}
if (!text.equals(addressText.getText().toString())) {
addressTextShadow.setText(text);
addressText.setText(text);
if(streetName.text == null || streetName.text.isEmpty()) {
addressTextShadow.setText("");
addressText.setText("");
} else if (!streetName.text.equals(addressText.getText().toString())) {
addressTextShadow.setText(streetName.text);
addressText.setText(streetName.text );
return true;
}
}