Skip to content

Commit 2b94551

Browse files
fix : PinLayoutV6
1 parent ba0884f commit 2b94551

File tree

4 files changed

+604
-37
lines changed

4 files changed

+604
-37
lines changed

app/src/main/java/io/pslab/activity/MainActivity.java

+49-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.pslab.activity;
22

3+
import static io.pslab.others.ScienceLabCommon.isWifiConnected;
34
import static io.pslab.others.ScienceLabCommon.scienceLab;
45

56
import android.app.PendingIntent;
@@ -10,6 +11,7 @@
1011
import android.content.IntentFilter;
1112
import android.hardware.usb.UsbDevice;
1213
import android.hardware.usb.UsbManager;
14+
import android.net.wifi.WifiManager;
1315
import android.os.Bundle;
1416
import android.os.Handler;
1517
import android.util.Log;
@@ -50,11 +52,13 @@
5052
import io.pslab.fragment.HomeFragment;
5153
import io.pslab.fragment.InstrumentsFragment;
5254
import io.pslab.fragment.PSLabPinLayoutFragment;
55+
import io.pslab.fragment.PSLabPinLayoutFragment_v6;
5356
import io.pslab.others.CustomSnackBar;
5457
import io.pslab.others.CustomTabService;
5558
import io.pslab.others.InitializationVariable;
5659
import io.pslab.others.ScienceLabCommon;
5760
import io.pslab.receivers.USBDetachReceiver;
61+
import io.pslab.receivers.WifiDisconnectReceiver;
5862

5963
public class MainActivity extends AppCompatActivity {
6064

@@ -83,6 +87,7 @@ public class MainActivity extends AppCompatActivity {
8387
private static final String TAG_INSTRUMENTS = "instruments";
8488
private static final String TAG_ABOUTUS = "aboutUs";
8589
private static final String TAG_PINLAYOUT = "pinLayout";
90+
private static final String TAG_PINLAYOUT_V6 = "PINLAYOUTV6";
8691
private static final String TAG_FAQ = "faq";
8792
private static String CURRENT_TAG = TAG_INSTRUMENTS;
8893
private String[] activityTitles;
@@ -136,6 +141,11 @@ protected void onCreate(Bundle savedInstanceState) {
136141
usbDetachReceiver = new USBDetachReceiver(this);
137142
registerReceiver(usbDetachReceiver, usbDetachFilter);
138143

144+
IntentFilter wifiDisconnectFilter = new IntentFilter();
145+
wifiDisconnectFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
146+
WifiDisconnectReceiver wifiDisconnectReceiver = new WifiDisconnectReceiver(this);
147+
registerReceiver(wifiDisconnectReceiver, wifiDisconnectFilter);
148+
139149
setSupportActionBar(toolbar);
140150
mHandler = new Handler();
141151

@@ -329,6 +339,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
329339
OssLicensesMenuActivity.setActivityTitle(getString(R.string.third_party_libs));
330340
startActivity(new Intent(MainActivity.this, OssLicensesMenuActivity.class));
331341
break;
342+
332343
default:
333344
navItemIndex = 0;
334345
}
@@ -414,21 +425,30 @@ public boolean onCreateOptionsMenu(Menu menu) {
414425
@Override
415426
public boolean onOptionsItemSelected(MenuItem item) {
416427
switch (item.getItemId()) {
417-
case R.id.menu_pslab_connected:
428+
case R.id.menu_wifi_connected, R.id.menu_pslab_connected:
418429
CustomSnackBar.showSnackBar(findViewById(android.R.id.content),
419430
getString(R.string.device_connected_successfully), null, null, Snackbar.LENGTH_SHORT);
420431
break;
421432
case R.id.menu_pslab_disconnected:
422433
attemptToConnectPSLab();
423434
break;
424-
case R.id.menu_pslab_layout_front:
435+
case R.id.menu_pslab_layout_front_v5:
425436
PSLabPinLayoutFragment.frontSide = true;
426-
displayPSLabPinLayout();
437+
displayPSLabPinLayout(TAG_PINLAYOUT);
427438
break;
428-
case R.id.menu_pslab_layout_back:
439+
case R.id.menu_pslab_layout_back_v5:
429440
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);
431450
break;
451+
432452
default:
433453
break;
434454
}
@@ -457,20 +477,36 @@ private void attemptToConnectPSLab() {
457477
}
458478
}
459479

460-
private void displayPSLabPinLayout() {
461-
CURRENT_TAG = TAG_PINLAYOUT;
480+
private void displayPSLabPinLayout(String fragmentTag) {
481+
CURRENT_TAG = fragmentTag;
462482
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+
464491
Runnable mPendingRunnable = new Runnable() {
465492
@Override
466493
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+
468503
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
469504
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)
471506
.commitAllowingStateLoss();
472507
}
473508
};
509+
474510
mHandler.post(mPendingRunnable);
475511
}
476512

@@ -496,8 +532,9 @@ private void attemptToGetUSBPermission() {
496532

497533
@Override
498534
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);
501538
setPSLabVersionIDs();
502539
return true;
503540
}
@@ -552,7 +589,6 @@ public void onReceive(Context context, Intent intent) {
552589
}
553590
}
554591
};
555-
556592
@Override
557593
protected void onNewIntent(Intent intent) {
558594
super.onNewIntent(intent);
@@ -573,7 +609,6 @@ protected void onNewIntent(Intent intent) {
573609
}
574610
}
575611
}
576-
577612
@Override
578613
protected void onPostResume() {
579614
super.onPostResume();

0 commit comments

Comments
 (0)