From 7588431354ebbecf175be4ded91014da3eafbf6f Mon Sep 17 00:00:00 2001 From: Johan von Forstner Date: Thu, 2 Jul 2015 22:21:56 +0200 Subject: [PATCH] SH: Line colors for Kiel buses. --- .../schildbach/pte/AbstractHafasProvider.java | 35 +++++++++++-- enabler/src/de/schildbach/pte/ShProvider.java | 52 +++++++++++++++++++ 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/enabler/src/de/schildbach/pte/AbstractHafasProvider.java b/enabler/src/de/schildbach/pte/AbstractHafasProvider.java index a06faa8c..20d052b6 100644 --- a/enabler/src/de/schildbach/pte/AbstractHafasProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractHafasProvider.java @@ -648,6 +648,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider final String delayReason = XmlPullUtil.optAttr(pp, "delayReason", null); // TODO is_reachable // TODO disableTrainInfo + // TODO lineFG/lineBG (ZVV) + final String administration = normalizeLineAdministration(XmlPullUtil.optAttr(pp, "administration", null)); if (!"cancel".equals(eDelay)) { @@ -725,13 +727,17 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider // could check for type consistency here final Set attrs = prodLine.attrs; if (attrs != null) - line = newLine(product, prodLine.label, null, attrs.toArray(new Line.Attr[0])); + line = newLine(administration, product, prodLine.label, null, attrs.toArray(new Line.Attr[0])); else - line = newLine(product, prodLine.label, null); + line = newLine(administration, product, prodLine.label, null); } else { - line = prodLine; + final Set attrs = prodLine.attrs; + if (attrs != null) + line = newLine(administration, prodLine.product, prodLine.label, null, attrs.toArray(new Line.Attr[0])); + else + line = newLine(administration, prodLine.product, prodLine.label, null); } final int[] capacity; @@ -3077,6 +3083,20 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider return lineName; } + private static final Pattern P_NORMALIZE_LINE_ADMINISTRATION = Pattern.compile("([^_]*)_*"); + + private final String normalizeLineAdministration(final String administration) + { + if (administration == null) + return null; + + final Matcher m = P_NORMALIZE_LINE_ADMINISTRATION.matcher(administration); + if (m.find()) + return m.group(1); + else + return administration; + } + private static final Pattern P_CATEGORY_FROM_NAME = Pattern.compile("([A-Za-zßÄÅäáàâåéèêíìîÖöóòôÜüúùûØ]+).*"); protected final String categoryFromName(final String lineName) @@ -3178,17 +3198,22 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider } protected Line newLine(final Product product, final String normalizedName, final String comment, final Line.Attr... attrs) + { + return newLine(null, product, normalizedName, comment, attrs); + } + + protected Line newLine(final String network, final Product product, final String normalizedName, final String comment, final Line.Attr... attrs) { if (attrs.length == 0) { - return new Line(null, null, product, normalizedName, lineStyle(null, product, normalizedName), comment); + return new Line(null, network, product, normalizedName, lineStyle(network, product, normalizedName), comment); } else { final Set attrSet = new HashSet(); for (final Line.Attr attr : attrs) attrSet.add(attr); - return new Line(null, null, product, normalizedName, lineStyle(null, product, normalizedName), attrSet, comment); + return new Line(null, network, product, normalizedName, lineStyle(network, product, normalizedName), attrSet, comment); } } } diff --git a/enabler/src/de/schildbach/pte/ShProvider.java b/enabler/src/de/schildbach/pte/ShProvider.java index 93fd5da1..e41ce6ad 100644 --- a/enabler/src/de/schildbach/pte/ShProvider.java +++ b/enabler/src/de/schildbach/pte/ShProvider.java @@ -18,12 +18,15 @@ package de.schildbach.pte; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.regex.Matcher; import com.google.common.base.Charsets; import de.schildbach.pte.dto.NearbyLocationsResult; import de.schildbach.pte.dto.Product; +import de.schildbach.pte.dto.Style; /** * @author Andreas Schildbach @@ -40,6 +43,7 @@ public class ShProvider extends AbstractHafasProvider setJsonGetStopsEncoding(Charsets.UTF_8); setJsonNearbyLocationsEncoding(Charsets.UTF_8); + setStyles(STYLES); } private static final String[] PLACES = { "Hamburg", "Kiel", "Lübeck", "Flensburg", "Neumünster" }; @@ -83,4 +87,52 @@ public class ShProvider extends AbstractHafasProvider uri.append("&input=").append(normalizeStationId(id)); return htmlNearbyStations(uri.toString()); } + + protected static final Map STYLES = new HashMap(); + + static + { + // Busse Kiel + putKielBusStyle("1", new Style(Style.parseColor("#7288af"), Style.WHITE)); + putKielBusStyle("2", new Style(Style.parseColor("#50bbb4"), Style.WHITE)); + putKielBusStyle("5", new Style(Style.parseColor("#f39222"), Style.WHITE)); + putKielBusStyle("6", new Style(Style.parseColor("#aec436"), Style.WHITE)); + putKielBusStyle("8", new Style(Style.parseColor("#bcb261"), Style.WHITE)); + putKielBusStyle("9", new Style(Style.parseColor("#c99c7d"), Style.WHITE)); + putKielBusStyle("11", new Style(Style.parseColor("#f9b000"), Style.WHITE)); + putKielBusStyle("22", new Style(Style.parseColor("#8ea48a"), Style.WHITE)); + putKielBusStyle("31", new Style(Style.parseColor("#009ee3"), Style.WHITE)); + putKielBusStyle("32", new Style(Style.parseColor("#009ee3"), Style.WHITE)); + putKielBusStyle("33", new Style(Style.parseColor("#009ee3"), Style.WHITE)); + putKielBusStyle("34", new Style(Style.parseColor("#009ee3"), Style.WHITE)); + putKielBusStyle("41", new Style(Style.parseColor("#8ba5d6"), Style.WHITE)); + putKielBusStyle("42", new Style(Style.parseColor("#8ba5d6"), Style.WHITE)); + putKielBusStyle("50", new Style(Style.parseColor("#00a138"), Style.WHITE)); + putKielBusStyle("51", new Style(Style.parseColor("#00a138"), Style.WHITE)); + putKielBusStyle("52", new Style(Style.parseColor("#00a138"), Style.WHITE)); + putKielBusStyle("60S", new Style(Style.parseColor("#92b4af"), Style.WHITE)); + putKielBusStyle("60", new Style(Style.parseColor("#92b4af"), Style.WHITE)); + putKielBusStyle("61", new Style(Style.parseColor("#9d1380"), Style.WHITE)); + putKielBusStyle("62", new Style(Style.parseColor("#9d1380"), Style.WHITE)); + putKielBusStyle("71", new Style(Style.parseColor("#777e6f"), Style.WHITE)); + putKielBusStyle("72", new Style(Style.parseColor("#777e6f"), Style.WHITE)); + putKielBusStyle("81", new Style(Style.parseColor("#00836e"), Style.WHITE)); + putKielBusStyle("91", new Style(Style.parseColor("#947e62"), Style.WHITE)); + putKielBusStyle("92", new Style(Style.parseColor("#947e62"), Style.WHITE)); + putKielBusStyle("100", new Style(Style.parseColor("#d40a11"), Style.WHITE)); + putKielBusStyle("101", new Style(Style.parseColor("#d40a11"), Style.WHITE)); + putKielBusStyle("300", new Style(Style.parseColor("#cf94c2"), Style.WHITE)); + putKielBusStyle("501", new Style(Style.parseColor("#0f3f93"), Style.WHITE)); + putKielBusStyle("502", new Style(Style.parseColor("#0f3f93"), Style.WHITE)); + putKielBusStyle("503", new Style(Style.parseColor("#0f3f93"), Style.WHITE)); + putKielBusStyle("503S", new Style(Style.parseColor("#0f3f93"), Style.WHITE)); + putKielBusStyle("512", new Style(Style.parseColor("#0f3f93"), Style.WHITE)); + putKielBusStyle("512S", new Style(Style.parseColor("#0f3f93"), Style.WHITE)); + } + + private static void putKielBusStyle(final String name, final Style style) + { + STYLES.put("AK|B" + name, style); + STYLES.put("KIEL|B" + name, style); + } }