]>
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 | ||
19 | public static void displayEvent(final Context context, final Event event){ | |
20 | final Intent i=new Intent(context,DisplayEventActivity.class); | |
21 | i.putExtra(DisplayEventActivity.EXTRA_EVENT, event); | |
22 | context.startActivity(i); | |
23 | } | |
24 | ||
25 | @Override | |
26 | protected void onCreate(final Bundle savedInstanceState) { | |
27 | super.onCreate(savedInstanceState); | |
28 | final Event e=getIntent().getParcelableExtra(EXTRA_EVENT); | |
29 | setContentView(R.layout.event_view); | |
30 | setTitle(e.title); | |
31 | ||
32 | final TextView startDay= (TextView) findViewById(R.id.startday); | |
33 | final TextView endDay= (TextView) findViewById(R.id.endday); | |
34 | final TextView startDate= (TextView) findViewById(R.id.startdate); | |
35 | final TextView endDate= (TextView) findViewById(R.id.enddate); | |
36 | final TextView startTime= (TextView) findViewById(R.id.starttime); | |
37 | final TextView endTime= (TextView) findViewById(R.id.endtime); | |
38 | ||
39 | final Date start=new Date(e.dtstart); | |
40 | final Date end=new Date(e.dtend); | |
41 | final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.UK); | |
42 | final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.UK); | |
43 | final SimpleDateFormat dayOfWeekFormat = new SimpleDateFormat("EEEEEEE", Locale.UK); | |
44 | ||
45 | startDay.setText(dayOfWeekFormat.format(start)); | |
46 | if(dateFormat.format(start)!=dateFormat.format(end)) { | |
47 | endDay.setText(dayOfWeekFormat.format(end)); | |
48 | endDate.setText(dateFormat.format(end)); | |
49 | } | |
50 | startDate.setText(dateFormat.format(start)); | |
51 | startTime.setText(timeFormat.format(start)); | |
52 | endTime.setText(timeFormat.format(end)); | |
53 | } | |
54 | ||
55 | @Override | |
56 | public boolean onCreateOptionsMenu(final Menu menu) { | |
57 | final MenuInflater inflater = getMenuInflater(); | |
58 | inflater.inflate(R.menu.event, menu); | |
59 | return true; | |
60 | } | |
61 | ||
62 | @Override | |
63 | public boolean onOptionsItemSelected(final MenuItem item) { | |
64 | // Handle item selection | |
65 | switch (item. getItemId()) { | |
66 | case R.id.NewEvent: | |
67 | final Intent i=new Intent(this,AddEventActivity.class); | |
68 | startActivity(i); | |
69 | return true; | |
70 | case R.id.deleteevent: | |
71 | final DeleteEventDialog d=new DeleteEventDialog(); | |
72 | d.show(getFragmentManager(), "Delete"); | |
73 | return true; | |
74 | case R.id.eventlist: | |
75 | final Intent it=new Intent(this,EventListActivity.class); | |
76 | startActivity(it); | |
77 | return true; | |
78 | default: | |
79 | return true; | |
80 | } | |
81 | } | |
82 | } |