From 36c4a5768fe75e8b8c9d65680a7706eba3e29e4f Mon Sep 17 00:00:00 2001 From: Petru Date: Thu, 22 Aug 2013 12:35:11 +0300 Subject: [PATCH] Some improvements Adds dialog when two alarms are on the same time Date and time pickers now start with event date and time --- res/values/strings.xml | 2 + src/ro/ieval/unical/AddAlarmActivity.java | 40 ++++++++++++++++++- src/ro/ieval/unical/DisplayEventActivity.java | 4 +- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c491c2c..91b1e86 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -51,6 +51,8 @@ Delete Alarms Delete event + Cannot have more alarms on the same time + Alarm error Day diff --git a/src/ro/ieval/unical/AddAlarmActivity.java b/src/ro/ieval/unical/AddAlarmActivity.java index c823809..851edae 100644 --- a/src/ro/ieval/unical/AddAlarmActivity.java +++ b/src/ro/ieval/unical/AddAlarmActivity.java @@ -1,22 +1,49 @@ package ro.ieval.unical; +import android.app.AlertDialog; import android.app.ListActivity; +import android.content.Context; +import android.content.Intent; +import android.database.SQLException; 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.Date; import java.util.GregorianCalendar; public class AddAlarmActivity extends ListActivity { public static final String EXTRA_EVENT = "event"; + private static Event event; + + public static void addAlarm(final Context c, final Event e) { + final Intent i = new Intent(c,AddAlarmActivity.class); + i.putExtra(AddAlarmActivity.EXTRA_EVENT,e); + event=e; + c.startActivity(i); + } + @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_alarm); setTitle(R.string.add_alarm); + event = getIntent().hasExtra(EXTRA_EVENT) ? (Event) getIntent().getParcelableExtra(EXTRA_EVENT) : new Event(); + final DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker); + final TimePicker timePicker = (TimePicker) findViewById(R.id.timePicker); + Date d=new Date(Math.max(event.dtstart,GregorianCalendar.getInstance().getTimeInMillis())); + datePicker.init(d.getYear()+1900,d.getMonth(),d.getDay(),new DatePicker.OnDateChangedListener() { + @Override + public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { + } + }); + timePicker.setCurrentHour(d.getHours()); + timePicker.setCurrentMinute(d.getMinutes()); + } @Override @@ -33,8 +60,17 @@ public class AddAlarmActivity extends ListActivity { 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(); + try { + Utils.addAlarm((Application) getApplication(), calendar.getTimeInMillis(), getIntent().getLongExtra(EXTRA_EVENT, 0)); + finish(); + }catch(SQLException e) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(R.string.alarm_error) + .setTitle(R.string.alarm_error_title); + AlertDialog dialog = builder.create(); + dialog.show(); + } + return true; default: return false; diff --git a/src/ro/ieval/unical/DisplayEventActivity.java b/src/ro/ieval/unical/DisplayEventActivity.java index 31e0626..2ed4aab 100644 --- a/src/ro/ieval/unical/DisplayEventActivity.java +++ b/src/ro/ieval/unical/DisplayEventActivity.java @@ -117,9 +117,7 @@ public class DisplayEventActivity extends Activity { AddEventActivity.editEvent(this, event); return true; case R.id.add_alarm: - final Intent intent = new Intent(this, AddAlarmActivity.class); - intent.putExtra(AddAlarmActivity.EXTRA_EVENT, event._id); - startActivity(intent); + AddAlarmActivity.addAlarm(this,event); return true; default: return false; -- 2.39.2