Fix issues

This commit is contained in:
Victor Shcherb 2014-06-09 16:16:13 +02:00
parent e2406d4ea4
commit 7b7de23c81
4 changed files with 53 additions and 42 deletions

View file

@ -16,8 +16,8 @@ public class OsmAndFormatter {
public final static float METERS_IN_ONE_MILE = 1609.344f; // 1609.344
public final static float YARDS_IN_ONE_METER = 1.0936f;
public final static float FOOTS_IN_ONE_METER = YARDS_IN_ONE_METER * 3f;
private static final DecimalFormat fixed2 = new DecimalFormat("#.00");
private static final DecimalFormat fixed1 = new DecimalFormat("#.0");
private static final DecimalFormat fixed2 = new DecimalFormat("0.00");
private static final DecimalFormat fixed1 = new DecimalFormat("0.0");
{
fixed2.setMinimumFractionDigits(2);
fixed1.setMinimumFractionDigits(1);

View file

@ -632,8 +632,9 @@ public class OsmandSettings {
public final OsmandPreference<DrivingRegion> DRIVING_REGION = new EnumIntPreference<DrivingRegion>(
"default_driving_region", DrivingRegion.EUROPE_ASIA, DrivingRegion.values()) {
protected boolean setValue(Object prefs, DrivingRegion val) {
//((CommonPreference<MetricsConstants>)METRIC_SYSTEM).cachedValue = null;
((CommonPreference<MetricsConstants>)METRIC_SYSTEM).set(DRIVING_REGION.get().defMetrics);
if(val != null) {
((CommonPreference<MetricsConstants>)METRIC_SYSTEM).set(val.defMetrics);
}
return super.setValue(prefs, val);
};
}.makeGlobal().cache();

View file

@ -79,11 +79,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
private AsyncTask<GpxInfo, ?, ?> operationTask;
private GpxSelectionHelper selectedGpxHelper;
private SavingTrackHelper savingTrackHelper;
private OsmandApplication app;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.app = (OsmandApplication) getActivity().getApplication();
final Collator collator = Collator.getInstance();
collator.setStrength(Collator.SECONDARY);
asyncLoader = new LoadGpxTask();
@ -93,10 +95,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
setAdapter(listAdapter);
}
public OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
public List<GpxInfo> getSelectedItems() {
return selectedItems;
}
@ -231,7 +229,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
private void updateSelectionMode(ActionMode m) {
if(selectedItems.size() > 0) {
m.setTitle(selectedItems.size() + " " + getString(R.string.selected));
m.setTitle(selectedItems.size() + " " + app.getString(R.string.selected));
} else{
m.setTitle("");
}
@ -294,13 +292,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon,
final DialogInterface.OnClickListener listener){
final int actionIconId = !isLightActionBar() ? darkIcon : lightIcon;
String value = getString(actionResId);
String value = app.getString(actionResId);
if (value.endsWith("...")) {
value = value.substring(0, value.length() - 3);
}
final String actionButton = value;
if(listAdapter.getGroupCount() == 0){
AccessibleToast.makeText(getActivity(), 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;
}
@ -329,7 +327,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (selectedItems.isEmpty()) {
AccessibleToast.makeText(getActivity(),
getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
app.getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
return true;
}
@ -471,9 +469,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
List<GpxInfo> result = new ArrayList<GpxInfo>();
if(!savingTrackHelper.getCurrentGpx().isEmpty()) {
loadFile(new GpxInfo(savingTrackHelper.getCurrentGpx(),
getMyApplication().getString(R.string.gpx_available_current_track)));
app.getString(R.string.gpx_available_current_track)));
}
loadGPXData(getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR), result, this);
loadGPXData(app.getAppPath(IndexConstants.GPX_INDEX_DIR), result, this);
return result;
}
@ -611,7 +609,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
if(info.gpx != null && info.gpx.showCurrentTrack) {
catName = info.name;
} else {
catName = getString(R.string.local_indexes_cat_gpx) + " " + info.subfolder;
catName = app.getString(R.string.local_indexes_cat_gpx) + " " + info.subfolder;
}
int found = -1;
// search from end
@ -838,7 +836,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
}
}
}
return getString(R.string.local_index_items_deleted, count, total);
return app.getString(R.string.local_index_items_deleted, count, total);
}

View file

@ -128,7 +128,7 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
timeSplit.add(-1);
addOptionSplit(30, true, options, distanceSplit, timeSplit, checkedItem, model); // 100 feet, 50 yards, 50 m
addOptionSplit(60, true, options, distanceSplit, timeSplit, checkedItem, model); // 200 feet, 100 yards, 100 m
addOptionSplit(180, true, options, distanceSplit, timeSplit, checkedItem, model); // 500 feet, 200 yards, 200 m
addOptionSplit(150, true, options, distanceSplit, timeSplit, checkedItem, model); // 500 feet, 200 yards, 200 m
addOptionSplit(300, true, options, distanceSplit, timeSplit, checkedItem, model); // 1000 feet, 500 yards, 500 m
addOptionSplit(600, true, options, distanceSplit, timeSplit, checkedItem, model); // 2000 feet, 1000 yards, 1km
addOptionSplit(1500, true, options, distanceSplit, timeSplit, checkedItem, model); // 1mi, 2km
@ -212,9 +212,9 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
Filter myFilter;
private List<GpxDisplayGroup> displayGroups = new ArrayList<GpxDisplayGroup>();
private ExpandableListView expandableListView;
private boolean manualScroll;
private boolean groupScroll = true;
private int maxNumberOfSections = 1;
private double positionsInGroup;
private double itemsInSection;
public SelectedGPXAdapter(ExpandableListView lv) {
this.expandableListView = lv;
@ -224,7 +224,7 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
this.manualScroll = scrollState == SCROLL_STATE_TOUCH_SCROLL;
// this.manualScroll = scrollState == SCROLL_STATE_TOUCH_SCROLL;
}
@Override
@ -235,12 +235,11 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
@Override
public int getPositionForSection(int section) {
if (manualScroll) {
return section;
if(groupScroll) {
return expandableListView.getFlatListPosition(
ExpandableListView.getPackedPositionForGroup(section));
} else {
// return expandableListView.getFlatListPosition(
// ExpandableListView.getPackedPositionForGroup(section));
return (int) (section * positionsInGroup);
return (int) (section * itemsInSection);
}
}
@ -248,12 +247,24 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
@Override
public int getSectionForPosition(int position) {
// Get the packed position of the provided flat one and find the corresponding group
// return ExpandableListView.getPackedPositionChild(expandableListView
// .getExpandableListPosition(position));
return Math.min(maxNumberOfSections - 1, (int) (position / positionsInGroup));
if (groupScroll) {
return ExpandableListView
.getPackedPositionGroup(expandableListView.getExpandableListPosition(position));
} else {
int m = Math.min(maxNumberOfSections - 1, (int) (position / itemsInSection));
return m;
}
}
@Override
public Object[] getSections() {
String[] ar ;
if (groupScroll) {
ar = new String[getGroupCount()];
for (int i = 0; i < getGroupCount(); i++) {
ar[i] = getGroup(i).getGroupName();
}
} else {
int total = getGroupCount();
for (int i = 0; i < getGroupCount(); i++) {
if (expandableListView.isGroupExpanded(i)) {
@ -261,11 +272,12 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
}
}
maxNumberOfSections = Math.max(1, Math.min(25, total));
positionsInGroup = ((double)total) / maxNumberOfSections;
String[] ar = new String[maxNumberOfSections];
itemsInSection = ((double) total) / maxNumberOfSections;
ar = new String[maxNumberOfSections];
for (int i = 0; i < ar.length; i++) {
ar[i] = ((i + 1) * 100 / maxNumberOfSections) + "%";
}
}
return ar;
}