-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOsmAndAidlHelper.java
More file actions
2069 lines (1929 loc) · 72 KB
/
OsmAndAidlHelper.java
File metadata and controls
2069 lines (1929 loc) · 72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main.java.net.osmand.osmandapidemo;
import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.KeyEvent;
import android.util.Log;
//import android.widget.Toast;
import net.osmand.aidlapi.IOsmAndAidlCallback;
import net.osmand.aidlapi.IOsmAndAidlInterface;
import net.osmand.aidlapi.contextmenu.AContextMenuButton;
import net.osmand.aidlapi.contextmenu.ContextMenuButtonsParams;
import net.osmand.aidlapi.contextmenu.RemoveContextMenuButtonsParams;
import net.osmand.aidlapi.contextmenu.UpdateContextMenuButtonsParams;
import net.osmand.aidlapi.copyfile.CopyFileParams;
import net.osmand.aidlapi.customization.CustomizationInfoParams;
import net.osmand.aidlapi.customization.MapMarginsParams;
import net.osmand.aidlapi.customization.OsmandSettingsInfoParams;
import net.osmand.aidlapi.customization.OsmandSettingsParams;
import net.osmand.aidlapi.customization.ProfileSettingsParams;
import net.osmand.aidlapi.customization.SetWidgetsParams;
import net.osmand.aidlapi.favorite.AFavorite;
import net.osmand.aidlapi.favorite.AddFavoriteParams;
import net.osmand.aidlapi.favorite.RemoveFavoriteParams;
import net.osmand.aidlapi.favorite.UpdateFavoriteParams;
import net.osmand.aidlapi.favorite.group.AFavoriteGroup;
import net.osmand.aidlapi.favorite.group.AddFavoriteGroupParams;
import net.osmand.aidlapi.favorite.group.RemoveFavoriteGroupParams;
import net.osmand.aidlapi.favorite.group.UpdateFavoriteGroupParams;
import net.osmand.aidlapi.gpx.AGpxBitmap;
import net.osmand.aidlapi.gpx.AGpxFile;
import net.osmand.aidlapi.gpx.ASelectedGpxFile;
import net.osmand.aidlapi.gpx.CreateGpxBitmapParams;
import net.osmand.aidlapi.gpx.HideGpxParams;
import net.osmand.aidlapi.gpx.ImportGpxParams;
import net.osmand.aidlapi.gpx.RemoveGpxParams;
import net.osmand.aidlapi.gpx.ShowGpxParams;
import net.osmand.aidlapi.gpx.StartGpxRecordingParams;
import net.osmand.aidlapi.gpx.StopGpxRecordingParams;
import net.osmand.aidlapi.map.ALatLon;
import net.osmand.aidlapi.map.SetMapLocationParams;
import net.osmand.aidlapi.maplayer.AMapLayer;
import net.osmand.aidlapi.maplayer.AddMapLayerParams;
import net.osmand.aidlapi.maplayer.RemoveMapLayerParams;
import net.osmand.aidlapi.maplayer.UpdateMapLayerParams;
import net.osmand.aidlapi.maplayer.point.AMapPoint;
import net.osmand.aidlapi.maplayer.point.AddMapPointParams;
import net.osmand.aidlapi.maplayer.point.RemoveMapPointParams;
import net.osmand.aidlapi.maplayer.point.ShowMapPointParams;
import net.osmand.aidlapi.maplayer.point.UpdateMapPointParams;
import net.osmand.aidlapi.mapmarker.AMapMarker;
import net.osmand.aidlapi.mapmarker.AddMapMarkerParams;
import net.osmand.aidlapi.mapmarker.RemoveMapMarkerParams;
import net.osmand.aidlapi.mapmarker.RemoveMapMarkersParams;
import net.osmand.aidlapi.mapmarker.UpdateMapMarkerParams;
import net.osmand.aidlapi.mapwidget.AMapWidget;
import net.osmand.aidlapi.mapwidget.AddMapWidgetParams;
import net.osmand.aidlapi.mapwidget.RemoveMapWidgetParams;
import net.osmand.aidlapi.mapwidget.UpdateMapWidgetParams;
import net.osmand.aidlapi.navdrawer.NavDrawerFooterParams;
import net.osmand.aidlapi.navdrawer.NavDrawerHeaderParams;
import net.osmand.aidlapi.navdrawer.NavDrawerItem;
import net.osmand.aidlapi.navdrawer.SetNavDrawerItemsParams;
import net.osmand.aidlapi.navigation.ABlockedRoad;
import net.osmand.aidlapi.navigation.ADirectionInfo;
import net.osmand.aidlapi.navigation.ANavigationUpdateParams;
import net.osmand.aidlapi.navigation.ANavigationVoiceRouterMessageParams;
import net.osmand.aidlapi.navigation.AddBlockedRoadParams;
import net.osmand.aidlapi.navigation.MuteNavigationParams;
import net.osmand.aidlapi.navigation.NavigateGpxParams;
import net.osmand.aidlapi.navigation.NavigateParams;
import net.osmand.aidlapi.navigation.NavigateSearchParams;
import net.osmand.aidlapi.navigation.OnVoiceNavigationParams;
import net.osmand.aidlapi.navigation.PauseNavigationParams;
import net.osmand.aidlapi.navigation.RemoveBlockedRoadParams;
import net.osmand.aidlapi.navigation.ResumeNavigationParams;
import net.osmand.aidlapi.navigation.StopNavigationParams;
import net.osmand.aidlapi.navigation.UnmuteNavigationParams;
import net.osmand.aidlapi.note.StartAudioRecordingParams;
import net.osmand.aidlapi.note.StartVideoRecordingParams;
import net.osmand.aidlapi.note.StopRecordingParams;
import net.osmand.aidlapi.note.TakePhotoNoteParams;
import net.osmand.aidlapi.plugins.PluginParams;
import net.osmand.aidlapi.profile.ExportProfileParams;
import net.osmand.aidlapi.profile.AExportSettingsType;
import net.osmand.aidlapi.search.SearchParams;
import net.osmand.aidlapi.search.SearchResult;
import net.osmand.aidlapi.tiles.ASqliteDbFile;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import main.java.net.osmand.osmandapidemo.OsmAndHelper.OnOsmandMissingListener;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_IO_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_MAX_LOCK_TIME_MS;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PARAMS_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PART_SIZE_LIMIT;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PART_SIZE_LIMIT_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_UNSUPPORTED_FILE_TYPE_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.OK_RESPONSE;
public class OsmAndAidlHelper implements OnOsmandMissingListener {
private static final String OSMAND_FREE_PACKAGE_NAME = "net.osmand";
private static final String OSMAND_PLUS_PACKAGE_NAME = "net.osmand.plus";
private static final String OSMAND_PACKAGE_NAME = OSMAND_FREE_PACKAGE_NAME;
private static final int MAX_RETRY_COUNT = 10;
private static final long BUFFER_SIZE = COPY_FILE_PART_SIZE_LIMIT;
private final Application app;
private final OnOsmandMissingListener mOsmandMissingListener;
private IOsmAndAidlInterface mIOsmAndAidlInterface;
private SearchCompleteListener mSearchCompleteListener;
private UpdateListener updateListener;
private OsmandInitializedListener osmandInitializedListener;
private GpxBitmapCreatedListener gpxBitmapCreatedListener;
private NavigationInfoUpdateListener navigationInfoUpdateListener;
private ContextButtonClickListener contextButtonClickListener;
private VoiceRouterNotifyListener voiceRouterNotifyListener;
public void osmandMissing() {
Log.w("python","OsmAnd was not found!");
}
interface SearchCompleteListener {
void onSearchComplete(List<SearchResult> resultSet);
}
interface UpdateListener {
void onUpdatePing();
}
interface OsmandInitializedListener {
void onOsmandInitilized();
}
interface GpxBitmapCreatedListener {
void onGpxBitmapCreated(Bitmap bitmap);
}
interface NavigationInfoUpdateListener {
void onNavigationInfoUpdate(ADirectionInfo directionInfo);
}
interface ContextButtonClickListener {
void onContextButtonClick(int buttonId, String pointId, String layerId);
}
interface VoiceRouterNotifyListener {
void onVoiceRouterNotify(OnVoiceNavigationParams params);
}
private IOsmAndAidlCallback.Stub mIOsmAndAidlCallback = new IOsmAndAidlCallback.Stub() {
@Override
public void onSearchComplete(List<SearchResult> resultSet) throws RemoteException {
if (mSearchCompleteListener != null) {
mSearchCompleteListener.onSearchComplete(resultSet);
}
}
@Override
public void onUpdate() {
if (updateListener != null) {
updateListener.onUpdatePing();
}
}
@Override
public void onAppInitialized() {
if (osmandInitializedListener != null) {
osmandInitializedListener.onOsmandInitilized();
}
}
@Override
public void onGpxBitmapCreated(AGpxBitmap bitmap) {
if (gpxBitmapCreatedListener != null) {
gpxBitmapCreatedListener.onGpxBitmapCreated(bitmap.getBitmap());
}
}
@Override
public void updateNavigationInfo(ADirectionInfo directionInfo) {
if (navigationInfoUpdateListener != null) {
navigationInfoUpdateListener.onNavigationInfoUpdate(directionInfo);
}
}
@Override
public void onContextMenuButtonClicked(int buttonId, String pointId, String layerId) {
if (contextButtonClickListener != null) {
contextButtonClickListener.onContextButtonClick(buttonId, pointId, layerId);
}
}
@Override
public void onVoiceRouterNotify(OnVoiceNavigationParams params) throws RemoteException {
if (voiceRouterNotifyListener != null) {
voiceRouterNotifyListener.onVoiceRouterNotify(params);
}
}
@Override
public void onKeyEvent(KeyEvent keyEvent) throws RemoteException {
}
};
public void setSearchCompleteListener(SearchCompleteListener mSearchCompleteListener) {
this.mSearchCompleteListener = mSearchCompleteListener;
}
public void setUpdateListener(UpdateListener updateListener) {
this.updateListener = updateListener;
}
public void setOsmandInitializedListener(OsmandInitializedListener osmandInitializedListener) {
this.osmandInitializedListener = osmandInitializedListener;
}
public void setGpxBitmapCreatedListener(GpxBitmapCreatedListener gpxBitmapCreatedListener) {
this.gpxBitmapCreatedListener = gpxBitmapCreatedListener;
}
public void setNavigationInfoUpdateListener(NavigationInfoUpdateListener navigationInfoUpdateListener) {
this.navigationInfoUpdateListener = navigationInfoUpdateListener;
}
public void setContextButtonClickListener(ContextButtonClickListener contextButtonClickListener) {
this.contextButtonClickListener = contextButtonClickListener;
}
public void setVoiceRouterNotifyListener(VoiceRouterNotifyListener voiceRouterNotifyListener) {
this.voiceRouterNotifyListener = voiceRouterNotifyListener;
}
/**
* Class for interacting with the main interface of the service.
*/
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className,
IBinder service) {
// This is called when the connection with the service has been
// established, giving us the service object we can use to
// interact with the service. We are communicating with our
// service through an IDL interface, so get a client-side
// representation of that from the raw service object.
mIOsmAndAidlInterface = IOsmAndAidlInterface.Stub.asInterface(service);
Log.i("python","OsmAnd Service Connected");
//Toast.makeText(app, "OsmAnd service connected", Toast.LENGTH_SHORT).show();
}
public void onServiceDisconnected(ComponentName className) {
// This is called when the connection with the service has been
// unexpectedly disconnected -- that is, its process crashed.
mIOsmAndAidlInterface = null;
Log.w("python","OsmAnd service disconnected");
//Toast.makeText(app, "OsmAnd service disconnected", Toast.LENGTH_SHORT).show();
}
};
public OsmAndAidlHelper(Application application) {
this.app = application;
this.mOsmandMissingListener = this;
bindService();
}
private boolean bindService() {
if (mIOsmAndAidlInterface == null) {
Intent intent = new Intent("net.osmand.aidl.OsmandAidlServiceV2");
intent.setPackage(OSMAND_PACKAGE_NAME);
boolean res = app.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
if (res) {
Log.i("python","OsmAnd Service bound");
//Toast.makeText(app, "OsmAnd service bind", Toast.LENGTH_SHORT).show();
return true;
} else {
Log.w("python","OsmAnd service NOT bound");
//Toast.makeText(app, "OsmAnd service NOT bind", Toast.LENGTH_SHORT).show();
mOsmandMissingListener.osmandMissing();
return false;
}
} else {
return true;
}
}
public void cleanupResources() {
if (mIOsmAndAidlInterface != null) {
app.unbindService(mConnection);
}
}
/**
* Refresh the map (UI)
*/
public boolean refreshMap() {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.refreshMap();
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Add favorite group with given params.
*
* @param name - group name.
* @param color - group color. Can be one of: "red", "orange", "yellow",
* "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown".
* @param visible - group visibility.
*/
public boolean addFavoriteGroup(String name, String color, boolean visible) {
if (mIOsmAndAidlInterface != null) {
try {
AFavoriteGroup favoriteGroup = new AFavoriteGroup(name, color, visible);
return mIOsmAndAidlInterface.addFavoriteGroup(new AddFavoriteGroupParams(favoriteGroup));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Update favorite group with given params.
*
* @param namePrev - group name (current).
* @param colorPrev - group color (current).
* @param visiblePrev - group visibility (current).
* @param nameNew - group name (new).
* @param colorNew - group color (new).
* @param visibleNew - group visibility (new).
*/
public boolean updateFavoriteGroup(String namePrev, String colorPrev, boolean visiblePrev,
String nameNew, String colorNew, boolean visibleNew) {
if (mIOsmAndAidlInterface != null) {
try {
AFavoriteGroup favoriteGroupPrev = new AFavoriteGroup(namePrev, colorPrev, visiblePrev);
AFavoriteGroup favoriteGroupNew = new AFavoriteGroup(nameNew, colorNew, visibleNew);
return mIOsmAndAidlInterface.updateFavoriteGroup(new UpdateFavoriteGroupParams(favoriteGroupPrev, favoriteGroupNew));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Remove favorite group with given name.
*
* @param name - name of favorite group.
*/
public boolean removeFavoriteGroup(String name) {
if (mIOsmAndAidlInterface != null) {
try {
AFavoriteGroup favoriteGroup = new AFavoriteGroup(name, "", false);
return mIOsmAndAidlInterface.removeFavoriteGroup(new RemoveFavoriteGroupParams(favoriteGroup));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Add favorite at given location with given params.
*
* @param lat - latitude.
* @param lon - longitude.
* @param name - name of favorite item.
* @param description - description of favorite item.
* @param category - category of favorite item.
* @param color - color of favorite item. Can be one of: "red", "orange", "yellow",
* "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown".
* @param visible - should favorite item be visible after creation.
*/
public boolean addFavorite(double lat, double lon, String name, String description, String address,
String category, String color, boolean visible) {
if (mIOsmAndAidlInterface != null) {
try {
AFavorite favorite = new AFavorite(lat, lon, name, description,address, category, color, visible);
return mIOsmAndAidlInterface.addFavorite(new AddFavoriteParams(favorite));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Update favorite at given location with given params.
*
* @param latPrev - latitude (current favorite).
* @param lonPrev - longitude (current favorite).
* @param namePrev - name of favorite item (current favorite).
* @param categoryPrev - category of favorite item (current favorite).
* @param latNew - latitude (new favorite).
* @param lonNew - longitude (new favorite).
* @param nameNew - name of favorite item (new favorite).
* @param descriptionNew - description of favorite item (new favorite).
* @param categoryNew - category of favorite item (new favorite). Use only to create a new category,
* not to update an existing one. If you want to update an existing category,
* use the {@link #updateFavoriteGroup(String, String, boolean, String, String, boolean)} method.
* @param colorNew - color of new category. Can be one of: "red", "orange", "yellow",
* "lightgreen", "green", "lightblue", "blue", "purple", "pink", "brown".
* @param visibleNew - should new category be visible after creation.
*/
public boolean updateFavorite(double latPrev, double lonPrev, String namePrev, String categoryPrev,
double latNew, double lonNew, String nameNew, String descriptionNew,
String categoryNew, String colorNew, boolean visibleNew) {
if (mIOsmAndAidlInterface != null) {
try {
AFavorite favoritePrev = new AFavorite(latPrev, lonPrev, namePrev, "","", categoryPrev, "", false);
AFavorite favoriteNew = new AFavorite(latNew, lonNew, nameNew, descriptionNew,"", categoryNew, colorNew, visibleNew);
return mIOsmAndAidlInterface.updateFavorite(new UpdateFavoriteParams(favoritePrev, favoriteNew));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Remove favorite at given location with given params.
*
* @param lat - latitude.
* @param lon - longitude.
* @param name - name of favorite item.
* @param category - category of favorite item.
*/
public boolean removeFavorite(double lat, double lon, String name, String category) {
if (mIOsmAndAidlInterface != null) {
try {
AFavorite favorite = new AFavorite(lat, lon, name, "","", category, "", false);
return mIOsmAndAidlInterface.removeFavorite(new RemoveFavoriteParams(favorite));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Add map marker at given location.
*
* @param lat - latitude.
* @param lon - longitude.
* @param name - name.
*/
public boolean addMapMarker(double lat, double lon, String name) {
if (mIOsmAndAidlInterface != null) {
try {
AMapMarker marker = new AMapMarker(new ALatLon(lat, lon), name);
return mIOsmAndAidlInterface.addMapMarker(new AddMapMarkerParams(marker));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Update map marker at given location with name.
*
* @param latPrev - latitude (current marker).
* @param lonPrev - longitude (current marker).
* @param namePrev - name (current marker).
* @param latNew - latitude (new marker).
* @param lonNew - longitude (new marker).
* @param nameNew - name (new marker).
*/
public boolean updateMapMarker(double latPrev, double lonPrev, String namePrev,
double latNew, double lonNew, String nameNew) {
if (mIOsmAndAidlInterface != null) {
try {
AMapMarker markerPrev = new AMapMarker(new ALatLon(latPrev, lonPrev), namePrev);
AMapMarker markerNew = new AMapMarker(new ALatLon(latNew, lonNew), nameNew);
return mIOsmAndAidlInterface.updateMapMarker(new UpdateMapMarkerParams(markerPrev, markerNew));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Remove map marker at given location with name.
*
* @param lat - latitude.
* @param lon - longitude.
* @param name - name.
*/
public boolean removeMapMarker(double lat, double lon, String name) {
if (mIOsmAndAidlInterface != null) {
try {
AMapMarker marker = new AMapMarker(new ALatLon(lat, lon), name);
return mIOsmAndAidlInterface.removeMapMarker(new RemoveMapMarkerParams(marker));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Add map widget to the right side of the main screen.
* Note: any specified icon should exist in OsmAnd app resources.
*
* @param id - widget id.
* @param menuIconName - icon name (configure map menu).
* @param menuTitle - widget name (configure map menu).
* @param lightIconName - icon name for the light theme (widget).
* @param darkIconName - icon name for the dark theme (widget).
* @param text - main widget text.
* @param description - sub text, like "km/h".
* @param order - order position in the widgets list.
* @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent).
*/
public boolean addMapWidget(String id, String menuIconName, String menuTitle,
String lightIconName, String darkIconName, String text, String description,
int order, Intent intentOnClick) {
if (mIOsmAndAidlInterface != null) {
try {
AMapWidget widget = new AMapWidget(id, menuIconName, menuTitle, lightIconName,
darkIconName, text, description, order, intentOnClick);
return mIOsmAndAidlInterface.addMapWidget(new AddMapWidgetParams(widget));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Update map widget.
* Note: any specified icon should exist in OsmAnd app resources.
*
* @param id - widget id.
* @param menuIconName - icon name (configure map menu).
* @param menuTitle - widget name (configure map menu).
* @param lightIconName - icon name for the light theme (widget).
* @param darkIconName - icon name for the dark theme (widget).
* @param text - main widget text.
* @param description - sub text, like "km/h".
* @param order - order position in the widgets list.
* @param intentOnClick - onClick intent. Called after click on widget as startActivity(Intent intent).
*/
public boolean updateMapWidget(String id, String menuIconName, String menuTitle,
String lightIconName, String darkIconName, String text, String description,
int order, Intent intentOnClick) {
if (mIOsmAndAidlInterface != null) {
try {
AMapWidget widget = new AMapWidget(id, menuIconName, menuTitle, lightIconName,
darkIconName, text, description, order, intentOnClick);
return mIOsmAndAidlInterface.updateMapWidget(new UpdateMapWidgetParams(widget));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Remove map widget.
*
* @param id - widget id.
*/
public boolean removeMapWidget(String id) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.removeMapWidget(new RemoveMapWidgetParams(id));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Add user layer on the map.
*
* @param id - layer id.
* @param name - layer name.
* @param zOrder - z-order position of layer. Default value is 5.5f
* @param points - initial list of points. Nullable.
* @param imagePoints - use new style for points on map or not. Also default zoom bounds for new style can be edited.
*/
public boolean addMapLayer(String id, String name, float zOrder, List<AMapPoint> points, boolean imagePoints) {
if (mIOsmAndAidlInterface != null) {
try {
AMapLayer layer = new AMapLayer(id, name, zOrder, points);
layer.setImagePoints(imagePoints);
return mIOsmAndAidlInterface.addMapLayer(new AddMapLayerParams(layer));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Update user layer.
*
* @param id - layer id.
* @param name - layer name.
* @param zOrder - z-order position of layer. Default value is 5.5f
* @param points - list of points. Nullable.
* @param imagePoints - use new style for points on map or not. Also default zoom bounds for new style can be edited.
*/
public boolean updateMapLayer(String id, String name, float zOrder, List<AMapPoint> points, boolean imagePoints) {
if (mIOsmAndAidlInterface != null) {
try {
AMapLayer layer = new AMapLayer(id, name, zOrder, points);
layer.setImagePoints(imagePoints);
return mIOsmAndAidlInterface.updateMapLayer(new UpdateMapLayerParams(layer));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Remove user layer.
*
* @param id - layer id.
*/
public boolean removeMapLayer(String id) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.removeMapLayer(new RemoveMapLayerParams(id));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Show AMapPoint on map in OsmAnd.
*
* @param layerId - layer id. Note: layer should be added first.
* @param pointId - point id.
* @param shortName - short name (single char). Displayed on the map.
* @param fullName - full name. Displayed in the context menu on first row.
* @param typeName - type name. Displayed in context menu on second row.
* @param color - color of circle's background.
* @param location - location of the point.
* @param details - list of details. Displayed under context menu.
* @param params - optional map of params for point.
*/
public boolean showMapPoint(String layerId, String pointId, String shortName, String fullName,
String typeName, int color, ALatLon location, List<String> details,
Map<String, String> params) {
if (mIOsmAndAidlInterface != null) {
try {
AMapPoint point = new AMapPoint(pointId, shortName, fullName, typeName, layerId, color, location, details, params);
return mIOsmAndAidlInterface.showMapPoint(new ShowMapPointParams(layerId, point));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Add point to user layer.
*
* @param layerId - layer id. Note: layer should be added first.
* @param pointId - point id.
* @param shortName - short name (single char). Displayed on the map.
* @param fullName - full name. Displayed in the context menu on first row.
* @param typeName - type name. Displayed in context menu on second row.
* @param color - color of circle's background.
* @param location - location of the point.
* @param details - list of details. Displayed under context menu.
* @param params - optional map of params for point.
*/
public boolean addMapPoint(String layerId, String pointId, String shortName, String fullName,
String typeName, int color, ALatLon location, List<String> details,
Map<String, String> params) {
if (mIOsmAndAidlInterface != null) {
try {
AMapPoint point = new AMapPoint(pointId, shortName, fullName, typeName, layerId, color, location, details, params);
return mIOsmAndAidlInterface.addMapPoint(new AddMapPointParams(layerId, point));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Update point.
*
* @param layerId - layer id.
* @param pointId - point id.
* @param shortName - short name (single char). Displayed on the map.
* @param fullName - full name. Displayed in the context menu on first row.
* @param typeName - type name. Displayed in context menu on second row.
* @param color - color of circle's background.
* @param location - location of the point.
* @param details - list of details. Displayed under context menu.
* @param params - optional map of params for point.
*/
public boolean updateMapPoint(String layerId, String pointId, String shortName, String fullName,
String typeName, int color, ALatLon location, List<String> details,
Map<String, String> params) {
if (mIOsmAndAidlInterface != null) {
try {
AMapPoint point = new AMapPoint(pointId, shortName, fullName, typeName, layerId, color, location, details, params);
return mIOsmAndAidlInterface.updateMapPoint(new UpdateMapPointParams(layerId, point, false));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Remove point.
*
* @param layerId - layer id.
* @param pointId - point id.
*/
public boolean removeMapPoint(String layerId, String pointId) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.removeMapPoint(new RemoveMapPointParams(layerId, pointId));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Import GPX file to OsmAnd.
* OsmAnd must have rights to access location. Not recommended.
*
* @param file - File which represents GPX track.
* @param fileName - Destination file name. May contain dirs.
* @param color - color of gpx. Can be one of: "red", "orange", "lightblue", "blue", "purple",
* "translucent_red", "translucent_orange", "translucent_lightblue",
* "translucent_blue", "translucent_purple"
* @param show - show track on the map after import
*/
public boolean importGpxFromFile(File file, String fileName, String color, boolean show) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.importGpx(new ImportGpxParams(file, fileName, color, show));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Import GPX file to OsmAnd.
*
* @param gpxUri - URI created by FileProvider.
* @param fileName - Destination file name. May contain dirs.
* @param color - color of gpx. Can be one of: "", "red", "orange", "lightblue", "blue", "purple",
* "translucent_red", "translucent_orange", "translucent_lightblue",
* "translucent_blue", "translucent_purple"
* @param show - show track on the map after import
*/
public boolean importGpxFromUri(Uri gpxUri, String fileName, String color, boolean show) {
if (mIOsmAndAidlInterface != null) {
try {
app.grantUriPermission(OSMAND_PACKAGE_NAME, gpxUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
return mIOsmAndAidlInterface.importGpx(new ImportGpxParams(gpxUri, fileName, color, show));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Start navigation using gpx file.
*
* @param gpxUri - URI created by FileProvider.
* @param force - ask to stop current navigation if any. False - ask. True - don't ask.
*/
public boolean navigateGpxFromUri(Uri gpxUri, boolean force, boolean needLocationPermission) {
if (mIOsmAndAidlInterface != null) {
try {
app.grantUriPermission(OSMAND_PACKAGE_NAME, gpxUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
return mIOsmAndAidlInterface.navigateGpx(new NavigateGpxParams(gpxUri, force, needLocationPermission));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Import GPX file to OsmAnd.
*
* @param data - Raw contents of GPX file. Sent as intent's extra string parameter.
* @param fileName - Destination file name. May contain dirs.
* @param color - color of gpx. Can be one of: "red", "orange", "lightblue", "blue", "purple",
* "translucent_red", "translucent_orange", "translucent_lightblue",
* "translucent_blue", "translucent_purple"
* @param show - show track on the map after import
*/
public boolean importGpxFromData(String data, String fileName, String color, boolean show) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.importGpx(new ImportGpxParams(data, fileName, color, show));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Start navigation using gpx file content.
*
* @param data - gpx file content.
* @param force - ask to stop current navigation if any. False - ask. True - don't ask.
*/
public boolean navigateGpxFromData(String data, boolean force, boolean needLocationPermission) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.navigateGpx(new NavigateGpxParams(data, force, needLocationPermission));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Show GPX file on map.
*
* @param fileName - file name to show. Must be imported first.
*/
public boolean showGpx(String fileName) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.showGpx(new ShowGpxParams(fileName));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Hide GPX file.
*
* @param fileName - file name to hide.
*/
public boolean hideGpx(String fileName) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.hideGpx(new HideGpxParams(fileName));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Get list of active GPX files.
*
* @return list of active gpx files.
*/
public List<ASelectedGpxFile> getActiveGpxFiles() {
if (mIOsmAndAidlInterface != null) {
try {
List<ASelectedGpxFile> res = new ArrayList<>();
if (mIOsmAndAidlInterface.getActiveGpx(res)) {
return res;
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
return null;
}
/**
* Remove GPX file.
*
* @param fileName - file name to remove;
*/
public boolean removeGpx(String fileName) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.removeGpx(new RemoveGpxParams(fileName));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Get list of active GPX files.
*
* @param latitude - latitude of new map center.
* @param longitude - longitude of new map center.
* @param zoom - map zoom level. Set 0 to keep zoom unchanged.
* @param animated - set true to animate changes.
*/
public boolean setMapLocation(double latitude, double longitude, int zoom, float rotation, boolean animated) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.setMapLocation(
new SetMapLocationParams(latitude, longitude, zoom, rotation, animated));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Start gpx recording.
*/
public boolean startGpxRecording() {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.startGpxRecording(new StartGpxRecordingParams());
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Stop gpx recording.
*/
public boolean stopGpxRecording() {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.stopGpxRecording(new StopGpxRecordingParams());
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Take photo note.
*
* @param lat - latutude of photo note.
* @param lon - longitude of photo note.
*/
public boolean takePhotoNote(double lat, double lon) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.takePhotoNote(new TakePhotoNoteParams(lat, lon));
} catch (RemoteException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Start video note recording.
*
* @param lat - latutude of video note point.
* @param lon - longitude of video note point.
*/
public boolean startVideoRecording(double lat, double lon) {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface.startVideoRecording(new StartVideoRecordingParams(lat, lon));
} catch (RemoteException e) {