]> iEval git - unical.git/blob - src/ro/ieval/unical/AddEventActivity.java
Edit event. work in progress[3]
[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.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.*;
18
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;
24
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);
28 tempEvent=e;
29 c.startActivity(i);
30 }
31
32
33 @Override
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));
42
43 f1 = new TrivialFragment(tempEvent);
44 final Bundle b1=new Bundle();
45 b1.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_basic_tab);
46 f1.setArguments(b1);
47
48 f2 = new TrivialFragment(tempEvent);
49 final Bundle b2=new Bundle();
50 b2.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_details_tab);
51 f2.setArguments(b2);
52
53 f3 = new TrivialFragment(tempEvent);
54 final Bundle b3=new Bundle();
55 b3.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_other_tab);
56 f3.setArguments(b3);
57
58 t1.setTabListener(new AddEventTabListener(f1,tempEvent,0));
59 t2.setTabListener(new AddEventTabListener(f2,tempEvent,1));
60 t3.setTabListener(new AddEventTabListener(f3,tempEvent,2));
61
62 actionBar.addTab(t1);
63 actionBar.addTab(t2);
64 actionBar.addTab(t3);
65 }
66
67 @Override
68 public boolean onCreateOptionsMenu(final Menu menu) {
69 final MenuInflater inflater = getMenuInflater();
70 inflater.inflate(R.menu.add_event, menu);
71 return true;
72 }
73
74 @Override
75 public boolean onOptionsItemSelected(final MenuItem item) {
76 switch (item.getItemId()) {
77 case R.id.cancel:
78 finish();
79 return true;
80 case R.id.save:
81 //TODO Save event
82 Toast toast = Toast.makeText(getApplicationContext(),"Event saved!",Toast.LENGTH_LONG);
83 toast.show();
84 finish();
85 return true;
86 default:
87 return false;
88 }
89 }
90
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");
95 else
96 new TimePickerFragment().show(getFragmentManager(), "timePicker");
97 }
98
99 @Override
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));
104 }
105
106 @Override
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)));
113 }
114 }
This page took 0.054552 seconds and 4 git commands to generate.