Code example for GregorianCalendar

Methods: add, before, get, getTimeInMillis, set

0
			// アラームセット 
			GregorianCalendar cal = getAlermDate();
			Intent i = new Intent(m_context, EnableSilentMode.class);
			PendingIntent pi = PendingIntent.getBroadcast(m_context, 0, i, 0);
			AlarmManager am = (AlarmManager) m_context.getSystemService(Context.ALARM_SERVICE);
			am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi);
 
			Logger.debug("scheduled @ " + cal.get(GregorianCalendar.HOUR_OF_DAY) + ":" + cal.get(GregorianCalendar.MINUTE) + ":" + cal.get(GregorianCalendar.SECOND));
		} else { 
			// アラーム解除 
			Intent i = new Intent(m_context, EnableSilentMode.class);
			PendingIntent pi = PendingIntent.getBroadcast(m_context, 0, i, 0);
			AlarmManager am = (AlarmManager) m_context.getSystemService(Context.ALARM_SERVICE);
			am.cancel(pi);
		} 
	} 
 
	// アラーム時間取得 
	private GregorianCalendar getAlermDate() {
		Integer[] config_time = getAlermtime();
		GregorianCalendar cal = new GregorianCalendar();
		cal.set(GregorianCalendar.HOUR_OF_DAY, config_time[0]);
		cal.set(GregorianCalendar.MINUTE, config_time[1]);
		cal.set(GregorianCalendar.SECOND, 0);
		cal.set(GregorianCalendar.MILLISECOND, 0);
		if (cal.before(new GregorianCalendar())) {
			cal.add(GregorianCalendar.DAY_OF_MONTH, 1);
		} 
//		// for debug ------------------------------------- 
//		cal = new GregorianCalendar(); 
//		cal.add(GregorianCalendar.SECOND, 20); 
//		// for debug ------------------------------------- 
		Logger.debug("getAlermDate: " + cal.get(GregorianCalendar.HOUR_OF_DAY) + ":" + cal.get(GregorianCalendar.MINUTE) + ":" + cal.get(GregorianCalendar.SECOND));
		return cal;
	} 
 
}