]>
Commit | Line | Data |
---|---|---|
1 | package ro.ieval.unical; | |
2 | ||
3 | import java.text.SimpleDateFormat; | |
4 | import java.util.Date; | |
5 | import java.util.Locale; | |
6 | ||
7 | import android.app.Activity; | |
8 | import android.content.Context; | |
9 | import android.content.Intent; | |
10 | import android.os.Bundle; | |
11 | import android.view.Menu; | |
12 | import android.view.MenuInflater; | |
13 | import android.view.MenuItem; | |
14 | import android.widget.TextView; | |
15 | ||
16 | public class DisplayEventActivity extends Activity { | |
17 | public static final String EXTRA_EVENT = "event"; | |
18 | private Event event; | |
19 | ||
20 | public static void displayEvent(final Context context, final Event event){ | |
21 | final Intent i=new Intent(context,DisplayEventActivity.class); | |
22 | i.putExtra(DisplayEventActivity.EXTRA_EVENT, event); | |
23 | context.startActivity(i); | |
24 | } | |
25 | ||
26 | @Override | |
27 | protected void onCreate(final Bundle savedInstanceState) { | |
28 | super.onCreate(savedInstanceState); | |
29 | event=getIntent().getParcelableExtra(EXTRA_EVENT); | |
30 | setContentView(R.layout.event_view); | |
31 | setTitle(event.title); | |
32 | ||
33 | final TextView startDay= (TextView) findViewById(R.id.startday); | |
34 | final TextView endDay= (TextView) findViewById(R.id.endday); | |
35 | final TextView startDate= (TextView) findViewById(R.id.startdate); | |
36 | final TextView endDate= (TextView) findViewById(R.id.enddate); | |
37 | final TextView startTime= (TextView) findViewById(R.id.starttime); | |
38 | final TextView endTime= (TextView) findViewById(R.id.endtime); | |
39 | final TextView description= (TextView) findViewById(R.id.event_view_description); | |
40 | ||
41 | final Date start=new Date(event.dtstart); | |
42 | final Date end=new Date(event.dtend); | |
43 | final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.UK); | |
44 | final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.UK); | |
45 | final SimpleDateFormat dayOfWeekFormat = new SimpleDateFormat("EEEEEEE", Locale.UK); | |
46 | ||
47 | startDay.setText(dayOfWeekFormat.format(start)); | |
48 | if(!dateFormat.format(start).equals(dateFormat.format(end))) { | |
49 | endDay.setText(dayOfWeekFormat.format(end)); | |
50 | endDate.setText(dateFormat.format(end)); | |
51 | } | |
52 | startDate.setText(dateFormat.format(start)); | |
53 | startTime.setText(timeFormat.format(start)); | |
54 | endTime.setText(timeFormat.format(end)); | |
55 | description.setText(event.description); | |
56 | } | |
57 | ||
58 | @Override | |
59 | public boolean onCreateOptionsMenu(final Menu menu) { | |
60 | final MenuInflater inflater = getMenuInflater(); | |
61 | inflater.inflate(R.menu.event, menu); | |
62 | return true; | |
63 | } | |
64 | ||
65 | @Override | |
66 | public boolean onOptionsItemSelected(final MenuItem item) { | |
67 | // Handle item selection | |
68 | switch (item. getItemId()) { | |
69 | case R.id.deleteevent: | |
70 | final DeleteEventDialog d=new DeleteEventDialog(event,this); | |
71 | d.show(getFragmentManager(), "Delete"); | |
72 | return true; | |
73 | case R.id.eventlist: | |
74 | final Intent it=new Intent(this,EventListActivity.class); | |
75 | startActivity(it); | |
76 | return true; | |
77 | case R.id.edit_event: | |
78 | AddEventActivity.editEvent(DisplayEventActivity.this,event); | |
79 | return true; | |
80 | case R.id.add_alarm: | |
81 | ||
82 | return true; | |
83 | default: | |
84 | return true; | |
85 | } | |
86 | } | |
87 | } |