1 package ro
.ieval
.unical
;
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
.*;
12 import java
.text
.SimpleDateFormat
;
13 import java
.util
.Date
;
15 public final class TrivialFragment
extends Fragment
{
17 public static final String ARGUMENT_EVENT
= "Event";
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
);
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
);
34 tend
.setText(sf
.format(d
).toString(),TextView
.BufferType
.NORMAL
);
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
);
42 dend
.setText(sd
.format(d
).toString(),TextView
.BufferType
.NORMAL
);
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
);
48 case R
.layout
.add_event_other_tab
:
54 private static class OnItemSelectedListener
implements android
.widget
.AdapterView
.OnItemSelectedListener
{
55 private final View repeatCount
;
56 private final View repeatUntil
;
58 public OnItemSelectedListener(final View repeatCount
, final View repeatUntil
) {
59 this.repeatCount
=repeatCount
;
60 this.repeatUntil
=repeatUntil
;
64 public void onItemSelected(final AdapterView
<?
> whatever
, final View ignored
, final int pos
, final long id
) {
67 repeatCount
.setVisibility(View
.GONE
);
68 repeatUntil
.setVisibility(View
.GONE
);
71 repeatCount
.setVisibility(View
.GONE
);
72 repeatUntil
.setVisibility(View
.VISIBLE
);
75 repeatCount
.setVisibility(View
.VISIBLE
);
76 repeatUntil
.setVisibility(View
.GONE
);
82 @Override public void onNothingSelected(final AdapterView
<?
> arg0
) { /* do nothing */ }
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
){
94 public void onCheckedChanged(final CompoundButton buttonView
, final boolean 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
)));
100 Utils
.setEnabledRecursively(layout
, false);
105 public static final String ARGUMENT_LAYOUT
="layout";
108 public View
onCreateView(final LayoutInflater inflater
, final ViewGroup container
, final Bundle savedInstanceState
) {
110 final View view
=inflater
.inflate(getArguments().getInt(ARGUMENT_LAYOUT
), container
, false);
111 final LinearLayout layout
= (LinearLayout
) view
.findViewById(R
.id
.repeat_layout
);
114 final Switch repeatSwitch
= (Switch
) view
.findViewById(R
.id
.repeat_switch
);
115 Utils
.setEnabledRecursively(layout
, false);
117 repeatSwitch
.setOnCheckedChangeListener(new OnCheckedChangeListener(layout
, view
));