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 FIELD_LEFT_HAND_DRIVING = "left_hand_driving";
public static final String FIELD_DOWNLOAD_NAME = "download_name";
public static final String FIELD_NAME = "name";
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_FULL_NAME = "region_full_name";
public static final String FIELD_LANG = "lang";
public static final String FIELD_METRIC = "metric";
public static final String FIELD_ROAD_SIGNS = "road_signs";
public static final String FIELD_LANG = "region_lang";
public static final String FIELD_METRIC = "region_metric";
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 String locale = "en";
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandRegions.class);
@ -164,10 +164,10 @@ public class OsmandRegions {
return rd.getLocaleName();
}
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)) {
return parentParent.getRegionId() + " " + rd.getLocaleName();
return parentParent.getLocaleName() + " " + rd.getLocaleName();
}
return parent.getLocaleName() + " " + rd.getLocaleName();
} else {
@ -389,10 +389,10 @@ public class OsmandRegions {
rd.regionName = mapIndexFields.get(mapIndexFields.nameType, object);
rd.regionNameLocale = mapIndexFields.get(mapIndexFields.nameLocaleType, object);
rd.regionNameEn = mapIndexFields.get(mapIndexFields.nameEnType, object);
rd.regionLang = mapIndexFields.get(mapIndexFields.langType, object);
rd.regionLeftHandDriving = mapIndexFields.get(mapIndexFields.leftHandDrivingType, object);
rd.regionMetric = mapIndexFields.get(mapIndexFields.metricType, object);
rd.regionRoadSigns = mapIndexFields.get(mapIndexFields.roadSignsType, object);
rd.params.regionLang = mapIndexFields.get(mapIndexFields.langType, object);
rd.params.regionLeftHandDriving = mapIndexFields.get(mapIndexFields.leftHandDrivingType, object);
rd.params.regionMetric = mapIndexFields.get(mapIndexFields.metricType, object);
rd.params.regionRoadSigns = mapIndexFields.get(mapIndexFields.roadSignsType, object);
rd.regionSearchText = getSearchIndex(object);
rd.regionMapDownload = isDownloadOfType(object, MAP_TYPE);
return rd;

View file

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

View file

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

View file

@ -1,18 +1,28 @@
package net.osmand.plus.download;
import java.io.File;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StatFs;
import android.support.annotation.UiThread;
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.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.map.WorldRegion;
import net.osmand.map.WorldRegion.RegionParams;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.DrivingRegion;
@ -34,23 +44,14 @@ import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import org.apache.commons.logging.Log;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StatFs;
import android.support.annotation.UiThread;
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 java.io.File;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
public class DownloadActivity extends ActionBarProgressActivity implements DownloadEvents {
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) {
// 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);
DrivingRegion drg = null;
boolean americanSigns = "american".equals(reg.getRegionRoadSigns());
boolean leftHand = "yes".equals(reg.getRegionLeftHandDriving());
MetricsConstants mc = "miles".equals(reg.getRegionMetric()) ?
RegionParams params = reg.getParams();
boolean americanSigns = "american".equals(params.getRegionRoadSigns());
boolean leftHand = "yes".equals(params.getRegionLeftHandDriving());
MetricsConstants mc = "miles".equals(params.getRegionMetric()) ?
MetricsConstants.MILES_AND_FOOTS : MetricsConstants.KILOMETERS_AND_METERS;
for (DrivingRegion r : DrivingRegion.values()) {
if(r.americanSigns == americanSigns && r.leftHandDriving == leftHand &&
@ -515,8 +517,9 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
if (drg != null) {
getMyApplication().getSettings().DRIVING_REGION.set(drg);
}
String lng = reg.getRegionLang();
if (lng != null) {
String lang = params.getRegionLang();
if (lang != null) {
String lng = lang.split(",")[0];
String setTts = null;
for (String s : OsmandSettings.TTS_AVAILABLE_VOICES) {
if (lng.startsWith(s)) {
@ -567,10 +570,9 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
}
private void showFirstTimeExternalStorage() {
// TODO finish + test & hide dialog if the download has started
final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(this);
final boolean externalExists =
DataStoragePlaceDialogFragment.getExternalStorageDirectory() != null;
getMyApplication().getSettings().getSecondaryStorage() != null;
if (firstTime && externalExists) {
new DataStoragePlaceDialogFragment().show(getFragmentManager(), null);
}

View file

@ -102,14 +102,21 @@ public class DownloadResourceGroup {
public WorldRegion getIndexItemRegion(IndexItem item) {
DownloadResourceGroup group = getIndexItemGroup(item);
return getRegion(group);
}
public static WorldRegion getRegion(DownloadResourceGroup group) {
if (group != null) {
if (group.getRegion() != null) {
return group.getRegion();
} 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) {

View file

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

View file

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

View file

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