Updated to fix of 119 bug in Jira
This commit is contained in:
parent
18e88f9e1f
commit
fc508f4ce5
1 changed files with 141 additions and 135 deletions
|
@ -80,7 +80,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
private GpxSelectionHelper selectedGpxHelper;
|
private GpxSelectionHelper selectedGpxHelper;
|
||||||
private SavingTrackHelper savingTrackHelper;
|
private SavingTrackHelper savingTrackHelper;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
|
@ -94,11 +94,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
listAdapter = new GpxIndexesAdapter(getActivity());
|
listAdapter = new GpxIndexesAdapter(getActivity());
|
||||||
setAdapter(listAdapter);
|
setAdapter(listAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GpxInfo> getSelectedItems() {
|
public List<GpxInfo> getSelectedItems() {
|
||||||
return selectedItems;
|
return selectedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View vs = super.onCreateView(inflater, container, savedInstanceState);
|
View vs = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
@ -115,6 +115,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
});
|
});
|
||||||
return vs;
|
return vs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -123,11 +124,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
asyncLoader.execute(getActivity());
|
asyncLoader.execute(getActivity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if(operationTask != null){
|
if (operationTask != null) {
|
||||||
operationTask.cancel(true);
|
operationTask.cancel(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +178,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
optionsMenuAdapter.item(R.string.show_gpx_route)
|
optionsMenuAdapter.item(R.string.show_gpx_route)
|
||||||
.icons(R.drawable.ic_action_map_marker_dark, R.drawable.ic_action_map_marker_light).listen(listener).reg();
|
.icons(R.drawable.ic_action_map_marker_dark, R.drawable.ic_action_map_marker_light).listen(listener).reg();
|
||||||
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).listen(listener).reg();
|
.icons(R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_light).listen(listener).reg();
|
||||||
optionsMenuAdapter.item(R.string.local_index_mi_reload)
|
optionsMenuAdapter.item(R.string.local_index_mi_reload)
|
||||||
|
@ -185,28 +186,28 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
OsmandPlugin.onOptionsMenuActivity(getSherlockActivity(), this, optionsMenuAdapter);
|
OsmandPlugin.onOptionsMenuActivity(getSherlockActivity(), this, optionsMenuAdapter);
|
||||||
for (int j = 0; j < optionsMenuAdapter.length(); j++) {
|
for (int j = 0; j < optionsMenuAdapter.length(); j++) {
|
||||||
MenuItem item;
|
MenuItem item;
|
||||||
item = menu.add(0, optionsMenuAdapter.getItemId(j), j + 1, optionsMenuAdapter.getItemName(j));
|
item = menu.add(0, optionsMenuAdapter.getItemId(j), j + 1, optionsMenuAdapter.getItemName(j));
|
||||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
|
||||||
);
|
);
|
||||||
if (optionsMenuAdapter.getImageId(j, isLightActionBar()) != 0) {
|
if (optionsMenuAdapter.getImageId(j, isLightActionBar()) != 0) {
|
||||||
item.setIcon(optionsMenuAdapter.getImageId(j, isLightActionBar()));
|
item.setIcon(optionsMenuAdapter.getImageId(j, isLightActionBar()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doAction(int actionResId){
|
public void doAction(int actionResId) {
|
||||||
if(actionResId == R.string.local_index_mi_delete){
|
if (actionResId == R.string.local_index_mi_delete) {
|
||||||
operationTask = new DeleteGpxTask();
|
operationTask = new DeleteGpxTask();
|
||||||
operationTask.execute(selectedItems.toArray(new GpxInfo[selectedItems.size()]));
|
operationTask.execute(selectedItems.toArray(new GpxInfo[selectedItems.size()]));
|
||||||
} else {
|
} else {
|
||||||
operationTask = null;
|
operationTask = null;
|
||||||
}
|
}
|
||||||
if(actionMode != null) {
|
if (actionMode != null) {
|
||||||
actionMode.finish();
|
actionMode.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int itemId = item.getItemId();
|
int itemId = item.getItemId();
|
||||||
|
@ -226,16 +227,16 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
public void hideProgressBar() {
|
public void hideProgressBar() {
|
||||||
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
|
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSelectionMode(ActionMode m) {
|
private void updateSelectionMode(ActionMode m) {
|
||||||
if(selectedItems.size() > 0) {
|
if (selectedItems.size() > 0) {
|
||||||
m.setTitle(selectedItems.size() + " " + app.getString(R.string.selected));
|
m.setTitle(selectedItems.size() + " " + app.getString(R.string.selected));
|
||||||
} else{
|
} else {
|
||||||
m.setTitle("");
|
m.setTitle("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openShowOnMapMode(){
|
private void openShowOnMapMode() {
|
||||||
selectionMode = true;
|
selectionMode = true;
|
||||||
selectedItems.clear();
|
selectedItems.clear();
|
||||||
final Set<GpxInfo> originalSelectedItems = listAdapter.getSelectedGpx();
|
final Set<GpxInfo> originalSelectedItems = listAdapter.getSelectedGpx();
|
||||||
|
@ -247,13 +248,12 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
selectionMode = true;
|
selectionMode = true;
|
||||||
updateSelectionMode(mode);
|
updateSelectionMode(mode);
|
||||||
MenuItem it = menu.add(R.string.show_gpx_route);
|
MenuItem it = menu.add(R.string.show_gpx_route);
|
||||||
it.setIcon(!isLightActionBar() ? R.drawable.ic_action_map_marker_dark : R.drawable.ic_action_map_marker_light);
|
it.setIcon(!isLightActionBar() ? R.drawable.ic_action_map_marker_dark : R.drawable.ic_action_map_marker_light);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||||
|
@ -283,25 +283,25 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
runSelection(false);
|
runSelection(false);
|
||||||
listAdapter.notifyDataSetChanged();
|
listAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
listAdapter.notifyDataSetChanged();
|
listAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon,
|
|
||||||
final DialogInterface.OnClickListener listener){
|
public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon,
|
||||||
|
final DialogInterface.OnClickListener listener) {
|
||||||
final int actionIconId = !isLightActionBar() ? darkIcon : lightIcon;
|
final int actionIconId = !isLightActionBar() ? darkIcon : lightIcon;
|
||||||
String value = app.getString(actionResId);
|
String value = app.getString(actionResId);
|
||||||
if (value.endsWith("...")) {
|
if (value.endsWith("...")) {
|
||||||
value = value.substring(0, value.length() - 3);
|
value = value.substring(0, value.length() - 3);
|
||||||
}
|
}
|
||||||
final String actionButton = value;
|
final String actionButton = value;
|
||||||
if(listAdapter.getGroupCount() == 0){
|
if (listAdapter.getGroupCount() == 0) {
|
||||||
AccessibleToast.makeText(getActivity(), app.getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
|
AccessibleToast.makeText(getActivity(), app.getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectionMode = true;
|
selectionMode = true;
|
||||||
selectedItems.clear();
|
selectedItems.clear();
|
||||||
actionMode = getSherlockActivity().startActionMode(new Callback() {
|
actionMode = getSherlockActivity().startActionMode(new Callback() {
|
||||||
|
@ -310,10 +310,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -345,26 +345,26 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
getView().findViewById(R.id.DescriptionText).setVisibility(View.GONE);
|
getView().findViewById(R.id.DescriptionText).setVisibility(View.GONE);
|
||||||
listAdapter.notifyDataSetChanged();
|
listAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(R.string.local_index_mi_upload_gpx == actionResId){
|
if (R.string.local_index_mi_upload_gpx == actionResId) {
|
||||||
((TextView) getView().findViewById(R.id.DescriptionText)).setText(R.string.local_index_upload_gpx_description);
|
((TextView) getView().findViewById(R.id.DescriptionText)).setText(R.string.local_index_upload_gpx_description);
|
||||||
((TextView) getView().findViewById(R.id.DescriptionText)).setVisibility(View.VISIBLE);
|
((TextView) getView().findViewById(R.id.DescriptionText)).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
listAdapter.notifyDataSetChanged();
|
listAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renameFile(GpxInfo info) {
|
private void renameFile(GpxInfo info) {
|
||||||
final File f = info.file;
|
final File f = info.file;
|
||||||
Builder b = new AlertDialog.Builder(getActivity());
|
Builder b = new AlertDialog.Builder(getActivity());
|
||||||
if(f.exists()){
|
if (f.exists()) {
|
||||||
final EditText editText = new EditText(getActivity());
|
final EditText editText = new EditText(getActivity());
|
||||||
editText.setPadding(7, 3, 7, 3);
|
editText.setPadding(7, 3, 7, 3);
|
||||||
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() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
String newName = editText.getText().toString();
|
String newName = editText.getText().toString();
|
||||||
|
@ -372,24 +372,24 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
if (dest.exists()) {
|
if (dest.exists()) {
|
||||||
AccessibleToast.makeText(getActivity(), R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
|
AccessibleToast.makeText(getActivity(), 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();
|
||||||
}
|
}
|
||||||
if(f.renameTo(dest)){
|
if (f.renameTo(dest)) {
|
||||||
asyncLoader = new LoadGpxTask();
|
asyncLoader = new LoadGpxTask();
|
||||||
asyncLoader.execute(getActivity());
|
asyncLoader.execute(getActivity());
|
||||||
} else {
|
} else {
|
||||||
AccessibleToast.makeText(getActivity(), R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
|
AccessibleToast.makeText(getActivity(), R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
b.setNegativeButton(R.string.default_buttons_cancel, null);
|
b.setNegativeButton(R.string.default_buttons_cancel, null);
|
||||||
b.show();
|
b.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void basicFileOperation(final GpxInfo info, ContextMenuAdapter adapter) {
|
private void basicFileOperation(final GpxInfo info, ContextMenuAdapter adapter) {
|
||||||
OnContextMenuClick listener = new OnContextMenuClick() {
|
OnContextMenuClick listener = new OnContextMenuClick() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -406,7 +406,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
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) {
|
||||||
new DeleteGpxTask().execute(info);
|
new DeleteGpxTask().execute(info);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
confirm.setNegativeButton(R.string.default_buttons_no, null);
|
confirm.setNegativeButton(R.string.default_buttons_no, null);
|
||||||
|
@ -437,12 +437,21 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if(info.gpx != null && info.file != null){
|
if (info.gpx != null) {
|
||||||
if(getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(info.file.getAbsolutePath()) == null) {
|
if (info.file == null){
|
||||||
adapter.item(R.string.local_index_select_gpx_file).listen(listener).reg();
|
GpxSelectionHelper.SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedCurrentRecordingTrack();
|
||||||
} else {
|
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() == info.gpx){
|
||||||
adapter.item(R.string.local_index_unselect_gpx_file).listen(listener).reg();
|
adapter.item(R.string.local_index_unselect_gpx_file).listen(listener).reg();
|
||||||
}
|
} else {
|
||||||
|
adapter.item(R.string.local_index_select_gpx_file).listen(listener).reg();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(info.file.getAbsolutePath()) == null) {
|
||||||
|
adapter.item(R.string.local_index_select_gpx_file).listen(listener).reg();
|
||||||
|
} else {
|
||||||
|
adapter.item(R.string.local_index_unselect_gpx_file).listen(listener).reg();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
adapter.item(R.string.show_gpx_route).listen(listener).reg();
|
adapter.item(R.string.show_gpx_route).listen(listener).reg();
|
||||||
if (info.file != null) {
|
if (info.file != null) {
|
||||||
|
@ -452,7 +461,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
OsmandPlugin.onContextMenuActivity(getSherlockActivity(), this, info, adapter);
|
OsmandPlugin.onContextMenuActivity(getSherlockActivity(), this, info, adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showContextMenu(final GpxInfo info) {
|
private void showContextMenu(final GpxInfo info) {
|
||||||
Builder builder = new AlertDialog.Builder(getActivity());
|
Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
final ContextMenuAdapter adapter = new ContextMenuAdapter(getActivity());
|
final ContextMenuAdapter adapter = new ContextMenuAdapter(getActivity());
|
||||||
|
@ -471,8 +480,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
});
|
});
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class LoadGpxTask extends AsyncTask<Activity, GpxInfo, List<GpxInfo>> {
|
public class LoadGpxTask extends AsyncTask<Activity, GpxInfo, List<GpxInfo>> {
|
||||||
|
|
||||||
private List<GpxInfo> result;
|
private List<GpxInfo> result;
|
||||||
|
@ -480,11 +489,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
@Override
|
@Override
|
||||||
protected List<GpxInfo> doInBackground(Activity... params) {
|
protected List<GpxInfo> doInBackground(Activity... params) {
|
||||||
List<GpxInfo> result = new ArrayList<GpxInfo>();
|
List<GpxInfo> result = new ArrayList<GpxInfo>();
|
||||||
if(!savingTrackHelper.getCurrentGpx().isEmpty()) {
|
if (!savingTrackHelper.getCurrentGpx().isEmpty()) {
|
||||||
loadFile(new GpxInfo(savingTrackHelper.getCurrentGpx(),
|
loadFile(new GpxInfo(savingTrackHelper.getCurrentGpx(),
|
||||||
app.getString(R.string.gpx_available_current_track)));
|
app.getString(R.string.gpx_available_current_track)));
|
||||||
}
|
}
|
||||||
loadGPXData(app.getAppPath(IndexConstants.GPX_INDEX_DIR), result, this);
|
loadGPXData(app.getAppPath(IndexConstants.GPX_INDEX_DIR), result, this);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +506,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(true);
|
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(true);
|
||||||
listAdapter.clear();
|
listAdapter.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onProgressUpdate(GpxInfo... values) {
|
protected void onProgressUpdate(GpxInfo... values) {
|
||||||
for (GpxInfo v : values) {
|
for (GpxInfo v : values) {
|
||||||
|
@ -505,11 +514,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
listAdapter.notifyDataSetChanged();
|
listAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setResult(List<GpxInfo> result) {
|
public void setResult(List<GpxInfo> result) {
|
||||||
this.result = result;
|
this.result = result;
|
||||||
listAdapter.clear();
|
listAdapter.clear();
|
||||||
if(result != null){
|
if (result != null) {
|
||||||
for (GpxInfo v : result) {
|
for (GpxInfo v : result) {
|
||||||
listAdapter.addLocalIndexInfo(v);
|
listAdapter.addLocalIndexInfo(v);
|
||||||
}
|
}
|
||||||
|
@ -523,16 +532,16 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
this.result = result;
|
this.result = result;
|
||||||
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
|
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File[] listFilesSorted(File dir){
|
private File[] listFilesSorted(File dir) {
|
||||||
File[] listFiles = dir.listFiles();
|
File[] listFiles = dir.listFiles();
|
||||||
if(listFiles == null) {
|
if (listFiles == null) {
|
||||||
return new File[0];
|
return new File[0];
|
||||||
}
|
}
|
||||||
Arrays.sort(listFiles);
|
Arrays.sort(listFiles);
|
||||||
return listFiles;
|
return listFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadGPXData(File mapPath, List<GpxInfo> result, LoadGpxTask loadTask) {
|
private void loadGPXData(File mapPath, List<GpxInfo> result, LoadGpxTask loadTask) {
|
||||||
if (mapPath.canRead()) {
|
if (mapPath.canRead()) {
|
||||||
List<GpxInfo> progress = new ArrayList<GpxInfo>();
|
List<GpxInfo> progress = new ArrayList<GpxInfo>();
|
||||||
|
@ -544,7 +553,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadGPXFolder(File mapPath, List<GpxInfo> result, LoadGpxTask loadTask,
|
private void loadGPXFolder(File mapPath, List<GpxInfo> result, LoadGpxTask loadTask,
|
||||||
List<GpxInfo> progress, String gpxSubfolder) {
|
List<GpxInfo> progress, String gpxSubfolder) {
|
||||||
for (File gpxFile : listFilesSorted(mapPath)) {
|
for (File gpxFile : listFilesSorted(mapPath)) {
|
||||||
if (gpxFile.isDirectory()) {
|
if (gpxFile.isDirectory()) {
|
||||||
String sub = gpxSubfolder.length() == 0 ? gpxFile.getName() : gpxSubfolder + "/" + gpxFile.getName();
|
String sub = gpxSubfolder.length() == 0 ? gpxFile.getName() : gpxSubfolder + "/" + gpxFile.getName();
|
||||||
|
@ -563,18 +572,16 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GpxInfo> getResult() {
|
public List<GpxInfo> getResult() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected class GpxIndexesAdapter extends OsmandBaseExpandableListAdapter implements Filterable {
|
protected class GpxIndexesAdapter extends OsmandBaseExpandableListAdapter implements Filterable {
|
||||||
|
|
||||||
Map<String, List<GpxInfo>> data = new LinkedHashMap<String, List<GpxInfo>>();
|
Map<String, List<GpxInfo>> data = new LinkedHashMap<String, List<GpxInfo>>();
|
||||||
List<String> category = new ArrayList<String>();
|
List<String> category = new ArrayList<String>();
|
||||||
int warningColor;
|
int warningColor;
|
||||||
|
@ -582,7 +589,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
int defaultColor;
|
int defaultColor;
|
||||||
int corruptedColor;
|
int corruptedColor;
|
||||||
private SearchFilter filter;
|
private SearchFilter filter;
|
||||||
|
|
||||||
|
|
||||||
public GpxIndexesAdapter(Context ctx) {
|
public GpxIndexesAdapter(Context ctx) {
|
||||||
warningColor = ctx.getResources().getColor(R.color.color_warning);
|
warningColor = ctx.getResources().getColor(R.color.color_warning);
|
||||||
|
@ -591,7 +598,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
defaultColor = ta.getColor(0, ctx.getResources().getColor(R.color.color_unknown));
|
defaultColor = ta.getColor(0, ctx.getResources().getColor(R.color.color_unknown));
|
||||||
ta.recycle();
|
ta.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<GpxInfo> getSelectedGpx() {
|
public Set<GpxInfo> getSelectedGpx() {
|
||||||
Set<GpxInfo> originalSelectedItems = new HashSet<GpxInfo>();
|
Set<GpxInfo> originalSelectedItems = new HashSet<GpxInfo>();
|
||||||
for (List<GpxInfo> l : data.values()) {
|
for (List<GpxInfo> l : data.values()) {
|
||||||
|
@ -611,7 +618,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
return originalSelectedItems;
|
return originalSelectedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
data.clear();
|
data.clear();
|
||||||
category.clear();
|
category.clear();
|
||||||
|
@ -620,7 +627,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
|
|
||||||
public void addLocalIndexInfo(GpxInfo info) {
|
public void addLocalIndexInfo(GpxInfo info) {
|
||||||
String catName;
|
String catName;
|
||||||
if(info.gpx != null && info.gpx.showCurrentTrack) {
|
if (info.gpx != null && info.gpx.showCurrentTrack) {
|
||||||
catName = info.name;
|
catName = info.name;
|
||||||
} else {
|
} else {
|
||||||
catName = app.getString(R.string.local_indexes_cat_gpx) + " " + info.subfolder;
|
catName = app.getString(R.string.local_indexes_cat_gpx) + " " + info.subfolder;
|
||||||
|
@ -660,17 +667,17 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
|
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
|
||||||
View v = convertView;
|
View v = convertView;
|
||||||
final GpxInfo child = (GpxInfo) getChild(groupPosition, childPosition);
|
final GpxInfo child = (GpxInfo) getChild(groupPosition, childPosition);
|
||||||
if (v == null ) {
|
if (v == null) {
|
||||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
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));
|
||||||
viewName.setText(child.getName());
|
viewName.setText(child.getName());
|
||||||
|
|
||||||
if (child.isCorrupted()) {
|
if (child.isCorrupted()) {
|
||||||
viewName.setTextColor(corruptedColor);
|
viewName.setTextColor(corruptedColor);
|
||||||
viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
|
viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
|
||||||
} else if(selectedGpxHelper.getSelectedFileByName(child.getFileName()) != null){
|
} else if (selectedGpxHelper.getSelectedFileByName(child.getFileName()) != null) {
|
||||||
viewName.setTextColor(okColor);
|
viewName.setTextColor(okColor);
|
||||||
viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
|
viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
|
||||||
} else {
|
} else {
|
||||||
|
@ -680,7 +687,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
if (child.getSize() >= 0) {
|
if (child.getSize() >= 0) {
|
||||||
String size;
|
String size;
|
||||||
if (child.getSize() > 100) {
|
if (child.getSize() > 100) {
|
||||||
size = formatMb.format(new Object[] { (float) child.getSize() / (1 << 10) });
|
size = formatMb.format(new Object[]{(float) child.getSize() / (1 << 10)});
|
||||||
} else {
|
} else {
|
||||||
size = child.getSize() + " kB";
|
size = child.getSize() + " kB";
|
||||||
}
|
}
|
||||||
|
@ -700,11 +707,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
if (selectionMode) {
|
if (selectionMode) {
|
||||||
checkbox.setChecked(selectedItems.contains(child));
|
checkbox.setChecked(selectedItems.contains(child));
|
||||||
checkbox.setOnClickListener(new View.OnClickListener() {
|
checkbox.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if(checkbox.isChecked()){
|
if (checkbox.isChecked()) {
|
||||||
selectedItems.add(child);
|
selectedItems.add(child);
|
||||||
} else {
|
} else {
|
||||||
selectedItems.remove(child);
|
selectedItems.remove(child);
|
||||||
|
@ -713,7 +720,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -757,7 +764,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGroup(int groupPosition) {
|
public String getGroup(int groupPosition) {
|
||||||
return category.get(groupPosition) ;
|
return category.get(groupPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -782,7 +789,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Filter getFilter() {
|
public Filter getFilter() {
|
||||||
if(filter == null) {
|
if (filter == null) {
|
||||||
filter = new SearchFilter();
|
filter = new SearchFilter();
|
||||||
}
|
}
|
||||||
return filter;
|
return filter;
|
||||||
|
@ -798,12 +805,12 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(found != -1) {
|
if (found != -1) {
|
||||||
data.get(category.get(found)).remove(g);
|
data.get(category.get(found)).remove(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LoadLocalIndexDescriptionTask extends AsyncTask<GpxInfo, GpxInfo, GpxInfo[]> {
|
public class LoadLocalIndexDescriptionTask extends AsyncTask<GpxInfo, GpxInfo, GpxInfo[]> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -828,13 +835,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
protected void onPostExecute(GpxInfo[] result) {
|
protected void onPostExecute(GpxInfo[] result) {
|
||||||
hideProgressBar();
|
hideProgressBar();
|
||||||
listAdapter.notifyDataSetChanged();
|
listAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeleteGpxTask extends AsyncTask<GpxInfo, GpxInfo, String> {
|
public class DeleteGpxTask extends AsyncTask<GpxInfo, GpxInfo, String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(GpxInfo... params) {
|
protected String doInBackground(GpxInfo... params) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -856,12 +863,12 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onProgressUpdate(GpxInfo... values) {
|
protected void onProgressUpdate(GpxInfo... values) {
|
||||||
for(GpxInfo g : values) {
|
for (GpxInfo g : values) {
|
||||||
listAdapter.delete(g);
|
listAdapter.delete(g);
|
||||||
}
|
}
|
||||||
listAdapter.notifyDataSetChanged();
|
listAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
getSherlockActivity().setProgressBarIndeterminateVisibility(true);
|
getSherlockActivity().setProgressBarIndeterminateVisibility(true);
|
||||||
|
@ -873,9 +880,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
AccessibleToast.makeText(getSherlockActivity(), result, Toast.LENGTH_LONG).show();
|
AccessibleToast.makeText(getSherlockActivity(), result, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SelectGpxTask extends AsyncTask<GpxInfo, GpxInfo, String> {
|
public class SelectGpxTask extends AsyncTask<GpxInfo, GpxInfo, String> {
|
||||||
|
|
||||||
private boolean showOnMap;
|
private boolean showOnMap;
|
||||||
private WptPt toShow;
|
private WptPt toShow;
|
||||||
|
|
||||||
|
@ -898,16 +905,16 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onProgressUpdate(GpxInfo... values) {
|
protected void onProgressUpdate(GpxInfo... values) {
|
||||||
for(GpxInfo g : values) {
|
for (GpxInfo g : values) {
|
||||||
final boolean visible = selectedItems.contains(g);
|
final boolean visible = selectedItems.contains(g);
|
||||||
selectedGpxHelper.selectGpxFile(g.gpx, visible, false);
|
selectedGpxHelper.selectGpxFile(g.gpx, visible, false);
|
||||||
if(visible && toShow == null) {
|
if (visible && toShow == null) {
|
||||||
toShow = g.gpx.findPointToShow();
|
toShow = g.gpx.findPointToShow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
listAdapter.notifyDataSetInvalidated();
|
listAdapter.notifyDataSetInvalidated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
getSherlockActivity().setProgressBarIndeterminateVisibility(true);
|
getSherlockActivity().setProgressBarIndeterminateVisibility(true);
|
||||||
|
@ -917,7 +924,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
protected void onPostExecute(String result) {
|
protected void onPostExecute(String result) {
|
||||||
selectedGpxHelper.runUiListeners();
|
selectedGpxHelper.runUiListeners();
|
||||||
getSherlockActivity().setProgressBarIndeterminateVisibility(false);
|
getSherlockActivity().setProgressBarIndeterminateVisibility(false);
|
||||||
if(showOnMap && toShow != null) {
|
if (showOnMap && toShow != null) {
|
||||||
getMyApplication().getSettings().setMapLocationToShow(toShow.lat, toShow.lon,
|
getMyApplication().getSettings().setMapLocationToShow(toShow.lat, toShow.lon,
|
||||||
getMyApplication().getSettings().getLastKnownMapZoom());
|
getMyApplication().getSettings().getLastKnownMapZoom());
|
||||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||||
|
@ -938,8 +945,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
} else {
|
} else {
|
||||||
String cs = constraint.toString().toLowerCase();
|
String cs = constraint.toString().toLowerCase();
|
||||||
List<GpxInfo> res = new ArrayList<GpxInfo>();
|
List<GpxInfo> res = new ArrayList<GpxInfo>();
|
||||||
for(GpxInfo r : raw) {
|
for (GpxInfo r : raw) {
|
||||||
if(r.getName().toLowerCase().indexOf(cs) != -1) {
|
if (r.getName().toLowerCase().indexOf(cs) != -1) {
|
||||||
res.add(r);
|
res.add(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -967,14 +974,14 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if(descriptionLoader != null) {
|
if (descriptionLoader != null) {
|
||||||
descriptionLoader.cancel(true);
|
descriptionLoader.cancel(true);
|
||||||
}
|
}
|
||||||
if(asyncLoader != null) {
|
if (asyncLoader != null) {
|
||||||
asyncLoader.cancel(true);
|
asyncLoader.cancel(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1000,35 +1007,35 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class GpxInfo {
|
public static class GpxInfo {
|
||||||
public GPXFile gpx;
|
public GPXFile gpx;
|
||||||
public File file;
|
public File file;
|
||||||
public String subfolder;
|
public String subfolder;
|
||||||
|
|
||||||
private String name = null;
|
private String name = null;
|
||||||
private int sz = -1;
|
private int sz = -1;
|
||||||
private String fileName = null;
|
private String fileName = null;
|
||||||
private String description;
|
private String description;
|
||||||
private boolean corrupted;
|
private boolean corrupted;
|
||||||
private boolean expanded;
|
private boolean expanded;
|
||||||
private Spanned htmlDescription;
|
private Spanned htmlDescription;
|
||||||
|
|
||||||
public GpxInfo(){
|
public GpxInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public GpxInfo(GPXFile file, String name) {
|
public GpxInfo(GPXFile file, String name) {
|
||||||
this.gpx = file;
|
this.gpx = file;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if(name == null) {
|
if (name == null) {
|
||||||
name = formatName(file.getName());
|
name = formatName(file.getName());
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatName(String name) {
|
private String formatName(String name) {
|
||||||
int ext = name.lastIndexOf('.');
|
int ext = name.lastIndexOf('.');
|
||||||
if (ext != -1) {
|
if (ext != -1) {
|
||||||
|
@ -1036,74 +1043,73 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
}
|
}
|
||||||
return name.replace('_', ' ');
|
return name.replace('_', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCorrupted() {
|
public boolean isCorrupted() {
|
||||||
return corrupted;
|
return corrupted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
if(sz == -1) {
|
if (sz == -1) {
|
||||||
if(file == null) {
|
if (file == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sz = (int) (file.length() >> 10);
|
sz = (int) (file.length() >> 10);
|
||||||
}
|
}
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpanded() {
|
public boolean isExpanded() {
|
||||||
return expanded;
|
return expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExpanded(boolean expanded) {
|
public void setExpanded(boolean expanded) {
|
||||||
this.expanded = expanded;
|
this.expanded = expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence getDescription() {
|
public CharSequence getDescription() {
|
||||||
if(description == null) {
|
if (description == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Spanned getHtmlDescription() {
|
public Spanned getHtmlDescription() {
|
||||||
if(htmlDescription != null) {
|
if (htmlDescription != null) {
|
||||||
return htmlDescription;
|
return htmlDescription;
|
||||||
}
|
}
|
||||||
htmlDescription = Html.fromHtml(getDescription().toString().replace("\n", "<br/>"));
|
htmlDescription = Html.fromHtml(getDescription().toString().replace("\n", "<br/>"));
|
||||||
return htmlDescription;
|
return htmlDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setGpx(GPXFile gpx) {
|
public void setGpx(GPXFile gpx) {
|
||||||
this.gpx = gpx;
|
this.gpx = gpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateGpxInfo(OsmandApplication app ) {
|
public void updateGpxInfo(OsmandApplication app) {
|
||||||
if(gpx == null){
|
if (gpx == null) {
|
||||||
gpx = GPXUtilities.loadGPXFile(app, file);
|
gpx = GPXUtilities.loadGPXFile(app, file);
|
||||||
}
|
}
|
||||||
if(gpx.warning != null){
|
if (gpx.warning != null) {
|
||||||
corrupted = true;
|
corrupted = true;
|
||||||
description = gpx.warning;
|
description = gpx.warning;
|
||||||
} else {
|
} else {
|
||||||
// 'Long-press for options' message
|
// 'Long-press for options' message
|
||||||
description = GpxUiHelper.getDescription(app, gpx, file, true) +
|
description = GpxUiHelper.getDescription(app, gpx, file, true) +
|
||||||
app.getString(R.string.local_index_gpx_info_show);
|
app.getString(R.string.local_index_gpx_info_show);
|
||||||
}
|
}
|
||||||
htmlDescription = null;
|
htmlDescription = null;
|
||||||
getHtmlDescription();
|
getHtmlDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
if(fileName != null) {
|
if (fileName != null) {
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
if(file == null) {
|
if (file == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return fileName = file.getName();
|
return fileName = file.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue