Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-09-12 10:08:14 +02:00
commit 71246eb2c5
24 changed files with 1262 additions and 1026 deletions

View file

@ -132,7 +132,6 @@
<activity android:name="net.osmand.access.SettingsAccessibilityActivity" android:configChanges="keyboardHidden|orientation" /> <activity android:name="net.osmand.access.SettingsAccessibilityActivity" android:configChanges="keyboardHidden|orientation" />
<activity android:name="net.osmand.plus.activities.search.SearchActivity" android:label="@string/search_activity" /> <activity android:name="net.osmand.plus.activities.search.SearchActivity" android:label="@string/search_activity" />
<activity android:name="net.osmand.plus.activities.DownloadIndexActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/local_index_download" />
<activity android:name="net.osmand.plus.activities.ShowRouteInfoActivity" android:label="@string/show_route" /> <activity android:name="net.osmand.plus.activities.ShowRouteInfoActivity" android:label="@string/show_route" />
<activity android:name="net.osmand.plus.activities.FavouritesListActivity" android:label="@string/favourites_list_activity" /> <activity android:name="net.osmand.plus.activities.FavouritesListActivity" android:label="@string/favourites_list_activity" />
<activity android:name="net.osmand.plus.activities.FavouritesActivity" android:windowSoftInputMode="adjustPan" /> <activity android:name="net.osmand.plus.activities.FavouritesActivity" android:windowSoftInputMode="adjustPan" />
@ -220,7 +219,7 @@
</activity> </activity>
<activity android:name="net.osmand.plus.development.TestVoiceActivity" /> <activity android:name="net.osmand.plus.development.TestVoiceActivity" />
<activity android:name="net.osmand.plus.activities.LocalIndexesActivity" android:label="@string/local_index_descr_title" /> <activity android:name="net.osmand.plus.download.DownloadActivity" android:label="@string/local_index_descr_title" />
<activity android:name="net.osmand.plus.osmedit.LocalOpenstreetmapActivity" android:label="@string/local_openstreetmap_act_title" /> <activity android:name="net.osmand.plus.osmedit.LocalOpenstreetmapActivity" android:label="@string/local_openstreetmap_act_title" />
<!-- keep android:process on a separate line !! --> <!-- keep android:process on a separate line !! -->

View file

@ -5,77 +5,6 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" > android:orientation="vertical" >
<LinearLayout
android:id="@+id/ProgressView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:orientation="horizontal" >
<ProgressBar
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/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/ProgressMessage"
android:layout_width="fill_parent"
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" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
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="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageView
android:id="@+id/Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/a_1_navigation_cancel_small_dark" />
</LinearLayout>
</LinearLayout>
<EditText <EditText
android:id="@+id/search_box" android:id="@+id/search_box"
@ -99,15 +28,4 @@
android:layout_weight="1" android:layout_weight="1"
android:groupIndicator="@android:color/transparent" /> android:groupIndicator="@android:color/transparent" />
<Button
android:id="@+id/DownloadButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:gravity="center"
android:text="@string/download_files"
android:visibility="gone" />
</LinearLayout> </LinearLayout>

View file

@ -9,14 +9,88 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<TabWidget <LinearLayout
android:id="@+id/ProgressView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:orientation="horizontal" >
<ProgressBar
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/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/ProgressMessage"
android:layout_width="fill_parent"
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" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
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="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageView
android:id="@+id/Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/a_1_navigation_cancel_small_dark" />
</LinearLayout>
</LinearLayout>
<TabWidget
android:id="@android:id/tabs" android:id="@android:id/tabs"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="0"/> android:layout_weight="0"/>
<FrameLayout
<FrameLayout
android:id="@android:id/tabcontent" android:id="@android:id/tabcontent"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
@ -28,5 +102,19 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1"/> android:layout_weight="1"/>
<Button
android:id="@+id/DownloadButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:gravity="center"
android:text="@string/download_files"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
</TabHost> </TabHost>

View file

@ -10,14 +10,9 @@ import net.osmand.IProgress;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.activities.*;
import net.osmand.plus.activities.FavouritesActivity;
import net.osmand.plus.activities.LocalIndexesActivity;
import net.osmand.plus.activities.MainMenuActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginsActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteCalculationResult;
@ -79,15 +74,15 @@ public class OsmAndAppCustomization {
} }
public Class<? extends Activity> getDownloadIndexActivity() { public Class<? extends Activity> getDownloadIndexActivity() {
return DownloadIndexActivity.class; return DownloadActivity.class;
} }
public Class<? extends Activity> getPluginsActivity() { public Class<? extends Activity> getPluginsActivity() {
return PluginsActivity.class; return PluginsActivity.class;
} }
public Class<? extends Activity> getLocalIndexActivity() { public Class<? extends Activity> getDownloadActivity() {
return LocalIndexesActivity.class; return DownloadActivity.class;
} }
// Download screen // Download screen
@ -115,30 +110,6 @@ public class OsmAndAppCustomization {
return "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + Version.getVersionAsURLParam(app); //$NON-NLS-1$; return "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?gzip&" + Version.getVersionAsURLParam(app); //$NON-NLS-1$;
} }
public void preDownloadActivity(final DownloadIndexActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar ) {
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(actionBar.getThemedContext(), R.layout.sherlock_spinner_item,
toString(downloadTypes)
);
spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
actionBar.setListNavigationCallbacks(spinnerAdapter, new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
da.changeType(downloadTypes.get(itemPosition));
return true;
}
});
}
private List<String> toString(List<DownloadActivityType> t) {
ArrayList<String> items = new ArrayList<String>();
for(DownloadActivityType ts : t) {
items.add(ts.getString(app));
}
return items;
}
public boolean showDownloadExtraActions() { public boolean showDownloadExtraActions() {
return true; return true;
} }

View file

@ -18,11 +18,8 @@ import net.osmand.access.AccessibilityPlugin;
import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.access.AccessibilityMode; import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.activities.DayNightHelper; import net.osmand.plus.activities.*;
import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SQLiteAPIImpl; import net.osmand.plus.api.SQLiteAPIImpl;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;
@ -114,7 +111,7 @@ public class OsmandApplication extends Application {
BRouterServiceConnection bRouterServiceConnection; BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity; MapActivity mapActivity;
DownloadIndexActivity downloadActivity; DownloadIndexFragment downloadActivity;
@Override @Override
public void onCreate() { public void onCreate() {
@ -882,11 +879,11 @@ public class OsmandApplication extends Application {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
} }
public void setDownloadActivity(DownloadIndexActivity downloadActivity) { public void setDownloadActivity(DownloadIndexFragment downloadActivity) {
this.downloadActivity = downloadActivity; this.downloadActivity = downloadActivity;
} }
public DownloadIndexActivity getDownloadActivity() { public DownloadIndexFragment getDownloadActivity() {
return downloadActivity; return downloadActivity;
} }
} }

View file

@ -10,7 +10,7 @@ import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin; import net.osmand.access.AccessibilityPlugin;
import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask; import net.osmand.plus.download.LocalIndexesFragment.LoadLocalIndexTask;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
@ -19,7 +19,6 @@ import net.osmand.plus.distancecalculator.DistanceCalculatorPlugin;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmo.OsMoPlugin; import net.osmand.plus.osmo.OsMoPlugin;
import net.osmand.plus.osmodroid.OsMoDroidPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.routepointsnavigation.RoutePointsPlugin; import net.osmand.plus.routepointsnavigation.RoutePointsPlugin;

View file

@ -1,681 +0,0 @@
package net.osmand.plus.activities;
import java.io.File;
import java.io.FilenameFilter;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
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.SettingsGeneralActivity.MoveFilesToDifferentDirectory;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadEntry;
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.srtmplugin.SRTMPlugin;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
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.Status;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
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;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SubMenu;
public class DownloadIndexActivity extends OsmandExpandableListActivity {
/** menus **/
private static final int MORE_ID = 10;
private static final int RELOAD_ID = 0;
private static final int SELECT_ALL_ID = 1;
private static final int DESELECT_ALL_ID = 2;
private static final int FILTER_EXISTING_REGIONS = 3;
public static final String FILTER_KEY = "filter";
public static final String FILTER_CAT = "filter_cat";
public static DownloadIndexesThread downloadListIndexThread;
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
private TextWatcher textWatcher ;
private EditText filterText;
private OsmandSettings settings;
private View progressView;
private ProgressBar indeterminateProgressBar;
private ProgressBar determinateProgressBar;
private TextView progressMessage;
private TextView progressPercent;
private ImageView cancel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final List<DownloadActivityType> downloadTypes = getDownloadTypes();
type = downloadTypes.get(0);
settings = ((OsmandApplication) getApplication()).getSettings();
if(downloadListIndexThread == null) {
downloadListIndexThread = new DownloadIndexesThread(this);
}
setContentView(R.layout.download_index);
indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar);
determinateProgressBar = (ProgressBar) findViewById(R.id.DeterminateProgressBar);
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().setTitle(R.string.local_index_download);
// recreation upon rotation is pgetaprevented in manifest file
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
downloadFilesCheckFreeVersion();
}
});
filterText = (EditText) findViewById(R.id.search_box);
textWatcher = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
DownloadIndexAdapter adapter = ((DownloadIndexAdapter)getExpandableListAdapter());
if(adapter != null){
adapter.getFilter().filter(s);
}
}
};
filterText.addTextChangedListener(textWatcher);
final Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
final String filter = intent.getExtras().getString(FILTER_KEY);
if (filter != null) {
filterText.setText(filter);
}
final String filterCat = intent.getExtras().getString(FILTER_CAT);
if (filterCat != null) {
DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase());
if (type != null) {
this.type = type;
downloadTypes.remove(type);
downloadTypes.add(0, type);
}
}
}
List<IndexItem> list = new ArrayList<IndexItem>();
downloadListIndexThread.setUiActivity(this);
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
downloadListIndexThread.runCategorization(type);
} else {
downloadListIndexThread.runReloadIndexFiles();
}
DownloadIndexAdapter adapter = new DownloadIndexAdapter(this, list);
setListAdapter(adapter);
if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
boolean showedDialog = false;
if(Build.VERSION.SDK_INT < OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
SuggestExternalDirectoryDialog.showDialog(this, null, null);
}
if(!showedDialog) {
showDialogOfFreeDownloadsIfNeeded();
}
} else {
showDialogOfFreeDownloadsIfNeeded();
}
getMyApplication().getAppCustomization().preDownloadActivity(this, downloadTypes, getSupportActionBar());
if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath();
String primaryStorage = settings.getDefaultExternalStorageLocation();
if (!currentStorage.startsWith(primaryStorage)) {
// secondary storage
boolean currentDirectoryNotWritable = true;
for (String writeableDirectory : settings.getWritableSecondaryStorageDirectorys()) {
if (currentStorage.startsWith(writeableDirectory)) {
currentDirectoryNotWritable = false;
break;
}
}
if (currentDirectoryNotWritable) {
currentDirectoryNotWritable = !OsmandSettings.isWritable(settings.getExternalStorageDirectory());
}
if (currentDirectoryNotWritable) {
final String newLoc = settings.getMatchingExternalFilesDir(currentStorage);
if (newLoc != null && newLoc.length() != 0) {
AccessibleAlertBuilder ab = new AccessibleAlertBuilder(this);
ab.setMessage(getString(R.string.android_19_location_disabled,
settings.getExternalStorageDirectory()));
ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
copyFilesForAndroid19(newLoc);
}
});
ab.setNegativeButton(R.string.default_buttons_cancel, null);
ab.show();
}
}
}
}
}
private void copyFilesForAndroid19(final String newLoc) {
MoveFilesToDifferentDirectory task =
new MoveFilesToDifferentDirectory(DownloadIndexActivity.this,
new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR),
new File(newLoc, IndexConstants.APP_DIR)) {
protected Boolean doInBackground(Void[] params) {
Boolean result = super.doInBackground(params);
if(result) {
settings.setExternalStorageDirectory(newLoc);
getMyApplication().getResourceManager().resetStoreDirectory();
getMyApplication().getResourceManager().reloadIndexes(progress) ;
}
return result;
};
};
task.execute();
}
@Override
protected void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
updateProgress(false);
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
View mainView = findViewById(R.id.MainLayout);
if (mainView != null) {
mainView.setKeepScreenOn(true);
}
}
}
@Override
protected void onPause() {
super.onPause();
getMyApplication().setDownloadActivity(null);
}
public void showDialogToDownloadMaps(Collection<String> maps) {
int count = 0;
int sz = 0;
String s = "";
for (IndexItem i : downloadListIndexThread.getCachedIndexFiles()) {
for (String map : maps) {
if (i.getFileName().equals(map + ".obf.zip") && i.getType() == DownloadActivityType.NORMAL_FILE) {
final List<DownloadEntry> de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList<DownloadEntry>(1));
for(DownloadEntry d : de ) {
count++;
sz += d.sizeMB;
}
if(s.length() > 0) {
s +=", ";
}
s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
getEntriesToDownload().put(i, de);
}
}
}
if(count > 0){
Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.download_additional_maps, s, sz));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
downloadFilesCheckInternet();
}
});
builder.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getEntriesToDownload().clear();
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
getEntriesToDownload().clear();
}
});
builder.show();
}
}
private void showDialogOfFreeDownloadsIfNeeded() {
if (Version.isFreeVersion(getMyApplication())) {
Builder msg = new AlertDialog.Builder(this);
msg.setTitle(R.string.free_version_title);
String m = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "", "") + "\n";
m += getString(R.string.available_downloads_left, MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get());
msg.setMessage(m);
if (Version.isMarketEnabled(getMyApplication())) {
msg.setNeutralButton(R.string.install_paid, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(getMyApplication()) + "net.osmand.plus"));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
}
msg.setPositiveButton(R.string.default_buttons_ok, null);
msg.show();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == RELOAD_ID) {
// re-create the thread
downloadListIndexThread.runReloadIndexFiles();
return true;
} else if (item.getItemId() == SELECT_ALL_ID) {
selectAll();
return true;
} else if (item.getItemId() == FILTER_EXISTING_REGIONS) {
filterExisting();
return true;
} else if (item.getItemId() == DESELECT_ALL_ID) {
deselectAll();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (getMyApplication().getAppCustomization().showDownloadExtraActions()) {
SubMenu s = menu.addSubMenu(0, MORE_ID, 0, R.string.default_buttons_other_actions);
s.add(0, RELOAD_ID, 0, R.string.update_downlod_list);
s.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes);
s.add(0, SELECT_ALL_ID, 0, R.string.select_all);
s.add(0, DESELECT_ALL_ID, 0, R.string.deselect_all);
s.setIcon(isLightActionBar() ? R.drawable.abs__ic_menu_moreoverflow_holo_light
: R.drawable.abs__ic_menu_moreoverflow_holo_dark);
s.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
return super.onCreateOptionsMenu(menu);
}
public DownloadActivityType getType() {
return type;
}
public Map<IndexItem, List<DownloadEntry>> getEntriesToDownload() {
if(downloadListIndexThread == null) {
return new LinkedHashMap<IndexItem, List<DownloadEntry>>();
}
return downloadListIndexThread.getEntriesToDownload();
}
public String getFilterText() {
return filterText.getText().toString();
}
public void deselectAll() {
final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
downloadListIndexThread.getEntriesToDownload().clear();
listAdapter.notifyDataSetInvalidated();
findViewById(R.id.DownloadButton).setVisibility(View.GONE);
}
private void filterExisting() {
final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
final Map<String, String> listAlreadyDownloaded = downloadListIndexThread.getDownloadedIndexFileNames();
final List<IndexItem> filtered = new ArrayList<IndexItem>();
for (IndexItem fileItem : listAdapter.getIndexFiles()) {
if(fileItem.isAlreadyDownloaded(listAlreadyDownloaded)){
filtered.add(fileItem);
}
}
listAdapter.setIndexFiles(filtered, IndexItemCategory.categorizeIndexItems(getMyApplication(), filtered));
listAdapter.notifyDataSetChanged();
}
private void selectAll() {
final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter();
int selected = 0;
for (int j = 0; j < listAdapter.getGroupCount(); j++) {
for (int i = 0; i < listAdapter.getChildrenCount(j); i++) {
IndexItem es = listAdapter.getChild(j, i);
if (!getEntriesToDownload().containsKey(es)) {
selected++;
getEntriesToDownload().put(es, es.createDownloadEntry(getMyApplication(), 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){
updateDownloadButton(true);
}
}
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 + ")"; //$NON-NLS-1$
} else {
text = getString(R.string.downloading_file_new) + " (" + downloads + ")"; //$NON-NLS-1$
}
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
if (Version.isFreeVersion(getMyApplication())) {
int countedDownloads = downloadListIndexThread.getDownloads();
int left = MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
boolean excessLimit = left < 0;
if (left < 0)
left = 0;
if (DownloadActivityType.isCountedInDownloads(getType())) {
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
}
}
((Button) findViewById(R.id.DownloadButton)).setText(text);
}
if (scroll) {
getListView().scrollTo(x, y);
}
}
private List<DownloadActivityType> getDownloadTypes() {
List<DownloadActivityType> items = new ArrayList<DownloadActivityType>();
items.add(DownloadActivityType.NORMAL_FILE);
items.add(DownloadActivityType.VOICE_FILE);
items.add(DownloadActivityType.ROADS_FILE);
if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null){
items.add(DownloadActivityType.HILLSHADE_FILE);
items.add(DownloadActivityType.SRTM_COUNTRY_FILE);
}
getMyApplication().getAppCustomization().getDownloadTypes(items);
return items;
}
public void changeType(final DownloadActivityType tp) {
invalidateOptionsMenu();
if (downloadListIndexThread != null && type != tp) {
type = tp;
downloadListIndexThread.runCategorization(tp);
}
}
public ExpandableListView getListView() {
return super.getExpandableListView();
}
public ExpandableListAdapter getListAdapter() {
return super.getExpandableListAdapter();
}
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) {
dialog.dismiss();
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
if(t != null) {
t.setInterrupted(true);
}
}
});
bld.setNegativeButton(R.string.default_buttons_no, null);
bld.show();
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
final IndexItem e = (IndexItem) ((DownloadIndexAdapter)getListAdapter()).getChild(groupPosition, childPosition);
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
if(ch.isChecked()){
ch.setChecked(!ch.isChecked());
getEntriesToDownload().remove(e);
updateDownloadButton(true);
return true;
}
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), type, new ArrayList<DownloadEntry>());
if (download.size() > 0) {
// if(!fileToUnzip.exists()){
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
getEntriesToDownload().put(e, download);
updateDownloadButton(true);
ch.setChecked(!ch.isChecked());
}
return true;
}
public static Map<String, String> listWithAlternatives(final java.text.DateFormat dateFormat, File file, final String ext,
final Map<String, String> files) {
if (file.isDirectory()) {
file.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
if (filename.endsWith(ext)) {
String date = dateFormat.format(findFileInDir(new File(dir, filename)).lastModified());
files.put(filename, date);
return true;
} else {
return false;
}
}
});
}
return files;
}
public static File findFileInDir(File file) {
if(file.isDirectory()) {
File[] lf = file.listFiles();
if(lf != null) {
for(File f : lf) {
if(f.isFile()) {
return f;
}
}
}
}
return file;
}
protected void downloadFilesCheckFreeVersion() {
if (Version.isFreeVersion(getMyApplication()) ) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
boolean wiki = false;
for (IndexItem es : downloadListIndexThread.getEntriesToDownload().keySet()) {
if (es.getBasename() != null && es.getBasename().contains("_wiki")) {
wiki = true;
break;
} else if (DownloadActivityType.isCountedInDownloads(es.getType())) {
total++;
}
}
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
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 {
downloadFilesCheckInternet();
}
} else {
downloadFilesCheckInternet();
}
}
protected void downloadFilesCheckInternet() {
if(!getMyApplication().getSettings().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();
}
});
builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show();
} else {
downloadFilesPreCheckSpace();
}
}
protected void downloadFilesPreCheckSpace() {
double sz = 0;
List<DownloadEntry> list = downloadListIndexThread.flattenDownloadEntries();
for (DownloadEntry es : list) {
sz += es.sizeMB;
}
// get availabile space
double asz = downloadListIndexThread.getAvailableSpace();
if (asz != -1 && asz > 0 && sz / asz > 0.4) {
Builder builder = new AlertDialog.Builder(this);
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();
}
});
builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show();
} else {
downloadListIndexThread.runDownloadFiles();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (textWatcher != null) {
EditText filterText = (EditText) findViewById(R.id.search_box);
filterText.removeTextChangedListener(textWatcher);
}
downloadListIndexThread.setUiActivity(null);
}
public void updateProgress(boolean updateOnlyProgress) {
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = downloadListIndexThread.getCurrentRunningTask();
if(updateOnlyProgress) {
if(!basicProgressAsyncTask.isIndeterminate()) {
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() +"%");
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
}
} else {
boolean visible = basicProgressAsyncTask != null && basicProgressAsyncTask.getStatus() != Status.FINISHED;
progressView.setVisibility(visible ? View.VISIBLE : View.GONE);
if (visible) {
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());
if (!indeterminate) {
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
}
}
updateDownloadButton(false);
}
}
}

View file

@ -130,7 +130,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
if(favouritesAdapter.getGroupCount() > 0 && if(favouritesAdapter.getGroupCount() > 0 &&
"".equals(favouritesAdapter.getGroup(0).name)) { "".equals(favouritesAdapter.getGroup(0).name)) {
getListView().expandGroup(0); getExpandableListView().expandGroup(0);
} }
} }

View file

@ -31,7 +31,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask; import net.osmand.plus.download.LocalIndexesFragment.LoadLocalIndexTask;
import net.osmand.plus.voice.MediaCommandPlayerImpl; import net.osmand.plus.voice.MediaCommandPlayerImpl;
import net.osmand.plus.voice.TTSCommandPlayerImpl; import net.osmand.plus.voice.TTSCommandPlayerImpl;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;

View file

@ -11,8 +11,8 @@ import net.osmand.plus.OsmandApplication;
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.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.sherpafy.SherpafyCustomization;
import net.osmand.plus.sherpafy.TourViewActivity; import net.osmand.plus.sherpafy.TourViewActivity;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
@ -376,7 +376,7 @@ public class MainMenuActivity extends Activity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(MainMenuActivity.this, DownloadIndexActivity.class)); startActivity(new Intent(MainMenuActivity.this, DownloadIndexFragment.class));
} }
}); });

View file

@ -61,14 +61,10 @@ public abstract class OsmandExpandableListFragment extends SherlockFragment impl
} }
} }
} }
public ExpandableListView getListView() { public ExpandableListView getExpandableListView() { return listView; }
return listView;
} public void setListView(ExpandableListView listView) { this.listView = listView;}
public ExpandableListView getExpandableListView() {
return listView;
}
public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType) { public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType) {
int r = isLightActionBar() ? iconLight : iconDark; int r = isLightActionBar() ? iconLight : iconDark;

View file

@ -104,10 +104,10 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
public void setContent() { public void setContent() {
getListView().setFastScrollEnabled(true); getExpandableListView().setFastScrollEnabled(true);
lightContent = app.getSettings().isLightContent(); lightContent = app.getSettings().isLightContent();
if (adapter == null) { if (adapter == null) {
adapter = new SelectedGPXAdapter(getListView()); adapter = new SelectedGPXAdapter(getExpandableListView());
setAdapter(adapter); setAdapter(adapter);
} }
List<GpxDisplayGroup> groups = selectedGpxHelper.getDisplayGroups(); List<GpxDisplayGroup> groups = selectedGpxHelper.getDisplayGroups();
@ -131,7 +131,7 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
adapter.setDisplayGroups(groups); adapter.setDisplayGroups(groups);
if(isArgumentTrue(ARG_TO_EXPAND_TRACK_INFO)){ if(isArgumentTrue(ARG_TO_EXPAND_TRACK_INFO)){
for(int i = 0; i < groups.size(); i++) { for(int i = 0; i < groups.size(); i++) {
getListView().expandGroup(i); getExpandableListView().expandGroup(i);
} }
} }
} }
@ -248,7 +248,7 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
// MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_light, // MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_light,
// R.drawable.ic_action_search_dark, MenuItem.SHOW_AS_ACTION_ALWAYS // R.drawable.ic_action_search_dark, MenuItem.SHOW_AS_ACTION_ALWAYS
// | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); // | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
// searchView = new com.actionbarsherlock.widget.SearchView(getMyActivity()); // searchView = new com.actionbarsherlock.widget.SearchView(getDownloadActivity());
// mi.setActionView(searchView); // mi.setActionView(searchView);
// searchView.setOnQueryTextListener(new OnQueryTextListener() { // searchView.setOnQueryTextListener(new OnQueryTextListener() {
// //

View file

@ -101,7 +101,7 @@ public class SettingsActivity extends SettingsBaseActivity {
if (empty) { if (empty) {
startActivity(new Intent(this, getMyApplication().getAppCustomization().getDownloadIndexActivity())); startActivity(new Intent(this, getMyApplication().getAppCustomization().getDownloadIndexActivity()));
} else { } else {
startActivity(new Intent(this, getMyApplication().getAppCustomization().getLocalIndexActivity())); startActivity(new Intent(this, getMyApplication().getAppCustomization().getDownloadActivity()));
} }
return true; return true;
} else if (preference == bidforfix) { } else if (preference == bidforfix) {

View file

@ -22,7 +22,9 @@ import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.base.SuggestExternalDirectoryDialog; import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayer;
@ -372,8 +374,8 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
if (id.equals(settings.VOICE_PROVIDER.getId())) { if (id.equals(settings.VOICE_PROVIDER.getId())) {
if (MORE_VALUE.equals(newValue)) { if (MORE_VALUE.equals(newValue)) {
// listPref.set(oldValue); // revert the change.. // listPref.set(oldValue); // revert the change..
final Intent intent = new Intent(this, DownloadIndexActivity.class); final Intent intent = new Intent(this, DownloadIndexFragment.class);
intent.putExtra(DownloadIndexActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag()); intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag());
startActivity(intent); startActivity(intent);
} else { } else {
super.onPreferenceChange(preference, newValue); super.onPreferenceChange(preference, newValue);

View file

@ -34,11 +34,11 @@ import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.LocalIndexesActivity; import net.osmand.plus.download.LocalIndexesFragment.LoadLocalIndexTask;
import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
@ -1094,8 +1094,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override @Override
public void contextMenuLocalIndexes(Activity activity, SherlockFragment fragment, Object obj, public void contextMenuLocalIndexes(Activity activity, SherlockFragment fragment, Object obj,
ContextMenuAdapter adapter) { ContextMenuAdapter adapter) {
if (activity instanceof LocalIndexesActivity) { if (activity instanceof DownloadActivity) {
final LocalIndexesActivity la = (LocalIndexesActivity) activity; final DownloadActivity la = (DownloadActivity) activity;
LocalIndexInfo info = (LocalIndexInfo) obj; LocalIndexInfo info = (LocalIndexInfo) obj;
if (info.getType() == LocalIndexType.AV_DATA) { if (info.getType() == LocalIndexType.AV_DATA) {
final RecordingLocalIndexInfo ri = (RecordingLocalIndexInfo) info; final RecordingLocalIndexInfo ri = (RecordingLocalIndexInfo) info;

View file

@ -0,0 +1,377 @@
package net.osmand.plus.download;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.*;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.osmand.plus.*;
import net.osmand.plus.activities.FavouritesActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Denis on 08.09.2014.
*/
public class DownloadActivity extends SherlockFragmentActivity {
private TabHost tabHost;
private FavouritesActivity.TabsAdapter mTabsAdapter;
public static DownloadIndexesThread downloadListIndexThread;
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
private OsmandSettings settings;
private View progressView;
private ProgressBar indeterminateProgressBar;
private ProgressBar determinateProgressBar;
private TextView progressMessage;
private TextView progressPercent;
private ImageView cancel;
public static final String FILTER_KEY = "filter";
public static final String FILTER_CAT = "filter_cat";
@Override
protected void onCreate(Bundle savedInstanceState) {
getMyApplication().applyTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_content);
OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
mTabsAdapter = new FavouritesActivity.TabsAdapter(this, tabHost, viewPager, settings);
mTabsAdapter.addTab(tabHost.newTabSpec("LOCAL_INDEX").setIndicator("Local"),
LocalIndexesFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("DOWNLOADS").setIndicator("Downloads"),
DownloadIndexFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("UPDATES").setIndicator("Updates"),
UpdatesIndexFragment.class, null);
tabHost.setCurrentTab(0);
if(downloadListIndexThread == null) {
downloadListIndexThread = new DownloadIndexesThread(this);
}
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
downloadListIndexThread.runCategorization(type);
} else {
downloadListIndexThread.runReloadIndexFiles();
}
settings = ((OsmandApplication)getApplication()).getSettings();
indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar);
determinateProgressBar = (ProgressBar) findViewById(R.id.DeterminateProgressBar);
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();
}
});
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
downloadFilesCheckFreeVersion();
}
});
final List<DownloadActivityType> downloadTypes = getDownloadTypes();
final Intent intent = getIntent();
setType(downloadTypes.get(0));
if (intent != null && intent.getExtras() != null) {
final String filter = intent.getExtras().getString(FILTER_KEY);
// if (filter != null) {
// filterText.setText(filter);
// }
final String filterCat = intent.getExtras().getString(FILTER_CAT);
if (filterCat != null) {
DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase());
if (type != null) {
setType(type);
downloadTypes.remove(type);
downloadTypes.add(0, type);
}
}
}
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
protected void onResume() {
super.onResume();
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
}
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
finish();
return true;
}
return false;
}
public DownloadActivityType getType() { return type;}
public void setType(DownloadActivityType type) { this.type = type;}
public void changeType(final DownloadActivityType tp) {
invalidateOptionsMenu();
if (downloadListIndexThread != null && type != tp) {
type = tp;
downloadListIndexThread.runCategorization(tp);
}
}
public void downloadFilesPreCheckSpace() {
double sz = 0;
List<DownloadEntry> list = downloadListIndexThread.flattenDownloadEntries();
for (DownloadEntry es : list) {
sz += es.sizeMB;
}
// get availabile space
double asz = downloadListIndexThread.getAvailableSpace();
if (asz != -1 && asz > 0 && sz / asz > 0.4) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
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();
}
});
builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show();
} else {
downloadListIndexThread.runDownloadFiles();
}
}
public Map<IndexItem, List<DownloadEntry>> getEntriesToDownload() {
if(downloadListIndexThread == null) {
return new LinkedHashMap<IndexItem, List<DownloadEntry>>();
}
return downloadListIndexThread.getEntriesToDownload();
}
@Override
public void onPause() {
super.onPause();
(getMyApplication()).setDownloadActivity(null);
}
protected void downloadFilesCheckFreeVersion() {
if (Version.isFreeVersion(getMyApplication()) ) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
boolean wiki = false;
for (IndexItem es : DownloadActivity.downloadListIndexThread.getEntriesToDownload().keySet()) {
if (es.getBasename() != null && es.getBasename().contains("_wiki")) {
wiki = true;
break;
} else if (DownloadActivityType.isCountedInDownloads(es.getType())) {
total++;
}
}
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
String msgTx = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
AlertDialog.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 {
downloadFilesCheckInternet();
}
} else {
downloadFilesCheckInternet();
}
}
protected void downloadFilesCheckInternet() {
if(!getMyApplication().getSettings().isWifiConnected()) {
AlertDialog.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();
}
});
builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show();
} else {
downloadFilesPreCheckSpace();
}
}
public OsmandApplication getMyApplication(){ return (OsmandApplication)getApplication();}
public void showDialogOfFreeDownloadsIfNeeded() {
if (Version.isFreeVersion(getMyApplication())) {
AlertDialog.Builder msg = new AlertDialog.Builder(this);
msg.setTitle(R.string.free_version_title);
String m = getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "", "") + "\n";
m += getString(R.string.available_downloads_left, MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get());
msg.setMessage(m);
if (Version.isMarketEnabled(getMyApplication())) {
msg.setNeutralButton(R.string.install_paid, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(getMyApplication()) + "net.osmand.plus"));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
}
msg.setPositiveButton(R.string.default_buttons_ok, null);
msg.show();
}
}
public void updateProgress(boolean updateOnlyProgress) {
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
//needed when rotation is performed and progress can be null
if (progressView == null){
return;
}
if(updateOnlyProgress) {
if(!basicProgressAsyncTask.isIndeterminate()) {
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() +"%");
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
}
} else {
boolean visible = basicProgressAsyncTask != null && basicProgressAsyncTask.getStatus() != AsyncTask.Status.FINISHED;
progressView.setVisibility(visible ? View.VISIBLE : View.GONE);
if (visible) {
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());
if (!indeterminate) {
progressPercent.setText(basicProgressAsyncTask.getProgressPercentage() + "%");
determinateProgressBar.setProgress(basicProgressAsyncTask.getProgressPercentage());
}
}
updateDownloadButton(false);
}
}
private void makeSureUserCancelDownload() {
AlertDialog.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 DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
if(t != null) {
t.setInterrupted(true);
}
}
});
bld.setNegativeButton(R.string.default_buttons_no, null);
bld.show();
}
public void updateDownloadList(List<IndexItem> list){
Fragment fragment = mTabsAdapter.getItem(2);
//will fall if change tab order
((UpdatesIndexFragment) fragment).updateItemsList(list);
}
public void updateDownloadButton(boolean scroll) {
// View view = getView();
// if (view == null || getExpandableListView() == null){
// return;
// }
// int x = getExpandableListView().getScrollX();
// int y = getExpandableListView().getScrollY();
if (getEntriesToDownload().isEmpty()) {
findViewById(R.id.DownloadButton).setVisibility(View.GONE);
} else {
BasicProgressAsyncTask<?, ?, ?> task = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
boolean running = task instanceof DownloadIndexesThread.DownloadIndexesAsyncTask;
((Button) findViewById(R.id.DownloadButton)).setEnabled(!running);
String text;
int downloads = DownloadActivity.downloadListIndexThread.getDownloads();
if (!running) {
text = getString(R.string.download_files) + " (" + downloads + ")"; //$NON-NLS-1$
} else {
text = getString(R.string.downloading_file_new) + " (" + downloads + ")"; //$NON-NLS-1$
}
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
if (Version.isFreeVersion(getMyApplication())) {
int countedDownloads = DownloadActivity.downloadListIndexThread.getDownloads();
int left = DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - settings.NUMBER_OF_FREE_DOWNLOADS.get() - downloads;
boolean excessLimit = left < 0;
if (left < 0)
left = 0;
if (DownloadActivityType.isCountedInDownloads(getType())) {
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
}
}
((Button) findViewById(R.id.DownloadButton)).setText(text);
}
// if (scroll) {
// getExpandableListView().scrollTo(x, y);
// }
}
public List<DownloadActivityType> getDownloadTypes() {
List<DownloadActivityType> items = new ArrayList<DownloadActivityType>();
items.add(DownloadActivityType.NORMAL_FILE);
items.add(DownloadActivityType.VOICE_FILE);
items.add(DownloadActivityType.ROADS_FILE);
if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null){
items.add(DownloadActivityType.HILLSHADE_FILE);
items.add(DownloadActivityType.SRTM_COUNTRY_FILE);
}
getMyApplication().getAppCustomization().getDownloadTypes(items);
return items;
}
}

View file

@ -8,7 +8,6 @@ import java.util.Map;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
@ -28,7 +27,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
private DownloadIndexFilter myFilter; private DownloadIndexFilter myFilter;
private final List<IndexItem> indexFiles; private final List<IndexItem> indexFiles;
private final List<IndexItemCategory> list = new ArrayList<IndexItemCategory>(); private final List<IndexItemCategory> list = new ArrayList<IndexItemCategory>();
private DownloadIndexActivity downloadActivity; private DownloadIndexFragment downloadFragment;
private Map<String, String> indexFileNames = null; private Map<String, String> indexFileNames = null;
private Map<String, String> indexActivatedFileNames = null; private Map<String, String> indexActivatedFileNames = null;
@ -38,21 +37,21 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
private OsmandRegions osmandRegions; private OsmandRegions osmandRegions;
private java.text.DateFormat format; private java.text.DateFormat format;
public DownloadIndexAdapter(DownloadIndexActivity downloadActivity, List<IndexItem> indexFiles) { public DownloadIndexAdapter(DownloadIndexFragment downloadFragment, List<IndexItem> indexFiles) {
this.downloadActivity = downloadActivity; this.downloadFragment = downloadFragment;
this.indexFiles = new ArrayList<IndexItem>(indexFiles); this.indexFiles = new ArrayList<IndexItem>(indexFiles);
List<IndexItemCategory> cats = IndexItemCategory.categorizeIndexItems(downloadActivity.getMyApplication(), indexFiles); List<IndexItemCategory> cats = IndexItemCategory.categorizeIndexItems(downloadFragment.getMyApplication(), indexFiles);
synchronized (this) { synchronized (this) {
list.clear(); list.clear();
list.addAll(cats); list.addAll(cats);
} }
format = downloadActivity.getMyApplication().getResourceManager().getDateFormat(); format = downloadFragment.getMyApplication().getResourceManager().getDateFormat();
okColor = downloadActivity.getResources().getColor(R.color.color_ok); okColor = downloadFragment.getResources().getColor(R.color.color_ok);
TypedArray ta = downloadActivity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary}); TypedArray ta = downloadFragment.getDownloadActivity().getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown)); defaultColor = ta.getColor(0, downloadFragment.getResources().getColor(R.color.color_unknown));
ta.recycle(); ta.recycle();
updateColor = downloadActivity.getResources().getColor(R.color.color_update); updateColor = downloadFragment.getResources().getColor(R.color.color_update);
osmandRegions = downloadActivity.getMyApplication().getResourceManager().getOsmandRegions(); osmandRegions = downloadFragment.getMyApplication().getResourceManager().getOsmandRegions();
} }
public void setLoadedFiles(Map<String, String> indexActivatedFileNames, Map<String, String> indexFileNames) { public void setLoadedFiles(Map<String, String> indexActivatedFileNames, Map<String, String> indexFileNames) {
@ -62,11 +61,11 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
} }
public void collapseTrees(final CharSequence constraint) { public void collapseTrees(final CharSequence constraint) {
downloadActivity.runOnUiThread(new Runnable() { downloadFragment.getDownloadActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
synchronized (DownloadIndexAdapter.this) { synchronized (DownloadIndexAdapter.this) {
final ExpandableListView expandableListView = downloadActivity.getExpandableListView(); final ExpandableListView expandableListView = downloadFragment.getExpandableListView();
for (int i = 0; i < getGroupCount(); i++) { for (int i = 0; i < getGroupCount(); i++) {
int cp = getChildrenCount(i); int cp = getChildrenCount(i);
if (cp < 7) { if (cp < 7) {
@ -125,7 +124,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
} }
} }
List<IndexItem> filter = new ArrayList<IndexItem>(); List<IndexItem> filter = new ArrayList<IndexItem>();
Context c = downloadActivity; Context c = downloadFragment.getDownloadActivity();
for (IndexItem item : indexFiles) { for (IndexItem item : indexFiles) {
boolean add = true; boolean add = true;
String indexLC = osmandRegions.getDownloadNameIndexLowercase(item.getBasename()); String indexLC = osmandRegions.getDownloadNameIndexLowercase(item.getBasename());
@ -166,11 +165,11 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
list.clear(); list.clear();
Collection<IndexItem> items = (Collection<IndexItem>) results.values; Collection<IndexItem> items = (Collection<IndexItem>) results.values;
if (items != null && !items.isEmpty()) { if (items != null && !items.isEmpty()) {
list.addAll(IndexItemCategory.categorizeIndexItems(downloadActivity.getMyApplication(), items)); list.addAll(IndexItemCategory.categorizeIndexItems(downloadFragment.getMyApplication(), items));
} else if(DownloadIndexAdapter.this.indexFiles.isEmpty()){ } else if(DownloadIndexAdapter.this.indexFiles.isEmpty()){
list.add(new IndexItemCategory(downloadActivity.getResources().getString(R.string.no_index_file_to_download), 1)); list.add(new IndexItemCategory(downloadFragment.getResources().getString(R.string.no_index_file_to_download), 1));
} else { } else {
list.add(new IndexItemCategory(downloadActivity.getResources().getString(R.string.select_index_file_to_download), 1)); list.add(new IndexItemCategory(downloadFragment.getResources().getString(R.string.select_index_file_to_download), 1));
} }
} }
notifyDataSetChanged(); notifyDataSetChanged();
@ -218,7 +217,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
View v = convertView; View v = convertView;
IndexItemCategory group = getGroup(groupPosition); IndexItemCategory group = getGroup(groupPosition);
if (v == null) { if (v == null) {
LayoutInflater inflater = downloadActivity.getLayoutInflater(); LayoutInflater inflater = (LayoutInflater) downloadFragment.getDownloadActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false);
} }
final View row = v; final View row = v;
@ -233,27 +232,27 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView; View v = convertView;
if (v == null) { if (v == null) {
LayoutInflater inflater = downloadActivity.getLayoutInflater(); LayoutInflater inflater = (LayoutInflater) downloadFragment.getDownloadActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(net.osmand.plus.R.layout.download_index_list_item, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.download_index_list_item, parent, false);
} }
final View row = v; final View row = v;
TextView item = (TextView) row.findViewById(R.id.download_item); TextView item = (TextView) row.findViewById(R.id.download_item);
TextView description = (TextView) row.findViewById(R.id.download_descr); TextView description = (TextView) row.findViewById(R.id.download_descr);
IndexItem e = (IndexItem) getChild(groupPosition, childPosition); IndexItem e = (IndexItem) getChild(groupPosition, childPosition);
OsmandApplication clctx = downloadActivity.getMyApplication(); OsmandApplication clctx = downloadFragment.getMyApplication();
String eName = e.getVisibleDescription(clctx) + "\n" + e.getVisibleName(clctx, osmandRegions); String eName = e.getVisibleDescription(clctx) + "\n" + e.getVisibleName(clctx, osmandRegions);
item.setText(eName.trim()); //$NON-NLS-1$ item.setText(eName.trim()); //$NON-NLS-1$
String d = e.getDate(format) + "\n" + e.getSizeDescription(clctx); String d = e.getDate(format) + "\n" + e.getSizeDescription(clctx);
description.setText(d.trim()); description.setText(d.trim());
CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item); CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item);
ch.setChecked(downloadActivity.getEntriesToDownload().containsKey(e)); ch.setChecked(downloadFragment.getDownloadActivity().getEntriesToDownload().containsKey(e));
ch.setOnClickListener(new View.OnClickListener() { ch.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item); final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
ch.setChecked(!ch.isChecked()); ch.setChecked(!ch.isChecked());
downloadActivity.onChildClick(downloadActivity.getListView(), row, groupPosition, childPosition, getChildId(groupPosition, childPosition)); downloadFragment.onChildClick(downloadFragment.getExpandableListView(), row, groupPosition, childPosition, getChildId(groupPosition, childPosition));
} }
}); });
@ -278,22 +277,22 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
} else if (e.getDate(format) != null) { } else if (e.getDate(format) != null) {
String sfName = e.getTargetFileName(); String sfName = e.getTargetFileName();
if (e.getDate(format).equals(indexActivatedFileNames.get(sfName))) { if (e.getDate(format).equals(indexActivatedFileNames.get(sfName))) {
item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : " item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName)); + indexActivatedFileNames.get(sfName));
item.setTextColor(okColor); // GREEN item.setTextColor(okColor); // GREEN
item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else if (e.getDate(format).equals(indexFileNames.get(sfName))) { } else if (e.getDate(format).equals(indexFileNames.get(sfName))) {
item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : " item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName)); + indexFileNames.get(sfName));
item.setTextColor(okColor); item.setTextColor(okColor);
item.setTypeface(Typeface.DEFAULT, Typeface.ITALIC); item.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
} else if (indexActivatedFileNames.containsKey(sfName)) { } else if (indexActivatedFileNames.containsKey(sfName)) {
item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : " item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName)); + indexActivatedFileNames.get(sfName));
item.setTextColor(updateColor); // LIGHT_BLUE item.setTextColor(updateColor); // LIGHT_BLUE
item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else { } else {
item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : " item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName)); + indexFileNames.get(sfName));
item.setTextColor(updateColor); item.setTextColor(updateColor);
item.setTypeface(Typeface.DEFAULT, Typeface.ITALIC); item.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);

View file

@ -0,0 +1,421 @@
package net.osmand.plus.download;
import java.io.File;
import java.io.FilenameFilter;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.*;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.MenuInflater;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
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.OsmandExpandableListFragment;
import net.osmand.plus.activities.SettingsGeneralActivity.MoveFilesToDifferentDirectory;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.AsyncTask.Status;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SubMenu;
public class DownloadIndexFragment extends OsmandExpandableListFragment {
/** menus **/
private static final int MORE_ID = 10;
private static final int RELOAD_ID = 0;
private static final int SELECT_ALL_ID = 1;
private static final int DESELECT_ALL_ID = 2;
private static final int FILTER_EXISTING_REGIONS = 3;
private TextWatcher textWatcher ;
private EditText filterText;
private OsmandSettings settings;
DownloadIndexAdapter listAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.download_index, container, false);
ExpandableListView listView = (ExpandableListView)view.findViewById(android.R.id.list);
List<IndexItem> list = new ArrayList<IndexItem>();
listAdapter = new DownloadIndexAdapter(this, list);
listView.setAdapter(listAdapter);
setListView(listView);
//getSupportActionBar().setTitle(R.string.local_index_download);
// recreation upon rotation is pgetaprevented in manifest file
filterText = (EditText) view.findViewById(R.id.search_box);
textWatcher = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if(listAdapter != null){
listAdapter.getFilter().filter(s);
}
}
};
filterText.addTextChangedListener(textWatcher);
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
DownloadActivity.downloadListIndexThread.setUiFragment(this);
settings = getMyApplication().getSettings();
if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
boolean showedDialog = false;
if(Build.VERSION.SDK_INT < OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
SuggestExternalDirectoryDialog.showDialog(getActivity(), null, null);
}
if(!showedDialog) {
getDownloadActivity().showDialogOfFreeDownloadsIfNeeded();
}
} else {
getDownloadActivity().showDialogOfFreeDownloadsIfNeeded();
}
if (Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) {
final String currentStorage = settings.getExternalStorageDirectory().getAbsolutePath();
String primaryStorage = settings.getDefaultExternalStorageLocation();
if (!currentStorage.startsWith(primaryStorage)) {
// secondary storage
boolean currentDirectoryNotWritable = true;
for (String writeableDirectory : settings.getWritableSecondaryStorageDirectorys()) {
if (currentStorage.startsWith(writeableDirectory)) {
currentDirectoryNotWritable = false;
break;
}
}
if (currentDirectoryNotWritable) {
currentDirectoryNotWritable = !OsmandSettings.isWritable(settings.getExternalStorageDirectory());
}
if (currentDirectoryNotWritable) {
final String newLoc = settings.getMatchingExternalFilesDir(currentStorage);
if (newLoc != null && newLoc.length() != 0) {
AccessibleAlertBuilder ab = new AccessibleAlertBuilder(getDownloadActivity());
ab.setMessage(getString(R.string.android_19_location_disabled,
settings.getExternalStorageDirectory()));
ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
copyFilesForAndroid19(newLoc);
}
});
ab.setNegativeButton(R.string.default_buttons_cancel, null);
ab.show();
}
}
}
}
}
private void copyFilesForAndroid19(final String newLoc) {
MoveFilesToDifferentDirectory task =
new MoveFilesToDifferentDirectory(getDownloadActivity(),
new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR),
new File(newLoc, IndexConstants.APP_DIR)) {
protected Boolean doInBackground(Void[] params) {
Boolean result = super.doInBackground(params);
if(result) {
settings.setExternalStorageDirectory(newLoc);
getMyApplication().getResourceManager().resetStoreDirectory();
getMyApplication().getResourceManager().reloadIndexes(progress) ;
}
return result;
};
};
task.execute();
}
@Override
public void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
getDownloadActivity().updateProgress(false);
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
View mainView = getView().findViewById(R.id.MainLayout);
if (mainView != null) {
mainView.setKeepScreenOn(true);
}
}
}
public void showDialogToDownloadMaps(Collection<String> maps) {
int count = 0;
int sz = 0;
String s = "";
for (IndexItem i : DownloadActivity.downloadListIndexThread.getCachedIndexFiles()) {
for (String map : maps) {
if (i.getFileName().equals(map + ".obf.zip") && i.getType() == DownloadActivityType.NORMAL_FILE) {
final List<DownloadEntry> de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList<DownloadEntry>(1));
for(DownloadEntry d : de ) {
count++;
sz += d.sizeMB;
}
if(s.length() > 0) {
s +=", ";
}
s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
getDownloadActivity().getEntriesToDownload().put(i, de);
}
}
}
if(count > 0){
Builder builder = new AlertDialog.Builder(getDownloadActivity());
builder.setMessage(getString(R.string.download_additional_maps, s, sz));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getDownloadActivity().downloadFilesCheckInternet();
}
});
builder.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getDownloadActivity().getEntriesToDownload().clear();
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
getDownloadActivity().getEntriesToDownload().clear();
}
});
builder.show();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == RELOAD_ID) {
// re-create the thread
DownloadActivity.downloadListIndexThread.runReloadIndexFiles();
return true;
} else if (item.getItemId() == SELECT_ALL_ID) {
selectAll();
return true;
} else if (item.getItemId() == FILTER_EXISTING_REGIONS) {
filterExisting();
return true;
} else if (item.getItemId() == DESELECT_ALL_ID) {
deselectAll();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
ActionBar actionBar = getDownloadActivity().getSupportActionBar();
final List<DownloadActivityType> downloadTypes = getDownloadActivity().getDownloadTypes();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(actionBar.getThemedContext(), R.layout.sherlock_spinner_item,
toString(downloadTypes));
spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
actionBar.setListNavigationCallbacks(spinnerAdapter, new ActionBar.OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
getDownloadActivity().changeType(downloadTypes.get(itemPosition));
return true;
}
});
if (getMyApplication().getAppCustomization().showDownloadExtraActions()) {
SubMenu s = menu.addSubMenu(0, MORE_ID, 0, R.string.default_buttons_other_actions);
s.add(0, RELOAD_ID, 0, R.string.update_downlod_list);
s.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes);
s.add(0, SELECT_ALL_ID, 0, R.string.select_all);
s.add(0, DESELECT_ALL_ID, 0, R.string.deselect_all);
s.setIcon(isLightActionBar() ? R.drawable.abs__ic_menu_moreoverflow_holo_light
: R.drawable.abs__ic_menu_moreoverflow_holo_dark);
}
}
public String getFilterText() {
return filterText.getText().toString();
}
public void deselectAll() {
DownloadActivity.downloadListIndexThread.getEntriesToDownload().clear();
listAdapter.notifyDataSetInvalidated();
getView().findViewById(R.id.DownloadButton).setVisibility(View.GONE);
}
private void filterExisting() {
final Map<String, String> listAlreadyDownloaded = DownloadActivity.downloadListIndexThread.getDownloadedIndexFileNames();
final List<IndexItem> filtered = new ArrayList<IndexItem>();
for (IndexItem fileItem : listAdapter.getIndexFiles()) {
if(fileItem.isAlreadyDownloaded(listAlreadyDownloaded)){
filtered.add(fileItem);
}
}
listAdapter.setIndexFiles(filtered, IndexItemCategory.categorizeIndexItems(getMyApplication(), filtered));
listAdapter.notifyDataSetChanged();
}
private void selectAll() {
int selected = 0;
for (int j = 0; j < listAdapter.getGroupCount(); j++) {
for (int i = 0; i < listAdapter.getChildrenCount(j); i++) {
IndexItem es = listAdapter.getChild(j, i);
if (!getDownloadActivity().getEntriesToDownload().containsKey(es)) {
selected++;
getDownloadActivity().getEntriesToDownload().put(es, es.createDownloadEntry(getMyApplication(),
getDownloadActivity().getType(), new ArrayList<DownloadEntry>(1)));
}
}
}
AccessibleToast.makeText(getDownloadActivity(), MessageFormat.format(getString(R.string.items_were_selected), selected), Toast.LENGTH_SHORT).show();
listAdapter.notifyDataSetInvalidated();
if(selected > 0){
getDownloadActivity().updateDownloadButton(true);
}
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
final IndexItem e = (IndexItem) listAdapter.getChild(groupPosition, childPosition);
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
if(ch.isChecked()){
ch.setChecked(!ch.isChecked());
getDownloadActivity().getEntriesToDownload().remove(e);
getDownloadActivity().updateDownloadButton(true);
return true;
}
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) {
// if(!fileToUnzip.exists()){
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
getDownloadActivity().getEntriesToDownload().put(e, download);
getDownloadActivity().updateDownloadButton(true);
ch.setChecked(!ch.isChecked());
}
return true;
}
public static Map<String, String> listWithAlternatives(final java.text.DateFormat dateFormat, File file, final String ext,
final Map<String, String> files) {
if (file.isDirectory()) {
file.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
if (filename.endsWith(ext)) {
String date = dateFormat.format(findFileInDir(new File(dir, filename)).lastModified());
files.put(filename, date);
return true;
} else {
return false;
}
}
});
}
return files;
}
public static File findFileInDir(File file) {
if(file.isDirectory()) {
File[] lf = file.listFiles();
if(lf != null) {
for(File f : lf) {
if(f.isFile()) {
return f;
}
}
}
}
return file;
}
@Override
public void onDestroy() {
super.onDestroy();
if (textWatcher != null && getView() != null) {
EditText filterText = (EditText) getView().findViewById(R.id.search_box);
filterText.removeTextChangedListener(textWatcher);
}
DownloadActivity.downloadListIndexThread.setUiFragment(null);
}
public List<String> toString(List<DownloadActivityType> t) {
ArrayList<String> items = new ArrayList<String>();
for(DownloadActivityType ts : t) {
items.add(ts.getString(getMyApplication()));
}
return items;
}
public DownloadActivity getDownloadActivity(){ return (DownloadActivity)getActivity();}
public ExpandableListAdapter getExpandableListAdapter(){ return listAdapter;}
public View findViewById(int id){ return getView().findViewById(id);}
public void updateProgress(boolean b) {
getDownloadActivity().updateProgress(b);
}
}

View file

@ -23,7 +23,6 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.OsmandPreference;
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.DownloadIndexActivity;
import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning; import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
@ -47,7 +46,7 @@ import android.view.View;
import android.widget.Toast; import android.widget.Toast;
public class DownloadIndexesThread { public class DownloadIndexesThread {
private DownloadIndexActivity uiActivity = null; private DownloadIndexFragment uiFragment = null;
private IndexFileList indexFiles = null; private IndexFileList indexFiles = null;
private Map<IndexItem, List<DownloadEntry>> entriesToDownload = new ConcurrentHashMap<IndexItem, List<DownloadEntry>>(); private Map<IndexItem, List<DownloadEntry>> entriesToDownload = new ConcurrentHashMap<IndexItem, List<DownloadEntry>>();
private Set<DownloadEntry> currentDownloads = new HashSet<DownloadEntry>(); private Set<DownloadEntry> currentDownloads = new HashSet<DownloadEntry>();
@ -59,7 +58,8 @@ public class DownloadIndexesThread {
private Map<String, String> indexFileNames = new LinkedHashMap<String, String>(); private Map<String, String> indexFileNames = new LinkedHashMap<String, String>();
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<String, String>(); private Map<String, String> indexActivatedFileNames = new LinkedHashMap<String, String>();
private java.text.DateFormat dateFormat; private java.text.DateFormat dateFormat;
private List<IndexItem> itemsToUpdate = new ArrayList<IndexItem>();
public DownloadIndexesThread(Context ctx) { public DownloadIndexesThread(Context ctx) {
this.ctx = ctx; this.ctx = ctx;
@ -72,8 +72,8 @@ public class DownloadIndexesThread {
indexFiles = null; indexFiles = null;
} }
public void setUiActivity(DownloadIndexActivity uiActivity) { public void setUiFragment(DownloadIndexFragment uiFragment) {
this.uiActivity = uiActivity; this.uiFragment = uiFragment;
} }
public List<DownloadEntry> flattenDownloadEntries() { public List<DownloadEntry> flattenDownloadEntries() {
@ -92,13 +92,13 @@ public class DownloadIndexesThread {
public void updateLoadedFiles() { public void updateLoadedFiles() {
Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames(); Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT, DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
indexActivatedFileNames); indexActivatedFileNames);
Map<String, String> indexFileNames = app.getResourceManager().getIndexFileNames(); Map<String, String> indexFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT, DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
indexFileNames); indexFileNames);
app.getAppCustomization().updatedLoadedFiles(indexFileNames, indexActivatedFileNames); app.getAppCustomization().updatedLoadedFiles(indexFileNames, indexActivatedFileNames);
DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR), DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR),
IndexConstants.SQLITE_EXT, indexFileNames); IndexConstants.SQLITE_EXT, indexFileNames);
app.getResourceManager().getBackupIndexes(indexFileNames); app.getResourceManager().getBackupIndexes(indexFileNames);
this.indexFileNames = indexFileNames; this.indexFileNames = indexFileNames;
@ -112,6 +112,8 @@ public class DownloadIndexesThread {
public boolean isDownloadedFromInternet() { public boolean isDownloadedFromInternet() {
return indexFiles != null && indexFiles.isDownloadedFromInternet(); return indexFiles != null && indexFiles.isDownloadedFromInternet();
} }
public List<IndexItem> getItemsToUpdate() { return itemsToUpdate;}
public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask<IndexItem, Object, String> implements DownloadFileShowWarning { public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask<IndexItem, Object, String> implements DownloadFileShowWarning {
@ -134,15 +136,15 @@ public class DownloadIndexesThread {
protected void onProgressUpdate(Object... values) { protected void onProgressUpdate(Object... values) {
for (Object o : values) { for (Object o : values) {
if (o instanceof DownloadEntry) { if (o instanceof DownloadEntry) {
if (uiActivity != null) { if (uiFragment != null) {
((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).notifyDataSetInvalidated(); ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter()).notifyDataSetInvalidated();
uiActivity.updateDownloadButton(false); uiFragment.getDownloadActivity().updateDownloadButton(false);
} }
} else if (o instanceof IndexItem) { } else if (o instanceof IndexItem) {
entriesToDownload.remove(o); entriesToDownload.remove(o);
if (uiActivity != null) { if (uiFragment != null) {
((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()).notifyDataSetInvalidated(); ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter()).notifyDataSetInvalidated();
uiActivity.updateDownloadButton(false); uiFragment.getDownloadActivity().updateDownloadButton(false);
} }
} else if (o instanceof String) { } else if (o instanceof String) {
AccessibleToast.makeText(ctx, (String) o, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(ctx, (String) o, Toast.LENGTH_LONG).show();
@ -155,9 +157,9 @@ public class DownloadIndexesThread {
protected void onPreExecute() { protected void onPreExecute() {
currentRunningTask.add( this); currentRunningTask.add( this);
super.onPreExecute(); super.onPreExecute();
if (uiActivity != null) { if (uiFragment != null) {
downloadFileHelper.setInterruptDownloading(false); downloadFileHelper.setInterruptDownloading(false);
View mainView = uiActivity.findViewById(R.id.MainLayout); View mainView = uiFragment.findViewById(R.id.MainLayout);
if (mainView != null) { if (mainView != null) {
mainView.setKeepScreenOn(true); mainView.setKeepScreenOn(true);
} }
@ -171,19 +173,19 @@ public class DownloadIndexesThread {
AccessibleToast.makeText(ctx, result, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(ctx, result, Toast.LENGTH_LONG).show();
} }
currentDownloads.clear(); currentDownloads.clear();
if (uiActivity != null) { if (uiFragment != null) {
View mainView = uiActivity.findViewById(R.id.MainLayout); View mainView = uiFragment.findViewById(R.id.MainLayout);
if (mainView != null) { if (mainView != null) {
mainView.setKeepScreenOn(false); mainView.setKeepScreenOn(false);
} }
DownloadIndexAdapter adapter = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()); DownloadIndexAdapter adapter = ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter());
if (adapter != null) { if (adapter != null) {
adapter.setLoadedFiles(indexActivatedFileNames, indexFileNames); adapter.setLoadedFiles(indexActivatedFileNames, indexFileNames);
} }
} }
currentRunningTask.remove(this); currentRunningTask.remove(this);
if(uiActivity != null) { if(uiFragment != null) {
uiActivity.updateProgress(false); uiFragment.updateProgress(false);
} }
} }
@ -230,7 +232,7 @@ public class DownloadIndexesThread {
break downloadCycle; break downloadCycle;
} }
if (exceedsFreelimit(entry)) { if (exceedsFreelimit(entry)) {
breakDownloadMessage = app.getString(R.string.free_version_message, DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS breakDownloadMessage = app.getString(R.string.free_version_message, DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
+ ""); + "");
break downloadCycle; break downloadCycle;
} }
@ -272,7 +274,7 @@ public class DownloadIndexesThread {
private boolean exceedsFreelimit(DownloadEntry entry) { private boolean exceedsFreelimit(DownloadEntry entry) {
return Version.isFreeVersion(app) && return Version.isFreeVersion(app) &&
DownloadActivityType.isCountedInDownloads(entry.item.getType()) && downloads.get() >= DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS; DownloadActivityType.isCountedInDownloads(entry.item.getType()) && downloads.get() >= DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
} }
private String reindexFiles(List<File> filesToReindex) { private String reindexFiles(List<File> filesToReindex) {
@ -322,8 +324,8 @@ public class DownloadIndexesThread {
boolean res = false; boolean res = false;
if (de.isAsset) { if (de.isAsset) {
try { try {
if (uiActivity != null) { if (uiFragment != null) {
ResourceManager.copyAssets(uiActivity.getAssets(), de.assetName, de.targetFile); ResourceManager.copyAssets(uiFragment.getDownloadActivity().getAssets(), de.assetName, de.targetFile);
boolean changedDate = de.targetFile.setLastModified(de.dateModified); boolean changedDate = de.targetFile.setLastModified(de.dateModified);
if(!changedDate) { if(!changedDate) {
log.error("Set last timestamp is not supported"); log.error("Set last timestamp is not supported");
@ -344,8 +346,8 @@ public class DownloadIndexesThread {
@Override @Override
protected void updateProgress(boolean updateOnlyProgress) { protected void updateProgress(boolean updateOnlyProgress) {
if(uiActivity != null) { if(uiFragment != null) {
uiActivity.updateProgress(updateOnlyProgress); uiFragment.updateProgress(updateOnlyProgress);
} }
} }
} }
@ -376,19 +378,19 @@ public class DownloadIndexesThread {
protected void onPostExecute(IndexFileList result) { protected void onPostExecute(IndexFileList result) {
indexFiles = result; indexFiles = result;
if (indexFiles != null && uiActivity != null) { if (indexFiles != null && uiFragment != null) {
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap(); boolean basemapExists = uiFragment.getMyApplication().getResourceManager().containsBasemap();
IndexItem basemap = indexFiles.getBasemap(); IndexItem basemap = indexFiles.getBasemap();
if (basemap != null ) { if (basemap != null ) {
String dt = uiActivity.getMyApplication().getResourceManager().getIndexFileNames().get(basemap.getTargetFileName()); String dt = uiFragment.getMyApplication().getResourceManager().getIndexFileNames().get(basemap.getTargetFileName());
if (!basemapExists || !Algorithms.objectEquals(dt, basemap.getDate(dateFormat))) { if (!basemapExists || !Algorithms.objectEquals(dt, basemap.getDate(dateFormat))) {
List<DownloadEntry> downloadEntry = basemap List<DownloadEntry> downloadEntry = basemap
.createDownloadEntry(uiActivity.getMyApplication(), DownloadActivityType.NORMAL_FILE, .createDownloadEntry(uiFragment.getMyApplication(), DownloadActivityType.NORMAL_FILE,
new ArrayList<DownloadEntry>()); new ArrayList<DownloadEntry>());
uiActivity.getEntriesToDownload().put(basemap, downloadEntry); uiFragment.getDownloadActivity().getEntriesToDownload().put(basemap, downloadEntry);
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download, AccessibleToast.makeText(uiFragment.getDownloadActivity(), R.string.basemap_was_selected_to_download,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE); uiFragment.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
} }
} }
if (indexFiles.isIncreasedMapVersion()) { if (indexFiles.isIncreasedMapVersion()) {
@ -398,9 +400,9 @@ public class DownloadIndexesThread {
AccessibleToast.makeText(ctx, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(ctx, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show();
} }
currentRunningTask.remove(this); currentRunningTask.remove(this);
if (uiActivity != null) { if (uiFragment != null) {
uiActivity.updateProgress(false); uiFragment.updateProgress(false);
runCategorization(uiActivity.getType()); runCategorization(uiFragment.getDownloadActivity().getType());
} }
} }
@ -429,8 +431,8 @@ public class DownloadIndexesThread {
@Override @Override
protected void updateProgress(boolean updateOnlyProgress) { protected void updateProgress(boolean updateOnlyProgress) {
if (uiActivity != null) { if (uiFragment != null) {
uiActivity.updateProgress(updateOnlyProgress); uiFragment.updateProgress(updateOnlyProgress);
} }
}; };
@ -469,8 +471,8 @@ public class DownloadIndexesThread {
super.onPreExecute(); super.onPreExecute();
currentRunningTask.add(this); currentRunningTask.add(this);
this.message = ctx.getString(R.string.downloading_list_indexes); this.message = ctx.getString(R.string.downloading_list_indexes);
if(uiActivity != null) { if(uiFragment != null) {
uiActivity.updateProgress(false); uiFragment.updateProgress(false);
} }
} }
@ -498,16 +500,17 @@ public class DownloadIndexesThread {
@Override @Override
protected void onPostExecute(List<IndexItem> filtered) { protected void onPostExecute(List<IndexItem> filtered) {
if (uiActivity != null) { if (uiFragment != null) {
DownloadIndexAdapter a = ((DownloadIndexAdapter) uiActivity.getExpandableListAdapter()); DownloadIndexAdapter a = ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter());
a.setLoadedFiles(indexActivatedFileNames, indexFileNames); a.setLoadedFiles(indexActivatedFileNames, indexFileNames);
a.setIndexFiles(filtered, cats); a.setIndexFiles(filtered, cats);
prepareFilesToDownload(filtered);
a.notifyDataSetChanged(); a.notifyDataSetChanged();
a.getFilter().filter(uiActivity.getFilterText()); a.getFilter().filter(uiFragment.getFilterText());
if ((type == DownloadActivityType.SRTM_COUNTRY_FILE || type == DownloadActivityType.HILLSHADE_FILE) if ((type == DownloadActivityType.SRTM_COUNTRY_FILE || type == DownloadActivityType.HILLSHADE_FILE)
&& OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin && OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin
&& !OsmandPlugin.getEnabledPlugin(SRTMPlugin.class).isPaid()) { && !OsmandPlugin.getEnabledPlugin(SRTMPlugin.class).isPaid()) {
Builder msg = new AlertDialog.Builder(uiActivity); Builder msg = new AlertDialog.Builder(uiFragment.getDownloadActivity());
msg.setTitle(R.string.srtm_paid_version_title); msg.setTitle(R.string.srtm_paid_version_title);
msg.setMessage(R.string.srtm_paid_version_msg); msg.setMessage(R.string.srtm_paid_version_msg);
msg.setNegativeButton(R.string.button_upgrade_osmandplus, new DialogInterface.OnClickListener() { msg.setNegativeButton(R.string.button_upgrade_osmandplus, new DialogInterface.OnClickListener() {
@ -525,15 +528,15 @@ public class DownloadIndexesThread {
} }
} }
currentRunningTask.remove(this); currentRunningTask.remove(this);
if(uiActivity != null) { if(uiFragment != null) {
uiActivity.updateProgress(false); uiFragment.updateProgress(false);
} }
} }
@Override @Override
protected void updateProgress(boolean updateOnlyProgress) { protected void updateProgress(boolean updateOnlyProgress) {
if(uiActivity != null) { if(uiFragment != null) {
uiActivity.updateProgress(updateOnlyProgress); uiFragment.updateProgress(updateOnlyProgress);
} }
}; };
@ -542,7 +545,26 @@ public class DownloadIndexesThread {
execute(inst, new Void[0]); execute(inst, new Void[0]);
} }
private void prepareFilesToDownload(List<IndexItem> filtered) {
itemsToUpdate.clear();
for (IndexItem item : filtered) {
String sfName = item.getTargetFileName();
java.text.DateFormat format = uiFragment.getDownloadActivity().getMyApplication().getResourceManager().getDateFormat();
String date = item.getDate(format);
String indexactivateddate = indexActivatedFileNames.get(sfName);
String indexfilesdate = indexFileNames.get(sfName);
if (date != null &&
!date.equals(indexactivateddate) &&
!date.equals(indexfilesdate) &&
indexActivatedFileNames.containsKey(sfName)) {
itemsToUpdate.add(item);
}
}
itemsToUpdate.size();
uiFragment.getDownloadActivity().updateDownloadList(itemsToUpdate);
}
public boolean isDownloadRunning() { public boolean isDownloadRunning() {
for (int i = 0; i < currentRunningTask.size(); i++) { for (int i = 0; i < currentRunningTask.size(); i++) {
if (currentRunningTask.get(i) instanceof DownloadIndexesAsyncTask) { if (currentRunningTask.get(i) instanceof DownloadIndexesAsyncTask) {

View file

@ -1,4 +1,4 @@
package net.osmand.plus.activities; package net.osmand.plus.download;
import java.io.File; import java.io.File;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -10,6 +10,8 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.*;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
@ -18,6 +20,7 @@ import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.*;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -30,12 +33,10 @@ import android.content.Intent;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.os.Bundle; import android.os.Bundle;
import android.os.StatFs; import android.os.StatFs;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan; import android.text.style.ClickableSpan;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
@ -49,14 +50,9 @@ import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.ActionMode.Callback; import com.actionbarsherlock.view.ActionMode.Callback;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SubMenu;
import com.actionbarsherlock.view.Window;
public class LocalIndexesActivity extends OsmandExpandableListActivity { public class LocalIndexesFragment extends OsmandExpandableListFragment {
private LoadLocalIndexTask asyncLoader; private LoadLocalIndexTask asyncLoader;
private LocalIndexesAdapter listAdapter; private LocalIndexesAdapter listAdapter;
@ -75,22 +71,48 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
private ContextMenuAdapter optionsMenuAdapter; private ContextMenuAdapter optionsMenuAdapter;
private ActionMode actionMode; private ActionMode actionMode;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.local_index, container, false);
getDownloadActivity().getSupportActionBar().setTitle(R.string.local_index_descr_title);
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
ExpandableListView listView = (ExpandableListView)view.findViewById(android.R.id.list);
listAdapter = new LocalIndexesAdapter(getActivity());
listView.setAdapter(listAdapter);
setListView(listView);
//getDownloadActivity().getSupportActionBar().setLogo(R.drawable.tab_download_screen_icon);
return view;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.local_index);
getSupportActionBar().setTitle(R.string.local_index_descr_title);
setSupportProgressBarIndeterminateVisibility(false);
// getSupportActionBar().setLogo(R.drawable.tab_download_screen_icon);
descriptionLoader = new LoadLocalIndexDescriptionTask(); descriptionLoader = new LoadLocalIndexDescriptionTask();
listAdapter = new LocalIndexesAdapter(this);
updateDescriptionTextWithSize();
if (asyncLoader == null || asyncLoader.getResult() == null) {
// getLastNonConfigurationInstance method should be in onCreate() method
// (onResume() doesn't work)
Object indexes = getActivity().getLastNonConfigurationInstance();
asyncLoader = new LoadLocalIndexTask();
if (indexes instanceof List<?>) {
asyncLoader.setResult((List<LocalIndexInfo>) indexes);
}
}
setHasOptionsMenu(true);
}
@Override
public void onResume() {
super.onResume();
if (asyncLoader == null || asyncLoader.getResult() == null) {
asyncLoader = new LoadLocalIndexTask();
asyncLoader.execute(getActivity());
}
getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@Override @Override
@ -104,35 +126,14 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
} }
} }
}); });
setListAdapter(listAdapter);
updateDescriptionTextWithSize();
if (asyncLoader == null || asyncLoader.getResult() == null) {
// getLastNonConfigurationInstance method should be in onCreate() method
// (onResume() doesn't work)
Object indexes = getLastNonConfigurationInstance();
asyncLoader = new LoadLocalIndexTask();
if (indexes instanceof List<?>) {
asyncLoader.setResult((List<LocalIndexInfo>) indexes);
}
}
}
@Override
protected void onResume() {
super.onResume();
if (asyncLoader == null || asyncLoader.getResult() == null) {
asyncLoader = new LoadLocalIndexTask();
asyncLoader.execute(this);
}
} }
private void showContextMenu(final LocalIndexInfo info) { private void showContextMenu(final LocalIndexInfo info) {
Builder builder = new AlertDialog.Builder(this); Builder builder = new AlertDialog.Builder(getActivity());
final ContextMenuAdapter adapter = new ContextMenuAdapter(this); final ContextMenuAdapter adapter = new ContextMenuAdapter(getActivity());
basicFileOperation(info, adapter); basicFileOperation(info, adapter);
OsmandPlugin.onContextMenuActivity(this, null, info, adapter); OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter);
String[] values = adapter.getItemNames(); String[] values = adapter.getItemNames();
builder.setItems(values, new DialogInterface.OnClickListener() { builder.setItems(values, new DialogInterface.OnClickListener() {
@ -158,7 +159,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
} else if (resId == R.string.local_index_mi_restore) { } else if (resId == R.string.local_index_mi_restore) {
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info); new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
} else if (resId == R.string.local_index_mi_delete) { } else if (resId == R.string.local_index_mi_delete) {
Builder confirm = new AlertDialog.Builder(LocalIndexesActivity.this); Builder confirm = new AlertDialog.Builder(getActivity());
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -187,9 +188,9 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
private void renameFile(LocalIndexInfo info) { private void renameFile(LocalIndexInfo info) {
final File f = new File(info.getPathToData()); final File f = new File(info.getPathToData());
Builder b = new AlertDialog.Builder(this); Builder b = new AlertDialog.Builder(getActivity());
if(f.exists()){ if(f.exists()){
final EditText editText = new EditText(this); final EditText editText = new EditText(getActivity());
editText.setText(f.getName()); editText.setText(f.getName());
b.setView(editText); b.setView(editText);
b.setPositiveButton(R.string.default_buttons_save, new DialogInterface.OnClickListener() { b.setPositiveButton(R.string.default_buttons_save, new DialogInterface.OnClickListener() {
@ -199,7 +200,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
String newName = editText.getText().toString(); String newName = editText.getText().toString();
File dest = new File(f.getParentFile(), newName); File dest = new File(f.getParentFile(), newName);
if (dest.exists()) { if (dest.exists()) {
AccessibleToast.makeText(LocalIndexesActivity.this, R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(getDownloadActivity(), R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
} else { } else {
if(!f.getParentFile().exists()) { if(!f.getParentFile().exists()) {
f.getParentFile().mkdirs(); f.getParentFile().mkdirs();
@ -207,7 +208,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
if(f.renameTo(dest)){ if(f.renameTo(dest)){
reloadIndexes(); reloadIndexes();
} else { } else {
AccessibleToast.makeText(LocalIndexesActivity.this, R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(getDownloadActivity(), R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
} }
} }
@ -234,9 +235,9 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
setSupportProgressBarIndeterminateVisibility(true); getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
} }
@Override @Override
protected void onProgressUpdate(LocalIndexInfo... values) { protected void onProgressUpdate(LocalIndexInfo... values) {
for (LocalIndexInfo v : values) { for (LocalIndexInfo v : values) {
@ -244,7 +245,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
} }
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
public void setResult(List<LocalIndexInfo> result) { public void setResult(List<LocalIndexInfo> result) {
this.result = result; this.result = result;
if(result == null){ if(result == null){
@ -261,15 +262,15 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override @Override
protected void onPostExecute(List<LocalIndexInfo> result) { protected void onPostExecute(List<LocalIndexInfo> result) {
this.result = result; this.result = result;
setSupportProgressBarIndeterminateVisibility(false); getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
} }
public List<LocalIndexInfo> getResult() { public List<LocalIndexInfo> getResult() {
return result; return result;
} }
} }
private File getFileToRestore(LocalIndexInfo i){ private File getFileToRestore(LocalIndexInfo i){
if(i.isBackupedData()){ if(i.isBackupedData()){
File parent = new File(i.getPathToData()).getParentFile(); File parent = new File(i.getPathToData()).getParentFile();
@ -366,13 +367,13 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
setProgressBarIndeterminateVisibility(true); getDownloadActivity().setProgressBarIndeterminateVisibility(true);
} }
@Override @Override
protected void onPostExecute(String result) { protected void onPostExecute(String result) {
setProgressBarIndeterminateVisibility(false); getDownloadActivity().setProgressBarIndeterminateVisibility(false);
AccessibleToast.makeText(LocalIndexesActivity.this, result, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(getDownloadActivity(), result, Toast.LENGTH_LONG).show();
listAdapter.clear(); listAdapter.clear();
reloadIndexes(); reloadIndexes();
@ -431,7 +432,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override @Override
protected void onPause() { public void onPause() {
super.onPause(); super.onPause();
if(operationTask != null){ if(operationTask != null){
operationTask.cancel(true); operationTask.cancel(true);
@ -439,32 +440,32 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
} }
@Override @Override
protected void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
asyncLoader.cancel(true); asyncLoader.cancel(true);
descriptionLoader.cancel(true); descriptionLoader.cancel(true);
} }
@Override // @Override
public Object onRetainNonConfigurationInstance() { // public Object onRetainNonConfigurationInstance() {
if(asyncLoader != null){ // if(asyncLoader != null){
return asyncLoader.getResult(); // return asyncLoader.getResult();
} // }
return super.onRetainNonConfigurationInstance(); // return super.onRetainNonConfigurationInstance();
} // }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
optionsMenuAdapter = new ContextMenuAdapter(this); ActionBar actionBar = getDownloadActivity().getSupportActionBar();
//hide action bar from downloadindexfragment
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
optionsMenuAdapter = new ContextMenuAdapter(getDownloadActivity());
OnContextMenuClick listener = new OnContextMenuClick() { OnContextMenuClick listener = new OnContextMenuClick() {
@Override @Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
localOptionsMenu(itemId); localOptionsMenu(itemId);
} }
}; };
optionsMenuAdapter.item(R.string.local_index_download)
.icons(R.drawable.ic_action_gdown_dark, R.drawable.ic_action_gdown_light)
.listen(listener).position(0).reg();
optionsMenuAdapter.item(R.string.local_index_mi_reload) optionsMenuAdapter.item(R.string.local_index_mi_reload)
.icons(R.drawable.ic_action_refresh_dark, R.drawable.ic_action_refresh_light) .icons(R.drawable.ic_action_refresh_dark, R.drawable.ic_action_refresh_light)
.listen(listener).position(1).reg(); .listen(listener).position(1).reg();
@ -477,7 +478,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
optionsMenuAdapter.item(R.string.local_index_mi_delete) optionsMenuAdapter.item(R.string.local_index_mi_delete)
.icons(R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_light) .icons(R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_light)
.listen(listener).position(4).reg(); .listen(listener).position(4).reg();
OsmandPlugin.onOptionsMenuActivity(this, null, optionsMenuAdapter); OsmandPlugin.onOptionsMenuActivity(getDownloadActivity(), null, optionsMenuAdapter);
// doesn't work correctly // doesn't work correctly
int max = getResources().getInteger(R.integer.abs__max_action_buttons); int max = getResources().getInteger(R.integer.abs__max_action_buttons);
SubMenu split = null; SubMenu split = null;
@ -502,18 +503,16 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
} }
} }
return true;
} }
@Override // @Override
public boolean onPrepareOptionsMenu(Menu menu) { // public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if(operationTask == null || operationTask.getStatus() == Status.FINISHED){ // if(operationTask == null || operationTask.getStatus() == Status.FINISHED){
menu.setGroupVisible(0, true); // menu.setGroupVisible(0, true);
} else { // } else {
menu.setGroupVisible(0, false); // menu.setGroupVisible(0, false);
} // }
return true; // }
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
@ -562,23 +561,23 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
final String actionButton = value; final String actionButton = value;
if(listAdapter.getGroupCount() == 0){ if(listAdapter.getGroupCount() == 0){
listAdapter.cancelFilter(); listAdapter.cancelFilter();
AccessibleToast.makeText(LocalIndexesActivity.this, getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show(); AccessibleToast.makeText(getDownloadActivity(), getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
return; return;
} }
collapseAllGroups(); collapseAllGroups();
selectionMode = true; selectionMode = true;
selectedItems.clear(); selectedItems.clear();
actionMode = startActionMode(new Callback() { actionMode = getDownloadActivity().startActionMode(new Callback() {
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
selectionMode = true; selectionMode = true;
MenuItem it = menu.add(actionResId); MenuItem it = menu.add(actionResId);
if(actionIconId != 0) { if (actionIconId != 0) {
it.setIcon(actionIconId); it.setIcon(actionIconId);
} }
it.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | it.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT); MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true; return true;
} }
@ -591,12 +590,12 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (selectedItems.isEmpty()) { if (selectedItems.isEmpty()) {
AccessibleToast.makeText(LocalIndexesActivity.this, AccessibleToast.makeText(getDownloadActivity(),
getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show(); getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
return true; return true;
} }
Builder builder = new AlertDialog.Builder(LocalIndexesActivity.this); Builder builder = new AlertDialog.Builder(getDownloadActivity());
builder.setMessage(getString(R.string.local_index_action_do, actionButton.toLowerCase(), selectedItems.size())); builder.setMessage(getString(R.string.local_index_action_do, actionButton.toLowerCase(), selectedItems.size()));
builder.setPositiveButton(actionButton, listener); builder.setPositiveButton(actionButton, listener);
builder.setNegativeButton(R.string.default_buttons_cancel, null); builder.setNegativeButton(R.string.default_buttons_cancel, null);
@ -607,15 +606,15 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override @Override
public void onDestroyActionMode(ActionMode mode) { public void onDestroyActionMode(ActionMode mode) {
selectionMode = false; selectionMode = false;
findViewById(R.id.DescriptionText).setVisibility(View.VISIBLE); //findViewById(R.id.DescriptionText).setVisibility(View.VISIBLE);
updateDescriptionTextWithSize(); //updateDescriptionTextWithSize();
listAdapter.cancelFilter(); listAdapter.cancelFilter();
collapseAllGroups(); collapseAllGroups();
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
}); });
findViewById(R.id.DescriptionText).setVisibility(View.GONE); //findViewById(R.id.DescriptionText).setVisibility(View.GONE);
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
@ -626,7 +625,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
StatFs fs = new StatFs(dir.getAbsolutePath()); StatFs fs = new StatFs(dir.getAbsolutePath());
size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) }); size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) });
} }
TextView ds = (TextView) findViewById(R.id.DescriptionText); //TextView ds = (TextView) findViewById(R.id.DescriptionText);
String text = getString(R.string.download_link_and_local_description, size); String text = getString(R.string.download_link_and_local_description, size);
int l = text.indexOf('.'); int l = text.indexOf('.');
if(l == -1) { if(l == -1) {
@ -637,7 +636,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override @Override
public void onClick(View widget) { public void onClick(View widget) {
asyncLoader.setResult(null); asyncLoader.setResult(null);
startActivity(new Intent(LocalIndexesActivity.this, DownloadIndexActivity.class)); startActivity(new Intent(getDownloadActivity(), DownloadIndexFragment.class));
} }
@Override @Override
@ -646,8 +645,8 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
// ds.setColor(Color.GREEN); // ds.setColor(Color.GREEN);
} }
}, 0, l, 0); }, 0, l, 0);
ds.setText(content); //ds.setText(content);
ds.setMovementMethod(LinkMovementMethod.getInstance()); //ds.setMovementMethod(LinkMovementMethod.getInstance());
} }
@ -655,7 +654,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
public void localOptionsMenu(final int itemId) { public void localOptionsMenu(final int itemId) {
if (itemId == R.string.local_index_download) { if (itemId == R.string.local_index_download) {
asyncLoader.setResult(null); asyncLoader.setResult(null);
startActivity(new Intent(LocalIndexesActivity.this, DownloadIndexActivity.class)); startActivity(new Intent(getDownloadActivity(), DownloadIndexFragment.class));
} else if (itemId == R.string.local_index_mi_reload) { } else if (itemId == R.string.local_index_mi_reload) {
reloadIndexes(); reloadIndexes();
} else if (itemId == R.string.local_index_mi_delete) { } else if (itemId == R.string.local_index_mi_delete) {
@ -708,7 +707,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
@Override @Override
protected void onPostExecute(List<String> warnings) { protected void onPostExecute(List<String> warnings) {
setProgressBarIndeterminateVisibility(false); getDownloadActivity().setProgressBarIndeterminateVisibility(false);
if (!warnings.isEmpty()) { if (!warnings.isEmpty()) {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
boolean f = true; boolean f = true;
@ -720,17 +719,17 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
} }
b.append(w); b.append(w);
} }
AccessibleToast.makeText(LocalIndexesActivity.this, b.toString(), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(getDownloadActivity(), b.toString(), Toast.LENGTH_LONG).show();
} }
if(asyncLoader.getStatus() == Status.PENDING) { if(asyncLoader.getStatus() == Status.PENDING) {
asyncLoader.execute(LocalIndexesActivity.this); asyncLoader.execute(getDownloadActivity());
} }
} }
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
setProgressBarIndeterminateVisibility(true); getDownloadActivity().setProgressBarIndeterminateVisibility(true);
} }
@Override @Override
protected List<String> doInBackground(Void... params) { protected List<String> doInBackground(Void... params) {
@ -878,12 +877,12 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
View v = convertView; View v = convertView;
final LocalIndexInfo child = (LocalIndexInfo) getChild(groupPosition, childPosition); final LocalIndexInfo child = (LocalIndexInfo) getChild(groupPosition, childPosition);
if (v == null ) { if (v == null ) {
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false);
} }
TextView viewName = ((TextView) v.findViewById(R.id.local_index_name)); TextView viewName = ((TextView) v.findViewById(R.id.local_index_name));
String mapDescr = getMapDescription(child.getFileName()); String mapDescr = getMapDescription(child.getFileName());
String mapName = FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) getApplication()).getResourceManager().getOsmandRegions(), child.getFileName()); String mapName = FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) getDownloadActivity().getApplication()).getResourceManager().getOsmandRegions(), child.getFileName());
if (mapDescr.length() > 0){ if (mapDescr.length() > 0){
viewName.setText(mapDescr + " - " + mapName); viewName.setText(mapDescr + " - " + mapName);
@ -952,10 +951,10 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
View v = convertView; View v = convertView;
LocalIndexInfo group = getGroup(groupPosition); LocalIndexInfo group = getGroup(groupPosition);
if (v == null) { if (v == null) {
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false);
} }
StringBuilder t = new StringBuilder(group.getType().getHumanString(LocalIndexesActivity.this)); StringBuilder t = new StringBuilder(group.getType().getHumanString(getDownloadActivity()));
if(group.getSubfolder() != null) { if(group.getSubfolder() != null) {
t.append(" ").append(group.getSubfolder()); t.append(" ").append(group.getSubfolder());
} }
@ -1036,4 +1035,6 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
return ""; return "";
} }
} }
private DownloadActivity getDownloadActivity(){ return (DownloadActivity)getActivity();}
} }

View file

@ -0,0 +1,125 @@
package net.osmand.plus.download;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by Denis on 09.09.2014.
*/
public class UpdatesIndexFragment extends SherlockListFragment {
private OsmandRegions osmandRegions;
private java.text.DateFormat format;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
format = getMyApplication().getResourceManager().getDateFormat();
osmandRegions = getMyApplication().getResourceManager().getOsmandRegions();
setListAdapter(new UpdateIndexAdapter(getDownloadActivity(), R.layout.download_index_list_item, DownloadActivity.downloadListIndexThread.getItemsToUpdate()));
setHasOptionsMenu(true);
}
@Override
public void onResume() {
super.onResume();
Map<IndexItem, List<DownloadEntry>> map = getDownloadActivity().getEntriesToDownload();
}
public void updateItemsList(List<IndexItem> items){
UpdateIndexAdapter adapter = (UpdateIndexAdapter) getListAdapter();
if (adapter == null){
return;
}
adapter.clear();
for (IndexItem item : items){
adapter.add(item);
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
}
public DownloadActivity getDownloadActivity() { return (DownloadActivity)getActivity(); }
private class UpdateIndexAdapter extends ArrayAdapter<IndexItem>{
List<IndexItem> items;
public UpdateIndexAdapter(Context context, int resource, List<IndexItem> items) {
super(context, resource, items);
this.items = items;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null){
LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.download_index_list_item, null);
}
TextView name = (TextView) v.findViewById(R.id.download_item);
TextView description = (TextView) v.findViewById(R.id.download_descr);
IndexItem e = items.get(position);
String eName = e.getVisibleDescription(getMyApplication()) + "\n" + e.getVisibleName(getMyApplication(), osmandRegions);
name.setText(eName.trim()); //$NON-NLS-1$
String d = e.getDate(format) + "\n" + e.getSizeDescription(getMyApplication());
description.setText(d);
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
ch.setChecked(getDownloadActivity().getEntriesToDownload().containsKey(e));
ch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ch.setChecked(!ch.isChecked());
final IndexItem e = (IndexItem) getListAdapter().getItem(position);
if(ch.isChecked()){
ch.setChecked(!ch.isChecked());
getDownloadActivity().getEntriesToDownload().remove(e);
getDownloadActivity().updateDownloadButton(true);
return;
}
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) {
getDownloadActivity().getEntriesToDownload().put(e, download);
getDownloadActivity().updateDownloadButton(true);
ch.setChecked(!ch.isChecked());
}
}
});
return v;
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
ActionBar actionBar = getDownloadActivity().getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
public OsmandApplication getMyApplication() { return getDownloadActivity().getMyApplication(); }
}

View file

@ -29,13 +29,14 @@ import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.activities.SelectedGPXFragment; import net.osmand.plus.activities.SelectedGPXFragment;
import net.osmand.plus.activities.actions.ShareLocation; import net.osmand.plus.activities.actions.ShareLocation;
import net.osmand.plus.api.FileSettingsAPIImpl; import net.osmand.plus.api.FileSettingsAPIImpl;
import net.osmand.plus.api.SettingsAPI; import net.osmand.plus.api.SettingsAPI;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteCalculationResult;
@ -106,8 +107,8 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
public boolean setAccessCode(String acCode) { public boolean setAccessCode(String acCode) {
acCode = acCode.toUpperCase(); acCode = acCode.toUpperCase();
if(DownloadIndexActivity.downloadListIndexThread != null) { if(DownloadActivity.downloadListIndexThread != null) {
DownloadIndexActivity.downloadListIndexThread.clear(); DownloadActivity.downloadListIndexThread.clear();
} }
if(validate(acCode) || Algorithms.isEmpty(acCode)) { if(validate(acCode) || Algorithms.isEmpty(acCode)) {
accessCodePref.set(acCode); accessCodePref.set(acCode);
@ -181,7 +182,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
} }
public void updatedLoadedFiles(java.util.Map<String,String> indexFileNames, java.util.Map<String,String> indexActivatedFileNames) { public void updatedLoadedFiles(java.util.Map<String,String> indexFileNames, java.util.Map<String,String> indexActivatedFileNames) {
DownloadIndexActivity.listWithAlternatives(app.getResourceManager().getDateFormat(), DownloadIndexFragment.listWithAlternatives(app.getResourceManager().getDateFormat(),
toursFolder, "", indexFileNames); toursFolder, "", indexFileNames);
} }
@ -197,7 +198,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
for(File tr : availableTours) { for(File tr : availableTours) {
if (tr.isDirectory()) { if (tr.isDirectory()) {
String date = app.getResourceManager().getDateFormat() String date = app.getResourceManager().getDateFormat()
.format(new Date(DownloadIndexActivity.findFileInDir(tr).lastModified())); .format(new Date(DownloadIndexFragment.findFileInDir(tr).lastModified()));
indexFileNames.put(tr.getName(), date); indexFileNames.put(tr.getName(), date);
final TourInformation tourInformation = new TourInformation(tr); final TourInformation tourInformation = new TourInformation(tr);
tourPresent.add(tourInformation); tourPresent.add(tourInformation);
@ -228,7 +229,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
} }
this.tourPresent = tourPresent; this.tourPresent = tourPresent;
if(!suggestToDownloadMap.isEmpty()) { if(!suggestToDownloadMap.isEmpty()) {
final DownloadIndexActivity da = app.getDownloadActivity(); final DownloadIndexFragment da = app.getDownloadActivity();
if (da != null) { if (da != null) {
app.runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
@ -626,7 +627,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
return s; return s;
} }
public void preDownloadActivity(final DownloadIndexActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar) { public void preDownloadActivity(final DownloadActivity da, final List<DownloadActivityType> downloadTypes, ActionBar actionBar) {
actionBar.setTitle(TourDownloadType.TOUR.getString(da)); actionBar.setTitle(TourDownloadType.TOUR.getString(da));
} }

View file

@ -5,7 +5,7 @@ import java.util.WeakHashMap;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.sherpafy.TourInformation.StageFavorite; import net.osmand.plus.sherpafy.TourInformation.StageFavorite;
import net.osmand.plus.sherpafy.TourInformation.StageInformation; import net.osmand.plus.sherpafy.TourInformation.StageInformation;
import android.content.Intent; import android.content.Intent;
@ -376,7 +376,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
public void startDownloadActivity() { public void startDownloadActivity() {
final Intent download = new Intent(this, DownloadIndexActivity.class); final Intent download = new Intent(this, DownloadIndexFragment.class);
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
refreshListAfterDownload = true; refreshListAfterDownload = true;
startActivity(download); startActivity(download);

View file

@ -12,7 +12,8 @@ import net.osmand.binary.BinaryMapDataObject;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -87,7 +88,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final Intent intent = new Intent(view.getContext(), view.getApplication().getAppCustomization().getDownloadIndexActivity()); final Intent intent = new Intent(view.getContext(), view.getApplication().getAppCustomization().getDownloadIndexActivity());
intent.putExtra(DownloadIndexActivity.FILTER_KEY, filter.toString()); intent.putExtra(DownloadActivity.FILTER_KEY, filter.toString());
view.getContext().startActivity(intent); view.getContext().startActivity(intent);
} }
}); });