Closed dutchscout closed 11 years ago
For the part 4, it can be done by using Alert Dialog which will pop up a message with OK button. I think this is better than toast message as when the toast message pops up, the touch screen is NOT disable which means that user can still do something else such as move to another page
For part (3), I believe I will move the AlgorithmError enum into the backend and return the error code (if there is one).
I've got my local repo running message handling correctly :) See this sample code I've been running in my SearchActivity. It uses Toasts, so you should change it. It also hard-codes the date/time, so that should be replaced, too. (These are part of why I'm not planning to check it in).
Sample code (goes in SearchActivity.java):
private void requestForRoutes() {
Thread dirThread = new Thread(new DirThread());
dirThread.start();
}
/**
* An inner class that allows the backend request to run on its own thread.
*
* @author dutchscout
*/
private class DirThread implements Runnable {
/**
* {@inheritDoc}
*/
@Override
public void run() {
DirectionsRequest dReq =
(new DirectionsRequest())
.setStartAddress(startFromEditText.getText().toString())
.setEndAddress(toEditText.getText().toString())
.setTravelMode(TravelMode.MIXED).setArrivalTime(1368644400);
DirectionsStatus retVal = dReq.doLiveRequest();
if (retVal.isError()) {
// There was an error in the request, display this to the user
// NOTE: This version uses a Toast. Replace with whatever
// display
// method you prefer.
final CharSequence errorMessage =
"Error getting directions: " + dReq.getErrorMessages();
runOnUiThread(new Runnable() {
public void run() {
Toast errorToast =
Toast.makeText(getApplicationContext(), errorMessage,
Toast.LENGTH_LONG);
errorToast.show();
}
});
// Stay in the search activity
pd.dismiss();
return;
}
Intent intent = new Intent(SearchActivity.this, ResultsActivity.class);
intent.putExtra("List of Routes", (Serializable) dReq.getSolutions());
intent.putExtra("Current Route Index", 0);
startActivity(intent);
pd.dismiss();
}
}
Parts 1-3 of the original post are complete! (checkin momentarily...)
I have created a dialog instead of a toast and have committed the code. So Part 4 finished. Check it out!
This issue includes several people, including @sw11, dutchscout, coreyh3, and others.
Part of our extension to Use Case 1 was that if the user entered bad trip parameters, we would tell them.. We have a validateParameters method now, but we need to get the information back to the user. I think there are a few steps to get this done:
(1) Move the call to validateParameters() from findRoutes() in the AlgorithmWorker to doRequest() in DirectionsRequest, so it is only called once (when we have more algorithms in the future).
(2) If the call to validateParameters finds that the parameters were invalid, stop processing the request and leave the results null.
(3) Modify doRequest() to return an enum (or boolean, or something else) in DirectionsRequest to indicate whether doRequest was successful.
(4) Add UI code to notify the user that their request parameters were invalid and display a message from DirectionsRequest. The easiest way to do this is with a Toast message. The harder way would be to add an overlapping message with an 'OK' button so the user must acknowledge.