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
.TextView
;
17 import android
.widget
.TimePicker
;
19 public final class AddEventActivity
extends Activity
implements OnDateSetListener
, OnTimeSetListener
{
20 private TextView dateTimeTextView
;
23 protected void onCreate(final Bundle savedInstanceState
) {
24 super.onCreate(savedInstanceState
);
25 setContentView(R
.layout
.add_event
);
26 setTitle(R
.string
.addeventtitle
);
27 final ActionBar actionBar
= getActionBar();
28 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_TABS
);
29 final ActionBar
.Tab t1
= actionBar
.newTab().setText(this.getString(R
.string
.addevtab1
));
30 final ActionBar
.Tab t2
= actionBar
.newTab().setText(this.getString(R
.string
.addevtab2
));
31 final ActionBar
.Tab t3
= actionBar
.newTab().setText(this.getString(R
.string
.addevtab3
));
33 final Fragment f1
= new TrivialFragment();
34 final Bundle b1
=new Bundle();
35 b1
.putInt(TrivialFragment
.ARGUMENT_LAYOUT
, R
.layout
.add_event_basic_tab
);
38 final Fragment f2
= new TrivialFragment();
39 final Bundle b2
=new Bundle();
40 b2
.putInt(TrivialFragment
.ARGUMENT_LAYOUT
, R
.layout
.add_event_details_tab
);
43 final Fragment f3
= new TrivialFragment();
44 final Bundle b3
=new Bundle();
45 b3
.putInt(TrivialFragment
.ARGUMENT_LAYOUT
, R
.layout
.add_event_other_tab
);
48 t1
.setTabListener(new AddEventTabListener(f1
));
49 t2
.setTabListener(new AddEventTabListener(f2
));
50 t3
.setTabListener(new AddEventTabListener(f3
));
58 public boolean onCreateOptionsMenu(final Menu menu
) {
59 final MenuInflater inflater
= getMenuInflater();
60 inflater
.inflate(R
.menu
.add_event
, menu
);
65 public boolean onOptionsItemSelected(final MenuItem item
) {
66 switch (item
.getItemId()) {
75 public void showDateTimePickerDialog(final View v
) {
76 dateTimeTextView
=(TextView
) v
;
77 if(v
.getId()==R
.id
.date_start
|| v
.getId()==R
.id
.date_end
)
78 new DatePickerFragment().show(getFragmentManager(), "datePicker");
80 new TimePickerFragment().show(getFragmentManager(), "timePicker");
84 public void onTimeSet(final TimePicker picker
, final int hour
, final int minute
) {
85 dateTimeTextView
.setText(String
.format("%02d:%02d",hour
,minute
));
86 if(dateTimeTextView
.getId() == R
.id
.time_start
)
87 ((TextView
)findViewById(R
.id
.time_end
)).setText(String
.format("%2d:%2d",hour
,minute
));
91 public void onDateSet(final DatePicker picker
, final int year
, final int monthOfYear
, final int dayOfMonth
) {
92 final Calendar calendar
=new GregorianCalendar(year
, monthOfYear
, dayOfMonth
);
93 dateTimeTextView
.setText(Utils
.formatDate(year
, monthOfYear
, dayOfMonth
));
94 calendar
.add(Calendar
.DAY_OF_MONTH
, 1);
95 if(dateTimeTextView
.getId() == R
.id
.date_start
)
96 ((TextView
)findViewById(R
.id
.date_end
)).setText(Utils
.formatDate(calendar
.get(Calendar
.YEAR
), calendar
.get(Calendar
.MONTH
), calendar
.get(Calendar
.DAY_OF_MONTH
)));