@Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); memoDb = getActivity() .openOrCreateDatabase(DBConstant.DB_FILENAME, getActivity().MODE_PRIVATE, null); campusDb = getActivity() .openOrCreateDatabase(DBConstant.CAMPUSDBFILENAME, getActivity().MODE_PRIVATE, null); timService = TimeService.getInstance(); campusService = new CampusService(campusDb); }
public void memosRemind() { int tSize, pSize; List<Timing> timingList = timingService.getTimingByUserID(sp.getString("user", null)); List<Periodic> periodicList = periodicService.getPeriodicByUserID(sp.getString("user", null)); List<Campus> campusList = campusService.getAllCampus(); if (timingList != null) { Collections.sort( timingList, new Comparator<Timing>() { @Override public int compare(Timing lhs, Timing rhs) { long timingEndtime1 = timService.getSecondsFromDate(lhs.getEnd_time()); long timingEndtime2 = timService.getSecondsFromDate(rhs.getEnd_time()); if (timingEndtime1 <= timingEndtime2) { return -1; } else return 1; } }); } if (periodicList != null) { Collections.sort( periodicList, new Comparator<Periodic>() { @Override public int compare(Periodic lhs, Periodic rhs) { long periodicEndtime1 = timService.getSecondsFromDate(lhs.getEnd_time()); long periodicEndtime2 = timService.getSecondsFromDate(rhs.getEnd_time()); if (periodicEndtime1 <= periodicEndtime2) { return -1; } else return 1; } }); } if (timingList != null && periodicList != null) { tSize = timingList.size(); pSize = periodicList.size(); } else if (timingList != null && periodicList == null) { tSize = timingList.size(); pSize = 0; } else if (timingList == null && periodicList != null) { tSize = 0; pSize = periodicList.size(); } else { tSize = 0; pSize = 0; } if (0 != tSize && 0 != pSize) { for (int i = 1; i <= tSize; i++) { if (timingList.get(i - 1).getIsfinish() == 0) { if (timService.getSecondsFromDate(periodicList.get(0).getEnd_time()) > timService.getSecondsFromDate(timingList.get(i - 1).getEnd_time())) { String content = timingList.get(i - 1).getContent(); String userId = sp.getString("user", null); long endTime = timService.getSecondsFromDate(timingList.get(i - 1).getEnd_time()); Intent timingAlarm = new Intent(getActivity(), Receiver.class); Bundle bund = new Bundle(); bund.putString("class", "timing"); bund.putString("user", userId); bund.putString("content", content); bund.putString("Id", timingList.get(i - 1).getTiming_id()); if (timingList.get(i - 1).getLocation().isEmpty()) { bund.putString("location", null); } else { bund.putString("location", timingList.get(i - 1).getLocation()); } timingAlarm.putExtras(bund); PendingIntent pendingIntent = PendingIntent.getBroadcast( getActivity(), 0, timingAlarm, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager timingManager = (AlarmManager) getActivity().getSystemService(getActivity().ALARM_SERVICE); timingManager.set(AlarmManager.RTC_WAKEUP, endTime, pendingIntent); return; } else if (periodicList != null) { String content = periodicList.get(0).getContent(); String userId = sp.getString("user", null); long endTime = timService.getSecondsFromDate(periodicList.get(0).getEnd_time()); Intent timingAlarm = new Intent(getActivity(), Receiver.class); Bundle bund = new Bundle(); bund.putString("class", "periodic"); bund.putString("user", userId); bund.putString("content", content); bund.putString("Id", periodicList.get(0).getPeriodic_id()); bund.putString("location", null); timingAlarm.putExtras(bund); PendingIntent pendingIntent = PendingIntent.getBroadcast( getActivity(), 0, timingAlarm, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager timingManager = (AlarmManager) getActivity().getSystemService(getActivity().ALARM_SERVICE); timingManager.set(AlarmManager.RTC_WAKEUP, endTime, pendingIntent); return; } } else { Intent timingAlarm = new Intent(getActivity(), Receiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast( getActivity(), 0, timingAlarm, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager timingManager = (AlarmManager) getActivity().getSystemService(getActivity().ALARM_SERVICE); timingManager.cancel(pendingIntent); } } } else if (0 != pSize) { String content = periodicList.get(0).getContent(); String userId = sp.getString("user", null); long endTime = timService.getSecondsFromDate(periodicList.get(0).getEnd_time()); Intent timingAlarm = new Intent(getActivity(), Receiver.class); Bundle bund = new Bundle(); bund.putString("user", userId); bund.putString("class", "periodic"); bund.putString("content", content); bund.putString("Id", periodicList.get(0).getPeriodic_id()); timingAlarm.putExtras(bund); PendingIntent pendingIntent = PendingIntent.getBroadcast( getActivity(), 0, timingAlarm, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager timingManager = (AlarmManager) getActivity().getSystemService(getActivity().ALARM_SERVICE); timingManager.set(AlarmManager.RTC_WAKEUP, endTime, pendingIntent); return; } else if (0 != tSize) { for (int i = 0; i < tSize; i++) { if (timingList.get(i).getIsfinish() == 0) { String content = timingList.get(i).getContent(); String userId = sp.getString("user", null); long endTime = timService.getSecondsFromDate(timingList.get(i).getEnd_time()); Intent timingAlarm = new Intent(getActivity(), Receiver.class); Bundle bund = new Bundle(); bund.putString("class", "timing"); bund.putString("user", userId); bund.putString("content", content); bund.putString("Id", timingList.get(i).getTiming_id()); if (timingList.get(i).getLocation().isEmpty()) { bund.putString("location", null); } else { bund.putString("location", timingList.get(i).getLocation()); } timingAlarm.putExtras(bund); PendingIntent pendingIntent = PendingIntent.getBroadcast( getActivity(), 0, timingAlarm, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager timingManager = (AlarmManager) getActivity().getSystemService(getActivity().ALARM_SERVICE); timingManager.set(AlarmManager.RTC_WAKEUP, endTime, pendingIntent); return; } } } }