android:id="@+id/AddEventButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="Add Event"
+ android:text="@string/addeventtitle"
/>
</LinearLayout>
\ No newline at end of file
android:layout_height="match_parent"
android:orientation="vertical" >
- <ScrollView
- android:id="@+id/scrollView1"
+ <ListView
+ android:id="@+id/eventlist"
android:layout_width="match_parent"
android:layout_height="match_parent" >
-
- <LinearLayout
- android:id="@+id/eventslayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
-
- </LinearLayout>
- </ScrollView>
+ </ListView>
</LinearLayout>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/smalleventtitle"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Medium Text"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <TextView
+ android:id="@+id/smalldatestart"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.85"
+ android:text="Small Text"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ <TextView
+ android:id="@+id/smalldateend"
+ android:layout_width="179dp"
+ android:layout_height="wrap_content"
+ android:text="Small Text"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+ </LinearLayout>
+
+</LinearLayout>
android:gravity="center"
android:text=""
android:textSize="35sp"
- android:selectAllOnFocus="true"
android:textIsSelectable="true"
/>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="askdeleteevent">Delete this event ?</string>
+ <string name="addeventtitle">New Event</string>
<string-array name="Repeat">
<item>Daily</item>
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_event);
+ setTitle(R.string.addeventtitle);
}
}
+++ /dev/null
-package ro.ieval.unical;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.database.Cursor;
-import android.provider.BaseColumns;
-import android.provider.CalendarContract.Calendars;
-
-final class Calendar {
- private static final String[] PROJECTION = {
- BaseColumns._ID,
- Calendars.NAME,
- Calendars.CALENDAR_DISPLAY_NAME,
- Calendars.VISIBLE,
- Calendars.ACCOUNT_NAME,
- Calendars.ACCOUNT_TYPE,
- };
-
- /** Calendar ID */
- public final long _id;
- /** Calendar name */
- public final String name;
- /** Calendar display name */
- public final String displayName;
- /** Calendar visibility (false - do not show events associated with this calendar, true - show events associated with this calendar) */
- public final boolean visible;
- /** Name of the account used to sync this calendar */
- public final String accountName;
- /** 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) {
- this._id=_id;
- this.name=name;
- this.displayName=displayName;
- this.visible=visible;
- this.accountName=accountName;
- this.accountType=accountType;
- }
-
- public static Calendar[] 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()];
- for(int i=0;i<calendars.length;i++){
- calendars[i]=new Calendar(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getInt(3)!=0, cursor.getString(4), cursor.getString(5));
- cursor.moveToNext();
- }
- cursor.close();
- return calendars;
- }
-}
public static Event[] getAllEvents(final Context context) {
final ArrayList<Event> r = new ArrayList<Event>();
- 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()]);
--- /dev/null
+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<EventRowContainer> {
+ 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;
+ }
+}
+++ /dev/null
-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
- }
-
-}
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<events.length; ++i) {
+ EventRowContainer c=new EventRowContainer(i,events[i].title, events[i].dtstart, events[i].dtend);
+ r[i]=c;
+ }
+ final EventAdapter adapter = new EventAdapter(this, r);
+ lv.setAdapter(adapter);
+ lv.setOnItemClickListener(new OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
+ long arg3) {
+ // TODO Auto-generated method stub
+ DisplayEventActivity.displayEvent(EventListActivity.this,events[arg2]);
+ }
+
+ });
+ }
+
private static class EventComparator implements Comparator<Event> {
@Override
public int compare(final Event lhs, final Event rhs) {
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;
+ }
}
}
--- /dev/null
+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() {
+ }
+}
--- /dev/null
+package ro.ieval.unical;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.Cursor;
+import android.provider.BaseColumns;
+import android.provider.CalendarContract.Calendars;
+
+final class GCalendar {
+ private static final String[] PROJECTION = {
+ BaseColumns._ID,
+ Calendars.NAME,
+ Calendars.CALENDAR_DISPLAY_NAME,
+ Calendars.VISIBLE,
+ Calendars.ACCOUNT_NAME,
+ Calendars.ACCOUNT_TYPE,
+ };
+
+ /** Calendar ID */
+ public final long _id;
+ /** Calendar name */
+ public final String name;
+ /** Calendar display name */
+ public final String displayName;
+ /** Calendar visibility (false - do not show events associated with this calendar, true - show events associated with this calendar) */
+ public final boolean visible;
+ /** Name of the account used to sync this calendar */
+ public final String accountName;
+ /** Type of the calendar used to sync this calendar */
+ public 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;
+ this.visible=visible;
+ this.accountName=accountName;
+ this.accountType=accountType;
+ }
+
+ 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 GCalendar[] calendars = new GCalendar[cursor.getCount()];
+ for(int i=0;i<calendars.length;i++){
+ calendars[i]=new GCalendar(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getInt(3)!=0, cursor.getString(4), cursor.getString(5));
+ cursor.moveToNext();
+ }
+ cursor.close();
+ return calendars;
+ }
+}