Skip to content

Commit 93bae65

Browse files
committed
Progress
1 parent 090c59f commit 93bae65

File tree

8 files changed

+216
-36
lines changed

8 files changed

+216
-36
lines changed

app/src/main/java/space/itoncek/trailcompass/app/hideandseek/generic_ui/MainmenuHideandseekLogin.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,19 @@ public void afterTextChanged(Editable s) {
9292
} catch (Exception e) {
9393
serverValidity.set(ServerValidity.NOT_FOUND);
9494
}
95-
requireActivity().runOnUiThread(() -> {
96-
int textID;
97-
if (Objects.requireNonNull(serverValidity.get()) == ServerValidity.NOT_FOUND) {
98-
textID = R.string.fragment_status_unknown;
99-
} else if (serverValidity.get() == ServerValidity.INCOMPATIBLE_VERSION) {
100-
textID = R.string.fragment_status_incompatible;
101-
} else if (serverValidity.get() == ServerValidity.DEVELOPMENT_VERSION) {
102-
textID = R.string.fragment_status_dev;
103-
} else if (serverValidity.get() == ServerValidity.OK) {
104-
textID = R.string.fragment_status_ok;
105-
} else {
106-
throw new IllegalArgumentException();
107-
}
108-
((TextView) v.findViewById(R.id.hideandseek_fragment_status)).setText(textID);
109-
});
95+
int textID;
96+
if (Objects.requireNonNull(serverValidity.get()) == ServerValidity.NOT_FOUND) {
97+
textID = R.string.fragment_status_unknown;
98+
} else if (serverValidity.get() == ServerValidity.INCOMPATIBLE_VERSION) {
99+
textID = R.string.fragment_status_incompatible;
100+
} else if (serverValidity.get() == ServerValidity.DEVELOPMENT_VERSION) {
101+
textID = R.string.fragment_status_dev;
102+
} else if (serverValidity.get() == ServerValidity.OK) {
103+
textID = R.string.fragment_status_ok;
104+
} else {
105+
throw new IllegalArgumentException();
106+
}
107+
requireActivity().runOnUiThread(() -> ((TextView) v.findViewById(R.id.hideandseek_fragment_status)).setText(textID));
110108
});
111109

112110
t.start();

app/src/main/java/space/itoncek/trailcompass/app/hideandseek/hider_ui/HiderMapView.java

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import static android.view.View.GONE;
44
import static android.view.View.VISIBLE;
5-
65
import static space.itoncek.trailcompass.app.utils.RunnableUtils.runOnBackgroundThread;
76

87
import android.content.Intent;
98
import android.os.Bundle;
109
import android.util.Log;
10+
import android.view.View;
11+
import android.view.ViewGroup;
1112
import android.widget.TextView;
1213

1314
import androidx.activity.EdgeToEdge;
@@ -16,11 +17,15 @@
1617
import androidx.core.view.ViewCompat;
1718
import androidx.core.view.WindowInsetsCompat;
1819

20+
import org.mapsforge.core.model.LatLong;
1921
import org.mapsforge.core.util.Parameters;
2022
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
2123
import org.mapsforge.map.android.util.AndroidUtil;
24+
import org.mapsforge.map.android.view.MapView;
2225
import org.mapsforge.map.datastore.MapDataStore;
26+
import org.mapsforge.map.layer.Layers;
2327
import org.mapsforge.map.layer.cache.TileCache;
28+
import org.mapsforge.map.layer.overlay.Marker;
2429
import org.mapsforge.map.layer.renderer.TileRendererLayer;
2530
import org.mapsforge.map.reader.MapFile;
2631
import org.mapsforge.map.rendertheme.internal.MapsforgeThemes;
@@ -33,11 +38,11 @@
3338
import space.itoncek.trailcompass.app.R;
3439
import space.itoncek.trailcompass.app.hideandseek.api.HideAndSeekAPIFactory;
3540
import space.itoncek.trailcompass.app.hideandseek.seeker_ui.SeekerMapView;
41+
import space.itoncek.trailcompass.app.utils.MapUtils;
3642
import space.itoncek.trailcompass.client.api.HideAndSeekAPI;
3743

3844
public class HiderMapView extends AppCompatActivity {
3945
private HideAndSeekAPI api;
40-
private org.mapsforge.map.android.view.MapView mapView;
4146
File mapfile;
4247

4348
@Override
@@ -53,10 +58,9 @@ protected void onCreate(Bundle savedInstanceState) {
5358
AndroidGraphicFactory.createInstance(getApplication());
5459

5560
mapfile = new File(getCacheDir() + "/map.map");
56-
mapView = findViewById(R.id.map_mapview);
5761
api = new HideAndSeekAPIFactory(getFilesDir()).generateHideAndSeekAPI();
5862

59-
if(amIHider()) {
63+
if (amIHider()) {
6064
showAdminView();
6165
setUsername();
6266
setupTimer();
@@ -72,12 +76,12 @@ protected void onCreate(Bundle savedInstanceState) {
7276
private boolean amIHider() {
7377
AtomicBoolean result = new AtomicBoolean(false);
7478
CountDownLatch cdl = new CountDownLatch(1);
75-
runOnBackgroundThread(()-> {
79+
runOnBackgroundThread(() -> {
7680
try {
7781
result.set(api.amIHider());
7882
cdl.countDown();
7983
} catch (IOException e) {
80-
Log.e(HiderMapView.class.getName(),"Unable to determine if I'm a hider or not",e);
84+
Log.e(HiderMapView.class.getName(), "Unable to determine if I'm a hider or not", e);
8185
}
8286
});
8387
try {
@@ -89,7 +93,7 @@ private boolean amIHider() {
8993
}
9094

9195
private void setupButtons() {
92-
findViewById(R.id.map_resetButton).setOnClickListener((c)-> {
96+
findViewById(R.id.map_resetButton).setOnClickListener((c) -> {
9397
setUsername();
9498
showAdminView();
9599
setupTimer();
@@ -102,10 +106,10 @@ private void setupTimer() {
102106
}
103107

104108
private void setUsername() {
105-
Thread t = new Thread(()-> {
109+
Thread t = new Thread(() -> {
106110
try {
107111
String name = api.myName();
108-
runOnUiThread(()-> ((TextView)findViewById(R.id.map_username)).setText(name));
112+
runOnUiThread(() -> ((TextView) findViewById(R.id.map_username)).setText(name));
109113
} catch (IOException e) {
110114
Log.e(HiderMapView.class.getName(), "Unable to contact the main server", e);
111115
}
@@ -114,12 +118,12 @@ private void setUsername() {
114118
}
115119

116120
private void showAdminView() {
117-
Thread t = new Thread(()-> {
121+
Thread t = new Thread(() -> {
118122
try {
119123
if (api.amIAdmin()) {
120-
runOnUiThread(()->findViewById(R.id.map_switchToSettings).setVisibility(VISIBLE));
124+
runOnUiThread(() -> findViewById(R.id.map_switchToSettings).setVisibility(VISIBLE));
121125
} else {
122-
runOnUiThread(()->findViewById(R.id.map_switchToSettings).setVisibility(GONE));
126+
runOnUiThread(() -> findViewById(R.id.map_switchToSettings).setVisibility(GONE));
123127
}
124128
} catch (IOException e) {
125129
Log.e(HiderMapView.class.getName(), "Unable to contact the main server", e);
@@ -129,29 +133,48 @@ private void showAdminView() {
129133
}
130134

131135
private void openMap() {
132-
mapView.setClickable(true);
133-
mapView.getMapScaleBar().setVisible(true);
134-
mapView.setBuiltInZoomControls(true);
136+
MapView mw = new MapView(this);
137+
mw.setClickable(true);
138+
mw.getMapScaleBar().setVisible(true);
139+
mw.setBuiltInZoomControls(true);
135140

136141
Parameters.NUMBER_OF_THREADS = 8;
137142
Parameters.ANTI_ALIASING = true;
138143
Parameters.PARENT_TILES_RENDERING = Parameters.ParentTilesRendering.SPEED;
139144

140145
TileCache tileCache = AndroidUtil.createTileCache(this, "mapcache",
141-
mapView.getModel().displayModel.getTileSize(), 1f,
142-
mapView.getModel().frameBufferModel.getOverdrawFactor());
146+
mw.getModel().displayModel.getTileSize(), 1f,
147+
mw.getModel().frameBufferModel.getOverdrawFactor());
143148

144149
MapDataStore mapDataStore = new MapFile(mapfile);
145150
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
146-
mapView.getModel().mapViewPosition, AndroidGraphicFactory.INSTANCE);
151+
mw.getModel().mapViewPosition, AndroidGraphicFactory.INSTANCE);
147152
tileRendererLayer.setCacheTileMargin(1);
148153
tileRendererLayer.setCacheZoomMinus(1);
149154
tileRendererLayer.setCacheZoomPlus(2);
150155
tileRendererLayer.setXmlRenderTheme(MapsforgeThemes.OSMARENDER);
151156

152-
mapView.getLayerManager().getLayers().add(tileRendererLayer);
157+
Layers layers = mw.getLayerManager().getLayers();
158+
layers.add(tileRendererLayer);
159+
160+
Marker m1 = MapUtils.createMarker(this, R.drawable.location_marker_blue, new LatLong(50.0835035, 14.4341259));
161+
Marker m2 = MapUtils.createMarker(this, R.drawable.location_marker_green, new LatLong(50.0948317, 14.4158918));
162+
Marker m3 = MapUtils.createMarker(this, R.drawable.location_marker_red, new LatLong(50.0833949, 14.3950736));
163+
Marker m4 = MapUtils.createMarker(this, R.drawable.location_marker_orange, new LatLong(50.0637249, 14.4165013));
164+
165+
layers.add(m1);
166+
layers.add(m2);
167+
layers.add(m3);
168+
layers.add(m4);
169+
170+
mw.setCenter(mapDataStore.startPosition());
171+
mw.setZoomLevel(mapDataStore.startZoomLevel());
172+
View C = findViewById(R.id.map_mapview);
173+
ViewGroup parent = (ViewGroup) C.getParent();
174+
int index = parent.indexOfChild(C);
175+
parent.removeView(C);
176+
C = mw;
177+
parent.addView(C, index);
153178

154-
mapView.setCenter(mapDataStore.startPosition());
155-
mapView.setZoomLevel(mapDataStore.startZoomLevel());
156179
}
157180
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package space.itoncek.trailcompass.app.utils;
2+
3+
import android.annotation.TargetApi;
4+
import android.app.Activity;
5+
import android.content.Context;
6+
import android.graphics.BitmapFactory;
7+
import android.graphics.drawable.BitmapDrawable;
8+
import android.graphics.drawable.Drawable;
9+
import android.view.View;
10+
import android.widget.Toast;
11+
12+
import org.mapsforge.core.graphics.Bitmap;
13+
import org.mapsforge.core.graphics.Paint;
14+
import org.mapsforge.core.graphics.Style;
15+
import org.mapsforge.core.model.LatLong;
16+
import org.mapsforge.core.model.Point;
17+
import org.mapsforge.map.android.graphics.AndroidBitmap;
18+
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
19+
import org.mapsforge.map.android.view.MapView;
20+
import org.mapsforge.map.layer.overlay.Marker;
21+
22+
public class MapUtils {
23+
/**
24+
* Compatibility method.
25+
*
26+
* @param a the current activity
27+
*/
28+
public static void enableHome(Activity a) {
29+
// Show the Up button in the action bar.
30+
a.getActionBar().setDisplayHomeAsUpEnabled(true);
31+
}
32+
33+
/**
34+
* Compatibility method.
35+
*
36+
* @param view the view to set the background on
37+
* @param background the background
38+
*/
39+
public static void setBackground(View view, Drawable background) {
40+
view.setBackground(background);
41+
}
42+
43+
public static Marker createMarker(Context c, int resourceIdentifier, LatLong latLong) {
44+
Bitmap bitmap = new AndroidBitmap(BitmapFactory.decodeResource(c.getResources(), resourceIdentifier));
45+
return new Marker(latLong, bitmap, 0, -bitmap.getHeight() / 2);
46+
}
47+
48+
public static Paint createPaint(int color, int strokeWidth, Style style) {
49+
Paint paint = AndroidGraphicFactory.INSTANCE.createPaint();
50+
paint.setColor(color);
51+
paint.setStrokeWidth(strokeWidth);
52+
paint.setStyle(style);
53+
return paint;
54+
}
55+
56+
public static Marker createTappableMarker(Context c, int resourceIdentifier, LatLong latLong, MapView mapView) {
57+
Bitmap bitmap = new AndroidBitmap(BitmapFactory.decodeResource(c.getResources(), resourceIdentifier));
58+
bitmap.incrementRefCount();
59+
return new Marker(latLong, bitmap, 0, -bitmap.getHeight() / 2) {
60+
@Override
61+
public boolean onLongPress(LatLong tapLatLong, Point layerXY, Point tapXY) {
62+
if (contains(layerXY, tapXY, mapView)) {
63+
Toast.makeText(c, "Marker long press\n" + tapLatLong, Toast.LENGTH_SHORT).show();
64+
return true;
65+
}
66+
return false;
67+
}
68+
69+
@Override
70+
public boolean onTap(LatLong tapLatLong, Point layerXY, Point tapXY) {
71+
if (contains(layerXY, tapXY, mapView)) {
72+
Toast.makeText(c, "Marker tap\n" + tapLatLong, Toast.LENGTH_SHORT).show();
73+
return true;
74+
}
75+
return false;
76+
}
77+
};
78+
}
79+
80+
@SuppressWarnings("deprecation")
81+
public static Bitmap viewToBitmap(Context c, View view) {
82+
view.measure(View.MeasureSpec.getSize(view.getMeasuredWidth()),
83+
View.MeasureSpec.getSize(view.getMeasuredHeight()));
84+
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
85+
view.setDrawingCacheEnabled(true);
86+
Drawable drawable = new BitmapDrawable(c.getResources(),
87+
android.graphics.Bitmap.createBitmap(view.getDrawingCache()));
88+
view.setDrawingCacheEnabled(false);
89+
return AndroidGraphicFactory.convertToBitmap(drawable);
90+
}
91+
92+
private MapUtils() {
93+
throw new IllegalStateException();
94+
}
95+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="200sp"
3+
android:height="200sp"
4+
android:viewportWidth="1000"
5+
android:viewportHeight="1000">
6+
<path
7+
android:fillColor="@color/marker_blue"
8+
android:pathData="m500 150c193.2 0 350 156.8 350 350c0 193.2 -156.8 350 -350 350c-193.2 0 -350 -156.8 -350 -350c0 -193.2 156.8 -350 350 -350z" />
9+
<path
10+
android:fillColor="@color/marker_blue"
11+
android:pathData="m500 108.5c216.1 0 391.5 175.4 391.5 391.5c0 216.1 -175.4 391.5 -391.5 391.5c-216.1 0 -391.5 -175.4 -391.5 -391.5c0 -216.1 175.4 -391.5 391.5 -391.5zm0 -58.5c-248.4 0 -450 201.6 -450 450c0 248.4 201.6 450 450 450c248.4 0 450 -201.6 450 -450c0 -248.4 -201.6 -450 -450 -450z" />
12+
<path
13+
android:fillColor="@color/marker_blue"
14+
android:pathData="m500 20c264.9 0 480 215.1 480 480c0 264.9 -215.1 480 -480 480c-264.9 0 -480 -215.1 -480 -480c0 -264.9 215.1 -480 480 -480zm0 -20c-276 0 -500 224 -500 500c0 276 224 500 500 500c276 0 500 -224 500 -500c0 -276 -224 -500 -500 -500z" />
15+
</vector>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="200sp"
3+
android:height="200sp"
4+
android:viewportWidth="1000"
5+
android:viewportHeight="1000">
6+
<path
7+
android:fillColor="@color/marker_green"
8+
android:pathData="m500 150c193.2 0 350 156.8 350 350c0 193.2 -156.8 350 -350 350c-193.2 0 -350 -156.8 -350 -350c0 -193.2 156.8 -350 350 -350z" />
9+
<path
10+
android:fillColor="@color/marker_green"
11+
android:pathData="m500 108.5c216.1 0 391.5 175.4 391.5 391.5c0 216.1 -175.4 391.5 -391.5 391.5c-216.1 0 -391.5 -175.4 -391.5 -391.5c0 -216.1 175.4 -391.5 391.5 -391.5zm0 -58.5c-248.4 0 -450 201.6 -450 450c0 248.4 201.6 450 450 450c248.4 0 450 -201.6 450 -450c0 -248.4 -201.6 -450 -450 -450z" />
12+
<path
13+
android:fillColor="@color/marker_green"
14+
android:pathData="m500 20c264.9 0 480 215.1 480 480c0 264.9 -215.1 480 -480 480c-264.9 0 -480 -215.1 -480 -480c0 -264.9 215.1 -480 480 -480zm0 -20c-276 0 -500 224 -500 500c0 276 224 500 500 500c276 0 500 -224 500 -500c0 -276 -224 -500 -500 -500z" />
15+
</vector>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="200sp"
3+
android:height="200sp"
4+
android:viewportWidth="1000"
5+
android:viewportHeight="1000">
6+
<path
7+
android:fillColor="@color/marker_orange"
8+
android:pathData="m500 150c193.2 0 350 156.8 350 350c0 193.2 -156.8 350 -350 350c-193.2 0 -350 -156.8 -350 -350c0 -193.2 156.8 -350 350 -350z" />
9+
<path
10+
android:fillColor="@color/marker_orange"
11+
android:pathData="m500 108.5c216.1 0 391.5 175.4 391.5 391.5c0 216.1 -175.4 391.5 -391.5 391.5c-216.1 0 -391.5 -175.4 -391.5 -391.5c0 -216.1 175.4 -391.5 391.5 -391.5zm0 -58.5c-248.4 0 -450 201.6 -450 450c0 248.4 201.6 450 450 450c248.4 0 450 -201.6 450 -450c0 -248.4 -201.6 -450 -450 -450z" />
12+
<path
13+
android:fillColor="@color/marker_orange"
14+
android:pathData="m500 20c264.9 0 480 215.1 480 480c0 264.9 -215.1 480 -480 480c-264.9 0 -480 -215.1 -480 -480c0 -264.9 215.1 -480 480 -480zm0 -20c-276 0 -500 224 -500 500c0 276 224 500 500 500c276 0 500 -224 500 -500c0 -276 -224 -500 -500 -500z" />
15+
</vector>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="200sp"
3+
android:height="200sp"
4+
android:viewportWidth="1000"
5+
android:viewportHeight="1000">
6+
<path
7+
android:fillColor="@color/marker_red"
8+
android:pathData="m500 150c193.2 0 350 156.8 350 350c0 193.2 -156.8 350 -350 350c-193.2 0 -350 -156.8 -350 -350c0 -193.2 156.8 -350 350 -350z" />
9+
<path
10+
android:fillColor="@color/marker_red"
11+
android:pathData="m500 108.5c216.1 0 391.5 175.4 391.5 391.5c0 216.1 -175.4 391.5 -391.5 391.5c-216.1 0 -391.5 -175.4 -391.5 -391.5c0 -216.1 175.4 -391.5 391.5 -391.5zm0 -58.5c-248.4 0 -450 201.6 -450 450c0 248.4 201.6 450 450 450c248.4 0 450 -201.6 450 -450c0 -248.4 -201.6 -450 -450 -450z" />
12+
<path
13+
android:fillColor="@color/marker_red"
14+
android:pathData="m500 20c264.9 0 480 215.1 480 480c0 264.9 -215.1 480 -480 480c-264.9 0 -480 -215.1 -480 -480c0 -264.9 215.1 -480 480 -480zm0 -20c-276 0 -500 224 -500 500c0 276 224 500 500 500c276 0 500 -224 500 -500c0 -276 -224 -500 -500 -500z" />
15+
</vector>

app/src/main/res/values/colors.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@
99
<color name="design_blue_black">#2058DD</color>
1010
<color name="design_red_white">#FDEBEB</color>
1111
<color name="design_red_black">#E71D1D</color>
12+
<color name="marker_blue">#00ADFF</color>
13+
<color name="marker_red">#FF1616</color>
14+
<color name="marker_green">#9DFF56</color>
15+
<color name="marker_orange">#FF7A2F</color>
1216
</resources>

0 commit comments

Comments
 (0)