Search in sources :

Example 6 with Station

use of im.tny.segvault.subway.Station in project underlx by underlx.

the class StationTriviaFragment method update.

private void update() {
    if (mListener == null)
        return;
    MainService service = mListener.getMainService();
    if (service == null)
        return;
    Network net = service.getNetwork(networkId);
    if (net == null)
        return;
    Station station = net.getStation(stationId);
    if (station == null)
        return;
    ExtraContentCache.getTrivia(getContext(), new ExtraContentCache.OnTriviaReadyListener() {

        @Override
        public void onSuccess(List<String> trivia) {
            if (isAdded()) {
                triviaView.setHtml(trivia.get(0));
            }
        }

        @Override
        public void onProgress(int current) {
        }

        @Override
        public void onFailure() {
            if (isAdded()) {
                triviaView.setHtml(getString(R.string.frag_station_info_unavailable));
            }
        }
    }, station);
}
Also used : MainService(im.tny.segvault.disturbances.MainService) Station(im.tny.segvault.subway.Station) ExtraContentCache(im.tny.segvault.disturbances.ExtraContentCache) Network(im.tny.segvault.subway.Network)

Example 7 with Station

use of im.tny.segvault.subway.Station 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 8 with Station

use of im.tny.segvault.subway.Station in project underlx by underlx.

the class TripFragment method populatePathView.

public static void populatePathView(final Context context, final LayoutInflater inflater, final Path path, ViewGroup root, boolean showInfoIcons) {
    root.removeAllViews();
    List<Connection> el = path.getEdgeList();
    final int stepviewPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, context.getResources().getDisplayMetrics());
    if (el.size() == 0) {
        View stepview = inflater.inflate(R.layout.path_station, root, false);
        FrameLayout prevLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.prev_line_stripe_layout);
        FrameLayout nextLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.next_line_stripe_layout);
        prevLineStripeLayout.setVisibility(View.GONE);
        nextLineStripeLayout.setVisibility(View.GONE);
        TextView timeView = (TextView) stepview.findViewById(R.id.time_view);
        if (path.getManualEntry(0)) {
            timeView.setVisibility(View.INVISIBLE);
        } else {
            timeView.setText(DateUtils.formatDateTime(context, path.getEntryTime(0).getTime(), DateUtils.FORMAT_SHOW_TIME));
        }
        final Station station = path.getStartVertex().getStation();
        stepview.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, StationActivity.class);
                intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
                intent.putExtra(StationActivity.EXTRA_NETWORK_ID, station.getNetwork().getId());
                context.startActivity(intent);
            }
        });
        RouteFragment.populateStationView(context, station, stepview, showInfoIcons, false);
        stepview.setPadding(stepviewPadding, 0, stepviewPadding, 0);
        root.addView(stepview);
        return;
    }
    boolean isFirst = true;
    Connection c = el.get(0);
    int i = 0;
    for (; i < el.size(); i++) {
        c = el.get(i);
        if (i == 0 && c instanceof Transfer) {
            // starting with a line change? ignore
            continue;
        }
        View stepview = inflater.inflate(R.layout.path_station, root, false);
        FrameLayout prevLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.prev_line_stripe_layout);
        FrameLayout nextLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.next_line_stripe_layout);
        if (isFirst) {
            Line line = c.getSource().getLine();
            int lineColor = line.getColor();
            prevLineStripeLayout.setVisibility(View.GONE);
            nextLineStripeLayout.setBackgroundColor(lineColor);
            TextView timeView = (TextView) stepview.findViewById(R.id.time_view);
            if (path.getManualEntry(i)) {
                timeView.setVisibility(View.INVISIBLE);
            } else {
                timeView.setText(DateUtils.formatDateTime(context, path.getEntryTime(i).getTime(), DateUtils.FORMAT_SHOW_TIME));
            }
            isFirst = false;
        } else {
            Line targetLine = c.getTarget().getLine();
            int prevLineColor = c.getSource().getLine().getColor();
            int nextLineColor = targetLine.getColor();
            prevLineStripeLayout.setBackgroundColor(prevLineColor);
            nextLineStripeLayout.setBackgroundColor(nextLineColor);
            TextView timeView = (TextView) stepview.findViewById(R.id.time_view);
            // start of the path was extended with the first step getting replaced by a transfer
            if (path.getManualEntry(i) && !(c instanceof Transfer && !path.getManualEntry(i + 1))) {
                timeView.setVisibility(View.INVISIBLE);
            } else {
                timeView.setText(DateUtils.formatDateTime(context, path.getEntryTime(i).getTime(), DateUtils.FORMAT_SHOW_TIME));
            }
        }
        final Station station = c.getSource().getStation();
        stepview.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, StationActivity.class);
                intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
                intent.putExtra(StationActivity.EXTRA_NETWORK_ID, station.getNetwork().getId());
                context.startActivity(intent);
            }
        });
        RouteFragment.populateStationView(context, station, stepview, showInfoIcons, false);
        ImageView crossView = (ImageView) stepview.findViewById(R.id.station_cross_image);
        if (c.getSource().getStation().isAlwaysClosed()) {
            crossView.setVisibility(View.VISIBLE);
        }
        stepview.setPadding(stepviewPadding, 0, stepviewPadding, 0);
        root.addView(stepview);
        if (c instanceof Transfer && i != el.size() - 1) {
            c = el.get(++i);
        }
    }
    View stepview = inflater.inflate(R.layout.path_station, root, false);
    int lineColor = c.getSource().getLine().getColor();
    FrameLayout prevLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.prev_line_stripe_layout);
    FrameLayout nextLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.next_line_stripe_layout);
    prevLineStripeLayout.setBackgroundColor(lineColor);
    nextLineStripeLayout.setVisibility(View.GONE);
    TextView timeView = (TextView) stepview.findViewById(R.id.time_view);
    if (path.getManualEntry(i)) {
        timeView.setVisibility(View.INVISIBLE);
    } else {
        timeView.setText(DateUtils.formatDateTime(context, path.getEntryTime(i).getTime(), DateUtils.FORMAT_SHOW_TIME));
    }
    ImageView crossView = (ImageView) stepview.findViewById(R.id.station_cross_image);
    if (c.getTarget().getStation().isAlwaysClosed()) {
        crossView.setVisibility(View.VISIBLE);
    }
    final Station station = c.getTarget().getStation();
    stepview.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(context, StationActivity.class);
            intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
            intent.putExtra(StationActivity.EXTRA_NETWORK_ID, station.getNetwork().getId());
            context.startActivity(intent);
        }
    });
    RouteFragment.populateStationView(context, station, stepview, showInfoIcons, false);
    stepview.setPadding(stepviewPadding, 0, stepviewPadding, 0);
    root.addView(stepview);
}
Also used : Connection(im.tny.segvault.subway.Connection) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Station(im.tny.segvault.subway.Station) Line(im.tny.segvault.subway.Line) FrameLayout(android.widget.FrameLayout) Transfer(im.tny.segvault.subway.Transfer) StationActivity(im.tny.segvault.disturbances.ui.activity.StationActivity) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 9 with Station

use of im.tny.segvault.subway.Station in project underlx by underlx.

the class TripFragment method refreshUI.

private void refreshUI() {
    Network network = this.network;
    if (network == null) {
        return;
    }
    Realm realm = Application.getDefaultRealmInstance(getContext());
    Trip trip = realm.where(Trip.class).equalTo("id", tripId).findFirst();
    if (trip == null) {
        return;
    }
    Path path = trip.toConnectionPath(network);
    Station origin = path.getStartVertex().getStation();
    Station dest = path.getEndVertex().getStation();
    SpannableStringBuilder builder = new SpannableStringBuilder();
    if (path.getEdgeList().size() == 0) {
        builder.append("#");
        builder.setSpan(new ImageSpan(getActivity(), R.drawable.ic_beenhere_black_24dp), builder.length() - 1, builder.length(), 0);
        builder.append(" " + origin.getName());
    } else {
        builder.append(origin.getName() + " ").append("#");
        builder.setSpan(new ImageSpan(getActivity(), R.drawable.ic_arrow_forward_black_24dp), builder.length() - 1, builder.length(), 0);
        builder.append(" " + dest.getName());
    }
    stationNamesView.setText(builder);
    dateView.setText(DateUtils.formatDateTime(getContext(), path.getEntryTime(0).getTime(), DateUtils.FORMAT_SHOW_DATE));
    int length = path.getTimeablePhysicalLength();
    long time = path.getMovementMilliseconds();
    if (length == 0 || time == 0) {
        statsLayout.setVisibility(View.GONE);
    } else {
        statsView.setText(String.format(getString(R.string.frag_trip_stats), length, DateUtils.formatElapsedTime(time / 1000), (((double) length / (double) (time / 1000)) * 3.6)));
    }
    populatePathView(getContext(), inflater, path, layoutRoute, true);
    if (!trip.canBeCorrected()) {
        correctButton.setVisibility(View.GONE);
    }
    realm.close();
}
Also used : Path(im.tny.segvault.s2ls.Path) Station(im.tny.segvault.subway.Station) Trip(im.tny.segvault.disturbances.model.Trip) Network(im.tny.segvault.subway.Network) Realm(io.realm.Realm) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 10 with Station

use of im.tny.segvault.subway.Station in project underlx by underlx.

the class SearchContentProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (!serviceBound) {
        return null;
    }
    String query = uri.getLastPathSegment();
    final String normalizedQuery = Normalizer.normalize(query.toString().toLowerCase().trim(), Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "");
    final List<ResultRow> results = new ArrayList<>();
    final String locale = Util.getCurrentLanguage(getContext());
    for (Station station : mainService.getAllStations()) {
        double distance = getDistance(station.getName(), normalizedQuery);
        if (station.getId().equals(query)) {
            // push to top of results
            distance = -5000;
        }
        for (String altName : station.getAltNames()) {
            double altDistance = getDistance(altName, normalizedQuery);
            if (altDistance < distance) {
                distance = altDistance;
            }
        }
        if (distance < Double.MAX_VALUE) {
            ResultRow row = new ResultRow();
            row.title = station.getName();
            row.subtitle = String.format(getContext().getString(R.string.search_station_subtitle), Util.getNetworkNames(getContext(), station.getNetwork())[0]);
            row.drawable = R.drawable.network_pt_ml;
            row.intentData = "station:" + station.getId();
            row.distance = distance;
            results.add(row);
        }
        for (Lobby lobby : station.getLobbies()) {
            if (lobby.getId().equals(query)) {
                for (Lobby.Exit exit : lobby.getExits()) {
                    results.add(buildResultRowForExit(station, lobby, exit, -5000, null));
                }
                break;
            }
            for (Lobby.Exit exit : lobby.getExits()) {
                boolean added = false;
                for (String street : exit.streets) {
                    distance = getDistance(street, normalizedQuery);
                    if (distance < Double.MAX_VALUE) {
                        results.add(buildResultRowForExit(station, lobby, exit, distance, street));
                        added = true;
                        break;
                    }
                }
                // do not add the same exit twice
                if (added)
                    break;
            }
        }
    }
    for (Line line : mainService.getAllLines()) {
        double distance = Double.MAX_VALUE;
        if (line.getId().equals(query)) {
            // push to top of results
            distance = -5000;
        }
        for (String name : Util.getLineNames(getContext(), line)) {
            double thisDistance = getDistance(name, normalizedQuery);
            if (thisDistance < distance) {
                distance = thisDistance;
            }
        }
        if (distance < Double.MAX_VALUE) {
            ResultRow row = new ResultRow();
            row.title = Util.getLineNames(getContext(), line)[0];
            row.subtitle = String.format(getContext().getString(R.string.search_line_subtitle), Util.getNetworkNames(getContext(), line.getNetwork())[0]);
            row.drawable = Util.getDrawableResourceIdForLineId(line.getId());
            row.intentData = "line:" + line.getId();
            row.distance = distance;
            results.add(row);
        }
    }
    for (POI poi : mainService.getAllPOIs()) {
        double distance = Double.MAX_VALUE;
        // it's unlikely anyone will search by POI ID, but let's support it anyway
        if (poi.getId().equals(query)) {
            // push to top of results
            distance = -5000;
        }
        for (String name : poi.getNames(locale)) {
            double thisDistance = getDistance(name, normalizedQuery);
            if (thisDistance < distance) {
                distance = thisDistance;
            }
        }
        if (distance < Double.MAX_VALUE) {
            ResultRow row = new ResultRow();
            row.title = poi.getNames(locale)[0];
            row.subtitle = String.format("%s \u2022 %s", getContext().getString(R.string.search_poi_subtitle), getContext().getString(Util.getStringResourceIdForPOIType(poi.getType())));
            row.drawable = R.drawable.ic_place_black_24dp;
            row.drawable2 = Util.getDrawableResourceIdForPOIType(poi.getType());
            row.intentData = "poi:" + poi.getId();
            row.distance = distance;
            results.add(row);
        }
    }
    // TODO search train services, bus services, trivia, etc.
    Collections.sort(results, new Comparator<ResultRow>() {

        @Override
        public int compare(ResultRow row, ResultRow t1) {
            return Double.compare(row.distance, t1.distance);
        }
    });
    if (results.size() == 0) {
        ResultRow row = new ResultRow();
        row.title = getContext().getString(R.string.search_no_results);
        row.drawable = R.drawable.ic_sentiment_dissatisfied_black_24dp;
        row.intentData = "no-results";
        row.distance = 0;
        results.add(row);
    }
    MatrixCursor cursor = new MatrixCursor(columns);
    int i = 0;
    for (ResultRow row : results) {
        Object[] cursorRow = { i++, row.title, row.subtitle, row.drawable, row.drawable2, row.intentData };
        cursor.addRow(cursorRow);
    }
    return cursor;
}
Also used : ArrayList(java.util.ArrayList) POI(im.tny.segvault.subway.POI) MatrixCursor(android.database.MatrixCursor) Station(im.tny.segvault.subway.Station) Line(im.tny.segvault.subway.Line) Lobby(im.tny.segvault.subway.Lobby)

Aggregations

Station (im.tny.segvault.subway.Station)19 View (android.view.View)7 Network (im.tny.segvault.subway.Network)7 TextView (android.widget.TextView)6 MainService (im.tny.segvault.disturbances.MainService)5 Stop (im.tny.segvault.subway.Stop)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 ImageView (android.widget.ImageView)4 Line (im.tny.segvault.subway.Line)4 Lobby (im.tny.segvault.subway.Lobby)4 Realm (io.realm.Realm)4 Connection (im.tny.segvault.subway.Connection)3 POI (im.tny.segvault.subway.POI)3 Location (android.location.Location)2 ViewTreeObserver (android.view.ViewTreeObserver)2 FrameLayout (android.widget.FrameLayout)2 GoogleMap (com.google.android.gms.maps.GoogleMap)2 OnMapReadyCallback (com.google.android.gms.maps.OnMapReadyCallback)2 Marker (com.google.android.gms.maps.model.Marker)2