]> iEval git - unical.git/commitdiff
Replace scroll view with list view
authorPetru Trimbitas <l3asketballplayer@yahoo.com>
Sun, 9 Jun 2013 16:32:43 +0000 (19:32 +0300)
committerPetru Trimbitas <l3asketballplayer@yahoo.com>
Sun, 9 Jun 2013 16:32:43 +0000 (19:32 +0300)
13 files changed:
res/layout/add_event.xml
res/layout/event_list.xml
res/layout/event_row_layout.xml [new file with mode: 0644]
res/layout/event_view.xml
res/values/strings.xml
src/ro/ieval/unical/AddEventActivity.java
src/ro/ieval/unical/Calendar.java [deleted file]
src/ro/ieval/unical/Event.java
src/ro/ieval/unical/EventAdapter.java [new file with mode: 0644]
src/ro/ieval/unical/EventButton.java [deleted file]
src/ro/ieval/unical/EventListActivity.java
src/ro/ieval/unical/EventRowContainer.java [new file with mode: 0644]
src/ro/ieval/unical/GCalendar.java [new file with mode: 0644]

index 0e57abc89aa16c7c3b3706edeaf36ded52144ecb..002e6dbd3b6374b12633f892e11200f6f23cc40e 100644 (file)
         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
index cc212a82ea8e1db3395462964f9b466de65f58d2..6cc66cba0cf946d4fbfc96c52b70407d569039e2 100644 (file)
@@ -5,18 +5,10 @@
     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>
diff --git a/res/layout/event_row_layout.xml b/res/layout/event_row_layout.xml
new file mode 100644 (file)
index 0000000..bb55f15
--- /dev/null
@@ -0,0 +1,34 @@
+<?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>
index b8f77135e3c481e31128812f889ca9f172939594..72b207821f3feda4bd67edfd8493f2c977ffc46e 100644 (file)
@@ -11,7 +11,6 @@
         android:gravity="center"
         android:text=""
         android:textSize="35sp"
-        android:selectAllOnFocus="true"
         android:textIsSelectable="true"
          />
 
index f3b0ab1ec1879f76d494b1af336c12574cd22b08..ed1faa212f81fb9cff2abf08cb72da5ce0b124cf 100644 (file)
@@ -16,6 +16,7 @@
     <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>
index efb6de7fe7809e5a037aa68144b8c5fabb3669a8..95b66a30ef4dac9349b933e4949ac7167ca69df6 100644 (file)
@@ -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/Calendar.java b/src/ro/ieval/unical/Calendar.java
deleted file mode 100644 (file)
index 11b2667..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-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;
-       }
-}
index 23ccd74d5488b9ba411464bc294bf315c540a7ee..94b817ac63169656a2fbe556d16909aa3ed90840 100644 (file)
@@ -86,7 +86,7 @@ final class Event implements Parcelable{
        
        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()]);
diff --git a/src/ro/ieval/unical/EventAdapter.java b/src/ro/ieval/unical/EventAdapter.java
new file mode 100644 (file)
index 0000000..4443cd8
--- /dev/null
@@ -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<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;
+        }
+}
diff --git a/src/ro/ieval/unical/EventButton.java b/src/ro/ieval/unical/EventButton.java
deleted file mode 100644 (file)
index 3061d7d..0000000
+++ /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
-       }
-       
-}
index 17b219a320895777fc6e6165a210bf3dc2b0e5df..9e6d2e8e1e89e480b964e476a4330fcfc662a1df 100644 (file)
@@ -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<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) {
@@ -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 (file)
index 0000000..7f08d0d
--- /dev/null
@@ -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/GCalendar.java b/src/ro/ieval/unical/GCalendar.java
new file mode 100644 (file)
index 0000000..3889def
--- /dev/null
@@ -0,0 +1,53 @@
+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;
+       }
+}
This page took 0.050188 seconds and 4 git commands to generate.