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
.content
.Context
;
11 import android
.content
.Intent
;
12 import android
.os
.Bundle
;
13 import android
.view
.Menu
;
14 import android
.view
.MenuInflater
;
15 import android
.view
.MenuItem
;
16 import android
.view
.View
;
17 import android
.widget
.*;
19 public final class AddEventActivity
extends Activity
implements OnDateSetListener
, OnTimeSetListener
{
20 private TextView dateTimeTextView
;
21 private static Event tempEvent
=new Event();
22 public static final String EXTRA_EVENT
= "event";
23 private static Fragment f1
,f2
,f3
;
25 public static void editEvent(final Context c
, final Event e
) {
26 Intent i
= new Intent(c
,AddEventActivity
.class);
27 i
.putExtra(AddEventActivity
.EXTRA_EVENT
,e
);
34 protected void onCreate(final Bundle savedInstanceState
) {
35 super.onCreate(savedInstanceState
);
36 setTitle(R
.string
.add_event_title
);
37 final ActionBar actionBar
= getActionBar();
38 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_TABS
);
39 final ActionBar
.Tab t1
= actionBar
.newTab().setText(this.getString(R
.string
.addevtab1
));
40 final ActionBar
.Tab t2
= actionBar
.newTab().setText(this.getString(R
.string
.addevtab2
));
41 final ActionBar
.Tab t3
= actionBar
.newTab().setText(this.getString(R
.string
.addevtab3
));
43 f1
= new TrivialFragment(tempEvent
);
44 final Bundle b1
=new Bundle();
45 b1
.putInt(TrivialFragment
.ARGUMENT_LAYOUT
, R
.layout
.add_event_basic_tab
);
48 f2
= new TrivialFragment(tempEvent
);
49 final Bundle b2
=new Bundle();
50 b2
.putInt(TrivialFragment
.ARGUMENT_LAYOUT
, R
.layout
.add_event_details_tab
);
53 f3
= new TrivialFragment(tempEvent
);
54 final Bundle b3
=new Bundle();
55 b3
.putInt(TrivialFragment
.ARGUMENT_LAYOUT
, R
.layout
.add_event_other_tab
);
58 t1
.setTabListener(new AddEventTabListener(f1
,tempEvent
,0));
59 t2
.setTabListener(new AddEventTabListener(f2
,tempEvent
,1));
60 t3
.setTabListener(new AddEventTabListener(f3
,tempEvent
,2));
68 public boolean onCreateOptionsMenu(final Menu menu
) {
69 final MenuInflater inflater
= getMenuInflater();
70 inflater
.inflate(R
.menu
.add_event
, menu
);
75 public boolean onOptionsItemSelected(final MenuItem item
) {
76 switch (item
.getItemId()) {
82 Toast toast
= Toast
.makeText(getApplicationContext(),"Event saved!",Toast
.LENGTH_LONG
);
91 public void showDateTimePickerDialog(final View v
) {
92 dateTimeTextView
=(TextView
) v
;
93 if(v
.getId()==R
.id
.date_start
|| v
.getId()==R
.id
.date_end
|| v
.getId() == R
.id
.repeat_until
)
94 new DatePickerFragment().show(getFragmentManager(), "datePicker");
96 new TimePickerFragment().show(getFragmentManager(), "timePicker");
100 public void onTimeSet(final TimePicker picker
, final int hour
, final int minute
) {
101 dateTimeTextView
.setText(String
.format("%02d:%02d",hour
,minute
));
102 if(dateTimeTextView
.getId() == R
.id
.time_start
)
103 ((TextView
)findViewById(R
.id
.time_end
)).setText(String
.format("%2d:%2d",hour
,minute
));
107 public void onDateSet(final DatePicker picker
, final int year
, final int monthOfYear
, final int dayOfMonth
) {
108 final Calendar calendar
=new GregorianCalendar(year
, monthOfYear
, dayOfMonth
);
109 dateTimeTextView
.setText(Utils
.formatDate(year
, monthOfYear
, dayOfMonth
));
110 //calendar.add(Calendar.DAY_OF_MONTH, 1);
111 if(dateTimeTextView
.getId() == R
.id
.date_start
)
112 ((TextView
)findViewById(R
.id
.date_end
)).setText(Utils
.formatDate(calendar
.get(Calendar
.YEAR
), calendar
.get(Calendar
.MONTH
), calendar
.get(Calendar
.DAY_OF_MONTH
)));