Skip to content

Commit

Permalink
Issue OneBusAway#794: Trip planning (bikeshare beta) - add "transit o…
Browse files Browse the repository at this point in the history
…nly" mode
  • Loading branch information
carvalhorr committed Sep 4, 2017
1 parent 7169d78 commit 733babd
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ public class TripRequestBuilder {
private static final String MODE_SET = ".MODE_SET";
private static final String DATE_TIME = ".DATE_TIME";

private static final int TRANSIT_MODE = 0;
private static final int TRANSIT_AND_BIKE_MODE = 0;
private static final int BUS_ONLY_MODE = 1;
private static final int RAIL_ONLY_MODE = 2;
private static final int BIKESHARE_MODE = 3;
private static final int TRANSIT_ONLY_MODE = 4;


private TripRequest.Callback mListener;
Expand Down Expand Up @@ -160,11 +161,13 @@ public TripRequestBuilder setModeSetById(int id) {
List<String> modes;

mModeId = id;

switch (id) {
// Transit only
case TRANSIT_ONLY_MODE:
modes = Arrays.asList(TraverseMode.TRANSIT.toString(), TraverseMode.WALK.toString());
break;
// Transit & bikeshare
case TRANSIT_MODE:
case TRANSIT_AND_BIKE_MODE:
if (Application.isBikeshareEnabled()) {
modes = Arrays.asList(TraverseMode.TRANSIT.toString(),
TraverseMode.WALK.toString(),
Expand Down Expand Up @@ -196,7 +199,7 @@ public TripRequestBuilder setModeSetById(int id) {
public int getModeSetId() {
// IF bike mode is selected in the trip plan additional preferences but bikeshare is not enabled use the default mode (TRANSTI)
if (BIKESHARE_MODE == mModeId && !Application.isBikeshareEnabled()) {
return TRANSIT_MODE;
return TRANSIT_AND_BIKE_MODE;
}
return mModeId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.onebusaway.android.ui;

import org.onebusaway.android.R;
import org.onebusaway.android.app.Application;

/**
* Created by carvalhorr on 9/3/17.
*/

public class TripModes {

public static final int TRANSIT_AND_BIKE_MODE = 0;
public static final int BUS_ONLY_MODE = 1;
public static final int RAIL_ONLY_MODE = 2;
public static final int BIKESHARE_MODE = 3;
public static final int TRANSIT_ONLY_MODE = 4;

public static int getTripModeCodeFromSelection(int selection) {
switch (selection) {
case R.string.transit_mode_transit_and_bikeshare:
return TRANSIT_AND_BIKE_MODE;
case R.string.transit_mode_transit_only:
return TRANSIT_ONLY_MODE;
case R.string.transit_mode_bus:
return BUS_ONLY_MODE;
case R.string.transit_mode_rail:
return RAIL_ONLY_MODE;
case R.string.transit_mode_bikeshare:
return BIKESHARE_MODE;
}
return -1;

}

public static int getSpinnerPositionFromSeledctedCode(int selectedCode) {
if (Application.isBikeshareEnabled()) {
switch (selectedCode) {
case TRANSIT_AND_BIKE_MODE:
return 0;
case TRANSIT_ONLY_MODE:
return 1;
case BUS_ONLY_MODE:
return 2;
case RAIL_ONLY_MODE:
return 3;
case BIKESHARE_MODE:
return 4;
}
} else {
switch (selectedCode) {
case TRANSIT_ONLY_MODE:
return 0;
case BUS_ONLY_MODE:
return 1;
case RAIL_ONLY_MODE:
return 2;
}
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;


public class TripPlanFragment extends Fragment {
Expand Down Expand Up @@ -272,7 +274,7 @@ private void loadAndSetAdditionalTripPreferences() {
int modeId = PreferenceUtils.getInt(getString(R.string.preference_key_trip_plan_travel_by), 0);
double maxWalkDistance = PreferenceUtils.getDouble(getString(R.string.preference_key_trip_plan_maximum_walking_distance), 0);
boolean optimizeTransfers = PreferenceUtils.getBoolean(getString(R.string.preference_key_trip_plan_minimize_transfers), false);
boolean wheelchair = PreferenceUtils.getBoolean(getString(R.string.preference_key_trip_plan_avoid_stairs), false);
boolean wheelchair = PreferenceUtils.getBoolean(getString(R.string.preference_key_trip_plan_avoid_stairs), false);

mBuilder.setOptimizeTransfers(optimizeTransfers)
.setModeSetById(modeId)
Expand Down Expand Up @@ -408,7 +410,9 @@ public void onClick(DialogInterface dialogInterface, int which) {

Spinner spinnerTravelBy = (Spinner) dialog.findViewById(R.id.spinner_travel_by);

int modeId = spinnerTravelBy.getSelectedItemPosition();
final TypedArray transitModeResource = getContext().getResources().obtainTypedArray(R.array.transit_mode_array);

int modeId = TripModes.getTripModeCodeFromSelection(transitModeResource.getResourceId(spinnerTravelBy.getSelectedItemPosition(), 0));

boolean wheelchair = ((CheckBox) dialog.findViewById(R.id.checkbox_wheelchair_acccesible))
.isChecked();
Expand Down Expand Up @@ -459,8 +463,6 @@ public void onClick(DialogInterface dialogInterface, int which) {
if (!Application.isBikeshareEnabled()) {
travelByOptions.remove(getString(R.string.transit_mode_bikeshare));
travelByOptions.remove(getString(R.string.transit_mode_transit_and_bikeshare));
} else {
travelByOptions.remove(getString(R.string.transit_mode_transit_only));
}

ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, travelByOptions);
Expand All @@ -471,7 +473,7 @@ public void onClick(DialogInterface dialogInterface, int which) {

int modeSetId = mBuilder.getModeSetId();
if (modeSetId != -1 && modeSetId < travelByOptions.size()) {
spinnerTravelBy.setSelection(modeSetId);
spinnerTravelBy.setSelection(TripModes.getSpinnerPositionFromSeledctedCode(modeSetId));
}

Double maxWalk = mBuilder.getMaxWalkDistance();
Expand Down Expand Up @@ -603,5 +605,6 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
}
});
}

}

2 changes: 1 addition & 1 deletion onebusaway-android/src/main/res/values-es/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@
</string-array>

<string-array name="transit_mode_array">
<item>@string/transit_mode_transit_only</item>
<item>@string/transit_mode_transit_and_bikeshare</item>
<item>@string/transit_mode_transit_only</item>
<item>@string/transit_mode_bus</item>
<item>@string/transit_mode_rail</item>
<item>@string/transit_mode_bikeshare</item>
Expand Down
2 changes: 1 addition & 1 deletion onebusaway-android/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@
</string-array>

<string-array name="transit_mode_array">
<item>@string/transit_mode_transit_only</item>
<item>@string/transit_mode_transit_and_bikeshare</item>
<item>@string/transit_mode_transit_only</item>
<item>@string/transit_mode_bus</item>
<item>@string/transit_mode_rail</item>
<item>@string/transit_mode_bikeshare</item>
Expand Down

0 comments on commit 733babd

Please sign in to comment.