From f5cc75723a73a807920083b4e925a16d111554ef Mon Sep 17 00:00:00 2001 From: cyBerta Date: Wed, 17 Apr 2019 19:42:17 +0200 Subject: [PATCH] add markers with single characters to map --- .../ic_location_on_white_48dp.png | Bin 0 -> 423 bytes .../securesms/map/MapDataManager.java | 68 ++++++--- .../securesms/map/model/FeatureTreeSet.java | 55 -------- .../map/model/TimeComparableFeature.java | 59 -------- .../map/model/FeatureTreeSetTest.java | 131 ------------------ .../map/model/TimeComparableFeatureTest.java | 99 ------------- test/utils/TestUtils.java | 42 ------ 7 files changed, 48 insertions(+), 406 deletions(-) create mode 100755 res/drawable-hdpi/ic_location_on_white_48dp.png delete mode 100644 src/org/thoughtcrime/securesms/map/model/FeatureTreeSet.java delete mode 100644 src/org/thoughtcrime/securesms/map/model/TimeComparableFeature.java delete mode 100644 test/org/thoughtcrime/securesms/map/model/FeatureTreeSetTest.java delete mode 100644 test/org/thoughtcrime/securesms/map/model/TimeComparableFeatureTest.java delete mode 100644 test/utils/TestUtils.java diff --git a/res/drawable-hdpi/ic_location_on_white_48dp.png b/res/drawable-hdpi/ic_location_on_white_48dp.png new file mode 100755 index 0000000000000000000000000000000000000000..d226e78f17e8c05900f62de02d255d9bd025bcd1 GIT binary patch literal 423 zcmV;Y0a*TtP)Zp>wmAi z-|xNmhO7JRJx@K4TABl$Op)T6EZ=;PXm+Zaf!#Jd|1M3Q66OR%F2!rqNJHr36rFWG9oK>sI;XrY*A@P zR-6$!QGjDY=dvP0XhH$T31wu(2caGX=ppnjD?Vcte9DS@LgR*s?q$VAtdlQfMT$z> zD#JFFQnF&6C~0O?!VGDm%*%>)-tc;(U3To_bs!JM@EVg3H+bC0i#0sf= 0; i--) { Point point = Point.fromLngLat(locations.getLongitude(i), locations.getLatitude(i)); + String codepointChar = + locations.getMarker(i) != null && locations.getMarker(i).length() > 0 ? + new StringBuilder().appendCodePoint(locations.getMarker(i).codePointAt(0)).toString() : + ""; + Log.d(TAG, "codepointChar: " + codepointChar); + Feature pointFeature = Feature.fromGeometry(point, new JsonObject(), String.valueOf(locations.getLocationId(i))); pointFeature.addBooleanProperty(MARKER_SELECTED, false); pointFeature.addBooleanProperty(LAST_LOCATION, false); @@ -318,6 +335,8 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn pointFeature.addNumberProperty(TIMESTAMP, locations.getTimestamp(i)); pointFeature.addNumberProperty(MESSAGE_ID, locations.getMsgId(i)); pointFeature.addNumberProperty(ACCURACY, locations.getAccuracy(i)); + pointFeature.addStringProperty(MARKER_CHAR, codepointChar); + pointFeature.addStringProperty(MARKER_ICON, contactMapMetadata.getMarkerIcon()); sortedPointFeatures.addFirst(pointFeature); if (sortedPointFeatures.size() > 1) { @@ -337,10 +356,11 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn } if (sortedPointFeatures.size() > 0) { - sortedPointFeatures.get(0).addStringProperty(LAST_POSITION_ICON_ID, contactMapMetadata.getMarkerLastPositon()); - sortedPointFeatures.get(0).addBooleanProperty(LAST_LOCATION, true); - lastPositions.remove(contactId); - lastPositions.put(contactId, sortedPointFeatures.get(0)); + Feature lastPostion = sortedPointFeatures.getFirst(); + lastPostion.addStringProperty(LAST_POSITION_ICON, contactMapMetadata.getMarkerLastPositon()); + lastPostion.removeProperty(MARKER_ICON); + lastPostion.addBooleanProperty(LAST_LOCATION, true); + lastPositions.put(contactId, lastPostion); } featureCollections.put(contactMapMetadata.getMarkerFeatureCollection(), sortedPointFeatures); @@ -403,14 +423,14 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn GeoJsonSource lastPositionSource = new GeoJsonSource(LAST_POSITION_SOURCE); mapboxStyle.addSource(lastPositionSource); Expression markerSize = - switchCase(toBool(get(MARKER_SELECTED)), literal(1.5f), literal(1.0f)); - mapboxStyle.addLayer(new SymbolLayer(LAST_POSITION_LAYER, LAST_POSITION_SOURCE).withProperties( - iconImage("{" + LAST_POSITION_ICON_ID + "}"), + switchCase(toBool(get(MARKER_SELECTED)), literal(1.75f), literal(1.25f)); + mapboxStyle.addLayerBelow(new SymbolLayer(LAST_POSITION_LAYER, LAST_POSITION_SOURCE).withProperties( + iconImage(get(LAST_POSITION_ICON)), /* all info window and marker image to appear at the same time*/ iconAllowOverlap(true), iconIgnorePlacement(true), iconSize(markerSize) - ).withFilter(filterProvider.getRangeFilter())); + ).withFilter(filterProvider.getRangeFilter()), INFO_WINDOW_LAYER); } private void initContactBasedLayers(MapSource source) { @@ -420,10 +440,13 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn generateColoredLocationIcon(source.getColorArgb())); Expression markerSize = - switchCase(toBool(get(MARKER_SELECTED)), literal(1.5f), - switchCase(toBool(get(LAST_LOCATION)), literal(0f), - switchCase(eq(get(MESSAGE_ID), literal(0)), literal(0.7f), literal(1.1f)))); - Expression markerIcon = switchCase(toBool(get(LAST_LOCATION)), literal(""), literal(source.getMarkerIcon())); + switchCase( + eq(length(get(MARKER_CHAR)), literal(1)), + switchCase(toBool(get(MARKER_SELECTED)), literal(2.25f), literal(2.0f)), + eq(get(MESSAGE_ID), literal(0)), + switchCase(toBool(get(MARKER_SELECTED)), literal(1.1f), literal(1.0f)), + switchCase(toBool(get(MARKER_SELECTED)), literal(1.1f), literal(0.7f))); + Expression markerIcon = get(MARKER_ICON); mapboxStyle.addLayerBelow(new LineLayer(source.getLineLayer(), source.getLineSource()) .withProperties(PropertyFactory.lineCap(Property.LINE_CAP_ROUND), @@ -431,20 +454,25 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn lineWidth(3f), lineOpacity(0.5f), lineColor(source.getColorArgb()), - visibility(NONE), - iconAllowOverlap(true), - iconIgnorePlacement(true) + visibility(NONE) ) .withFilter(filterProvider.getRangeFilter()), - INFO_WINDOW_LAYER); + LAST_POSITION_LAYER); mapboxStyle.addLayerBelow(new SymbolLayer(source.getMarkerLayer(), source.getMarkerSource()) .withProperties( iconImage(markerIcon), - iconSize(markerSize)) - .withFilter(filterProvider.getMarkerFilter()), - INFO_WINDOW_LAYER); + iconSize(markerSize), + textAllowOverlap(true), + textIgnorePlacement(true), + iconIgnorePlacement(false), + iconAllowOverlap(false), + textField(get(MARKER_CHAR)) + ) + .withFilter(all(filterProvider.getMarkerFilter(), + not(get(LAST_LOCATION)))), + LAST_POSITION_LAYER); } private MapSource addContactMapSource(int contactId) { @@ -462,7 +490,7 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, GenerateIn } private Bitmap generateColoredLastPositionIcon(int colorFilter) { - return generateColoredBitmap(colorFilter, R.drawable.ic_location_on_white_24dp); + return generateColoredBitmap(colorFilter, R.drawable.ic_location_on_white_48dp); } private Bitmap generateColoredLocationIcon(int colorFilter) { diff --git a/src/org/thoughtcrime/securesms/map/model/FeatureTreeSet.java b/src/org/thoughtcrime/securesms/map/model/FeatureTreeSet.java deleted file mode 100644 index 0a5a80c00..000000000 --- a/src/org/thoughtcrime/securesms/map/model/FeatureTreeSet.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.thoughtcrime.securesms.map.model; - -import android.support.annotation.NonNull; - -import com.google.gson.JsonSyntaxException; -import com.mapbox.geojson.Feature; -import com.mapbox.geojson.Point; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.TreeSet; - -/** - * Created by cyberta on 21.03.19. - */ - -public class FeatureTreeSet extends TreeSet { - - /** - * - * @param obj - * @return true if element was added newly, false if element was replaced - */ - @Override - public boolean add(@NonNull TimeComparableFeature obj) { - boolean existed = remove(obj); - super.add(obj); - return !existed; - } - - public ArrayList getFeatureList() { - ArrayList featureList = new ArrayList<>(); - Iterator iterator = this.iterator(); - while (iterator.hasNext()) { - TimeComparableFeature timeComparableFeature = iterator.next(); - featureList.add(timeComparableFeature.getFeature()); - } - return featureList; - } - - public ArrayList getPointList() { - ArrayList points = new ArrayList<>(); - Iterator iterator = this.iterator(); - while (iterator.hasNext()) { - TimeComparableFeature timeComparableFeature = iterator.next(); - try { - points.add(Point.fromJson(timeComparableFeature.getFeature().geometry().toJson())); - } catch (JsonSyntaxException | NullPointerException e) { - e.printStackTrace(); - } - } - return points; - } -} diff --git a/src/org/thoughtcrime/securesms/map/model/TimeComparableFeature.java b/src/org/thoughtcrime/securesms/map/model/TimeComparableFeature.java deleted file mode 100644 index 7b80185d1..000000000 --- a/src/org/thoughtcrime/securesms/map/model/TimeComparableFeature.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.thoughtcrime.securesms.map.model; - -import android.support.annotation.NonNull; - -import com.mapbox.geojson.Feature; - -import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP; - -/** - * Created by cyberta on 21.03.19. - */ - -public class TimeComparableFeature implements Comparable { - private Feature feature; - - public TimeComparableFeature(@NonNull Feature feature) { - if (!feature.hasProperty(TIMESTAMP)) { - throw new IllegalArgumentException("Time comparable features need to have a TIMESTAMP property"); - } - - this.feature = feature; - } - - public Feature getFeature() { - return feature; - } - - /** - * - * @param o for same timestamps but different featureIds, this object is considered lower - * @return - */ - @Override - public int compareTo(@NonNull TimeComparableFeature o) { - if (this.equals(o) && this.feature.getNumberProperty(TIMESTAMP).longValue() == o.getFeature().getNumberProperty(TIMESTAMP).longValue()) { - return 0; - } - return this.feature.getNumberProperty(TIMESTAMP).longValue() > o.getFeature().getNumberProperty(TIMESTAMP).longValue() ? -1 : 1; - } - - - @Override - public int hashCode() { - return this.feature.id().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == null || !(obj instanceof TimeComparableFeature)) { - return false; - } - - TimeComparableFeature compare = (TimeComparableFeature) obj; - return this.feature.id() != null && - compare.feature.id() != null && - this.feature.id().equals(compare.feature.id()); - } - -} diff --git a/test/org/thoughtcrime/securesms/map/model/FeatureTreeSetTest.java b/test/org/thoughtcrime/securesms/map/model/FeatureTreeSetTest.java deleted file mode 100644 index 6b7a52b52..000000000 --- a/test/org/thoughtcrime/securesms/map/model/FeatureTreeSetTest.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.thoughtcrime.securesms.map.model; - -import com.mapbox.geojson.Feature; -import com.mapbox.geojson.Point; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Iterator; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP; -import static utils.TestUtils.getPointFeature; - -/** - * Created by cyberta on 22.03.19. - */ -public class FeatureTreeSetTest { - - @Test - public void add_differentFeaturesIds_differentTimestamps_descendingOrder() { - FeatureTreeSet featureTreeSet = new FeatureTreeSet(); - - Feature point2 = getPointFeature("3"); - point2.addNumberProperty(TIMESTAMP, 2); - featureTreeSet.add(new TimeComparableFeature(point2)); - - Feature point = getPointFeature("2"); - point.addNumberProperty(TIMESTAMP, 1); - featureTreeSet.add(new TimeComparableFeature(point)); - - featureTreeSet.add(new TimeComparableFeature(getPointFeature("1"))); - - Iterator iterator = featureTreeSet.iterator(); - assertEquals(123456789, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue()); - assertEquals(2, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue()); - assertEquals(1, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue()); - - } - - - @Test - public void add_sameFeaturesIds_differentTimestamps_descendingOrder() { - FeatureTreeSet featureTreeSet = new FeatureTreeSet(); - - Feature point2 = getPointFeature(); - point2.addNumberProperty(TIMESTAMP, 2); - featureTreeSet.add(new TimeComparableFeature(point2)); - - Feature point = getPointFeature(); - point.addNumberProperty(TIMESTAMP, 1); - featureTreeSet.add(new TimeComparableFeature(point)); - - featureTreeSet.add(new TimeComparableFeature(getPointFeature("1"))); - - - Iterator iterator = featureTreeSet.iterator(); - assertEquals(123456789, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue()); - assertEquals(2, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue()); - assertEquals(1, iterator.next().getFeature().getNumberProperty(TIMESTAMP).longValue()); - } - - @Test - public void add_sameFeaturesIds_sameTimestamps_noDuplicatedEntries() { - FeatureTreeSet featureTreeSet = new FeatureTreeSet(); - featureTreeSet.add(new TimeComparableFeature(getPointFeature())); - featureTreeSet.add(new TimeComparableFeature(getPointFeature())); - assertEquals(1, featureTreeSet.size()); - } - - @Test - public void add_sameFeaturesIds_sameTimestamps_elementReplaced() { - FeatureTreeSet featureTreeSet = new FeatureTreeSet(); - Feature feature = getPointFeature(); - feature.addStringProperty("Test", "element1"); - featureTreeSet.add(new TimeComparableFeature(feature)); - featureTreeSet.add(new TimeComparableFeature(getPointFeature())); - assertFalse(featureTreeSet.first().getFeature().hasProperty("Test")); - } - - - - @Test - public void getFeatureList_returnsOrderedList() throws Exception { - FeatureTreeSet featureTreeSet = new FeatureTreeSet(); - - Feature point2 = getPointFeature(); - point2.addNumberProperty(TIMESTAMP, 2); - featureTreeSet.add(new TimeComparableFeature(point2)); - - Feature point = getPointFeature(); - point.addNumberProperty(TIMESTAMP, 1); - featureTreeSet.add(new TimeComparableFeature(point)); - - featureTreeSet.add(new TimeComparableFeature(getPointFeature("1"))); - - ArrayList features = featureTreeSet.getFeatureList(); - assertEquals(123456789, features.get(0).getNumberProperty(TIMESTAMP).longValue()); - assertEquals(2, features.get(1).getNumberProperty(TIMESTAMP).longValue()); - assertEquals(1, features.get(2).getNumberProperty(TIMESTAMP).longValue()); - - } - - @Test - public void getPointList_returnsOrderedPointList() throws Exception { - FeatureTreeSet featureTreeSet = new FeatureTreeSet(); - - Feature point = getPointFeature("id2", 1.00, 1.00); - point.addNumberProperty(TIMESTAMP, 2); - featureTreeSet.add(new TimeComparableFeature(point)); - - Feature point2 = getPointFeature("id1", 2.00, 2.00); - point2.addNumberProperty(TIMESTAMP, 1); - featureTreeSet.add(new TimeComparableFeature(point2)); - - - Feature point3 = getPointFeature("id3", 3.00, 3.00); - point3.addNumberProperty(TIMESTAMP, 3); - - featureTreeSet.add(new TimeComparableFeature(point3)); - - - ArrayList points = featureTreeSet.getPointList(); - assertEquals(new Double(3.00), points.get(0).coordinates().get(0)); - assertEquals(new Double(1.00), points.get(1).coordinates().get(0)); - assertEquals(new Double(2.00), points.get(2).coordinates().get(0)); - - } - -} \ No newline at end of file diff --git a/test/org/thoughtcrime/securesms/map/model/TimeComparableFeatureTest.java b/test/org/thoughtcrime/securesms/map/model/TimeComparableFeatureTest.java deleted file mode 100644 index 9dd4f48aa..000000000 --- a/test/org/thoughtcrime/securesms/map/model/TimeComparableFeatureTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.thoughtcrime.securesms.map.model; - -import com.mapbox.geojson.Feature; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP; -import static utils.TestUtils.getPointFeature; - -/** - * Created by cyberta on 22.03.19. - */ - -public class TimeComparableFeatureTest { - - @Test(expected = IllegalArgumentException.class) - public void init_noTimestamp_throwIllegalStateException() throws Exception { - Feature feature = getPointFeature(); - feature.removeProperty(TIMESTAMP); - new TimeComparableFeature(feature); - } - - @Test - public void compareTo_sameTimestamp_return0() throws Exception { - TimeComparableFeature tcf1 = new TimeComparableFeature(getPointFeature()); - TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature()); - - assertEquals(0, tcf1.compareTo(tcf2)); - assertEquals(0, tcf2.compareTo(tcf1)); - } - - @Test - public void compareTo_biggerTimestamp_return1() throws Exception { - Feature feature = getPointFeature(); - feature.addNumberProperty(TIMESTAMP, 234567890); - TimeComparableFeature tcf1 = new TimeComparableFeature(getPointFeature()); - TimeComparableFeature tcf2 = new TimeComparableFeature(feature); - - assertEquals(1, tcf1.compareTo(tcf2)); - } - - @Test - public void compareTo_biggerTimestamp_returnMinus1() throws Exception { - Feature feature = getPointFeature(); - feature.addNumberProperty(TIMESTAMP, 234567890); - TimeComparableFeature tcf1 = new TimeComparableFeature(feature); - TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature()); - - assertEquals(-1, tcf1.compareTo(tcf2)); - } - - @Test - public void compareTo_sameTimestamp_differntId_returnMinus1() throws Exception { - Feature feature = getPointFeature(); - feature.addNumberProperty(TIMESTAMP, 234567890); - TimeComparableFeature tcf1 = new TimeComparableFeature(feature); - TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature()); - - assertEquals(-1, tcf1.compareTo(tcf2)); - } - - @Test - public void equals_differentObjects_sameId_returnTrue() throws Exception { - TimeComparableFeature tcf1 = new TimeComparableFeature(getPointFeature()); - TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature()); - - assertEquals(true, tcf1.equals(tcf2)); - } - - @Test - public void equals_differentObjects_differentId_returnFalse() throws Exception { - Feature feature = getPointFeature("id2"); - TimeComparableFeature tcf1 = new TimeComparableFeature(feature); - TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature()); - - assertEquals(false, tcf1.equals(tcf2)); - } - - @Test - public void equals_differentObjects_differentId_sameTimeStamp_returnFalse() throws Exception { - Feature feature = getPointFeature("id2"); - TimeComparableFeature tcf1 = new TimeComparableFeature(feature); - TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature()); - - assertEquals(false, tcf1.equals(tcf2)); - } - - @Test - public void equals_differentObjects_sameId_differentTimeStamp_returnTrue() throws Exception { - Feature feature = getPointFeature(); - feature.addNumberProperty(TIMESTAMP, 234567890); - TimeComparableFeature tcf1 = new TimeComparableFeature(feature); - TimeComparableFeature tcf2 = new TimeComparableFeature(getPointFeature()); - - assertEquals(true, tcf1.equals(tcf2)); - } - -} \ No newline at end of file diff --git a/test/utils/TestUtils.java b/test/utils/TestUtils.java deleted file mode 100644 index 8a7b7ccfc..000000000 --- a/test/utils/TestUtils.java +++ /dev/null @@ -1,42 +0,0 @@ -package utils; - -import com.google.gson.JsonObject; -import com.mapbox.geojson.Feature; -import com.mapbox.geojson.Point; - -import static org.thoughtcrime.securesms.map.MapDataManager.ACCURACY; -import static org.thoughtcrime.securesms.map.MapDataManager.CONTACT_ID; -import static org.thoughtcrime.securesms.map.MapDataManager.INFO_WINDOW_ID; -import static org.thoughtcrime.securesms.map.MapDataManager.LAST_LOCATION; -import static org.thoughtcrime.securesms.map.MapDataManager.MARKER_SELECTED; -import static org.thoughtcrime.securesms.map.MapDataManager.MESSAGE_ID; -import static org.thoughtcrime.securesms.map.MapDataManager.TIMESTAMP; - -/** - * Created by cyberta on 22.03.19. - */ - -public class TestUtils { - - public static Feature getPointFeature(String id) { - return getPointFeature(id, 10.00, 52.00); - } - - public static Feature getPointFeature() { - return getPointFeature("id1"); - } - - public static Feature getPointFeature(String id, double latitude, double longitude) { - Point p = Point.fromLngLat(longitude, latitude); - Feature pointFeature = Feature.fromGeometry(p, new JsonObject(), id); - pointFeature.addBooleanProperty(MARKER_SELECTED, false); - pointFeature.addBooleanProperty(LAST_LOCATION, false); - pointFeature.addNumberProperty(CONTACT_ID, 1); - pointFeature.addStringProperty(INFO_WINDOW_ID, "0_1_info_2"); - pointFeature.addNumberProperty(TIMESTAMP, 123456789); - pointFeature.addNumberProperty(MESSAGE_ID, 1); - pointFeature.addNumberProperty(ACCURACY, 12); - return Feature.fromJson(pointFeature.toJson()); - } - -}