1 package ro
.ieval
.unical
;
2 import java
.util
.Calendar
;
3 import java
.util
.GregorianCalendar
;
5 import android
.app
.ActionBar
;
6 import android
.app
.Activity
;
7 import android
.app
.DatePickerDialog
.OnDateSetListener
;
8 import android
.app
.Fragment
;
9 import android
.app
.TimePickerDialog
.OnTimeSetListener
;
10 import android
.os
.Bundle
;
11 import android
.view
.Menu
;
12 import android
.view
.MenuInflater
;
13 import android
.view
.MenuItem
;
14 import android
.view
.View
;
15 import android
.widget
.DatePicker
;
16 import android
.widget
.EditText
;
17 import android
.widget
.TextView
;
18 import android
.widget
.TimePicker
;
20 public final class AddEventActivity
extends Activity
implements OnDateSetListener
, OnTimeSetListener
{
21 private TextView dateTimeTextView
;
24 protected void onCreate(final Bundle savedInstanceState
) {
25 super.onCreate(savedInstanceState
);
26 setContentView(R
.layout
.add_event
);
27 setTitle(R
.string
.add_event_title
);
28 final ActionBar actionBar
= getActionBar();
29 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_TABS
);
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
));
34 final Fragment f1
= new TrivialFragment();
35 final Bundle b1
=new Bundle();
36 b1
.putInt(TrivialFragment
.ARGUMENT_LAYOUT
, R
.layout
.add_event_basic_tab
);
39 final Fragment f2
= new TrivialFragment();
40 final Bundle b2
=new Bundle();
41 b2
.putInt(TrivialFragment
.ARGUMENT_LAYOUT
, R
.layout
.add_event_details_tab
);
44 final Fragment f3
= new TrivialFragment();
45 final Bundle b3
=new Bundle();
46 b3
.putInt(TrivialFragment
.ARGUMENT_LAYOUT
, R
.layout
.add_event_other_tab
);
49 t1
.setTabListener(new AddEventTabListener(f1
));
50 t2
.setTabListener(new AddEventTabListener(f2
));
51 t3
.setTabListener(new AddEventTabListener(f3
));
59 public boolean onCreateOptionsMenu(final Menu menu
) {
60 final MenuInflater inflater
= getMenuInflater();
61 inflater
.inflate(R
.menu
.add_event
, menu
);
66 public boolean onOptionsItemSelected(final MenuItem item
) {
67 switch (item
.getItemId()) {
72 Event e
= getEvent(this);
79 private Event
getEvent(final Activity v
) {
80 //TODO get all information
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;
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
);
95 public void showDateTimePickerDialog(final View v
) {
96 dateTimeTextView
=(TextView
) v
;
97 if(v
.getId()==R
.id
.date_start
|| v
.getId()==R
.id
.date_end
|| v
.getId() == R
.id
.repeat_until
)
98 new DatePickerFragment().show(getFragmentManager(), "datePicker");
100 new TimePickerFragment().show(getFragmentManager(), "timePicker");
104 public void onTimeSet(final TimePicker picker
, final int hour
, final int minute
) {
105 dateTimeTextView
.setText(String
.format("%02d:%02d",hour
,minute
));
106 if(dateTimeTextView
.getId() == R
.id
.time_start
)
107 ((TextView
)findViewById(R
.id
.time_end
)).setText(String
.format("%2d:%2d",hour
,minute
));
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
);
113 dateTimeTextView
.setText(Utils
.formatDate(year
, monthOfYear
, dayOfMonth
));
114 calendar
.add(Calendar
.DAY_OF_MONTH
, 1);
115 if(dateTimeTextView
.getId() == R
.id
.date_start
)
116 ((TextView
)findViewById(R
.id
.date_end
)).setText(Utils
.formatDate(calendar
.get(Calendar
.YEAR
), calendar
.get(Calendar
.MONTH
), calendar
.get(Calendar
.DAY_OF_MONTH
)));