Permalink
Browse files

auto-capitalize stations entered before submitting

  • Loading branch information...
1 parent 36d4107 commit 6c6dbcffba6b27d0a4a493818ccce7f6fd6747c9 @phoxicle committed May 6, 2011
Showing with 14 additions and 0 deletions.
  1. +14 −0 src/com/pheide/trainose/RouteEdit.java
@@ -82,6 +82,20 @@ public void onClick(View view) {
* @return boolean
*/
private Boolean stationsAreValid() { // Android really ought to handle this itself..
+ // Make sure stations entered are capitalized
+ String sourceText = mSourceTextView.getText().toString();
+ String destinationText = mDestinationTextView.getText().toString();
+
+ if (sourceText.length() == 0 || destinationText.length() == 0) {
+ return false;
+ }
+
+ // Capitalize first letter, lowercase the rest
+ mSourceTextView.setText(sourceText.substring(0, 1).toUpperCase()
+ + sourceText.substring(1).toLowerCase());
+ mDestinationTextView.setText(destinationText.substring(0, 1).toUpperCase()
+ + destinationText.substring(1).toLowerCase());
+
String[] stations = getResources().getStringArray(R.array.stations_array);
Arrays.sort(stations);
if (Arrays.binarySearch(stations, mSourceTextView.getText().toString()) > 0

0 comments on commit 6c6dbcf

Please sign in to comment.