This commit is contained in:
Alexey Kulish 2015-10-26 19:56:21 +03:00
parent ff4e58b7b2
commit 4e42031882
8 changed files with 123 additions and 109 deletions

View file

@ -38,16 +38,16 @@ public class OsmandRegions {
public static final String MAP_TYPE = "region_map"; public static final String MAP_TYPE = "region_map";
public static final String FIELD_LEFT_HAND_DRIVING = "left_hand_driving";
public static final String FIELD_DOWNLOAD_NAME = "download_name"; public static final String FIELD_DOWNLOAD_NAME = "download_name";
public static final String FIELD_NAME = "name"; public static final String FIELD_NAME = "name";
public static final String FIELD_NAME_EN = "name:en"; public static final String FIELD_NAME_EN = "name:en";
public static final String FIELD_REGION_PARENT_NAME = "region_parent_name"; public static final String FIELD_REGION_PARENT_NAME = "region_parent_name";
public static final String FIELD_REGION_FULL_NAME = "region_full_name"; public static final String FIELD_REGION_FULL_NAME = "region_full_name";
public static final String FIELD_LANG = "lang"; public static final String FIELD_LANG = "region_lang";
public static final String FIELD_METRIC = "metric"; public static final String FIELD_METRIC = "region_metric";
public static final String FIELD_ROAD_SIGNS = "road_signs"; public static final String FIELD_ROAD_SIGNS = "region_road_signs";
public static final String FIELD_LEFT_HAND_DRIVING = "region_left_hand_navigation";
private BinaryMapIndexReader reader; private BinaryMapIndexReader reader;
private String locale = "en"; private String locale = "en";
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandRegions.class); private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandRegions.class);
@ -164,10 +164,10 @@ public class OsmandRegions {
return rd.getLocaleName(); return rd.getLocaleName();
} }
if(parentParent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) { if(parentParent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) {
return parentParent.getRegionId() + " " + rd.getLocaleName(); return parentParent.getLocaleName() + " " + rd.getLocaleName();
} }
if(parentParent.getRegionId().equals(WorldRegion.JAPAN_REGION_ID)) { if(parentParent.getRegionId().equals(WorldRegion.JAPAN_REGION_ID)) {
return parentParent.getRegionId() + " " + rd.getLocaleName(); return parentParent.getLocaleName() + " " + rd.getLocaleName();
} }
return parent.getLocaleName() + " " + rd.getLocaleName(); return parent.getLocaleName() + " " + rd.getLocaleName();
} else { } else {
@ -389,10 +389,10 @@ public class OsmandRegions {
rd.regionName = mapIndexFields.get(mapIndexFields.nameType, object); rd.regionName = mapIndexFields.get(mapIndexFields.nameType, object);
rd.regionNameLocale = mapIndexFields.get(mapIndexFields.nameLocaleType, object); rd.regionNameLocale = mapIndexFields.get(mapIndexFields.nameLocaleType, object);
rd.regionNameEn = mapIndexFields.get(mapIndexFields.nameEnType, object); rd.regionNameEn = mapIndexFields.get(mapIndexFields.nameEnType, object);
rd.regionLang = mapIndexFields.get(mapIndexFields.langType, object); rd.params.regionLang = mapIndexFields.get(mapIndexFields.langType, object);
rd.regionLeftHandDriving = mapIndexFields.get(mapIndexFields.leftHandDrivingType, object); rd.params.regionLeftHandDriving = mapIndexFields.get(mapIndexFields.leftHandDrivingType, object);
rd.regionMetric = mapIndexFields.get(mapIndexFields.metricType, object); rd.params.regionMetric = mapIndexFields.get(mapIndexFields.metricType, object);
rd.regionRoadSigns = mapIndexFields.get(mapIndexFields.roadSignsType, object); rd.params.regionRoadSigns = mapIndexFields.get(mapIndexFields.roadSignsType, object);
rd.regionSearchText = getSearchIndex(object); rd.regionSearchText = getSearchIndex(object);
rd.regionMapDownload = isDownloadOfType(object, MAP_TYPE); rd.regionMapDownload = isDownloadOfType(object, MAP_TYPE);
return rd; return rd;

View file

@ -25,10 +25,7 @@ public class WorldRegion {
protected List<WorldRegion> subregions; protected List<WorldRegion> subregions;
// filled by osmand regions // filled by osmand regions
protected String regionLeftHandDriving; protected RegionParams params = new RegionParams();
protected String regionLang;
protected String regionMetric;
protected String regionRoadSigns;
protected String regionFullName; protected String regionFullName;
protected String regionParentFullName; protected String regionParentFullName;
protected String regionName; protected String regionName;
@ -38,6 +35,30 @@ public class WorldRegion {
protected String regionDownloadName; protected String regionDownloadName;
protected boolean regionMapDownload; protected boolean regionMapDownload;
protected LatLon regionCenter; protected LatLon regionCenter;
public static class RegionParams {
protected String regionLeftHandDriving;
protected String regionLang;
protected String regionMetric;
protected String regionRoadSigns;
public String getRegionLeftHandDriving() {
return regionLeftHandDriving;
}
public String getRegionLang() {
return regionLang;
}
public String getRegionMetric() {
return regionMetric;
}
public String getRegionRoadSigns() {
return regionRoadSigns;
}
}
public boolean isRegionMapDownload() { public boolean isRegionMapDownload() {
@ -65,19 +86,11 @@ public class WorldRegion {
public String getRegionDownloadNameLC() { public String getRegionDownloadNameLC() {
return regionDownloadName == null ? null : regionDownloadName.toLowerCase(); return regionDownloadName == null ? null : regionDownloadName.toLowerCase();
} }
public String getRegionLeftHandDriving() { public RegionParams getParams() {
return regionLeftHandDriving; return params;
} }
public String getRegionMetric() {
return regionMetric;
}
public String getRegionRoadSigns() {
return regionRoadSigns;
}
public LatLon getRegionCenter() { public LatLon getRegionCenter() {
return regionCenter; return regionCenter;
} }
@ -85,11 +98,6 @@ public class WorldRegion {
public String getRegionSearchText() { public String getRegionSearchText() {
return regionSearchText; return regionSearchText;
} }
public String getRegionLang() {
return regionLang;
}
public WorldRegion getSuperregion() { public WorldRegion getSuperregion() {
return superregion; return superregion;

View file

@ -1,21 +1,16 @@
package net.osmand.plus; package net.osmand.plus;
import java.io.File; import android.annotation.TargetApi;
import java.io.IOException; import android.content.Context;
import java.lang.ref.WeakReference; import android.content.res.Configuration;
import java.util.ArrayList; import android.hardware.Sensor;
import java.util.Arrays; import android.hardware.SensorManager;
import java.util.Comparator; import android.net.ConnectivityManager;
import java.util.Iterator; import android.net.NetworkInfo;
import java.util.LinkedHashMap; import android.os.Build;
import java.util.LinkedHashSet; import android.os.Environment;
import java.util.LinkedList; import android.support.annotation.Nullable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.StateChangedListener; import net.osmand.StateChangedListener;
@ -34,17 +29,22 @@ import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import android.annotation.TargetApi;
import android.content.Context; import java.io.File;
import android.content.res.Configuration; import java.io.IOException;
import android.hardware.Sensor; import java.lang.ref.WeakReference;
import android.hardware.SensorManager; import java.util.ArrayList;
import android.net.ConnectivityManager; import java.util.Arrays;
import android.net.NetworkInfo; import java.util.Comparator;
import android.os.Build; import java.util.Iterator;
import android.os.Environment; import java.util.LinkedHashMap;
import android.support.annotation.Nullable; import java.util.LinkedHashSet;
import android.text.TextUtils; import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
public class OsmandSettings { public class OsmandSettings {
@ -1314,13 +1314,13 @@ public class OsmandSettings {
} }
@Nullable @Nullable
public static File getSecondaryStorage() { public File getSecondaryStorage() {
final String value = System.getenv("SECONDARY_STORAGE"); if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
if (!TextUtils.isEmpty(value)) { return getExternalStorageDirectoryPre19();
final String[] paths = value.split(":"); } else {
for (String path : paths) { File[] externals = ctx.getExternalFilesDirs(null);
File file = new File(path); for (File file : externals) {
if (file.isDirectory() && file.canWrite()) { if (!file.getAbsolutePath().contains("emulated")) {
return file; return file;
} }
} }

View file

@ -1,18 +1,28 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import java.io.File; import android.content.ActivityNotFoundException;
import java.lang.ref.WeakReference; import android.content.Intent;
import java.text.MessageFormat; import android.net.Uri;
import java.util.ArrayList; import android.os.AsyncTask;
import java.util.HashSet; import android.os.Bundle;
import java.util.List; import android.os.StatFs;
import java.util.Locale; import android.support.annotation.UiThread;
import java.util.Set; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
import net.osmand.map.WorldRegion.RegionParams;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.DrivingRegion; import net.osmand.plus.OsmandSettings.DrivingRegion;
@ -34,23 +44,14 @@ import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import android.content.ActivityNotFoundException; import java.io.File;
import android.content.Intent; import java.lang.ref.WeakReference;
import android.net.Uri; import java.text.MessageFormat;
import android.os.AsyncTask; import java.util.ArrayList;
import android.os.Bundle; import java.util.HashSet;
import android.os.StatFs; import java.util.List;
import android.support.annotation.UiThread; import java.util.Locale;
import android.support.v4.app.DialogFragment; import java.util.Set;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class DownloadActivity extends ActionBarProgressActivity implements DownloadEvents { public class DownloadActivity extends ActionBarProgressActivity implements DownloadEvents {
private static final Log LOG = PlatformUtil.getLog(DownloadActivity.class); private static final Log LOG = PlatformUtil.getLog(DownloadActivity.class);
@ -498,12 +499,13 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
} }
private void initSettingsFirstMap(WorldRegion reg) { private void initSettingsFirstMap(WorldRegion reg) {
// TODO test set correctly (4 tests): when you download first Australia, Japan, Luxembourgh, US // TODO Fix metric
getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(true); getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(true);
DrivingRegion drg = null; DrivingRegion drg = null;
boolean americanSigns = "american".equals(reg.getRegionRoadSigns()); RegionParams params = reg.getParams();
boolean leftHand = "yes".equals(reg.getRegionLeftHandDriving()); boolean americanSigns = "american".equals(params.getRegionRoadSigns());
MetricsConstants mc = "miles".equals(reg.getRegionMetric()) ? boolean leftHand = "yes".equals(params.getRegionLeftHandDriving());
MetricsConstants mc = "miles".equals(params.getRegionMetric()) ?
MetricsConstants.MILES_AND_FOOTS : MetricsConstants.KILOMETERS_AND_METERS; MetricsConstants.MILES_AND_FOOTS : MetricsConstants.KILOMETERS_AND_METERS;
for (DrivingRegion r : DrivingRegion.values()) { for (DrivingRegion r : DrivingRegion.values()) {
if(r.americanSigns == americanSigns && r.leftHandDriving == leftHand && if(r.americanSigns == americanSigns && r.leftHandDriving == leftHand &&
@ -515,8 +517,9 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
if (drg != null) { if (drg != null) {
getMyApplication().getSettings().DRIVING_REGION.set(drg); getMyApplication().getSettings().DRIVING_REGION.set(drg);
} }
String lng = reg.getRegionLang(); String lang = params.getRegionLang();
if (lng != null) { if (lang != null) {
String lng = lang.split(",")[0];
String setTts = null; String setTts = null;
for (String s : OsmandSettings.TTS_AVAILABLE_VOICES) { for (String s : OsmandSettings.TTS_AVAILABLE_VOICES) {
if (lng.startsWith(s)) { if (lng.startsWith(s)) {
@ -567,10 +570,9 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
} }
private void showFirstTimeExternalStorage() { private void showFirstTimeExternalStorage() {
// TODO finish + test & hide dialog if the download has started
final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(this); final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(this);
final boolean externalExists = final boolean externalExists =
DataStoragePlaceDialogFragment.getExternalStorageDirectory() != null; getMyApplication().getSettings().getSecondaryStorage() != null;
if (firstTime && externalExists) { if (firstTime && externalExists) {
new DataStoragePlaceDialogFragment().show(getFragmentManager(), null); new DataStoragePlaceDialogFragment().show(getFragmentManager(), null);
} }

View file

@ -102,14 +102,21 @@ public class DownloadResourceGroup {
public WorldRegion getIndexItemRegion(IndexItem item) { public WorldRegion getIndexItemRegion(IndexItem item) {
DownloadResourceGroup group = getIndexItemGroup(item); DownloadResourceGroup group = getIndexItemGroup(item);
return getRegion(group);
}
public static WorldRegion getRegion(DownloadResourceGroup group) {
if (group != null) { if (group != null) {
if (group.getRegion() != null) { if (group.getRegion() != null) {
return group.getRegion(); return group.getRegion();
} else if (group.getParentGroup() != null) { } else if (group.getParentGroup() != null) {
return group.getParentGroup().getRegion(); return getRegion(group.getParentGroup());
} else {
return null;
} }
} else {
return null;
} }
return null;
} }
public DownloadResourceGroup getIndexItemGroup(IndexItem item) { public DownloadResourceGroup getIndexItemGroup(IndexItem item) {

View file

@ -55,7 +55,7 @@ public class DataStoragePlaceDialogFragment extends DialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
internalStorage = getInternalStorageDirectory(getActivity()); internalStorage = getInternalStorageDirectory(getActivity());
externalStorage = getExternalStorageDirectory(); externalStorage = getMyApplication().getSettings().getSecondaryStorage();
final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container, final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container,
false); false);
@ -95,10 +95,6 @@ public class DataStoragePlaceDialogFragment extends DialogFragment {
return view; return view;
} }
public static File getExternalStorageDirectory() {
return OsmandSettings.getSecondaryStorage();
}
public static File getInternalStorageDirectory(Activity activity) { public static File getInternalStorageDirectory(Activity activity) {
return ((OsmandApplication) activity.getApplication()).getSettings() return ((OsmandApplication) activity.getApplication()).getSettings()
.getDefaultInternalStorage(); .getDefaultInternalStorage();

View file

@ -20,8 +20,8 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.map.WorldRegion;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
@ -209,7 +209,8 @@ public class ItemViewHolder {
protected void download(IndexItem indexItem, DownloadResourceGroup parentOptional) { protected void download(IndexItem indexItem, DownloadResourceGroup parentOptional) {
boolean handled = false; boolean handled = false;
if(parentOptional != null) { if(parentOptional != null) {
context.setDownloadItem(parentOptional.getRegion()); WorldRegion region = DownloadResourceGroup.getRegion(parentOptional);
context.setDownloadItem(region);
} }
if (indexItem.getType() == DownloadActivityType.ROADS_FILE && parentOptional != null) { if (indexItem.getType() == DownloadActivityType.ROADS_FILE && parentOptional != null) {
for (IndexItem ii : parentOptional.getIndividualResources()) { for (IndexItem ii : parentOptional.getIndividualResources()) {

View file

@ -1060,7 +1060,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
final String mapDescription = getMapDescription(child.getFileName()); final String mapDescription = getMapDescription(child.getFileName());
if (mapDescription.length() > 0) { if (mapDescription.length() > 0) {
builder.append(mapDescription).append(""); builder.append(mapDescription).append("");
} }
if (child.getSize() >= 0) { if (child.getSize() >= 0) {
@ -1069,7 +1069,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
} else { } else {
builder.append(child.getSize()).append(" KB"); builder.append(child.getSize()).append(" KB");
} }
builder.append(""); builder.append("");
} }
if (child.getType() == LocalIndexType.TILES_DATA) { if (child.getType() == LocalIndexType.TILES_DATA) {