@@ -41,6 +41,11 @@ public class ASAPActivity extends AppCompatActivity implements
41
41
42
42
private ASAPApplication asapApplication ;
43
43
44
+ /**
45
+ * Create a new activity object. Make sure your application object is fully
46
+ * instantiated
47
+ * @param asapApplication
48
+ */
44
49
public ASAPActivity (ASAPApplication asapApplication ) {
45
50
this .asapApplication = asapApplication ;
46
51
}
@@ -51,13 +56,17 @@ protected ASAPApplication getASAPApplication() {
51
56
52
57
/**
53
58
* Create a closed asap channel. Ensure to call this method before ever sending a message into
54
- * that channel.
55
- * @param appName
56
- * @param uri
57
- * @param recipients
59
+ * that channel. Any prior message would create an open channel with unrestricted recipient list.
60
+ * (It sound worse than it is, though. Have a look at the concept description of ASAP.)
61
+ * @param appName format / appName of your application and its ASAPEngine
62
+ * @param uri describes content within your application
63
+ * @param recipients list of recipients. Only peers on that list will even get this message.
64
+ * This is more than setting access rights. It like a registered letter.
65
+ * Peers which are not on the list will not even be aware of the existence
66
+ * of this channel and it messages.
58
67
* @throws ASAPException
59
68
*/
60
- public void createClosedASAPChannel (CharSequence appName , CharSequence uri ,
69
+ public final void createClosedASAPChannel (CharSequence appName , CharSequence uri ,
61
70
Collection <CharSequence > recipients ) throws ASAPException {
62
71
63
72
ASAPServiceMessage createClosedChannelMessage =
@@ -69,13 +78,13 @@ public void createClosedASAPChannel(CharSequence appName, CharSequence uri,
69
78
/**
70
79
* Send asap message. If that channel does not exist: it will be created as open channel
71
80
* (unrestricted recipient list). Closed channels must be created before
72
- * @param appName
73
- * @param uri
74
- * @param message
81
+ * @param appName format / appName of your application and its ASAPEngine
82
+ * @param uri describes content within your application
83
+ * @param message application specific message as bytes.
75
84
* @param persistent keep in an asap store and resent in following asap sessions
76
85
* @throws ASAPException
77
86
*/
78
- public void sendASAPMessage (CharSequence appName , CharSequence uri ,
87
+ public final void sendASAPMessage (CharSequence appName , CharSequence uri ,
79
88
byte [] message , boolean persistent ) throws ASAPException {
80
89
81
90
Log .d (this .getLogStart (), "ask service to send: "
@@ -93,7 +102,13 @@ public void sendASAPMessage(CharSequence appName, CharSequence uri,
93
102
// asap service requests //
94
103
///////////////////////////////////////////////////////////////////////////////////////
95
104
105
+ /**
106
+ * Application developer should neither call nor overwrite this message. It is called
107
+ * as result of a start bluetooth request. We will hide it behind an interface in later
108
+ * version. Until than: Please, do not call this method.
109
+ */
96
110
@ Override
111
+ @ CallSuper
97
112
public void asapSrcRq_enableBluetooth () {
98
113
// check if bt is enabled
99
114
// get default bt adapter - there could be proprietary adapters
@@ -121,7 +136,13 @@ public void asapSrcRq_enableBluetooth() {
121
136
122
137
private int visibilityTime = 1 ;
123
138
139
+ /**
140
+ * Application developer should neither call nor overwrite this message. It is called
141
+ * as result of a start bluetooth request. We will hide it behind an interface in later
142
+ * version. Until than: Please, do not call this method.
143
+ */
124
144
@ Override
145
+ @ CallSuper
125
146
public void asapSrcRq_startBTDiscoverable (int time ) {
126
147
this .visibilityTime = time ;
127
148
Log .d (this .getLogStart (), "going to make device bt visibile for seconds: "
@@ -135,6 +156,13 @@ public void asapSrcRq_startBTDiscoverable(int time) {
135
156
this .startActivityForResult (discoverableIntent , MY_REQUEST_SET_BT_DISCOVERABLE );
136
157
}
137
158
159
+ /**
160
+ * Application developer should neither call nor overwrite this message. It is the callback
161
+ * method that is called if a broadcast is received. We will hide it behind an
162
+ * interface in later
163
+ * version. Until than: Please, do not call this method.
164
+ */
165
+ @ CallSuper
138
166
public void onActivityResult (int requestCode , int resultCode , Intent data ) {
139
167
Log .d (this .getLogStart (),
140
168
".onActivityResult(): requestCode == " + requestCode +
@@ -189,31 +217,62 @@ protected String getLogStart() {
189
217
// mac protocol stuff //
190
218
/////////////////////////////////////////////////////////////////////////////////////
191
219
220
+ /**
221
+ * Call this message to start Bluetooth.
222
+ * asapNotifyBTEnvironmentStarted() is called later if BT could be started.
223
+ */
192
224
public void startBluetooth () {
193
225
Log .d (this .getLogStart (), "send message to service: start BT" );
194
226
this .sendMessage2Service (ASAPServiceMethods .START_BLUETOOTH );
195
227
}
196
228
229
+ /**
230
+ * Call this message to stop Bluetooth.
231
+ * asapNotifyBTEnvironmentStopped() is called later if BT could be stopped
232
+ */
197
233
public void stopBluetooth () {
198
234
Log .d (this .getLogStart (), "send message to service: stop BT" );
199
235
this .sendMessage2Service (ASAPServiceMethods .STOP_BLUETOOTH );
200
236
}
201
237
238
+ /**
239
+ * Call this message to start Wifi direct.
240
+ * Note: Wifi is not yet fully supported. Do not use this method yet.
241
+ */
202
242
public void startWifiP2P () {
203
243
Log .d (this .getLogStart (), "send message to service: start Wifi P2P" );
204
244
this .sendMessage2Service (ASAPServiceMethods .START_WIFI_DIRECT );
205
245
}
206
246
247
+ /**
248
+ * Call this message to stop Wifi direct.
249
+ * Note: Wifi is not yet fully supported. Do not use this method yet.
250
+ */
207
251
public void stopWifiP2P () {
208
252
Log .d (this .getLogStart (), "send message to service: stop Wifi P2P" );
209
253
this .sendMessage2Service (ASAPServiceMethods .STOP_WIFI_DIRECT );
210
254
}
211
255
256
+ /**
257
+ * Call this message to make this device discoverable with Bluetooth.
258
+ * asapNotifyBTDiscoverableStarted() is called later.
259
+ * There is not matching stop method. Bluetooth discoverability is stopped after some time
260
+ * from Android. asapNotifyBTDiscoverableStopped() is called in this case.
261
+ *
262
+ */
212
263
public void startBluetoothDiscoverable () {
213
264
Log .d (this .getLogStart (), "send message to service: start BT Discoverable" );
214
265
this .sendMessage2Service (ASAPServiceMethods .START_BLUETOOTH_DISCOVERABLE );
215
266
}
216
267
268
+ /**
269
+ * Call this message to start Bluetooth discovery. This device will look for discoverable
270
+ * Bluetooth devices.
271
+ * asapNotifyBTDiscoveryStarted() is called later.
272
+ * There is not matching stop method. Bluetooth discovery is stopped after some time
273
+ * from Android. asapNotifyBTDiscoveryStopped() is called in this case.
274
+ *
275
+ */
217
276
public void startBluetoothDiscovery () {
218
277
Log .d (this .getLogStart (), "send message to service: start BT Discovery" );
219
278
this .sendMessage2Service (ASAPServiceMethods .START_BLUETOOTH_DISCOVERY );
@@ -229,12 +288,12 @@ twice in the row (a.onStart() sometimes earlier, than b.onStart()) followed by
229
288
230
289
Solution: We only stop broadcasting if there if the last activity signs off.
231
290
*/
232
- public void startASAPEngineBroadcasts () {
291
+ private void startASAPEngineBroadcasts () {
233
292
Log .d (this .getLogStart (), "send message to service: start ASAP Engine Broadcasts" );
234
293
this .sendMessage2Service (ASAPServiceMethods .START_BROADCASTS );
235
294
}
236
295
237
- public void stopASAPEngineBroadcasts () {
296
+ private void stopASAPEngineBroadcasts () {
238
297
if (this .getASAPApplication ().getNumberASAPActivities () == 1 ) {
239
298
Log .d (this .getLogStart (), "send message to service: stop ASAP Engine Broadcasts" );
240
299
this .sendMessage2Service (ASAPServiceMethods .STOP_BROADCASTS );
@@ -322,6 +381,7 @@ private void shutdownASAPChunkReceivedBroadcastReceiver() {
322
381
*/
323
382
324
383
/** currently, we have only two stats: on and off */
384
+ @ CallSuper
325
385
protected void onCreate (Bundle savedInstanceState ) {
326
386
super .onCreate (savedInstanceState );
327
387
Log .d (this .getLogStart (), "onCreate" );
@@ -435,37 +495,101 @@ public void onServiceDisconnected(ComponentName className) {
435
495
}
436
496
};
437
497
498
+ /**
499
+ * Application developers can use this method like life-cycle methods in Android
500
+ * (onStart() etc.). Overwrite this method to get informed about changes in environment.
501
+ * Do not call this method yourself. Do not forget to call the super method if you overwrite.
502
+ *
503
+ * <br/><br/>
504
+ * This method informs that this device is now a discoverable Bluetooth device
505
+ */
438
506
@ Override
507
+ @ CallSuper
439
508
public void asapNotifyBTDiscoverableStarted () {
440
509
this .asapApplication .setBTDiscoverable (true );
441
510
}
442
511
512
+ /**
513
+ * Application developers can use this method like life-cycle methods in Android
514
+ * (onStart() etc.). Overwrite this method to get informed about changes in environment.
515
+ * Do not call this method yourself. Do not forget to call the super method if you overwrite.
516
+ *
517
+ * <br/><br/>
518
+ * This method informs that this device is no longer a discoverable Bluetooth device
519
+ */
443
520
@ Override
521
+ @ CallSuper
444
522
public void asapNotifyBTDiscoverableStopped () {
445
523
this .asapApplication .setBTDiscoverable (false );
446
524
}
447
525
526
+ /**
527
+ * Application developers can use this method like life-cycle methods in Android
528
+ * (onStart() etc.). Overwrite this method to get informed about changes in environment.
529
+ * Do not call this method yourself. Do not forget to call the super method if you overwrite.
530
+ *
531
+ * <br/><br/>
532
+ * This method informs that bluetooth is enabled now.
533
+ */
448
534
@ Override
535
+ @ CallSuper
449
536
public void asapNotifyBTEnvironmentStarted () {
450
537
this .asapApplication .setBTEnvironmentRunning (true );
451
538
}
452
539
540
+ /**
541
+ * Application developers can use this method like life-cycle methods in Android
542
+ * (onStart() etc.). Overwrite this method to get informed about changes in environment.
543
+ * Do not call this method yourself. Do not forget to call the super method if you overwrite.
544
+ *
545
+ * <br/><br/>
546
+ * This method informs that bluetooth is disabled now.
547
+ */
453
548
@ Override
549
+ @ CallSuper
454
550
public void asapNotifyBTEnvironmentStopped () {
455
551
this .asapApplication .setBTEnvironmentRunning (false );
456
552
}
457
553
554
+ /**
555
+ * Application developers can use this method like life-cycle methods in Android
556
+ * (onStart() etc.). Overwrite this method to get informed about changes in environment.
557
+ * Do not call this method yourself. Do not forget to call the super method if you overwrite.
558
+ *
559
+ * <br/><br/>
560
+ * This method called whenever list of connected peers changed. This happens when
561
+ * a connection is created or broken. The current list of peers comes as parameter.
562
+ */
458
563
@ Override
564
+ @ CallSuper
459
565
public void asapNotifyOnlinePeersChanged (List <CharSequence > peerList ) {
460
566
this .asapApplication .setOnlinePeersList (peerList );
461
567
}
462
568
569
+ /**
570
+ * Application developers can use this method like life-cycle methods in Android
571
+ * (onStart() etc.). Overwrite this method to get informed about changes in environment.
572
+ * Do not call this method yourself. Do not forget to call the super method if you overwrite.
573
+ *
574
+ * <br/><br/>
575
+ * This method informs that bluetooth discovery started.
576
+ */
463
577
@ Override
578
+ @ CallSuper
464
579
public void asapNotifyBTDiscoveryStarted () {
465
580
this .asapApplication .setBTDiscovery (true );
466
581
}
467
582
583
+ /**
584
+ * Application developers can use this method like life-cycle methods in Android
585
+ * (onStart() etc.). Overwrite this method to get informed about changes in environment.
586
+ * Do not call this method yourself. Do not forget to call the super method if you overwrite.
587
+ *
588
+ * <br/><br/>
589
+ * This method informs that bluetooth discovery stopped.
590
+ */
468
591
@ Override
592
+ @ CallSuper
469
593
public void asapNotifyBTDiscoveryStopped () {
470
594
this .asapApplication .setBTDiscovery (false );
471
595
}
@@ -474,14 +598,23 @@ public void asapNotifyBTDiscoveryStopped() {
474
598
// status methods //
475
599
////////////////////////////////////////////////////////////////////////////////
476
600
601
+ /**
602
+ * @return true if bluetooth environment is one.
603
+ */
477
604
public boolean isBluetoothEnvironmentOn () {
478
605
return this .asapApplication .getBTEnvironmentRunning ();
479
606
}
480
607
608
+ /**
609
+ * @return true if this device is discoverable now.
610
+ */
481
611
public boolean isBluetoothDiscoverable () {
482
612
return this .asapApplication .getBTDiscoverable ();
483
613
}
484
614
615
+ /**
616
+ * @return true if this device looking for other Bluetooth devices.
617
+ */
485
618
public boolean isBluetoothDiscovery () {
486
619
return this .asapApplication .getBTDiscovery ();
487
620
}
0 commit comments