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);
}
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");
}
}
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);
}
}
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);
}
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));
}
Aggregations