Guest User

Untitled

a guest
Dec 27th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.83 KB | None | 0 0
  1.  
  2.  
  3. import android.app.Fragment;
  4. import android.app.FragmentTransaction;
  5. import android.os.Build;
  6. import android.os.Bundle;
  7. import android.support.annotation.RequiresApi;
  8. import android.util.Log;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.EditText;
  13. import android.widget.RadioGroup;
  14. import android.widget.Toast;
  15.  
  16. public class TimeIntervalModeFragment extends Fragment {
  17.  
  18.     private View view;
  19.     private EditText sTIEditText, msTIEditText, microsTIEditText, nsTIEditText, psTIEditText;
  20.     private int outputWidth = 0;
  21.     private boolean isPeriodTriggerSectionSelected;
  22.  
  23.     @Override
  24.     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  25.         view = inflater.inflate(R.layout.ti_mode_layout, container, false);
  26.  
  27.         sTIEditText = (EditText) view.findViewById(R.id.seconds);
  28.         msTIEditText = (EditText) view.findViewById(R.id.miliseconds);
  29.         microsTIEditText = (EditText) view.findViewById(R.id.microseconds);
  30.         nsTIEditText = (EditText) view.findViewById(R.id.nanoseconds);
  31.         psTIEditText = (EditText) view.findViewById(R.id.picoseconds);
  32.         Log.i("TIMF", " EditText is okey");
  33.  
  34.         RadioGroup outputWidthRadioGroup = (RadioGroup) view.findViewById(R.id.output_width_radio_group);
  35.         outputWidthRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  36.             @Override
  37.             public void onCheckedChanged(RadioGroup group, int checkedId) {
  38.                 if (checkedId == R.id.ten_radio_button) setOutputWidth(10);
  39.                 else if (checkedId == R.id.twenty_radio_button) setOutputWidth(20);
  40.                 else if (checkedId == R.id.fifty_radio_button) setOutputWidth(50);
  41.                 else if (checkedId == R.id.hundred_radio_button) setOutputWidth(100);
  42.                 else
  43.                     Toast.makeText(view.getContext(), "Non of output widths has been selected!", Toast.LENGTH_SHORT).show();
  44.                 Log.i("TIMF/checkedId", String.valueOf(checkedId));
  45.             }
  46.         });
  47.  
  48.         RadioGroup triggerRadioGroup = (RadioGroup) view.findViewById(R.id.trigger_radio_group);
  49.         triggerRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  50.             @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
  51.             @Override
  52.             public void onCheckedChanged(RadioGroup group, int checkedId) {
  53.                 // find which radio button is selected
  54.                 if (checkedId == R.id.period_trigger_section_radio_button) {
  55.                     setPeriodTriggerSectionSelected(true);
  56.                     PeriodTriggerSectionFragment periodTriggerSectionFragment = new PeriodTriggerSectionFragment();
  57.                     FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
  58.                     transaction.replace(R.id.trigger_section_frame_layout, periodTriggerSectionFragment).commit();
  59.                     Log.i("TIMF", "fragment replaced on PeriodTriggerSectionFragment");
  60.  
  61.                 } else if (checkedId == R.id.frequency_trigger_section_radio_button) {
  62.                     setPeriodTriggerSectionSelected(false);
  63.                     FrequencyTriggerSectionFragment frequencyTriggerSectionFragment = new FrequencyTriggerSectionFragment();
  64.                     FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
  65.                     transaction.replace(R.id.trigger_section_frame_layout, frequencyTriggerSectionFragment).commit();
  66.                     Log.i("TIMF", "fragment replaced on FrequencyTriggerSectionFragment");
  67.                 }
  68.             }
  69.         });
  70.         return view;
  71.     }
  72.  
  73.  
  74.     public int getOutputWidth() {
  75.         return outputWidth;
  76.     }
  77.  
  78.     private void setOutputWidth(int outputWidth) {
  79.         this.outputWidth = outputWidth;
  80.     }
  81.  
  82.     public int getsTI() {
  83.         String s = sTIEditText.getText().toString();
  84.         Toast.makeText(view.getContext(), s, Toast.LENGTH_SHORT).show();
  85.  
  86.         int x = Integer.parseInt(s);
  87.         return x;
  88.     }
  89.  
  90.     public int getMsTI() {
  91.         return Integer.parseInt(String.valueOf(msTIEditText.getText()));
  92.     }
  93.  
  94.     public int getMicrosTI() {
  95.         return Integer.parseInt(String.valueOf(microsTIEditText.getText()));
  96.     }
  97.  
  98.     public int getNsTI() {
  99.         return Integer.parseInt(String.valueOf(nsTIEditText.getText()));
  100.     }
  101.  
  102.     public int getPsTI() {
  103.         return Integer.parseInt(String.valueOf(psTIEditText.getText()));
  104.     }
  105.  
  106.     public void setPeriodTriggerSectionSelected(boolean periodTriggerSectionSelected) {
  107.         isPeriodTriggerSectionSelected = periodTriggerSectionSelected;
  108.     }
  109.  
  110.     public boolean isPeriodTriggerSectionSelected() {
  111.         return isPeriodTriggerSectionSelected;
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment