Clean up
[unical.git] / src / ro / ieval / unical / TrivialFragment.java
index 3de4ed48ece35316ce24b5408f04a3e394d50925..4a1c0b2b38a17f39b160c424e011eb9a50d2374f 100644 (file)
@@ -5,35 +5,71 @@ 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;
-import android.widget.CompoundButton.OnCheckedChangeListener;
 
 public final class TrivialFragment extends Fragment {
+       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) {
                
                final View view=inflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT), container, false);
-               final LinearLayout ll = (LinearLayout) view.findViewById(R.id.repeat_layout);
+               final LinearLayout layout = (LinearLayout) view.findViewById(R.id.repeat_layout);
                
-               if(ll != null){
+               if(layout != null){
                        final Switch repeatSwitch = (Switch) view.findViewById(R.id.repeat_switch);
-                       Utils.setEnabledRecursively(ll, false);
+                       Utils.setEnabledRecursively(layout, false);
                        
-                       repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
-                               @Override
-                               public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
-                                       if(isChecked) {
-                                               Utils.setEnabledRecursively(ll, true);
-                                       }else {
-                                               Utils.setEnabledRecursively(ll, false);
-                                       }
-                               }
-                       });
+                       repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout, view));
                }
                return view;
        }
This page took 0.010901 seconds and 4 git commands to generate.