Clean up
[unical.git] / src / ro / ieval / unical / TrivialFragment.java
index 727814ae85dd6e45ddafe3df7719ea0e978f50e2..4a1c0b2b38a17f39b160c424e011eb9a50d2374f 100644 (file)
@@ -5,15 +5,72 @@ import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.CompoundButton;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+import android.widget.Switch;
 
 public final class TrivialFragment extends Fragment {
-       private final int layout;
-       public TrivialFragment(final int layout){
-               this.layout=layout;
+       private static class OnItemSelectedListener implements android.widget.AdapterView.OnItemSelectedListener{
+               private final View repeatCount;
+               public OnItemSelectedListener(final View repeatCount) {
+                       this.repeatCount=repeatCount;
+               }
+
+               @Override
+               public void onItemSelected(final AdapterView<?> whatever, final View ignored, final int pos, final long id) {
+                       switch(pos){
+                       case 0:
+                               repeatCount.setVisibility(View.GONE);
+                               break;
+                       case 1:
+                               repeatCount.setVisibility(View.GONE);
+                               break;
+                       case 2:
+                               repeatCount.setVisibility(View.VISIBLE);
+                               break;
+                       default:
+                       }
+               }
+
+               @Override public void onNothingSelected(final AdapterView<?> arg0) { /* do nothing */   }
        }
 
+       private static class OnCheckedChangeListener implements android.widget.CompoundButton.OnCheckedChangeListener{
+               private final LinearLayout layout;
+               private final View root;
+               public OnCheckedChangeListener(final LinearLayout layout, final View root){
+                       this.layout=layout;
+                       this.root=root;
+               }
+
+               @Override
+               public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
+                       if(isChecked) {
+                               Utils.setEnabledRecursively(layout, true);
+                               final Spinner repeatType = (Spinner) root.findViewById(R.id.repeat_type);
+                               repeatType.setOnItemSelectedListener(new OnItemSelectedListener(root.findViewById(R.id.repeat_count)));
+                       }else {
+                               Utils.setEnabledRecursively(layout, false);
+                       }
+               }
+       }
+
+       public static final String ARGUMENT_LAYOUT="layout";
+
        @Override
     public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
-        return inflater.inflate(layout, container, false);
-    }
+               
+               final View view=inflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT), container, false);
+               final LinearLayout layout = (LinearLayout) view.findViewById(R.id.repeat_layout);
+               
+               if(layout != null){
+                       final Switch repeatSwitch = (Switch) view.findViewById(R.id.repeat_switch);
+                       Utils.setEnabledRecursively(layout, false);
+                       
+                       repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout, view));
+               }
+               return view;
+       }
 }
This page took 0.010796 seconds and 4 git commands to generate.