[android] #3276 - only update thumb Icon when needed, disabled background task for now, added view pool counter
This commit is contained in:
@@ -250,8 +250,6 @@ public class MapView extends FrameLayout {
|
||||
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
|
||||
mMapboxMap.getUiSettings().setZoomControlsEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void setInitialState(MapboxMapOptions options) {
|
||||
@@ -479,19 +477,19 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
|
||||
mViewMarkerBoundsUpdateTime = currentTime + 300;
|
||||
new ViewMarkerInBoundsTask().execute();
|
||||
}
|
||||
// new ViewMarkerInBoundsTask().execute();
|
||||
// }
|
||||
|
||||
public class ViewMarkerInBoundsTask extends AsyncTask<Void, Void, ViewMarkerInBoundsTask.Result> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
// public class ViewMarkerInBoundsTask extends AsyncTask<Void, Void, ViewMarkerInBoundsTask.Result> {
|
||||
//
|
||||
// @Override
|
||||
// protected void onPreExecute() {
|
||||
// super.onPreExecute();
|
||||
mViewMarkersUpdateRunning = true;
|
||||
}
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected Result doInBackground(Void... params) {
|
||||
// @Override
|
||||
// protected Result doInBackground(Void... params) {
|
||||
List<Marker> inBounds = new ArrayList<>();
|
||||
Map<Marker, View> outBounds = new HashMap<>();
|
||||
|
||||
@@ -544,13 +542,14 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
}
|
||||
Result result = new Result(inBounds, outBounds);
|
||||
|
||||
return new Result(inBounds, outBounds);
|
||||
}
|
||||
// return new Result(inBounds, outBounds);
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Result result) {
|
||||
super.onPostExecute(result);
|
||||
// @Override
|
||||
// protected void onPostExecute(Result result) {
|
||||
// super.onPostExecute(result);
|
||||
mMapboxMap.setViewMarkersBoundsTaskResult(result);
|
||||
mViewMarkersUpdateRunning = false;
|
||||
Log.v(MapboxConstants.TAG, "Amount of child views " + getChildCount());
|
||||
@@ -573,7 +572,7 @@ public class MapView extends FrameLayout {
|
||||
return outBounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link android.app.Activity#onSaveInstanceState(Bundle)}
|
||||
|
||||
@@ -638,7 +638,7 @@ public class MapboxMap {
|
||||
// Annotations
|
||||
//
|
||||
|
||||
void setViewMarkersBoundsTaskResult(MapView.ViewMarkerInBoundsTask.Result result) {
|
||||
void setViewMarkersBoundsTaskResult(MapView.Result result) {
|
||||
Map<Marker, View> outBoundsMarker = result.getOutBounds();
|
||||
View convertView;
|
||||
|
||||
@@ -660,11 +660,13 @@ public class MapboxMap {
|
||||
if (adaptedView != null) {
|
||||
// hack to hide old marker, todo replace with visibility
|
||||
Icon icon = marker.getIcon();
|
||||
if(mViewMarkerBitmap==null){
|
||||
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
|
||||
mViewMarkerBitmap = Bitmap.createBitmap(icon.getBitmap().getWidth(), icon.getBitmap().getHeight(), conf);
|
||||
if(!icon.getBitmap().equals(mViewMarkerBitmap)) {
|
||||
if (mViewMarkerBitmap == null) {
|
||||
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
|
||||
mViewMarkerBitmap = Bitmap.createBitmap(icon.getBitmap().getWidth(), icon.getBitmap().getHeight(), conf);
|
||||
}
|
||||
marker.setIcon(IconFactory.recreate(icon.getId(), mViewMarkerBitmap));
|
||||
}
|
||||
marker.setIcon(IconFactory.recreate(icon.getId(), mViewMarkerBitmap));
|
||||
adaptedView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@@ -74,6 +74,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
|
||||
});
|
||||
|
||||
final View fab = findViewById(R.id.fab);
|
||||
final TextView viewCountView = (TextView) findViewById(R.id.countView);
|
||||
if (fab != null) {
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -81,6 +82,22 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
|
||||
if (mMapboxMap != null) {
|
||||
fab.animate().alpha(0).start();
|
||||
mMapboxMap.setMarkerViewAdapter(new TextAdapter(BulkMarkerActivity.this));
|
||||
mMapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
|
||||
@Override
|
||||
public void onMapChanged(@MapView.MapChange int change) {
|
||||
if (change == MapView.REGION_IS_CHANGING || change == MapView.REGION_DID_CHANGE) {
|
||||
if (mMapboxMap.getMarkerViewAdapter() != null) {
|
||||
viewCountView.setText("ViewCache size " + (mMapView.getChildCount()-5));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
mMapboxMap.setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
|
||||
@Override
|
||||
public void onMarkerClick(@NonNull Marker marker, @NonNull View view) {
|
||||
mMapboxMap.selectMarker(marker);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -28,6 +28,13 @@
|
||||
app:style_url="@string/style_mapbox_streets"
|
||||
app:zoom="10" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/countView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/toolbar"
|
||||
android:padding="16dp"
|
||||
android:textSize="20sp"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
|
||||
Reference in New Issue
Block a user