@@ -30,6 +30,7 @@ public class ASAPActivity extends AppCompatActivity implements
3030 ASAPServiceRequestListener , ASAPServiceNotificationListener {
3131
3232 private static final int MY_REQUEST_2ENABLE_BT = 1 ;
33+ private static final int MY_REQUEST_SET_BT_DISCOVERABLE = 2 ;
3334
3435 private Messenger mService ;
3536 private boolean mBound ;
@@ -40,6 +41,10 @@ public ASAPActivity(ASAPApplication asapApplication) {
4041 this .asapApplication = asapApplication ;
4142 }
4243
44+ protected ASAPApplication getASAPApplication () {
45+ return this .asapApplication ;
46+ }
47+
4348 ///////////////////////////////////////////////////////////////////////////////////////
4449 // asap service requests //
4550 ///////////////////////////////////////////////////////////////////////////////////////
@@ -83,26 +88,27 @@ public void asapSrcRq_startBTDiscoverable(int time) {
8388 this .visibilityTime );
8489
8590 // ask user to confirm - result is passed to onActivityResult
86- this .startActivity (discoverableIntent );
91+ this .startActivityForResult (discoverableIntent , MY_REQUEST_SET_BT_DISCOVERABLE );
8792 }
8893
8994 public void onActivityResult (int requestCode , int resultCode , Intent data ) {
9095 Log .d (this .getLogStart (),
91- "requestCode == " + requestCode +
96+ ".onActivityResult(): requestCode == " + requestCode +
9297 " / resultCode == " + resultCode );
9398
9499 if (requestCode == MY_REQUEST_2ENABLE_BT && resultCode == RESULT_OK ) {
95100 Log .d (this .getLogStart (), "Bluetooth now enabled - ask service to start BT" );
96101 this .sendMessage2Service (ASAPServiceMethods .START_BLUETOOTH );
97102 }
98103
99- if (resultCode == this .visibilityTime ) {
100- Log .d (this .getLogStart (), "user allowed BT discoverability for seconds: "
101- + this .visibilityTime );
104+ if (requestCode == MY_REQUEST_SET_BT_DISCOVERABLE ) {
105+ Log .d (this .getLogStart (),
106+ "user allowed BT discoverability for seconds: "
107+ + resultCode );
102108
103109 // notify
104- Log .d (this .getLogStart (), "call aspNotifyBTDiscoverableStarted ()" );
105- this .aspNotifyBTDiscoverableStarted ();
110+ Log .d (this .getLogStart (), "call asapNotifyBTDiscoverableStarted ()" );
111+ this .asapNotifyBTDiscoverableStarted ();
106112 }
107113 }
108114
@@ -266,6 +272,7 @@ protected void onStart() {
266272 // Bind to the service
267273 super .onStart ();
268274 Log .d (this .getLogStart (), "onStart" );
275+ this .asapApplication .setActivity (this );
269276 this .setupASAPServiceNotificationBroadcastReceiver ();
270277 this .setupASAPReceivedBroadcastReceiver ();
271278 this .bindServices ();
@@ -349,7 +356,7 @@ public void onServiceConnected(ComponentName className, IBinder service) {
349356 mService = new Messenger (service );
350357 mBound = true ;
351358
352- Log .d (getLogStart (), "connection established " );
359+ Log .d (getLogStart (), "asap activity got connected to asap service " );
353360 if (messageStorage != null && messageStorage .size () > 0 ) {
354361 Log .d (getLogStart (), "send stored messages | #msg = " + messageStorage .size ());
355362 for (Message msg : messageStorage ) {
@@ -369,7 +376,7 @@ public void onServiceDisconnected(ComponentName className) {
369376 };
370377
371378 @ Override
372- public void aspNotifyBTDiscoverableStarted () {
379+ public void asapNotifyBTDiscoverableStarted () {
373380 this .asapApplication .setBTDiscoverable (true );
374381 }
375382
@@ -379,22 +386,27 @@ public void asapNotifyBTDiscoverableStopped() {
379386 }
380387
381388 @ Override
382- public void aspNotifyBTEnvironmentStarted () {
389+ public void asapNotifyBTEnvironmentStarted () {
383390 this .asapApplication .setBTEnvironmentRunning (true );
384391 }
385392
386393 @ Override
387- public void aspNotifyBTEnvironmentStopped () {
394+ public void asapNotifyBTEnvironmentStopped () {
388395 this .asapApplication .setBTEnvironmentRunning (false );
389396 }
390397
391398 @ Override
392- public void aspNotifyBTDiscoveryStarted () {
399+ public void asapNotifyOnlinePeersChanged (List <CharSequence > peerList ) {
400+ this .asapApplication .setOnlinePeersList (peerList );
401+ }
402+
403+ @ Override
404+ public void asapNotifyBTDiscoveryStarted () {
393405 this .asapApplication .setBTDiscovery (true );
394406 }
395407
396408 @ Override
397- public void aspNotifyBTDiscoveryStopped () {
409+ public void asapNotifyBTDiscoveryStopped () {
398410 this .asapApplication .setBTDiscovery (false );
399411 }
400412
0 commit comments