]>
Commit | Line | Data |
---|---|---|
1 | package ro.ieval.unical; | |
2 | ||
3 | import android.app.ActionBar; | |
4 | import android.app.ActionBar.Tab; | |
5 | import android.app.Fragment; | |
6 | import android.app.FragmentTransaction; | |
7 | import android.widget.EditText; | |
8 | import android.widget.TextView; | |
9 | ||
10 | import java.text.ParseException; | |
11 | import java.text.SimpleDateFormat; | |
12 | import java.util.Date; | |
13 | ||
14 | public class AddEventTabListener implements ActionBar.TabListener { | |
15 | private Fragment fragment; | |
16 | private Event ev; | |
17 | private boolean isAdded = false; | |
18 | private int tabId; | |
19 | ||
20 | public AddEventTabListener(final Fragment fragment,Event e,int tabId) { | |
21 | this.fragment = fragment; | |
22 | this.ev = e; | |
23 | this.tabId=tabId; | |
24 | } | |
25 | ||
26 | @Override | |
27 | public void onTabSelected(final Tab tab, final FragmentTransaction ft) { | |
28 | if(isAdded) | |
29 | ft.attach(fragment); | |
30 | else { | |
31 | isAdded = true; | |
32 | ft.add(android.R.id.content, fragment); | |
33 | } | |
34 | ||
35 | switch (tabId) { | |
36 | case 0: | |
37 | //EditText title =(EditText) fragment.getView().findViewById(R.id.eventtitle); | |
38 | //title.setText(ev.title, TextView.BufferType.EDITABLE); | |
39 | break; | |
40 | } | |
41 | } | |
42 | ||
43 | @Override | |
44 | public void onTabUnselected(final Tab tab, final FragmentTransaction ft) { | |
45 | switch (tabId) { | |
46 | case 0: | |
47 | ev.title=fragment.getView().findViewById(R.id.eventtitle).toString(); | |
48 | String start=fragment.getView().findViewById(R.id.date_start).toString()+ " " + | |
49 | fragment.getView().findViewById(R.id.time_start).toString(); | |
50 | String end=fragment.getView().findViewById(R.id.date_end).toString()+ " " + | |
51 | fragment.getView().findViewById(R.id.time_end).toString(); | |
52 | try { | |
53 | Date s=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(start); | |
54 | Date e=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(end); | |
55 | ev.dtstart=s.getTime(); | |
56 | ev.dtend=s.getTime(); | |
57 | } catch (ParseException e) { | |
58 | e.printStackTrace(); | |
59 | } | |
60 | ||
61 | break; | |
62 | case 1: | |
63 | ev.description=fragment.getView().findViewById(R.id.description).toString(); | |
64 | break; | |
65 | case 2: | |
66 | break; | |
67 | } | |
68 | ft.detach(fragment); | |
69 | } | |
70 | ||
71 | @Override | |
72 | public void onTabReselected(final Tab tab, final FragmentTransaction ft) { | |
73 | // do nothing | |
74 | } | |
75 | } |