]> iEval git - unical.git/blob - src/ro/ieval/unical/AddEventActivity.java
Adds method to get information from add event layout. work in progress
[unical.git] / src / ro / ieval / unical / AddEventActivity.java
1 package ro.ieval.unical;
2 import java.util.Calendar;
3 import java.util.GregorianCalendar;
4
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;
19
20 public final class AddEventActivity extends Activity implements OnDateSetListener, OnTimeSetListener{
21 private TextView dateTimeTextView;
22
23 @Override
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));
33
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);
48
49 t1.setTabListener(new AddEventTabListener(f1));
50 t2.setTabListener(new AddEventTabListener(f2));
51 t3.setTabListener(new AddEventTabListener(f3));
52
53 actionBar.addTab(t1);
54 actionBar.addTab(t2);
55 actionBar.addTab(t3);
56 }
57
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 }
64
65 @Override
66 public boolean onOptionsItemSelected(final MenuItem item) {
67 switch (item.getItemId()) {
68 case R.id.cancel:
69 finish();
70 return true;
71 case R.id.save:
72 Event e = getEvent(this);
73 return true;
74 default:
75 return false;
76 }
77 }
78
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) {
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");
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) {
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));
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);
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)));
117 }
118 }
This page took 0.045806 seconds and 4 git commands to generate.