Update open hours ui

This commit is contained in:
Victor Shcherb 2015-04-07 00:34:11 +02:00
parent 8ebc11039a
commit 3b0f6f49af
4 changed files with 132 additions and 83 deletions

View file

@ -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);
}
}

View file

@ -1,61 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/list_item_height"
android:background="?attr/expandable_list_item_background"
android:orientation="horizontal"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/expandable_list_item_background"
android:minHeight="@dimen/list_item_height"
android:orientation="horizontal"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding" >
<ImageView
android:id="@+id/poi_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
tools:visiblity="visible"/>
<ImageView
android:id="@+id/poi_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
tools:visiblity="visible" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:paddingRight="3dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:paddingRight="3dp" >
<TextView
android:id="@+id/poi_label"
style="@style/ListText.Small"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:maxLines="1"
tools:text="@string/lorem_ipsum"/>
<TextView
android:id="@+id/poi_label"
style="@style/ListText.Small"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:maxLines="1"
tools:text="@string/lorem_ipsum" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/poi_direction"
android:layout_width="@dimen/dashFavDirectionSize"
android:layout_height="@dimen/dashFavDirectionSize"
android:layout_gravity="center_vertical"
tools:visiblity="visible"/>
<ImageView
android:id="@+id/poi_direction"
android:layout_width="@dimen/dashFavDirectionSize"
android:layout_height="@dimen/dashFavDirectionSize"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_destination_arrow_white"
tools:visiblity="visible" />
<TextView
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/color_distance"
android:maxLines="1"
tools:text="@string/lorem_ipsum"/>
<TextView
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/download_descr_text_size"
android:layout_marginRight="@dimen/gpx_small_text_margin"
tools:text="300 km" />
</LinearLayout>
<ImageView
android:id="@+id/time_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/gpx_small_icon_margin"
android:src="@drawable/ic_small_time" />
</LinearLayout>
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/gpx_small_text_margin"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/download_descr_text_size" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -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<Amenity> {
private AmenityFilter listFilter;
private List<Amenity> originalAmenityList;
private int screenOrientation;
AmenityAdapter(List<Amenity> list) {
super(SearchPOIActivity.this, R.layout.searchpoi_list, list);
@ -729,6 +731,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
public void setNewModel(List<Amenity> amenityList, String filter) {
setNotifyOnChange(false);
screenOrientation = DashLocationFragment.getScreenOrientation(SearchPOIActivity.this);
originalAmenityList = new ArrayList<Amenity>(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) {

View file

@ -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));
}
}