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;
|
package net.osmand.osm;
|
||||||
|
|
||||||
import gnu.trove.list.array.TIntArrayList;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -21,53 +20,54 @@ public class OpeningHoursParser {
|
||||||
|
|
||||||
public static class BasicDayOpeningHourRule implements OpeningHoursRule {
|
public static class BasicDayOpeningHourRule implements OpeningHoursRule {
|
||||||
private boolean[] days = new boolean[7];
|
private boolean[] days = new boolean[7];
|
||||||
private TIntArrayList startTime = new TIntArrayList();
|
private int startTime = -1;
|
||||||
private TIntArrayList endTime = new TIntArrayList();
|
private int endTime = -1;
|
||||||
|
|
||||||
public boolean[] getDays() {
|
public boolean[] getDays() {
|
||||||
return days;
|
return days;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStartEndTime(int startTime, int endTime) {
|
public void setStartEndTime(int startTime, int endTime) {
|
||||||
this.startTime.add(startTime);
|
this.startTime = startTime;
|
||||||
this.endTime.add(endTime);
|
this.endTime = endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStartTime(int idx) {
|
public int getStartTime() {
|
||||||
return startTime.get(idx);
|
return startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndTime(int idx) {
|
public int getEndTime() {
|
||||||
return endTime.get(idx);
|
return endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOpenedForTime(Calendar cal) {
|
public boolean isOpenedForTime(Calendar cal) {
|
||||||
for (int ij = 0; ij < startTime.size(); ij++) {
|
if (startTime == -1) {
|
||||||
int i = cal.get(Calendar.DAY_OF_WEEK);
|
return false;
|
||||||
int d = (i + 5) % 7;
|
}
|
||||||
int p = d - 1;
|
int i = cal.get(Calendar.DAY_OF_WEEK);
|
||||||
if(p < 0){
|
int d = (i + 5) % 7;
|
||||||
p+=7;
|
int p = d - 1;
|
||||||
|
if (p < 0) {
|
||||||
|
p += 7;
|
||||||
|
}
|
||||||
|
int time = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
|
||||||
|
int startTime = this.startTime;
|
||||||
|
int endTime = this.endTime;
|
||||||
|
// one day working 10 - 20 (not 20 - 04)
|
||||||
|
if (startTime < endTime || endTime == -1) {
|
||||||
|
if (days[d]) {
|
||||||
|
if (time >= startTime && (endTime == -1 || time <= endTime)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int time = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
|
} else {
|
||||||
int startTime = this.startTime.get(ij);
|
if (time >= startTime && days[p]) {
|
||||||
int endTime = this.endTime.get(ij);
|
// check in previous day
|
||||||
// one day working 10 - 20 (not 20 - 04)
|
return true;
|
||||||
if (startTime < endTime || endTime == -1) {
|
} else if (time <= endTime && days[d]) {
|
||||||
if (days[d]) {
|
// check in previous day
|
||||||
if (time >= startTime && (endTime == -1 || time <= endTime)) {
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (time >= startTime && days[p]) {
|
|
||||||
// check in previous day
|
|
||||||
return true;
|
|
||||||
} else if (time <= endTime && days[d]) {
|
|
||||||
// check in previous day
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -78,7 +78,7 @@ public class OpeningHoursParser {
|
||||||
boolean dash = false;
|
boolean dash = false;
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
boolean open24_7 = true;
|
boolean open24_7 = true;
|
||||||
for(int i=0; i< 7; i++){
|
for (int i = 0; i < 7; i++) {
|
||||||
if (days[i]) {
|
if (days[i]) {
|
||||||
if (i > 0 && days[i - 1] && i < 6 && days[i + 1]) {
|
if (i > 0 && days[i - 1] && i < 6 && days[i + 1]) {
|
||||||
if (!dash) {
|
if (!dash) {
|
||||||
|
@ -98,22 +98,17 @@ public class OpeningHoursParser {
|
||||||
open24_7 = false;
|
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";
|
return "24/7";
|
||||||
}
|
}
|
||||||
b.append(" "); //$NON-NLS-1$
|
b.append(" "); //$NON-NLS-1$
|
||||||
for (int i = 0; i < startTime.size(); i++) {
|
int stHour = startTime / 60;
|
||||||
if(i > 0) {
|
int stTime = startTime - stHour * 60;
|
||||||
b.append(", ");
|
int enHour = endTime / 60;
|
||||||
}
|
int enTime = endTime - enHour * 60;
|
||||||
int stHour = startTime.get(i) / 60;
|
formatTime(stHour, stTime, b);
|
||||||
int stTime = startTime.get(i) - stHour * 60;
|
b.append("-"); //$NON-NLS-1$
|
||||||
int enHour = endTime.get(i) / 60;
|
formatTime(enHour, enTime, b);
|
||||||
int enTime = endTime.get(i) - enHour * 60;
|
|
||||||
formatTime(stHour, stTime, b);
|
|
||||||
b.append("-"); //$NON-NLS-1$
|
|
||||||
formatTime(enHour, enTime, b);
|
|
||||||
}
|
|
||||||
return b.toString();
|
return b.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,10 +116,18 @@ public class OpeningHoursParser {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toRuleString();
|
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 startDay = -1;
|
||||||
int previousDay = -1;
|
int previousDay = -1;
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
@ -134,6 +137,7 @@ public class OpeningHoursParser {
|
||||||
if("24/7".equals(r)){
|
if("24/7".equals(r)){
|
||||||
Arrays.fill(days, true);
|
Arrays.fill(days, true);
|
||||||
basic.setStartEndTime(0, 24*60);
|
basic.setStartEndTime(0, 24*60);
|
||||||
|
rs.add(basic);
|
||||||
return basic;
|
return basic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,6 +208,10 @@ public class OpeningHoursParser {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
basic.setStartEndTime(st, end);
|
basic.setStartEndTime(st, end);
|
||||||
|
rs.add(basic);
|
||||||
|
BasicDayOpeningHourRule nbasic = new BasicDayOpeningHourRule();
|
||||||
|
nbasic.days = basic.days;
|
||||||
|
basic = nbasic;
|
||||||
}
|
}
|
||||||
if(!timesExist){
|
if(!timesExist){
|
||||||
return null;
|
return null;
|
||||||
|
@ -221,12 +229,10 @@ public class OpeningHoursParser {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// check if valid
|
// check if valid
|
||||||
OpeningHoursRule rule = parseRule(r);
|
OpeningHoursRule rule = parseRule(r, rs);
|
||||||
if(rule == null){
|
if(rule == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
rs.add(rule);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
@ -259,19 +265,28 @@ public class OpeningHoursParser {
|
||||||
b.append(t);
|
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 {
|
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$
|
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(hours);
|
||||||
System.out.println(toStringOpenedHours(hours));
|
System.out.println(toStringOpenedHours(hours));
|
||||||
hours = parseOpenedHours("Mo-Fr 08:30-14:40,15:00-19:00"); //$NON-NLS-1$
|
hours = parseOpenedHours("Mo-Fr 08:30-14:40,15:00-19:00"); //$NON-NLS-1$
|
||||||
Calendar cal = Calendar.getInstance();
|
testOpened("20.04.2012 14:00", hours, true);
|
||||||
cal.setTime(new SimpleDateFormat("dd.MM.yyyy hh:mm").parse("20.04.2012 14:00"));
|
testOpened("20.04.2012 15:00", hours, true);
|
||||||
System.out.println("true="+hours.get(0).isOpenedForTime(cal));
|
testOpened("20.04.2012 14:50", hours, false);
|
||||||
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));
|
|
||||||
System.out.println(hours);
|
System.out.println(hours);
|
||||||
System.out.println(toStringOpenedHours(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$
|
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")+"";
|
String closed = obj.get("U")+"";
|
||||||
int start = Integer.parseInt(opened.substring(0, 2)) * 60 + Integer.parseInt(opened.substring(2));
|
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));
|
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;
|
prev.getDays()[i] = true;
|
||||||
} else {
|
} else {
|
||||||
BasicDayOpeningHourRule rule = new OpeningHoursParser.BasicDayOpeningHourRule();
|
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());
|
String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, SearchPOIActivity.this, settings.usingEnglishNames());
|
||||||
settings.setPointToNavigate(l.getLatitude(), l.getLongitude(), getString(R.string.poi)+" : " + poiSimpleFormat);
|
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);
|
MapActivity.launchMapActivityMoveToTop(SearchPOIActivity.this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -515,10 +510,6 @@ public class SearchPOIActivity extends OsmandListActivity implements SensorEvent
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView parent, View v, int position, long id) {
|
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();
|
int z = settings.getLastKnownMapZoom();
|
||||||
Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
|
Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
|
||||||
String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, this, settings.usingEnglishNames());
|
String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, this, settings.usingEnglishNames());
|
||||||
|
|
Loading…
Reference in a new issue