From f648fc7f77edf7310594e7fd450ce81c70f55e62 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 17 Mar 2017 22:04:38 +0300 Subject: [PATCH] Added fonts download --- .../src/net/osmand/IndexConstants.java | 5 +- OsmAnd/res/values/strings.xml | 1 + .../plus/activities/LocalIndexHelper.java | 25 ++++++++++ .../plus/download/DownloadActivity.java | 16 +++++++ .../plus/download/DownloadActivityType.java | 46 +++++++++++++++---- .../plus/download/DownloadIndexesThread.java | 1 + .../plus/download/DownloadResourceGroup.java | 16 ++++--- .../plus/download/DownloadResources.java | 30 ++++++++---- .../download/ui/DownloadGroupViewHolder.java | 2 + .../ui/DownloadResourceGroupFragment.java | 2 + .../plus/download/ui/ItemViewHolder.java | 2 + .../download/ui/LocalIndexesFragment.java | 5 +- .../download/ui/SearchDialogFragment.java | 3 +- .../helpers/FileNameTranslationHelper.java | 14 ++++-- .../controllers/MapDataMenuController.java | 2 + .../plus/resources/ResourceManager.java | 18 ++++++++ 16 files changed, 157 insertions(+), 31 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/IndexConstants.java b/OsmAnd-java/src/net/osmand/IndexConstants.java index e7134506d5..5d41d0a9c7 100644 --- a/OsmAnd-java/src/net/osmand/IndexConstants.java +++ b/OsmAnd-java/src/net/osmand/IndexConstants.java @@ -33,7 +33,9 @@ public class IndexConstants { public static final String TTSVOICE_INDEX_EXT_ZIP = ".ttsvoice.zip"; //$NON-NLS-1$ public static final String ANYVOICE_INDEX_EXT_ZIP = "voice.zip"; //$NON-NLS-1$ //to cactch both voices, .voice.zip and .ttsvoice.zip - + public static final String FONT_INDEX_EXT = ".otf"; //$NON-NLS-1$ + public static final String FONT_INDEX_EXT_ZIP = ".otf.zip"; //$NON-NLS-1$ + public static final String RENDERER_INDEX_EXT = ".render.xml"; //$NON-NLS-1$ @@ -53,6 +55,7 @@ public class IndexConstants { public static final String ROADS_INDEX_DIR = "roads/"; //$NON-NLS-1$ public static final String WIKI_INDEX_DIR = "wiki/"; //$NON-NLS-1$ public static final String AV_INDEX_DIR = "avnotes/"; //$NON-NLS-1$ + public static final String FONT_INDEX_DIR = "fonts/"; //$NON-NLS-1$ public static final String VOICE_INDEX_DIR = "voice/"; //$NON-NLS-1$ public static final String RENDERERS_DIR = "rendering/"; //$NON-NLS-1$ public static final String ROUTING_XML_FILE= "routing.xml"; diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 1830b17a05..9cb2860bcd 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Fonts for map Right-hand driving Automatic Do not send anonymous app usage diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java index 4ffea1a5ee..8149945230 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java @@ -89,6 +89,8 @@ public class LocalIndexHelper { info.setDescription(getInstalledDate(f)); } else if (info.getType() == LocalIndexType.VOICE_DATA) { info.setDescription(getInstalledDate(f)); + } else if (info.getType() == LocalIndexType.FONT_DATA) { + info.setDescription(getInstalledDate(f)); } } @@ -210,6 +212,7 @@ public class LocalIndexHelper { loadWikiData(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), result, loadTask); //loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask); loadVoiceData(app.getAppPath(IndexConstants.VOICE_INDEX_DIR), result, false, loadTask); + loadFontData(app.getAppPath(IndexConstants.FONT_INDEX_DIR), result, false, loadTask); loadObfData(app.getAppPath(IndexConstants.BACKUP_INDEX_DIR), result, true, loadTask, loadedMaps); return result; @@ -255,6 +258,20 @@ public class LocalIndexHelper { } } + private void loadFontData(File fontDir, List result, boolean backup, AbstractLoadLocalIndexTask loadTask) { + if (fontDir.canRead()) { + for (File fontFile : listFilesSorted(fontDir)) { + if (fontFile.isFile() && fontFile.getName().endsWith(IndexConstants.FONT_INDEX_EXT)) { + LocalIndexType lt = LocalIndexType.FONT_DATA; + LocalIndexInfo info = new LocalIndexInfo(lt, fontFile, backup, app); + updateDescription(info); + result.add(info); + loadTask.loadFile(info); + } + } + } + } + private void loadTilesData(File tilesPath, List result, boolean backup, AbstractLoadLocalIndexTask loadTask) { if (tilesPath.canRead()) { for (File tileFile : listFilesSorted(tilesPath)) { @@ -342,6 +359,7 @@ public class LocalIndexHelper { WIKI_DATA(R.string.local_indexes_cat_wiki, R.drawable.ic_plugin_wikipedia, 50), TTS_VOICE_DATA(R.string.local_indexes_cat_tts, R.drawable.ic_action_volume_up, 20), VOICE_DATA(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up, 30), + FONT_DATA(R.string.fonts_header, R.drawable.ic_action_map_language, 35), DEACTIVATED(R.string.local_indexes_cat_backup, R.drawable.ic_type_archive, 1000); // AV_DATA(R.string.local_indexes_cat_av);; @@ -392,6 +410,13 @@ public class LocalIndexHelper { } return fileName.substring(0, l); } + if (this == FONT_DATA) { + int l = fileName.indexOf('.'); + if (l == -1) { + l = fileName.length(); + } + return fileName.substring(0, l).replace('_', ' ').replace('-', ' '); + } int ls = fileName.lastIndexOf('_'); if (ls >= 0) { return fileName.substring(0, ls); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index 1d54cac532..f827c8a434 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -2,6 +2,7 @@ package net.osmand.plus.download; import android.Manifest; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.os.AsyncTask; @@ -17,6 +18,7 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewPager; import android.support.v4.widget.Space; +import android.support.v7.app.AlertDialog; import android.support.v7.widget.AppCompatButton; import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; @@ -33,6 +35,7 @@ import android.widget.TextView; import android.widget.Toast; import net.osmand.IProgress; +import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.access.AccessibilityAssistant; import net.osmand.data.LatLon; @@ -281,6 +284,19 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo downloadItem = null; downloadTargetFileName = null; } + if (!Algorithms.isEmpty(downloadTargetFileName) && downloadTargetFileName.endsWith(IndexConstants.FONT_INDEX_EXT)) { + AlertDialog.Builder bld = new AlertDialog.Builder(this); + bld.setMessage(R.string.restart_is_required); + bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + android.os.Process.killProcess(android.os.Process.myPid()); + } + }); + bld.setNegativeButton(R.string.shared_string_cancel, null); + bld.show(); + } for (WeakReference ref : fragSet) { Fragment f = ref.get(); if (f instanceof DownloadEvents && f.isAdded()) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index 71015c0115..695beb7093 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -33,17 +33,16 @@ public class DownloadActivityType { new DownloadActivityType(R.string.download_regular_maps, "map", 10); public static final DownloadActivityType VOICE_FILE = new DownloadActivityType(R.string.voices, R.drawable.ic_action_volume_up, "voice", 20); + public static final DownloadActivityType FONT_FILE = + new DownloadActivityType(R.string.fonts_header, R.drawable.ic_action_map_language, "fonts", 25); public static final DownloadActivityType ROADS_FILE = new DownloadActivityType(R.string.download_roads_only_maps, "road_map", 30); public static final DownloadActivityType SRTM_COUNTRY_FILE = - new DownloadActivityType(R.string.download_srtm_maps, - R.drawable.ic_plugin_srtm, "srtm_map", 40); + new DownloadActivityType(R.string.download_srtm_maps, R.drawable.ic_plugin_srtm, "srtm_map", 40); public static final DownloadActivityType HILLSHADE_FILE = - new DownloadActivityType(R.string.download_hillshade_maps, - R.drawable.ic_action_hillshade_dark, "hillshade", 50); + new DownloadActivityType(R.string.download_hillshade_maps, R.drawable.ic_action_hillshade_dark, "hillshade", 50); public static final DownloadActivityType WIKIPEDIA_FILE = - new DownloadActivityType(R.string.download_wikipedia_maps, - R.drawable.ic_plugin_wikipedia, "wikimap", 60); + new DownloadActivityType(R.string.download_wikipedia_maps, R.drawable.ic_plugin_wikipedia, "wikimap", 60); public static final DownloadActivityType LIVE_UPDATES_FILE = new DownloadActivityType(R.string.download_live_updates, "live_updates", 70); private final int stringResource; @@ -115,6 +114,8 @@ public class DownloadActivityType { return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)); } else if (VOICE_FILE == this) { return fileName.endsWith(addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION)); + } else if (FONT_FILE == this) { + return fileName.endsWith(IndexConstants.FONT_INDEX_EXT_ZIP); } else if (WIKIPEDIA_FILE == this) { return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)); @@ -135,6 +136,8 @@ public class DownloadActivityType { return ctx.getAppPath(IndexConstants.MAPS_PATH); } else if (VOICE_FILE == this) { return ctx.getAppPath(IndexConstants.VOICE_INDEX_DIR); + } else if (FONT_FILE == this) { + return ctx.getAppPath(IndexConstants.FONT_INDEX_DIR); } else if (ROADS_FILE == this) { return ctx.getAppPath(IndexConstants.ROADS_INDEX_DIR); } else if (SRTM_COUNTRY_FILE == this) { @@ -178,6 +181,8 @@ public class DownloadActivityType { return IndexConstants.BINARY_ROAD_MAP_INDEX_EXT; } else if (VOICE_FILE == this) { return ""; + } else if (FONT_FILE == this) { + return IndexConstants.FONT_INDEX_EXT; } else if (SRTM_COUNTRY_FILE == this) { return IndexConstants.BINARY_SRTM_MAP_INDEX_EXT; } else if (WIKIPEDIA_FILE == this) { @@ -199,15 +204,20 @@ public class DownloadActivityType { return "&srtmcountry=yes"; } else if (this == DownloadActivityType.WIKIPEDIA_FILE) { return "&wiki=yes"; - }else if (this== DownloadActivityType.HILLSHADE_FILE) { + }else if (this == DownloadActivityType.HILLSHADE_FILE) { return "&hillshade=yes"; } return ""; } public String getBaseUrl(OsmandApplication ctx, String fileName) { - return "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&" - + Version.getVersionAsURLParam(ctx) + "&file=" + encode(fileName); + if (this == FONT_FILE) { + return "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&fonts=yes&" + + Version.getVersionAsURLParam(ctx) + "&file=" + encode(fileName); + } else { + return "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&" + + Version.getVersionAsURLParam(ctx) + "&file=" + encode(fileName); + } } @@ -268,9 +278,12 @@ public class DownloadActivityType { } return getBasename(indexItem); } + if (this == FONT_FILE) { + return FileNameTranslationHelper.getFontName(ctx, getBasename(indexItem)); + } final String basename = getBasename(indexItem); if (basename.endsWith(FileNameTranslationHelper.WIKI_NAME)){ - return FileNameTranslationHelper.getWikiName(ctx,basename); + return FileNameTranslationHelper.getWikiName(ctx, basename); } // if (this == HILLSHADE_FILE){ // return FileNameTranslationHelper.getHillShadeName(ctx, osmandRegions, bn); @@ -300,6 +313,12 @@ public class DownloadActivityType { l = fileName.length(); } return fileName.substring(0, l); + } else if (this == FONT_FILE) { + int l = fileName.indexOf('.'); + if (l == -1) { + l = fileName.length(); + } + return fileName.substring(0, l) + IndexConstants.FONT_INDEX_EXT; } else if (this == HILLSHADE_FILE) { return fileName.replace('_', ' '); } else if (this == LIVE_UPDATES_FILE) { @@ -355,6 +374,13 @@ public class DownloadActivityType { } return fileName.substring(0, l); } + if (this == FONT_FILE) { + int l = fileName.indexOf('.'); + if (l == -1) { + l = fileName.length(); + } + return fileName.substring(0, l); + } if (this == LIVE_UPDATES_FILE) { if(fileName.indexOf('.') > 0){ return fileName.substring(0, fileName.indexOf('.')); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 3d07372e06..cb7168a77b 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -586,6 +586,7 @@ public class DownloadIndexesThread { } List warnings = new ArrayList(); manager.indexVoiceFiles(this); + manager.indexFontFiles(this); if (vectorMapsToReindex) { warnings = manager.indexingMaps(this); } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java index 603b533be1..403610ba38 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java @@ -37,12 +37,15 @@ public class DownloadResourceGroup { // headers with voice items VOICE_HEADER_TTS(R.string.index_name_tts_voice), VOICE_HEADER_REC(R.string.index_name_voice), + // headers with font items + FONTS_HEADER(R.string.fonts_header), // headers with resources OTHER_MAPS_GROUP(R.string.download_select_map_types), - VOICE_GROUP(R.string.voices), + OTHER_GROUP(R.string.other_menu_group), SUBREGIONS(R.string.regions), // screen items VOICE_TTS(R.string.index_name_tts_voice), + FONTS(R.string.fonts_header), VOICE_REC(R.string.index_name_voice), OTHER_MAPS(R.string.download_select_map_types), WORLD(-1), @@ -56,7 +59,7 @@ public class DownloadResourceGroup { public boolean isScreen() { return this == WORLD || this == REGION || this == VOICE_TTS - || this == VOICE_REC || this == OTHER_MAPS; + || this == VOICE_REC || this == OTHER_MAPS || this == FONTS; } public String getDefaultId() { @@ -68,18 +71,19 @@ public class DownloadResourceGroup { } public boolean containsIndexItem() { - return isHeader() && this != SUBREGIONS && this != VOICE_GROUP && this != OTHER_MAPS_GROUP; + return isHeader() && this != SUBREGIONS && this != OTHER_GROUP && this != OTHER_MAPS_GROUP; } public boolean isHeader() { return this == VOICE_HEADER_REC || this == VOICE_HEADER_TTS || this == SUBREGIONS - || this == WORLD_MAPS || this == REGION_MAPS || this == VOICE_GROUP + || this == WORLD_MAPS || this == REGION_MAPS || this == OTHER_GROUP || this == HILLSHADE_HEADER || this == SRTM_HEADER - || this == OTHER_MAPS_HEADER || this == OTHER_MAPS_GROUP; + || this == OTHER_MAPS_HEADER || this == OTHER_MAPS_GROUP + || this == FONTS_HEADER; } public static String getVoiceTTSId() { - return "#" + VOICE_GROUP.name().toLowerCase() + "#" + VOICE_TTS.name().toLowerCase(); + return "#" + OTHER_GROUP.name().toLowerCase() + "#" + VOICE_TTS.name().toLowerCase(); } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index a29c694b9b..17d8a4b0e6 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -155,6 +155,8 @@ public class DownloadResources extends DownloadResourceGroup { } } } + } else if (item.getType() == DownloadActivityType.FONT_FILE) { + oldItemSize = new File(app.getAppPath(IndexConstants.FONT_INDEX_DIR), item.getTargetFileName()).length(); } else { oldItemSize = app.getAppPath(item.getTargetFileName()).length(); } @@ -244,11 +246,13 @@ public class DownloadResources extends DownloadResourceGroup { otherMapsScreen.addGroup(otherMaps); otherMapsGroup.addGroup(otherMapsScreen); - DownloadResourceGroup voiceGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.VOICE_GROUP); - DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_TTS); - DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_REC); - DownloadResourceGroup voiceTTS = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_HEADER_TTS); - DownloadResourceGroup voiceRec = new DownloadResourceGroup(voiceGroup, DownloadResourceGroupType.VOICE_HEADER_REC); + DownloadResourceGroup otherGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.OTHER_GROUP); + DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_TTS); + DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_REC); + DownloadResourceGroup fontScreen = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS); + DownloadResourceGroup voiceTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_TTS); + DownloadResourceGroup voiceRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_REC); + DownloadResourceGroup fonts = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS_HEADER); DownloadResourceGroup worldMaps = new DownloadResourceGroup(this, DownloadResourceGroupType.WORLD_MAPS); Map > groupByRegion = new LinkedHashMap>(); @@ -262,6 +266,10 @@ public class DownloadResources extends DownloadResourceGroup { } continue; } + if (ii.getType() == DownloadActivityType.FONT_FILE) { + fonts.addItem(ii); + continue; + } String basename = ii.getBasename().toLowerCase(); WorldRegion wg = regs.getRegionDataByDownloadName(basename); if (wg != null) { @@ -322,9 +330,15 @@ public class DownloadResources extends DownloadResourceGroup { voiceScreenTTS.addGroup(voiceTTS); voiceScreenRec.addGroup(voiceRec); - voiceGroup.addGroup(voiceScreenTTS); - voiceGroup.addGroup(voiceScreenRec); - addGroup(voiceGroup); + if (fonts.getIndividualResources() != null) { + fontScreen.addGroup(fonts); + } + otherGroup.addGroup(voiceScreenTTS); + otherGroup.addGroup(voiceScreenRec); + if (fonts.getIndividualResources() != null) { + otherGroup.addGroup(fontScreen); + } + addGroup(otherGroup); createHillshadeSRTMGroups(); trimEmptyGroups(); diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java index 34643969bd..0801b8368d 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java @@ -30,6 +30,8 @@ public class DownloadGroupViewHolder { if (group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_REC || group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_TTS) { iconLeft = ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_volume_up); + } else if (group.getType() == DownloadResourceGroup.DownloadResourceGroupType.FONTS) { + iconLeft = ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_map_language); } else { IconsCache cache = ctx.getMyApplication().getIconsCache(); if (isParentWorld(group) || isParentWorld(group.getParentGroup())) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java index c18caef529..3475f99f65 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java @@ -308,6 +308,8 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow if (group.getType() == DownloadResourceGroupType.VOICE_REC || group.getType() == DownloadResourceGroupType.VOICE_TTS) { iconLeft = ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_volume_up); + } else if (group.getType() == DownloadResourceGroupType.FONTS) { + iconLeft = ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_map_language); } else { IconsCache cache = ctx.getMyApplication().getIconsCache(); if (isParentWorld(group) || isParentWorld(group.getParentGroup())) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 4e914fac8d..5bd9a3ab5b 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -400,6 +400,8 @@ public class ItemViewHolder { tp = LocalIndexType.SRTM_DATA; } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE) { tp = LocalIndexType.MAP_DATA; + } else if (indexItem.getType() == DownloadActivityType.FONT_FILE) { + tp = LocalIndexType.FONT_DATA; } else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) { tp = indexItem.getBasename().contains("tts") ? LocalIndexType.TTS_VOICE_DATA : LocalIndexType.VOICE_DATA; diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index 32a3b6bf76..2115f507d6 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -197,7 +197,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement .setListener(listener) .setPosition(2).createItem()); } - if (info.getType() != LocalIndexType.TTS_VOICE_DATA && info.getType() != LocalIndexType.VOICE_DATA) { + if (info.getType() != LocalIndexType.TTS_VOICE_DATA && info.getType() != LocalIndexType.VOICE_DATA + && info.getType() != LocalIndexType.FONT_DATA) { adapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.shared_string_rename, getContext()) .setListener(listener) @@ -447,6 +448,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR); } else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) { parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR); + } else if (i.getOriginalType() == LocalIndexType.FONT_DATA) { + parent = getMyApplication().getAppPath(IndexConstants.FONT_INDEX_DIR); } return new File(parent, i.getFileName()); } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java index acf3e9e205..c6f67cded9 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java @@ -478,7 +478,8 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven // process other maps & voice prompts if (group.getType() == DownloadResourceGroupType.OTHER_MAPS_HEADER || group.getType() == DownloadResourceGroupType.VOICE_HEADER_REC - || group.getType() == DownloadResourceGroupType.VOICE_HEADER_TTS) { + || group.getType() == DownloadResourceGroupType.VOICE_HEADER_TTS + || group.getType() == DownloadResourceGroupType.FONTS_HEADER) { if (group.getIndividualResources() != null) { for (IndexItem item : group.getIndividualResources()) { name = item.getVisibleName(ctx, osmandRegions, false).toLowerCase(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java index 67125b71a9..4dd39b3f2b 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java @@ -23,9 +23,11 @@ public class FileNameTranslationHelper { public static String getFileName(Context ctx, OsmandRegions regions, String fileName) { String basename = getBasename(fileName); if (basename.endsWith(WIKI_NAME)) { //wiki files - return getWikiName(ctx,basename); + return getWikiName(ctx, basename); } else if (fileName.endsWith("tts")) { //tts files return getVoiceName(ctx, fileName); + } else if (fileName.endsWith(IndexConstants.FONT_INDEX_EXT)) { //otf files + return getFontName(ctx, basename); } else if (fileName.startsWith(HILL_SHADE)){ return getHillShadeName(ctx, regions, basename); } else if (fileName.length() == 2) { //voice recorded files @@ -75,9 +77,9 @@ public class FileNameTranslationHelper { return wikiName + " " + ctx.getString(R.string.amenity_type_osmwiki); } - public static String getVoiceName(Context ctx, String basename) { + public static String getVoiceName(Context ctx, String fileName) { try { - String nm = basename.replace('-', '_').replace(' ', '_'); + String nm = fileName.replace('-', '_').replace(' ', '_'); if (nm.endsWith("_tts") || nm.endsWith("-tts")) { nm = nm.substring(0, nm.length() - 4); } @@ -89,7 +91,11 @@ public class FileNameTranslationHelper { } catch (Exception e) { System.err.println(e.getMessage()); } - return basename; + return fileName; + } + + public static String getFontName(Context ctx, String basename) { + return basename.replace('-', ' ').replace('_', ' '); } private static String getBasename(String fileName) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java index e35e800fa6..2e0c0c2e24 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java @@ -513,6 +513,8 @@ public class MapDataMenuController extends MenuController { } else if (localIndexInfo.getOriginalType() == LocalIndexType.TTS_VOICE_DATA || localIndexInfo.getOriginalType() == LocalIndexType.VOICE_DATA) { return DownloadActivityType.VOICE_FILE; + } else if (localIndexInfo.getOriginalType() == LocalIndexType.FONT_DATA) { + return DownloadActivityType.FONT_FILE; } else { return null; } diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 65fc477f58..ffcfdc8262 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -506,6 +506,7 @@ public class ResourceManager { // indexingImageTiles(progress); warnings.addAll(indexingMaps(progress)); warnings.addAll(indexVoiceFiles(progress)); + warnings.addAll(indexFontFiles(progress)); warnings.addAll(OsmandPlugin.onIndexingFiles(progress)); warnings.addAll(indexAdditionalMaps(progress)); return warnings; @@ -538,6 +539,23 @@ public class ResourceManager { } return warnings; } + + public List indexFontFiles(IProgress progress){ + File file = context.getAppPath(IndexConstants.FONT_INDEX_DIR); + file.mkdirs(); + List warnings = new ArrayList(); + if (file.exists() && file.canRead()) { + File[] lf = file.listFiles(); + if (lf != null) { + for (File f : lf) { + if (!f.isDirectory()) { + indexFileNames.put(f.getName(), dateFormat.format(f.lastModified())); + } + } + } + } + return warnings; + } private List checkAssets(IProgress progress) { String fv = Version.getFullVersion(context);