Commit | Line | Data |
---|---|---|
5cf4714f | 1 | package ro.ieval.unical; |
3dd871ef MG |
2 | import java.util.Calendar; |
3 | import java.util.GregorianCalendar; | |
4 | ||
6d7e08bf | 5 | import android.app.ActionBar; |
5cf4714f | 6 | import android.app.Activity; |
3dd871ef | 7 | import android.app.DatePickerDialog.OnDateSetListener; |
6d7e08bf | 8 | import android.app.Fragment; |
3dd871ef | 9 | import android.app.TimePickerDialog.OnTimeSetListener; |
ad349897 P |
10 | import android.content.Context; |
11 | import android.content.Intent; | |
5cf4714f | 12 | import android.os.Bundle; |
6d7e08bf PT |
13 | import android.view.Menu; |
14 | import android.view.MenuInflater; | |
15 | import android.view.MenuItem; | |
e6ba41a8 | 16 | import android.view.View; |
c32befcc | 17 | import android.widget.*; |
3dd871ef | 18 | |
fb0c61c1 P |
19 | //TODO if i want to add a new event after i edit one the fields are being filled with the last event data |
20 | ||
3dd871ef MG |
21 | public final class AddEventActivity extends Activity implements OnDateSetListener, OnTimeSetListener{ |
22 | private TextView dateTimeTextView; | |
2a92dcf2 | 23 | private static Event tempEvent=new Event(); |
ad349897 | 24 | public static final String EXTRA_EVENT = "event"; |
2a92dcf2 | 25 | private static Fragment f1,f2,f3; |
ad349897 P |
26 | |
27 | public static void editEvent(final Context c, final Event e) { | |
28 | Intent i = new Intent(c,AddEventActivity.class); | |
29 | i.putExtra(AddEventActivity.EXTRA_EVENT,e); | |
2a92dcf2 | 30 | tempEvent=e; |
ad349897 P |
31 | c.startActivity(i); |
32 | } | |
33 | ||
5cf4714f | 34 | |
5cf4714f MG |
35 | @Override |
36 | protected void onCreate(final Bundle savedInstanceState) { | |
37 | super.onCreate(savedInstanceState); | |
f2e460f4 | 38 | setTitle(R.string.add_event_title); |
724f9857 | 39 | final ActionBar actionBar = getActionBar(); |
6d7e08bf | 40 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
724f9857 MG |
41 | final ActionBar.Tab t1 = actionBar.newTab().setText(this.getString(R.string.addevtab1)); |
42 | final ActionBar.Tab t2 = actionBar.newTab().setText(this.getString(R.string.addevtab2)); | |
43 | final ActionBar.Tab t3 = actionBar.newTab().setText(this.getString(R.string.addevtab3)); | |
070d3ab2 | 44 | |
fb0c61c1 | 45 | f1 = new TrivialFragment(); |
88ba7fcf MG |
46 | final Bundle b1=new Bundle(); |
47 | b1.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_basic_tab); | |
fb0c61c1 | 48 | b1.putParcelable(TrivialFragment.ARGUMENT_EVENT,tempEvent); |
88ba7fcf MG |
49 | f1.setArguments(b1); |
50 | ||
fb0c61c1 | 51 | f2 = new TrivialFragment(); |
88ba7fcf MG |
52 | final Bundle b2=new Bundle(); |
53 | b2.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_details_tab); | |
fb0c61c1 | 54 | b2.putParcelable(TrivialFragment.ARGUMENT_EVENT,tempEvent); |
88ba7fcf MG |
55 | f2.setArguments(b2); |
56 | ||
fb0c61c1 | 57 | f3 = new TrivialFragment(); |
88ba7fcf MG |
58 | final Bundle b3=new Bundle(); |
59 | b3.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_other_tab); | |
fb0c61c1 | 60 | b3.putParcelable(TrivialFragment.ARGUMENT_EVENT,tempEvent); |
88ba7fcf | 61 | f3.setArguments(b3); |
070d3ab2 | 62 | |
c32befcc P |
63 | t1.setTabListener(new AddEventTabListener(f1,tempEvent,0)); |
64 | t2.setTabListener(new AddEventTabListener(f2,tempEvent,1)); | |
65 | t3.setTabListener(new AddEventTabListener(f3,tempEvent,2)); | |
070d3ab2 | 66 | |
6d7e08bf PT |
67 | actionBar.addTab(t1); |
68 | actionBar.addTab(t2); | |
69 | actionBar.addTab(t3); | |
2821d13f PT |
70 | } |
71 | ||
6d7e08bf PT |
72 | @Override |
73 | public boolean onCreateOptionsMenu(final Menu menu) { | |
74 | final MenuInflater inflater = getMenuInflater(); | |
75 | inflater.inflate(R.menu.add_event, menu); | |
76 | return true; | |
77 | } | |
070d3ab2 | 78 | |
6d7e08bf PT |
79 | @Override |
80 | public boolean onOptionsItemSelected(final MenuItem item) { | |
81 | switch (item.getItemId()) { | |
82 | case R.id.cancel: | |
83 | finish(); | |
84 | return true; | |
412b2d69 | 85 | case R.id.save: |
c32befcc P |
86 | //TODO Save event |
87 | Toast toast = Toast.makeText(getApplicationContext(),"Event saved!",Toast.LENGTH_LONG); | |
88 | toast.show(); | |
89 | finish(); | |
412b2d69 | 90 | return true; |
6d7e08bf PT |
91 | default: |
92 | return false; | |
93 | } | |
5cf4714f | 94 | } |
070d3ab2 | 95 | |
412b2d69 | 96 | public void showDateTimePickerDialog(final View v) { |
3dd871ef | 97 | dateTimeTextView=(TextView) v; |
0dde5456 | 98 | if(v.getId()==R.id.date_start || v.getId()==R.id.date_end || v.getId() == R.id.repeat_until) |
3dd871ef MG |
99 | new DatePickerFragment().show(getFragmentManager(), "datePicker"); |
100 | else | |
101 | new TimePickerFragment().show(getFragmentManager(), "timePicker"); | |
102 | } | |
103 | ||
104 | @Override | |
105 | public void onTimeSet(final TimePicker picker, final int hour, final int minute) { | |
66307122 | 106 | dateTimeTextView.setText(String.format("%02d:%02d",hour,minute)); |
3dd871ef MG |
107 | if(dateTimeTextView.getId() == R.id.time_start) |
108 | ((TextView)findViewById(R.id.time_end)).setText(String.format("%2d:%2d",hour,minute)); | |
109 | } | |
110 | ||
111 | @Override | |
112 | public void onDateSet(final DatePicker picker, final int year, final int monthOfYear, final int dayOfMonth) { | |
113 | final Calendar calendar=new GregorianCalendar(year, monthOfYear, dayOfMonth); | |
dfc674f6 | 114 | dateTimeTextView.setText(Utils.formatDate(year, monthOfYear, dayOfMonth)); |
5835912b | 115 | //calendar.add(Calendar.DAY_OF_MONTH, 1); |
3dd871ef | 116 | if(dateTimeTextView.getId() == R.id.date_start) |
dfc674f6 | 117 | ((TextView)findViewById(R.id.date_end)).setText(Utils.formatDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); |
e6ba41a8 | 118 | } |
5cf4714f | 119 | } |