]> iEval git - unical.git/blob - src/ro/ieval/unical/TrivialFragment.java
Fix previous commit
[unical.git] / src / ro / ieval / unical / TrivialFragment.java
1 package ro.ieval.unical;
2
3 import android.app.ActionBar;
4 import android.app.Fragment;
5 import android.app.FragmentTransaction;
6 import android.os.Bundle;
7 import android.view.LayoutInflater;
8 import android.view.View;
9 import android.view.ViewGroup;
10 import android.widget.*;
11
12 import java.text.SimpleDateFormat;
13 import java.util.Date;
14
15 public final class TrivialFragment extends Fragment {
16 Event ev;
17 public static final String ARGUMENT_EVENT= "Event";
18
19 @Override
20 public void onActivityCreated (Bundle savedInstanceState) {
21 super.onCreate(savedInstanceState);
22 ev=getArguments().getParcelable(ARGUMENT_EVENT);
23 switch (getArguments().getInt(ARGUMENT_LAYOUT)) {
24 case R.layout.add_event_basic_tab:
25 EditText title = (EditText) getView().findViewById(R.id.eventtitle);
26 title.setText(ev.title, TextView.BufferType.EDITABLE);
27
28 TextView tstart = (TextView) getView().findViewById(R.id.time_start);
29 TextView tend = (TextView) getView().findViewById(R.id.time_end);
30 SimpleDateFormat sf=new SimpleDateFormat("HH:MM");
31 Date d=new Date(ev.dtstart);
32 tstart.setText(sf.format(d).toString(),TextView.BufferType.NORMAL);
33 d.setTime(ev.dtend);
34 tend.setText(sf.format(d).toString(),TextView.BufferType.NORMAL);
35
36 SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
37 TextView dstart = (TextView)getView().findViewById(R.id.date_start);
38 TextView dend = (TextView)getView().findViewById(R.id.date_end);
39 d.setTime(ev.dtstart);
40 dstart.setText(sd.format(d).toString(),TextView.BufferType.NORMAL);
41 d.setTime(ev.dtend);
42 dend.setText(sd.format(d).toString(),TextView.BufferType.NORMAL);
43 break;
44 case R.layout.add_event_details_tab:
45 EditText description = (EditText) getView().findViewById(R.id.description);
46 description.setText(ev.description,TextView.BufferType.EDITABLE);
47 break;
48 case R.layout.add_event_other_tab:
49 break;
50 }
51
52 }
53
54 private static class OnItemSelectedListener implements android.widget.AdapterView.OnItemSelectedListener{
55 private final View repeatCount;
56 private final View repeatUntil;
57
58 public OnItemSelectedListener(final View repeatCount, final View repeatUntil) {
59 this.repeatCount=repeatCount;
60 this.repeatUntil=repeatUntil;
61 }
62
63 @Override
64 public void onItemSelected(final AdapterView<?> whatever, final View ignored, final int pos, final long id) {
65 switch(pos){
66 case 0:
67 repeatCount.setVisibility(View.GONE);
68 repeatUntil.setVisibility(View.GONE);
69 break;
70 case 1:
71 repeatCount.setVisibility(View.GONE);
72 repeatUntil.setVisibility(View.VISIBLE);
73 break;
74 case 2:
75 repeatCount.setVisibility(View.VISIBLE);
76 repeatUntil.setVisibility(View.GONE);
77 break;
78 default:
79 }
80 }
81
82 @Override public void onNothingSelected(final AdapterView<?> arg0) { /* do nothing */ }
83 }
84
85 private static class OnCheckedChangeListener implements android.widget.CompoundButton.OnCheckedChangeListener{
86 private final LinearLayout layout;
87 private final View root;
88 public OnCheckedChangeListener(final LinearLayout layout, final View root){
89 this.layout=layout;
90 this.root=root;
91 }
92
93 @Override
94 public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
95 if(isChecked) {
96 Utils.setEnabledRecursively(layout, true);
97 final Spinner repeatType = (Spinner) root.findViewById(R.id.repeat_type);
98 repeatType.setOnItemSelectedListener(new OnItemSelectedListener(root.findViewById(R.id.repeat_count),root.findViewById(R.id.repeat_until)));
99 }else {
100 Utils.setEnabledRecursively(layout, false);
101 }
102 }
103 }
104
105 public static final String ARGUMENT_LAYOUT="layout";
106
107 @Override
108 public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
109
110 final View view=inflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT), container, false);
111 final LinearLayout layout = (LinearLayout) view.findViewById(R.id.repeat_layout);
112
113 if(layout != null){
114 final Switch repeatSwitch = (Switch) view.findViewById(R.id.repeat_switch);
115 Utils.setEnabledRecursively(layout, false);
116
117 repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout, view));
118 }
119 return view;
120 }
121 }
This page took 0.052434 seconds and 4 git commands to generate.