| 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 | public Fragment fragment; |
| 16 | private Event ev; |
| 17 | int tabId; |
| 18 | |
| 19 | public AddEventTabListener(final Fragment fragment,Event e,int tabId) { |
| 20 | this.fragment = fragment; |
| 21 | this.ev = e; |
| 22 | this.tabId=tabId; |
| 23 | } |
| 24 | |
| 25 | @Override |
| 26 | public void onTabSelected(final Tab tab, final FragmentTransaction ft) { |
| 27 | ft.replace(R.id.fragment_container, fragment); |
| 28 | switch (tabId) { |
| 29 | case 0: |
| 30 | if(fragment.getView()==null) System.err.println("MuieLaComisie"); |
| 31 | //EditText title =(EditText) fragment.getView().findViewById(R.id.eventtitle); |
| 32 | // title.setText(ev.title, TextView.BufferType.EDITABLE); |
| 33 | break; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public void onTabUnselected(final Tab tab, final FragmentTransaction ft) { |
| 39 | switch (tabId) { |
| 40 | case 0: |
| 41 | ev.title=fragment.getView().findViewById(R.id.eventtitle).toString(); |
| 42 | String start=fragment.getView().findViewById(R.id.date_start).toString()+ " " + |
| 43 | fragment.getView().findViewById(R.id.time_start).toString(); |
| 44 | String end=fragment.getView().findViewById(R.id.date_end).toString()+ " " + |
| 45 | fragment.getView().findViewById(R.id.time_end).toString(); |
| 46 | try { |
| 47 | Date s=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(start); |
| 48 | Date e=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(end); |
| 49 | ev.dtstart=s.getTime(); |
| 50 | ev.dtend=s.getTime(); |
| 51 | } catch (ParseException e) { |
| 52 | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
| 53 | } |
| 54 | |
| 55 | break; |
| 56 | case 1: |
| 57 | ev.description=fragment.getView().findViewById(R.id.description).toString(); |
| 58 | break; |
| 59 | case 2: |
| 60 | break; |
| 61 | } |
| 62 | ft.remove(fragment); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void onTabReselected(final Tab tab, final FragmentTransaction ft) { |
| 67 | // TODO Auto-generated method stub |
| 68 | |
| 69 | } |
| 70 | } |