]>
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; |
5cf4714f | 10 | import android.os.Bundle; |
6d7e08bf PT |
11 | import android.view.Menu; |
12 | import android.view.MenuInflater; | |
13 | import android.view.MenuItem; | |
e6ba41a8 | 14 | import android.view.View; |
3dd871ef | 15 | import android.widget.DatePicker; |
412b2d69 | 16 | import android.widget.EditText; |
3dd871ef MG |
17 | import android.widget.TextView; |
18 | import android.widget.TimePicker; | |
19 | ||
20 | public final class AddEventActivity extends Activity implements OnDateSetListener, OnTimeSetListener{ | |
21 | private TextView dateTimeTextView; | |
5cf4714f | 22 | |
5cf4714f MG |
23 | @Override |
24 | protected void onCreate(final Bundle savedInstanceState) { | |
25 | super.onCreate(savedInstanceState); | |
26 | setContentView(R.layout.add_event); | |
f2e460f4 | 27 | setTitle(R.string.add_event_title); |
724f9857 | 28 | final ActionBar actionBar = getActionBar(); |
6d7e08bf | 29 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
724f9857 MG |
30 | final ActionBar.Tab t1 = actionBar.newTab().setText(this.getString(R.string.addevtab1)); |
31 | final ActionBar.Tab t2 = actionBar.newTab().setText(this.getString(R.string.addevtab2)); | |
32 | final ActionBar.Tab t3 = actionBar.newTab().setText(this.getString(R.string.addevtab3)); | |
070d3ab2 | 33 | |
88ba7fcf MG |
34 | final Fragment f1 = new TrivialFragment(); |
35 | final Bundle b1=new Bundle(); | |
36 | b1.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_basic_tab); | |
37 | f1.setArguments(b1); | |
38 | ||
39 | final Fragment f2 = new TrivialFragment(); | |
40 | final Bundle b2=new Bundle(); | |
41 | b2.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_details_tab); | |
42 | f2.setArguments(b2); | |
43 | ||
44 | final Fragment f3 = new TrivialFragment(); | |
45 | final Bundle b3=new Bundle(); | |
46 | b3.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_other_tab); | |
47 | f3.setArguments(b3); | |
070d3ab2 | 48 | |
6d7e08bf PT |
49 | t1.setTabListener(new AddEventTabListener(f1)); |
50 | t2.setTabListener(new AddEventTabListener(f2)); | |
51 | t3.setTabListener(new AddEventTabListener(f3)); | |
070d3ab2 | 52 | |
6d7e08bf PT |
53 | actionBar.addTab(t1); |
54 | actionBar.addTab(t2); | |
55 | actionBar.addTab(t3); | |
2821d13f PT |
56 | } |
57 | ||
6d7e08bf PT |
58 | @Override |
59 | public boolean onCreateOptionsMenu(final Menu menu) { | |
60 | final MenuInflater inflater = getMenuInflater(); | |
61 | inflater.inflate(R.menu.add_event, menu); | |
62 | return true; | |
63 | } | |
070d3ab2 | 64 | |
6d7e08bf PT |
65 | @Override |
66 | public boolean onOptionsItemSelected(final MenuItem item) { | |
67 | switch (item.getItemId()) { | |
68 | case R.id.cancel: | |
69 | finish(); | |
70 | return true; | |
412b2d69 P |
71 | case R.id.save: |
72 | Event e = getEvent(this); | |
73 | return true; | |
6d7e08bf PT |
74 | default: |
75 | return false; | |
76 | } | |
5cf4714f | 77 | } |
070d3ab2 | 78 | |
412b2d69 P |
79 | private Event getEvent(final Activity v) { |
80 | //TODO get all information | |
81 | final long _id=22; | |
82 | final String organizer=""; | |
83 | final String title=((EditText)v.findViewById(R.id.eventtitle)).getText().toString(); | |
84 | final String eventLocation=""; | |
85 | final String description=((EditText)v.findViewById(R.id.description)).getText().toString(); | |
86 | final int eventColor=0; | |
87 | final long dtstart=0; | |
88 | final long dtend=0; | |
89 | final long calendarID = 0; | |
90 | System.out.print(title + description); | |
91 | Event ret = new Event(_id,organizer,title,eventLocation,description,eventColor,dtstart,dtend,calendarID); | |
92 | return ret; | |
93 | } | |
94 | ||
95 | public void showDateTimePickerDialog(final View v) { | |
3dd871ef | 96 | dateTimeTextView=(TextView) v; |
0dde5456 | 97 | if(v.getId()==R.id.date_start || v.getId()==R.id.date_end || v.getId() == R.id.repeat_until) |
3dd871ef MG |
98 | new DatePickerFragment().show(getFragmentManager(), "datePicker"); |
99 | else | |
100 | new TimePickerFragment().show(getFragmentManager(), "timePicker"); | |
101 | } | |
102 | ||
103 | @Override | |
104 | public void onTimeSet(final TimePicker picker, final int hour, final int minute) { | |
66307122 | 105 | dateTimeTextView.setText(String.format("%02d:%02d",hour,minute)); |
3dd871ef MG |
106 | if(dateTimeTextView.getId() == R.id.time_start) |
107 | ((TextView)findViewById(R.id.time_end)).setText(String.format("%2d:%2d",hour,minute)); | |
108 | } | |
109 | ||
110 | @Override | |
111 | public void onDateSet(final DatePicker picker, final int year, final int monthOfYear, final int dayOfMonth) { | |
112 | final Calendar calendar=new GregorianCalendar(year, monthOfYear, dayOfMonth); | |
dfc674f6 | 113 | dateTimeTextView.setText(Utils.formatDate(year, monthOfYear, dayOfMonth)); |
3dd871ef MG |
114 | calendar.add(Calendar.DAY_OF_MONTH, 1); |
115 | if(dateTimeTextView.getId() == R.id.date_start) | |
dfc674f6 | 116 | ((TextView)findViewById(R.id.date_end)).setText(Utils.formatDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); |
e6ba41a8 | 117 | } |
5cf4714f | 118 | } |