Fix compilation error and poi display
This commit is contained in:
parent
1d4319f9aa
commit
a261f9447c
3 changed files with 74 additions and 68 deletions
|
@ -1,6 +1,5 @@
|
|||
package net.osmand.osm;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -21,29 +20,31 @@ public class OpeningHoursParser {
|
|||
|
||||
public static class BasicDayOpeningHourRule implements OpeningHoursRule {
|
||||
private boolean[] days = new boolean[7];
|
||||
private TIntArrayList startTime = new TIntArrayList();
|
||||
private TIntArrayList endTime = new TIntArrayList();
|
||||
private int startTime = -1;
|
||||
private int endTime = -1;
|
||||
|
||||
public boolean[] getDays() {
|
||||
return days;
|
||||
}
|
||||
|
||||
public void setStartEndTime(int startTime, int endTime) {
|
||||
this.startTime.add(startTime);
|
||||
this.endTime.add(endTime);
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public int getStartTime(int idx) {
|
||||
return startTime.get(idx);
|
||||
public int getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public int getEndTime(int idx) {
|
||||
return endTime.get(idx);
|
||||
public int getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpenedForTime(Calendar cal) {
|
||||
for (int ij = 0; ij < startTime.size(); ij++) {
|
||||
if (startTime == -1) {
|
||||
return false;
|
||||
}
|
||||
int i = cal.get(Calendar.DAY_OF_WEEK);
|
||||
int d = (i + 5) % 7;
|
||||
int p = d - 1;
|
||||
|
@ -51,8 +52,8 @@ public class OpeningHoursParser {
|
|||
p += 7;
|
||||
}
|
||||
int time = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
|
||||
int startTime = this.startTime.get(ij);
|
||||
int endTime = this.endTime.get(ij);
|
||||
int startTime = this.startTime;
|
||||
int endTime = this.endTime;
|
||||
// one day working 10 - 20 (not 20 - 04)
|
||||
if (startTime < endTime || endTime == -1) {
|
||||
if (days[d]) {
|
||||
|
@ -69,7 +70,6 @@ public class OpeningHoursParser {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
|
@ -98,22 +98,17 @@ public class OpeningHoursParser {
|
|||
open24_7 = false;
|
||||
}
|
||||
}
|
||||
if(open24_7 && startTime.get(0) == 0 && endTime.get(0) / 60 == 24){
|
||||
if (open24_7 && startTime == 0 && endTime / 60 == 24) {
|
||||
return "24/7";
|
||||
}
|
||||
b.append(" "); //$NON-NLS-1$
|
||||
for (int i = 0; i < startTime.size(); i++) {
|
||||
if(i > 0) {
|
||||
b.append(", ");
|
||||
}
|
||||
int stHour = startTime.get(i) / 60;
|
||||
int stTime = startTime.get(i) - stHour * 60;
|
||||
int enHour = endTime.get(i) / 60;
|
||||
int enTime = endTime.get(i) - enHour * 60;
|
||||
int stHour = startTime / 60;
|
||||
int stTime = startTime - stHour * 60;
|
||||
int enHour = endTime / 60;
|
||||
int enTime = endTime - enHour * 60;
|
||||
formatTime(stHour, stTime, b);
|
||||
b.append("-"); //$NON-NLS-1$
|
||||
formatTime(enHour, enTime, b);
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
|
@ -121,10 +116,18 @@ public class OpeningHoursParser {
|
|||
public String toString() {
|
||||
return toRuleString();
|
||||
}
|
||||
|
||||
public void setStartTime(int startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public void setEndTime(int endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static OpeningHoursRule parseRule(String r){
|
||||
public static OpeningHoursRule parseRule(String r, List<OpeningHoursRule> rs){
|
||||
int startDay = -1;
|
||||
int previousDay = -1;
|
||||
int k = 0;
|
||||
|
@ -134,6 +137,7 @@ public class OpeningHoursParser {
|
|||
if("24/7".equals(r)){
|
||||
Arrays.fill(days, true);
|
||||
basic.setStartEndTime(0, 24*60);
|
||||
rs.add(basic);
|
||||
return basic;
|
||||
}
|
||||
|
||||
|
@ -204,6 +208,10 @@ public class OpeningHoursParser {
|
|||
return null;
|
||||
}
|
||||
basic.setStartEndTime(st, end);
|
||||
rs.add(basic);
|
||||
BasicDayOpeningHourRule nbasic = new BasicDayOpeningHourRule();
|
||||
nbasic.days = basic.days;
|
||||
basic = nbasic;
|
||||
}
|
||||
if(!timesExist){
|
||||
return null;
|
||||
|
@ -221,12 +229,10 @@ public class OpeningHoursParser {
|
|||
continue;
|
||||
}
|
||||
// check if valid
|
||||
OpeningHoursRule rule = parseRule(r);
|
||||
OpeningHoursRule rule = parseRule(r, rs);
|
||||
if(rule == null){
|
||||
return null;
|
||||
}
|
||||
rs.add(rule);
|
||||
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
@ -259,19 +265,28 @@ public class OpeningHoursParser {
|
|||
b.append(t);
|
||||
}
|
||||
|
||||
private static void testOpened(String time, List<OpeningHoursRule> hours, boolean expected) throws ParseException {
|
||||
boolean opened = false;
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new SimpleDateFormat("dd.MM.yyyy hh:mm").parse(time));
|
||||
for(OpeningHoursRule r : hours) {
|
||||
if(r.isOpenedForTime(cal)){
|
||||
opened = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println("Expected " + expected +" = " + opened);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ParseException {
|
||||
|
||||
List<OpeningHoursRule> hours = parseOpenedHours("Mo-Fr 08:30-14:40; Sa 08:00 - 14:00"); //$NON-NLS-1$
|
||||
System.out.println(hours);
|
||||
System.out.println(toStringOpenedHours(hours));
|
||||
hours = parseOpenedHours("Mo-Fr 08:30-14:40,15:00-19:00"); //$NON-NLS-1$
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new SimpleDateFormat("dd.MM.yyyy hh:mm").parse("20.04.2012 14:00"));
|
||||
System.out.println("true="+hours.get(0).isOpenedForTime(cal));
|
||||
cal.setTime(new SimpleDateFormat("dd.MM.yyyy hh:mm").parse("20.04.2012 15:50"));
|
||||
System.out.println("true="+hours.get(0).isOpenedForTime(cal));
|
||||
cal.setTime(new SimpleDateFormat("dd.MM.yyyy hh:mm").parse("20.04.2012 14:50"));
|
||||
System.out.println("false="+hours.get(0).isOpenedForTime(cal));
|
||||
testOpened("20.04.2012 14:00", hours, true);
|
||||
testOpened("20.04.2012 15:00", hours, true);
|
||||
testOpened("20.04.2012 14:50", hours, false);
|
||||
System.out.println(hours);
|
||||
System.out.println(toStringOpenedHours(hours));
|
||||
hours = parseOpenedHours("Mo, We-Fr, Th, Sa 08:30-14:40; Sa 08:00 - 14:00"); //$NON-NLS-1$
|
||||
|
|
|
@ -202,7 +202,7 @@ public class AHSupermarketResolver {
|
|||
String closed = obj.get("U")+"";
|
||||
int start = Integer.parseInt(opened.substring(0, 2)) * 60 + Integer.parseInt(opened.substring(2));
|
||||
int end = Integer.parseInt(closed.substring(0, 2)) * 60 + Integer.parseInt(closed.substring(2));
|
||||
if(prev != null && prev.getStartTime(0) == start && prev.getEndTime(0) == end){
|
||||
if(prev != null && prev.getStartTime() == start && prev.getEndTime() == end){
|
||||
prev.getDays()[i] = true;
|
||||
} else {
|
||||
BasicDayOpeningHourRule rule = new OpeningHoursParser.BasicDayOpeningHourRule();
|
||||
|
|
|
@ -419,11 +419,6 @@ public class SearchPOIActivity extends OsmandListActivity implements SensorEvent
|
|||
String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, SearchPOIActivity.this, settings.usingEnglishNames());
|
||||
settings.setPointToNavigate(l.getLatitude(), l.getLongitude(), getString(R.string.poi)+" : " + poiSimpleFormat);
|
||||
}
|
||||
if(filter != null){
|
||||
settings.setPoiFilterForMap(filter.getFilterId());
|
||||
settings.SHOW_POI_OVER_MAP.set(true);
|
||||
}
|
||||
|
||||
MapActivity.launchMapActivityMoveToTop(SearchPOIActivity.this);
|
||||
|
||||
}
|
||||
|
@ -515,10 +510,6 @@ public class SearchPOIActivity extends OsmandListActivity implements SensorEvent
|
|||
|
||||
@Override
|
||||
public void onListItemClick(ListView parent, View v, int position, long id) {
|
||||
if(filter != null){
|
||||
settings.setPoiFilterForMap(filter.getFilterId());
|
||||
settings.SHOW_POI_OVER_MAP.set(true);
|
||||
}
|
||||
int z = settings.getLastKnownMapZoom();
|
||||
Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
|
||||
String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, this, settings.usingEnglishNames());
|
||||
|
|
Loading…
Reference in a new issue