1
1
package io .pslab .activity ;
2
2
3
+ import static io .pslab .others .ScienceLabCommon .isWifiConnected ;
3
4
import static io .pslab .others .ScienceLabCommon .scienceLab ;
4
5
5
6
import android .app .PendingIntent ;
10
11
import android .content .IntentFilter ;
11
12
import android .hardware .usb .UsbDevice ;
12
13
import android .hardware .usb .UsbManager ;
14
+ import android .net .wifi .WifiManager ;
13
15
import android .os .Bundle ;
14
16
import android .os .Handler ;
15
17
import android .util .Log ;
50
52
import io .pslab .fragment .HomeFragment ;
51
53
import io .pslab .fragment .InstrumentsFragment ;
52
54
import io .pslab .fragment .PSLabPinLayoutFragment ;
55
+ import io .pslab .fragment .PSLabPinLayoutFragment_v6 ;
53
56
import io .pslab .others .CustomSnackBar ;
54
57
import io .pslab .others .CustomTabService ;
55
58
import io .pslab .others .InitializationVariable ;
56
59
import io .pslab .others .ScienceLabCommon ;
57
60
import io .pslab .receivers .USBDetachReceiver ;
61
+ import io .pslab .receivers .WifiDisconnectReceiver ;
58
62
59
63
public class MainActivity extends AppCompatActivity {
60
64
@@ -83,6 +87,7 @@ public class MainActivity extends AppCompatActivity {
83
87
private static final String TAG_INSTRUMENTS = "instruments" ;
84
88
private static final String TAG_ABOUTUS = "aboutUs" ;
85
89
private static final String TAG_PINLAYOUT = "pinLayout" ;
90
+ private static final String TAG_PINLAYOUT_V6 = "PINLAYOUTV6" ;
86
91
private static final String TAG_FAQ = "faq" ;
87
92
private static String CURRENT_TAG = TAG_INSTRUMENTS ;
88
93
private String [] activityTitles ;
@@ -136,6 +141,11 @@ protected void onCreate(Bundle savedInstanceState) {
136
141
usbDetachReceiver = new USBDetachReceiver (this );
137
142
registerReceiver (usbDetachReceiver , usbDetachFilter );
138
143
144
+ IntentFilter wifiDisconnectFilter = new IntentFilter ();
145
+ wifiDisconnectFilter .addAction (WifiManager .NETWORK_STATE_CHANGED_ACTION );
146
+ WifiDisconnectReceiver wifiDisconnectReceiver = new WifiDisconnectReceiver (this );
147
+ registerReceiver (wifiDisconnectReceiver , wifiDisconnectFilter );
148
+
139
149
setSupportActionBar (toolbar );
140
150
mHandler = new Handler ();
141
151
@@ -329,6 +339,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
329
339
OssLicensesMenuActivity .setActivityTitle (getString (R .string .third_party_libs ));
330
340
startActivity (new Intent (MainActivity .this , OssLicensesMenuActivity .class ));
331
341
break ;
342
+
332
343
default :
333
344
navItemIndex = 0 ;
334
345
}
@@ -414,21 +425,30 @@ public boolean onCreateOptionsMenu(Menu menu) {
414
425
@ Override
415
426
public boolean onOptionsItemSelected (MenuItem item ) {
416
427
switch (item .getItemId ()) {
417
- case R .id .menu_pslab_connected :
428
+ case R .id .menu_wifi_connected , R . id . menu_pslab_connected :
418
429
CustomSnackBar .showSnackBar (findViewById (android .R .id .content ),
419
430
getString (R .string .device_connected_successfully ), null , null , Snackbar .LENGTH_SHORT );
420
431
break ;
421
432
case R .id .menu_pslab_disconnected :
422
433
attemptToConnectPSLab ();
423
434
break ;
424
- case R .id .menu_pslab_layout_front :
435
+ case R .id .menu_pslab_layout_front_v5 :
425
436
PSLabPinLayoutFragment .frontSide = true ;
426
- displayPSLabPinLayout ();
437
+ displayPSLabPinLayout (TAG_PINLAYOUT );
427
438
break ;
428
- case R .id .menu_pslab_layout_back :
439
+ case R .id .menu_pslab_layout_back_v5 :
429
440
PSLabPinLayoutFragment .frontSide = false ;
430
- displayPSLabPinLayout ();
441
+ displayPSLabPinLayout (TAG_PINLAYOUT );
442
+ break ;
443
+ case R .id .menu_pslab_layout_front_v6 :
444
+ PSLabPinLayoutFragment_v6 .topside =true ;
445
+ displayPSLabPinLayout (TAG_PINLAYOUT_V6 );
446
+ break ;
447
+ case R .id .menu_pslab_layout_back_v6 :
448
+ PSLabPinLayoutFragment_v6 .topside =false ;
449
+ displayPSLabPinLayout (TAG_PINLAYOUT_V6 );
431
450
break ;
451
+
432
452
default :
433
453
break ;
434
454
}
@@ -457,20 +477,36 @@ private void attemptToConnectPSLab() {
457
477
}
458
478
}
459
479
460
- private void displayPSLabPinLayout () {
461
- CURRENT_TAG = TAG_PINLAYOUT ;
480
+ private void displayPSLabPinLayout (String fragmentTag ) {
481
+ CURRENT_TAG = fragmentTag ;
462
482
navigationView .getMenu ().getItem (navItemIndex ).setChecked (false );
463
- setToolbarTitle (getResources ().getString (R .string .pslab_pinlayout ));
483
+
484
+ // Set toolbar title based on the fragment tag
485
+ if (fragmentTag .equals (TAG_PINLAYOUT )) {
486
+ setToolbarTitle (getResources ().getString (R .string .pslab_pinlayout ));
487
+ } else if (fragmentTag .equals (TAG_PINLAYOUT_V6 )) {
488
+ setToolbarTitle (getResources ().getString (R .string .pslab_pinlayout_v6 ));
489
+ }
490
+
464
491
Runnable mPendingRunnable = new Runnable () {
465
492
@ Override
466
493
public void run () {
467
- Fragment fragment = PSLabPinLayoutFragment .newInstance ();
494
+ Fragment fragment ;
495
+ if (fragmentTag .equals (TAG_PINLAYOUT )) {
496
+ fragment = PSLabPinLayoutFragment .newInstance ();
497
+ } else if (fragmentTag .equals (TAG_PINLAYOUT_V6 )) {
498
+ fragment = PSLabPinLayoutFragment_v6 .newInstance ();
499
+ } else {
500
+ return ; // Exit if no valid tag is provided
501
+ }
502
+
468
503
FragmentTransaction fragmentTransaction = getSupportFragmentManager ().beginTransaction ();
469
504
fragmentTransaction .setCustomAnimations (R .anim .fade_in , R .anim .fade_out )
470
- .replace (R .id .frame , fragment , TAG_PINLAYOUT )
505
+ .replace (R .id .frame , fragment , fragmentTag )
471
506
.commitAllowingStateLoss ();
472
507
}
473
508
};
509
+
474
510
mHandler .post (mPendingRunnable );
475
511
}
476
512
@@ -496,8 +532,9 @@ private void attemptToGetUSBPermission() {
496
532
497
533
@ Override
498
534
public boolean onPrepareOptionsMenu (Menu menu ) {
499
- menu .getItem (0 ).setVisible (PSLabisConnected );
500
- menu .getItem (1 ).setVisible (!PSLabisConnected );
535
+ menu .getItem (0 ).setVisible (isWifiConnected );
536
+ menu .getItem (1 ).setVisible (PSLabisConnected );
537
+ menu .getItem (2 ).setVisible (!PSLabisConnected && !isWifiConnected );
501
538
setPSLabVersionIDs ();
502
539
return true ;
503
540
}
@@ -552,7 +589,6 @@ public void onReceive(Context context, Intent intent) {
552
589
}
553
590
}
554
591
};
555
-
556
592
@ Override
557
593
protected void onNewIntent (Intent intent ) {
558
594
super .onNewIntent (intent );
@@ -573,7 +609,6 @@ protected void onNewIntent(Intent intent) {
573
609
}
574
610
}
575
611
}
576
-
577
612
@ Override
578
613
protected void onPostResume () {
579
614
super .onPostResume ();
0 commit comments