List of usage examples for org.joda.time DateTimeZone forID
@FromString public static DateTimeZone forID(String id)
From source file:io.warp10.script.mapper.MapperMinuteOfHour.java
License:Apache License
public MapperMinuteOfHour(String name, Object timezone) { super(name);// w w w . j ava 2s . co m if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:io.warp10.script.mapper.MapperMonthOfYear.java
License:Apache License
public MapperMonthOfYear(String name, Object timezone) { super(name);//from w ww . j a v a2 s.com if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:io.warp10.script.mapper.MapperSecondOfMinute.java
License:Apache License
public MapperSecondOfMinute(String name, Object timezone) { super(name);/* w w w .j a v a2 s . c o m*/ if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:io.warp10.script.mapper.MapperYear.java
License:Apache License
public MapperYear(String name, Object timezone) { super(name);/* w w w.j a v a 2 s . c o m*/ if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:it.elmariachistudios.mystorews.utils.DateTimeUtils.java
/** * Restituisce la data e l'ora del timezone locale in formato Java Date * @return la data, completa di ora in formato Java Date *///from ww w. j av a 2 s .c om public static Date getNowInJavaDate() { return DateTime.now(DateTimeZone.forID("Europe/Rome")).toDate(); }
From source file:it.elmariachistudios.mystorews.utils.DateTimeUtils.java
/** * Restituisce la data e l'ora del timezone locale in formato Java Date * @return la data completa di ora in formato Joda DateTime *//*from w ww. j ava 2 s . com*/ public static DateTime getNowInJoda() { return DateTime.now(DateTimeZone.forID("Europe/Rome")); }
From source file:it.elmariachistudios.mystorews.utils.DateTimeUtils.java
/** * Restituisce la data priva di ora in formato Java Date * @return la data senza orario in formato Java Date */// ww w. j a v a 2 s. c o m public static Date getNowNoHourInJavaDate() { return LocalDate.now(DateTimeZone.forID("Europe/Rome")).toDate(); }
From source file:it.elmariachistudios.mystorews.utils.DateTimeUtils.java
/** * Restituisce la data priva di ora in formato Joda * @return la data in formato Joda senza ora *//*from w ww. j a va2 s. c om*/ public static LocalDate getNowNoHourInJoda() { return LocalDate.now(DateTimeZone.forID("Europe/Rome")); }
From source file:javafxapplication4.JavaFXApplication4.java
@Override public void init() throws IOException { // Twitter ============================== // String Test = "This is a test message"; // Twitter twitter = TwitterFactory.getSingleton(); // Status status = null; // try { // status = twitter.updateStatus(Test); // } catch (TwitterException ex) { // logger.warn("Unexpected error", e); // } // System.out.println("Successfully updated the status to [" + status.getText() + "]."); logger.info("Starting application...Bissmillah."); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override/*from w w w.j a va2s. com*/ public void run() { logger.info("Exiting application...."); ProcessBuilder processBuilder2 = new ProcessBuilder("bash", "-c", "echo \"standby 0000\" | cec-client -d 1 -s \"standby 0\" RPI"); try { Process process2 = processBuilder2.start(); } catch (IOException e) { logger.warn("Unexpected error", e); } } })); moonPhase = 200; // Get Parameter from database========================================================== try { c = DBConnect.connect(); SQL = "Select * from settings_parramatta"; rs = c.createStatement().executeQuery(SQL); while (rs.next()) { id = rs.getInt("id"); platform = rs.getString("platform"); facebook_notification_enable = rs.getBoolean("facebook_notification_enable"); internet_able = rs.getBoolean("internet_able"); facebook_Receive = rs.getBoolean("facebook_Receive"); latitude = rs.getDouble("latitude"); longitude = rs.getDouble("longitude"); timezone = rs.getInt("timezone"); timeZone_ID = rs.getString("timeZone_ID"); device_name = rs.getString("device_name"); device_location = rs.getString("device_location"); pir_sensor = rs.getBoolean("pir_sensor"); calcMethod = rs.getInt("calcMethod"); AsrJuristic = rs.getInt("AsrJuristic"); fb_Access_token = rs.getString("fb_Access_token"); page_ID = rs.getString("page_ID"); maghrib_adj = rs.getInt("maghrib_adj"); max_ar_hadith_len = rs.getInt("max_ar_hadith_len"); max_en_hadith_len = rs.getInt("max_en_hadith_len"); } c.close(); System.out.format("Prayertime server running on %s platform\n", platform); System.out.format( " Face Book Notification Enabled: %s \n Device is internet able: %s \n Face Book Receive posts: %s \n Facebook page ID: %s \n Latitude: %s \n Longitude: %s \n Time Zone: %s \n Calculation Method: %s \n Asr Juristic: %s \n", facebook_notification_enable, internet_able, facebook_Receive, page_ID, latitude, longitude, timezone, calcMethod, AsrJuristic); System.out.format("This Device Name is:%s at %s \n", device_name, device_location); System.out.format("Time Zone ID is:%s \n", timeZone_ID); } catch (Exception e) { logger.warn("Unexpected error", e); } if (facebook_notification_enable) { System.out.println("facebook notification is enabled"); } if (!facebook_notification_enable) { System.out.println("facebook notification is not enabled"); } if (pir_sensor) { System.out.println("PIR sensor is enabled"); } // facebook Client ========================================================================== // FacebookClient facebookClient = new DefaultFacebookClient("CAAJRZCld8U30BAMmPyEHDW2tlR07At1vTmtHEmD8iHtiFWx7D2ZBroCVWQfdhxQ7h2Eohv8ZBPRk85vs2r7XC0K4ibGdFNMTkh0mJU8vui9PEnpvENOSAFD2q7CQ7NJXjlyK1yITmcrvZBAZByy4qV7whiAb2a2SN7s23nYvDgMMG3RhdPIakZBLV39pkksjYZD"); FacebookClient facebookClient = new DefaultFacebookClient(fb_Access_token); // Pushover ========================================================================== //https://github.com/nicatronTg/jPushover\ // Pushover p = new Pushover("WHq3q48zEFpTqU47Wxygr3VMqoodxc", "skhELgtWRXslAUrYx9yp1s0Os89JTF"); String temp_msg = device_name + " at " + device_location + " is starting"; try { if (internet_able) { p.sendMessage(temp_msg); } } // catch (IOException e){e.printStackTrace();} catch (Exception e) { System.err.println("Sending failed. " + e.getMessage()); } // } // test // try // { // //String pageID = page_ID +"/feed?; // String pageID = "me/feed"; // String temporary_msg = " This is an Automated test message"; // facebookClient.publish(pageID, FacebookType.class, Parameter.with("message", temporary_msg)); // // } // catch (FacebookException e){logger.warn("Unexpected error", e);} //Load random Background image on strtup =============================================== images = new ArrayList<String>(); //change on osx if (platform.equals("osx")) // {directory = new File("/Users/ossama/Projects/Pi/javafx/prayertime/background/");} { directory = new File("/Users/ossama/Dropbox/Projects/Pi/javafx/prayertime/background"); } // {directory = new File("/Users/samia/NetBeansProjects/prayertime_files/background/");} //change on Pi if (platform.equals("pi")) { directory = new File("/home/pi/prayertime/Images/"); } files = directory.listFiles(); for (File f : files) { images.add(f.getName()); } System.out.println(images); countImages = images.size(); imageNumber = (int) (Math.random() * countImages); rand_Image_Path = directory + "/" + images.get(imageNumber); System.out.println(rand_Image_Path); if (!platform.equals("osx")) { try { broadcast_msg = "Prayer Time Server Starting"; socket1 = new DatagramSocket(null); socket1.setBroadcast(true); buf1 = broadcast_msg.getBytes(); group = InetAddress.getByName("255.255.255.255"); packet1 = new DatagramPacket(buf1, buf1.length, group, 8888); socket1.send(packet1); } catch (Exception e) { System.err.println("Sending failed. " + e.getMessage()); } } // ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", "echo \"as\" | cec-client -d 1 -s \"standby 0\" RPI"); // Process process = processBuilder.start(); // BufferedReader br = new BufferedReader(new InputStreamReader(process.getErrorStream())); // String line = null; // while ((line = br.readLine()) != null) { // System.out.println(line); // } // ProcessBuilder processBuilder_Athan = new ProcessBuilder("bash", "-c", "mpg123 /home/pi/prayertime/Audio/athan1.mp3"); // try {Process process3 = processBuilder_Athan.start();} // catch (IOException e) {logger.warn("Unexpected error", e);} Font.loadFont(JavaFXApplication4.class.getResource("Fonts/PTBLARC.TTF").toExternalForm(), 30); Font.loadFont(JavaFXApplication4.class.getResource("Fonts/BMajidSh.ttf").toExternalForm(), 30); Font.loadFont(JavaFXApplication4.class.getResource("Fonts/Oldoutsh.ttf").toExternalForm(), 30); Font.loadFont(JavaFXApplication4.class.getResource("Fonts/BJadidBd.ttf").toExternalForm(), 30); Font.loadFont(JavaFXApplication4.class.getResource("Fonts/wlm_carton.ttf").toExternalForm(), 30); Font.loadFont(JavaFXApplication4.class.getResource("Fonts/Arial_Black.ttf").toExternalForm(), 30); Font.loadFont(JavaFXApplication4.class.getResource("Fonts/Arial_Bold.ttf").toExternalForm(), 30); Font.loadFont(JavaFXApplication4.class.getResource("Fonts/timeburner_regular.ttf").toExternalForm(), 30); Font.loadFont(JavaFXApplication4.class.getResource("Fonts/Pinstripe_Limo.ttf").toExternalForm(), 30); Font.loadFont(JavaFXApplication4.class.getResource("Fonts/LateefRegOT.ttf").toExternalForm(), 30); data = FXCollections.observableArrayList(); Mainpane = new GridPane(); footer_Label = new Label(); like_Label = new Label(); Moon_Image_Label = new Label(); Sunrise_Image_Label = new Label(); Phase_Label = new Label(); Moon_Date_Label = new Label(); Sunrise_Date_Label = new Label(); jamaat_Label_eng = new Label(); jamaat_Label_ar = new Label(); athan_Label_eng = new Label(); athan_Label_ar = new Label(); friday_Label_eng = new Label(); friday_Label_ar = new Label(); sunrise_Label_eng = new Label(); sunrise_Label_ar = new Label(); fajr_Label_ar = new Label(); fajr_Label_eng = new Label(); zuhr_Label_ar = new Label(); zuhr_Label_eng = new Label(); asr_Label_ar = new Label(); asr_Label_eng = new Label(); maghrib_Label_ar = new Label(); maghrib_Label_eng = new Label(); isha_Label_ar = new Label(); isha_Label_eng = new Label(); hadith_Label = new Label(); ar_moon_hadith_Label_L1 = new Label(); ar_moon_hadith_Label_L2 = new Label(); en_moon_hadith_Label_L1 = new Label(); en_moon_hadith_Label_L2 = new Label(); announcement_Label = new Label(); athan_Change_Label_L1 = new Label(); athan_Change_Label_L2 = new Label(); hour_Label = new Label(); minute_Label = new Label(); second_Label = new Label(); date_Label = new Label(); separator_Label = new Label(); divider1_Label = new Label(); divider2_Label = new Label(); fajr_hourLeft = new Label(); fajr_hourRight = new Label(); time_Separator1 = new Label(); fajr_minLeft = new Label(); fajr_minRight = new Label(); fajr_jamma_hourLeft = new Label(); fajr_jamma_hourRight = new Label(); time_jamma_Separator1 = new Label(); fajr_jamma_minLeft = new Label(); fajr_jamma_minRight = new Label(); sunrise_hourLeft = new Label(); sunrise_hourRight = new Label(); time_Separator2 = new Label(); sunrise_minLeft = new Label(); sunrise_minRight = new Label(); zuhr_hourLeft = new Label(); zuhr_hourRight = new Label(); time_Separator3 = new Label(); zuhr_minLeft = new Label(); zuhr_minRight = new Label(); zuhr_jamma_hourLeft = new Label(); zuhr_jamma_hourRight = new Label(); time_jamma_Separator2 = new Label(); zuhr_jamma_minLeft = new Label(); zuhr_jamma_minRight = new Label(); asr_hourLeft = new Label(); asr_hourRight = new Label(); time_Separator4 = new Label(); asr_minLeft = new Label(); asr_minRight = new Label(); asr_jamma_hourLeft = new Label(); asr_jamma_hourRight = new Label(); time_jamma_Separator3 = new Label(); asr_jamma_minLeft = new Label(); asr_jamma_minRight = new Label(); maghrib_hourLeft = new Label(); maghrib_hourRight = new Label(); time_Separator5 = new Label(); maghrib_minLeft = new Label(); maghrib_minRight = new Label(); maghrib_jamma_hourLeft = new Label(); maghrib_jamma_hourRight = new Label(); time_jamma_Separator4 = new Label(); maghrib_jamma_minLeft = new Label(); maghrib_jamma_minRight = new Label(); isha_hourLeft = new Label(); isha_hourRight = new Label(); time_Separator6 = new Label(); isha_minLeft = new Label(); isha_minRight = new Label(); isha_jamma_hourLeft = new Label(); isha_jamma_hourRight = new Label(); time_jamma_Separator5 = new Label(); isha_jamma_minLeft = new Label(); isha_jamma_minRight = new Label(); friday_hourLeft = new Label(); friday_hourRight = new Label(); time_Separator8 = new Label(); friday_minLeft = new Label(); friday_minRight = new Label(); friday2_hourLeft = new Label(); friday2_hourRight = new Label(); time_Separator9 = new Label(); friday2_minLeft = new Label(); friday2_minRight = new Label(); facebook_Label = new Label(); athan_Label_ar.setId("prayer-label-arabic"); athan_Label_ar.setText(""); prayertime_pane.setHalignment(athan_Label_ar, HPos.CENTER); athan_Label_eng.setId("prayer-label-english"); athan_Label_eng.setText("Athan"); prayertime_pane.setHalignment(athan_Label_eng, HPos.CENTER); jamaat_Label_ar.setId("prayer-label-arabic"); jamaat_Label_ar.setText(""); prayertime_pane.setHalignment(jamaat_Label_ar, HPos.CENTER); jamaat_Label_eng.setId("prayer-label-english"); jamaat_Label_eng.setText("Congregation"); prayertime_pane.setHalignment(jamaat_Label_eng, HPos.CENTER); sunrise_Label_ar.setId("prayer-label-arabic"); sunrise_Label_ar.setText(""); prayertime_pane.setHalignment(sunrise_Label_ar, HPos.CENTER); sunrise_Label_eng.setId("prayer-label-english"); sunrise_Label_eng.setText("Sunrise"); prayertime_pane.setHalignment(sunrise_Label_eng, HPos.CENTER); friday_Label_ar.setId("prayer-label-arabic"); friday_Label_ar.setText(""); prayertime_pane.setHalignment(friday_Label_ar, HPos.CENTER); friday_Label_eng.setId("prayer-label-english"); friday_Label_eng.setText("Friday"); prayertime_pane.setHalignment(friday_Label_eng, HPos.CENTER); isha_Label_ar.setId("prayer-label-arabic"); isha_Label_ar.setText(""); prayertime_pane.setHalignment(isha_Label_ar, HPos.CENTER); isha_Label_eng.setId("prayer-label-english"); isha_Label_eng.setText("Isha"); prayertime_pane.setHalignment(isha_Label_eng, HPos.CENTER); maghrib_Label_ar.setId("prayer-label-arabic"); maghrib_Label_ar.setText(""); prayertime_pane.setHalignment(maghrib_Label_ar, HPos.CENTER); maghrib_Label_eng.setId("prayer-label-english"); maghrib_Label_eng.setText("Maghrib"); prayertime_pane.setHalignment(maghrib_Label_eng, HPos.CENTER); asr_Label_ar.setId("prayer-label-arabic"); asr_Label_ar.setText(""); GridPane.setHalignment(asr_Label_ar, HPos.CENTER); asr_Label_eng.setId("prayer-label-english"); asr_Label_eng.setText("Asr"); GridPane.setHalignment(asr_Label_eng, HPos.CENTER); zuhr_Label_ar.setId("prayer-label-arabic"); zuhr_Label_ar.setText(""); GridPane.setHalignment(zuhr_Label_ar, HPos.CENTER); zuhr_Label_eng.setId("prayer-label-english"); zuhr_Label_eng.setText("Duhr"); GridPane.setHalignment(zuhr_Label_eng, HPos.CENTER); fajr_Label_ar.setId("prayer-label-arabic"); fajr_Label_ar.setText("?"); GridPane.setHalignment(fajr_Label_ar, HPos.CENTER); fajr_Label_eng.setId("prayer-label-english"); fajr_Label_eng.setText("Fajr"); GridPane.setHalignment(fajr_Label_eng, HPos.CENTER); Timer prayerCalcTimer = new Timer(); prayerCalcTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { // Moon m = new Moon(); // moonPhase = m.illuminatedPercentage(); // isWaning = m.isWaning(); // update_moon_image = true; // System.out.println("The moon is " + moonPhase + "% full and " + (isWaning ? "waning" : "waxing")); // Locale.setDefault(new Locale("en", "AU")); Date now = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(now); // cal.add(Calendar.DAY_OF_MONTH, -3); // cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); cal.setFirstDayOfWeek(Calendar.MONDAY); dayofweek_int = cal.get(Calendar.DAY_OF_WEEK); String date = new SimpleDateFormat("dd/MM/yyyy").format(new Date()); PrayTime getprayertime = new PrayTime(); getprayertime.setTimeFormat(0); getprayertime.setCalcMethod(calcMethod); getprayertime.setAsrJuristic(AsrJuristic); getprayertime.setAdjustHighLats(0); int[] offsets = { 0, 0, 0, 0, 0, 0, 0 }; // {Fajr,Sunrise,Dhuhr,Asr,Sunset,Maghrib,Isha} getprayertime.tune(offsets); Date time = cal.getTime(); System.out .println(" daylight saving? " + TimeZone.getTimeZone(timeZone_ID).inDaylightTime(time)); // The following calculate the next daylight saving date DateTimeZone zone = DateTimeZone.forID(timeZone_ID); DateTimeFormatter format = DateTimeFormat.mediumDateTime(); // long current = System.currentTimeMillis(); // for (int i=0; i < 1; i++) // { // long next = zone.nextTransition(current); // if (current == next) // { // break; // } // System.out.println ("Next Daylight saving Change: " + format.print(next) + " Into DST? " // + !zone.isStandardOffset(next)); // current = next; // } long next = zone.nextTransition(System.currentTimeMillis()); Date nextTransitionDate = new Date(next); Format format1 = new SimpleDateFormat("yyyy MM dd HH:mm:ss"); format1.format(nextTransitionDate).toString(); Calendar nextTransitionCal = Calendar.getInstance(); nextTransitionCal.setTime(nextTransitionDate); // Date fajr_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm").parse(next); nextTransitionCal.add(Calendar.DAY_OF_MONTH, -7); nextTransitionCal.set(Calendar.HOUR_OF_DAY, 0); System.out.println("Next Daylight saving Check (-7 days): " + nextTransitionCal.getTime()); ArrayList<String> prayerTimes = getprayertime.getPrayerTimes(cal, latitude, longitude, timezone); ArrayList<String> prayerNames = getprayertime.getTimeNames(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm"); Date fajr_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + new Time(formatter.parse(prayerTimes.get(0)).getTime())); cal.setTime(fajr_temp); if (TimeZone.getTimeZone(timeZone_ID).inDaylightTime(time)) { cal.add(Calendar.MINUTE, 60); } Date fajr = cal.getTime(); fajr_cal = Calendar.getInstance(); fajr_cal.setTime(fajr); fajr_begins_time = fajr_cal.getTime(); System.out.println(" fajr time " + fajr_begins_time); Date sunrise_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + new Time(formatter.parse(prayerTimes.get(1)).getTime())); cal.setTime(sunrise_temp); if (TimeZone.getTimeZone(timeZone_ID).inDaylightTime(time)) { cal.add(Calendar.MINUTE, 60); } Date sunrise = cal.getTime(); sunrise_cal = Calendar.getInstance(); sunrise_cal.setTime(sunrise); sunrise_time = sunrise_cal.getTime(); System.out.println(" sunrise time " + sunrise_time); cal.add(Calendar.MINUTE, 15); Date duha = cal.getTime(); // System.out.println(duha); duha_cal = Calendar.getInstance(); duha_cal.setTime(duha); duha_cal.set(Calendar.MILLISECOND, 0); duha_cal.set(Calendar.SECOND, 0); System.out.println(" Duha alarm time " + duha_cal.getTime()); Date zuhr_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + new Time(formatter.parse(prayerTimes.get(2)).getTime())); cal.setTime(zuhr_temp); if (TimeZone.getTimeZone(timeZone_ID).inDaylightTime(time)) { cal.add(Calendar.MINUTE, 60); } Date zuhr = cal.getTime(); zuhr_cal = Calendar.getInstance(); zuhr_cal.setTime(zuhr); zuhr_begins_time = zuhr_cal.getTime(); System.out.println(" Zuhr time " + zuhr_begins_time); Date asr_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + new Time(formatter.parse(prayerTimes.get(3)).getTime())); cal.setTime(asr_temp); if (TimeZone.getTimeZone(timeZone_ID).inDaylightTime(time)) { cal.add(Calendar.MINUTE, 60); } Date asr = cal.getTime(); asr_cal = Calendar.getInstance(); asr_cal.setTime(asr); asr_begins_time = asr_cal.getTime(); System.out.println(" Asr time " + asr_begins_time); Date maghrib_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + new Time(formatter.parse(prayerTimes.get(5)).getTime())); cal.setTime(maghrib_temp); if (TimeZone.getTimeZone(timeZone_ID).inDaylightTime(time)) { cal.add(Calendar.MINUTE, 60); } Date maghrib = cal.getTime(); maghrib_cal = Calendar.getInstance(); maghrib_cal.setTime(maghrib); maghrib_begins_time = maghrib_cal.getTime(); System.out.println(" maghrib time " + maghrib_begins_time); maghrib_plus15_cal = (Calendar) maghrib_cal.clone(); maghrib_plus15_cal.add(Calendar.MINUTE, +15); Date isha_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + new Time(formatter.parse(prayerTimes.get(6)).getTime())); cal.setTime(isha_temp); if (TimeZone.getTimeZone(timeZone_ID).inDaylightTime(time)) { cal.add(Calendar.MINUTE, 60); } Date isha = cal.getTime(); isha_cal = Calendar.getInstance(); isha_cal.setTime(isha); isha_begins_time = isha_cal.getTime(); System.out.println(" isha time " + isha_begins_time); // set friday prayer here if (TimeZone.getTimeZone(timeZone_ID).inDaylightTime(time)) { friday_jamaat = "12:45"; friday2_jamaat = "01:20"; } else { friday_jamaat = "12:45"; friday2_jamaat = "01:20"; } update_prayer_labels = true; getFacebook = true; DateTime_now = new DateTime(); Calendar_now = Calendar.getInstance(); Calendar_now.setTime(new Date()); Calendar_now.set(Calendar.MILLISECOND, 0); Calendar_now.set(Calendar.SECOND, 0); Calendar_now.set(Calendar.MINUTE, 0); Calendar_now.set(Calendar.HOUR_OF_DAY, 0); tzSAUDI_ARABIA = DateTimeZone.forID("Asia/Riyadh"); dtIslamic = DateTime_now.withChronology( IslamicChronology.getInstance(tzSAUDI_ARABIA, IslamicChronology.LEAP_YEAR_15_BASED)); System.out.print("Arabic Date: "); System.out.print(dtIslamic.getMonthOfYear()); System.out.print("/"); System.out.println(dtIslamic.getDayOfMonth()); if (dtIslamic.getMonthOfYear() == 9) { System.out.println("==========Ramadan Moubarik=========="); } //enable athan play time if (dayofweek_int != olddayofweek_int) { Moon m = new Moon(); moonPhase = m.illuminatedPercentage(); isWaning = m.isWaning(); update_moon_image = true; System.out.println( "The moon is " + moonPhase + "% full and " + (isWaning ? "waning" : "waxing")); // old_today = Calendar.getInstance(); olddayofweek_int = dayofweek_int; // System.out.println("current day of the week " + dayofweek_int ); // System.out.println("old day of the week " + olddayofweek_int ); // System.out.println(" cal: " + cal ); fajr_athan_enable = true; duha_athan_enable = true; zuhr_athan_enable = true; asr_athan_enable = true; maghrib_athan_enable = true; isha_athan_enable = true; getHadith = true; //==============JAMAA Prayer time try { c = DBConnect.connect(); // System.out.println("connected"); SQL = "select * from paramatta_prayertimes where DATE(date) = DATE(NOW())"; rs = c.createStatement().executeQuery(SQL); while (rs.next()) { id = rs.getInt("id"); prayer_date = rs.getDate("date"); fajr_jamaat_time = rs.getTime("fajr_jamaat"); zuhr_jamaat_time = rs.getTime("zuhr_jamaat"); asr_jamaat_time = rs.getTime("asr_jamaat"); maghrib_jamaat_time = rs.getTime("maghrib_jamaat"); isha_jamaat_time = rs.getTime("isha_jamaat"); } c.close(); fajr_jamaat = fajr_jamaat_time.toString(); zuhr_jamaat = zuhr_jamaat_time.toString(); // if (TimeZone.getTimeZone( timeZone_ID).inDaylightTime( time )){zuhr_jamaat = "01:15";} // // else // { // // HolidayManager HOLIDAY = HolidayManager.getInstance(HolidayCalendar.AUSTRALIA); // Set<Holiday> holidays = HOLIDAY.getHolidays(2014, "NSW"); // System.out.println(holidays); // System.out.println(dayofweek_int); // if (dayofweek_int == 1 || dayofweek_int == 7) // { // zuhr_jamaat = "12:15"; // } // else{zuhr_jamaat = "01:15";} // } asr_jamaat = asr_jamaat_time.toString(); maghrib_jamaat = maghrib_jamaat_time.toString(); isha_jamaat = isha_jamaat_time.toString(); // print the results System.out.format("%s,%s,%s,%s,%s,%s,%s \n", id, prayer_date, fajr_jamaat, zuhr_jamaat, asr_jamaat, maghrib_jamaat, isha_jamaat); } catch (Exception e) { logger.warn("Unexpected error", e); } //==============Prayer notification - setup notification timming Date fajr_jamaat_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + fajr_jamaat); cal.setTime(fajr_jamaat_temp); cal.add(Calendar.MINUTE, 5); Date fajr_jamaat = cal.getTime(); fajr_jamaat_update_cal = Calendar.getInstance(); fajr_jamaat_update_cal.setTime(fajr_jamaat); fajr_jamaat_update_cal.set(Calendar.MILLISECOND, 0); fajr_jamaat_update_cal.set(Calendar.SECOND, 0); fajr_jamaat_cal = (Calendar) fajr_jamaat_update_cal.clone(); fajr_jamaat_cal.add(Calendar.MINUTE, -5); // System.out.println("fajr Jamaat update scheduled at:" + fajr_jamaat_update_cal.getTime()); Date zuhr_jamaat_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + zuhr_jamaat); cal.setTime(zuhr_jamaat_temp); Date zuhr_jamaat_Date = cal.getTime(); zuhr_jamaat_cal = Calendar.getInstance(); zuhr_jamaat_cal.setTime(zuhr_jamaat_Date); zuhr_jamaat_cal.set(Calendar.MILLISECOND, 0); zuhr_jamaat_cal.set(Calendar.SECOND, 0); zuhr_plus15_cal = (Calendar) zuhr_jamaat_cal.clone(); zuhr_plus15_cal.add(Calendar.MINUTE, +15); Date asr_jamaat_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + asr_jamaat); cal.setTime(asr_jamaat_temp); cal.add(Calendar.MINUTE, 5); Date asr_jamaat = cal.getTime(); asr_jamaat_update_cal = Calendar.getInstance(); asr_jamaat_update_cal.setTime(asr_jamaat); asr_jamaat_update_cal.set(Calendar.MILLISECOND, 0); asr_jamaat_update_cal.set(Calendar.SECOND, 0); // System.out.println("asr Jamaat update scheduled at:" + asr_jamaat_update_cal.getTime()); asr_jamaat_cal = (Calendar) asr_jamaat_update_cal.clone(); asr_jamaat_cal.add(Calendar.MINUTE, -5); // maghrib_jamaat_cal = (Calendar)maghrib_cal.clone(); // maghrib_jamaat_cal.add(Calendar.MINUTE, maghrib_adj); Date maghrib_jamaat_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + maghrib_jamaat); cal.setTime(maghrib_jamaat_temp); cal.add(Calendar.MINUTE, 5); Date maghrib_jamaat = cal.getTime(); maghrib_jamaat_update_cal = Calendar.getInstance(); maghrib_jamaat_update_cal.setTime(maghrib_jamaat); maghrib_jamaat_update_cal.set(Calendar.MILLISECOND, 0); maghrib_jamaat_update_cal.set(Calendar.SECOND, 0); // System.out.println("maghrib Jamaat update scheduled at:" + maghrib_jamaat_update_cal.getTime()); maghrib_jamaat_cal = (Calendar) maghrib_jamaat_update_cal.clone(); maghrib_jamaat_cal.add(Calendar.MINUTE, -5); Date isha_jamaat_temp = new SimpleDateFormat("dd/MM/yyyy HH:mm") .parse(date + " " + isha_jamaat); cal.setTime(isha_jamaat_temp); cal.add(Calendar.MINUTE, 5); Date isha_jamaat = cal.getTime(); isha_jamaat_update_cal = Calendar.getInstance(); isha_jamaat_update_cal.setTime(isha_jamaat); isha_jamaat_update_cal.set(Calendar.MILLISECOND, 0); isha_jamaat_update_cal.set(Calendar.SECOND, 0); // System.out.println("Isha Jamaat update scheduled at:" + isha_jamaat_update_cal.getTime()); isha_jamaat_cal = (Calendar) isha_jamaat_update_cal.clone(); isha_jamaat_cal.add(Calendar.MINUTE, -5); //==============Prayer time change notification logic + 5days // check excel file in documentation folder for a flow chart // check if a notification has already been sent, to avoid flooding users with notifications, i.e during a system restart ar_notification_Msg_Lines = null; try { c = DBConnect.connect(); SQL = "Select * from notification where id = (select max(id) from notification)"; rs = c.createStatement().executeQuery(SQL); while (rs.next()) { id = rs.getInt("id"); notification_Date = rs.getDate("notification_Date"); en_message_String = rs.getString("en_message_String"); ar_message_String = rs.getString("ar_message_String"); notification_Sent = rs.getBoolean("notification_Sent"); } c.close(); System.out.format("%s,%s,%s,%s \n", notification_Date, en_message_String, ar_message_String, notification_Sent); } catch (Exception e) { logger.warn("Unexpected error", e); } notification_Date_cal = Calendar.getInstance(); notification_Date_cal.setTime(notification_Date); notification_Date_cal.set(Calendar.MILLISECOND, 0); notification_Date_cal.set(Calendar.SECOND, 0); // System.out.println("notification_Date_cal:" + notification_Date_cal.getTime()); // System.out.println("Calendar_now: " + Calendar_now.getTime()); if (Calendar_now.compareTo(notification_Date_cal) < 0) //&& !notification_Sent { en_notification_Msg = en_message_String; ar_notification_Msg = ar_message_String; ar_notification_Msg_Lines = ar_notification_Msg.split("\\r?\\n"); en_notification_Msg_Lines = en_notification_Msg.split("\\r?\\n"); athan_Change_Label_visible = true; getFacebook = false; } if (Calendar_now.compareTo(notification_Date_cal) >= 0) //&& !notification_Sent { athan_Change_Label_visible = false; try { c = DBConnect.connect(); SQL = "select * from paramatta_prayertimes where DATE(date) = DATE(NOW() ) + INTERVAL 2 DAY "; rs = c.createStatement().executeQuery(SQL); while (rs.next()) { future_prayer_date = rs.getDate("date"); future_fajr_jamaat_time = rs.getTime("fajr_jamaat"); future_asr_jamaat_time = rs.getTime("asr_jamaat"); future_maghrib_jamaat_time = rs.getTime("maghrib_jamaat"); future_isha_jamaat_time = rs.getTime("isha_jamaat"); } c.close(); // print the results System.out.format("%s,%s,%s,%s,%s \n", future_prayer_date, future_fajr_jamaat_time, future_asr_jamaat_time, future_maghrib_jamaat_time, future_isha_jamaat_time); if (!fajr_jamaat_time.equals(future_fajr_jamaat_time)) { System.out.println("Fajr Prayer Time Difference"); fajr_jamma_time_change = true; notification = true; java.sql.Date sqlDate = new java.sql.Date(future_prayer_date.getTime()); c = DBConnect.connect(); PreparedStatement ps = c.prepareStatement( "INSERT INTO prayertime.notification (notification_Date) VALUE (?)"); ps.setDate(1, sqlDate); ps.executeUpdate(); c.close(); } if (!asr_jamaat_time.equals(future_asr_jamaat_time)) { System.out.println("asr Prayer Time Difference"); asr_jamma_time_change = true; if (!notification) { java.sql.Date sqlDate = new java.sql.Date(future_prayer_date.getTime()); c = DBConnect.connect(); PreparedStatement ps = c.prepareStatement( "INSERT INTO prayertime.notification (notification_Date) VALUE (?)"); ps.setDate(1, sqlDate); ps.executeUpdate(); c.close(); } notification = true; } if (!maghrib_jamaat_time.equals(future_maghrib_jamaat_time)) { System.out.println("maghrib Prayer Time Difference"); maghrib_jamma_time_change = true; if (!notification) { java.sql.Date sqlDate = new java.sql.Date(future_prayer_date.getTime()); c = DBConnect.connect(); PreparedStatement ps = c.prepareStatement( "INSERT INTO prayertime.notification (notification_Date) VALUE (?)"); ps.setDate(1, sqlDate); ps.executeUpdate(); c.close(); } notification = true; } if (!isha_jamaat_time.equals(future_isha_jamaat_time)) { System.out.println("isha Prayer Time Difference"); isha_jamma_time_change = true; if (!notification) { java.sql.Date sqlDate = new java.sql.Date(future_prayer_date.getTime()); c = DBConnect.connect(); PreparedStatement ps = c.prepareStatement( "INSERT INTO prayertime.notification (notification_Date) VALUE (?)"); ps.setDate(1, sqlDate); ps.executeUpdate(); c.close(); } notification = true; } } catch (Exception e) { logger.warn("Unexpected error", e); } } fullMoon = MoonPhaseFinder.findFullMoonFollowing(Calendar.getInstance()); newMoon = MoonPhaseFinder.findNewMoonFollowing(Calendar.getInstance()); System.out.println("The moon is full on " + fullMoon); System.out.println("The moon is new on " + newMoon); if (newMoon.before(fullMoon)) { System.out.println("New moon is before full moon"); } else { System.out.println("Full moon is before new moon"); } pir_disactive_startup = false; // ======= Notification for ashura and full moon 5 days earlier, 2 days before fasting period //TODO Use moonsighting.info to get moon sighting observations Days d = Days.daysBetween(new DateMidnight(DateTime_now), new DateMidnight(fullMoon)); int days_Between_Now_Fullmoon = d.getDays(); System.out.format("Days left to full moon: %s\n", days_Between_Now_Fullmoon); fullMoon_plus1 = (Date) fullMoon.clone(); Date ashura = (Date) fullMoon.clone(); DateTimeComparator comparator = DateTimeComparator.getTimeOnlyInstance(); // System.out.println(days_Between_Now_Fullmoon); if (dtIslamic.getMonthOfYear() == 1 && days_Between_Now_Fullmoon == 9 && comparator.compare(fullMoon, maghrib_cal) > 0) { //hide hadith label boolean getHadith = false; // getFacebook = false; hadith_Label_visible = false; //show moon notification label boolean moon_hadith_Label_visible = true; // 15 - 9 = 6 Ashura = fullMoon_plus1.setTime(fullMoon.getTime() - 4 * 24 * 60 * 60 * 1000); try { c = DBConnect.connect(); SQL = "select hadith, translated_hadith from hadith WHERE (translated_hadith LIKE '%Ashura%') and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; rs = c.createStatement().executeQuery(SQL); while (rs.next()) { hadith = rs.getString("hadith"); translated_hadith = rs.getString("translated_hadith"); } c.close(); System.out.println("Ashura arabic hadith length" + hadith.length()); System.out.println("Ashura english hadith length" + translated_hadith.length()); } catch (Exception e) { logger.warn("Unexpected error", e); } ashura.setTime(fullMoon.getTime() - 4 * 24 * 60 * 60 * 1000); String Ashura_dow_ar = new SimpleDateFormat("' 'EEEE' '", new Locale("ar")) .format(ashura); String Ashura_dow_en = new SimpleDateFormat("EEEE").format(ashura); String temp_ar_text1 = " "; String temp_ar_text2 = " . ? "; ar_moon_notification = temp_ar_text1 + Ashura_dow_ar + temp_ar_text2; en_moon_notification = "A reminder that the 10th of Muharram \"Ashura\" will fall on " + Ashura_dow_en + ", It is recommended to fast either the 9th & 10th of Muharram or the 10th & 11th "; facebook_moon_notification_Msg = ar_moon_notification + "\n\n" + en_moon_notification; if (facebook_notification_enable) { try { //String pageID = page_ID +"/feed?; String pageID = "me/feed"; facebookClient.publish(pageID, FacebookType.class, Parameter.with("message", facebook_moon_notification_Msg)); System.out.println("Full Moon Notification Sent to Facebook:"); System.out.println(facebook_moon_notification_Msg); } catch (FacebookException e) { logger.warn("Unexpected error", e); } } } else if (dtIslamic.getMonthOfYear() == 1 && days_Between_Now_Fullmoon == 9) { //hide hadith label boolean getHadith = false; // getFacebook = false; hadith_Label_visible = false; //show moon notification label boolean moon_hadith_Label_visible = true; // 15 - 9 = 6 Ashura = fullMoon_plus1.setTime(fullMoon.getTime() - 5 * 24 * 60 * 60 * 1000); } if (dtIslamic.getMonthOfYear() != 9 && days_Between_Now_Fullmoon <= 5 && days_Between_Now_Fullmoon >= 2) { //hide hadith label boolean getHadith = false; // getFacebook = false; hadith_Label_visible = false; //show moon notification label boolean moon_hadith_Label_visible = true; try { c = DBConnect.connect(); SQL = "select hadith, translated_hadith from hadith WHERE day = '15' ORDER BY RAND( ) LIMIT 1"; rs = c.createStatement().executeQuery(SQL); while (rs.next()) { ar_full_moon_hadith = rs.getString("hadith"); en_full_moon_hadith = rs.getString("translated_hadith"); } c.close(); System.out.format("Full Moon arabic hadith: %s\n", ar_full_moon_hadith); System.out.format("Full Moon english hadith: %s\n", en_full_moon_hadith); } catch (Exception e) { logger.warn("Unexpected error", e); } if (days_Between_Now_Fullmoon == 5 && comparator.compare(fullMoon, maghrib_cal) < 0) { fullMoon_plus1.setTime(fullMoon.getTime() - 2 * 24 * 60 * 60 * 1000); String FullMoon_dow_ar = new SimpleDateFormat("' 'EEEE' '", new Locale("ar")) .format(fullMoon_plus1); String FullMoon_dow_en = new SimpleDateFormat("EEEE").format(fullMoon_plus1); String temp_ar_text1 = " ? ? "; String temp_ar_text2 = " ? . "; ar_moon_notification = temp_ar_text1 + FullMoon_dow_ar + temp_ar_text2; en_moon_notification = "We would like to remind our dear brothers & sisters that this month's \"White days\" will start this " + FullMoon_dow_en + ", it is recommended to fast these days. Pls note that this is based on calendar calculations not moon sighting observations"; facebook_moon_notification_Msg = ar_moon_notification + "\n\n" + en_moon_notification; // try // { // //String pageID = page_ID +"/feed?; // String pageID = "me/feed"; // facebookClient.publish(pageID, FacebookType.class, Parameter.with("message", facebook_moon_notification_Msg)); // } // catch (FacebookException e){logger.warn("Unexpected error", e);} // System.out.println("Full Moon Notification Sent to Facebook:" ); // System.out.println(facebook_moon_notification_Msg); } else if (days_Between_Now_Fullmoon == 5) { if (comparator.compare(fullMoon, maghrib_cal) > 0) { fullMoon_plus1.setTime(fullMoon.getTime() - 1 * 24 * 60 * 60 * 1000); String FullMoon_dow_ar = new SimpleDateFormat("' 'EEEE' '", new Locale("ar")) .format(fullMoon_plus1); String FullMoon_dow_en = new SimpleDateFormat("EEEE").format(fullMoon_plus1); String temp_ar_text1 = " ? ? "; String temp_ar_text2 = " ? . "; ar_moon_notification = temp_ar_text1 + FullMoon_dow_ar + temp_ar_text2; en_moon_notification = "We would like to remind our dear brothers & sisters that this month's \"White days\" will start this " + FullMoon_dow_en + ", it is recommended to fast these days. Pls note that this is based on calendar calculations not moon sighting observations"; facebook_moon_notification_Msg = ar_moon_notification + "\n\n" + en_moon_notification; if (facebook_notification_enable) { try { //String pageID = page_ID +"/feed?; String pageID = "me/feed"; facebookClient.publish(pageID, FacebookType.class, Parameter.with("message", facebook_moon_notification_Msg)); System.out.println("Full Moon Notification Sent to Facebook:"); System.out.println(facebook_moon_notification_Msg); } catch (FacebookException e) { logger.warn("Unexpected error", e); } } } else { fullMoon_plus1.setTime(fullMoon.getTime() - 2 * 24 * 60 * 60 * 1000); String FullMoon_dow_ar = new SimpleDateFormat("' 'EEEE' '", new Locale("ar")) .format(fullMoon_plus1); String FullMoon_dow_en = new SimpleDateFormat("EEEE").format(fullMoon_plus1); String temp_ar_text1 = " ? ? "; String temp_ar_text2 = " ? . "; ar_moon_notification = temp_ar_text1 + FullMoon_dow_ar + temp_ar_text2; en_moon_notification = "We would like to remind our dear brothers & sisters that this month's \"White days\" will start this " + FullMoon_dow_en + ", it is recommended to fast these days. Pls note that this is based on calendar calculations not moon sighting observations"; facebook_moon_notification_Msg = ar_moon_notification + "\n\n" + en_moon_notification; System.out.println("Full Moon Notification:"); System.out.println(facebook_moon_notification_Msg); } } else if (days_Between_Now_Fullmoon == 3) { if (comparator.compare(fullMoon, maghrib_cal) > 0) { fullMoon_plus1.setTime(fullMoon.getTime() - 1 * 24 * 60 * 60 * 1000); String FullMoon_dow_ar = new SimpleDateFormat("' 'EEEE' '", new Locale("ar")) .format(fullMoon_plus1); String FullMoon_dow_en = new SimpleDateFormat("EEEE").format(fullMoon_plus1); String temp_ar_text1 = " ? ? "; String temp_ar_text2 = " ? . "; ar_moon_notification = temp_ar_text1 + FullMoon_dow_ar + temp_ar_text2; en_moon_notification = "We would like to remind our dear brothers & sisters that this month's \"White days\" will start this " + FullMoon_dow_en + ", it is recommended to fast these days. Pls note that this is based on calendar calculations not moon sighting observations"; facebook_moon_notification_Msg = ar_moon_notification + "\n\n" + en_moon_notification; } else { String temp_ar_text1 = " ? ? "; String temp_ar_text2 = " ? . "; ar_moon_notification = temp_ar_text1 + temp_ar_text2; en_moon_notification = "We would like to remind our dear brothers & sisters that this month's \"White days\" will start tomorrow, it is recommended to fast these days. Pls note that this is based on calendar calculations not moon sighting observations"; facebook_moon_notification_Msg = ar_moon_notification + "\n\n" + en_moon_notification; if (facebook_notification_enable) { try { //String pageID = page_ID +"/feed?; String pageID = "me/feed"; facebookClient.publish(pageID, FacebookType.class, Parameter.with("message", facebook_moon_notification_Msg)); System.out.println("Full Moon Notification Sent to Facebook:"); System.out.println(facebook_moon_notification_Msg); } catch (FacebookException e) { logger.warn("Unexpected error", e); } } } } else if (days_Between_Now_Fullmoon == 2 && comparator.compare(fullMoon, maghrib_cal) > 0) { String temp_ar_text1 = " ? ? "; String temp_ar_text2 = " ? . "; ar_moon_notification = temp_ar_text1 + temp_ar_text2; System.out.println(ar_moon_notification); en_moon_notification = "We would like to remind our dear brothers & sisters that this month's \"White days\" will start tomorrow, it is recommended to fast these days. Pls note that this is based on calendar calculations not moon sighting observations"; System.out.println(en_moon_notification); facebook_moon_notification_Msg = ar_moon_notification + "\n\n" + en_moon_notification; if (facebook_notification_enable) { try { //String pageID = page_ID +"/feed?; String pageID = "me/feed"; facebookClient.publish(pageID, FacebookType.class, Parameter.with("message", facebook_moon_notification_Msg)); System.out.println("Full Moon Notification Sent to Facebook:"); System.out.println(facebook_moon_notification_Msg); } catch (FacebookException e) { logger.warn("Unexpected error", e); } } } else { getHadith = true; moon_hadith_Label_visible = false; hadith_Label_visible = true; System.out.println("moon else"); } } else if (days_Between_Now_Fullmoon > 5 || days_Between_Now_Fullmoon < 2 || dtIslamic.getMonthOfYear() != 1) { getHadith = true; // getFacebook = true; //hide moon notification label boolean moon_hadith_Label_visible = false; //show hadith label boolean hadith_Label_visible = true; } } //TODO Prayer time change notification/////////////////////put this in a thread, so error does not stop code further down ======================================================== // creates message to send to facebook // creates labels for notification if (notification) { ar_notification_Msg_Lines = null; // Calendar_now.setTime(future_prayer_date); Calendar prayertime_Change_Due_Date = null; prayertime_Change_Due_Date = Calendar.getInstance(); prayertime_Change_Due_Date.setTime(future_prayer_date); System.out.println("Calendar_now: " + Calendar_now.getTime()); int day = prayertime_Change_Due_Date.get(Calendar.DAY_OF_MONTH); String dayStr = day + suffixes[day]; String en_notification_date = new SimpleDateFormat("EEEE").format(future_prayer_date); String en_notification_date1 = new SimpleDateFormat("' of ' MMMM") .format(future_prayer_date); String ar_notification_date = new SimpleDateFormat(" EEEE d MMMM ", new Locale("ar")) .format(future_prayer_date); labeconv = " " + ar_notification_date + " \n"; StringBuilder builder = new StringBuilder(); for (int i = 0; i < labeconv.length(); i++) { if (Character.isDigit(labeconv.charAt(i))) { builder.append(arabicChars[(int) (labeconv.charAt(i)) - 48]); } else { builder.append(labeconv.charAt(i)); } } ar_notification_Msg = builder.toString(); en_notification_Msg = "Starting from " + en_notification_date + " the " + dayStr + en_notification_date1 + " the following prayer time(s) will change\n"; SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm"); // en_notification_Msg = "Time change\nTime saving will be in effect as of *Sunday, November 03, 2013*\nAll prayer times will move back by one hour.\nJummah prayer will be at 1:00 PM"; if (fajr_jamma_time_change) { String future_fajr_jamaat_time_mod = DATE_FORMAT.format(future_fajr_jamaat_time); // Date future_fajr_jamaat_time_mod = new SimpleDateFormat("HH:mm").parse("Fajr time: " + future_fajr_jamaat_time); en_notification_Msg = en_notification_Msg + "Fajr: " + future_fajr_jamaat_time_mod + " "; ar_notification_Msg = ar_notification_Msg + "?: " + future_fajr_jamaat_time_mod + " "; fajr_jamma_time_change = false; } if (Calendar_now.compareTo(nextTransitionCal) == 0) { if (TimeZone.getTimeZone(timeZone_ID).inDaylightTime(time)) { future_zuhr_jamaat_time = "12:15"; } else { future_zuhr_jamaat_time = "13:15"; } en_notification_Msg = en_notification_Msg + "Duhr & Friday: " + future_zuhr_jamaat_time + " "; ar_notification_Msg = ar_notification_Msg + " : " + future_zuhr_jamaat_time + " "; } if (asr_jamma_time_change) { String future_asr_jamaat_time_mod = DATE_FORMAT.format(future_asr_jamaat_time); // Date future_fajr_jamaat_time_mod = new SimpleDateFormat("HH:mm").parse("Fajr time: " + future_fajr_jamaat_time); en_notification_Msg = en_notification_Msg + "Asr: " + future_asr_jamaat_time_mod + " "; ar_notification_Msg = ar_notification_Msg + ": " + future_asr_jamaat_time_mod + " "; asr_jamma_time_change = false; } if (maghrib_jamma_time_change) { String future_maghrib_jamaat_time_mod = DATE_FORMAT.format(future_maghrib_jamaat_time); // Date future_maghrib_jamaat_time_mod = new SimpleDateFormat("HH:mm").parse("Fajr time: " + future_maghrib_jamaat_time); en_notification_Msg = en_notification_Msg + "Maghrib: " + future_maghrib_jamaat_time_mod; ar_notification_Msg = ar_notification_Msg + ": " + future_maghrib_jamaat_time_mod; maghrib_jamma_time_change = false; } if (isha_jamma_time_change) { String future_isha_jamaat_time_mod = DATE_FORMAT.format(future_isha_jamaat_time); // Date future_fajr_jamaat_time_mod = new SimpleDateFormat("HH:mm").parse("Fajr time: " + future_fajr_jamaat_time); en_notification_Msg = en_notification_Msg + "Isha: " + future_isha_jamaat_time_mod; ar_notification_Msg = ar_notification_Msg + ": " + future_isha_jamaat_time_mod; isha_jamma_time_change = false; } try { c = DBConnect.connect(); Statement st = (Statement) c.createStatement(); st.executeUpdate("UPDATE prayertime.notification SET en_message_String='" + en_notification_Msg + "' ORDER BY id DESC LIMIT 1"); st.executeUpdate("UPDATE prayertime.notification SET ar_message_String= '" + ar_notification_Msg + "' ORDER BY id DESC LIMIT 1"); c.close(); ar_notification_Msg_Lines = ar_notification_Msg.split("\\r?\\n"); en_notification_Msg_Lines = en_notification_Msg.split("\\r?\\n"); } catch (Exception e) { logger.warn("Unexpected error", e); } notification = false; athan_Change_Label_visible = true; getFacebook = false; notification_Msg = ar_notification_Msg_Lines[0] + "\n" + ar_notification_Msg_Lines[1] + "\n\n" + en_notification_Msg_Lines[0] + "\n" + en_notification_Msg_Lines[1]; System.out.println(notification_Msg); // Twitter twitter = TwitterFactory.getSingleton(); // Status status = null; // try {status = twitter.updateStatus(notification_Msg);} // catch (TwitterException ex) {logger.warn("Unexpected error", e);} // System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.out.println("Notification Sent to Facebook"); if (facebook_notification_enable) { try { //String pageID = page_ID +"/feed?; String pageID = "me/feed"; facebookClient.publish(pageID, FacebookType.class, Parameter.with("message", notification_Msg)); } catch (Exception e) { logger.warn("Unexpected error", e); } } try { p.sendMessage(en_notification_Msg); } catch (Exception e) { { logger.warn("Unexpected error", e); } } } if (isStarting) { isStarting = false; } // Get Facebook Latest Post ================================================================================= if (getFacebook && facebook_Receive && internet_able) { getFacebook = false; facebook_Text_Post = false; facebook_Picture_Post = false; facebook_post = ""; // facebook_Post_Url = ""; facebook_Fan_Count = ""; Calendar facebook_created_time_calendar = null; Calendar facebook_photo_created_time_calendar = null; Calendar facebook_check_post_date = Calendar.getInstance(); facebook_check_post_date.add(Calendar.DAY_OF_MONTH, -6); long facebook_check_post_Unix_Time = facebook_check_post_date.getTimeInMillis() / 1000; // out.println(facebook_check_post_Unix_Time); String query = "SELECT message,timeline_visibility, created_time FROM stream WHERE source_id = " + page_ID + " AND message AND strlen(attachment.fb_object_type) < 1 AND type != 56 AND type = 46 AND strpos(message, \"prayer time(s)\") < 0 AND strpos(message, \"White days\") < 0 AND strpos(message, \"Hadith of the Day:\") < 0 AND created_time > " + facebook_check_post_Unix_Time + " LIMIT 1"; // String query = "{\"messages\":\"SELECT message,timeline_visibility, created_time FROM stream WHERE source_id = " + page_ID + " AND message AND strlen(attachment.fb_object_type) < 1 AND type != 56 AND type = 46 AND strpos(message, \'prayer time(s)\') < 0 AND strpos(message, \'White days\') < 0 AND strpos(message, \'Hadith of the Day:\') < 0 AND created_time > " + facebook_check_post_Unix_Time + " LIMIT 1\" , \"count\": \"SELECT fan_count FROM page WHERE page_id = " + page_ID + "\"}"; // out.println(query); try { List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class); if (!queryResults.isEmpty()) { JsonObject facebookPost_J = queryResults.get(0); facebook_post = facebookPost_J.getString("message"); // facebook_post = "Asalamualaikum,\n" + "We have been given a large printer/copier for administration at Daar Ibn\n Abbas. Is there any brothers available to pick it up from Lakemba? "; String[] lines = facebook_post.split("\r\n|\r|\n"); if (null != facebook_post && !"".equals(facebook_post)) { if (facebook_post.contains("\n\n")) { out.println("'/n/n' detected"); facebook_post = facebook_post.replace("\n\n", "\n"); out.println(facebook_post); } facebook_created_time_calendar = Calendar .getInstance(TimeZone.getTimeZone(timeZone_ID)); facebook_created_time_calendar .setTimeInMillis(queryResults.get(0).getLong("created_time") * 1000); // out.print("Comment posted on:"); out.println(facebook_created_time_calendar.getTime()); if (facebook_post.contains("tonight") || facebook_post.contains("today") && Days .daysBetween(new DateMidnight(DateTime_now), new DateMidnight(facebook_created_time_calendar)) .getDays() != 0) { out.println( "Facebook post contains either the word 'today' or 'tonight' and has not been posted today"); facebook_post = ""; facebook_Label_visible = false; } else if (facebook_post.length() > 390 || lines.length > 6) { System.out.println("Facebook post is too large, it will not be posted"); System.out.println("Facebook lines: " + lines.length); System.out.println("Facebook string length: " + facebook_post.length()); facebook_post = ""; facebook_Label_visible = false; } else { facebook_Text_Post = true; facebook_Label_visible = true; facebook_Label_visible_set_once = true; } } } else { out.println("Facebook post is empty"); } } catch (FacebookException e) { logger.warn("Unexpected error", e); } catch (Exception e) { logger.warn("Unexpected error", e); } query = "SELECT fan_count FROM page WHERE page_id = " + page_ID; try { List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class); facebook_Fan_Count = queryResults.get(0).getString("fan_count"); out.println("Page Likes: " + facebook_Fan_Count); } catch (FacebookException e) { logger.warn("Unexpected error", e); } catch (Exception e) { logger.warn("Unexpected error", e); } query = "SELECT attachment.media.photo.images.src, created_time FROM stream WHERE source_id = " + page_ID + " AND type = 247 AND created_time > " + facebook_check_post_Unix_Time + " LIMIT 1"; try { List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class); if (!queryResults.isEmpty()) { if (null != facebook_Post_Url && !"".equals(facebook_Post_Url)) { old_facebook_Post_Url = new String(facebook_Post_Url); } // out.println(old_facebook_Post_Url); try { facebook_Post_Url = queryResults.get(0).getJsonObject("attachment") .getJsonArray("media").getJsonObject(0).getJsonObject("photo") .getJsonArray("images").getJsonObject(1).getString("src"); } catch (Exception e) { logger.warn("facebook post url exception", e); } out.println(facebook_Post_Url); facebook_photo_created_time_calendar = Calendar .getInstance(TimeZone.getTimeZone(timeZone_ID)); facebook_photo_created_time_calendar .setTimeInMillis(queryResults.get(0).getLong("created_time") * 1000); out.print("Comment posted on:"); out.println(facebook_photo_created_time_calendar.getTime()); if (null != facebook_Post_Url && !"".equals(facebook_Post_Url)) { if (null != old_facebook_Post_Url && !"".equals(old_facebook_Post_Url)) { if (facebook_Post_Url.equals(old_facebook_Post_Url)) { out.print( "Facebook photo post has not changed from previous fetch, nothing has been set"); } if (!facebook_Post_Url.equals(old_facebook_Post_Url)) { facebook_Picture_Post = true; facebook_Label_visible = true; facebook_Label_visible_set_once = true; } } else { facebook_Picture_Post = true; facebook_Label_visible = true; facebook_Label_visible_set_once = true; } } } } catch (FacebookException e) { logger.warn("Unexpected error", e); } catch (Exception e) { logger.warn("Unexpected error", e); } //compare text and picture post dates, if facebook_Picture_Post && facebook_Text_Post are true, and dates are not null // which ever was posted last, clear facebook_post = ""; or facebook_Post_Url = ""; if (facebook_Picture_Post && facebook_Text_Post) { if (facebook_photo_created_time_calendar.before(facebook_created_time_calendar)) { facebook_Post_Url = ""; } else { facebook_post = ""; } } } // Get Daily Hadith ================================================================================= if (getHadith) { getHadith = false; try { c = DBConnect.connect(); if (dtIslamic.getMonthOfYear() == 9 && dtIslamic.getDayOfMonth() < 19) { SQL = "select hadith, translated_hadith from hadith WHERE topic = 'fasting' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } // if (dtIslamic.getMonthOfYear()==9){SQL ="select hadith, translated_hadith from hadith WHERE ID = 2872";} else if (dtIslamic.getMonthOfYear() == 9 && dtIslamic.getDayOfMonth() > 19) { SQL = "select hadith, translated_hadith from hadith WHERE topic = 'Virtues of the Night of Qadr' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } else if (dtIslamic.getMonthOfYear() == 9 && dtIslamic.getDayOfMonth() > 28) { SQL = "select hadith, translated_hadith from hadith WHERE translated_hadith LIKE '%fitr %' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } else if (dtIslamic.getMonthOfYear() == 10 && dtIslamic.getDayOfMonth() == 1) { SQL = "select hadith, translated_hadith from hadith WHERE translated_hadith LIKE '%fitr %' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } //SELECT * FROM hadith WHERE translated_hadith LIKE '%fitr %' else if (dtIslamic.getMonthOfYear() == 12 && dtIslamic.getDayOfMonth() < 13) { SQL = "select hadith, translated_hadith from hadith WHERE topic = 'Hajj (Pilgrimage)' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } else if (dayofweek_int == 6) { SQL = "select hadith, translated_hadith from hadith WHERE day = '5' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } else if (dtIslamic.getMonthOfYear() == 1 && dtIslamic.getDayOfMonth() > 7 && dtIslamic.getDayOfMonth() < 12) { SQL = "select hadith, translated_hadith from hadith WHERE (translated_hadith LIKE '%Ashura%') and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } else { SQL = "select * from hadith WHERE day = '0' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; // SQL = "select * from hadith where length(translated_hadith)>527"; // the bigest Hadith } rs = c.createStatement().executeQuery(SQL); while (rs.next()) { hadith = rs.getString("hadith"); translated_hadith = rs.getString("translated_hadith"); } c.close(); System.out.println("arabic hadith length" + hadith.length()); System.out.println(" english hadith length" + translated_hadith.length()); // 528 length should be the max allowed for the hadith in english, generally arabic hadith is smaller than english translation facebook_hadith = "Hadith of the Day:\n\n" + hadith + "\n\n" + translated_hadith; // check if a notification has already been sent, to avoid flooding users with notifications, i.e during system restarts c = DBConnect.connect(); SQL = "Select * from facebook_hadith_notification where id = (select max(id) from facebook_hadith_notification)"; rs = c.createStatement().executeQuery(SQL); while (rs.next()) { id = rs.getInt("id"); hadith_notification_Date = rs.getDate("notification_date"); } c.close(); hadith_notification_Date_cal = Calendar.getInstance(); hadith_notification_Date_cal.setTime(hadith_notification_Date); hadith_notification_Date_cal.set(Calendar.MILLISECOND, 0); hadith_notification_Date_cal.set(Calendar.SECOND, 0); // System.out.println(hadith_notification_Date_cal.getTime()); System.out.println(Calendar_now.getTime()); if (Calendar_now.compareTo(hadith_notification_Date_cal) == 0) { System.out.println("hadith has already been posted today to Facebook"); } if (Calendar_now.compareTo(hadith_notification_Date_cal) != 0) { try { if (facebook_notification_enable) { try { String pageID = "me/feed"; facebookClient.publish(pageID, FacebookType.class, Parameter.with("message", facebook_hadith)); // DefaultFacebookClient fbClient; // fbClient = new DefaultFacebookClient(pageAccessToken); // fbClient.publish("me/feed", FacebookType.class, Parameter.with("message", "Aloha! ;)")); c = DBConnect.connect(); PreparedStatement ps = c.prepareStatement( "INSERT INTO prayertime.facebook_hadith_notification (notification_date) VALUE (?)"); java.sql.Timestamp mysqldate = new java.sql.Timestamp( new java.util.Date().getTime()); ps.setTimestamp(1, mysqldate); ps.executeUpdate(); c.close(); System.out.println("hadith posted to Facebook: \n" + facebook_hadith); } catch (FacebookException e) { logger.warn("Unexpected error", e); } } } catch (FacebookException e) { logger.warn("Unexpected error", e); } catch (Exception e) { logger.warn("Unexpected error", e); } } } catch (Exception e) { logger.warn("Unexpected error", e); } } } catch (SQLException e) { System.out.println("Error on Database connection"); logger.warn("Unexpected error", e); } catch (ParseException e) { logger.warn("Unexpected error", e); } catch (Exception e) { logger.warn("Unexpected error", e); } } }, 0, 3600000); // }, 0, 120000); // Timer to traslate labels from arabic to english on the screen==================================================== // translate_lastTimerCall = System.nanoTime(); translate_timer = new AnimationTimer() { @Override public void handle(long now) { if (now > translate_lastTimerCall + 40000_000_000l) { try { update_labels(); } catch (Exception e) { logger.warn("Unexpected error", e); } translate_lastTimerCall = now; } } }; // Timer to update clock==================================================== // translate_lastTimerCall = System.nanoTime(); clock_update_timer = new AnimationTimer() { @Override public void handle(long now) { if (now > clock_update_lastTimerCall + 1000_000_000l) { try { play_athan(); } catch (Exception e) { logger.warn("Unexpected error", e); } clock_update_lastTimerCall = now; } } }; hour_Label.textProperty().bind(hour); minute_Label.textProperty().bind(minute); second_Label.textProperty().bind(second); date_Label.textProperty().bind(date); Timeline clock = new Timeline(new KeyFrame(Duration.seconds(0), evt -> { LocalTime now = LocalTime.now(); hour.set(new SimpleDateFormat("h").format(new Date())); minute.set(String.format("%02d", now.getMinute())); second.set(String.format("%d", now.getSecond())); date.set(new SimpleDateFormat("EEEE, d MMMM").format(Calendar_now.getTime())); }), new KeyFrame(Duration.seconds(1))); clock.setCycleCount(Animation.INDEFINITE); clock.play(); // Timer to change friday prayer label==================================================== // translate_lastTimerCall = System.nanoTime(); // friday_update_timer = new AnimationTimer() { // @Override public void handle(long now) { // if (now > friday_update_lastTimerCall + 1500_000_000l) // { // try {update_friday_label();} // catch (Exception e) {logger.warn("Unexpected error", e);} // friday_update_lastTimerCall = now; // } // } // }; // PIR sensor thread to turn on/Off TV screen to save energy =============================================================== new Thread(() -> { // try { // Thread.sleep(1000); // } catch (InterruptedException ex) { // java.util.logging.Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, ex); // } final GpioController gpioSensor = GpioFactory.getInstance(); sensor_lastTimerCall = System.nanoTime(); final GpioPinDigitalInput sensor = gpioSensor.provisionDigitalInputPin(RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN); sensor.addListener(new GpioPinListenerDigital() { @Override public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) { if (event.getState().isHigh()) { sensor_lastTimerCall = System.nanoTime(); if (!hdmiOn && !pir_disactive_startup) { if (!prayer_In_Progress) { ProcessBuilder processBuilder1 = new ProcessBuilder("bash", "-c", "echo \"as\" | cec-client -d 1 -s \"standby 0\" RPI"); hdmiOn = true; startup = false; System.out.println("Tv turned on"); try { Thread.sleep(2500); processBuilder1.start(); Thread.sleep(2500); processBuilder1.start(); } catch (IOException e) { logger.warn("Unexpected error", e); } catch (InterruptedException ex) { java.util.logging.Logger.getLogger(JavaFXApplication4.class.getName()) .log(Level.SEVERE, null, ex); } } if (prayer_In_Progress) { Calendar cal = Calendar.getInstance(); int hour_Now_int = cal.get(Calendar.HOUR_OF_DAY); int hourbefore_fajr_int = fajr_cal.get(Calendar.HOUR_OF_DAY) - 1; hourbefore_fajr_int = hourbefore_fajr_int - 1; // System.out.println("hour now is" + hour_Now_int); // System.out.println("fajr hour -1 hour is" + hourbefore_fajr_int); if (hour_Now_int >= 0 && hour_Now_int <= hourbefore_fajr_int) { System.out.println("prayer detected in after hours"); if (System.nanoTime() > proximity_lastTimerCall + delay_turnOnTV_after_Prayers_nightmode) { // System.out.println(proximity_lastTimerCall + delay_turnOnTV_after_Prayers_nightmode); // System.out.println(System.nanoTime()); ProcessBuilder processBuilder1 = new ProcessBuilder("bash", "-c", "echo \"as\" | cec-client -d 1 -s \"standby 0\" RPI"); hdmiOn = true; prayer_In_Progress = false; System.out.println("Tv turned on"); try { Thread.sleep(2500); processBuilder1.start(); Thread.sleep(2500); processBuilder1.start(); } catch (IOException e) { logger.warn("Unexpected error", e); } catch (InterruptedException ex) { java.util.logging.Logger.getLogger(JavaFXApplication4.class.getName()) .log(Level.SEVERE, null, ex); } } } else { System.out.println("prayer detected during normal hours"); if (fajr_prayer_In_Progress_notification && cal.after(fajr_jamaat_cal) && cal.before(fajr_jamaat_update_cal)) { fajr_prayer_In_Progress_notification = false; Pushover p = new Pushover("WHq3q48zEFpTqU47Wxygr3VMqoodxc", "skhELgtWRXslAUrYx9yp1s0Os89JTF"); try { p.sendMessage("Fajr Jamaa at Daar Ibn Abass has just started"); System.out.println("Prayer in progress notification sent"); } catch (IOException e) { e.printStackTrace(); } send_Broadcast_msg = true; broadcast_msg = "Fajr Jamaa at Daar Ibn Abass has just started"; } if (zuhr_prayer_In_Progress_notification && cal.after(zuhr_jamaat_cal) && cal.before(zuhr_plus15_cal)) { zuhr_prayer_In_Progress_notification = false; Pushover p = new Pushover("WHq3q48zEFpTqU47Wxygr3VMqoodxc", "skhELgtWRXslAUrYx9yp1s0Os89JTF"); try { p.sendMessage("Zuhr Jamaa at Daar Ibn Abass has just started"); System.out.println("Prayer in progress notification sent"); } catch (IOException e) { e.printStackTrace(); } send_Broadcast_msg = true; broadcast_msg = "Zuhr Jamaa at Daar Ibn Abass has just started"; } if (asr_prayer_In_Progress_notification && cal.after(asr_jamaat_cal) && cal.before(asr_jamaat_update_cal)) { asr_prayer_In_Progress_notification = false; Pushover p = new Pushover("WHq3q48zEFpTqU47Wxygr3VMqoodxc", "skhELgtWRXslAUrYx9yp1s0Os89JTF"); try { p.sendMessage("Asr Jamaa at Daar Ibn Abass has just started"); System.out.println("Prayer in progress notification sent"); } catch (IOException e) { e.printStackTrace(); } send_Broadcast_msg = true; broadcast_msg = "Asr Jamaa at Daar Ibn Abass has just started"; } if (maghrib_prayer_In_Progress_notification && cal.after(maghrib_cal) && cal.before(maghrib_plus15_cal)) { maghrib_prayer_In_Progress_notification = false; Pushover p = new Pushover("WHq3q48zEFpTqU47Wxygr3VMqoodxc", "skhELgtWRXslAUrYx9yp1s0Os89JTF"); try { p.sendMessage("Maghrib Jamaa at Daar Ibn Abass has just started"); System.out.println("Prayer in progress notification sent"); } catch (IOException e) { e.printStackTrace(); } send_Broadcast_msg = true; broadcast_msg = "Maghrib Jamaa at Daar Ibn Abass has just started"; } if (isha_prayer_In_Progress_notification && cal.after(isha_jamaat_cal) && cal.before(isha_jamaat_update_cal)) { isha_prayer_In_Progress_notification = false; Pushover p = new Pushover("WHq3q48zEFpTqU47Wxygr3VMqoodxc", "skhELgtWRXslAUrYx9yp1s0Os89JTF"); try { p.sendMessage("Isha Jamaa at Daar Ibn Abass has just started"); System.out.println("Prayer in progress notification sent"); } catch (IOException e) { e.printStackTrace(); } send_Broadcast_msg = true; broadcast_msg = "Isha Jamaa at Daar Ibn Abass has just started"; } if (System.nanoTime() > proximity_lastTimerCall + delay_turnOnTV_after_Prayers) { // System.out.println(proximity_lastTimerCall + delay_turnOnTV_after_Prayers); // System.out.println(System.nanoTime()); ProcessBuilder processBuilder1 = new ProcessBuilder("bash", "-c", "echo \"as\" | cec-client -d 1 -s \"standby 0\" RPI"); hdmiOn = true; prayer_In_Progress = false; System.out.println("Tv turned on"); try { Thread.sleep(2500); processBuilder1.start(); Thread.sleep(2500); processBuilder1.start(); } catch (IOException e) { logger.warn("Unexpected error", e); } catch (InterruptedException ex) { java.util.logging.Logger.getLogger(JavaFXApplication4.class.getName()) .log(Level.SEVERE, null, ex); } } if (send_Broadcast_msg) { try { send_Broadcast_msg = false; socket1 = new DatagramSocket(null); socket1.setBroadcast(true); buf1 = broadcast_msg.getBytes(); group = InetAddress.getByName("255.255.255.255"); packet1 = new DatagramPacket(buf1, buf1.length, group, 8888); socket1.send(packet1); } catch (Exception e) { logger.warn("Unexpected error", e); } } } } } } if (event.getState().isLow()) { sensorLow = true; } } }); System.out.println(" ... Motion Detection Starting....."); for (;;) { try { if (System.nanoTime() > sensor_lastTimerCall + delay_turnOffTV_after_inactivity && sensorLow && hdmiOn || startup) { startup = false; System.out.println("All is quiet..."); ProcessBuilder processBuilder2 = new ProcessBuilder("bash", "-c", "echo \"standby 0000\" | cec-client -d 1 -s \"standby 0\" RPI"); hdmiOn = false; try { Process process2 = processBuilder2.start(); } catch (IOException e) { logger.warn("Unexpected error", e); } sensor_lastTimerCall = System.nanoTime(); sensorLow = false; } Thread.sleep(1000); } catch (InterruptedException e) { gpioSensor.shutdown(); Thread.currentThread().interrupt(); } } }).start(); // //Infrared sensor thread to turn on/Off TV screen when Prayer starts =============================================================== new Thread(() -> { System.out.println(" ... Prayer Detection Starting....."); for (;;) { try { DatagramSocket socket = new DatagramSocket(8888, InetAddress.getByName("0.0.0.0")); socket.setBroadcast(true); byte[] buf = new byte[512]; DatagramPacket packet = new DatagramPacket(buf, buf.length); while (true) { socket.receive(packet); String received = new String(packet.getData(), 0, packet.getLength()); System.out.println("UDP Packet received: " + received); proximity_lastTimerCall = System.nanoTime(); if (received.equals("Prayer in progress") && pir_sensor) { ProcessBuilder processBuilder2 = new ProcessBuilder("bash", "-c", "echo \"standby 0000\" | cec-client -d 1 -s \"standby 0\" RPI"); try { if (hdmiOn) { Process process2 = processBuilder2.start(); System.out.println("Prayer in Progress...Turning Off TV(s)"); Thread.sleep(1000); hdmiOn = false; prayer_In_Progress = true; proximity_lastTimerCall = System.nanoTime(); } } catch (IOException e) { logger.warn("Unexpected error", e); } } else if (received.equals("refresh background")) { try { System.out.println("Changing Background..."); images = new ArrayList<String>(); //change on osx if (platform.equals("osx")) // {directory = new File("/Users/ossama/Projects/Pi/javafx/prayertime/background/");} { directory = new File( "/Users/ossama/Dropbox/Projects/Pi/javafx/prayertime/background"); } // {directory = new File("/Users/samia/NetBeansProjects/prayertime_files/background/");} //change on Pi if (platform.equals("pi")) { directory = new File("/home/pi/prayertime/Images/"); } files = directory.listFiles(); for (File f : files) { images.add(f.getName()); } System.out.println(images); countImages = images.size(); imageNumber = (int) (Math.random() * countImages); rand_Image_Path = directory + "/" + images.get(imageNumber); System.out.println(rand_Image_Path); String image = new File(rand_Image_Path).toURI().toURL().toString(); Platform.runLater(new Runnable() { @Override public void run() { Mainpane.setStyle("-fx-background-image: url('" + image + "'); -fx-background-image-repeat: repeat; -fx-background-size: 1080 1920;-fx-background-position: bottom left;"); } }); } catch (IOException e) { logger.warn("Unexpected error", e); } } else if (received.equals("refresh hadith")) { System.out.println("Getting Hadith..."); try { c = DBConnect.connect(); if (dtIslamic.getMonthOfYear() == 9) { SQL = "select hadith, translated_hadith from hadith WHERE topic = 'fasting' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } // if (dtIslamic.getMonthOfYear()==9){SQL ="select hadith, translated_hadith from hadith WHERE ID = 2872";} else if (dtIslamic.getMonthOfYear() == 12) { SQL = "select hadith, translated_hadith from hadith WHERE topic = 'Hajj (Pilgrimage)' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } else if (dayofweek_int == 5 || dayofweek_int == 6) { SQL = "select hadith, translated_hadith from hadith WHERE day = '5' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; } else { SQL = "select * from hadith WHERE day = '0' and length(translated_hadith)<" + max_en_hadith_len + " and length(hadith)<" + max_ar_hadith_len + " ORDER BY RAND( ) LIMIT 1"; // SQL = "select * from hadith where length(translated_hadith)>527"; // the bigest Hadith } rs = c.createStatement().executeQuery(SQL); while (rs.next()) { hadith = rs.getString("hadith"); translated_hadith = rs.getString("translated_hadith"); } c.close(); System.out.println("arabic hadith length" + hadith.length()); System.out.println(" english hadith length" + translated_hadith.length()); } catch (Exception e) { logger.warn("Unexpected error", e); } } if (received.equals("prayer call")) { ProcessBuilder processBuilder_Athan = new ProcessBuilder("bash", "-c", "mpg123 /home/pi/prayertime/Audio/athan1.mp3"); try { Process process = processBuilder_Athan.start(); } catch (IOException e) { logger.warn("Unexpected error", e); } } if (received.equals("ping")) { DatagramSocket send_datagramSocket = new DatagramSocket(); InetAddress hostAddress = InetAddress.getByName("localhost"); String outString = "pong"; byte[] send_buffer = outString.getBytes(); InetAddress receiverAddress = InetAddress.getLocalHost(); DatagramPacket send_packet = new DatagramPacket(send_buffer, send_buffer.length, hostAddress, 9999); send_datagramSocket.send(packet); } if (received.equals("snapshot")) { System.out.println("saving..."); // WritableImage snapshot_prayertime_pane = prayertime_pane.getScene().snapshot(null); // WritableImage snapshot_full = scene.snapshot(null); // ImageIO.write(SwingFXUtils.fromFXImage(snapshot_full, null), "png", file); WritableImage image = new WritableImage(400, 400); scene.snapshot(image); File outputfile = new File("saved.png"); ImageIO.write((RenderedImage) image, "png", outputfile); System.out.println("saved..."); } if (received.equals("refresh facebook")) { if (facebook_Receive && internet_able) { getFacebook = false; facebook_Text_Post = false; facebook_Picture_Post = false; facebook_post = ""; // facebook_Post_Url = ""; facebook_Fan_Count = ""; Calendar facebook_created_time_calendar = null; Calendar facebook_photo_created_time_calendar = null; Calendar facebook_check_post_date = Calendar.getInstance(); facebook_check_post_date.add(Calendar.DAY_OF_MONTH, -6); long facebook_check_post_Unix_Time = facebook_check_post_date.getTimeInMillis() / 1000; // out.println(facebook_check_post_Unix_Time); String query = "SELECT message,timeline_visibility, created_time FROM stream WHERE source_id = " + page_ID + " AND message AND strlen(attachment.fb_object_type) < 1 AND type != 56 AND type = 46 AND strpos(message, \"prayer time(s)\") < 0 AND strpos(message, \"White days\") < 0 AND strpos(message, \"Hadith of the Day:\") < 0 AND created_time > " + facebook_check_post_Unix_Time + " LIMIT 1"; // String query = "{\"messages\":\"SELECT message,timeline_visibility, created_time FROM stream WHERE source_id = " + page_ID + " AND message AND strlen(attachment.fb_object_type) < 1 AND type != 56 AND type = 46 AND strpos(message, \'prayer time(s)\') < 0 AND strpos(message, \'White days\') < 0 AND strpos(message, \'Hadith of the Day:\') < 0 AND created_time > " + facebook_check_post_Unix_Time + " LIMIT 1\" , \"count\": \"SELECT fan_count FROM page WHERE page_id = " + page_ID + "\"}"; // out.println(query); try { List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class); if (!queryResults.isEmpty()) { JsonObject facebookPost_J = queryResults.get(0); facebook_post = facebookPost_J.getString("message"); // facebook_post = "Asalamualaikum,\n" + "We have been given a large printer/copier for administration at Daar Ibn\n Abbas. Is there any brothers available to pick it up from Lakemba? "; String[] lines = facebook_post.split("\r\n|\r|\n"); if (null != facebook_post && !"".equals(facebook_post)) { if (facebook_post.contains("\n\n")) { out.println("'/n/n' detected"); facebook_post = facebook_post.replace("\n\n", "\n"); out.println(facebook_post); } facebook_created_time_calendar = Calendar .getInstance(TimeZone.getTimeZone(timeZone_ID)); facebook_created_time_calendar.setTimeInMillis( queryResults.get(0).getLong("created_time") * 1000); // out.print("Comment posted on:"); out.println(facebook_created_time_calendar.getTime()); if (facebook_post.contains("tonight") || facebook_post.contains("today") && Days .daysBetween(new DateMidnight(DateTime_now), new DateMidnight( facebook_created_time_calendar)) .getDays() != 0) { out.println( "Facebook post contains either the word 'today' or 'tonight' and has not been posted today"); facebook_post = ""; facebook_Label_visible = false; } else if (facebook_post.length() > 390 || lines.length > 6) { System.out.println( "Facebook post is too large, it will not be posted"); System.out.println("Facebook lines: " + lines.length); System.out.println( "Facebook string length: " + facebook_post.length()); facebook_post = ""; facebook_Label_visible = false; } else { facebook_Text_Post = true; facebook_Label_visible = true; facebook_Label_visible_set_once = true; } } } else { out.println("Facebook post is empty"); } } catch (FacebookException e) { logger.warn("Unexpected error", e); } catch (Exception e) { logger.warn("Unexpected error", e); } query = "SELECT fan_count FROM page WHERE page_id = " + page_ID; try { List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class); facebook_Fan_Count = queryResults.get(0).getString("fan_count"); out.println("Page Likes: " + facebook_Fan_Count); } catch (FacebookException e) { logger.warn("Unexpected error", e); } catch (Exception e) { logger.warn("Unexpected error", e); } query = "SELECT attachment.media.photo.images.src, created_time FROM stream WHERE source_id = " + page_ID + " AND type = 247 AND created_time > " + facebook_check_post_Unix_Time + " LIMIT 1"; try { List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class); if (!queryResults.isEmpty()) { if (null != facebook_Post_Url && !"".equals(facebook_Post_Url)) { old_facebook_Post_Url = new String(facebook_Post_Url); } // out.println(old_facebook_Post_Url); facebook_Post_Url = queryResults.get(0).getJsonObject("attachment") .getJsonArray("media").getJsonObject(0).getJsonObject("photo") .getJsonArray("images").getJsonObject(1).getString("src"); // out.println(facebook_Post_Url); facebook_photo_created_time_calendar = Calendar .getInstance(TimeZone.getTimeZone(timeZone_ID)); facebook_photo_created_time_calendar.setTimeInMillis( queryResults.get(0).getLong("created_time") * 1000); out.print("Comment posted on:"); out.println(facebook_photo_created_time_calendar.getTime()); if (null != facebook_Post_Url && !"".equals(facebook_Post_Url)) { if (null != old_facebook_Post_Url && !"".equals(old_facebook_Post_Url)) { if (facebook_Post_Url.equals(old_facebook_Post_Url)) { out.print( "Facebook photo post has not changed from previous fetch, nothing has been set"); } if (!facebook_Post_Url.equals(old_facebook_Post_Url)) { facebook_Picture_Post = true; facebook_Label_visible = true; facebook_Label_visible_set_once = true; } } else { facebook_Picture_Post = true; facebook_Label_visible = true; facebook_Label_visible_set_once = true; } } } } catch (FacebookException e) { logger.warn("Unexpected error", e); } catch (Exception e) { logger.warn("Unexpected error", e); } //compare text and picture post dates, if facebook_Picture_Post && facebook_Text_Post are true, and dates are not null // which ever was posted last, clear facebook_post = ""; or facebook_Post_Url = ""; if (facebook_Picture_Post && facebook_Text_Post) { if (facebook_photo_created_time_calendar .before(facebook_created_time_calendar)) { facebook_Post_Url = ""; } else { facebook_post = ""; } } } } } } // catch(InterruptedException e){Thread.currentThread().interrupt();} catch (Exception e) { logger.warn("Unexpected error", e); Thread.currentThread().interrupt(); } } }).start(); }
From source file:joliex.mongodb.MongoDbConnector.java
@RequestResponse public void connect(Value request) throws FaultException { try {// w w w.j a v a2 s . co m host = request.getFirstChild("host").strValue(); port = request.getFirstChild("port").intValue(); dbname = request.getFirstChild("dbname").strValue(); timeZone = request.getFirstChild("timeZone").strValue(); password = request.getFirstChild("password").strValue(); username = request.getFirstChild("username").strValue(); log = Logger.getLogger("org.mongodb.driver"); log.setLevel(Level.OFF); if (request.hasChildren("jsonStringDebug")) { jsonDebuger = request.getFirstChild("jsonStringDebug").boolValue(); } if (request.hasChildren("logStreamDebug")) { logStream = request.getFirstChild("logStreamDebug").boolValue(); logString = "Processing Steps at " + System.currentTimeMillis(); } if (System.getProperty("os.arch").contains("64")) { is64 = true; } else { is64 = false; } zone = DateTimeZone.forID(timeZone); ServerAddress serverAddress = new ServerAddress(host, port); MongoCredential credential = MongoCredential.createCredential(username, dbname, password.toCharArray()); mongoClientOptions = MongoClientOptions.builder().build(); if (null != mongoClient) { System.out.println("recovering client"); db = mongoClient.getDatabase(dbname); } else { mongoClient = new MongoClient(serverAddress, credential, mongoClientOptions); db = mongoClient.getDatabase(dbname); } } catch (MongoException ex) { throw new FaultException("LoginConnection", ex); } }