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