Fix location issue and fix download issue

This commit is contained in:
Victor Shcherb 2013-06-06 23:04:25 +02:00
parent 93e2cd2e2e
commit 6ec7c0b33e
6 changed files with 33 additions and 33 deletions

View file

@ -307,7 +307,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
newSegment = true; newSegment = true;
} else { } else {
float[] lastInterval = new float[1]; float[] lastInterval = new float[1];
Location.distanceBetween(lat, lon, lastPoint.getLatitude(), lastPoint.getLongitude(), lastInterval); net.osmand.Location.distanceBetween(lat, lon, lastPoint.getLatitude(), lastPoint.getLongitude(), lastInterval);
distance += lastInterval[0]; distance += lastInterval[0];
lastPoint = new LatLon(lat, lon); lastPoint = new LatLon(lat, lon);
} }

View file

@ -686,7 +686,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
if(loc != null){ if(loc != null){
mes = new float[2]; mes = new float[2];
LatLon l = amenity.getLocation(); LatLon l = amenity.getLocation();
Location.distanceBetween(l.getLatitude(), l.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes); net.osmand.Location.distanceBetween(l.getLatitude(), l.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes);
} }
int opened = -1; int opened = -1;
if (amenity.getOpeningHours() != null) { if (amenity.getOpeningHours() != null) {

View file

@ -44,7 +44,6 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
list.clear(); list.clear();
list.addAll(cats); list.addAll(cats);
} }
updateLoadedFiles();
okColor = downloadActivity.getResources().getColor(R.color.color_ok); okColor = downloadActivity.getResources().getColor(R.color.color_ok);
TypedArray ta = downloadActivity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary}); TypedArray ta = downloadActivity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown)); defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown));
@ -52,20 +51,10 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
updateColor = downloadActivity.getResources().getColor(R.color.color_update); updateColor = downloadActivity.getResources().getColor(R.color.color_update);
} }
public void updateLoadedFiles() { public void setLoadedFiles(Map<String, String> indexActivatedFileNames, Map<String, String> indexFileNames) {
indexActivatedFileNames = getMyApplication().getResourceManager().getIndexFileNames(); this.indexFileNames = indexFileNames;
DownloadIndexActivity.listWithAlternatives(getMyApplication().getAppPath(""), this.indexActivatedFileNames = indexActivatedFileNames;
IndexConstants.EXTRA_EXT, indexActivatedFileNames); notifyDataSetInvalidated();
indexFileNames = getMyApplication().getResourceManager().getIndexFileNames();
DownloadIndexActivity.listWithAlternatives(getMyApplication().getAppPath(""),
IndexConstants.EXTRA_EXT, indexFileNames);
DownloadIndexActivity.listWithAlternatives(getMyApplication().getAppPath(IndexConstants.TILES_INDEX_DIR),
IndexConstants.SQLITE_EXT, indexFileNames);
getMyApplication().getResourceManager().getBackupIndexes(indexFileNames);
}
private OsmandApplication getMyApplication() {
return (OsmandApplication) downloadActivity.getApplication();
} }
public void collapseTrees(final CharSequence constraint) { public void collapseTrees(final CharSequence constraint) {
@ -93,7 +82,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
} }
public synchronized void setIndexFiles(List<IndexItem> indexFiles, Collection<? extends IndexItemCategory> cats) { public void setIndexFiles(List<IndexItem> indexFiles, Collection<? extends IndexItemCategory> cats) {
this.indexFiles.clear(); this.indexFiles.clear();
this.indexFiles.addAll(indexFiles); this.indexFiles.addAll(indexFiles);
list.clear(); list.clear();

View file

@ -8,6 +8,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -58,6 +59,8 @@ public class DownloadIndexesThread {
private final static Log log = PlatformUtil.getLog(DownloadIndexesThread.class); private final static Log log = PlatformUtil.getLog(DownloadIndexesThread.class);
private DownloadFileHelper downloadFileHelper; private DownloadFileHelper downloadFileHelper;
private List<BasicProgressAsyncTask<?, ?, ?> > currentRunningTask = Collections.synchronizedList(new ArrayList<BasicProgressAsyncTask<?, ?, ?>>()); private List<BasicProgressAsyncTask<?, ?, ?> > currentRunningTask = Collections.synchronizedList(new ArrayList<BasicProgressAsyncTask<?, ?, ?>>());
private Map<String, String> indexFileNames = new LinkedHashMap<String, String>();
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<String, String>();
public DownloadIndexesThread(Context ctx) { public DownloadIndexesThread(Context ctx) {
this.ctx = ctx; this.ctx = ctx;
@ -83,6 +86,20 @@ public class DownloadIndexesThread {
return indexFiles != null ? indexFiles.getIndexFiles() : null; return indexFiles != null ? indexFiles.getIndexFiles() : null;
} }
public void updateLoadedFiles() {
Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexActivity.listWithAlternatives(app.getAppPath(""),
IndexConstants.EXTRA_EXT, indexActivatedFileNames);
Map<String, String> indexFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexActivity.listWithAlternatives(app.getAppPath(""),
IndexConstants.EXTRA_EXT, indexFileNames);
DownloadIndexActivity.listWithAlternatives(app.getAppPath(IndexConstants.TILES_INDEX_DIR),
IndexConstants.SQLITE_EXT, indexFileNames);
app.getResourceManager().getBackupIndexes(indexFileNames);
this.indexFileNames = indexFileNames;
this.indexActivatedFileNames = indexActivatedFileNames;
}
public boolean isDownloadedFromInternet() { public boolean isDownloadedFromInternet() {
return indexFiles != null && indexFiles.isDownloadedFromInternet(); return indexFiles != null && indexFiles.isDownloadedFromInternet();
} }
@ -150,10 +167,9 @@ public class DownloadIndexesThread {
if (mainView != null) { if (mainView != null) {
mainView.setKeepScreenOn(false); mainView.setKeepScreenOn(false);
} }
updateLoadedFiles();
DownloadIndexAdapter adapter = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()); DownloadIndexAdapter adapter = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter());
if (adapter != null) { if (adapter != null) {
adapter.notifyDataSetInvalidated(); adapter.setLoadedFiles(indexActivatedFileNames, indexFileNames);
} }
} }
currentRunningTask.remove(this); currentRunningTask.remove(this);
@ -163,13 +179,6 @@ public class DownloadIndexesThread {
} }
private void updateLoadedFiles() {
if (uiActivity != null) {
((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).notifyDataSetInvalidated();
((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).updateLoadedFiles();
}
}
@Override @Override
protected String doInBackground(IndexItem... filesToDownload) { protected String doInBackground(IndexItem... filesToDownload) {
try { try {
@ -242,6 +251,7 @@ public class DownloadIndexesThread {
warn = breakDownloadMessage; warn = breakDownloadMessage;
} }
} }
updateLoadedFiles();
return warn; return warn;
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.info("Download Interrupted"); log.info("Download Interrupted");
@ -452,6 +462,7 @@ public class DownloadIndexesThread {
protected List<IndexItem> doInBackground(Void... params) { protected List<IndexItem> doInBackground(Void... params) {
final List<IndexItem> filtered = getFilteredByType(); final List<IndexItem> filtered = getFilteredByType();
cats = IndexItemCategory.categorizeIndexItems(app, filtered); cats = IndexItemCategory.categorizeIndexItems(app, filtered);
updateLoadedFiles();
return filtered; return filtered;
}; };
@ -499,6 +510,7 @@ public class DownloadIndexesThread {
protected void onPostExecute(List<IndexItem> filtered) { protected void onPostExecute(List<IndexItem> filtered) {
if (uiActivity != null) { if (uiActivity != null) {
DownloadIndexAdapter a = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()); DownloadIndexAdapter a = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter());
a.setLoadedFiles(indexActivatedFileNames, indexFileNames);
a.setIndexFiles(filtered, cats); a.setIndexFiles(filtered, cats);
a.notifyDataSetChanged(); a.notifyDataSetChanged();
a.getFilter().filter(uiActivity.getFilterText()); a.getFilter().filter(uiActivity.getFilterText());

View file

@ -450,7 +450,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
OsmandMapTileView view = map.getMapView(); OsmandMapTileView view = map.getMapView();
int d = 0; int d = 0;
if (d == 0) { if (d == 0) {
Location.distanceBetween(view.getLatitude(), view.getLongitude(), parkingPoint.getLatitude(), parkingPoint.getLongitude(), calculations); net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), parkingPoint.getLatitude(), parkingPoint.getLongitude(), calculations);
d = (int) calculations[0]; d = (int) calculations[0];
} }
if (distChanged(cachedMeters, d)) { if (distChanged(cachedMeters, d)) {

View file

@ -20,7 +20,6 @@ import android.graphics.Paint.Align;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.RectF; import android.graphics.RectF;
import android.location.Location;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager; import android.view.WindowManager;
@ -115,7 +114,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
canvas.rotate(-view.getRotate(), locationX, locationY); canvas.rotate(-view.getRotate(), locationX, locationY);
canvas.drawBitmap(targetPoint, locationX - marginX, locationY - marginY, bitmapPaint); canvas.drawBitmap(targetPoint, locationX - marginX, locationY - marginY, bitmapPaint);
} else if (pointToNavigate != null && view.getSettings().SHOW_DESTINATION_ARROW.get()) { } else if (pointToNavigate != null && view.getSettings().SHOW_DESTINATION_ARROW.get()) {
Location.distanceBetween(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(),
pointToNavigate.getLongitude(), calculations); pointToNavigate.getLongitude(), calculations);
float bearing = calculations[1] - 90; float bearing = calculations[1] - 90;
float radiusBearing = DIST_TO_SHOW * dm.density; float radiusBearing = DIST_TO_SHOW * dm.density;