mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Add indeterminate progress bar
This commit is contained in:
parent
9cea643faa
commit
344b9a50eb
3 changed files with 25 additions and 16 deletions
|
|
@ -34,6 +34,7 @@ public class NearbyListFragment extends ListFragment {
|
||||||
|
|
||||||
private List<Place> places;
|
private List<Place> places;
|
||||||
private LatLng mLatestLocation;
|
private LatLng mLatestLocation;
|
||||||
|
private ProgressBar progressBar;
|
||||||
|
|
||||||
private static final String TAG = "NearbyListFragment";
|
private static final String TAG = "NearbyListFragment";
|
||||||
|
|
||||||
|
|
@ -45,8 +46,12 @@ public class NearbyListFragment extends ListFragment {
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
Log.d(TAG, "NearbyListFragment created");
|
Log.d(TAG, "NearbyListFragment created");
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.fragment_nearby, container, false);
|
View view = inflater.inflate(R.layout.fragment_nearby, container, false);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Create a progress bar to display while the list loads
|
// Create a progress bar to display while the list loads
|
||||||
|
|
@ -59,15 +64,10 @@ public class NearbyListFragment extends ListFragment {
|
||||||
ViewGroup root = (ViewGroup) view.getRootView();
|
ViewGroup root = (ViewGroup) view.getRootView();
|
||||||
root.addView(progressBar);
|
root.addView(progressBar);
|
||||||
*/
|
*/
|
||||||
|
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
|
||||||
|
progressBar.setMax(10);
|
||||||
return view;
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
}
|
progressBar.setProgress(0);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
//Load from data source (NearbyPlaces.java)
|
|
||||||
|
|
||||||
mLatestLocation = ((NearbyActivity) getActivity()).getmLatestLocation();
|
mLatestLocation = ((NearbyActivity) getActivity()).getmLatestLocation();
|
||||||
//Hardcoding mLatestLocation to Michigan for testing
|
//Hardcoding mLatestLocation to Michigan for testing
|
||||||
|
|
@ -100,7 +100,7 @@ public class NearbyListFragment extends ListFragment {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < places.size(); i++) {
|
for(int i = 0; i < 500; i++) {
|
||||||
Place place = places.get(i);
|
Place place = places.get(i);
|
||||||
String distance = formatDistanceBetween(mLatestLocation, place.location);
|
String distance = formatDistanceBetween(mLatestLocation, place.location);
|
||||||
System.out.println("Sorted " + place.name + " at " + distance + " away.");
|
System.out.println("Sorted " + place.name + " at " + distance + " away.");
|
||||||
|
|
@ -109,15 +109,16 @@ public class NearbyListFragment extends ListFragment {
|
||||||
return places;
|
return places;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class getNearbyPlaces extends AsyncTask<Void, String, List<Place>> {
|
private class getNearbyPlaces extends AsyncTask<Void, Integer, List<Place>> {
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
super.onPreExecute();
|
super.onPreExecute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onProgressUpdate(String... values) {
|
protected void onProgressUpdate(Integer... values) {
|
||||||
super.onProgressUpdate(values);
|
super.onProgressUpdate(values);
|
||||||
|
progressBar.setProgress(values[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -132,6 +133,8 @@ public class NearbyListFragment extends ListFragment {
|
||||||
|
|
||||||
mAdapter = new NearbyAdapter(getActivity(), places);
|
mAdapter = new NearbyAdapter(getActivity(), places);
|
||||||
|
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
|
||||||
ListView listview = (ListView) getView().findViewById(R.id.listview);
|
ListView listview = (ListView) getView().findViewById(R.id.listview);
|
||||||
//setListAdapter(mAdapter);
|
//setListAdapter(mAdapter);
|
||||||
listview.setAdapter(mAdapter);
|
listview.setAdapter(mAdapter);
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ public class NearbyPlaces {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
//TODO: Remove limit of lines after get AsyncTask done
|
//TODO: Remove limit of lines after get AsyncTask done
|
||||||
//while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
while (in.readLine() != null && counter < 500) {
|
//while (in.readLine() != null && counter < 1000) {
|
||||||
|
|
||||||
line = in.readLine();
|
line = in.readLine();
|
||||||
counter++;
|
counter++;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,12 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progressBar"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerInParent="true" />
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/listview"
|
android:id="@+id/listview"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue