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