+++ /dev/null
-package ro.ieval.unical;
-
-import java.util.GregorianCalendar;
-
-import android.content.Context;
-import android.content.res.Resources;
-
-public class CalendarUtils {
- public static String DayToString(Context context, GregorianCalendar gc) {
- int dc=gc.get(GregorianCalendar.DAY_OF_WEEK);
- if(dc==GregorianCalendar.SUNDAY) return context.getString(R.string.sunday);
- else if(dc==GregorianCalendar.MONDAY) return context.getString(R.string.monday);
- else if(dc==GregorianCalendar.TUESDAY) return context.getString(R.string.tuesday);
- else if(dc==GregorianCalendar.WEDNESDAY) return context.getString(R.string.wednesday);
- else if(dc==GregorianCalendar.THURSDAY) return context.getString(R.string.thursday);
- else if(dc==GregorianCalendar.FRIDAY) return context.getString(R.string.friday);
- else return context.getString(R.string.saturday);
- }
-}
public final class DeleteEventDialog extends DialogFragment {
@Override
- public Dialog onCreateDialog(final Bundle savedInstanceState) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setMessage(R.string.askdeleteevent)
- .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(final DialogInterface dialog, final int id) {
+ public Dialog onCreateDialog(final Bundle savedInstanceState) {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setMessage(R.string.askdeleteevent)
+ .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(final DialogInterface dialog, final int id) {
- }
- })
- .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(final DialogInterface dialog, final int id) {
- // User cancelled the dialog
- }
- });
- return builder.create();
- }
+ }
+ })
+ .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(final DialogInterface dialog, final int id) {
+ // User cancelled the dialog
+ }
+ });
+ return builder.create();
+ }
}
import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.GregorianCalendar;
+import java.util.Locale;
import android.app.Activity;
import android.content.Context;
setContentView(R.layout.event_view);
setTitle(e.title);
- final TextView startday= (TextView) findViewById(R.id.startday);
- final TextView endday= (TextView) findViewById(R.id.endday);
- final TextView startdate= (TextView) findViewById(R.id.startdate);
- final TextView enddate= (TextView) findViewById(R.id.enddate);
- final TextView starttime= (TextView) findViewById(R.id.starttime);
- final TextView endtime= (TextView) findViewById(R.id.endtime);
-
- GregorianCalendar cstart = new GregorianCalendar();
- cstart.setTime(new Date(e.dtstart));
- GregorianCalendar cend = new GregorianCalendar();
- cend.setTime(new Date(e.dtend));
- SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
- SimpleDateFormat stf = new SimpleDateFormat("kk:mm:ss");
-
- startday.setText(CalendarUtils.DayToString(this,cstart));
- if(CalendarUtils.DayToString(this,cstart)!=CalendarUtils.DayToString(this, cend))
- endday.setText(CalendarUtils.DayToString(this, cend));
- startdate.setText(sdf.format(cstart.getTime()));
- if(sdf.format(cstart.getTime())!=sdf.format(cend.getTime()))
- enddate.setText(sdf.format(cend.getTime()));
- starttime.setText(stf.format(cstart.getTime()));
- endtime.setText(stf.format(cend.getTime()));
+ final TextView startDay= (TextView) findViewById(R.id.startday);
+ final TextView endDay= (TextView) findViewById(R.id.endday);
+ final TextView startDate= (TextView) findViewById(R.id.startdate);
+ final TextView endDate= (TextView) findViewById(R.id.enddate);
+ final TextView startTime= (TextView) findViewById(R.id.starttime);
+ final TextView endTime= (TextView) findViewById(R.id.endtime);
+
+ final Date start=new Date(e.dtstart);
+ final Date end=new Date(e.dtend);
+ final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.UK);
+ final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.UK);
+ final SimpleDateFormat dayOfWeekFormat = new SimpleDateFormat("E", Locale.UK);
+
+ startDay.setText(dayOfWeekFormat.format(start));
+ if(dayOfWeekFormat.format(start)!=dayOfWeekFormat.format(end))
+ endDay.setText(dayOfWeekFormat.format(end));
+ startDate.setText(dateFormat.format(start));
+ if(dateFormat.format(start)!=dateFormat.format(end))
+ endDate.setText(dateFormat.format(end));
+ startTime.setText(timeFormat.format(start));
+ endTime.setText(timeFormat.format(end));
}
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
final MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.event, menu);
+ inflater.inflate(R.menu.event, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
- // Handle item selection
- switch (item. getItemId()) {
- case R.id.NewEvent:
- final Intent i=new Intent(this,AddEventActivity.class);
+ // Handle item selection
+ switch (item. getItemId()) {
+ case R.id.NewEvent:
+ final Intent i=new Intent(this,AddEventActivity.class);
startActivity(i);
- return true;
- case R.id.deleteevent:
- final DeleteEventDialog d=new DeleteEventDialog();
- d.show(getFragmentManager(), "Delete");
- return true;
- case R.id.eventlist:
- final Intent it=new Intent(this,EventListActivity.class);
- startActivity(it);
- return true;
- default:
- return true;
- }
+ return true;
+ case R.id.deleteevent:
+ final DeleteEventDialog d=new DeleteEventDialog();
+ d.show(getFragmentManager(), "Delete");
+ return true;
+ case R.id.eventlist:
+ final Intent it=new Intent(this,EventListActivity.class);
+ startActivity(it);
+ return true;
+ default:
+ return true;
+ }
}
}
@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;
+ 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;
}
}
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);
-
+ 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)
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
final MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.main, menu);
+ 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);
+ switch (item.getItemId()) {
+ case R.id.NewEvent:
+ final Intent i=new Intent(this,AddEventActivity.class);
startActivity(i);
- return true;
- default:
- return false;
- }
+ return true;
+ default:
+ return false;
+ }
}
}
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
final MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.main, menu);
+ 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);
+ switch (item.getItemId()) {
+ case R.id.NewEvent:
+ final Intent i=new Intent(this,AddEventActivity.class);
startActivity(i);
- return true;
- default:
- return false;
- }
+ return true;
+ default:
+ return false;
+ }
}
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(MySQLiteHelper.class.getName(),
- "Upgrading database from version " + oldVersion + " to "
- + newVersion + ", which will destroy all old data");
- db.execSQL("DROP TABLE IF EXISTS " + Name);
- onCreate(db);
+ "Upgrading database from version " + oldVersion + " to "
+ + newVersion + ", which will destroy all old data");
+ db.execSQL("DROP TABLE IF EXISTS " + Name);
+ onCreate(db);
}
}
\ No newline at end of file