]>
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 MG |
15 | import android.widget.DatePicker; |
16 | import android.widget.TextView; | |
17 | import android.widget.TimePicker; | |
18 | ||
19 | public final class AddEventActivity extends Activity implements OnDateSetListener, OnTimeSetListener{ | |
20 | private TextView dateTimeTextView; | |
5cf4714f | 21 | |
5cf4714f MG |
22 | @Override |
23 | protected void onCreate(final Bundle savedInstanceState) { | |
24 | super.onCreate(savedInstanceState); | |
25 | setContentView(R.layout.add_event); | |
ecee6932 | 26 | setTitle(R.string.addeventtitle); |
724f9857 | 27 | final ActionBar actionBar = getActionBar(); |
6d7e08bf | 28 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
724f9857 MG |
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)); | |
070d3ab2 | 32 | |
88ba7fcf MG |
33 | final Fragment f1 = new TrivialFragment(); |
34 | final Bundle b1=new Bundle(); | |
35 | b1.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_basic_tab); | |
36 | f1.setArguments(b1); | |
37 | ||
38 | final Fragment f2 = new TrivialFragment(); | |
39 | final Bundle b2=new Bundle(); | |
40 | b2.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_details_tab); | |
41 | f2.setArguments(b2); | |
42 | ||
43 | final Fragment f3 = new TrivialFragment(); | |
44 | final Bundle b3=new Bundle(); | |
45 | b3.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_other_tab); | |
46 | f3.setArguments(b3); | |
070d3ab2 | 47 | |
6d7e08bf PT |
48 | t1.setTabListener(new AddEventTabListener(f1)); |
49 | t2.setTabListener(new AddEventTabListener(f2)); | |
50 | t3.setTabListener(new AddEventTabListener(f3)); | |
070d3ab2 | 51 | |
6d7e08bf PT |
52 | actionBar.addTab(t1); |
53 | actionBar.addTab(t2); | |
54 | actionBar.addTab(t3); | |
2821d13f PT |
55 | } |
56 | ||
6d7e08bf PT |
57 | @Override |
58 | public boolean onCreateOptionsMenu(final Menu menu) { | |
59 | final MenuInflater inflater = getMenuInflater(); | |
60 | inflater.inflate(R.menu.add_event, menu); | |
61 | return true; | |
62 | } | |
070d3ab2 | 63 | |
6d7e08bf PT |
64 | @Override |
65 | public boolean onOptionsItemSelected(final MenuItem item) { | |
66 | switch (item.getItemId()) { | |
67 | case R.id.cancel: | |
68 | finish(); | |
69 | return true; | |
70 | default: | |
71 | return false; | |
72 | } | |
5cf4714f | 73 | } |
070d3ab2 | 74 | |
3dd871ef MG |
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"); | |
79 | else | |
80 | new TimePickerFragment().show(getFragmentManager(), "timePicker"); | |
81 | } | |
82 | ||
83 | @Override | |
84 | public void onTimeSet(final TimePicker picker, final int hour, final int minute) { | |
66307122 | 85 | dateTimeTextView.setText(String.format("%02d:%02d",hour,minute)); |
3dd871ef MG |
86 | if(dateTimeTextView.getId() == R.id.time_start) |
87 | ((TextView)findViewById(R.id.time_end)).setText(String.format("%2d:%2d",hour,minute)); | |
88 | } | |
89 | ||
90 | @Override | |
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); | |
dfc674f6 | 93 | dateTimeTextView.setText(Utils.formatDate(year, monthOfYear, dayOfMonth)); |
3dd871ef MG |
94 | calendar.add(Calendar.DAY_OF_MONTH, 1); |
95 | if(dateTimeTextView.getId() == R.id.date_start) | |
dfc674f6 | 96 | ((TextView)findViewById(R.id.date_end)).setText(Utils.formatDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); |
e6ba41a8 | 97 | } |
5cf4714f | 98 | } |