Skip to content

Commit

Permalink
Fix #1038 - Show transit icon next to transit geocoder results
Browse files Browse the repository at this point in the history
When planning a trip, geocoder results that have been marked as being in the "transport:public" category will now have a small transit (bus) icon displayed to the left of the result.
  • Loading branch information
barbeau committed May 6, 2020
1 parent 8ed86d8 commit f715e41
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 9 deletions.
2 changes: 1 addition & 1 deletion onebusaway-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ dependencies {
// POJOs used for full data-binding via Jackson
implementation 'edu.usf.cutr.opentripplanner.android:opentripplanner-pojos:1.0.0-SNAPSHOT'
// Pelias for point-of-interest search and geocoding for trip planning origin and destination
implementation 'edu.usf.cutr:pelias-client-library:1.0.3'
implementation 'edu.usf.cutr:pelias-client-library:1.1.0'
// Google Play Services Maps (only for Google flavor)
googleImplementation 'com.google.android.gms:play-services-maps:16.1.0'
// Google Play Services Places is required by ProprietaryMapHelpV2 (only for Google flavor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

package org.onebusaway.android.directions.util;

import org.geojson.Feature;
import org.geojson.Point;

import android.location.Address;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import org.geojson.Feature;
import org.geojson.Point;

import java.util.ArrayList;
import java.util.Locale;


Expand All @@ -36,6 +37,8 @@ public class CustomAddress extends Address {

private static final int ADDRESS_MAX_LINES_TO_SHOW = 5;

private boolean isTransitCategory = false;

public CustomAddress(Locale locale) {
super(locale);
}
Expand Down Expand Up @@ -98,6 +101,17 @@ public CustomAddress(Feature address) {
Point p = (Point) address.getGeometry();
super.setLatitude(p.getCoordinates().getLatitude());
super.setLongitude(p.getCoordinates().getLongitude());

// Check if the geocoder marked this location as having a public transportation category
ArrayList<String> categories = address.getProperty("category");
if (categories != null) {
for (String category : categories) {
if (category.equalsIgnoreCase("transport:public")) {
isTransitCategory = true;
break;
}
}
}
}

@Override
Expand Down Expand Up @@ -201,4 +215,15 @@ public static CustomAddress getEmptyAddress() {
addr.setLongitude(Double.MAX_VALUE);
return addr;
}

/**
* Return true if this location has been labeled under the category of "public transportation",
* false if it has not
*
* @return true if this location has been labeled under the category of "public transportation",
* false if it has not
*/
public boolean isTransitCategory() {
return isTransitCategory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,30 @@

import android.content.Context;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.view.View;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;

import org.onebusaway.android.BuildConfig;
import org.onebusaway.android.R;
import org.onebusaway.android.io.elements.ObaRegion;
import org.onebusaway.android.util.LocationUtils;

import java.util.ArrayList;
import java.util.List;

public class PlacesAutoCompleteAdapter extends ArrayAdapter<CustomAddress> implements Filterable {
public class PlacesAutoCompleteAdapter extends org.onebusaway.android.util.ArrayAdapter<CustomAddress> implements Filterable {

private Context mContext;
private ObaRegion mRegion;

private List<CustomAddress> mResultList = new ArrayList<CustomAddress>();

public PlacesAutoCompleteAdapter(Context context, int textViewResourceId,
public PlacesAutoCompleteAdapter(Context context, int viewId,
ObaRegion region) {
super(context, textViewResourceId);
super(context, viewId);
this.mContext = context;
this.mRegion = region;
}
Expand Down Expand Up @@ -101,4 +104,17 @@ public void setRegion(ObaRegion region) {
this.mRegion = region;
}

@Override
protected void initView(View view, CustomAddress address) {
TextView text = view.findViewById(R.id.geocode_text);
ImageView icon = view.findViewById(R.id.geocode_transit_icon);

text.setText(address.toString());

if (address.isTransitCategory()) {
icon.setVisibility(View.VISIBLE);
} else {
icon.setVisibility(View.GONE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ private void setUpAutocomplete(AutoCompleteTextView tv, final int use) {
}

// Set up autocomplete with Pelias geocoder
tv.setAdapter(new PlacesAutoCompleteAdapter(getContext(), android.R.layout.simple_list_item_1, region));
tv.setAdapter(new PlacesAutoCompleteAdapter(getContext(), R.layout.geocode_result, region));
tv.setOnItemClickListener((parent, view, position, id) -> {
CustomAddress addr = (CustomAddress) parent.getAdapter().getItem(position);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ public static List<CustomAddress> processPeliasGeocoding(Context context, ObaReg

requestBuilder.setBoundaryRect(minLat, minLon, maxLat, maxLon);
}
// Includes categories so we know if it's transit-related
requestBuilder.setCategories("");

// Call the Pelias API
PeliasResponse response = requestBuilder.build().call();
Expand Down
38 changes: 38 additions & 0 deletions onebusaway-android/src/main/res/layout/geocode_result.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:paddingStart="5dp"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingLeft="5dp"
android:paddingRight="?android:attr/listPreferredItemPaddingRight">

<ImageView
android:id="@+id/geocode_transit_icon"
android:src="@drawable/ic_bus"
android:tint="@color/material_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

<TextView
android:id="@+id/geocode_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
app:layout_constraintStart_toEndOf="@id/geocode_transit_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:paddingStart="5dp"
android:paddingLeft="5dp"
tools:text="University Area Transit Center" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit f715e41

Please sign in to comment.