X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fro%2Fieval%2Funical%2FTrivialFragment.java;h=4a1c0b2b38a17f39b160c424e011eb9a50d2374f;hb=f580909cce85fcd4edbba928c795abb2e75564be;hp=1dc538f23e1eda41ae0acb387532debc583376e3;hpb=408a62787e4432565f836d2c477206f7f92ca20a;p=unical.git diff --git a/src/ro/ieval/unical/TrivialFragment.java b/src/ro/ieval/unical/TrivialFragment.java index 1dc538f..4a1c0b2 100644 --- a/src/ro/ieval/unical/TrivialFragment.java +++ b/src/ro/ieval/unical/TrivialFragment.java @@ -2,68 +2,74 @@ package ro.ieval.unical; import android.app.Fragment; import android.os.Bundle; -import android.text.InputType; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import android.widget.AdapterView.OnItemSelectedListener; import android.widget.CompoundButton; -import android.widget.EditText; 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); - Spinner repeatType = (Spinner) view.findViewById(R.id.repeat_type); - final EditText repeatCount = new EditText(getActivity()); - repeatCount.setInputType(InputType.TYPE_CLASS_NUMBER); - final LinearLayout repeatLayout = (LinearLayout) view.findViewById(R.id.repeat_count_layout); - - repeatType.setOnItemSelectedListener(new OnItemSelectedListener() { - - @Override - public void onItemSelected(AdapterView arg0, - View arg1, int arg2, long arg3) { - if(arg2==1) { - //TODO adauga un date picker - //TODO sterge repeatCount - }else if(arg2==2) { - repeatLayout.addView(repeatCount); - }else { - //TODO sterge repeatCount - } - - } - - @Override - public void onNothingSelected(AdapterView arg0) { - - } - }); - }else { - Utils.setEnabledRecursively(ll, false); - } - } - }); + repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout, view)); } return view; }