@@ -128,7 +128,7 @@ protected void onCreate(final Bundle savedInstanceState) {
128128 tvShadow .setOnClickListener (new View .OnClickListener () {
129129 @ Override
130130 public void onClick (View v ) {
131- if (bottomSheetBehavior .getState ()== BottomSheetBehavior .STATE_EXPANDED )
131+ if (bottomSheetBehavior .getState () == BottomSheetBehavior .STATE_EXPANDED )
132132 bottomSheetBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
133133 tvShadow .setVisibility (View .GONE );
134134 }
@@ -184,6 +184,7 @@ public void onClick(View v) {
184184 switch (knobState ) {
185185 case 3 :
186186 if (scienceLab .isConnected ()) {
187+ v .setEnabled (false );
187188 DecimalFormat resistanceFormat = new DecimalFormat ("#.##" );
188189 Double resistance ;
189190 Double avgResistance = 0.0 ;
@@ -225,33 +226,41 @@ public void onClick(View v) {
225226 saveAndSetData (Resistance , resistanceUnit );
226227 if (recordData )
227228 record ("Resistance" , Resistance + recordUnit );
229+ v .setEnabled (true );
228230 }
229231 break ;
230232 case 4 :
231233 if (scienceLab .isConnected ()) {
234+ v .setEnabled (false );
232235 Double capacitance = scienceLab .getCapacitance ();
233236 DecimalFormat capacitanceFormat = new DecimalFormat ("#.##" );
234237 String Capacitance ;
235238 String capacitanceUnit ;
236- if (capacitance < 1e-9 ) {
237- Capacitance = capacitanceFormat .format ((capacitance / 1e-12 ));
238- capacitanceUnit = "pF" ;
239- } else if (capacitance < 1e-6 ) {
240- Capacitance = capacitanceFormat .format ((capacitance / 1e-9 ));
241- capacitanceUnit = "nF" ;
242- } else if (capacitance < 1e-3 ) {
243- Capacitance = capacitanceFormat .format ((capacitance / 1e-6 ));
244- capacitanceUnit = "\u00B5 " + "F" ;
245- } else if (capacitance < 1e-1 ) {
246- Capacitance = capacitanceFormat .format ((capacitance / 1e-3 ));
247- capacitanceUnit = "mF" ;
239+ if (capacitance == null ) {
240+ Capacitance = "Cannot measure!" ;
241+ capacitanceUnit = "" ;
248242 } else {
249- Capacitance = capacitanceFormat .format (capacitance );
250- capacitanceUnit = getString (R .string .capacitance_unit );
243+ if (capacitance < 1e-9 ) {
244+ Capacitance = capacitanceFormat .format ((capacitance / 1e-12 ));
245+ capacitanceUnit = "pF" ;
246+ } else if (capacitance < 1e-6 ) {
247+ Capacitance = capacitanceFormat .format ((capacitance / 1e-9 ));
248+ capacitanceUnit = "nF" ;
249+ } else if (capacitance < 1e-3 ) {
250+ Capacitance = capacitanceFormat .format ((capacitance / 1e-6 ));
251+ capacitanceUnit = "\u00B5 " + "F" ;
252+ } else if (capacitance < 1e-1 ) {
253+ Capacitance = capacitanceFormat .format ((capacitance / 1e-3 ));
254+ capacitanceUnit = "mF" ;
255+ } else {
256+ Capacitance = capacitanceFormat .format (capacitance );
257+ capacitanceUnit = getString (R .string .capacitance_unit );
258+ }
251259 }
252260 saveAndSetData (Capacitance , capacitanceUnit );
253261 if (recordData )
254262 record ("Capacitance" , Capacitance + capacitanceUnit );
263+ v .setEnabled (true );
255264 }
256265 break ;
257266 case 5 :
@@ -260,26 +269,32 @@ public void onClick(View v) {
260269 case 8 :
261270 if (!switchIsChecked ) {
262271 if (scienceLab .isConnected ()) {
272+ v .setEnabled (false );
263273 Double frequency = scienceLab .getFrequency (knobMarker [knobState ], null );
264274 saveAndSetData (String .valueOf (frequency ), getString (R .string .frequency_unit ));
265275 if (recordData )
266276 record (knobMarker [knobState ], String .valueOf (frequency ) + getString (R .string .frequency_unit ));
277+ v .setEnabled (true );
267278 }
268279 } else {
269280 if (scienceLab .isConnected ()) {
281+ v .setEnabled (false );
270282 scienceLab .countPulses (knobMarker [knobState ]);
271283 double pulseCount = scienceLab .readPulseCount ();
272284 saveAndSetData (String .valueOf (pulseCount ), "" );
273285 if (recordData )
274286 record (knobMarker [knobState ], String .valueOf (pulseCount ));
287+ v .setEnabled (true );
275288 }
276289 }
277290 break ;
278291 default :
279292 if (scienceLab .isConnected ()) {
293+ v .setEnabled (false );
280294 saveAndSetData (String .valueOf (String .format (Locale .ENGLISH , "%.2f" , scienceLab .getVoltage (knobMarker [knobState ], 1 ))), getString (R .string .multimeter_voltage_unit ));
281295 if (recordData )
282296 record (knobMarker [knobState ], String .valueOf (String .format (Locale .ENGLISH , "%.2f" , scienceLab .getVoltage (knobMarker [knobState ], 1 ))) + getString (R .string .multimeter_voltage_unit ));
297+ v .setEnabled (true );
283298 }
284299 break ;
285300 }
0 commit comments