diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 04e836e..f99571c 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,42 +1,42 @@ + android:versionCode="4" + android:versionName="1.3" > + android:theme="@style/AboutTheme" > diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml index 9a09959..5904390 100644 --- a/res/layout/activity_main.xml +++ b/res/layout/activity_main.xml @@ -1,88 +1,76 @@ - - + android:onClick="onSearchClick" /> + android:indeterminate="true" + android:visibility="invisible" /> + android:layout_below="@+id/busStopNameTextView" > \ No newline at end of file diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml index 580d940..8c3564b 100644 --- a/res/values-it/strings.xml +++ b/res/values-it/strings.xml @@ -1,57 +1,58 @@ Stai utilizzando l\'ultimo ritrovato in materia di rispetto della tua privacy. Cerca - Inserisci il numero della fermata. + Numero fermata Verifica l\'accesso ad Internet! Nessun arrivo previsto per questa fermata :( Fermata %1$s: + Nessun passaggio Info Preferiti Fermata aggiunta ai preferiti Preferiti Premi sul nome di una fermata per inserirla in questa lista :) Rimuovi Informazioni Benvenuto!

Grazie per aver scelto BusTO, un\'app indipendente nata dalla necessità di spostarsi a Torino attraverso software libero:

- Non sei monitorato
- Non ci sono pubblicità
- La tua privacy è al sicuro
- Inoltre l\'app è molto leggera!

Informazioni

Quest\'app ottiene i passaggi dei bus in tempo reale filtrando i dati forniti pubblicamente sul sito www.5t.torino.it «per uso personale».

Ingredienti:
- Valerio Bozzolan come sviluppatore principale.
- Marco Gagino come intenso collaboratore.
- Paolo Alloatti per l\'icona originale.
- JSoup libreria per "web scaping"
E tutti i contributori!

Licenze

L\'app e il relativo codice sorgente sono distribuiti sotto doppia licenza: GNU GPL e CC By-Sa. Ciò significa che puoi usare, studiare, migliorare e ricondividere quest\'app con qualunque mezzo e per qualsiasi scopo: a patto di mantenere sempre questi diritti a tua volta e di attribuire sempre a Valerio Bozzolan gli \"sforzi\" per il codice sorgente.

Quest\'applicazione è rilasciata nella speranza che sia utile a tutti ma senza alcuna garanzia.

Note

Invio di bugs/idee: lamentati qui.

Codice sorgente: lp:bus-torino.

Contatta l\'autore: Valerio Bozzolan.

Buon utilizzo! :)

]]>
\ No newline at end of file diff --git a/res/values/colors.xml b/res/values/colors.xml index 1adb919..9cbd66e 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -1,16 +1,13 @@ - - - #FF9800 - #F57C00 - - #2196F3 - #1976D2 - - #4DB6AC - #009688 - - #F5F5F5 - - #009688 - + + + #FF9800 + #F57C00 + #2196F3 + #1976D2 + #4DB6AC + #009688 + #F5F5F5 + #009688 + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 2c2da07..79b7c67 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,49 +1,50 @@ BusTO Stai utilizzando l\'ultimo ritrovato in materia di rispetto della tua privacy. Search - Insert the number of the bus stop. + Bus stop number Verify the state of your Internet connection! No bus is supposed to arrive at this stop :( Arrivals at %1$s: + No passages About Favorites Bus stop is now in your favorites Favorites Press on a bus stop name to populate this list :) Delete About Welcome!

Thanks for using BusTO, an indipendent app useful to move around Torino using a Free/Libre and Open Source software.

Why using this app?

- You\'ll never be tracked
- You\'ll never see boring ads
- We\'ll always respect your privacy
- Moreover, it\'s lightweight!

How does it work?

This app will show you the timetable of the buses using the information published on the site http://www.5t.torino.it.

Licenses

The app and the related source code are released by Valerio Bozzolan under the terms of two different licences: the Gnu General Public License v3+ (GNU GPLv3+) and the Creative Commons Attribution - Share alike 4.0 International (CC 4.0 By-Sa). So everyone is allowed to use, to study, to improve and to share this app by any kind of means and for any purpose: under the conditions of manteining this rights and of attributing the original source code to Valerio Bozzolan.

Notes

This app has been developed hoping to be useful to everyone but without any warranty (such as commercial warranties). If you discover some bugs or if you have some idea, please report them.

Source code: lp:bus-torino.

This translation is kindly provided by Riccardo Caniato.

]]>
\ No newline at end of file diff --git a/res/values/styles.xml b/res/values/styles.xml index 4d08b39..ba63890 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -1,33 +1,40 @@ + - + \ No newline at end of file diff --git a/res/values/theme.xml b/res/values/theme.xml index 9e210a9..e5f8af4 100644 --- a/res/values/theme.xml +++ b/res/values/theme.xml @@ -1,14 +1,16 @@ + - + + @color/accent + + \ No newline at end of file diff --git a/src/it/reyboz/bustorino/AsyncWget.java b/src/it/reyboz/bustorino/AsyncWget.java index 8492da7..350f901 100644 --- a/src/it/reyboz/bustorino/AsyncWget.java +++ b/src/it/reyboz/bustorino/AsyncWget.java @@ -1,51 +1,62 @@ package it.reyboz.bustorino; import java.io.BufferedInputStream; import java.io.BufferedReader; -import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import android.os.AsyncTask; import android.util.Log; public class AsyncWget extends AsyncTask { + protected Exception exceptions; + protected String doInBackground(String... uri) { - Log.d("async-action", "Async in backgroundo: " + uri[0]); + exceptions = null; + Log.d("AsyncWget", "Catching URL in background: " + uri[0]); HttpURLConnection urlConnection = null; StringBuilder result = null; try { URL url = new URL(uri[0]); urlConnection = (HttpURLConnection) url.openConnection(); InputStream in = new BufferedInputStream( urlConnection.getInputStream()); BufferedReader reader = new BufferedReader( new InputStreamReader(in)); result = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { result.append(line); } - } catch (IOException e) { + } catch (Exception e) { // TODO Auto-generated catch block - e.printStackTrace(); + Log.e("AsyncWget", e.getMessage()); + exceptions = e; } finally { urlConnection.disconnect(); } + + if(result == null) { + return null; + } return result.toString(); } protected void onProgressUpdate(Integer... progress) { } protected void onPostExecute(String result) { super.onPostExecute(result); } protected void onCancelled() { this.cancel(true); } + + protected void onError() { + + } } diff --git a/src/it/reyboz/bustorino/GTTSiteSucker.java b/src/it/reyboz/bustorino/GTTSiteSucker.java index 2343b0a..5580950 100644 --- a/src/it/reyboz/bustorino/GTTSiteSucker.java +++ b/src/it/reyboz/bustorino/GTTSiteSucker.java @@ -1,217 +1,234 @@ package it.reyboz.bustorino; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import android.util.Log; public class GTTSiteSucker { public static String arrivalTimesByLineQuery(String busStop) { return "http://www.5t.torino.it/5t/trasporto/arrival-times-byline.jsp?action=getTransitsByLine&shortName=" + busStop; } /** * A time passage is a time with the answer of: Is this in real time? * * @author boz */ public static class TimePassage { private String time; private boolean isInRealTime; public TimePassage(String time, boolean isInRealTime) { this.time = time; this.isInRealTime = isInRealTime; } public String getTime() { return time; } public boolean isInRealTime() { return isInRealTime; } } /** * Passages (at a bus line) (like line numbers) * * @author boz */ - public static class PassagesBusLine { + public static class BusLinePassages { private int busLineID; private String busLineName; private ArrayList timesPassages; - public PassagesBusLine() { + public BusLinePassages() { timesPassages = new ArrayList(); } public void addTimePassage(String time, boolean isInRealTime) { timesPassages.add(new TimePassage(time, isInRealTime)); } public ArrayList getTimePassages() { return timesPassages; } public String getTimePassagesString() { + if(timesPassages.size() == 0) { + return null; + } String out = ""; for (TimePassage timePassage : timesPassages) { out += timePassage.getTime() - + (timePassage.isInRealTime() ? "*" : "") + " "; - } - if (timesPassages.size() == 0) { - out = ":("; + + (timePassage.isInRealTime() ? "*" : " ") + " "; } return out; } public String getBusLineName() { return busLineName; } public void setBusLineName(String busLineName) { this.busLineName = busLineName; } public int getLineID() { return busLineID; } public void setBusLineID(int busLineID) { this.busLineID = busLineID; } public String toString() { return getTimePassagesString(); } } /** * A BusStop has information on the bus stop (bus stop name) and of all the * buses that pass through it * * @author boz */ public static class BusStop { private Integer busStopID; // Es: 1254 (always Integer) private String busStopName; // Es: MARCONI - private PassagesBusLine[] arrivalsAtBusStop; + private BusLinePassages[] arrivalsAtBusStop; BusStop(Integer busStopID, String busStopName, - PassagesBusLine[] arrivalsAtBusStop) { + BusLinePassages[] arrivalsAtBusStop) { this.busStopID = busStopID; this.busStopName = busStopName; this.arrivalsAtBusStop = arrivalsAtBusStop; } public void setGTTBusStopName(String busStopName) { this.busStopName = busStopName; } public String getBusStopName() { return busStopName; } public Integer getBusStopID() { return busStopID; } public void setBusStopName(String busStopName) { this.busStopName = busStopName; } - public PassagesBusLine[] getPassagesBusLine() { + public BusLinePassages[] getPassagesBusLine() { return arrivalsAtBusStop; } } /** * API/Workaround to get all informations from the 5T website + * Return a BusStop object. + * BusStop.busStopName can be null. * * @param html * @author Valerio Bozzolan * @return BusStop */ - public static BusStop arrivalTimesBylineHTMLSucker(String html) { - ArrayList arrivalsAtBusStop = new ArrayList(); + public static BusStop getBusStopSuckingHTML(String html) { + if(html == null) { + return null; + } + + ArrayList arrivalsAtBusStop = new ArrayList(); Document doc = Jsoup.parse(html); - for (Element tr : doc.getElementsByTag("tr")) { - PassagesBusLine passagesBusLine = new PassagesBusLine(); - boolean codLineaGTTfound = false; + Elements trs = doc.getElementsByTag("tr"); + for (Element tr : trs) { + BusLinePassages busLinePassages = new BusLinePassages(); - for (Element td : tr.children()) { + boolean isBusLineIDFound = false; + + Elements tds = tr.children(); + for (Element td : tds) { String tdContent = td.html(); if (tdContent.isEmpty()) { continue; } - if (!codLineaGTTfound) { + if (!isBusLineIDFound) { Element tdURL = td.select("a").first(); String busLineName = tdURL.html(); String busLineID = ""; Matcher matcher = Pattern.compile("([0-9])+").matcher( tdURL.attr("href")); if (matcher.find()) { busLineID = matcher.group(); } - passagesBusLine.setBusLineID(Integer.parseInt(busLineID)); - passagesBusLine.setBusLineName(busLineName); - codLineaGTTfound = true; + busLinePassages.setBusLineID(Integer.parseInt(busLineID)); + busLinePassages.setBusLineName(busLineName); + isBusLineIDFound = true; continue; } // Look for "*" (aka "prodotto surgelato") - boolean frozenProduct = !td.select("i").isEmpty(); - if (frozenProduct) { + boolean isFrozenProduct = !td.select("i").isEmpty(); + if (isFrozenProduct) { td.select("i").remove(); tdContent = td.html(); } - passagesBusLine.addTimePassage(tdContent, frozenProduct); + busLinePassages.addTimePassage(tdContent, isFrozenProduct); } - arrivalsAtBusStop.add(passagesBusLine); + arrivalsAtBusStop.add(busLinePassages); } - // Sucking bus stop info + // Sucking bus stop infos String busStopInfo = null; - String busStopName = null; - Integer busStopID = null; Element tagStationInfo = doc.select("span").first(); - if (tagStationInfo != null) { - busStopInfo = tagStationInfo.html(); - Log.d("it.reyboz", "stationInfo:" + busStopInfo); - - // Sucking station number (e.g.: 1254) - Matcher matcherStationNumber = Pattern.compile("([0-9]+)").matcher( - busStopInfo); - if (matcherStationNumber.find()) { - busStopID = Integer.parseInt(matcherStationNumber.group(1)); - } - Log.d("it.reyboz", "stationNumber:" + busStopID); + if (tagStationInfo == null) { + Log.e("GTTSiteSucker", "Parse error: tagStationInfo is null!"); + return null; + } + busStopInfo = tagStationInfo.html(); - // Sucking station name (e.g.: POZZO STRADA) - Matcher matcherStationName = Pattern.compile(" (.+)").matcher( - busStopInfo); - if (matcherStationName.find()) { - busStopName = matcherStationName.group(1); - } - Log.d("it.reyboz", "stationName:" + busStopName); + // Sucking busStopID (e.g.: 1254) + Integer busStopID = null; + Matcher matcherStationNumber = Pattern.compile("([0-9]+)").matcher( + busStopInfo); + if (matcherStationNumber.find()) { + busStopID = Integer.parseInt(matcherStationNumber.group(1)); + } + if(busStopID == null) { + Log.e("GTTSiteSucker", "Parse error: busStopID is null!"); + return null; } + // Sucking busStopName (e.g.: POZZO STRADA) + String busStopName = null; + Matcher matcherStationName = Pattern.compile(" (.+)").matcher( + busStopInfo); + if (matcherStationName.find()) { + busStopName = matcherStationName.group(1); + } + + Log.d("GTTSiteSucker", "busStopInfo: " + busStopInfo); + Log.d("GTTSiteSucker", "busStopID: " + busStopID); + Log.d("GTTSiteSucker", "busStopName:" + busStopName); + return new BusStop(busStopID, busStopName, - (PassagesBusLine[]) arrivalsAtBusStop - .toArray(new PassagesBusLine[] {})); + (BusLinePassages[]) arrivalsAtBusStop + .toArray(new BusLinePassages[] {})); } } diff --git a/src/it/reyboz/bustorino/MainActivity.java b/src/it/reyboz/bustorino/MainActivity.java index 645a35c..67c9750 100644 --- a/src/it/reyboz/bustorino/MainActivity.java +++ b/src/it/reyboz/bustorino/MainActivity.java @@ -1,251 +1,267 @@ package it.reyboz.bustorino; import java.util.ArrayList; import java.util.HashMap; -import it.reyboz.bustorino.GTTSiteSucker.PassagesBusLine; +import it.reyboz.bustorino.GTTSiteSucker.BusLinePassages; import it.reyboz.bustorino.GTTSiteSucker.BusStop; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.EditText; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; import android.view.KeyEvent; public class MainActivity extends ActionBarActivity { + private EditText busStopIDEditText; + private TextView busStopNameTextView; + private ProgressBar annoyingSpinner; + private ListView resultsListView; + private MyAsyncWget myAsyncWget; - private TextView busStationName; - private EditText busStopNumberEditText; - private ProgressBar annoyingFedbackProgressBar; - private Integer lastSearchedBusStopID; private DBBusTo mDbHelper; private SQLiteDatabase db; + private Integer lastSearchedBusStopID; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - busStationName = (TextView) findViewById(R.id.busStationName); - busStopNumberEditText = (EditText) findViewById(R.id.busStopNumberEditText); - annoyingFedbackProgressBar = (ProgressBar) findViewById(R.id.annoyingFedbackProgress); - annoyingFedbackProgressBar.setVisibility(View.INVISIBLE); + busStopIDEditText = (EditText) findViewById(R.id.busStopIDEditText); + busStopNameTextView = (TextView) findViewById(R.id.busStopNameTextView); + annoyingSpinner = (ProgressBar) findViewById(R.id.annoyingSpinner); + resultsListView = (ListView) findViewById(R.id.resultsListView); myAsyncWget = new MyAsyncWget(); - busStopNumberEditText + // IME_ACTION_SEARCH keyboard option + busStopIDEditText .setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { - searchClick(v); + onSearchClick(v); return true; } return false; } }); - // Gets the data repository in write mode + // Get data in write mode mDbHelper = new DBBusTo(this); db = mDbHelper.getWritableDatabase(); // Intercept calls from other part of the apps Bundle b = getIntent().getExtras(); - if(b != null) { + if (b != null) { String busStopID = b.getString("busStopID"); - if(busStopID != null) { + if (busStopID != null) { launchSearchAction(busStopID); - busStopNumberEditText.setText(busStopID); + busStopIDEditText.setText(busStopID); } } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { /* * case R.id.action_settings: Intent intentSettings = new * Intent(MainActivity.this,AboutActivity.class); * startActivity(intentSettings); return true; */ case R.id.action_about: Intent intentAbout = new Intent(MainActivity.this, AboutActivity.class); startActivity(intentAbout); return true; case R.id.action_favorites: Intent intentFavorites = new Intent(MainActivity.this, FavoritesActivity.class); startActivity(intentFavorites); return true; } return super.onOptionsItemSelected(item); } /** * Catch the Async action! * * @author boz */ public class MyAsyncWget extends AsyncWget { - protected void onPostExecute(String result) { - ArrayList> data = new ArrayList>(); - - BusStop busStop = GTTSiteSucker - .arrivalTimesBylineHTMLSucker(result); + protected void onPostExecute(String htmlResponse) { - // Remember that the user searched this at last - lastSearchedBusStopID = busStop.getBusStopID(); + // Network errors? + if (htmlResponse == null || exceptions != null) { + NetworkTools.showNetworkError(MainActivity.this); + stopSpinner(); + Log.e("MainActivity", "Network error!"); + return; + } - PassagesBusLine[] passagesBusLine = busStop.getPassagesBusLine(); + // Try sucking arrivals + BusStop busStop = GTTSiteSucker.getBusStopSuckingHTML(htmlResponse); - for (PassagesBusLine passageBusLine : passagesBusLine) { - HashMap singleEntry = new HashMap(); - singleEntry.put("icon", passageBusLine.getBusLineName()); - singleEntry.put("line-name", - passageBusLine.getTimePassagesString()); - data.add(singleEntry); + // Parse errors? + if (busStop == null) { + Toast.makeText(getApplicationContext(), + R.string.no_arrival_times, Toast.LENGTH_SHORT).show(); + stopSpinner(); + Log.e("MainActivity", "Parse error! htmlResponse: " + + htmlResponse); + return; } - if (passagesBusLine.length != 0) { - // Hide the keyboard before showing results - hideKeyboard(); + // Remember last successfully searched busStopID + Integer busStopID = busStop.getBusStopID(); + lastSearchedBusStopID = busStopID; - Integer busStopID = busStop.getBusStopID(); + // Retrieve passages + BusLinePassages[] passagesBusLine = busStop.getPassagesBusLine(); - String busStopName = busStop.getBusStopName(); - String busStopNameDisplay = "---"; - if (busStopName == null && busStopID != null) { - busStopNameDisplay = String.valueOf((busStopID)); - } else { - busStopNameDisplay = busStopName; - } - busStationName.setText(String.format( - getResources().getString(R.string.passages), - busStopNameDisplay)); - - // Insert the GTTBusStop in the DB - if (busStopID != null) { - ContentValues values = new ContentValues(); - values.put(DBBusTo.BusStop.COLUMN_NAME_BUSSTOP_ID, - busStopID); - values.put(DBBusTo.BusStop.COLUMN_NAME_BUSSTOP_NAME, - busStopName); - long lastInserted = db.insertWithOnConflict( - DBBusTo.BusStop.TABLE_NAME, null, values, - SQLiteDatabase.CONFLICT_IGNORE); - Log.d("bus-torino", "bustorinoDB last BusStop inserted: " - + lastInserted); - } - - // Show results - String[] from = { "icon", "line-name" }; - int[] to = { R.id.busLineIcon, R.id.busLine }; - SimpleAdapter adapter = new SimpleAdapter( - getApplicationContext(), data, R.layout.bus_line_passage_entry, - from, to); - - ListView tpm = (ListView) findViewById(R.id.resultsListView); - tpm.setAdapter(adapter); - tpm.setOnItemClickListener(new AdapterView.OnItemClickListener() { - public void onItemClick(AdapterView av, View view, - int i, long l) { - View child = av.getChildAt(i); - TextView busLineIcon = (TextView) child - .findViewById(R.id.busLineIcon); - String busLine = busLineIcon.getText().toString(); - Log.d("bus-torino", "bustorino tapped on busline: " + busLine); - //Toast.makeText(MainActivity.this, - // "myPos " + i + " " + busLineIcon.getText(), - // Toast.LENGTH_LONG).show(); - } - }); - } else { + // No passages? + if (passagesBusLine.length == 0) { Toast.makeText(getApplicationContext(), R.string.no_arrival_times, Toast.LENGTH_SHORT).show(); + stopSpinner(); + Log.d("MainActivity", "No passages!"); + return; } - annoyingFedbackProgressBar.setVisibility(View.INVISIBLE); - } - } + // Hide the keyboard before showing passages + hideKeyboard(); + + String busStopName = busStop.getBusStopName(); + String busStopNameDisplay; + if (busStopName == null) { + busStopNameDisplay = String.valueOf(busStopID); + } else { + busStopNameDisplay = busStopName; + } + busStopNameTextView.setText(String.format( + getString(R.string.passages), busStopNameDisplay)); + + // Insert GTTBusStop info in the DB + ContentValues values = new ContentValues(); + values.put(DBBusTo.BusStop.COLUMN_NAME_BUSSTOP_ID, busStopID); + values.put(DBBusTo.BusStop.COLUMN_NAME_BUSSTOP_NAME, busStopName); + long lastInserted = db.insertWithOnConflict( + DBBusTo.BusStop.TABLE_NAME, null, values, + SQLiteDatabase.CONFLICT_IGNORE); + Log.d("MainActivity", "DBBusTo last BusStopID inserted: " + + lastInserted); - public void searchClick(View v) { - String busStopID = busStopNumberEditText.getText().toString(); - launchSearchAction(busStopID); + // Populate the stupid ListView SimpleAdapter + ArrayList> entries = new ArrayList>(); + for (BusLinePassages passageBusLine : passagesBusLine) { + HashMap entry = new HashMap(); + String passages = passageBusLine.getTimePassagesString(); + if (passages == null) { + passages = getString(R.string.no_passages); + } + entry.put("icon", passageBusLine.getBusLineName()); + entry.put("passages", passages); + entries.add(entry); + } + + // Show results using the stupid SimpleAdapter + String[] from = { "icon", "passages" }; + int[] to = { R.id.busLineIcon, R.id.busLine }; + SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(), + entries, R.layout.bus_line_passage_entry, from, to); + resultsListView.setAdapter(adapter); + resultsListView + .setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView av, View view, + int i, long l) { + String busLine = ((TextView) av.getChildAt(i) + .findViewById(R.id.busLineIcon)).getText() + .toString(); + Log.d("MainActivity", "Tapped busLine: " + busLine); + } + }); + + stopSpinner(); + } } public void launchSearchAction(String busStopID) { if (busStopID.isEmpty()) { Toast.makeText(getApplicationContext(), R.string.insert_bus_stop_number, Toast.LENGTH_SHORT).show(); } else if (!NetworkTools.isConnected(this)) { NetworkTools.showNetworkError(this); } else { - annoyingFedbackProgressBar.setVisibility(View.VISIBLE); + startSpinner(); myAsyncWget.cancel(true); myAsyncWget = new MyAsyncWget(); - myAsyncWget.execute(GTTSiteSucker.arrivalTimesByLineQuery(busStopID)); + myAsyncWget.execute(GTTSiteSucker + .arrivalTimesByLineQuery(busStopID)); } } public void addInFavorites(View v) { if (lastSearchedBusStopID != null) { ContentValues newValues = new ContentValues(); newValues.put(DBBusTo.BusStop.COLUMN_NAME_BUSSTOP_ISFAVORITE, 1); db.update( DBBusTo.BusStop.TABLE_NAME, newValues, DBBusTo.somethingEqualsInt(DBBusTo.BusStop.COLUMN_NAME_BUSSTOP_ID), new String[] { String.valueOf(lastSearchedBusStopID) }); Toast.makeText(getApplicationContext(), R.string.added_in_favorites, Toast.LENGTH_SHORT).show(); } } + public void onSearchClick(View v) { + launchSearchAction(busStopIDEditText.getText().toString()); + } + + private void stopSpinner() { + annoyingSpinner.setVisibility(View.INVISIBLE); + } + + private void startSpinner() { + annoyingSpinner.setVisibility(View.VISIBLE); + } + private void hideKeyboard() { - InputMethodManager inputManager = (InputMethodManager) this - .getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - // Check if no view has focus: - View view = this.getCurrentFocus(); + // Check if no view has focus + View view = getCurrentFocus(); if (view != null) { inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } - /* - * private void spamThePoorUser() { AlertDialog.Builder alert = new - * AlertDialog.Builder(this); alert.setTitle(R.string.app_name); - * alert.setMessage(R.string.app_description); - * alert.setNegativeButton(android.R.string.ok, new - * DialogInterface.OnClickListener() { public void onClick(DialogInterface - * dialog, int whichButton) { } }); - * - * alert.show(); } - */ }