Search in sources :

Example 96 with Calendar

use of java.util.Calendar in project qksms by moezbhatti.

the class DeleteOldMessagesService method deleteOldUnreadMessages.

private void deleteOldUnreadMessages(Context context) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(QKPreferences.getString(QKPreference.AUTO_DELETE_UNREAD)));
    calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
    int count = deleteOldMessages(context, SmsHelper.UNREAD_SELECTION, calendar.getTimeInMillis());
    Log.i(TAG, "Deleted unread messages: " + count);
}
Also used : Calendar(java.util.Calendar)

Example 97 with Calendar

use of java.util.Calendar in project qksms by moezbhatti.

the class DeleteOldMessagesService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    Calendar last = Calendar.getInstance();
    last.setTimeInMillis(QKPreferences.getLong(QKPreference.LAST_AUTO_DELETE_CHECK));
    Calendar current = Calendar.getInstance();
    // Continue if the auto delete setting is enabled, and we haven't done a purge today
    if (QKPreferences.getBoolean(QKPreference.AUTO_DELETE) && (last.getTimeInMillis() == 0 || current.get(Calendar.DAY_OF_YEAR) != last.get(Calendar.DAY_OF_YEAR) || current.get(Calendar.YEAR) != last.get(Calendar.YEAR))) {
        Log.i(TAG, "Ready to delete old messages");
        QKPreferences.setLong(QKPreference.LAST_AUTO_DELETE_CHECK, System.currentTimeMillis());
        deleteOldUnreadMessages(this);
        deleteOldReadMessages(this);
    } else {
        Log.i(TAG, "Not going to delete old messages");
    }
}
Also used : Calendar(java.util.Calendar)

Example 98 with Calendar

use of java.util.Calendar in project qksms by moezbhatti.

the class SettingsFragment method updateAlarmManager.

public static void updateAlarmManager(Context context, boolean enabled) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("H:mm");
    Calendar calendar = Calendar.getInstance();
    Calendar dayCalendar = Calendar.getInstance();
    dayCalendar.setTimeInMillis(System.currentTimeMillis());
    try {
        calendar.setTime(simpleDateFormat.parse(PreferenceManager.getDefaultSharedPreferences(context).getString(DAY_START, "6:00")));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    dayCalendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
    dayCalendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE));
    Intent day = new Intent(context, NightModeAutoReceiver.class);
    PendingIntent dayIntent = PendingIntent.getBroadcast(context, 0, day, 0);
    Calendar nightCalendar = Calendar.getInstance();
    nightCalendar.setTimeInMillis(System.currentTimeMillis());
    try {
        calendar.setTime(simpleDateFormat.parse(PreferenceManager.getDefaultSharedPreferences(context).getString(NIGHT_START, "21:00")));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    nightCalendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
    nightCalendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE));
    Intent night = new Intent(context, NightModeAutoReceiver.class);
    PendingIntent nightIntent = PendingIntent.getBroadcast(context, 1, night, 0);
    context.sendBroadcast(night);
    if (enabled) {
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, dayCalendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, dayIntent);
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, nightCalendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, nightIntent);
    } else {
        alarmManager.cancel(dayIntent);
        alarmManager.cancel(nightIntent);
    }
}
Also used : Calendar(java.util.Calendar) AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ParseException(java.text.ParseException) PendingIntent(android.app.PendingIntent) SimpleDateFormat(java.text.SimpleDateFormat)

Example 99 with Calendar

use of java.util.Calendar in project qksms by moezbhatti.

the class TimePickerFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (mPreference == null) {
        Log.w(TAG, "No preference set");
        return null;
    }
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("H:mm");
    // Use the current time as the default values for the picker
    final Calendar c = Calendar.getInstance();
    try {
        Date date = simpleDateFormat.parse(mPrefs.getString(mPreference.getKey(), "6:00"));
        c.setTime(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    boolean isUsing24HourTime = DateFormat.is24HourFormat(getActivity());
    return new TimePickerDialog(getActivity(), this, hour, minute, isUsing24HourTime);
}
Also used : Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 100 with Calendar

use of java.util.Calendar in project morphia by mongodb.

the class LocalDateTimeConverterTest method testConversion.

@Test
public void testConversion() throws ParseException {
    Calendar cal = Calendar.getInstance();
    cal.set(2016, Calendar.MAY, 1, 12, 30, 45);
    cal.set(Calendar.MILLISECOND, 718);
    assertFormat(LocalDateTime.of(2016, 5, 1, 12, 30, 45, 718004350), cal.getTime());
    compare(LocalDateTime.class, LocalDateTime.now());
    compare(LocalDateTime.class, LocalDateTime.of(12016, 3, 11, 3, 30));
}
Also used : Calendar(java.util.Calendar) Test(org.junit.Test)

Aggregations

Calendar (java.util.Calendar)9446 Date (java.util.Date)2436 GregorianCalendar (java.util.GregorianCalendar)2130 Test (org.junit.Test)1735 SimpleDateFormat (java.text.SimpleDateFormat)889 ArrayList (java.util.ArrayList)476 ParseException (java.text.ParseException)353 HashMap (java.util.HashMap)270 TimeZone (java.util.TimeZone)270 IOException (java.io.IOException)235 DateFormat (java.text.DateFormat)224 Timestamp (java.sql.Timestamp)194 List (java.util.List)187 File (java.io.File)167 Map (java.util.Map)149 BigDecimal (java.math.BigDecimal)134 Locale (java.util.Locale)134 Test (org.testng.annotations.Test)118 Identity (org.olat.core.id.Identity)112 Date (java.sql.Date)110