|
38 | 38 | package com.st.BlueMS; |
39 | 39 |
|
40 | 40 |
|
| 41 | +import android.content.SharedPreferences; |
| 42 | +import android.preference.PreferenceManager; |
| 43 | +import android.widget.Toast; |
| 44 | + |
41 | 45 | import androidx.annotation.NonNull; |
42 | 46 |
|
43 | 47 | import com.st.BlueNRG.fwUpgrade.BlueNRGAdvertiseFilter; |
|
48 | 52 | import com.st.BlueSTSDK.Utils.ConnectionOption; |
49 | 53 | import com.st.BlueSTSDK.Utils.advertise.AdvertiseFilter; |
50 | 54 | import com.st.BlueSTSDK.gui.fwUpgrade.FwUpgradeActivity; |
| 55 | +import com.st.BlueSTSDK.gui.util.SimpleFragmentDialog; |
51 | 56 | import com.st.STM32WB.fwUpgrade.FwUpgradeSTM32WBActivity; |
52 | 57 | import com.st.STM32WB.fwUpgrade.feature.STM32OTASupport; |
53 | 58 | import com.st.STM32WB.p2pDemo.Peer2PeerDemoConfiguration; |
@@ -87,18 +92,58 @@ public void onNodeSelected(@NonNull Node n) { |
87 | 92 |
|
88 | 93 | ConnectionOption options = optionsBuilder.build(); |
89 | 94 |
|
90 | | - n.enableNodeServer(BLENodeDefines.FeatureCharacteristics.getDefaultExportedFeature()); |
| 95 | + //disable the ble server for sensor tile box, to improve stability for the fw upgrade. |
| 96 | + // it is not clear why.. and probably is not the root cause |
| 97 | + if(n.getType() != Node.Type.SENSOR_TILE_BOX) { |
| 98 | + try { |
| 99 | + n.enableNodeServer(BLENodeDefines.FeatureCharacteristics.getDefaultExportedFeature()); |
| 100 | + } catch (IllegalStateException e) { |
| 101 | + Toast.makeText(this, R.string.nodeList_serverNotStarted, Toast.LENGTH_SHORT).show(); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + |
91 | 106 |
|
92 | 107 | if(n.getAdvertiseInfo() instanceof BlueNRGAdvertiseFilter.BlueNRGAdvertiseInfo) |
93 | 108 | startActivity(FwUpgradeActivity.getStartIntent(this, n,false,options)); |
94 | 109 | else if(n.getType()== Node.Type.STEVAL_WESU1) |
95 | 110 | startActivity(DemosActivityWesu.getStartIntent(this,n,options)); |
96 | | - else if (STM32OTASupport.isOTANode(n)){ |
97 | | - startActivity(FwUpgradeSTM32WBActivity.getStartIntent(this, n,null,null,null)); |
| 111 | + else if (STM32OTASupport.isOTANode(n)) { |
| 112 | + startActivity(FwUpgradeSTM32WBActivity.getStartIntent(this, n, null, null, null)); |
| 113 | + }else if (n.getType() == Node.Type.SENSOR_TILE_BOX){ |
| 114 | + displayPinWarningsAndConnect(n,options); |
98 | 115 | }else { |
99 | 116 | startActivity(DemosActivity.getStartIntent(this, n, options)); |
100 | 117 | } |
101 | 118 |
|
102 | 119 | } |
103 | 120 |
|
| 121 | + |
| 122 | + private void displayPinWarningsAndConnect(Node node, ConnectionOption options){ |
| 123 | + if(stBoxPinDialogNeedToBeShown()){ |
| 124 | + displayPinWarnings(node,options); |
| 125 | + }else{ |
| 126 | + startActivity(DemosActivity.getStartIntent(this, node, options)); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + private static final String STBOX_PIN_DIALOG_SHOWN = NodeListActivity.class.getCanonicalName()+".STBOX_PIN_DIALOG_SHOWN"; |
| 131 | + private static final String STBOX_PIN_DIALOG_SHOWN_TAG = NodeListActivity.class.getCanonicalName()+".STBOX_PIN_DIALOG_SHOWN_TAG"; |
| 132 | + |
| 133 | + private boolean stBoxPinDialogNeedToBeShown(){ |
| 134 | + final SharedPreferences prefs= PreferenceManager.getDefaultSharedPreferences(this); |
| 135 | + return !prefs.contains(STBOX_PIN_DIALOG_SHOWN); |
| 136 | + } |
| 137 | + |
| 138 | + private void displayPinWarnings(Node node, ConnectionOption options) { |
| 139 | + SimpleFragmentDialog dialog = SimpleFragmentDialog.newInstance(R.string.nodeList_stbox_pinTitle,R.string.nodeList_stbox_pinDesc); |
| 140 | + dialog.show(getSupportFragmentManager(),STBOX_PIN_DIALOG_SHOWN_TAG); |
| 141 | + dialog.setOnclickListener((dialogInterface, i) -> { |
| 142 | + PreferenceManager.getDefaultSharedPreferences(this).edit() |
| 143 | + .putBoolean(STBOX_PIN_DIALOG_SHOWN,true) |
| 144 | + .apply(); |
| 145 | + startActivity(DemosActivity.getStartIntent(dialog.getContext(), node, options)); |
| 146 | + }); |
| 147 | + } |
| 148 | + |
104 | 149 | }//NodeListActivity |
0 commit comments