2121import io .pslab .DataFormatter ;
2222import io .pslab .R ;
2323import io .pslab .activity .OscilloscopeActivity ;
24- import io .pslab .others .NothingSelectedSpinnerAdapter ;
2524
2625public class ChannelParametersFragment extends Fragment {
2726
@@ -30,13 +29,11 @@ public class ChannelParametersFragment extends Fragment {
3029 private CheckBox checkBoxCH1 ;
3130 private CheckBox checkBoxCH2 ;
3231 private CheckBox checkBoxCH3 ;
33- private CheckBox checkBoxMIC ;
3432 private Spinner spinnerRangeCh1 ;
3533 private Spinner spinnerRangeCh2 ;
3634 private Spinner spinnerChannelSelect ;
37- private Spinner spinnerMICSelect ;
38- private int micSelectedPosition ;
39-
35+ private CheckBox builtInMicCheckBox ;
36+ private CheckBox pslabMicCheckBox ;
4037
4138 public static ChannelParametersFragment newInstance () {
4239 return new ChannelParametersFragment ();
@@ -56,15 +53,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
5653 spinnerRangeCh1 = v .findViewById (R .id .spinner_range_ch1_cp );
5754 spinnerRangeCh2 = v .findViewById (R .id .spinner_range_ch2_cp );
5855 spinnerChannelSelect = v .findViewById (R .id .spinner_channel_select_cp );
59- spinnerMICSelect = v .findViewById (R .id .spinner_mic_select_cp );
6056
6157 boolean tabletSize = getResources ().getBoolean (R .bool .isTablet );
6258 checkBoxCH1 = v .findViewById (R .id .checkBox_ch1_cp );
6359 checkBoxCH2 = v .findViewById (R .id .checkBox_ch2_cp );
6460 checkBoxCH3 = v .findViewById (R .id .checkBox_ch3_cp );
6561 checkBoxCH3 .setText (getString (R .string .ch3_value , 3.3 ));
66- checkBoxMIC = v .findViewById (R .id .checkBox_mic_cp );
6762
63+ builtInMicCheckBox = v .findViewById (R .id .built_in_mic_cb );
64+ pslabMicCheckBox = v .findViewById (R .id .pslab_mic_cb );
6865 ArrayAdapter <String > rangesAdapter ;
6966 ArrayAdapter <String > channelsAdapter ;
7067 ArrayAdapter <String > micsAdapter ;
@@ -88,9 +85,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
8885 spinnerRangeCh2 .setSelection (rangesAdapter .getPosition ("+/-16V" ), true );
8986 spinnerChannelSelect .setAdapter (channelsAdapter );
9087 spinnerChannelSelect .setSelection (channelsAdapter .getPosition ("CH1" ), true );
91- spinnerMICSelect .setAdapter (new NothingSelectedSpinnerAdapter (micsAdapter ,
92- R .layout .nothing_selected_spinner_row ,
93- getActivity ()));
9488
9589 spinnerRangeCh1 .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
9690 @ Override
@@ -220,31 +214,6 @@ public void onNothingSelected(AdapterView<?> parent) {
220214 }
221215 });
222216
223- spinnerMICSelect .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
224- @ Override
225- public void onItemSelected (AdapterView <?> parent , View view , int position , long id ) {
226- micSelectedPosition = position ;
227- if (position == 1 ) {
228- ((OscilloscopeActivity ) getActivity ()).isInBuiltMicSelected = false ;
229- if (checkBoxMIC .isChecked ()) {
230- ((OscilloscopeActivity ) getActivity ()).isMICSelected = true ;
231- ((OscilloscopeActivity ) getActivity ()).isAudioInputSelected = true ;
232- }
233- } else {
234- ((OscilloscopeActivity ) getActivity ()).isMICSelected = false ;
235- if (checkBoxMIC .isChecked ()) {
236- ((OscilloscopeActivity ) getActivity ()).isInBuiltMicSelected = true ;
237- ((OscilloscopeActivity ) getActivity ()).isAudioInputSelected = true ;
238- }
239- }
240- }
241-
242- @ Override
243- public void onNothingSelected (AdapterView <?> parent ) {
244-
245- }
246- });
247-
248217 checkBoxCH1 .setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
249218 @ Override
250219 public void onCheckedChanged (CompoundButton buttonView , boolean isChecked ) {
@@ -265,29 +234,37 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
265234 ((OscilloscopeActivity ) getActivity ()).isCH3Selected = isChecked ;
266235 }
267236 });
268- checkBoxMIC .setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
237+ builtInMicCheckBox .setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
269238 @ Override
270239 public void onCheckedChanged (CompoundButton buttonView , boolean isChecked ) {
271- if (micSelectedPosition == 1 ) {
272- ((OscilloscopeActivity ) getActivity ()).isAudioInputSelected = isChecked ;
273- ((OscilloscopeActivity ) getActivity ()).isMICSelected = isChecked ;
274- } else if (micSelectedPosition == 2 ) {
275- ((OscilloscopeActivity ) getActivity ()).isAudioInputSelected = isChecked ;
276- // check for RECORD_AUDIO permission if has then change boolean
277- if (isChecked )
278- if (ContextCompat .checkSelfPermission (getActivity (), Manifest .permission .RECORD_AUDIO ) != PackageManager .PERMISSION_GRANTED ) {
279- requestPermissions (new String []{Manifest .permission .RECORD_AUDIO }, RECORD_AUDIO_REQUEST_CODE );
280- } else {
281- ((OscilloscopeActivity ) getActivity ()).isInBuiltMicSelected = true ;
282- }
283- else
284- ((OscilloscopeActivity ) getActivity ()).isInBuiltMicSelected = false ;
285- } else {
286- ((OscilloscopeActivity ) getActivity ()).isAudioInputSelected = false ;
240+ ((OscilloscopeActivity ) getActivity ()).isInBuiltMicSelected = isChecked ;
241+ ((OscilloscopeActivity ) getActivity ()).isAudioInputSelected = isChecked ;
242+ ((OscilloscopeActivity ) getActivity ()).isMICSelected = !isChecked ;
243+ if (isChecked ) {
244+ pslabMicCheckBox .setChecked (false );
245+ if (ContextCompat .checkSelfPermission (getActivity (), Manifest .permission .RECORD_AUDIO ) != PackageManager .PERMISSION_GRANTED ) {
246+ requestPermissions (new String []{Manifest .permission .RECORD_AUDIO }, RECORD_AUDIO_REQUEST_CODE );
247+ ((OscilloscopeActivity ) getActivity ()).isAudioInputSelected = false ;
248+ }
287249 }
288250 }
289251 });
290252
253+ pslabMicCheckBox .setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
254+ @ Override
255+ public void onCheckedChanged (CompoundButton buttonView , boolean isChecked ) {
256+ ((OscilloscopeActivity ) getActivity ()).isMICSelected = isChecked ;
257+ ((OscilloscopeActivity ) getActivity ()).isAudioInputSelected = isChecked ;
258+ ((OscilloscopeActivity ) getActivity ()).isInBuiltMicSelected = !isChecked ;
259+ if (isChecked ) {
260+ builtInMicCheckBox .setChecked (false );
261+ if (ContextCompat .checkSelfPermission (getActivity (), Manifest .permission .RECORD_AUDIO ) != PackageManager .PERMISSION_GRANTED ) {
262+ requestPermissions (new String []{Manifest .permission .RECORD_AUDIO }, RECORD_AUDIO_REQUEST_CODE );
263+ ((OscilloscopeActivity ) getActivity ()).isAudioInputSelected = false ;
264+ }
265+ }
266+ }
267+ });
291268 return v ;
292269 }
293270
@@ -298,8 +275,8 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
298275 ((OscilloscopeActivity ) getActivity ()).isInBuiltMicSelected = true ;
299276 } else {
300277 Toast .makeText (getActivity (), "This feature won't work." , Toast .LENGTH_SHORT ).show ();
301- if (checkBoxMIC .isChecked ())
302- checkBoxMIC .toggle ();
278+ if (builtInMicCheckBox .isChecked ())
279+ builtInMicCheckBox .toggle ();
303280 }
304281 }
305282 }
0 commit comments