From 3b0f6f49af9691bd99537550add9a50e8564e573 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 7 Apr 2015 00:34:11 +0200 Subject: [PATCH] Update open hours ui --- .../net/osmand/util/OpeningHoursParser.java | 29 +++++ OsmAnd/res/layout/searchpoi_list.xml | 116 ++++++++++-------- .../activities/search/SearchPOIActivity.java | 54 ++++---- .../osmand/plus/views/DirectionDrawable.java | 16 +-- 4 files changed, 132 insertions(+), 83 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java b/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java index e993004bbd..090dcfa811 100644 --- a/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java +++ b/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java @@ -105,6 +105,33 @@ public class OpeningHoursParser { return isOpenDay || isOpenPrevious; } + public String getCurrentRuleTime(Calendar cal) { + String ruleOpen = null; + String ruleClosed = null; + for (OpeningHoursRule r : rules){ + if(r.containsDay(cal) && r.containsMonth(cal)){ + if(r.isOpenedForTime(cal, false)) { + ruleOpen = r.toRuleString(); + } else { + ruleClosed = r.toRuleString(); + } + } + } + for (OpeningHoursRule r : rules){ + if(r.containsPreviousDay(cal) && r.containsMonth(cal)){ + if(r.isOpenedForTime(cal, true)) { + ruleOpen = r.toRuleString(); + } else { + ruleClosed = r.toRuleString(); + } + } + } + if(ruleOpen != null) { + return ruleOpen; + } + return ruleClosed; + } + @Override public String toString(){ StringBuilder s = new StringBuilder(); @@ -119,6 +146,8 @@ public class OpeningHoursParser { return s.substring(0, s.length()-2); } + + } diff --git a/OsmAnd/res/layout/searchpoi_list.xml b/OsmAnd/res/layout/searchpoi_list.xml index 9b8b85cf7a..82d5a5d343 100644 --- a/OsmAnd/res/layout/searchpoi_list.xml +++ b/OsmAnd/res/layout/searchpoi_list.xml @@ -1,61 +1,77 @@ - + - + - + - + - + - + - + - + - + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 437cb90b36..76783ebfbf 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -25,6 +25,7 @@ import net.osmand.osm.PoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; +import net.osmand.plus.R.color; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -716,6 +717,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa class AmenityAdapter extends ArrayAdapter { private AmenityFilter listFilter; private List originalAmenityList; + private int screenOrientation; AmenityAdapter(List list) { super(SearchPOIActivity.this, R.layout.searchpoi_list, list); @@ -729,6 +731,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa public void setNewModel(List amenityList, String filter) { setNotifyOnChange(false); + screenOrientation = DashLocationFragment.getScreenOrientation(SearchPOIActivity.this); originalAmenityList = new ArrayList(amenityList); clear(); for (Amenity obj : amenityList) { @@ -750,9 +753,37 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa float[] mes = null; TextView label = (TextView) row.findViewById(R.id.poi_label); TextView distanceText = (TextView) row.findViewById(R.id.distance); + TextView timeText = (TextView) row.findViewById(R.id.time); ImageView direction = (ImageView) row.findViewById(R.id.poi_direction); + ImageView timeIcon = (ImageView) row.findViewById(R.id.time_icon); ImageView icon = (ImageView) row.findViewById(R.id.poi_icon); Amenity amenity = getItem(position); + if (amenity.getOpeningHours() != null) { + OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours()); + if (rs != null) { + Calendar inst = Calendar.getInstance(); + inst.setTimeInMillis(System.currentTimeMillis()); + boolean work = rs.isOpenedForTime(inst); + timeIcon.setVisibility(View.VISIBLE); + timeText.setVisibility(View.VISIBLE); + timeIcon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_small_time, work ? R.color.color_ok : R.color.color_warning)); + timeText.setTextColor(app.getResources().getColor(work ? R.color.color_ok : R.color.color_warning)); + String rt = rs.getCurrentRuleTime(inst); + timeText.setText(rt == null ? "" : rt); + } else { + timeIcon.setVisibility(View.GONE); + timeText.setVisibility(View.GONE); + } + } + Drawable dd = direction.getDrawable(); + DirectionDrawable draw; + if (dd instanceof DirectionDrawable) { + draw = (DirectionDrawable) dd; + } else { + draw = new DirectionDrawable(SearchPOIActivity.this, width, height, + R.drawable.ic_destination_arrow_white, R.color.color_distance); + direction.setImageDrawable(draw); + } net.osmand.Location loc = location; if (loc != null) { mes = new float[2]; @@ -760,33 +791,14 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa net.osmand.Location.distanceBetween(l.getLatitude(), l.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes); } - int opened = -1; - if (amenity.getOpeningHours() != null) { - OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours()); - if (rs != null) { - Calendar inst = Calendar.getInstance(); - inst.setTimeInMillis(System.currentTimeMillis()); - boolean work = false; - work = rs.isOpenedForTime(inst); - if (work) { - opened = 0; - } else { - opened = 1; - } - } - } - DirectionDrawable draw = new DirectionDrawable(SearchPOIActivity.this, width, height, - R.drawable.ic_destination_arrow_white, - R.color.color_distance); - int screenOrientation = DashLocationFragment.getScreenOrientation(SearchPOIActivity.this); if (loc != null) { float a = heading != null ? heading : 0; draw.setAngle(mes[1] - a + 180 + screenOrientation); + draw.setColorId(color.color_myloc_distance); } else { draw.setAngle(0); + draw.setColorId(color.color_distance); } - - draw.setOpenedColor(opened); direction.setImageDrawable(draw); PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); if (st != null) { diff --git a/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java b/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java index f541ac956b..ce997e3c70 100644 --- a/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java +++ b/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java @@ -53,21 +53,13 @@ public class DirectionDrawable extends Drawable { paintRouteDirection.setAntiAlias(true); } - public void setOpenedColor(int opened) { + public void setColorId(int clrId) { + // R.color.color_ok, R.color.color_unknown, R.color.color_warning if(arrowImage != null) { IconsCache iconsCache = ((OsmandApplication) ctx.getApplicationContext()).getIconsCache(); - if (opened == 0) { - arrowImage = iconsCache.getIcon(resourceId, R.color.color_ok); - } else if (opened != -1) { - arrowImage = iconsCache.getIcon(resourceId, R.color.color_warning); - } - } - if (opened == 0) { - paintRouteDirection.setColor(ctx.getResources().getColor(R.color.color_ok)); - } else if (opened == -1) { - paintRouteDirection.setColor(ctx.getResources().getColor(R.color.color_unknown)); + arrowImage = iconsCache.getIcon(resourceId, clrId); } else { - paintRouteDirection.setColor(ctx.getResources().getColor(R.color.color_warning)); + paintRouteDirection.setColor(ctx.getResources().getColor(clrId)); } }