+++ /dev/null
-package ro.ieval.unical;
-import java.util.Date;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.TextView;
-
-
-public class EventAdapter extends ArrayAdapter<Event> {
- private final Event[] values;
- private final Context context;
-
- public EventAdapter(final Context context, final Event[] values) {//NOPMD
- super(context,R.layout.event_row_layout,values);
- this.context=context;
- this.values=values;
- }
-
- @Override
- public View getView(final int position, final View convertView, final ViewGroup parent) {
- final LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- final View rowView = inflater.inflate(R.layout.event_row_layout, parent, false);
- final TextView title = (TextView) rowView.findViewById(R.id.smalleventtitle);
- final TextView dstart = (TextView) rowView.findViewById(R.id.smalldatestart);
- final TextView dend = (TextView) rowView.findViewById(R.id.smalldateend);
- final View header = rowView.findViewById(R.id.rowHeader);
- header.setBackgroundColor(values[position].eventColour);
- title.setText(values[position].title);
- dstart.setText(new Date(values[position].dtstart).toString());
- dend.setText(new Date(values[position].dtend).toString());
-
- return rowView;
- }
-}
package ro.ieval.unical;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Date;
-import android.app.Activity;
+import android.app.ListActivity;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.widget.AdapterView;
+import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
import android.widget.ListView;
+import android.widget.TextView;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Date;
-
-public class EventListActivity extends Activity {
-
- //Used to refresh events if the user wants to display only certain events
- //Sry for bad english
- //Muie la comisie
- private void displayEvents() {
- final Event events[]=Event.getAllEvents(getBaseContext());
- final ListView lv = (ListView) findViewById(R.id.eventlist);
-
- Arrays.sort(events,new EventComparator());
- int idx=-1;//index of the first event to be displayed
- for(int i=0; i<events.length; ++i)
- if(idx==-1 && events[i].dtend>new Date().getTime()) idx=i;
- if(idx==-1) idx=0;
-
- final EventAdapter adapter = new EventAdapter(this, events);
- lv.setAdapter(adapter);
- lv.setSelectionFromTop(idx, 0);
- lv.setOnItemClickListener(new OnItemClickListener() {
-
- @Override
- public void onItemClick(final AdapterView<?> arg0, final View arg1, final int arg2,
- final long arg3) {
- DisplayEventActivity.displayEvent(EventListActivity.this,events[arg2]);
- }
-
- });
- }
-
+public final class EventListActivity extends ListActivity {
private static class EventComparator implements Comparator<Event> {
@Override
public int compare(final Event lhs, final Event rhs) {
}
+ private class EventAdapter extends ArrayAdapter<Event> {
+ public EventAdapter() {//NOPMD
+ super(EventListActivity.this, R.layout.event_row_layout);
+ }
+
+ @Override
+ public View getView(final int position, final View convertView, final ViewGroup parent) {
+ final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ final View rowView = inflater.inflate(R.layout.event_row_layout, parent, false);
+ final TextView title = (TextView) rowView.findViewById(R.id.smalleventtitle);
+ final TextView dstart = (TextView) rowView.findViewById(R.id.smalldatestart);
+ final TextView dend = (TextView) rowView.findViewById(R.id.smalldateend);
+ final View header = rowView.findViewById(R.id.rowHeader);
+ header.setBackgroundColor(events[position].eventColour);
+ title.setText(events[position].title);
+ dstart.setText(new Date(events[position].dtstart).toString());
+ dend.setText(new Date(events[position].dtend).toString());
+
+ return rowView;
+ }
+ }
+
+ private Event[] events;
+
+ @Override
+ public void onListItemClick(final ListView view, final View v, final int pos, final long id) {
+ DisplayEventActivity.displayEvent(this, events[pos]);
+ }
+
+ private void displayEvents() {
+ events = Event.getAllEvents(this);
+
+ Arrays.sort(events, new EventComparator());
+ int idx=-1;//index of the first event to be displayed
+ for(int i=0; i<events.length; ++i)
+ if(idx==-1 && events[i].dtend>new Date().getTime()) idx=i;
+ if(idx==-1) idx=0;
+
+ setListAdapter(new EventAdapter());
+ getListView().setSelectionFromTop(idx, 0);
+ }
+
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.event_list);
-
displayEvents();
}
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.add_event:
- final Intent i=new Intent(this,AddEventActivity.class);
- startActivity(i);
+ startActivity(new Intent(this,AddEventActivity.class));
return true;
case R.id.refresh:
displayEvents();