From ecee6932221bfa129c90b47a4d8015c0082752f7 Mon Sep 17 00:00:00 2001 From: Petru Trimbitas Date: Sun, 9 Jun 2013 19:32:43 +0300 Subject: [PATCH] Replace scroll view with list view --- res/layout/add_event.xml | 2 +- res/layout/event_list.xml | 14 +--- res/layout/event_row_layout.xml | 34 ++++++++ res/layout/event_view.xml | 1 - res/values/strings.xml | 1 + src/ro/ieval/unical/AddEventActivity.java | 1 + src/ro/ieval/unical/Event.java | 2 +- src/ro/ieval/unical/EventAdapter.java | 33 ++++++++ src/ro/ieval/unical/EventButton.java | 14 ---- src/ro/ieval/unical/EventListActivity.java | 78 +++++++++++++++---- src/ro/ieval/unical/EventRowContainer.java | 18 +++++ .../unical/{Calendar.java => GCalendar.java} | 10 +-- 12 files changed, 158 insertions(+), 50 deletions(-) create mode 100644 res/layout/event_row_layout.xml create mode 100644 src/ro/ieval/unical/EventAdapter.java delete mode 100644 src/ro/ieval/unical/EventButton.java create mode 100644 src/ro/ieval/unical/EventRowContainer.java rename src/ro/ieval/unical/{Calendar.java => GCalendar.java} (74%) diff --git a/res/layout/add_event.xml b/res/layout/add_event.xml index 0e57abc..002e6db 100644 --- a/res/layout/add_event.xml +++ b/res/layout/add_event.xml @@ -100,7 +100,7 @@ android:id="@+id/AddEventButton" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="Add Event" + android:text="@string/addeventtitle" /> \ No newline at end of file diff --git a/res/layout/event_list.xml b/res/layout/event_list.xml index cc212a8..6cc66cb 100644 --- a/res/layout/event_list.xml +++ b/res/layout/event_list.xml @@ -5,18 +5,10 @@ android:layout_height="match_parent" android:orientation="vertical" > - - - - - - + diff --git a/res/layout/event_row_layout.xml b/res/layout/event_row_layout.xml new file mode 100644 index 0000000..bb55f15 --- /dev/null +++ b/res/layout/event_row_layout.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/res/layout/event_view.xml b/res/layout/event_view.xml index b8f7713..72b2078 100644 --- a/res/layout/event_view.xml +++ b/res/layout/event_view.xml @@ -11,7 +11,6 @@ android:gravity="center" android:text="" android:textSize="35sp" - android:selectAllOnFocus="true" android:textIsSelectable="true" /> diff --git a/res/values/strings.xml b/res/values/strings.xml index f3b0ab1..ed1faa2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -16,6 +16,7 @@ Yes No Delete this event ? + New Event Daily diff --git a/src/ro/ieval/unical/AddEventActivity.java b/src/ro/ieval/unical/AddEventActivity.java index efb6de7..95b66a3 100644 --- a/src/ro/ieval/unical/AddEventActivity.java +++ b/src/ro/ieval/unical/AddEventActivity.java @@ -7,5 +7,6 @@ public final class AddEventActivity extends Activity { protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_event); + setTitle(R.string.addeventtitle); } } diff --git a/src/ro/ieval/unical/Event.java b/src/ro/ieval/unical/Event.java index 23ccd74..94b817a 100644 --- a/src/ro/ieval/unical/Event.java +++ b/src/ro/ieval/unical/Event.java @@ -86,7 +86,7 @@ final class Event implements Parcelable{ public static Event[] getAllEvents(final Context context) { final ArrayList r = new ArrayList(); - for(final Calendar calendar : Calendar.getAllCalendars(context)) + for(final GCalendar calendar : GCalendar.getAllCalendars(context)) for(final Event event : getEventsByCalendar(context, calendar._id, null)) r.add(event); return r.toArray(new Event[r.size()]); diff --git a/src/ro/ieval/unical/EventAdapter.java b/src/ro/ieval/unical/EventAdapter.java new file mode 100644 index 0000000..4443cd8 --- /dev/null +++ b/src/ro/ieval/unical/EventAdapter.java @@ -0,0 +1,33 @@ +package ro.ieval.unical; +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 { + private final EventRowContainer[] values; + private final Context context; + public EventAdapter(Context context,EventRowContainer[] values) { + super(context,R.layout.event_row_layout,values); + this.context=context; + this.values=values; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rowView = inflater.inflate(R.layout.event_row_layout, parent, false); + TextView title = (TextView) rowView.findViewById(R.id.smalleventtitle); + TextView dstart = (TextView) rowView.findViewById(R.id.smalldatestart); + TextView dend = (TextView) rowView.findViewById(R.id.smalldateend); + title.setText(values[position].name); + dstart.setText(values[position].dtstart.toString()); + dend.setText(values[position].dtend.toString()); + + return rowView; + } +} diff --git a/src/ro/ieval/unical/EventButton.java b/src/ro/ieval/unical/EventButton.java deleted file mode 100644 index 3061d7d..0000000 --- a/src/ro/ieval/unical/EventButton.java +++ /dev/null @@ -1,14 +0,0 @@ -package ro.ieval.unical; -import android.content.Context; -import android.widget.Button; - - -public class EventButton extends Button{ - Event e; - public EventButton(Context context,Event z) { - super(context); - e=z; - // TODO Auto-generated constructor stub - } - -} diff --git a/src/ro/ieval/unical/EventListActivity.java b/src/ro/ieval/unical/EventListActivity.java index 17b219a..9e6d2e8 100644 --- a/src/ro/ieval/unical/EventListActivity.java +++ b/src/ro/ieval/unical/EventListActivity.java @@ -1,18 +1,58 @@ package ro.ieval.unical; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.Comparator; +import java.util.Date; +import java.util.GregorianCalendar; import android.app.Activity; +import android.content.Intent; import android.graphics.Color; import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.LinearLayout; +import android.widget.ListView; public class EventListActivity extends Activity { + + long dtstart,dtend; + //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()); + + EventRowContainer r[]=new EventRowContainer[events.length]; + for(int i=0; i arg0, View arg1, int arg2, + long arg3) { + // TODO Auto-generated method stub + DisplayEventActivity.displayEvent(EventListActivity.this,events[arg2]); + } + + }); + } + private static class EventComparator implements Comparator { @Override public int compare(final Event lhs, final Event rhs) { @@ -29,23 +69,27 @@ public class EventListActivity extends Activity { protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.event_list); - - final Event events[]=Event.getAllEvents(getBaseContext()); - final LinearLayout layout = (LinearLayout) findViewById(R.id.eventslayout); - Arrays.sort(events,new EventComparator()); - for(final Event event : events) { - final Button button=new Button(this); - button.setText(event.title); - - button.setTextColor(Color.BLACK); - button.setOnClickListener(new OnClickListener() { - @Override - public void onClick(final View v) { - DisplayEventActivity.displayEvent(EventListActivity.this, event); - } - }); - layout.addView(button); - } + + displayEvents(); + } + + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + final MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + switch (item.getItemId()) { + case R.id.NewEvent: + final Intent i=new Intent(this,AddEventActivity.class); + startActivity(i); + return true; + default: + return false; + } } } diff --git a/src/ro/ieval/unical/EventRowContainer.java b/src/ro/ieval/unical/EventRowContainer.java new file mode 100644 index 0000000..7f08d0d --- /dev/null +++ b/src/ro/ieval/unical/EventRowContainer.java @@ -0,0 +1,18 @@ +package ro.ieval.unical; + +import java.util.Date; + +public class EventRowContainer { + public String name; + public Date dtstart,dtend; + public int id; + public EventRowContainer(int id,String n,long ds,long de) { + // Container used to hold information for adapter + this.id=id; + this.name=n; + this.dtstart=new Date(ds); + this.dtend=new Date(de); + } + public EventRowContainer() { + } +} diff --git a/src/ro/ieval/unical/Calendar.java b/src/ro/ieval/unical/GCalendar.java similarity index 74% rename from src/ro/ieval/unical/Calendar.java rename to src/ro/ieval/unical/GCalendar.java index 11b2667..3889def 100644 --- a/src/ro/ieval/unical/Calendar.java +++ b/src/ro/ieval/unical/GCalendar.java @@ -6,7 +6,7 @@ import android.database.Cursor; import android.provider.BaseColumns; import android.provider.CalendarContract.Calendars; -final class Calendar { +final class GCalendar { private static final String[] PROJECTION = { BaseColumns._ID, Calendars.NAME, @@ -29,7 +29,7 @@ final class Calendar { /** Type of the calendar used to sync this calendar */ public final String accountType; - private Calendar(final long _id, final String name, final String displayName, final boolean visible, final String accountName, final String accountType) { + private GCalendar(final long _id, final String name, final String displayName, final boolean visible, final String accountName, final String accountType) { this._id=_id; this.name=name; this.displayName=displayName; @@ -38,13 +38,13 @@ final class Calendar { this.accountType=accountType; } - public static Calendar[] getAllCalendars(final Context context){ + public static GCalendar[] getAllCalendars(final Context context){ final ContentResolver cr=context.getContentResolver(); final Cursor cursor = cr.query(Calendars.CONTENT_URI, PROJECTION, null, null, null); cursor.moveToFirst(); - final Calendar[] calendars = new Calendar[cursor.getCount()]; + final GCalendar[] calendars = new GCalendar[cursor.getCount()]; for(int i=0;i