Update download
This commit is contained in:
parent
85008c9c88
commit
0ae7340cb1
10 changed files with 516 additions and 322 deletions
|
@ -43,7 +43,7 @@ public class RenderingRulesStorage {
|
|||
public RenderingRuleStorageProperties PROPS = new RenderingRuleStorageProperties();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected TIntObjectHashMap<RenderingRule>[] tagValueGlobalRules = new TIntObjectHashMap[LENGTH_RULES];
|
||||
public TIntObjectHashMap<RenderingRule>[] tagValueGlobalRules = new TIntObjectHashMap[LENGTH_RULES];
|
||||
|
||||
protected Map<String, RenderingRule> renderingAttributes = new LinkedHashMap<String, RenderingRule>();
|
||||
protected Map<String, String> renderingConstants= new LinkedHashMap<String, String>();
|
||||
|
|
|
@ -12,10 +12,11 @@
|
|||
android:orientation="vertical"
|
||||
android:visibility="gone" >
|
||||
|
||||
<LinearLayout
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="3dp"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:gravity="center_vertical|left"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
|
@ -23,46 +24,52 @@
|
|||
android:id="@+id/IndeterminateProgressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:indeterminate="true"
|
||||
android:indeterminateOnly="true"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ProgressMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:ellipsize="marquee"
|
||||
android:gravity="left|center_vertical"
|
||||
android:singleLine="true"
|
||||
android:id="@+id/ProgressPercent"
|
||||
android:layout_width="48dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:gravity="right|center_vertical"
|
||||
android:text=""
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ProgressPercent"
|
||||
android:id="@+id/ProgressMessage"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right|center_vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_toLeftOf="@id/ProgressPercent"
|
||||
android:layout_toRightOf="@id/IndeterminateProgressBar"
|
||||
android:ellipsize="end"
|
||||
android:gravity="left|center_vertical"
|
||||
android:singleLine="true"
|
||||
android:text=""
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_marginRight="3dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/DeterminateProgressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<ImageButton
|
||||
<ImageView
|
||||
android:id="@+id/Cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -1401,10 +1401,18 @@ public class OsmandSettings {
|
|||
return OSMAND_THEME.get() == OSMAND_LIGHT_THEME;
|
||||
}
|
||||
|
||||
public boolean isLightContent(){
|
||||
public boolean isLightContentMenu(){
|
||||
return OSMAND_THEME.get() != OSMAND_DARK_THEME || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB;
|
||||
}
|
||||
|
||||
public boolean isLightContent(){
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
|
||||
return false;
|
||||
}
|
||||
return OSMAND_THEME.get() != OSMAND_DARK_THEME ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public final CommonPreference<Boolean> FLUORESCENT_OVERLAYS =
|
||||
new BooleanPreference("fluorescent_overlays", false).makeGlobal().cache();
|
||||
|
|
|
@ -6,14 +6,13 @@ import java.io.FilenameFilter;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.map.RegionCountry;
|
||||
import net.osmand.map.RegionRegistry;
|
||||
import net.osmand.plus.ClientContext;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -28,21 +27,17 @@ import net.osmand.plus.download.DownloadIndexAdapter;
|
|||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.download.IndexItemCategory;
|
||||
import net.osmand.plus.download.SrtmIndexItem;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.AsyncTask.Status;
|
||||
import android.os.Bundle;
|
||||
import android.os.StatFs;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
|
@ -52,6 +47,7 @@ import android.widget.CheckBox;
|
|||
import android.widget.EditText;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -74,20 +70,16 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
public static final String FILTER_KEY = "filter";
|
||||
|
||||
private static DownloadIndexesThread downloadListIndexThread;
|
||||
|
||||
private TreeMap<IndexItem, List<DownloadEntry>> entriesToDownload = new TreeMap<IndexItem, List<DownloadEntry>>();
|
||||
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
|
||||
|
||||
private int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
|
||||
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
|
||||
|
||||
|
||||
private TextWatcher textWatcher ;
|
||||
private EditText filterText;
|
||||
|
||||
private OsmandSettings settings;
|
||||
private ArrayAdapter<String> spinnerAdapter;
|
||||
|
||||
private List<SrtmIndexItem> cachedSRTMFiles;
|
||||
|
||||
|
||||
|
||||
private View progressView;
|
||||
|
@ -95,6 +87,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
private ProgressBar determinateProgressBar;
|
||||
private TextView progressMessage;
|
||||
private TextView progressPercent;
|
||||
private ImageView cancel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -109,6 +102,16 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
progressView = findViewById(R.id.ProgressView);
|
||||
progressMessage = (TextView) findViewById(R.id.ProgressMessage);
|
||||
progressPercent = (TextView) findViewById(R.id.ProgressPercent);
|
||||
cancel = (ImageView) findViewById(R.id.Cancel);
|
||||
int d = settings.isLightContent() ? R.drawable.a_1_navigation_cancel_small_light : R.drawable.a_1_navigation_cancel_small_dark;
|
||||
cancel.setImageDrawable(getResources().getDrawable(d));
|
||||
cancel.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
makeSureUserCancelDownload();
|
||||
}
|
||||
});
|
||||
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
|
||||
getSupportActionBar().setTitle(R.string.local_index_download);
|
||||
// recreation upon rotation is prevented in manifest file
|
||||
|
@ -116,7 +119,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
downloadFilesCheckFreeVersion(flattenDownloadEntries());
|
||||
downloadFilesCheckFreeVersion();
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -152,7 +155,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
List<IndexItem> list = new ArrayList<IndexItem>();
|
||||
downloadListIndexThread.setUiActivity(this);
|
||||
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
|
||||
list = getFilteredByType();
|
||||
downloadListIndexThread.runCategorization(type);
|
||||
} else {
|
||||
downloadListIndexThread.runReloadIndexFiles();
|
||||
}
|
||||
|
@ -185,7 +188,14 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
updateProgress(false, downloadListIndexThread.getCurrentRunningTask());
|
||||
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
|
||||
updateProgress(false);
|
||||
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
|
||||
View mainView = findViewById(R.id.MainLayout);
|
||||
if (mainView != null) {
|
||||
mainView.setKeepScreenOn(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -214,17 +224,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
}
|
||||
|
||||
|
||||
public void updateLoadedFiles() {
|
||||
if (type == DownloadActivityType.SRTM_FILE) {
|
||||
if (cachedSRTMFiles != null) {
|
||||
for (SrtmIndexItem i : cachedSRTMFiles) {
|
||||
((SrtmIndexItem) i).updateExistingTiles(getMyApplication().getResourceManager().getIndexFileNames());
|
||||
}
|
||||
}
|
||||
((DownloadIndexAdapter) getExpandableListAdapter()).notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
@ -261,26 +260,23 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
return type;
|
||||
}
|
||||
|
||||
public List<DownloadEntry> flattenDownloadEntries() {
|
||||
List<DownloadEntry> res = new ArrayList<DownloadEntry>();
|
||||
for(List<DownloadEntry> ens : entriesToDownload.values()) {
|
||||
if(ens != null) {
|
||||
res.addAll(ens);
|
||||
public Map<IndexItem, List<DownloadEntry>> getEntriesToDownload() {
|
||||
if(downloadListIndexThread == null) {
|
||||
return new LinkedHashMap<IndexItem, List<DownloadEntry>>();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return downloadListIndexThread.getEntriesToDownload();
|
||||
}
|
||||
|
||||
public TreeMap<IndexItem, List<DownloadEntry>> getEntriesToDownload() {
|
||||
return entriesToDownload;
|
||||
public String getFilterText() {
|
||||
return filterText.getText().toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void deselectAll() {
|
||||
public void deselectAll() {
|
||||
final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
|
||||
entriesToDownload.clear();
|
||||
downloadListIndexThread.getEntriesToDownload().clear();
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
|
||||
findViewById(R.id.DownloadButton).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
@ -305,34 +301,52 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
for (int j = 0; j < listAdapter.getGroupCount(); j++) {
|
||||
for (int i = 0; i < listAdapter.getChildrenCount(j); i++) {
|
||||
IndexItem es = listAdapter.getChild(j, i);
|
||||
if (!entriesToDownload.containsKey(es)) {
|
||||
if (!getEntriesToDownload().containsKey(es)) {
|
||||
selected++;
|
||||
entriesToDownload.put(es, es.createDownloadEntry(getClientContext(), type, new ArrayList<DownloadEntry>(1)));
|
||||
getEntriesToDownload().put(es, es.createDownloadEntry(getClientContext(), type, new ArrayList<DownloadEntry>(1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
AccessibleToast.makeText(this, MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
|
||||
listAdapter.notifyDataSetInvalidated();
|
||||
if(selected > 0){
|
||||
makeDownloadVisible();
|
||||
updateDownloadButton(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void makeDownloadVisible() {
|
||||
public void updateDownloadButton(boolean scroll) {
|
||||
int x = getListView().getScrollX();
|
||||
int y = getListView().getScrollY();
|
||||
if (getEntriesToDownload().isEmpty()) {
|
||||
findViewById(R.id.DownloadButton).setVisibility(View.GONE);
|
||||
} else {
|
||||
BasicProgressAsyncTask<?, ?, ?> task = downloadListIndexThread.getCurrentRunningTask();
|
||||
boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask;
|
||||
((Button) findViewById(R.id.DownloadButton)).setEnabled(!running);
|
||||
String text;
|
||||
int downloads = downloadListIndexThread. getDownloads();
|
||||
if (!running) {
|
||||
text = getString(R.string.download_files) + " " + downloads;
|
||||
} else {
|
||||
text = getString(R.string.downloading_file_new) + " " + downloads;
|
||||
}
|
||||
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||
if (Version.isFreeVersion(getMyApplication())) {
|
||||
int left = MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - entriesToDownload.size();
|
||||
int left = MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
|
||||
boolean excessLimit = left < 0;
|
||||
if(left < 0) left = 0;
|
||||
String t = getString(R.string.download_files);
|
||||
if (left < 0)
|
||||
left = 0;
|
||||
if (getType() != DownloadActivityType.HILLSHADE_FILE || getType() != DownloadActivityType.SRTM_FILE) {
|
||||
t += " (" +(excessLimit?"! ":"") + getString(R.string.files_limit, left).toLowerCase() + ")";
|
||||
}
|
||||
((Button) findViewById(R.id.DownloadButton)).setText(t);
|
||||
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
|
||||
}
|
||||
}
|
||||
((Button) findViewById(R.id.DownloadButton)).setText(text);
|
||||
}
|
||||
if (scroll) {
|
||||
getListView().scrollTo(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void selectDownloadType() {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
|
@ -383,81 +397,11 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
public void changeType(final DownloadActivityType tp) {
|
||||
if (downloadListIndexThread != null && type != tp) {
|
||||
type = tp;
|
||||
AsyncTask<Void, Void, List<IndexItem>> t = new AsyncTask<Void, Void, List<IndexItem>>(){
|
||||
|
||||
private List<IndexItemCategory> cats;
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
progressDialog = ProgressDialog.show(DownloadIndexActivity.this,
|
||||
getString(R.string.downloading), getString(R.string.downloading_list_indexes));
|
||||
}
|
||||
@Override
|
||||
protected List<IndexItem> doInBackground(Void... params) {
|
||||
final List<IndexItem> filtered = getFilteredByType();
|
||||
cats = IndexItemCategory.categorizeIndexItems(getClientContext(), filtered);
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<IndexItem> filtered) {
|
||||
entriesToDownload.clear();
|
||||
DownloadIndexAdapter a = ((DownloadIndexAdapter) getExpandableListAdapter());
|
||||
// Strange null pointer fix (reproduce?)
|
||||
if (a != null) {
|
||||
a.setIndexFiles(filtered, cats);
|
||||
a.notifyDataSetChanged();
|
||||
a.getFilter().filter(filterText.getText());
|
||||
}
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
|
||||
};
|
||||
t.execute();
|
||||
downloadListIndexThread.runCategorization(tp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<IndexItem> getFilteredByType() {
|
||||
final List<IndexItem> filtered = new ArrayList<IndexItem>();
|
||||
if (type == DownloadActivityType.SRTM_FILE) {
|
||||
Map<String, String> indexFileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
||||
if (cachedSRTMFiles == null) {
|
||||
cachedSRTMFiles = new ArrayList<SrtmIndexItem>();
|
||||
List<RegionCountry> countries = RegionRegistry.getRegionRegistry().getCountries();
|
||||
for (RegionCountry rc : countries) {
|
||||
if (rc.tiles.size() > 35 && rc.getSubRegions().size() > 0) {
|
||||
for (RegionCountry ch : rc.getSubRegions()) {
|
||||
cachedSRTMFiles.add(new SrtmIndexItem(ch, indexFileNames));
|
||||
}
|
||||
} else {
|
||||
cachedSRTMFiles.add(new SrtmIndexItem(rc, indexFileNames));
|
||||
}
|
||||
}
|
||||
filtered.addAll(cachedSRTMFiles);
|
||||
} else {
|
||||
for (SrtmIndexItem s : cachedSRTMFiles) {
|
||||
s.updateExistingTiles(indexFileNames);
|
||||
filtered.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<IndexItem> cachedIndexFiles = downloadListIndexThread.getCachedIndexFiles();
|
||||
if (cachedIndexFiles != null) {
|
||||
for (IndexItem file : cachedIndexFiles) {
|
||||
if (file.getType() == type) {
|
||||
filtered.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ExpandableListView getListView() {
|
||||
return super.getExpandableListView();
|
||||
}
|
||||
|
@ -466,15 +410,18 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
return super.getExpandableListAdapter();
|
||||
}
|
||||
|
||||
// TODO
|
||||
private void makeSureUserCancelDownload(final DialogInterface dlg) {
|
||||
private void makeSureUserCancelDownload() {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
bld.setTitle(getString(R.string.default_buttons_cancel));
|
||||
bld.setMessage(R.string.confirm_interrupt_download);
|
||||
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dlg.dismiss();
|
||||
dialog.dismiss();
|
||||
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
|
||||
if(t != null) {
|
||||
t.setInterrupted(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.default_buttons_no, null);
|
||||
|
@ -489,15 +436,8 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
|
||||
if(ch.isChecked()){
|
||||
ch.setChecked(!ch.isChecked());
|
||||
entriesToDownload.remove(e);
|
||||
if(entriesToDownload.isEmpty()){
|
||||
int x = getListView().getScrollX();
|
||||
int y = getListView().getScrollY();
|
||||
findViewById(R.id.DownloadButton).setVisibility(View.GONE);
|
||||
getListView().scrollTo(x, y);
|
||||
} else {
|
||||
makeDownloadVisible();
|
||||
}
|
||||
getEntriesToDownload().remove(e);
|
||||
updateDownloadButton(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -505,11 +445,8 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
if (download.size() > 0) {
|
||||
// if(!fileToUnzip.exists()){
|
||||
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
|
||||
entriesToDownload.put(e, download);
|
||||
int x = getListView().getScrollX();
|
||||
int y = getListView().getScrollY();
|
||||
makeDownloadVisible();
|
||||
getListView().scrollTo(x, y);
|
||||
getEntriesToDownload().put(e, download);
|
||||
updateDownloadButton(true);
|
||||
ch.setChecked(!ch.isChecked());
|
||||
}
|
||||
return true;
|
||||
|
@ -548,105 +485,80 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
return files;
|
||||
}
|
||||
|
||||
protected void downloadFilesCheckFreeVersion(List<DownloadEntry> list) {
|
||||
protected void downloadFilesCheckFreeVersion() {
|
||||
if (Version.isFreeVersion(getMyApplication()) ) {
|
||||
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||
boolean wiki = false;
|
||||
for (DownloadEntry es : list) {
|
||||
if (es.baseName != null && es.baseName.contains("_wiki")) {
|
||||
for (IndexItem es : downloadListIndexThread.getEntriesToDownload().keySet()) {
|
||||
if (es.getBasename() != null && es.getBasename().contains("_wiki")) {
|
||||
wiki = true;
|
||||
break;
|
||||
} else if (es.type != DownloadActivityType.SRTM_FILE) {
|
||||
} else if (es.getType() != DownloadActivityType.SRTM_FILE) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
|
||||
String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "", "(" + total + ") ");
|
||||
String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
|
||||
Builder msg = new AlertDialog.Builder(this);
|
||||
msg.setTitle(R.string.free_version_title);
|
||||
msg.setMessage(msgTx);
|
||||
msg.setPositiveButton(R.string.default_buttons_ok, null);
|
||||
msg.show();
|
||||
} else {
|
||||
downloadFilesPreCheckSRTM( list);
|
||||
downloadFilesCheckInternet();
|
||||
}
|
||||
} else {
|
||||
downloadFilesPreCheckSRTM( list);
|
||||
downloadFilesCheckInternet();
|
||||
}
|
||||
}
|
||||
|
||||
protected void downloadFilesPreCheckSRTM(final List<DownloadEntry> list) {
|
||||
if (type == DownloadActivityType.SRTM_FILE &&
|
||||
OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin &&
|
||||
!OsmandPlugin.getEnabledPlugin(SRTMPlugin.class).isPaid()) {
|
||||
Builder msg = new AlertDialog.Builder(this);
|
||||
msg.setTitle(R.string.srtm_paid_version_title);
|
||||
msg.setMessage(getString(R.string.srtm_paid_version_msg));
|
||||
msg.setPositiveButton(R.string.default_buttons_ok, new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
downloadFilesCheckInternet(list);
|
||||
}
|
||||
});
|
||||
msg.show();
|
||||
} else {
|
||||
downloadFilesCheckInternet(list);
|
||||
}
|
||||
}
|
||||
|
||||
protected void downloadFilesCheckInternet(final List<DownloadEntry> list) {
|
||||
protected void downloadFilesCheckInternet() {
|
||||
if(!getMyApplication().getExternalServiceAPI().isWifiConnected()) {
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.download_using_mobile_internet));
|
||||
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
downloadFilesPreCheckSpace(list);
|
||||
downloadFilesPreCheckSpace();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.default_buttons_no, null);
|
||||
builder.show();
|
||||
} else {
|
||||
downloadFilesPreCheckSpace(list);
|
||||
downloadFilesPreCheckSpace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void downloadFilesPreCheckSpace(List<DownloadEntry> list) {
|
||||
protected void downloadFilesPreCheckSpace() {
|
||||
double sz = 0;
|
||||
List<DownloadEntry> list = downloadListIndexThread.flattenDownloadEntries();
|
||||
for (DownloadEntry es : list) {
|
||||
sz += es.sizeMB;
|
||||
}
|
||||
// get availabile space
|
||||
File dir = getMyApplication().getAppPath("").getParentFile();
|
||||
double asz = -1;
|
||||
if(dir.canRead()){
|
||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||
asz = (((long) fs.getAvailableBlocks()) * fs.getBlockSize()) / (1 << 20);
|
||||
}
|
||||
if(asz != -1 && asz < sz ){
|
||||
AccessibleToast.makeText(this, getString(R.string.download_files_not_enough_space, sz, asz), Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
double asz = downloadListIndexThread.getAvailableSpace();
|
||||
if (asz != -1 && asz > 0 && sz / asz > 0.4) {
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
if (asz > 0 && sz/asz > 0.4) {
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), list.size(), sz,
|
||||
asz));
|
||||
} else {
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question), list.size(), sz));
|
||||
}
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), list.size(), sz, asz));
|
||||
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
downloadListIndexThread.runDownloadFiles(entriesToDownload);
|
||||
downloadListIndexThread.runDownloadFiles();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.default_buttons_no, null);
|
||||
builder.show();
|
||||
} else {
|
||||
downloadListIndexThread.runDownloadFiles();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
@ -664,7 +576,8 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
}
|
||||
|
||||
|
||||
public void updateProgress(boolean updateOnlyProgress, BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask) {
|
||||
public void updateProgress(boolean updateOnlyProgress) {
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = downloadListIndexThread.getCurrentRunningTask();
|
||||
if(updateOnlyProgress) {
|
||||
if(!basicProgressAsyncTask.isIndeterminate()) {
|
||||
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() +"%");
|
||||
|
@ -677,6 +590,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
|
||||
indeterminateProgressBar.setVisibility(!indeterminate ? View.GONE : View.VISIBLE);
|
||||
determinateProgressBar.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
|
||||
cancel.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
|
||||
progressPercent.setVisibility(indeterminate ? View.GONE : View.VISIBLE);
|
||||
|
||||
progressMessage.setText(basicProgressAsyncTask.getDescription());
|
||||
|
@ -685,6 +599,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
||||
}
|
||||
}
|
||||
updateDownloadButton(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -516,7 +516,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
final TargetPointsHelper targets = getTargets();
|
||||
|
||||
View view = mapActivity.getLayoutInflater().inflate(R.layout.calculate_route, null);
|
||||
boolean lc = mapActivity.getMyApplication().getSettings().isLightContent();
|
||||
boolean lc = mapActivity.getMyApplication().getSettings().isLightContentMenu();
|
||||
final CheckBox nonoptimal = (CheckBox) view.findViewById(R.id.OptimalCheckox);
|
||||
final ToggleButton[] buttons = new ToggleButton[ApplicationMode.values().length];
|
||||
buttons[ApplicationMode.CAR.ordinal()] = (ToggleButton) view.findViewById(R.id.CarButton);
|
||||
|
@ -982,7 +982,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
final OsmandMapTileView mapView = mapActivity.getMapView();
|
||||
final OsmandApplication app = mapActivity.getMyApplication();
|
||||
ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app);
|
||||
boolean light = app.getSettings().isLightContent();
|
||||
boolean light = app.getSettings().isLightContentMenu();
|
||||
|
||||
// 1. Where am I
|
||||
optionsMenuHelper.registerItem(R.string.where_am_i,
|
||||
|
|
|
@ -18,6 +18,7 @@ public class DownloadEntry {
|
|||
public int parts;
|
||||
public File existingBackupFile;
|
||||
public boolean isAsset;
|
||||
public String assetName;
|
||||
public DownloadActivityType type;
|
||||
|
||||
public List<String> srtmFilesToDownload;
|
||||
|
@ -30,6 +31,7 @@ public class DownloadEntry {
|
|||
public DownloadEntry(String assetName, String fileName, long dateModified) {
|
||||
this.dateModified = dateModified;
|
||||
targetFile = new File(fileName);
|
||||
this.assetName = assetName;
|
||||
isAsset = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,10 @@ public class DownloadFileHelper {
|
|||
public void showWarning(String warning);
|
||||
}
|
||||
|
||||
public static boolean isInterruptedException(IOException e) {
|
||||
return e != null && e.getMessage().equals("Interrupted");
|
||||
}
|
||||
|
||||
private InputStream getInputStreamToDownload(final URL url, final boolean forceWifi) throws IOException {
|
||||
InputStream cis = new InputStream() {
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
|
@ -110,27 +114,20 @@ public class DownloadFileHelper {
|
|||
|
||||
@Override
|
||||
public int read(byte[] buffer, int offset, int len) throws IOException {
|
||||
int r = 0;
|
||||
while(len > 0) {
|
||||
if (bufLen == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (bufRead >= bufLen) {
|
||||
refillBuffer();
|
||||
}
|
||||
if (bufLen == -1) {
|
||||
return -1;
|
||||
}
|
||||
int av = bufLen - bufRead;
|
||||
if(len > av){
|
||||
System.arraycopy(this.buffer, bufRead, buffer, offset, av);
|
||||
len -= av;
|
||||
offset += av;
|
||||
bufRead += av;
|
||||
r += av;
|
||||
refillBuffer();
|
||||
} else {
|
||||
System.arraycopy(this.buffer, bufRead, buffer, offset, len);
|
||||
bufRead += len;
|
||||
r += len;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
int min = Math.min(len, av);
|
||||
System.arraycopy(this.buffer, bufRead, buffer, offset, min);
|
||||
bufRead += min;
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -159,18 +156,22 @@ public class DownloadFileHelper {
|
|||
readAgain = false;
|
||||
bufRead = 0;
|
||||
if ((bufLen = is.read(buffer)) != -1) {
|
||||
if (interruptDownloading) {
|
||||
throw new IOException("Interrupted");
|
||||
}
|
||||
fileread += bufLen;
|
||||
if (interruptDownloading) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if(interruptDownloading)
|
||||
log.error("IOException", e); //$NON-NLS-1$
|
||||
triesDownload--;
|
||||
reconnect();
|
||||
readAgain = true;
|
||||
}
|
||||
}
|
||||
if (interruptDownloading) {
|
||||
throw new IOException("Interrupted");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -210,7 +211,7 @@ public class DownloadFileHelper {
|
|||
}
|
||||
}
|
||||
de.fileToDownload = de.targetFile;
|
||||
if(de.targetFile.exists() && !de.unzipFolder) {
|
||||
if(!de.unzipFolder) {
|
||||
de.fileToDownload = new File(de.targetFile.getParentFile(), de.targetFile.getName() +".download");
|
||||
}
|
||||
unzipFile(de, progress, downloadInputStreams);
|
||||
|
@ -235,9 +236,14 @@ public class DownloadFileHelper {
|
|||
}
|
||||
|
||||
private void unzipFile(DownloadEntry de, IProgress progress, List<InputStream> is) throws IOException {
|
||||
String taskName = ctx.getString(R.string.downloading_file_new) + " " + de.baseName;
|
||||
CountingMultiInputStream fin = new CountingMultiInputStream(is);
|
||||
int len = (int) fin.available();
|
||||
int mb = (int) (len / (1024f*1024f));
|
||||
if(mb == 0) {
|
||||
mb = 1;
|
||||
}
|
||||
String taskName = ctx.getString(R.string.downloading_file_new) + " " + de.baseName /*+ " " + mb + " MB"*/;
|
||||
|
||||
progress.startTask(taskName, len / 1024);
|
||||
if (!de.zipStream) {
|
||||
copyFile(de, progress, fin, len, fin, de.fileToDownload);
|
||||
|
|
|
@ -4,13 +4,23 @@ package net.osmand.plus.download;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.map.RegionCountry;
|
||||
import net.osmand.map.RegionRegistry;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
|
@ -18,28 +28,36 @@ import net.osmand.plus.activities.DownloadIndexActivity;
|
|||
import net.osmand.plus.base.BasicProgressAsyncTask;
|
||||
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.AsyncTask.Status;
|
||||
import android.os.Build;
|
||||
import android.os.StatFs;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class DownloadIndexesThread {
|
||||
private DownloadIndexActivity uiActivity = null;
|
||||
private IndexFileList indexFiles = null;
|
||||
private List<SrtmIndexItem> cachedSRTMFiles;
|
||||
private Map<IndexItem, List<DownloadEntry>> entriesToDownload = Collections.synchronizedMap(new TreeMap<IndexItem, List<DownloadEntry>>());
|
||||
private Set<DownloadEntry> currentDownloads = new HashSet<DownloadEntry>();
|
||||
private final Context ctx;
|
||||
private OsmandApplication app;
|
||||
private final static Log log = PlatformUtil.getLog(DownloadIndexesThread.class);
|
||||
private DownloadFileHelper downloadFileHelper;
|
||||
private BasicProgressAsyncTask<?, ?, ?> currentRunningTask;
|
||||
private List<BasicProgressAsyncTask<?, ?, ?> > currentRunningTask = Collections.synchronizedList(new ArrayList<BasicProgressAsyncTask<?, ?, ?>>());
|
||||
|
||||
public DownloadIndexesThread(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
|
@ -51,6 +69,16 @@ public class DownloadIndexesThread {
|
|||
this.uiActivity = uiActivity;
|
||||
}
|
||||
|
||||
public List<DownloadEntry> flattenDownloadEntries() {
|
||||
List<DownloadEntry> res = new ArrayList<DownloadEntry>();
|
||||
for(List<DownloadEntry> ens : getEntriesToDownload().values()) {
|
||||
if(ens != null) {
|
||||
res.addAll(ens);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<IndexItem> getCachedIndexFiles() {
|
||||
return indexFiles != null ? indexFiles.getIndexFiles() : null;
|
||||
}
|
||||
|
@ -62,25 +90,33 @@ public class DownloadIndexesThread {
|
|||
public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask<IndexItem, Object, String> implements DownloadFileShowWarning {
|
||||
|
||||
private OsmandPreference<Integer> downloads;
|
||||
private TreeMap<IndexItem, List<DownloadEntry>> entriesToDownload;
|
||||
|
||||
public DownloadIndexesAsyncTask(Context ctx, TreeMap<IndexItem, List<DownloadEntry>> entriesToDownload) {
|
||||
public DownloadIndexesAsyncTask(Context ctx) {
|
||||
super(ctx);
|
||||
this.entriesToDownload = entriesToDownload;
|
||||
downloads = app.getSettings().NUMBER_OF_FREE_DOWNLOADS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInterrupted(boolean interrupted) {
|
||||
super.setInterrupted(interrupted);
|
||||
if(interrupted) {
|
||||
downloadFileHelper.setInterruptDownloading(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Object... values) {
|
||||
for (Object o : values) {
|
||||
if (o instanceof DownloadEntry) {
|
||||
if (uiActivity != null) {
|
||||
((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).notifyDataSetInvalidated();
|
||||
if (entriesToDownload.isEmpty()) {
|
||||
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.GONE);
|
||||
} else {
|
||||
uiActivity.makeDownloadVisible();
|
||||
uiActivity.updateDownloadButton(false);
|
||||
}
|
||||
} else if (o instanceof IndexItem) {
|
||||
entriesToDownload.remove(o);
|
||||
if (uiActivity != null) {
|
||||
((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).notifyDataSetInvalidated();
|
||||
uiActivity.updateDownloadButton(false);
|
||||
}
|
||||
} else if (o instanceof String) {
|
||||
AccessibleToast.makeText(ctx, (String) o, Toast.LENGTH_LONG).show();
|
||||
|
@ -91,7 +127,7 @@ public class DownloadIndexesThread {
|
|||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
currentRunningTask = this;
|
||||
currentRunningTask.add( this);
|
||||
super.onPreExecute();
|
||||
if (uiActivity != null) {
|
||||
downloadFileHelper.setInterruptDownloading(false);
|
||||
|
@ -99,58 +135,89 @@ public class DownloadIndexesThread {
|
|||
if (mainView != null) {
|
||||
mainView.setKeepScreenOn(true);
|
||||
}
|
||||
startTask(ctx.getString(R.string.downloading), -1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
if (result != null) {
|
||||
if (result != null && result.length() > 0) {
|
||||
AccessibleToast.makeText(ctx, result, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
currentDownloads.clear();
|
||||
if (uiActivity != null) {
|
||||
View mainView = uiActivity.findViewById(R.id.MainLayout);
|
||||
if (mainView != null) {
|
||||
mainView.setKeepScreenOn(false);
|
||||
}
|
||||
uiActivity.updateLoadedFiles();
|
||||
updateLoadedFiles();
|
||||
DownloadIndexAdapter adapter = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter());
|
||||
if (adapter != null) {
|
||||
adapter.notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
currentRunningTask.remove(this);
|
||||
if(uiActivity != null) {
|
||||
uiActivity.updateProgress(false, null);
|
||||
uiActivity.updateProgress(false);
|
||||
}
|
||||
}
|
||||
|
||||
private int countAllDownloadEntry(IndexItem... filesToDownload){
|
||||
int t = 0;
|
||||
for(IndexItem i : filesToDownload){
|
||||
List<DownloadEntry> list = entriesToDownload.get(i);
|
||||
if(list != null){
|
||||
t += list.size();
|
||||
|
||||
private void updateLoadedFiles() {
|
||||
if (uiActivity != null) {
|
||||
((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).notifyDataSetInvalidated();
|
||||
((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).updateLoadedFiles();
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(IndexItem... filesToDownload) {
|
||||
try {
|
||||
List<File> filesToReindex = new ArrayList<File>();
|
||||
boolean forceWifi = downloadFileHelper.isWifiConnected();
|
||||
int counter = 1;
|
||||
int all = countAllDownloadEntry(filesToDownload);
|
||||
for (int i = 0; i < filesToDownload.length; i++) {
|
||||
IndexItem filename = filesToDownload[i];
|
||||
List<DownloadEntry> list = entriesToDownload.get(filename);
|
||||
currentDownloads = new HashSet<DownloadEntry>();
|
||||
String breakDownloadMessage = null;
|
||||
downloadCycle : while(!entriesToDownload.isEmpty() ) {
|
||||
|
||||
Iterator<Entry<IndexItem, List<DownloadEntry>>> it = entriesToDownload.entrySet().iterator();
|
||||
IndexItem file = null;
|
||||
List<DownloadEntry> list = null;
|
||||
while(it.hasNext()) {
|
||||
Entry<IndexItem, List<DownloadEntry>> n = it.next();
|
||||
if(!currentDownloads.containsAll(n.getValue())) {
|
||||
file = n.getKey();
|
||||
list = n.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(file == null) {
|
||||
break downloadCycle;
|
||||
}
|
||||
if (list != null) {
|
||||
boolean success = false;
|
||||
for (DownloadEntry entry : list) {
|
||||
String indexOfAllFiles = all <= 1 ? "" : (" [" + counter + "/" + all + "]");
|
||||
counter++;
|
||||
boolean result = downloadFile(entry, filesToReindex, indexOfAllFiles, forceWifi);
|
||||
if(currentDownloads.contains(entry)) {
|
||||
continue;
|
||||
}
|
||||
currentDownloads.add(entry);
|
||||
double asz = getAvailableSpace();
|
||||
// validate interrupted
|
||||
if(downloadFileHelper.isInterruptDownloading()) {
|
||||
break downloadCycle;
|
||||
}
|
||||
// validate enough space
|
||||
if (asz != -1 && entry.sizeMB > asz) {
|
||||
breakDownloadMessage = app.getString(R.string.download_files_not_enough_space, entry.sizeMB, asz);
|
||||
break downloadCycle;
|
||||
}
|
||||
if (exceedsFreelimit(entry)) {
|
||||
breakDownloadMessage = app.getString(R.string.free_version_message, DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
|
||||
+ "");
|
||||
break downloadCycle;
|
||||
}
|
||||
boolean result = downloadFile(entry, filesToReindex, forceWifi);
|
||||
success = result || success;
|
||||
if (result) {
|
||||
entriesToDownload.remove(filename);
|
||||
if (entry.type != DownloadActivityType.SRTM_FILE && entry.type != DownloadActivityType.HILLSHADE_FILE) {
|
||||
downloads.set(downloads.get() + 1);
|
||||
}
|
||||
|
@ -161,8 +228,35 @@ public class DownloadIndexesThread {
|
|||
publishProgress(entry);
|
||||
}
|
||||
}
|
||||
if(success) {
|
||||
entriesToDownload.remove(file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
String warn = reindexFiles(filesToReindex);
|
||||
if(breakDownloadMessage != null) {
|
||||
if(warn != null) {
|
||||
warn = breakDownloadMessage + "\n" + warn;
|
||||
} else {
|
||||
warn = breakDownloadMessage;
|
||||
}
|
||||
}
|
||||
return warn;
|
||||
} catch (InterruptedException e) {
|
||||
log.info("Download Interrupted");
|
||||
// do not dismiss dialog
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean exceedsFreelimit(DownloadEntry entry) {
|
||||
return Version.isFreeVersion(app) &&
|
||||
entry.type != DownloadActivityType.SRTM_FILE && entry.type != DownloadActivityType.HILLSHADE_FILE
|
||||
&& downloads.get() >= DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
|
||||
}
|
||||
|
||||
private String reindexFiles(List<File> filesToReindex) {
|
||||
boolean vectorMapsToReindex = false;
|
||||
for (File f : filesToReindex) {
|
||||
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||
|
@ -173,15 +267,18 @@ public class DownloadIndexesThread {
|
|||
// reindex vector maps all at one time
|
||||
ResourceManager manager = app.getResourceManager();
|
||||
manager.indexVoiceFiles(this);
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
if (vectorMapsToReindex) {
|
||||
List<String> warnings = manager.indexingMaps(this);
|
||||
warnings = manager.indexingMaps(this);
|
||||
}
|
||||
if (cachedSRTMFiles != null) {
|
||||
for (SrtmIndexItem i : cachedSRTMFiles) {
|
||||
((SrtmIndexItem) i).updateExistingTiles(app.getResourceManager().getIndexFileNames());
|
||||
}
|
||||
}
|
||||
if (!warnings.isEmpty()) {
|
||||
return warnings.get(0);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// do not dismiss dialog
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -202,14 +299,16 @@ public class DownloadIndexesThread {
|
|||
|
||||
}
|
||||
|
||||
public boolean downloadFile(DownloadEntry de, List<File> filesToReindex, String indexOfAllFiles, boolean forceWifi)
|
||||
public boolean downloadFile(DownloadEntry de, List<File> filesToReindex, boolean forceWifi)
|
||||
throws InterruptedException {
|
||||
boolean res = false;
|
||||
if (de.isAsset) {
|
||||
try {
|
||||
ResourceManager.copyAssets(app.getAssets(), de.targetFile.getPath(), de.targetFile);
|
||||
if (uiActivity != null) {
|
||||
ResourceManager.copyAssets(uiActivity.getAssets(), de.assetName, de.targetFile);
|
||||
de.targetFile.setLastModified(de.dateModified);
|
||||
res = true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Copy exception", e);
|
||||
}
|
||||
|
@ -217,7 +316,7 @@ public class DownloadIndexesThread {
|
|||
res = downloadFileHelper.downloadFile(de, this, filesToReindex, this, forceWifi);
|
||||
}
|
||||
if (res && de.attachedEntry != null) {
|
||||
return downloadFile(de.attachedEntry, filesToReindex, indexOfAllFiles, forceWifi);
|
||||
return downloadFile(de.attachedEntry, filesToReindex, forceWifi);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -225,7 +324,7 @@ public class DownloadIndexesThread {
|
|||
@Override
|
||||
protected void updateProgress(boolean updateOnlyProgress) {
|
||||
if(uiActivity != null) {
|
||||
uiActivity.updateProgress(updateOnlyProgress, this);
|
||||
uiActivity.updateProgress(updateOnlyProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -238,19 +337,8 @@ public class DownloadIndexesThread {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void runDownloadFiles(TreeMap<IndexItem, List<DownloadEntry>> entriesToDownload){
|
||||
if(checkRunning()) {
|
||||
return;
|
||||
}
|
||||
IndexItem[] indexes = entriesToDownload.keySet().toArray(new IndexItem[0]);
|
||||
DownloadIndexesAsyncTask task = new DownloadIndexesAsyncTask(ctx, entriesToDownload);
|
||||
task.execute(indexes);
|
||||
}
|
||||
|
||||
public void runReloadIndexFiles() {
|
||||
if(checkRunning()) {
|
||||
return;
|
||||
}
|
||||
checkRunning();
|
||||
final BasicProgressAsyncTask<Void, Void, IndexFileList> inst = new BasicProgressAsyncTask<Void, Void, IndexFileList>(ctx) {
|
||||
|
||||
@Override
|
||||
|
@ -260,12 +348,9 @@ public class DownloadIndexesThread {
|
|||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
currentRunningTask = this;
|
||||
currentRunningTask.add(this);
|
||||
super.onPreExecute();
|
||||
this.message = ctx.getString(R.string.downloading_list_indexes);
|
||||
if(uiActivity != null) {
|
||||
uiActivity.updateProgress(false, this);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPostExecute(IndexFileList result) {
|
||||
|
@ -274,22 +359,23 @@ public class DownloadIndexesThread {
|
|||
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
|
||||
IndexItem basemap = indexFiles.getBasemap();
|
||||
if (!basemapExists && basemap != null) {
|
||||
List<DownloadEntry> downloadEntry = basemap
|
||||
.createDownloadEntry(uiActivity.getClientContext(), uiActivity.getType(), new ArrayList<DownloadEntry>());
|
||||
List<DownloadEntry> downloadEntry = basemap.createDownloadEntry(uiActivity.getClientContext(),
|
||||
uiActivity.getType(), new ArrayList<DownloadEntry>());
|
||||
uiActivity.getEntriesToDownload().put(basemap, downloadEntry);
|
||||
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download, Toast.LENGTH_LONG).show();
|
||||
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||
}
|
||||
uiActivity.setListAdapter(new DownloadIndexAdapter(uiActivity, uiActivity.getFilteredByType()));
|
||||
if (indexFiles.isIncreasedMapVersion()) {
|
||||
showWarnDialog();
|
||||
}
|
||||
} else {
|
||||
AccessibleToast.makeText(ctx, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
currentRunningTask.remove(this);
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(false, null);
|
||||
uiActivity.updateProgress(false);
|
||||
}
|
||||
runCategorization(uiActivity.getType());
|
||||
|
||||
}
|
||||
|
||||
|
@ -319,21 +405,190 @@ public class DownloadIndexesThread {
|
|||
@Override
|
||||
protected void updateProgress(boolean updateOnlyProgress) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(updateOnlyProgress, this);
|
||||
uiActivity.updateProgress(updateOnlyProgress);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
inst.execute(new Void[0]);
|
||||
execute(inst, new Void[0]);
|
||||
|
||||
}
|
||||
|
||||
public void runDownloadFiles(){
|
||||
if(checkRunning()) {
|
||||
return;
|
||||
}
|
||||
DownloadIndexesAsyncTask task = new DownloadIndexesAsyncTask(ctx);
|
||||
execute(task, new IndexItem[0]);
|
||||
}
|
||||
|
||||
private <P>void execute(BasicProgressAsyncTask<P, ?, ?> task, P... indexItems) {
|
||||
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ) {
|
||||
// TODO check
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, indexItems);
|
||||
} else {
|
||||
task.execute(indexItems);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<IndexItem, List<DownloadEntry>> getEntriesToDownload() {
|
||||
return entriesToDownload;
|
||||
}
|
||||
|
||||
public void runCategorization(final DownloadActivityType type) {
|
||||
final BasicProgressAsyncTask<Void, Void, List<IndexItem>> inst = new BasicProgressAsyncTask<Void, Void, List<IndexItem>>(ctx) {
|
||||
private List<IndexItemCategory> cats;
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
currentRunningTask.add(this);
|
||||
this.message = ctx.getString(R.string.downloading_list_indexes);
|
||||
if(uiActivity != null) {
|
||||
uiActivity.updateProgress(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IndexItem> doInBackground(Void... params) {
|
||||
final List<IndexItem> filtered = getFilteredByType();
|
||||
cats = IndexItemCategory.categorizeIndexItems(app, filtered);
|
||||
return filtered;
|
||||
};
|
||||
|
||||
public List<IndexItem> getFilteredByType() {
|
||||
final List<IndexItem> filtered = new ArrayList<IndexItem>();
|
||||
if (type == DownloadActivityType.SRTM_FILE) {
|
||||
Map<String, String> indexFileNames = app.getResourceManager().getIndexFileNames();
|
||||
if (cachedSRTMFiles == null) {
|
||||
cachedSRTMFiles = new ArrayList<SrtmIndexItem>();
|
||||
synchronized (cachedSRTMFiles) {
|
||||
List<RegionCountry> countries = RegionRegistry.getRegionRegistry().getCountries();
|
||||
for (RegionCountry rc : countries) {
|
||||
if (rc.tiles.size() > 35 && rc.getSubRegions().size() > 0) {
|
||||
for (RegionCountry ch : rc.getSubRegions()) {
|
||||
cachedSRTMFiles.add(new SrtmIndexItem(ch, indexFileNames));
|
||||
}
|
||||
} else {
|
||||
cachedSRTMFiles.add(new SrtmIndexItem(rc, indexFileNames));
|
||||
}
|
||||
}
|
||||
filtered.addAll(cachedSRTMFiles);
|
||||
}
|
||||
} else {
|
||||
synchronized (cachedSRTMFiles) {
|
||||
for (SrtmIndexItem s : cachedSRTMFiles) {
|
||||
s.updateExistingTiles(indexFileNames);
|
||||
filtered.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List<IndexItem> cachedIndexFiles = getCachedIndexFiles();
|
||||
if (cachedIndexFiles != null) {
|
||||
for (IndexItem file : cachedIndexFiles) {
|
||||
if (file.getType() == type) {
|
||||
filtered.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<IndexItem> filtered) {
|
||||
if (uiActivity != null) {
|
||||
DownloadIndexAdapter a = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter());
|
||||
a.setIndexFiles(filtered, cats);
|
||||
a.notifyDataSetChanged();
|
||||
a.getFilter().filter(uiActivity.getFilterText());
|
||||
if (type == DownloadActivityType.SRTM_FILE && OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin
|
||||
&& !OsmandPlugin.getEnabledPlugin(SRTMPlugin.class).isPaid()) {
|
||||
Builder msg = new AlertDialog.Builder(uiActivity);
|
||||
msg.setTitle(R.string.srtm_paid_version_title);
|
||||
msg.setMessage(R.string.srtm_paid_version_msg);
|
||||
msg.setNegativeButton(R.string.button_upgrade_osmandplus, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:net.osmand.srtmPlugin.paid"));
|
||||
try {
|
||||
ctx.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
msg.setPositiveButton(R.string.default_buttons_ok, null);
|
||||
msg.show();
|
||||
}
|
||||
}
|
||||
currentRunningTask.remove(this);
|
||||
if(uiActivity != null) {
|
||||
uiActivity.updateProgress(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateProgress(boolean updateOnlyProgress) {
|
||||
if(uiActivity != null) {
|
||||
uiActivity.updateProgress(updateOnlyProgress);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
execute(inst, new Void[0]);
|
||||
}
|
||||
|
||||
|
||||
public boolean isDownloadRunning(){
|
||||
for(int i =0; i<currentRunningTask.size(); i++) {
|
||||
if (currentRunningTask.get(i) instanceof DownloadIndexesAsyncTask) {
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public BasicProgressAsyncTask<?, ?, ?> getCurrentRunningTask() {
|
||||
if(currentRunningTask != null && currentRunningTask.getStatus() == Status.FINISHED) {
|
||||
currentRunningTask = null;
|
||||
for(int i = 0; i< currentRunningTask.size(); ) {
|
||||
if(currentRunningTask.get(i).getStatus() == Status.FINISHED) {
|
||||
currentRunningTask.remove(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
return currentRunningTask;
|
||||
}
|
||||
if(currentRunningTask.size() > 0) {
|
||||
return currentRunningTask.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getAvailableSpace() {
|
||||
File dir = app.getAppPath("").getParentFile();
|
||||
double asz = -1;
|
||||
if (dir.canRead()) {
|
||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||
asz = (((long) fs.getAvailableBlocks()) * fs.getBlockSize()) / (1 << 20);
|
||||
}
|
||||
return asz;
|
||||
}
|
||||
|
||||
public int getDownloads() {
|
||||
int i = 0;
|
||||
Collection<List<DownloadEntry>> vs = getEntriesToDownload().values();
|
||||
for (List<DownloadEntry> v : vs) {
|
||||
for(DownloadEntry e : v) {
|
||||
if(!currentDownloads.contains(e)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!currentDownloads.isEmpty()) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ public class SrtmIndexItem extends IndexItem {
|
|||
entry.urlToDownload = url +"file=" + fullName;
|
||||
// url + "file=" + fileName;
|
||||
entry.unzipFolder = false;
|
||||
entry.zipStream = true;
|
||||
entry.dateModified = System.currentTimeMillis();
|
||||
entry.sizeMB = 10;
|
||||
entry.parts = 1;
|
||||
|
|
|
@ -419,7 +419,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
public void registerOptionsMenuItems(final MapActivity mapActivity, ContextMenuAdapter helper) {
|
||||
if (parkingLayer != null) {
|
||||
if (getParkingPosition() != null) {
|
||||
boolean l = app.getSettings().isLightContent();
|
||||
boolean l = app.getSettings().isLightContentMenu();
|
||||
helper.registerItem(R.string.osmand_parking_delete, l ? R.drawable.a_1_navigation_cancel_light : R.drawable.a_1_navigation_cancel_dark,
|
||||
new OnContextMenuClick() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue