diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2015-10-26 08:32:08 +0100 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2015-10-26 10:53:14 +0100 |
commit | 388636b058fed19c37c4d21b3ffc23ecf5103654 (patch) | |
tree | e2895d9d8074035a946494bc23640ff58bf04546 | |
parent | bf8c5feb0bf25a038ac43580eed453d8fb822534 (diff) | |
download | qtlocation-mapboxgl-388636b058fed19c37c4d21b3ffc23ecf5103654.tar.gz |
[android] #2726 - finalise BulkAddMarkers activity
3 files changed, 61 insertions, 9 deletions
diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java index 3bddf4e32e..eeed77d5c6 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java @@ -1,19 +1,25 @@ package com.mapbox.mapboxsdk.testapp; +import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; -import android.os.Debug; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngZoom; +import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil; +import com.mapbox.mapboxsdk.testapp.utils.TimingLogger; import com.mapbox.mapboxsdk.utils.ApiAccess; import com.mapbox.mapboxsdk.views.MapView; @@ -25,20 +31,21 @@ import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; -public class BulkMarkerActivity extends AppCompatActivity { +public class BulkMarkerActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { private MapView mMapView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_infowindow); + setContentView(R.layout.activity_marker_bulk); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { + actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); } @@ -49,7 +56,22 @@ public class BulkMarkerActivity extends AppCompatActivity { mMapView.setCenterCoordinate(new LatLngZoom(38.87031, -77.00897, 10)); mMapView.setCompassEnabled(false); - new LoadBulkMarkerTask(mMapView, 27267).execute(); + ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.bulk_marker_list, android.R.layout.simple_spinner_item); + spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + Spinner spinner = (Spinner) findViewById(R.id.spinner); + spinner.setAdapter(spinnerAdapter); + spinner.setOnItemSelectedListener(this); + } + + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + int markersAmount = Integer.valueOf(getResources().getStringArray(R.array.bulk_marker_list)[position]); + new LoadBulkMarkerTask(mMapView, markersAmount).execute(); + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + } @Override @@ -105,16 +127,20 @@ public class BulkMarkerActivity extends AppCompatActivity { } } - private static class LoadBulkMarkerTask extends AsyncTask<Void, Void, List<MarkerOptions>> { + private static class LoadBulkMarkerTask extends AsyncTask<Void, Integer, List<MarkerOptions>> { private static final String TAG = "LoadBulkMarkerTask"; private WeakReference<MapView> mMapView; private Context mAppContext; + private ProgressDialog mProgressDialog; private int mAmount; public LoadBulkMarkerTask(MapView mapView, int amount) { + Context context = mapView.getContext(); + mapView.removeAllAnnotations(); mMapView = new WeakReference<>(mapView); - mAppContext = mapView.getContext().getApplicationContext(); + mProgressDialog = ProgressDialog.show(context, "Loading", "Fetching markers", false); + mAppContext = context.getApplicationContext(); mAmount = amount; } @@ -130,15 +156,21 @@ public class BulkMarkerActivity extends AppCompatActivity { try { DecimalFormat formatter = new DecimalFormat("#.#####"); - String json = Util.loadStringFromAssets(mAppContext, "points.geojson"); + String json = GeoParseUtil.loadStringFromAssets(mAppContext, "points.geojson"); timings.addSplit("loadStringFromAssets"); - List<LatLng> locations = Util.parseGeoJSONCoordinates(json); + List<LatLng> locations = GeoParseUtil.parseGeoJSONCoordinates(json); + timings.addSplit("parseGeoJSONCoordinates"); + if (locations.size() < mAmount) { + mAmount = locations.size(); + } + LatLng location; for (int i = 0; i < mAmount; i++) { location = locations.get(i); + Log.v(TAG, "marker " + i + " of " + mAmount + " added with " + location.getLatitude() + " " + location.getLongitude()); markerOptions.add(new MarkerOptions() .position(location) .title("Marker") @@ -155,6 +187,11 @@ public class BulkMarkerActivity extends AppCompatActivity { } @Override + protected void onProgressUpdate(Integer... values) { + super.onProgressUpdate(values); + } + + @Override protected void onPostExecute(List<MarkerOptions> markerOptions) { super.onPostExecute(markerOptions); TimingLogger timings = new TimingLogger(TAG, "onPostExecute"); @@ -167,6 +204,7 @@ public class BulkMarkerActivity extends AppCompatActivity { timings.addSplit("addMarkers"); timings.dumpToLog(); + mProgressDialog.hide(); //Debug.stopMethodTracing(); } } diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml index 24dfe110af..efca94e8a2 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml +++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml @@ -10,7 +10,14 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/primary" - android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> + + <Spinner + android:id="@+id/spinner" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + + </android.support.v7.widget.Toolbar> <com.mapbox.mapboxsdk.views.MapView android:id="@+id/mapView" diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 94c089146a..e47c4643af 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -43,4 +43,11 @@ <item>Night</item> </string-array> + <string-array name="bulk_marker_list"> + <item>10</item> + <item>100</item> + <item>1000</item> + <item>10000</item> + </string-array> + </resources> |