]> iEval git - unical.git/commitdiff
Some improvements
authorPetru <l3asketballplayer@yahoo.com>
Thu, 22 Aug 2013 09:35:11 +0000 (12:35 +0300)
committerPetru <l3asketballplayer@yahoo.com>
Thu, 22 Aug 2013 09:35:11 +0000 (12:35 +0300)
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
src/ro/ieval/unical/AddAlarmActivity.java
src/ro/ieval/unical/DisplayEventActivity.java

index c491c2c81a7f1034cd0c39d786c21d65c96a0fa0..91b1e8681bf0438878783c4319984e4c619befc5 100644 (file)
@@ -51,6 +51,8 @@
        <string name="delete">Delete</string>
        <string name="alarms">Alarms</string>
        <string name="delete_event">Delete event</string>
+    <string name="alarm_error">Cannot have more alarms on the same time</string>
+    <string name="alarm_error_title">Alarm error</string>
 
     <string-array name="repeat_array_s">
         <item>Day</item>
index c823809c3831dffdc61263de641cbdb01b5da757..851edaee11b73239cf671a5b569a9be205748123 100644 (file)
@@ -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;
index 31e0626f907b16ca709431ace770f82dca1bdc54..2ed4aab5d4bf6413be1abde3da9ac01ce090ad55 100644 (file)
@@ -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;
This page took 0.03073 seconds and 4 git commands to generate.