Search in sources :

Example 1 with S2LS

use of im.tny.segvault.s2ls.S2LS in project underlx by underlx.

the class RouteFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setUpActivity(getString(R.string.frag_route_title), R.id.nav_plan_route, false, false);
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_route, container, false);
    layoutNetworkClosed = (LinearLayout) view.findViewById(R.id.network_closed_layout);
    viewNetworkClosed = (TextView) view.findViewById(R.id.network_closed_view);
    layoutRoute = (LinearLayout) view.findViewById(R.id.layout_route);
    layoutOriginStationClosed = (LinearLayout) view.findViewById(R.id.origin_station_closed_layout);
    layoutDestinationStationClosed = (LinearLayout) view.findViewById(R.id.destination_station_closed_layout);
    viewOriginStationClosed = (TextView) view.findViewById(R.id.origin_station_closed_view);
    viewDestinationStationClosed = (TextView) view.findViewById(R.id.destination_station_closed_view);
    layoutInstructions = (LinearLayout) view.findViewById(R.id.layout_instructions);
    layoutBottomSheet = (RelativeLayout) view.findViewById(R.id.bottom_sheet_layout);
    swapButton = (ImageButton) view.findViewById(R.id.swap_button);
    swapButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Station o = originPicker.getSelection();
            originPicker.setSelection(destinationPicker.getSelection());
            destinationPicker.setSelection(o);
            tryPlanRoute();
        }
    });
    navigationStartButton = (Button) view.findViewById(R.id.navigation_start_button);
    navigationStartButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            S2LS loc = mListener.getMainService().getS2LS(networkId);
            if (loc != null && route != null) {
                loc.setCurrentTargetRoute(route, false);
                switchToPage("nav_home");
            }
        }
    });
    useRealtimeCheckbox = (CheckBox) view.findViewById(R.id.use_realtime_check);
    useRealtimeCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            tryPlanRoute();
        }
    });
    routeEtaView = (TextView) view.findViewById(R.id.route_eta_view);
    originPicker = (StationPickerView) view.findViewById(R.id.origin_picker);
    destinationPicker = (StationPickerView) view.findViewById(R.id.destination_picker);
    IntentFilter filter = new IntentFilter();
    filter.addAction(MainActivity.ACTION_MAIN_SERVICE_BOUND);
    filter.addAction(MainService.ACTION_UPDATE_TOPOLOGY_FINISHED);
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(getContext());
    bm.registerReceiver(mBroadcastReceiver, filter);
    if (mListener != null && mListener.getMainService() != null) {
        network = mListener.getMainService().getNetwork(networkId);
        loc = mListener.getMainService().getS2LS(networkId);
        // the network map might not be loaded yet
        if (network != null && loc != null) {
            populatePickers();
            updateClosedWarning();
        }
    }
    return view;
}
Also used : Station(im.tny.segvault.subway.Station) S2LS(im.tny.segvault.s2ls.S2LS) IntentFilter(android.content.IntentFilter) ImageView(android.widget.ImageView) StationPickerView(im.tny.segvault.disturbances.ui.widget.StationPickerView) View(android.view.View) TextView(android.widget.TextView) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) CompoundButton(android.widget.CompoundButton)

Example 2 with S2LS

use of im.tny.segvault.s2ls.S2LS in project underlx by underlx.

the class MainService method loadNetworks.

private void loadNetworks() {
    synchronized (lock) {
        try {
            Network net = TopologyCache.loadNetwork(this, PRIMARY_NETWORK_ID, api.getEndpoint().toString());
            putNetwork(net);
            S2LS loc = locServices.get(PRIMARY_NETWORK_ID);
            Log.d("loadNetworks", String.format("In network? %b", loc.inNetwork()));
            Log.d("loadNetworks", String.format("Near network? %b", loc.nearNetwork()));
            Zone z = loc.getLocation();
            for (Stop s : z.vertexSet()) {
                Log.d("loadNetworks", String.format("May be in station %s", s));
            }
        } catch (CacheException e) {
            // cache invalid, attempt to reload topology
            updateTopology();
        }
    }
}
Also used : S2LS(im.tny.segvault.s2ls.S2LS) Stop(im.tny.segvault.subway.Stop) CacheException(im.tny.segvault.disturbances.exception.CacheException) Zone(im.tny.segvault.subway.Zone) Network(im.tny.segvault.subway.Network)

Example 3 with S2LS

use of im.tny.segvault.s2ls.S2LS in project underlx by underlx.

the class MainService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (networks.size() == 0) {
        loadNetworks();
    }
    if (intent != null && intent.getAction() != null) {
        switch(intent.getAction()) {
            case ACTION_CHECK_TOPOLOGY_UPDATES:
                Log.d("MainService", "onStartCommand CheckUpdates");
                if (new Date().getTime() - creationDate.getTime() < TimeUnit.SECONDS.toMillis(10)) {
                    // service started less than 10 seconds ago, no need to check again
                    break;
                }
                checkForTopologyUpdates(true);
                Log.d("MainService", "onStartCommand updates checked");
                break;
            case ACTION_SYNC_TRIPS:
                Log.d("MainService", "onStartCommand SyncTrips");
                synchronizer.attemptSync();
                break;
            case ACTION_DISTURBANCE_NOTIFICATION:
                {
                    final String network = intent.getStringExtra(EXTRA_DISTURBANCE_NETWORK);
                    final String line = intent.getStringExtra(EXTRA_DISTURBANCE_LINE);
                    final String id = intent.getStringExtra(EXTRA_DISTURBANCE_ID);
                    final String status = intent.getStringExtra(EXTRA_DISTURBANCE_STATUS);
                    final boolean downtime = intent.getBooleanExtra(EXTRA_DISTURBANCE_DOWNTIME, false);
                    final long msgtime = intent.getLongExtra(EXTRA_DISTURBANCE_MSGTIME, 0);
                    handleDisturbanceNotification(network, line, id, status, downtime, msgtime);
                    break;
                }
            case ACTION_ANNOUNCEMENT_NOTIFICATION:
                {
                    final String network = intent.getStringExtra(EXTRA_ANNOUNCEMENT_NETWORK);
                    final String title = intent.getStringExtra(EXTRA_ANNOUNCEMENT_TITLE);
                    final String body = intent.getStringExtra(EXTRA_ANNOUNCEMENT_BODY);
                    final String url = intent.getStringExtra(EXTRA_ANNOUNCEMENT_URL);
                    final String source = intent.getStringExtra(EXTRA_ANNOUNCEMENT_SOURCE);
                    final long msgtime = intent.getLongExtra(EXTRA_ANNOUNCEMENT_MSGTIME, 0);
                    handleAnnouncementNotification(network, title, body, url, source, msgtime);
                    break;
                }
            case ACTION_END_TRIP:
                {
                    final String network = intent.getStringExtra(EXTRA_TRIP_NETWORK);
                    S2LS loc;
                    synchronized (lock) {
                        loc = locServices.get(network);
                    }
                    if (loc != null) {
                        loc.endCurrentTrip();
                    }
                    break;
                }
            case ACTION_END_NAVIGATION:
                {
                    final String network = intent.getStringExtra(EXTRA_NAVIGATION_NETWORK);
                    S2LS loc;
                    synchronized (lock) {
                        loc = locServices.get(network);
                    }
                    if (loc != null) {
                        loc.setCurrentTargetRoute(null, false);
                    }
                    break;
                }
        }
    }
    reloadFCMsubscriptions();
    UpdateTopologyJob.schedule();
    SyncTripsJob.schedule();
    SharedPreferences sharedPref = getSharedPreferences("settings", MODE_PRIVATE);
    boolean permanentForeground = sharedPref.getBoolean(PreferenceNames.PermanentForeground, false);
    if (permanentForeground) {
        startPermanentForeground();
    }
    return Service.START_STICKY;
}
Also used : S2LS(im.tny.segvault.s2ls.S2LS) SharedPreferences(android.content.SharedPreferences) SpannableString(android.text.SpannableString) Date(java.util.Date)

Example 4 with S2LS

use of im.tny.segvault.s2ls.S2LS in project underlx by underlx.

the class HomeFragment method refreshCurrentTrip.

private void refreshCurrentTrip() {
    if (mListener == null)
        return;
    final MainService m = mListener.getMainService();
    if (m == null)
        return;
    S2LS loc = m.getS2LS(MainService.PRIMARY_NETWORK_ID);
    if (loc == null || loc.getCurrentTrip() == null) {
        ongoingTripCard.setVisibility(View.GONE);
    } else {
        final Station station = loc.getCurrentTrip().getCurrentStop().getStation();
        curStationNameView.setText(station.getName());
        Stop direction = loc.getCurrentTrip().getDirection();
        Stop next = loc.getCurrentTrip().getNextStop();
        if (direction != null && next != null) {
            directionView.setText(String.format(getString(R.string.frag_home_trip_direction), direction.getStation().getName()));
            nextStationView.setText(String.format(getString(R.string.frag_home_trip_next_station), next.getStation().getName()));
            Stop likelyExit = m.getLikelyNextExit(loc.getCurrentTrip().getEdgeList(), 1);
            int resId = android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Small;
            if (next == likelyExit) {
                resId = android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Medium;
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                nextStationView.setTextAppearance(resId);
            } else {
                nextStationView.setTextAppearance(getContext(), resId);
            }
            directionView.setVisibility(View.VISIBLE);
            nextStationView.setVisibility(View.VISIBLE);
        } else {
            directionView.setVisibility(View.GONE);
            nextStationView.setVisibility(View.GONE);
        }
        redrawCurrentStationLineIcons(station);
        curStationLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), StationActivity.class);
                intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
                intent.putExtra(StationActivity.EXTRA_NETWORK_ID, MainService.PRIMARY_NETWORK_ID);
                startActivity(intent);
            }
        });
        curTripIncorrectLocationButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new FeedbackUtil.IncorrectLocation(getContext(), m, station).showReportWizard();
            }
        });
        if (loc.canRequestEndOfTrip()) {
            curTripEndButton.setVisibility(View.VISIBLE);
            curTripIncorrectLocationButton.setVisibility(View.GONE);
        } else {
            curTripEndButton.setVisibility(View.GONE);
            curTripIncorrectLocationButton.setVisibility(View.VISIBLE);
        }
        ongoingTripCard.setVisibility(View.VISIBLE);
    }
}
Also used : MainService(im.tny.segvault.disturbances.MainService) S2LS(im.tny.segvault.s2ls.S2LS) Station(im.tny.segvault.subway.Station) Stop(im.tny.segvault.subway.Stop) StationActivity(im.tny.segvault.disturbances.ui.activity.StationActivity) Intent(android.content.Intent) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView)

Example 5 with S2LS

use of im.tny.segvault.s2ls.S2LS in project underlx by underlx.

the class MainService method putNetwork.

private void putNetwork(final Network net) {
    synchronized (lock) {
        // create Realm stations for the network if they don't exist already
        Realm realm = Application.getDefaultRealmInstance(this);
        realm.executeTransaction(new Realm.Transaction() {

            @Override
            public void execute(Realm realm) {
                for (Station s : net.getStations()) {
                    if (realm.where(RStation.class).equalTo("id", s.getId()).count() == 0) {
                        RStation rs = new RStation();
                        rs.setStop(s);
                        rs.setNetwork(net.getId());
                        realm.copyToRealm(rs);
                    }
                }
            }
        });
        realm.close();
        net.setEdgeWeighter(cweighter);
        networks.put(net.getId(), net);
        S2LS loc = new S2LS(net, new S2LSChangeListener());
        locServices.put(net.getId(), loc);
        WiFiLocator wl = new WiFiLocator(net);
        wfc.setLocatorForNetwork(net, wl);
        loc.addNetworkDetector(wl);
        loc.addProximityDetector(wl);
        loc.addLocator(wl);
    }
}
Also used : RStation(im.tny.segvault.disturbances.model.RStation) Station(im.tny.segvault.subway.Station) S2LS(im.tny.segvault.s2ls.S2LS) RStation(im.tny.segvault.disturbances.model.RStation) Realm(io.realm.Realm) WiFiLocator(im.tny.segvault.s2ls.wifi.WiFiLocator)

Aggregations

S2LS (im.tny.segvault.s2ls.S2LS)6 Station (im.tny.segvault.subway.Station)3 Stop (im.tny.segvault.subway.Stop)3 SpannableString (android.text.SpannableString)2 View (android.view.View)2 TextView (android.widget.TextView)2 Network (im.tny.segvault.subway.Network)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)1 CardView (android.support.v7.widget.CardView)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 MainService (im.tny.segvault.disturbances.MainService)1 APIException (im.tny.segvault.disturbances.exception.APIException)1 CacheException (im.tny.segvault.disturbances.exception.CacheException)1 RStation (im.tny.segvault.disturbances.model.RStation)1 StationActivity (im.tny.segvault.disturbances.ui.activity.StationActivity)1 StationPickerView (im.tny.segvault.disturbances.ui.widget.StationPickerView)1