Commit | Line | Data |
---|---|---|
724f9857 MG |
1 | package ro.ieval.unical; |
2 | ||
3 | import android.app.Fragment; | |
4 | import android.os.Bundle; | |
5 | import android.view.LayoutInflater; | |
6 | import android.view.View; | |
7 | import android.view.ViewGroup; | |
408a6278 | 8 | import android.widget.AdapterView; |
306c1a65 | 9 | import android.widget.CompoundButton; |
361c6a28 | 10 | import android.widget.LinearLayout; |
306c1a65 MG |
11 | import android.widget.Spinner; |
12 | import android.widget.Switch; | |
724f9857 MG |
13 | |
14 | public final class TrivialFragment extends Fragment { | |
dfc674f6 MG |
15 | private static class OnItemSelectedListener implements android.widget.AdapterView.OnItemSelectedListener{ |
16 | final View repeatCount; | |
17 | public OnItemSelectedListener(final View repeatCount) { | |
18 | this.repeatCount=repeatCount; | |
19 | } | |
20 | ||
21 | @Override | |
22 | public void onItemSelected(final AdapterView<?> whatever, final View ignored, final int pos, final long id) { | |
23 | switch(pos){ | |
24 | case 0: | |
25 | repeatCount.setVisibility(View.GONE); | |
26 | break; | |
27 | case 1: | |
28 | repeatCount.setVisibility(View.GONE); | |
29 | break; | |
30 | case 2: | |
31 | repeatCount.setVisibility(View.VISIBLE); | |
32 | break; | |
33 | default: | |
34 | } | |
35 | } | |
36 | ||
37 | @Override public void onNothingSelected(final AdapterView<?> arg0) { /* do nothing */ } | |
38 | } | |
39 | ||
40 | private static class OnCheckedChangeListener implements android.widget.CompoundButton.OnCheckedChangeListener{ | |
41 | private final LinearLayout layout; | |
42 | private final View root; | |
43 | public OnCheckedChangeListener(final LinearLayout layout, final View root){ | |
44 | this.layout=layout; | |
45 | this.root=root; | |
46 | } | |
47 | ||
48 | @Override | |
49 | public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { | |
50 | if(isChecked) { | |
51 | Utils.setEnabledRecursively(layout, true); | |
52 | final Spinner repeatType = (Spinner) root.findViewById(R.id.repeat_type); | |
53 | repeatType.setOnItemSelectedListener(new OnItemSelectedListener(root.findViewById(R.id.repeat_count))); | |
54 | }else { | |
55 | Utils.setEnabledRecursively(layout, false); | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
88ba7fcf | 60 | public static final String ARGUMENT_LAYOUT="layout"; |
724f9857 MG |
61 | |
62 | @Override | |
63 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { | |
361c6a28 | 64 | |
306c1a65 | 65 | final View view=inflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT), container, false); |
dfc674f6 | 66 | final LinearLayout layout = (LinearLayout) view.findViewById(R.id.repeat_layout); |
361c6a28 | 67 | |
dfc674f6 | 68 | if(layout != null){ |
361c6a28 | 69 | final Switch repeatSwitch = (Switch) view.findViewById(R.id.repeat_switch); |
dfc674f6 | 70 | Utils.setEnabledRecursively(layout, false); |
361c6a28 | 71 | |
dfc674f6 | 72 | repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout, view)); |
306c1a65 MG |
73 | } |
74 | return view; | |
75 | } | |
724f9857 | 76 | } |