]> iEval git - unical.git/commitdiff
Add untested getAlarmsByEvent function
authorMarius Gavrilescu <marius@ieval.ro>
Mon, 19 Aug 2013 12:33:26 +0000 (15:33 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Mon, 19 Aug 2013 12:33:26 +0000 (15:33 +0300)
src/ro/ieval/unical/Utils.java

index e8423478c84b112f02aa1195ce560f3633f5283c..895c9464d30069dc8150934c5436b30f7f2d1d3d 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,24 @@ 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();
+               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(i);
+                               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.021474 seconds and 4 git commands to generate.