Add, show and remove alarms
[unical.git] / src / ro / ieval / unical / Utils.java
index e8423478c84b112f02aa1195ce560f3633f5283c..3b53b479a90cce7964136bcbaeb759055f1a6f5c 100644 (file)
@@ -8,6 +8,7 @@ import android.app.PendingIntent;
 import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
+import android.database.Cursor;
 import android.database.SQLException;
 import android.database.sqlite.SQLiteDatabase;
 import android.view.View;
@@ -40,10 +41,25 @@ final class Utils {
 
        public static void deleteAlarm(final Application application, final long time) throws SQLException{
                final SQLiteDatabase db = application.alarmOpenHelper.getWritableDatabase();
-               db.delete(AlarmOpenHelper.TABLE, AlarmOpenHelper.TIME + " = " + time, new String[]{});
+               db.delete(AlarmOpenHelper.TABLE, AlarmOpenHelper.TIME + " = " + time, new String[0]);
                unsetAlarm(application, time);
        }
 
+       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()];
+                       for(int i=0;i<ret.length;i++){
+                               ret[i]=cursor.getLong(0);
+                               cursor.moveToNext();
+                       }
+                       return ret;
+               }
+               return new Long[0];
+       }
+
        public static void setAlarm(final Context context, final long time, final long eventId){
                final Intent intent = new Intent(context, AlarmReceiverActivity.class);
                intent.setAction(Long.toString(time));
This page took 0.011019 seconds and 4 git commands to generate.