| 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 | final TextView description= (TextView) findViewById(R.id.event_view_description); |
| 39 | |
| 40 | final Date start=new Date(e.dtstart); |
| 41 | final Date end=new Date(e.dtend); |
| 42 | final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.UK); |
| 43 | final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.UK); |
| 44 | final SimpleDateFormat dayOfWeekFormat = new SimpleDateFormat("EEEEEEE", Locale.UK); |
| 45 | |
| 46 | startDay.setText(dayOfWeekFormat.format(start)); |
| 47 | if(dateFormat.format(start)!=dateFormat.format(end)) { |
| 48 | endDay.setText(dayOfWeekFormat.format(end)); |
| 49 | endDate.setText(dateFormat.format(end)); |
| 50 | } |
| 51 | startDate.setText(dateFormat.format(start)); |
| 52 | startTime.setText(timeFormat.format(start)); |
| 53 | endTime.setText(timeFormat.format(end)); |
| 54 | description.setText(e.description); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean onCreateOptionsMenu(final Menu menu) { |
| 59 | final MenuInflater inflater = getMenuInflater(); |
| 60 | inflater.inflate(R.menu.event, menu); |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public boolean onOptionsItemSelected(final MenuItem item) { |
| 66 | // Handle item selection |
| 67 | switch (item. getItemId()) { |
| 68 | case R.id.NewEvent: |
| 69 | final Intent i=new Intent(this,AddEventActivity.class); |
| 70 | startActivity(i); |
| 71 | return true; |
| 72 | case R.id.deleteevent: |
| 73 | final DeleteEventDialog d=new DeleteEventDialog(); |
| 74 | d.show(getFragmentManager(), "Delete"); |
| 75 | return true; |
| 76 | case R.id.eventlist: |
| 77 | final Intent it=new Intent(this,EventListActivity.class); |
| 78 | startActivity(it); |
| 79 | return true; |
| 80 | default: |
| 81 | return true; |
| 82 | } |
| 83 | } |
| 84 | } |