/
TrackerActivity.java
executable file
·2680 lines (2451 loc) · 110 KB
/
TrackerActivity.java
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 com.davidmascharka.lips;
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.mascharka.indoorlocalization.R;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import weka.classifiers.functions.RBFRegressor;
import weka.classifiers.lazy.KStar;
import weka.classifiers.trees.RandomForest;
import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.Instances;
/**
* Copyright 2015 David Mascharka
*
* This file is part of LIPS (Learning-based Indoor Positioning System).
*
* LIPS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* LIPS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LIPS. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @author David Mascharka (david.mascharka@drake.edu)
*
* Tracking side of the application. This is what would be implemented as part of an
* enterprise-scale application that actually wanted to perform live localization.
*
* Most of this is unnecessary in an application that just wants to keep track of user
* position. Take out the buttons, the view, etc. The only part we really care about
* in getting user position is the sensor values, the attributes/instances,
* and the updateScanResults method
*
* It may be desirable to break this logic off to run in a service so that
* localization can be performed in the background so the user experiences
* no delay on re-opening the application or to notify the user when
* they reach an area of interest in, for example, navigation in a mall
*
*/
/*
* Last Updated: April 23, 2016
* author: Mahesh Gaya
* Description:
* --added M permission implementations
* --added some TODOs for buildings
* --enabled home button (arrow on top left of Tracker Activity
*/
public class TrackerActivity extends AppCompatActivity implements SensorEventListener,
SelectPartitionDialogFragment.SelectPartitionDialogListener,
ActivityCompat.OnRequestPermissionsResultCallback{
//TODO: Need to actually test the app in Marshmallow
//@author Mahesh Gaya added this tag for debugging purposes
private String TAG = "Permission Test (TrackerActivity): ";
//private static final int MY_PERMISSIONS = 13;
//@author Mahesh Gaya added these for permissions
private static final int REQUEST_LOCATION = 110;
private static final int REQUEST_WRITE_STORAGE = 112;
private static final int REQUEST_WIFI = 114;
/**
* The accelerometer reading in the X direction
*/
private float accelerometerX;
/**
* The accelerometer reading in the Y direction
*/
private float accelerometerY;
/**
* The accelerometer reading in the Z direction
*/
private float accelerometerZ;
/**
* Reading from the X direction of the magnetic sensor
*/
private float magneticX;
/**
* Reading from the Y direction of the magnetic sensor
*/
private float magneticY;
/**
* Reading from the Z direction of the magnetic sensor
*/
private float magneticZ;
/**
* Reading of the intensity from the light sensor
*/
private float light;
/**
* Amount of rotation in the X direction
*/
private float rotationX;
/**
* Amount of rotation in the Y direction
*/
private float rotationY;
/**
* Amount of rotation in the Z direction
*/
private float rotationZ;
/**
* Array holding rotation values - for querying
*/
private float[] rotation;
/**
* Array holding inclination values - for querying
*/
private float[] inclination;
/**
* Array holding orientation values - for querying
*/
private float[] orientation;
/**
* Displays the user's x coordinate (predicted)
*/
private TextView xText;
/**
* Displays the user's y coordinate (predicted)
*/
private TextView yText;
/**
* Overlays a grid so the user can more easily see where they are
*/
private GridView grid;
/**
* Lets us query the sensors in the device
*/
private SensorManager sensorManager;
/**
* Holds what sensors are embedded in the device
*/
private List<Sensor> sensorList;
/**
* Lets us actively scan for WiFi signals
*/
private WifiManager wifiManager;
/**
* Holds the results of an active scan for WiFi signals
*/
private List<ScanResult> scanResults;
/**
* Holds each BSSID of interest and its signal strength
*/
private LinkedHashMap<String, Integer> wifiReadings;
/**
* Lets us set up a listener for location changes
*/
private LocationManager locationManager;
/**
* Listens for changes to reported location
*/
private LocationListener locationListener;
/**
* The user's current location, as reported by GPS/Network
*/
private Location location;
/**
* Worker thread for performing localization
*/
Thread t;
/**
* Will listen for broadcasts from the WiFi manager. When a scan has finished, the
*onReceive method will be called which will recalculate the user's position
*/
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateScanResults();
}
};
/**
* Which building is the user in?
*/
private String building;
/**
* X coordinate to display to the user to walk to (for evaluating)
*/
private float nextX = 0.0f;
/**
* Y coordinate to display to the user to walk to (for evaluating)
*/
private float nextY = 0.0f;
/**
* Predicted X position of the user
*/
private float predictedX;
/**
* Predicted Y position of the user
*/
private float predictedY;
private Timestamp time;
File file;
File valuesFile;
FileOutputStream outputStream;
FileOutputStream valuesOutputStream;
PrintWriter writer;
PrintWriter valuesWriter;
private double predictedPartition;
/**
* K* classifier for predicting x position
*/
KStar classifierXKStar;
/**
* RBF regression classifier for predicting x position
*/
RBFRegressor classifierXRBFRegressor;
/**
* K* classifier for predicting y position
*/
KStar classifierYKStar;
/**
* RBF regression classifier for predicting y position
*/
RBFRegressor classifierYRBFRegressor;
/**
* K* classifier for just the lower left portion of the building, predicting x
*/
KStar partitionLowerLeftX = null;
/**
* K* classifier for just the lower right portion of the building, predicting x
*/
KStar partitionLowerRightX = null;
/**
* K* classifier for just the upper left portion of the building, predicting x
*/
KStar partitionUpperLeftX = null;
/**
* K* classifier for just the upper right portion of the building, predicting x
*/
KStar partitionUpperRightX = null;
/**
* K* classifier for just the middle portion of the building, predicting x
*/
KStar partitionMiddleX = null;
/**
* K* classifier for just the lower left portion of the building, predicting y
*/
KStar partitionLowerLeftY = null;
/**
* K* classifier for just the lower right portion of the building, predicting y
*/
KStar partitionLowerRightY = null;
/**
* K* classifier for just the upper left portion of the building, predicting y
*/
KStar partitionUpperLeftY = null;
/**
* K* classifier for just the upper right portion of the building, predicting y
*/
KStar partitionUpperRightY = null;
/**
* K* classifier for just the middle portion of the building, predicting y
*/
KStar partitionMiddleY = null;
/**
* Random forest model to predict which portion of the building the user is in
* Determines if the user is in upper left, lower left, upper right, lower right, middle
*/
RandomForest partitionClassifier;
/**
* Instance for classifying X position
*/
Instances xInstances;
/**
* Instance for classifying Y position
*/
Instances yInstances;
/**
* Instance for classifying partition
*/
Instances partitionInstances;
// List of attributes we use for prediction
// TODO: make this not be ugly
Attribute attrAccelX = new Attribute("accelerometerX");
Attribute attrAccelY = new Attribute("accelerometerY");
Attribute attrAccelZ = new Attribute("accelerometerZ");
Attribute attrMagneticX = new Attribute("magneticX");
Attribute attrMagneticY = new Attribute("magneticY");
Attribute attrMagneticZ = new Attribute("magneticZ");
Attribute attrLight = new Attribute("light");
Attribute attrRotationX = new Attribute("rotationX");
Attribute attrRotationY = new Attribute("rotationY");
Attribute attrRotationZ = new Attribute("rotationZ");
Attribute attrOrientationX = new Attribute("orientationX");
Attribute attrOrientationY = new Attribute("orientationY");
Attribute attrOrientationZ = new Attribute("orientationZ");
Attribute attrBSSID1 = new Attribute("BSSID1");
Attribute attrBSSID2 = new Attribute("BSSID2");
Attribute attrBSSID3 = new Attribute("BSSID3");
Attribute attrBSSID4 = new Attribute("BSSID4");
Attribute attrBSSID5 = new Attribute("BSSID5");
Attribute attrBSSID6 = new Attribute("BSSID6");
Attribute attrBSSID7 = new Attribute("BSSID7");
Attribute attrBSSID8 = new Attribute("BSSID8");
Attribute attrBSSID9 = new Attribute("BSSID9");
Attribute attrBSSID10 = new Attribute("BSSID10");
Attribute attrBSSID11 = new Attribute("BSSID11");
Attribute attrBSSID12 = new Attribute("BSSID12");
Attribute attrBSSID13 = new Attribute("BSSID13");
Attribute attrBSSID14 = new Attribute("BSSID14");
Attribute attrBSSID15 = new Attribute("BSSID15");
Attribute attrBSSID16 = new Attribute("BSSID16");
Attribute attrBSSID17 = new Attribute("BSSID17");
Attribute attrBSSID18 = new Attribute("BSSID18");
Attribute attrBSSID19 = new Attribute("BSSID19");
Attribute attrBSSID20 = new Attribute("BSSID20");
Attribute attrBSSID21 = new Attribute("BSSID21");
Attribute attrBSSID22 = new Attribute("BSSID22");
Attribute attrBSSID23 = new Attribute("BSSID23");
Attribute attrBSSID24 = new Attribute("BSSID24");
Attribute attrBSSID25 = new Attribute("BSSID25");
Attribute attrBSSID26 = new Attribute("BSSID26");
Attribute attrBSSID27 = new Attribute("BSSID27");
Attribute attrBSSID28 = new Attribute("BSSID28");
Attribute attrBSSID29 = new Attribute("BSSID29");
Attribute attrBSSID30 = new Attribute("BSSID30");
Attribute attrBSSID31 = new Attribute("BSSID31");
Attribute attrBSSID32 = new Attribute("BSSID32");
Attribute attrBSSID33 = new Attribute("BSSID33");
Attribute attrBSSID34 = new Attribute("BSSID34");
Attribute attrBSSID35 = new Attribute("BSSID35");
Attribute attrBSSID36 = new Attribute("BSSID36");
Attribute attrBSSID37 = new Attribute("BSSID37");
Attribute attrBSSID38 = new Attribute("BSSID38");
Attribute attrBSSID39 = new Attribute("BSSID39");
Attribute attrBSSID40 = new Attribute("BSSID40");
Attribute attrBSSID41 = new Attribute("BSSID41");
Attribute attrBSSID42 = new Attribute("BSSID42");
Attribute attrBSSID43 = new Attribute("BSSID43");
Attribute attrBSSID44 = new Attribute("BSSID44");
Attribute attrBSSID45 = new Attribute("BSSID45");
Attribute attrBSSID46 = new Attribute("BSSID46");
Attribute attrBSSID47 = new Attribute("BSSID47");
Attribute attrBSSID48 = new Attribute("BSSID48");
Attribute attrBSSID49 = new Attribute("BSSID49");
Attribute attrBSSID50 = new Attribute("BSSID50");
Attribute attrBSSID51 = new Attribute("BSSID51");
Attribute attrBSSID52 = new Attribute("BSSID52");
Attribute attrBSSID53 = new Attribute("BSSID53");
Attribute attrBSSID54 = new Attribute("BSSID54");
Attribute attrBSSID55 = new Attribute("BSSID55");
Attribute attrBSSID56 = new Attribute("BSSID56");
Attribute attrBSSID57 = new Attribute("BSSID57");
Attribute attrBSSID58 = new Attribute("BSSID58");
Attribute attrBSSID59 = new Attribute("BSSID59");
Attribute attrBSSID60 = new Attribute("BSSID60");
Attribute attrBSSID61 = new Attribute("BSSID61");
Attribute attrBSSID62 = new Attribute("BSSID62");
Attribute attrBSSID63 = new Attribute("BSSID63");
Attribute attrBSSID64 = new Attribute("BSSID64");
Attribute attrBSSID65 = new Attribute("BSSID65");
Attribute attrBSSID66 = new Attribute("BSSID66");
Attribute attrBSSID67 = new Attribute("BSSID67");
Attribute attrBSSID68 = new Attribute("BSSID68");
Attribute attrBSSID69 = new Attribute("BSSID69");
Attribute attrBSSID70 = new Attribute("BSSID70");
Attribute attrBSSID71 = new Attribute("BSSID71");
Attribute attrBSSID72 = new Attribute("BSSID72");
Attribute attrBSSID73 = new Attribute("BSSID73");
Attribute attrBSSID74 = new Attribute("BSSID74");
Attribute attrBSSID75 = new Attribute("BSSID75");
Attribute attrBSSID76 = new Attribute("BSSID76");
Attribute attrBSSID77 = new Attribute("BSSID77");
Attribute attrBSSID78 = new Attribute("BSSID78");
Attribute attrBSSID79 = new Attribute("BSSID79");
Attribute attrBSSID80 = new Attribute("BSSID80");
Attribute attrBSSID81 = new Attribute("BSSID81");
Attribute attrBSSID82 = new Attribute("BSSID82");
Attribute attrBSSID83 = new Attribute("BSSID83");
Attribute attrBSSID84 = new Attribute("BSSID84");
Attribute attrBSSID85 = new Attribute("BSSID85");
Attribute attrBSSID86 = new Attribute("BSSID86");
Attribute attrBSSID87 = new Attribute("BSSID87");
Attribute attrBSSID88 = new Attribute("BSSID88");
Attribute attrBSSID89 = new Attribute("BSSID89");
Attribute attrBSSID90 = new Attribute("BSSID90");
Attribute attrBSSID91 = new Attribute("BSSID91");
Attribute attrBSSID92 = new Attribute("BSSID92");
Attribute attrBSSID93 = new Attribute("BSSID93");
Attribute attrBSSID94 = new Attribute("BSSID94");
Attribute attrBSSID95 = new Attribute("BSSID95");
Attribute attrBSSID96 = new Attribute("BSSID96");
Attribute attrBSSID97 = new Attribute("BSSID97");
Attribute attrBSSID98 = new Attribute("BSSID98");
Attribute attrBSSID99 = new Attribute("BSSID99");
Attribute attrBSSID100 = new Attribute("BSSID100");
Attribute attrBSSID101 = new Attribute("BSSID101");
Attribute attrBSSID102 = new Attribute("BSSID102");
Attribute attrBSSID103 = new Attribute("BSSID103");
Attribute attrBSSID104 = new Attribute("BSSID104");
Attribute attrBSSID105 = new Attribute("BSSID105");
Attribute attrBSSID106 = new Attribute("BSSID106");
Attribute attrBSSID107 = new Attribute("BSSID107");
Attribute attrBSSID108 = new Attribute("BSSID108");
Attribute attrBSSID109 = new Attribute("BSSID109");
Attribute attrBSSID110 = new Attribute("BSSID110");
Attribute attrBSSID111 = new Attribute("BSSID111");
Attribute attrBSSID112 = new Attribute("BSSID112");
Attribute attrBSSID113 = new Attribute("BSSID113");
Attribute attrBSSID114 = new Attribute("BSSID114");
Attribute attrBSSID115 = new Attribute("BSSID115");
Attribute attrBSSID116 = new Attribute("BSSID116");
Attribute attrBSSID117 = new Attribute("BSSID117");
Attribute attrBSSID118 = new Attribute("BSSID118");
Attribute attrBSSID119 = new Attribute("BSSID119");
Attribute attrBSSID120 = new Attribute("BSSID120");
Attribute attrBSSID121 = new Attribute("BSSID121");
Attribute attrBSSID122 = new Attribute("BSSID122");
Attribute attrBSSID123 = new Attribute("BSSID123");
Attribute attrBSSID124 = new Attribute("BSSID124");
Attribute attrBSSID125 = new Attribute("BSSID125");
Attribute attrBSSID126 = new Attribute("BSSID126");
Attribute attrBSSID127 = new Attribute("BSSID127");
Attribute attrBSSID128 = new Attribute("BSSID128");
Attribute attrBSSID129 = new Attribute("BSSID129");
Attribute attrBSSID130 = new Attribute("BSSID130");
Attribute attrBSSID131 = new Attribute("BSSID131");
Attribute attrBSSID132 = new Attribute("BSSID132");
Attribute attrBSSID133 = new Attribute("BSSID133");
Attribute attrBSSID134 = new Attribute("BSSID134");
Attribute attrBSSID135 = new Attribute("BSSID135");
Attribute attrBSSID136 = new Attribute("BSSID136");
Attribute attrBSSID137 = new Attribute("BSSID137");
Attribute attrBSSID138 = new Attribute("BSSID138");
Attribute attrBSSID139 = new Attribute("BSSID139");
Attribute attrBSSID140 = new Attribute("BSSID140");
Attribute attrBSSID141 = new Attribute("BSSID141");
Attribute attrBSSID142 = new Attribute("BSSID142");
Attribute attrBSSID143 = new Attribute("BSSID143");
Attribute attrBSSID144 = new Attribute("BSSID144");
Attribute attrBSSID145 = new Attribute("BSSID145");
Attribute attrBSSID146 = new Attribute("BSSID146");
Attribute attrBSSID147 = new Attribute("BSSID147");
Attribute attrBSSID148 = new Attribute("BSSID148");
Attribute attrBSSID149 = new Attribute("BSSID149");
Attribute attrBSSID150 = new Attribute("BSSID150");
Attribute attrBSSID151 = new Attribute("BSSID151");
Attribute attrBSSID152 = new Attribute("BSSID152");
Attribute attrBSSID153 = new Attribute("BSSID153");
Attribute attrBSSID154 = new Attribute("BSSID154");
Attribute attrBSSID155 = new Attribute("BSSID155");
Attribute attrBSSID156 = new Attribute("BSSID156");
Attribute attrLatitude = new Attribute("latitude");
Attribute attrLongitude = new Attribute("longitude");
Attribute attrLocationAccuracy = new Attribute("locationAccuracy");
Attribute attrXPosition = new Attribute("xPosition");
Attribute attrYPosition = new Attribute("yPosition");
List<String> values = Arrays.asList("upperleft", "lowerleft", "middle", "upperright", "lowerright");
Attribute attrPartition = new Attribute("partition", values);
ArrayList<Attribute> xClass = new ArrayList<Attribute>(173);
ArrayList<Attribute> yClass = new ArrayList<Attribute>(173);
ArrayList<Attribute> partitionClass = new ArrayList<Attribute>(173);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//allow users to go back to Main Activity
//TODO: test if this works on Marshmallow
if (Build.VERSION.SDK_INT >= 23){
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
} else {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestMyPermissions();
}
setContentView(R.layout.activity_tracker);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new TrackerFragment()).commit();
}
rotation = new float[9];
inclination = new float[9];
orientation = new float[3];
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
updateLocation(location);
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onProviderDisabled(String provider) {}
};
loadXClassifierModels();
loadYClassifierModels();
loadPartitionClassifierModels();
setUpXInstances();
setUpYInstances();
setUpPartitionInstances();
wifiReadings = new LinkedHashMap<String, Integer>();
t = new Thread();
t.start();
//load5PartitionClassifiers = new Thread();
//load5PartitionClassifiers.start();
}
private void requestMyPermissions() {
//@author Mahesh Gaya added new permission statement
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_FINE_LOCATION)
|| ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_WIFI_STATE)
|| ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CHANGE_WIFI_STATE)
|| ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)){
Toast.makeText(this, "GPS, WIFI, and Storage permissions are required for this app.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION );
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.CHANGE_WIFI_STATE}, REQUEST_WIFI);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_STORAGE);
}
}
// TODO: make pretty (i.e. hide this in another class)
/**
* Adds the attributes to the x classification, sets up the xInstance to
* allow the classifier to predict x position from these attributes
*/
private void setUpXInstances() {
xClass.add(attrAccelX);
xClass.add(attrAccelY);
xClass.add(attrAccelZ);
xClass.add(attrMagneticX);
xClass.add(attrMagneticY);
xClass.add(attrMagneticZ);
xClass.add(attrLight);
xClass.add(attrRotationX);
xClass.add(attrRotationY);
xClass.add(attrRotationZ);
xClass.add(attrOrientationX);
xClass.add(attrOrientationY);
xClass.add(attrOrientationZ);
xClass.add(attrBSSID1);
xClass.add(attrBSSID2);
xClass.add(attrBSSID3);
xClass.add(attrBSSID4);
xClass.add(attrBSSID5);
xClass.add(attrBSSID6);
xClass.add(attrBSSID7);
xClass.add(attrBSSID8);
xClass.add(attrBSSID9);
xClass.add(attrBSSID10);
xClass.add(attrBSSID11);
xClass.add(attrBSSID12);
xClass.add(attrBSSID13);
xClass.add(attrBSSID14);
xClass.add(attrBSSID15);
xClass.add(attrBSSID16);
xClass.add(attrBSSID17);
xClass.add(attrBSSID18);
xClass.add(attrBSSID19);
xClass.add(attrBSSID20);
xClass.add(attrBSSID21);
xClass.add(attrBSSID22);
xClass.add(attrBSSID23);
xClass.add(attrBSSID24);
xClass.add(attrBSSID25);
xClass.add(attrBSSID26);
xClass.add(attrBSSID27);
xClass.add(attrBSSID28);
xClass.add(attrBSSID29);
xClass.add(attrBSSID30);
xClass.add(attrBSSID31);
xClass.add(attrBSSID32);
xClass.add(attrBSSID33);
xClass.add(attrBSSID34);
xClass.add(attrBSSID35);
xClass.add(attrBSSID36);
xClass.add(attrBSSID37);
xClass.add(attrBSSID38);
xClass.add(attrBSSID39);
xClass.add(attrBSSID40);
xClass.add(attrBSSID41);
xClass.add(attrBSSID42);
xClass.add(attrBSSID43);
xClass.add(attrBSSID44);
xClass.add(attrBSSID45);
xClass.add(attrBSSID46);
xClass.add(attrBSSID47);
xClass.add(attrBSSID48);
xClass.add(attrBSSID49);
xClass.add(attrBSSID50);
xClass.add(attrBSSID51);
xClass.add(attrBSSID52);
xClass.add(attrBSSID53);
xClass.add(attrBSSID54);
xClass.add(attrBSSID55);
xClass.add(attrBSSID56);
xClass.add(attrBSSID57);
xClass.add(attrBSSID58);
xClass.add(attrBSSID59);
xClass.add(attrBSSID60);
xClass.add(attrBSSID61);
xClass.add(attrBSSID62);
xClass.add(attrBSSID63);
xClass.add(attrBSSID64);
xClass.add(attrBSSID65);
xClass.add(attrBSSID66);
xClass.add(attrBSSID67);
xClass.add(attrBSSID68);
xClass.add(attrBSSID69);
xClass.add(attrBSSID70);
xClass.add(attrBSSID71);
xClass.add(attrBSSID72);
xClass.add(attrBSSID73);
xClass.add(attrBSSID74);
xClass.add(attrBSSID75);
xClass.add(attrBSSID76);
xClass.add(attrBSSID77);
xClass.add(attrBSSID78);
xClass.add(attrBSSID79);
xClass.add(attrBSSID80);
xClass.add(attrBSSID81);
xClass.add(attrBSSID82);
xClass.add(attrBSSID83);
xClass.add(attrBSSID84);
xClass.add(attrBSSID85);
xClass.add(attrBSSID86);
xClass.add(attrBSSID87);
xClass.add(attrBSSID88);
xClass.add(attrBSSID89);
xClass.add(attrBSSID90);
xClass.add(attrBSSID91);
xClass.add(attrBSSID92);
xClass.add(attrBSSID93);
xClass.add(attrBSSID94);
xClass.add(attrBSSID95);
xClass.add(attrBSSID96);
xClass.add(attrBSSID97);
xClass.add(attrBSSID98);
xClass.add(attrBSSID99);
xClass.add(attrBSSID100);
xClass.add(attrBSSID101);
xClass.add(attrBSSID102);
xClass.add(attrBSSID103);
xClass.add(attrBSSID104);
xClass.add(attrBSSID105);
xClass.add(attrBSSID106);
xClass.add(attrBSSID107);
xClass.add(attrBSSID108);
xClass.add(attrBSSID109);
xClass.add(attrBSSID110);
xClass.add(attrBSSID111);
xClass.add(attrBSSID112);
xClass.add(attrBSSID113);
xClass.add(attrBSSID114);
xClass.add(attrBSSID115);
xClass.add(attrBSSID116);
xClass.add(attrBSSID117);
xClass.add(attrBSSID118);
xClass.add(attrBSSID119);
xClass.add(attrBSSID120);
xClass.add(attrBSSID121);
xClass.add(attrBSSID122);
xClass.add(attrBSSID123);
xClass.add(attrBSSID124);
xClass.add(attrBSSID125);
xClass.add(attrBSSID126);
xClass.add(attrBSSID127);
xClass.add(attrBSSID128);
xClass.add(attrBSSID129);
xClass.add(attrBSSID130);
xClass.add(attrBSSID131);
xClass.add(attrBSSID132);
xClass.add(attrBSSID133);
xClass.add(attrBSSID134);
xClass.add(attrBSSID135);
xClass.add(attrBSSID136);
xClass.add(attrBSSID137);
xClass.add(attrBSSID138);
xClass.add(attrBSSID139);
xClass.add(attrBSSID140);
xClass.add(attrBSSID141);
xClass.add(attrBSSID142);
xClass.add(attrBSSID143);
xClass.add(attrBSSID144);
xClass.add(attrBSSID145);
xClass.add(attrBSSID146);
xClass.add(attrBSSID147);
xClass.add(attrBSSID148);
xClass.add(attrBSSID149);
xClass.add(attrBSSID150);
xClass.add(attrBSSID151);
xClass.add(attrBSSID152);
xClass.add(attrBSSID153);
xClass.add(attrBSSID154);
xClass.add(attrBSSID155);
xClass.add(attrBSSID156);
xClass.add(attrLatitude);
xClass.add(attrLongitude);
xClass.add(attrLocationAccuracy);
xClass.add(attrXPosition);
xInstances = new Instances("xPos", xClass, 1);
xInstances.setClassIndex(172);
xInstances.add(new DenseInstance(173));
}
// TODO this one too
/**
* Adds the attributes to the y classification, sets up the yInstance to
* allow the classifier to predict y position from these attributes
*/
private void setUpYInstances() {
yClass.add(attrAccelX);
yClass.add(attrAccelY);
yClass.add(attrAccelZ);
yClass.add(attrMagneticX);
yClass.add(attrMagneticY);
yClass.add(attrMagneticZ);
yClass.add(attrLight);
yClass.add(attrRotationX);
yClass.add(attrRotationY);
yClass.add(attrRotationZ);
yClass.add(attrOrientationX);
yClass.add(attrOrientationY);
yClass.add(attrOrientationZ);
yClass.add(attrBSSID1);
yClass.add(attrBSSID2);
yClass.add(attrBSSID3);
yClass.add(attrBSSID4);
yClass.add(attrBSSID5);
yClass.add(attrBSSID6);
yClass.add(attrBSSID7);
yClass.add(attrBSSID8);
yClass.add(attrBSSID9);
yClass.add(attrBSSID10);
yClass.add(attrBSSID11);
yClass.add(attrBSSID12);
yClass.add(attrBSSID13);
yClass.add(attrBSSID14);
yClass.add(attrBSSID15);
yClass.add(attrBSSID16);
yClass.add(attrBSSID17);
yClass.add(attrBSSID18);
yClass.add(attrBSSID19);
yClass.add(attrBSSID20);
yClass.add(attrBSSID21);
yClass.add(attrBSSID22);
yClass.add(attrBSSID23);
yClass.add(attrBSSID24);
yClass.add(attrBSSID25);
yClass.add(attrBSSID26);
yClass.add(attrBSSID27);
yClass.add(attrBSSID28);
yClass.add(attrBSSID29);
yClass.add(attrBSSID30);
yClass.add(attrBSSID31);
yClass.add(attrBSSID32);
yClass.add(attrBSSID33);
yClass.add(attrBSSID34);
yClass.add(attrBSSID35);
yClass.add(attrBSSID36);
yClass.add(attrBSSID37);
yClass.add(attrBSSID38);
yClass.add(attrBSSID39);
yClass.add(attrBSSID40);
yClass.add(attrBSSID41);
yClass.add(attrBSSID42);
yClass.add(attrBSSID43);
yClass.add(attrBSSID44);
yClass.add(attrBSSID45);
yClass.add(attrBSSID46);
yClass.add(attrBSSID47);
yClass.add(attrBSSID48);
yClass.add(attrBSSID49);
yClass.add(attrBSSID50);
yClass.add(attrBSSID51);
yClass.add(attrBSSID52);
yClass.add(attrBSSID53);
yClass.add(attrBSSID54);
yClass.add(attrBSSID55);
yClass.add(attrBSSID56);
yClass.add(attrBSSID57);
yClass.add(attrBSSID58);
yClass.add(attrBSSID59);
yClass.add(attrBSSID60);
yClass.add(attrBSSID61);
yClass.add(attrBSSID62);
yClass.add(attrBSSID63);
yClass.add(attrBSSID64);
yClass.add(attrBSSID65);
yClass.add(attrBSSID66);
yClass.add(attrBSSID67);
yClass.add(attrBSSID68);
yClass.add(attrBSSID69);
yClass.add(attrBSSID70);
yClass.add(attrBSSID71);
yClass.add(attrBSSID72);
yClass.add(attrBSSID73);
yClass.add(attrBSSID74);
yClass.add(attrBSSID75);
yClass.add(attrBSSID76);
yClass.add(attrBSSID77);
yClass.add(attrBSSID78);
yClass.add(attrBSSID79);
yClass.add(attrBSSID80);
yClass.add(attrBSSID81);
yClass.add(attrBSSID82);
yClass.add(attrBSSID83);
yClass.add(attrBSSID84);
yClass.add(attrBSSID85);
yClass.add(attrBSSID86);
yClass.add(attrBSSID87);
yClass.add(attrBSSID88);
yClass.add(attrBSSID89);
yClass.add(attrBSSID90);
yClass.add(attrBSSID91);
yClass.add(attrBSSID92);
yClass.add(attrBSSID93);
yClass.add(attrBSSID94);
yClass.add(attrBSSID95);
yClass.add(attrBSSID96);
yClass.add(attrBSSID97);
yClass.add(attrBSSID98);
yClass.add(attrBSSID99);
yClass.add(attrBSSID100);
yClass.add(attrBSSID101);
yClass.add(attrBSSID102);
yClass.add(attrBSSID103);
yClass.add(attrBSSID104);
yClass.add(attrBSSID105);
yClass.add(attrBSSID106);
yClass.add(attrBSSID107);
yClass.add(attrBSSID108);
yClass.add(attrBSSID109);
yClass.add(attrBSSID110);
yClass.add(attrBSSID111);
yClass.add(attrBSSID112);
yClass.add(attrBSSID113);
yClass.add(attrBSSID114);
yClass.add(attrBSSID115);
yClass.add(attrBSSID116);
yClass.add(attrBSSID117);
yClass.add(attrBSSID118);
yClass.add(attrBSSID119);
yClass.add(attrBSSID120);
yClass.add(attrBSSID121);
yClass.add(attrBSSID122);
yClass.add(attrBSSID123);
yClass.add(attrBSSID124);
yClass.add(attrBSSID125);
yClass.add(attrBSSID126);
yClass.add(attrBSSID127);
yClass.add(attrBSSID128);
yClass.add(attrBSSID129);
yClass.add(attrBSSID130);
yClass.add(attrBSSID131);
yClass.add(attrBSSID132);
yClass.add(attrBSSID133);
yClass.add(attrBSSID134);
yClass.add(attrBSSID135);
yClass.add(attrBSSID136);
yClass.add(attrBSSID137);
yClass.add(attrBSSID138);
yClass.add(attrBSSID139);
yClass.add(attrBSSID140);
yClass.add(attrBSSID141);
yClass.add(attrBSSID142);
yClass.add(attrBSSID143);
yClass.add(attrBSSID144);
yClass.add(attrBSSID145);
yClass.add(attrBSSID146);
yClass.add(attrBSSID147);
yClass.add(attrBSSID148);
yClass.add(attrBSSID149);
yClass.add(attrBSSID150);
yClass.add(attrBSSID151);
yClass.add(attrBSSID152);
yClass.add(attrBSSID153);
yClass.add(attrBSSID154);
yClass.add(attrBSSID155);
yClass.add(attrBSSID156);
yClass.add(attrLatitude);