Back to project page keepmoving.
The source code is released under:
GNU General Public License
If you think the Android project keepmoving listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package it.rainbowbreeze.keepmoving.data; /*from w w w . j a v a 2 s. c o m*/ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import it.rainbowbreeze.keepmoving.common.ILogManager; import it.rainbowbreeze.keepmoving.common.Utils; import it.rainbowbreeze.keepmoving.domain.Coord; import it.rainbowbreeze.keepmoving.domain.GeoPoint; import it.rainbowbreeze.keepmoving.domain.GeoPointTypes; /** * This file is part of KeepMoving. KeepMoving is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public * License as published by the Free Software Foundation, version 2. * <p/> * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * <p/> * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * <p/> * Copyright Alfredo Morresi * <p/> * Created by Alfredo "Rainbowbreeze" Morresi on 17/06/14. */ public class GeoPointFixedRepository implements IGeoPointRepository { private static final String LOG_TAG = GeoPointFixedRepository.class.getSimpleName(); private static Coord getPaviaStationCoord() { return new Coord(45.189414, 9.145421); } private static Coord getPaviaStationBackCoord() { return new Coord(45.189472, 9.144841); } private static Coord getPaviaStationFrontCoord() { return new Coord(45.188692, 9.145882); } private static Coord getUnesBusStopCoord() { return new Coord(45.19994, 9.131181); } private static Coord getRogoredoStationCoord() { return new Coord(45.433365, 9.238343); } private static Coord getSanBabilaTubeStationCoord() { return new Coord(45.466182, 9.197854); } private static Coord getHomeCoord() { return new Coord(45.197118, 9.133394); } private static Coord getMilanOfficeCoord() { return new Coord(45.466182, 9.197854); } public static Coord getTripStartCoord() { return getHomeCoord(); } public static Coord getTripEndCoord() { return getMilanOfficeCoord(); } private final ILogManager mLogManager; public GeoPointFixedRepository(ILogManager logManager) { mLogManager = logManager; } @Override public List<GeoPoint> getAllGeoPoints() { mLogManager.e(LOG_TAG, "Need to create geo points"); // Some remarks: // * points have to be ordered by validity timestamp to improve performances ArrayList<GeoPoint> points = new ArrayList<GeoPoint>(); // Walking from home to nearest bus stop points.add(new GeoPoint() .setName("Home to bus stop") .setType(GeoPointTypes.Foot) .setStartCoord(getHomeCoord()) .setEndCoord(getUnesBusStopCoord()) .setLenght(7) .setValidAllDays() .setValidAllTime()); String[] times; // Bus 6 times = new String[] { "06:17", "06:37", "06:57", "07:17", "07:32", "07:50", "08:11", "08:30", "08:49", "09:08", "09:25", "09:43", "10:01", "10:19", "10:37", "10:55", "11:13", "11:31", "11:49", "12:07", "12:25", "12:43", "13:01", "13:19", "13:37", "13:55", "14:13", "14:31", "14:49", "15:07", "15:25", "15:43", "16:01", "16:19", "16:37", "16:56", "17:16", "17:36", "17:56", "18:16", "18:35", "18:54", "19:13", "19:32", "19:47", "20:02" }; for (String time : times) { points.add(createBus6Weekdays(time)); } // Bus 3 times = new String[] { "06:16", "06:31", "06:43", "06:56", "07:08", "07:21", "07:33", "07:45", "07:57", "08:08", "08:19", "08:31", "08:41", "08:52", "09:04", "09:16", "09:29", "09:41", "09:54", "10:05", "10:17", "10:29", "10:41", "10:53", "11:05", "11:18", "11:29", "11:41", "11:53", "12:05", "12:17", "12:29", "12:41", "12:52", "13:05", "13:18", "13:31", "13:44", "13:57", "14:10", "14:23", "14:36", "14:49", "15:02", "15:15", "15:28", "15:41", "15:54", "16:07", "16:20", "16:33", "16:46", "16:59", "17:12", "17:25", "17:38", "17:51", "18:04", "18:17", "18:30", "18:43", "18:56", "19:10", "19:22", "19:34", "19:46", "19:57", "20:09", "20:21", "20:33", "20:45", "21:03" }; for (String time : times) { points.add(createBus3Weekdays(time)); } // Train S13 // starts every 30 minutes from 5:09 to 12:39 int startingTimestamp = Utils.getTimestampFromTime("5:09"); for (int i=0; i<14; i++) { points.add(createTrainS13Weekdays(startingTimestamp + i*30)); //every 30 minutes } // Regional trains points.add(createTrainRegionalWeekdays("6:02", 20)); points.add(createTrainRegionalWeekdays("6:22", 26)); points.add(createTrainRegionalWeekdays("6:34", 20)); points.add(createTrainRegionalWeekdays("6:48", 26)); points.add(createTrainRegionalWeekdays("7:01", 20)); points.add(createTrainRegionalWeekdays("7:16", 25)); points.add(createTrainRegionalWeekdays("7:26", 22)); points.add(createTrainRegionalWeekdays("7:34", 20)); points.add(createTrainRegionalWeekdays("8:01", 18)); points.add(createTrainRegionalWeekdays("8:18", 24)); points.add(createTrainRegionalWeekdays("8:34", 20)); points.add(createTrainRegionalWeekdays("8:52", 20)); points.add(createTrainRegionalWeekdays("9:04", 19)); points.add(createTrainRegionalWeekdays("9:34", 20)); //Underground points.add(new GeoPoint() .setName("Tube Rogoredo - San Babila") .setType(GeoPointTypes.Tube) .setStartCoord(getRogoredoStationCoord()) .setEndCoord(getSanBabilaTubeStationCoord()) .setLenght(20) .setValidAllDays() .setValidAllTime()); //Walk from tube station to office points.add(new GeoPoint() .setName("Tube to office") .setType(GeoPointTypes.Foot) .setStartCoord(getSanBabilaTubeStationCoord()) .setEndCoord(getMilanOfficeCoord()) .setLenght(5) .setValidAllDays() .setValidAllTime()); //fake for test points.add(new GeoPoint() .setName("Unes to Office") .setType(GeoPointTypes.Train) .setStartCoord(getUnesBusStopCoord()) .setEndCoord(getMilanOfficeCoord()) .setLenght(20) .setValidSunday() .setValidTime("23:35")); //finally, sort the points by validity Collections.sort(points, new Comparator<GeoPoint>() { @Override public int compare(GeoPoint lhs, GeoPoint rhs) { if (lhs.isValidForAllTime()) return -1; if (rhs.isValidForAllTime()) return +1; return lhs.getValidTime() - rhs.getValidTime(); } }); return points; } private GeoPoint createBus6Weekdays(String time) { return new GeoPoint() .setName("Bus 6") .setType(GeoPointTypes.Bus) .setStartCoord(getUnesBusStopCoord()) .setEndCoord(getPaviaStationBackCoord()) .setLenght(11) .setValidWeekDays() .setValidTime(time); } private GeoPoint createBus3Weekdays(String time) { return new GeoPoint() .setName("Bus 3") .setType(GeoPointTypes.Bus) .setStartCoord(getUnesBusStopCoord()) .setEndCoord(getPaviaStationFrontCoord()) .setLenght(13) .setValidWeekDays() .setValidTime(time); } private GeoPoint createTrainS13Weekdays(int time) { return new GeoPoint() .setName("Train S13") .setType(GeoPointTypes.Train) .setStartCoord(getPaviaStationCoord()) .setEndCoord(getRogoredoStationCoord()) .setLenght(30) .setValidWeekDays() .setValidTime(time); } private GeoPoint createTrainRegionalWeekdays(String time, int length) { return new GeoPoint() .setName("Regional Train") .setType(GeoPointTypes.Train) .setStartCoord(getPaviaStationCoord()) .setEndCoord(getRogoredoStationCoord()) .setLenght(length) .setValidWeekDays() .setValidTime(time); } }