List of usage examples for com.google.gwt.jsonp.client JsonpRequestBuilder requestObject
public <T extends JavaScriptObject> JsonpRequest<T> requestObject(String url, AsyncCallback<T> callback)
From source file:gov.wa.wsdot.apps.analytics.client.activities.twitter.view.tweets.TweetsView.java
License:Open Source License
/** * Updates the list of tweets through a jsonp request. * * @param startDate/*from w w w .ja v a2 s . c o m*/ * @param endDate * @param account : The account, can be "All" for all accounts */ public static void updateTweets(String startDate, String endDate, String account) { tweetsList.clear(); moreTweetsBtn.setVisible(false); DateTimeFormat fmt = DateTimeFormat.getFormat("/yyyy/M/d"); String screenName = account; String url = Consts.HOST_URL + "/summary/mentions/" + screenName + startDate + endDate + "/"; currentUrl = url; tweetsLoader.setVisible(true); JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(url + pageNum, new AsyncCallback<Mention>() { @Override public void onFailure(Throwable caught) { Window.alert("Failure: " + caught.getMessage()); tweetsLoader.setVisible(false); } @Override public void onSuccess(Mention mention) { if (mention.getMentions() != null) { updateTweetsList(mention.getMentions()); tweetsLoader.setVisible(false); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.amtrakcascades.schedules.details.AmtrakCascadesSchedulesDetailsActivity.java
License:Open Source License
/** * Get train schedules for those with a departing and arriving station. * //from w ww. j av a 2 s . co m * @param url URL of the Web services API * @param toLocation arriving station name * @param fromLocation departing station name */ private void getDepartingArrivingTrains(String url, final String fromLocation, final String toLocation) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.setTimeout(30000); // Set timeout for 30 seconds jsonp.requestObject(url, new AsyncCallback<AmtrakCascadesScheduleFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); } @Override public void onSuccess(AmtrakCascadesScheduleFeed result) { if (result.getSchedule() != null) { serviceItems.clear(); AmtrakCascadesScheduleItem scheduleItem; int numItems = result.getSchedule().length(); int i = 0; int startingTripNumber = 0; int currentTripNumber = 0; while (i < numItems) { // Loop through all trains Date scheduledDepartureTime = null; locationItems = new ArrayList<Map<String, AmtrakCascadesScheduleItem>>(); stationItems = new HashMap<String, AmtrakCascadesScheduleItem>(); startingTripNumber = result.getSchedule().get(i).getTripNumber(); currentTripNumber = startingTripNumber; List<String> trainNameList = new ArrayList<String>(); int tripCounter = 0; while (currentTripNumber == startingTripNumber && i < numItems) { // Trains are grouped by two or more scheduleItem = new AmtrakCascadesScheduleItem(); if (result.getSchedule().get(i).getArrivalComment() != null) { scheduleItem.setArrivalComment(result.getSchedule().get(i).getArrivalComment()); } if (result.getSchedule().get(i).getArrivalScheduleType() != null) { scheduleItem.setArrivalScheduleType( result.getSchedule().get(i).getArrivalScheduleType()); } if (result.getSchedule().get(i).getArrivalTime() != null) { scheduleItem.setArrivalTime( result.getSchedule().get(i).getArrivalTime().toString().substring(6, 19)); } if (result.getSchedule().get(i).getDepartureComment() != null) { scheduleItem.setDepartureComment(result.getSchedule().get(i).getDepartureComment()); } if (result.getSchedule().get(i).getDepartureScheduleType() != null) { scheduleItem.setDepartureScheduleType( result.getSchedule().get(i).getDepartureScheduleType()); } if (result.getSchedule().get(i).getDepartureTime() != null) { scheduleItem.setDepartureTime( result.getSchedule().get(i).getDepartureTime().toString().substring(6, 19)); } if (result.getSchedule().get(i).getScheduledArrivalTime() != null) { scheduleItem.setScheduledArrivalTime(result.getSchedule().get(i) .getScheduledArrivalTime().toString().substring(6, 19)); } scheduleItem.setStationName(result.getSchedule().get(i).getStationName()); if (result.getSchedule().get(i).getTrainMessage() != "") { scheduleItem.setTrainMessage(result.getSchedule().get(i).getTrainMessage()); } if (result.getSchedule().get(i).getScheduledDepartureTime() != null) { scheduleItem.setScheduledDepartureTime(result.getSchedule().get(i) .getScheduledDepartureTime().toString().substring(6, 19)); // We sort by scheduled departure time of the From station. if (fromLocation.equalsIgnoreCase(scheduleItem.getStationName())) { scheduledDepartureTime = new Date( Long.parseLong((scheduleItem.getScheduledDepartureTime()))); } } int trainNumber = result.getSchedule().get(i).getTrainNumber(); scheduleItem.setTrainNumber(trainNumber); String serviceName = trainNumberMap.get(trainNumber); if (serviceName == null) { serviceName = "Bus Service"; } scheduleItem.setSortOrder(result.getSchedule().get(i).getSortOrder()); String trainName = trainNumber + " " + serviceName; // Add the train name for ever other record. When there is one orgin and destination point // the train name will be the same. If the tripNumber is the same over more than two records // then we have multiple origin and destination points and likely different train names. // e.g. 515 Amtrak Cascades Train, 8911 Bus Service if (tripCounter % 2 == 0) { trainNameList.add(trainName); } scheduleItem.setTrainName(trainName); scheduleItem.setTripNumber(result.getSchedule().get(i).getTripNumber()); scheduleItem.setUpdateTime( result.getSchedule().get(i).getUpdateTime().toString().substring(6, 19)); stationItems.put(scheduleItem.getStationName(), scheduleItem); i++; if (i < numItems) { currentTripNumber = result.getSchedule().get(i).getTripNumber(); } tripCounter++; } if (trainNameList.size() > 1) { StringBuilder sb = new StringBuilder(); for (String s : trainNameList) { if (sb.length() > 0) sb.append(", "); sb.append(s); } stationItems.get(fromLocation).setTrainName(sb.toString()); } locationItems.add(stationItems); serviceItems.add(new AmtrakCascadesServiceItem(scheduledDepartureTime, locationItems)); } } Collections.sort(serviceItems, AmtrakCascadesServiceItem.scheduledDepartureTimeComparator); view.hideProgressIndicator(); view.setFromToLocation(fromLocation, toLocation); view.setTitle("Departing: " + amtrakStations.get(fromLocation) + " and Arriving: " + amtrakStations.get(toLocation)); view.render(serviceItems); view.refresh(); accessibility.postScreenChangeNotification(); } }); }
From source file:gov.wa.wsdot.mobile.client.activities.amtrakcascades.schedules.details.AmtrakCascadesSchedulesDetailsActivity.java
License:Open Source License
/** * Get train schedules for those with just a departing station. * // www. j a v a 2 s .com * @param url URL of the Web services API * @param toLocation arriving station name * @param fromLocation departing station name */ private void getDepartingTrains(String url, final String fromLocation, final String toLocation) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.setTimeout(30000); // Set timeout for 30 seconds jsonp.requestObject(url, new AsyncCallback<AmtrakCascadesScheduleFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); } @Override public void onSuccess(AmtrakCascadesScheduleFeed result) { if (result.getSchedule() != null) { serviceItems.clear(); AmtrakCascadesScheduleItem scheduleItem; int numItems = result.getSchedule().length(); for (int i = 0; i < numItems; i++) { // Loop through all trains Date scheduledTime = null; locationItems = new ArrayList<Map<String, AmtrakCascadesScheduleItem>>(); stationItems = new HashMap<String, AmtrakCascadesScheduleItem>(); scheduleItem = new AmtrakCascadesScheduleItem(); if (result.getSchedule().get(i).getArrivalComment() != null) { scheduleItem.setArrivalComment(result.getSchedule().get(i).getArrivalComment()); } if (result.getSchedule().get(i).getArrivalScheduleType() != null) { scheduleItem .setArrivalScheduleType(result.getSchedule().get(i).getArrivalScheduleType()); } if (result.getSchedule().get(i).getArrivalTime() != null) { scheduleItem.setArrivalTime( result.getSchedule().get(i).getArrivalTime().toString().substring(6, 19)); } if (result.getSchedule().get(i).getDepartureComment() != null) { scheduleItem.setDepartureComment(result.getSchedule().get(i).getDepartureComment()); } if (result.getSchedule().get(i).getDepartureScheduleType() != null) { scheduleItem.setDepartureScheduleType( result.getSchedule().get(i).getDepartureScheduleType()); } if (result.getSchedule().get(i).getDepartureTime() != null) { scheduleItem.setDepartureTime( result.getSchedule().get(i).getDepartureTime().toString().substring(6, 19)); } scheduleItem.setStationName(result.getSchedule().get(i).getStationName()); if (result.getSchedule().get(i).getTrainMessage() != "") { scheduleItem.setTrainMessage(result.getSchedule().get(i).getTrainMessage()); } if (result.getSchedule().get(i).getScheduledArrivalTime() != null) { scheduleItem.setScheduledArrivalTime(result.getSchedule().get(i) .getScheduledArrivalTime().toString().substring(6, 19)); if (fromLocation.equalsIgnoreCase(scheduleItem.getStationName())) { scheduledTime = new Date(Long.parseLong((scheduleItem.getScheduledArrivalTime()))); } } if (result.getSchedule().get(i).getScheduledDepartureTime() != null) { scheduleItem.setScheduledDepartureTime(result.getSchedule().get(i) .getScheduledDepartureTime().toString().substring(6, 19)); // We sort by scheduled departure time of the From station. if (fromLocation.equalsIgnoreCase(scheduleItem.getStationName())) { scheduledTime = new Date( Long.parseLong((scheduleItem.getScheduledDepartureTime()))); } } int trainNumber = result.getSchedule().get(i).getTrainNumber(); scheduleItem.setTrainNumber(trainNumber); String serviceName = trainNumberMap.get(trainNumber); if (serviceName == null) { serviceName = "Bus Service"; } scheduleItem.setTrainName(trainNumber + " " + serviceName); scheduleItem.setTripNumber(result.getSchedule().get(i).getTripNumber()); scheduleItem.setUpdateTime( result.getSchedule().get(i).getUpdateTime().toString().substring(6, 19)); stationItems.put(scheduleItem.getStationName(), scheduleItem); locationItems.add(stationItems); serviceItems.add(new AmtrakCascadesServiceItem(scheduledTime, locationItems)); } } Collections.sort(serviceItems, AmtrakCascadesServiceItem.scheduledDepartureTimeComparator); view.hideProgressIndicator(); String location = fromLocation; view.setFromToLocation(fromLocation, location); view.setTitle(amtrakStations.get(fromLocation)); view.render(serviceItems); view.refresh(); } }); }
From source file:gov.wa.wsdot.mobile.client.activities.borderwait.BorderWaitActivity.java
License:Open Source License
private void createBorderWaitList(final BorderWaitView view) { /** /* ww w. j a va2 s.com*/ * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.BORDER_WAIT, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * 60000)); // Refresh every 15 minutes. } view.showProgressIndicator(); if (shouldUpdate) { /** * Check the travel border wait table for any starred entries. If we find some, * save them to a list so we can re-star those after we flush the database. */ dbService.getStarredBorderWaits(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { starred.clear(); if (!result.isEmpty()) { for (GenericRow row : result) { starred.add(row.getInt(BorderWaitColumns.BORDER_WAIT_ID)); } } JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(BORDER_WAIT_URL, new AsyncCallback<BorderCrossings>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); phoneGap.getNotification().alert("Can't load data. Check your connection.", new AlertCallback() { @Override public void onOkButtonClicked() { // TODO Auto-generated method stub } }, "Connection Error"); } @Override public void onSuccess(BorderCrossings result) { if (result.getWaitTimes() != null) { borderWaitItems.clear(); BorderWaitItem item; int numItems = result.getWaitTimes().getItems().length(); for (int i = 0; i < numItems; i++) { item = new BorderWaitItem(); item.setId(result.getWaitTimes().getItems().get(i).getId()); item.setTitle(result.getWaitTimes().getItems().get(i).getName()); item.setUpdated(result.getWaitTimes().getItems().get(i).getUpdated()); item.setLane(result.getWaitTimes().getItems().get(i).getLane()); item.setRoute(result.getWaitTimes().getItems().get(i).getRoute()); item.setDirection( result.getWaitTimes().getItems().get(i).getDirection()); item.setWait(result.getWaitTimes().getItems().get(i).getWait()); if (starred.contains(result.getWaitTimes().getItems().get(i).getId())) { item.setIsStarred(1); } borderWaitItems.add(item); } // Purge existing border wait times covered by incoming data dbService.deleteBorderWaits(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new border wait times dbService.insertBorderWaits(borderWaitItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update ArrayList<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add(new CacheItem(Tables.BORDER_WAIT, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess() { dbService.getBorderWaits( new ListCallback<GenericRow>() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess( List<GenericRow> result) { getBorderWaits(view, result); } }); } }); } }); } }); } } }); } }); } else { dbService.getBorderWaits(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { getBorderWaits(view, result); } }); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.ferries.schedules.departures.FerriesRouteDeparturesActivity.java
License:Open Source License
protected void createFerryTerminalSailingSpaces() { /** /* www.j a v a 2s .c om*/ * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.FERRIES_TERMINAL_SAILING_SPACE, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; view.showProgressIndicator(); if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * 1000)); // Refresh every 15 seconds. } if (shouldUpdate) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(TERMINAL_SAILING_SPACE_URL, new AsyncCallback<FerriesTerminalSailingSpaceFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); } @Override public void onSuccess(FerriesTerminalSailingSpaceFeed result) { if (result.getTerminals() != null) { DateTimeFormat dateFormat = DateTimeFormat.getFormat("MMMM d, yyyy h:mm a"); ferriesTerminalSailingSpaceItems.clear(); FerriesTerminalSailingSpaceItem item; int numItems = result.getTerminals().length(); for (int i = 0; i < numItems; i++) { item = new FerriesTerminalSailingSpaceItem(); item.setTerminalId(result.getTerminals().get(i).getTerminalId()); item.setTerminalName(result.getTerminals().get(i).getTerminalName()); item.setTerminalAbbrev( result.getTerminals().get(i).getTerminalAbbrev()); item.setTerminalDepartingSpaces( new JSONArray(result.getTerminals().get(i).getDepartingSpaces()) .toString()); item.setLastUpdated( dateFormat.format(new Date(System.currentTimeMillis()))); ferriesTerminalSailingSpaceItems.add(item); } // Purge existing terminal items covered by incoming data dbService.deleteFerriesTerminalSailingSpace(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new ferries terminal sailing space items dbService.insertFerriesTerminalSailingSpace( ferriesTerminalSailingSpaceItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update List<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add(new CacheItem( Tables.FERRIES_TERMINAL_SAILING_SPACE, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess() { // Get available drive-up vehicle spaces. dbService .getFerriesTerminalSailingSpace( scheduleDateItems .get(view .getDayOfWeekSelected()) .getFerriesTerminalItem() .get(sailingsIndex) .getDepartingTerminalID() .toString(), new ListCallback<GenericRow>() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess( List<GenericRow> result) { getFerryTerminalSailingSpaces( result); } }); } }); } }); } }); } } }); } else { // Get available drive-up vehicle spaces. dbService.getFerriesTerminalSailingSpace( scheduleDateItems.get(view.getDayOfWeekSelected()).getFerriesTerminalItem() .get(sailingsIndex).getDepartingTerminalID().toString(), new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { getFerryTerminalSailingSpaces(result); } }); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.ferries.schedules.departures.FerriesRouteDeparturesActivity.java
License:Open Source License
private void createFerryTerminalCameras() { /** /*from w w w. j av a2 s . c o m*/ * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.CAMERAS, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (7 * 86400000)); // Refresh every 7 days. } view.showProgressIndicator(); if (shouldUpdate) { /** * Check the cameras table for any starred entries. If we find some, * save them to a list so we can re-star those after we flush the database. */ dbService.getStarredCameras(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { starred.clear(); if (!result.isEmpty()) { for (GenericRow row : result) { starred.add(row.getInt(CamerasColumns.CAMERA_ID)); } } JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(CAMERAS_URL, new AsyncCallback<CamerasFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); phoneGap.getNotification().alert("Can't load data. Check your connection.", new AlertCallback() { @Override public void onOkButtonClicked() { // TODO Auto-generated method stub } }, "Connection Error"); } @Override public void onSuccess(CamerasFeed result) { if (result.getCameras() != null) { cameraItems.clear(); CameraItem item; int numCameras = result.getCameras().getItems().length(); for (int i = 0; i < numCameras; i++) { item = new CameraItem(); item.setCameraId(result.getCameras().getItems().get(i).getId()); item.setTitle(result.getCameras().getItems().get(i).getTitle()); item.setImageUrl(result.getCameras().getItems().get(i).getUrl()); item.setLatitude(result.getCameras().getItems().get(i).getLat()); item.setLongitude(result.getCameras().getItems().get(i).getLon()); item.setHasVideo(result.getCameras().getItems().get(i).getHasVideo()); item.setRoadName(result.getCameras().getItems().get(i).getRoadName()); if (starred.contains(result.getCameras().getItems().get(i).getId())) { item.setIsStarred(1); } cameraItems.add(item); } // Purge existing cameras covered by incoming data dbService.deleteCameras(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new cameras dbService.insertCameras(cameraItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update List<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add(new CacheItem(Tables.CAMERAS, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { getFerryTerminalCameras(); } }); } }); } }); } } }); } }); } else { getFerryTerminalCameras(); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.ferries.schedules.FerriesRouteSchedulesActivity.java
License:Open Source License
private void createTopicsList(final boolean forceUpdate) { /** // w w w .ja v a 2s. c om * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.FERRIES_SCHEDULES, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * 60000)); // Refresh every 15 minutes. } view.showProgressIndicator(); if (shouldUpdate || forceUpdate) { /** * Check the ferry schedules table for any starred entries. If we find some, * save them to a list so we can re-star those after we flush the database. */ dbService.getStarredFerriesSchedules(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { starred.clear(); if (!result.isEmpty()) { for (GenericRow row : result) { starred.add(row.getInt(FerriesSchedulesColumns.FERRIES_SCHEDULE_ID)); } } JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(FERRIES_SCHEDULES_URL, new AsyncCallback<FerriesRouteFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); if (!alertShowing) { alertShowing = true; phoneGap.getNotification().alert("Can't load data. Check your connection.", new AlertCallback() { @Override public void onOkButtonClicked() { alertShowing = false; } }, "Connection Error"); } } @Override public void onSuccess(FerriesRouteFeed result) { if (result.getRoutes() != null) { ferriesRouteItems.clear(); FerriesRouteItem item; int numRoutes = result.getRoutes().length(); for (int i = 0; i < numRoutes; i++) { item = new FerriesRouteItem(); item.setRouteID(result.getRoutes().get(i).getRouteID()); item.setDescription(result.getRoutes().get(i).getDescription()); item.setCrossingTime(result.getRoutes().get(i).getCrossingTime()); item.setScheduleDate( new JSONArray(result.getRoutes().get(i).getDate()).toString()); item.setRouteAlert( new JSONArray(result.getRoutes().get(i).getRouteAlert()) .toString()); item.setCacheDate(dateFormat.format(new Date(Long.parseLong( result.getRoutes().get(i).getCacheDate().substring(6, 19))))); if (starred.contains(result.getRoutes().get(i).getRouteID())) { item.setIsStarred(1); } ferriesRouteItems.add(item); } // Purge existing border wait times covered by incoming data dbService.deleteFerriesSchedules(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new ferries schedules dbService.insertFerriesSchedules(ferriesRouteItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update List<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems .add(new CacheItem(Tables.FERRIES_SCHEDULES, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess() { dbService.getFerriesSchedules( new ListCallback<GenericRow>() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess( List<GenericRow> result) { getFerriesSchedules( result); } }); } }); } }); } }); } } }); } }); } else { dbService.getFerriesSchedules(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { getFerriesSchedules(result); } }); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.ferries.vesselwatch.VesselWatchMapActivity.java
License:Open Source License
private void getCameras() { /** //from w w w.j a va 2 s . co m * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.CAMERAS, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (7 * 86400000)); // Refresh every 7 days. } view.showProgressIndicator(); if (shouldUpdate) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(CAMERAS_URL, new AsyncCallback<CamerasFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); phoneGap.getNotification().alert("Can't load data. Check your connection.", new AlertCallback() { @Override public void onOkButtonClicked() { // TODO Auto-generated method stub } }, "Connection Error"); } @Override public void onSuccess(final CamerasFeed result) { if (result.getCameras() != null) { final List<Integer> starred = new ArrayList<Integer>(); // Get any starred camera rows. dbService.getStarredCameras(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { Window.alert(error.getMessage()); } @Override public void onSuccess(List<GenericRow> rows) { final ArrayList<CameraItem> cameraItems = new ArrayList<CameraItem>(); CameraItem item; if (!rows.isEmpty()) { int numResults = rows.size(); for (int i = 0; i < numResults; i++) { starred.add(rows.get(i).getInt(CamerasColumns.CAMERA_ID)); } } //cameraItems.clear(); int numCameras = result.getCameras().getItems().length(); for (int i = 0; i < numCameras; i++) { item = new CameraItem(); item.setCameraId(result.getCameras().getItems().get(i).getId()); item.setTitle(result.getCameras().getItems().get(i).getTitle()); item.setImageUrl(result.getCameras().getItems().get(i).getUrl()); item.setLatitude(result.getCameras().getItems().get(i).getLat()); item.setLongitude(result.getCameras().getItems().get(i).getLon()); item.setHasVideo(result.getCameras().getItems().get(i).getHasVideo()); item.setRoadName(result.getCameras().getItems().get(i).getRoadName()); if (starred.contains(result.getCameras().getItems().get(i).getId())) { item.setIsStarred(1); } cameraItems.add(item); } // Purge existing cameras covered by incoming data dbService.deleteCameras(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new cameras dbService.insertCameras(cameraItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update ArrayList<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add(new CacheItem(Tables.CAMERAS, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { view.hideProgressIndicator(); drawCamerasLayer(); } }); } }); } }); } }); } } }); } else { view.hideProgressIndicator(); drawCamerasLayer(); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.ferries.vesselwatch.VesselWatchMapActivity.java
License:Open Source License
private void drawVesselsLayer() { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 25 seconds (25000 milliseconds) jsonp.setTimeout(25000);/*from www .j a va 2 s. c o m*/ jsonp.requestObject(VESSEL_WATCH_URL, new AsyncCallback<VesselWatchFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); phoneGap.getNotification().alert("Can't load data. Check your connection.", new AlertCallback() { @Override public void onOkButtonClicked() { // TODO Auto-generated method stub } }, "Connection Error"); } @Override public void onSuccess(VesselWatchFeed result) { vesselWatchItems.clear(); VesselWatchItem item = null; if (result != null) { int numEntries = result.length(); for (int i = 0; i < numEntries; i++) { item = new VesselWatchItem(); if (!result.get(i).getInService()) { continue; } item.setVesselID(result.get(i).getVesselID()); item.setName(result.get(i).getName()); item.setRoute(result.get(i).getRoute()); item.setLastDock(result.get(i).getLastDock()); item.setArrivingTerminal(result.get(i).getATerm()); item.setLeftDock(result.get(i).getLeftDock()); item.setNextDep(result.get(i).getNextDep()); item.setEta(result.get(i).getEta()); item.setHead(result.get(i).getHead()); item.setSpeed(result.get(i).getSpeed()); // round heading to nearest 30 degrees int nearest = (result.get(i).getHead() + 30 / 2) / 30 * 30; item.setIcon(ferryIcons.get(nearest)); item.setLat(result.get(i).getLat()); item.setLon(result.get(i).getLon()); vesselWatchItems.add(item); } view.drawFerries(vesselWatchItems); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.home.HomeActivity.java
License:Open Source License
private void createAlertsList() { /** /*from w w w. j av a2 s .c om*/ * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.HIGHWAY_ALERTS, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { // On first install the 'caches' table doesn't exist yet. Why? highwayAlertItems.clear(); highwayAlertItems.add(new HighwayAlertItem(-1, "No highest impact travel alerts")); view.hideProgressIndicator(); view.render(highwayAlertItems); view.refresh(); } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (5 * 60000)); // Refresh every 5 minutes. } view.showProgressIndicator(); view.clear(); if (shouldUpdate) { try { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(HIGHWAY_ALERTS_URL, new AsyncCallback<HighwayAlerts>() { @Override public void onFailure(Throwable caught) { highwayAlertItems.clear(); highwayAlertItems .add(new HighwayAlertItem(-1, "Can't load data. Check your connection.")); view.hideProgressIndicator(); view.render(highwayAlertItems); view.refresh(); } @Override public void onSuccess(HighwayAlerts result) { highwayAlertItems.clear(); if (result.getAlerts() != null) { HighwayAlertItem item; int size = result.getAlerts().getItems().length(); for (int i = 0; i < size; i++) { item = new HighwayAlertItem(); item.setAlertId(result.getAlerts().getItems().get(i).getAlertID()); item.setHeadlineDescription( result.getAlerts().getItems().get(i).getHeadlineDescription()); item.setEventCategory( result.getAlerts().getItems().get(i).getEventCategory()); item.setPriority(result.getAlerts().getItems().get(i).getPriority()); item.setStartLatitude(result.getAlerts().getItems().get(i) .getStartRoadwayLocation().getLatitude()); item.setStartLongitude(result.getAlerts().getItems().get(i) .getStartRoadwayLocation().getLongitude()); item.setStartRoadName(result.getAlerts().getItems().get(i) .getStartRoadwayLocation().getRoadName()); item.setLastUpdatedTime(dateFormat .format(new Date(Long.parseLong(result.getAlerts().getItems().get(i) .getLastUpdatedTime().substring(6, 19))))); highwayAlertItems.add(item); } // Purge existing highway alerts covered by incoming data dbService.deleteHighwayAlerts(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new highway alerts dbService.insertHighwayAlerts(highwayAlertItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { highwayAlertItems.clear(); highwayAlertItems.add( new HighwayAlertItem(-1, error.getMessage())); view.hideProgressIndicator(); view.render(highwayAlertItems); view.refresh(); } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update List<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add(new CacheItem(Tables.HIGHWAY_ALERTS, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess() { dbService.getHighwayAlerts( new ListCallback<GenericRow>() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess( List<GenericRow> result) { getHighestPriorityHighwayAlerts( result); } }); } }); } }); } }); } } }); } catch (Exception e) { } } else { dbService.getHighwayAlerts(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { getHighestPriorityHighwayAlerts(result); } }); } } }); }