android:layout_height="match_parent">
<TimePicker
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:id="@+id/timePicker" android:layout_gravity="left|center_vertical"/>
+ android:id="@+id/timePicker" android:layout_gravity="center"/>
<DatePicker
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:id="@+id/datePicker" android:layout_gravity="left|center_vertical"/>
-</LinearLayout>
\ No newline at end of file
+ android:id="@+id/datePicker" android:layout_gravity="center"/>
+</LinearLayout>
android:onClick="showDateTimePickerDialog"
android:text="@string/pick_date"
android:layout_weight="1"
- android:ems="10"
android:focusable="false"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
- </ScrollView>
\ No newline at end of file
+ </ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
+ android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
- <TextView
- android:id="@+id/smallalarmdatestart"
+ <TextView android:id="@+id/alarm_datetime"
android:layout_width="0dip"
android:layout_height="wrap_content"
- android:layout_weight="1"
- android:textAppearance="?android:attr/textAppearanceSmall" />
- <TextView
- android:id="@+id/smallalarmtimestart"
- android:layout_width="0dip"
- android:layout_height="wrap_content"
- android:layout_weight="1"
+ android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall" />
-</LinearLayout>
\ No newline at end of file
+ <Button android:id="@+id/alarm_delete"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/delete"/>
+</LinearLayout>
<TextView
android:id="@+id/event_view_description"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- />
-
-</LinearLayout>
\ No newline at end of file
+ android:layout_height="wrap_content" />
+ <ListView
+ android:id="@+id/alarm_list"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+</LinearLayout>
<string name="stop_alarm">Stop Alarm</string>
<string name="edit_event">Edit Event</string>
<string name="add_alarm">Add alarm</string>
+ <string name="delete">Delete</string>
<string-array name="repeat_array_s">
<item>Day</item>
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.widget.DatePicker;
+import android.widget.TimePicker;
+import java.util.GregorianCalendar;
public class AddAlarmActivity extends ListActivity {
+ public static final String EXTRA_EVENT = "event";
+
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
inflater.inflate(R.menu.add_alarm, menu);
return true;
}
+
+ @Override
+ public boolean onOptionsItemSelected(final MenuItem item){
+ switch(item.getItemId()){
+ case R.id.save:
+ final DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
+ final TimePicker timePicker = (TimePicker) findViewById(R.id.timePicker);
+ final GregorianCalendar calendar = new GregorianCalendar(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), timePicker.getCurrentHour(), timePicker.getCurrentMinute(), 0);
+ Utils.addAlarm((Application) getApplication(), calendar.getTimeInMillis(), getIntent().getLongExtra(EXTRA_EVENT, 0));
+ finish();
+ return true;
+ default:
+ return false;
+ }
+ }
}
final Cursor cur = alarmOpenHelper.getReadableDatabase().query(AlarmOpenHelper.TABLE, null, null, null, null, null, null);
if(cur.moveToFirst()) {
do {
- Utils.setAlarm(this, cur.getLong(0), cur.getLong(1));
+ if(cur.getLong(0) > System.currentTimeMillis())
+ Utils.setAlarm(this, cur.getLong(0), cur.getLong(1));
cur.moveToNext();
} while(!cur.isAfterLast());
}
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.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ListView;
import android.widget.TextView;
public class DisplayEventActivity extends Activity {
+ private final class DeleteListener implements View.OnClickListener {
+ private final long time;
+ DeleteListener(final long time){
+ this.time=time;
+ }
+
+ @Override public void onClick(final View v){
+ Utils.deleteAlarm((Application) getApplication(), time);
+ setAdapter();
+ }
+ }
+
public static final String EXTRA_EVENT = "event";
private Event event;
private final DeleteEventDialog d=new DeleteEventDialog();
+ private void setAdapter(){
+ final ListView alarms = (ListView) findViewById(R.id.alarm_list);
+ alarms.setAdapter(new ArrayAdapter<Long>(this, R.layout.alarm_row_layout, Utils.getAlarmsByEvent((Application) getApplication(), event._id)){
+ @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.alarm_row_layout, parent, false);
+ final TextView date = (TextView) rowView.findViewById(R.id.alarm_datetime);
+ final Button delete = (Button) rowView.findViewById(R.id.alarm_delete);
+ delete.setOnClickListener(new DeleteListener(getItem(position)));
+ date.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK).format(getItem(position)));
+
+ return rowView;
+ }
+ });
+ }
+
public static void displayEvent(final Context context, final long id){
final Intent i=new Intent(context,DisplayEventActivity.class);
i.putExtra(DisplayEventActivity.EXTRA_EVENT, id);
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 TextView description= (TextView) findViewById(R.id.event_view_description);
+ final TextView description= (TextView) findViewById(R.id.event_view_description);;
final Date start=new Date(event.dtstart);
final Date end=new Date(event.dtend);
- final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.UK);
+ final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.UK);
final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.UK);
final SimpleDateFormat dayOfWeekFormat = new SimpleDateFormat("EEEEEEE", Locale.UK);
startTime.setText(timeFormat.format(start));
endTime.setText(timeFormat.format(end));
description.setText(event.description);
+ setAdapter();
}
@Override
return true;
case R.id.eventlist:
- final Intent it=new Intent(this,EventListActivity.class);
+ final Intent it=new Intent(this, EventListActivity.class);
startActivity(it);
return true;
case R.id.edit_event:
- AddEventActivity.editEvent(DisplayEventActivity.this,event);
+ AddEventActivity.editEvent(this, event);
return true;
case R.id.add_alarm:
- startActivity(new Intent(this,AddAlarmActivity.class));
+ final Intent intent = new Intent(this, AddAlarmActivity.class);
+ intent.putExtra(AddAlarmActivity.EXTRA_EVENT, event._id);
+ startActivity(intent);
return true;
default:
- return true;
+ return false;
}
}
}
unsetAlarm(application, time);
}
- public static long[] getAlarmsByEvent(final Application application, final long eventId) throws SQLException{
+ public static Long[] getAlarmsByEvent(final Application application, final long eventId) throws SQLException{
final SQLiteDatabase db = application.alarmOpenHelper.getWritableDatabase();
+ db.delete(AlarmOpenHelper.TABLE, AlarmOpenHelper.TIME + " < " + System.currentTimeMillis(), new String[0]);
final Cursor cursor = db.query(AlarmOpenHelper.TABLE, new String[]{AlarmOpenHelper.TIME}, AlarmOpenHelper.EVENT + " = " + eventId, new String[0], null, null, null);
if(cursor.moveToFirst()){
- final long[] ret = new long[cursor.getCount()];
+ final Long[] ret = new Long[cursor.getCount()];
for(int i=0;i<ret.length;i++){
- ret[i]=cursor.getLong(i);
+ ret[i]=cursor.getLong(0);
cursor.moveToNext();
}
return ret;
}
- return new long[0];
+ return new Long[0];
}
public static void setAlarm(final Context context, final long time, final long eventId){