Skip to content

Commit

Permalink
Added small progressbar spinner when fetching autocomplete data.
Browse files Browse the repository at this point in the history
  • Loading branch information
dan1el committed Nov 8, 2012
1 parent c3fbad8 commit ab92c76
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
21 changes: 18 additions & 3 deletions application/res/layout/fragment_section_realtime.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
android:background="@drawable/list_background"
android:padding="5dp" >

<ProgressBar
android:id="@+id/autoCompleteProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/realtimeAutoCompleteView"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/realtimeAutoCompleteView" />

<AutoCompleteTextView
android:id="@+id/realtimeAutoCompleteView"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:ems="10"
android:hint="stoppested"
android:inputType="textAutoComplete"
Expand All @@ -37,4 +44,12 @@
android:layout_below="@+id/relativeLayout1" >
</ListView>

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ public class RealtimeSectionFragment extends Fragment {
private ListView realTimeResultsListView;
private List<RealTimeData> realTimeData;

private ProgressBar progressBar;
private ProgressBar autoCompleteProgressBar;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// The last two arguments ensure LayoutParams are inflated
// properly.
rootView = inflater.inflate(R.layout.fragment_section_realtime, container, false);
Bundle args = getArguments();

progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
progressBar.setVisibility(ProgressBar.GONE);

autoCompleteProgressBar = (ProgressBar) rootView.findViewById(R.id.autoCompleteProgressBar);
autoCompleteProgressBar.setVisibility(ProgressBar.INVISIBLE);

setUpResultListView();
setUpAutoCompleteTextViews();

Expand Down Expand Up @@ -73,7 +82,9 @@ public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
// If we have a selectedLocation do a search on that ID
// If not we have to do a places search on the string
if(selectedLocation != null) {
progressBar.setVisibility(ProgressBar.VISIBLE);
realTimeData = getRealTimeData(selectedLocation.getId());
progressBar.setVisibility(ProgressBar.GONE);
}
realTimeListViewAdapter.clear();
realTimeListViewAdapter.addAll(realTimeData);
Expand Down Expand Up @@ -137,13 +148,19 @@ protected String doInBackground(String... location) {
return null;
}

@Override
protected void onPreExecute() {
autoCompleteProgressBar.setVisibility(ProgressBar.VISIBLE);
}

// Need to call notifyDataSetChanged on the UI thread
@Override
protected void onPostExecute(String result) {
// TODO: Why does it not show up on the first update? Triggers at second update
// TODO: Should we clear, or just avoid duplicates?
realTimeAutoCompleteAdapter.clear();
realTimeAutoCompleteAdapter.addAll(realTimeLocations);
autoCompleteProgressBar.setVisibility(ProgressBar.INVISIBLE);
}
}

Expand Down

0 comments on commit ab92c76

Please sign in to comment.