1717import android .widget .Toast ;
1818
1919import net .sharksystem .asap .ASAPException ;
20+ import net .sharksystem .asap .ASAPPeer ;
2021import net .sharksystem .asap .android .ASAPAndroid ;
2122import net .sharksystem .asap .android .ASAPServiceMessage ;
2223import net .sharksystem .asap .android .ASAPServiceMethods ;
@@ -40,19 +41,30 @@ public class ASAPActivity extends AppCompatActivity implements
4041 private Messenger mService ;
4142 private boolean mBound ;
4243
43- private ASAPApplication asapApplication ;
44+ private ASAPAndroidPeer asapAndroidPeer ;
4445
4546 /**
4647 * Create a new activity object. Make sure your application object is fully
4748 * instantiated
48- * @param asapApplication
49+ * @param asapAndroidPeer
4950 */
50- public ASAPActivity (ASAPApplication asapApplication ) {
51- this .asapApplication = asapApplication ;
51+ ASAPActivity (ASAPAndroidPeer asapAndroidPeer ) {
52+ this .asapAndroidPeer = asapAndroidPeer ;
5253 }
5354
54- protected ASAPApplication getASAPApplication () {
55- return this .asapApplication ;
55+ /**
56+ * @throws ASAPComponentNotYetInitializedException if ASAPAndroidPeer was not initialized
57+ */
58+ public ASAPActivity () {
59+ this (ASAPAndroidPeer .getASAPAndroidPeer ());
60+ }
61+
62+ protected ASAPAndroidPeer getASAPAndroidPeer () {
63+ return this .asapAndroidPeer ;
64+ }
65+
66+ protected ASAPPeer getASAPPeer () {
67+ return this .asapAndroidPeer ;
5668 }
5769
5870 /**
@@ -87,7 +99,6 @@ public final void createClosedASAPChannel(CharSequence appName, CharSequence uri
8799 */
88100 public final void sendASAPMessage (CharSequence appName , CharSequence uri ,
89101 byte [] message , boolean persistent ) throws ASAPException {
90-
91102 Log .d (this .getLogStart (), "ask service to send: "
92103 + "format: " + appName
93104 + "| uri: " + uri
@@ -311,7 +322,7 @@ private void startASAPEngineBroadcasts() {
311322 }
312323
313324 private void stopASAPEngineBroadcasts () {
314- if (this .getASAPApplication ().getNumberASAPActivities () == 1 ) {
325+ if (this .getASAPAndroidPeer ().getNumberASAPActivities () == 1 ) {
315326 Log .d (this .getLogStart (), "send message to service: stop ASAP Engine Broadcasts" );
316327 this .sendMessage2Service (ASAPServiceMethods .STOP_BROADCASTS );
317328 } else {
@@ -370,13 +381,13 @@ private void setupASAPChunkReceivedBroadcastReceiver() {
370381 filter .addAction (ASAPAndroid .ASAP_CHUNK_RECEIVED_ACTION );
371382
372383 // register
373- this .registerReceiver (this .asapApplication , filter );
384+ this .registerReceiver (this .asapAndroidPeer , filter );
374385 }
375386
376387 private void shutdownASAPChunkReceivedBroadcastReceiver () {
377388 Log .d (this .getLogStart (), "shutdown asap received bc receiver" );
378389 try {
379- this .unregisterReceiver (this .asapApplication );
390+ this .unregisterReceiver (this .asapAndroidPeer );
380391 }
381392 catch (RuntimeException re ) {
382393 Log .d (this .getLogStart (), "problems when unregister asap received bcr - ignore"
@@ -402,14 +413,14 @@ private void shutdownASAPChunkReceivedBroadcastReceiver() {
402413 protected void onCreate (Bundle savedInstanceState ) {
403414 super .onCreate (savedInstanceState );
404415 Log .d (this .getLogStart (), "onCreate" );
405- this .asapApplication .activityCreated (this );
416+ this .asapAndroidPeer .activityCreated (this );
406417 }
407418
408419 protected void onStart () {
409420 // Bind to the service
410421 super .onStart ();
411422 Log .d (this .getLogStart (), "onStart" );
412- this .asapApplication .setActivity (this );
423+ this .asapAndroidPeer .setActivity (this );
413424 this .setupASAPServiceNotificationBroadcastReceiver ();
414425 this .setupASAPChunkReceivedBroadcastReceiver ();
415426 this .bindServices ();
@@ -420,7 +431,7 @@ protected void onStart() {
420431 protected void onResume () {
421432 super .onResume ();
422433 Log .d (this .getLogStart (), "onResume" );
423- this .asapApplication .setActivity (this );
434+ this .asapAndroidPeer .setActivity (this );
424435 this .startASAPEngineBroadcasts ();
425436 }
426437
@@ -448,7 +459,7 @@ protected void onDestroy() {
448459 Log .d (this .getLogStart (), "onDestroy" );
449460 this .shutdownASAPServiceNotificationBroadcastReceiver ();
450461 this .unbindServices ();
451- this .asapApplication .activityDestroyed (this );
462+ this .asapAndroidPeer .activityDestroyed (this );
452463
453464 // forget stored messages
454465 this .messageStorage = null ;
@@ -523,7 +534,7 @@ public void onServiceDisconnected(ComponentName className) {
523534 @ Override
524535 @ CallSuper
525536 public void asapNotifyBTDiscoverableStarted () {
526- this .asapApplication . setBTDiscoverable (true );
537+ this .asapAndroidPeer . notifyBTDiscoverable (true );
527538 }
528539
529540 /**
@@ -537,7 +548,7 @@ public void asapNotifyBTDiscoverableStarted() {
537548 @ Override
538549 @ CallSuper
539550 public void asapNotifyBTDiscoverableStopped () {
540- this .asapApplication . setBTDiscoverable (false );
551+ this .asapAndroidPeer . notifyBTDiscoverable (false );
541552 }
542553
543554 /**
@@ -551,7 +562,7 @@ public void asapNotifyBTDiscoverableStopped() {
551562 @ Override
552563 @ CallSuper
553564 public void asapNotifyBTEnvironmentStarted () {
554- this .asapApplication . setBTEnvironmentRunning (true );
565+ this .asapAndroidPeer . notifyBTEnvironmentRunning (true );
555566 }
556567
557568 /**
@@ -565,7 +576,7 @@ public void asapNotifyBTEnvironmentStarted() {
565576 @ Override
566577 @ CallSuper
567578 public void asapNotifyBTEnvironmentStopped () {
568- this .asapApplication . setBTEnvironmentRunning (false );
579+ this .asapAndroidPeer . notifyBTEnvironmentRunning (false );
569580 }
570581
571582 /**
@@ -581,7 +592,7 @@ public void asapNotifyBTEnvironmentStopped() {
581592 @ Override
582593 @ CallSuper
583594 public void asapNotifyOnlinePeersChanged (Set <CharSequence > peerList ) {
584- this .asapApplication . setOnlinePeersList (peerList );
595+ this .asapAndroidPeer . notifyOnlinePeersChanged (peerList );
585596 }
586597
587598 /**
@@ -595,7 +606,7 @@ public void asapNotifyOnlinePeersChanged(Set<CharSequence> peerList) {
595606 @ Override
596607 @ CallSuper
597608 public void asapNotifyBTDiscoveryStarted () {
598- this .asapApplication . setBTDiscovery (true );
609+ this .asapAndroidPeer . notifyBTDiscovery (true );
599610 }
600611
601612 /**
@@ -609,7 +620,7 @@ public void asapNotifyBTDiscoveryStarted() {
609620 @ Override
610621 @ CallSuper
611622 public void asapNotifyBTDiscoveryStopped () {
612- this .asapApplication . setBTDiscovery (false );
623+ this .asapAndroidPeer . notifyBTDiscovery (false );
613624 }
614625
615626 ////////////////////////////////////////////////////////////////////////////////
@@ -620,20 +631,20 @@ public void asapNotifyBTDiscoveryStopped() {
620631 * @return true if bluetooth environment is one.
621632 */
622633 public boolean isBluetoothEnvironmentOn () {
623- return this .asapApplication .getBTEnvironmentRunning ();
634+ return this .asapAndroidPeer .getBTEnvironmentRunning ();
624635 }
625636
626637 /**
627638 * @return true if this device is discoverable now.
628639 */
629640 public boolean isBluetoothDiscoverable () {
630- return this .asapApplication .getBTDiscoverable ();
641+ return this .asapAndroidPeer .getBTDiscoverable ();
631642 }
632643
633644 /**
634645 * @return true if this device looking for other Bluetooth devices.
635646 */
636647 public boolean isBluetoothDiscovery () {
637- return this .asapApplication .getBTDiscovery ();
648+ return this .asapAndroidPeer .getBTDiscovery ();
638649 }
639650}
0 commit comments