]> iEval git - unical.git/blame - src/ro/ieval/unical/Utils.java
Edit event. work in progress[3]
[unical.git] / src / ro / ieval / unical / Utils.java
CommitLineData
402e19d8
MG
1package ro.ieval.unical;
2
6f48b087 3import java.util.GregorianCalendar;
dfc674f6
MG
4import java.util.Locale;
5
6f48b087
PT
6import android.app.AlarmManager;
7import android.app.PendingIntent;
57ca4051 8import android.content.ContentValues;
6f48b087
PT
9import android.content.Context;
10import android.content.Intent;
57ca4051
MG
11import android.database.SQLException;
12import android.database.sqlite.SQLiteDatabase;
402e19d8
MG
13import android.view.View;
14import android.view.ViewGroup;
15
16final class Utils {
dfc674f6
MG
17 private Utils(){ /* do nothing */ }
18
361c6a28 19 public static void setEnabledRecursively(final View view, final boolean enabled){
402e19d8
MG
20 view.setEnabled(enabled);
21 if(view instanceof ViewGroup){
22 final ViewGroup group=(ViewGroup) view;
23 for(int i=0;i<group.getChildCount();i++)
24 setEnabledRecursively(group.getChildAt(i), enabled);
25 }
26 }
dfc674f6
MG
27
28 public static String formatDate(final int year, final int month, final int day){
29 return String.format(Locale.ENGLISH, "%4d-%02d-%02d", year, month, day);
30 }
57ca4051
MG
31
32 public static void addAlarm(final Application application, final long time, final long eventId) throws SQLException{
33 final SQLiteDatabase db = application.alarmOpenHelper.getWritableDatabase();
34 final ContentValues values = new ContentValues(2);
35 values.put(AlarmOpenHelper.TIME, time);
36 values.put(AlarmOpenHelper.EVENT, eventId);
37 db.insertOrThrow(AlarmOpenHelper.TABLE, null, values);
38 setAlarm(application, time, eventId);
39 }
40
41 public static void deleteAlarm(final Application application, final long time) throws SQLException{
42 final SQLiteDatabase db = application.alarmOpenHelper.getWritableDatabase();
43 db.delete(AlarmOpenHelper.TABLE, AlarmOpenHelper.TIME + " = " + time, new String[]{});
44 unsetAlarm(application, time);
45 }
46
47 public static void setAlarm(final Context context, final long time, final long eventId){
48 final Intent intent = new Intent(context, AlarmReceiverActivity.class);
49 intent.setAction(Long.toString(time));
50 intent.putExtra(AlarmReceiverActivity.EXTRA_EVENT, eventId);
51 final AlarmManager man = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
52 man.set(AlarmManager.RTC_WAKEUP, time, PendingIntent.getActivity(context, 0, intent, 0));
53 }
54
55 public static void unsetAlarm(final Context context, final long time){
56 final Intent intent = new Intent(context, AlarmReceiverActivity.class);
57 intent.setAction(Long.toString(time));
58 final AlarmManager man = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
59 man.cancel(PendingIntent.getActivity(context, 0, intent, 0));
6f48b087 60 }
402e19d8 61}
This page took 0.029327 seconds and 4 git commands to generate.