package com.google.maps.android.clustering.view; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.TimeInterpolator; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.OvalShape; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.MessageQueue; import android.util.SparseArray; import android.view.ViewGroup; import android.view.animation.DecelerateInterpolator; import androidx.compose.runtime.ComposerKt; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.Projection; import com.google.android.gms.maps.model.BitmapDescriptor; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import com.google.maps.android.R; import com.google.maps.android.clustering.Cluster; import com.google.maps.android.clustering.ClusterItem; import com.google.maps.android.clustering.ClusterManager; import com.google.maps.android.collections.MarkerManager; import com.google.maps.android.geometry.Point; import com.google.maps.android.projection.SphericalMercatorProjection; import com.google.maps.android.ui.IconGenerator; import com.google.maps.android.ui.SquareTextView; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; /* JADX INFO: loaded from: classes2.dex */ public class DefaultClusterRenderer implements ClusterRenderer { private ClusterManager.OnClusterClickListener mClickListener; private final ClusterManager mClusterManager; private MarkerCache> mClusterMarkerCache; private Set> mClusters; private ShapeDrawable mColoredCircleBackground; private final float mDensity; private final IconGenerator mIconGenerator; private ClusterManager.OnClusterInfoWindowClickListener mInfoWindowClickListener; private ClusterManager.OnClusterInfoWindowLongClickListener mInfoWindowLongClickListener; private ClusterManager.OnClusterItemClickListener mItemClickListener; private ClusterManager.OnClusterItemInfoWindowClickListener mItemInfoWindowClickListener; private ClusterManager.OnClusterItemInfoWindowLongClickListener mItemInfoWindowLongClickListener; private final GoogleMap mMap; private MarkerCache mMarkerCache; private final DefaultClusterRenderer.ViewModifier mViewModifier; private float mZoom; private static final int[] BUCKETS = {10, 20, 50, 100, ComposerKt.invocationKey, 500, 1000}; private static final TimeInterpolator ANIMATION_INTERP = new DecelerateInterpolator(); private final Executor mExecutor = Executors.newSingleThreadExecutor(); private Set mMarkers = Collections.newSetFromMap(new ConcurrentHashMap()); private SparseArray mIcons = new SparseArray<>(); private int mMinClusterSize = 4; private boolean mAnimate = true; private long mAnimationDurationMs = 300; protected void onClusterItemRendered(T t, Marker marker) { } protected void onClusterRendered(Cluster cluster, Marker marker) { } public DefaultClusterRenderer(Context context, GoogleMap googleMap, ClusterManager clusterManager) { this.mMarkerCache = new MarkerCache<>(); this.mClusterMarkerCache = new MarkerCache<>(); this.mViewModifier = new ViewModifier(); this.mMap = googleMap; this.mDensity = context.getResources().getDisplayMetrics().density; IconGenerator iconGenerator = new IconGenerator(context); this.mIconGenerator = iconGenerator; iconGenerator.setContentView(makeSquareTextView(context)); iconGenerator.setTextAppearance(R.style.amu_ClusterIcon_TextAppearance); iconGenerator.setBackground(makeClusterBackground()); this.mClusterManager = clusterManager; } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void onAdd() { this.mClusterManager.getMarkerCollection().setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { // from class: com.google.maps.android.clustering.view.DefaultClusterRenderer.1 /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.android.gms.maps.GoogleMap.OnMarkerClickListener public boolean onMarkerClick(Marker marker) { return DefaultClusterRenderer.this.mItemClickListener != null && DefaultClusterRenderer.this.mItemClickListener.onClusterItemClick((ClusterItem) DefaultClusterRenderer.this.mMarkerCache.get(marker)); } }); this.mClusterManager.getMarkerCollection().setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { // from class: com.google.maps.android.clustering.view.DefaultClusterRenderer.2 /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener public void onInfoWindowClick(Marker marker) { if (DefaultClusterRenderer.this.mItemInfoWindowClickListener != null) { DefaultClusterRenderer.this.mItemInfoWindowClickListener.onClusterItemInfoWindowClick((ClusterItem) DefaultClusterRenderer.this.mMarkerCache.get(marker)); } } }); this.mClusterManager.getMarkerCollection().setOnInfoWindowLongClickListener(new GoogleMap.OnInfoWindowLongClickListener() { // from class: com.google.maps.android.clustering.view.DefaultClusterRenderer$$ExternalSyntheticLambda0 @Override // com.google.android.gms.maps.GoogleMap.OnInfoWindowLongClickListener public final void onInfoWindowLongClick(Marker marker) { this.f$0.m7759x54249de(marker); } }); this.mClusterManager.getClusterMarkerCollection().setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { // from class: com.google.maps.android.clustering.view.DefaultClusterRenderer$$ExternalSyntheticLambda1 @Override // com.google.android.gms.maps.GoogleMap.OnMarkerClickListener public final boolean onMarkerClick(Marker marker) { return this.f$0.m7760x83a34dbd(marker); } }); this.mClusterManager.getClusterMarkerCollection().setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { // from class: com.google.maps.android.clustering.view.DefaultClusterRenderer$$ExternalSyntheticLambda2 @Override // com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener public final void onInfoWindowClick(Marker marker) { this.f$0.m7761x204519c(marker); } }); this.mClusterManager.getClusterMarkerCollection().setOnInfoWindowLongClickListener(new GoogleMap.OnInfoWindowLongClickListener() { // from class: com.google.maps.android.clustering.view.DefaultClusterRenderer$$ExternalSyntheticLambda3 @Override // com.google.android.gms.maps.GoogleMap.OnInfoWindowLongClickListener public final void onInfoWindowLongClick(Marker marker) { this.f$0.m7762x8065557b(marker); } }); } /* JADX INFO: renamed from: lambda$onAdd$0$com-google-maps-android-clustering-view-DefaultClusterRenderer, reason: not valid java name */ /* synthetic */ void m7759x54249de(Marker marker) { ClusterManager.OnClusterItemInfoWindowLongClickListener onClusterItemInfoWindowLongClickListener = this.mItemInfoWindowLongClickListener; if (onClusterItemInfoWindowLongClickListener != null) { onClusterItemInfoWindowLongClickListener.onClusterItemInfoWindowLongClick(this.mMarkerCache.get(marker)); } } /* JADX INFO: renamed from: lambda$onAdd$1$com-google-maps-android-clustering-view-DefaultClusterRenderer, reason: not valid java name */ /* synthetic */ boolean m7760x83a34dbd(Marker marker) { ClusterManager.OnClusterClickListener onClusterClickListener = this.mClickListener; return onClusterClickListener != null && onClusterClickListener.onClusterClick(this.mClusterMarkerCache.get(marker)); } /* JADX INFO: renamed from: lambda$onAdd$2$com-google-maps-android-clustering-view-DefaultClusterRenderer, reason: not valid java name */ /* synthetic */ void m7761x204519c(Marker marker) { ClusterManager.OnClusterInfoWindowClickListener onClusterInfoWindowClickListener = this.mInfoWindowClickListener; if (onClusterInfoWindowClickListener != null) { onClusterInfoWindowClickListener.onClusterInfoWindowClick(this.mClusterMarkerCache.get(marker)); } } /* JADX INFO: renamed from: lambda$onAdd$3$com-google-maps-android-clustering-view-DefaultClusterRenderer, reason: not valid java name */ /* synthetic */ void m7762x8065557b(Marker marker) { ClusterManager.OnClusterInfoWindowLongClickListener onClusterInfoWindowLongClickListener = this.mInfoWindowLongClickListener; if (onClusterInfoWindowLongClickListener != null) { onClusterInfoWindowLongClickListener.onClusterInfoWindowLongClick(this.mClusterMarkerCache.get(marker)); } } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void onRemove() { this.mClusterManager.getMarkerCollection().setOnMarkerClickListener(null); this.mClusterManager.getMarkerCollection().setOnInfoWindowClickListener(null); this.mClusterManager.getMarkerCollection().setOnInfoWindowLongClickListener(null); this.mClusterManager.getClusterMarkerCollection().setOnMarkerClickListener(null); this.mClusterManager.getClusterMarkerCollection().setOnInfoWindowClickListener(null); this.mClusterManager.getClusterMarkerCollection().setOnInfoWindowLongClickListener(null); } private LayerDrawable makeClusterBackground() { this.mColoredCircleBackground = new ShapeDrawable(new OvalShape()); ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); shapeDrawable.getPaint().setColor(-2130706433); LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{shapeDrawable, this.mColoredCircleBackground}); int i = (int) (this.mDensity * 3.0f); layerDrawable.setLayerInset(1, i, i, i, i); return layerDrawable; } private SquareTextView makeSquareTextView(Context context) { SquareTextView squareTextView = new SquareTextView(context); squareTextView.setLayoutParams(new ViewGroup.LayoutParams(-2, -2)); squareTextView.setId(R.id.amu_text); int i = (int) (this.mDensity * 12.0f); squareTextView.setPadding(i, i, i, i); return squareTextView; } @Override // com.google.maps.android.clustering.view.ClusterRenderer public int getColor(int i) { float fMin = 300.0f - Math.min(i, 300.0f); return Color.HSVToColor(new float[]{((fMin * fMin) / 90000.0f) * 220.0f, 1.0f, 0.6f}); } @Override // com.google.maps.android.clustering.view.ClusterRenderer public int getClusterTextAppearance(int i) { return R.style.amu_ClusterIcon_TextAppearance; } protected String getClusterText(int i) { if (i < BUCKETS[0]) { return String.valueOf(i); } return i + org.slf4j.Marker.ANY_NON_NULL_MARKER; } protected int getBucket(Cluster cluster) { int size = cluster.getSize(); int i = 0; if (size <= BUCKETS[0]) { return size; } while (true) { int[] iArr = BUCKETS; if (i < iArr.length - 1) { int i2 = i + 1; if (size < iArr[i2]) { return iArr[i]; } i = i2; } else { return iArr[iArr.length - 1]; } } } public int getMinClusterSize() { return this.mMinClusterSize; } public void setMinClusterSize(int i) { this.mMinClusterSize = i; } /* JADX INFO: Access modifiers changed from: private */ class ViewModifier extends Handler { private static final int RUN_TASK = 0; private static final int TASK_FINISHED = 1; private DefaultClusterRenderer.RenderTask mNextClusters; private boolean mViewModificationInProgress; private ViewModifier() { this.mViewModificationInProgress = false; this.mNextClusters = null; } @Override // android.os.Handler public void handleMessage(Message message) { DefaultClusterRenderer.RenderTask renderTask; if (message.what == 1) { this.mViewModificationInProgress = false; if (this.mNextClusters != null) { sendEmptyMessage(0); return; } return; } removeMessages(0); if (this.mViewModificationInProgress || this.mNextClusters == null) { return; } Projection projection = DefaultClusterRenderer.this.mMap.getProjection(); synchronized (this) { renderTask = this.mNextClusters; this.mNextClusters = null; this.mViewModificationInProgress = true; } renderTask.setCallback(new Runnable() { // from class: com.google.maps.android.clustering.view.DefaultClusterRenderer$ViewModifier$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { this.f$0.m7763xef9a7a7f(); } }); renderTask.setProjection(projection); renderTask.setMapZoom(DefaultClusterRenderer.this.mMap.getCameraPosition().zoom); DefaultClusterRenderer.this.mExecutor.execute(renderTask); } /* JADX INFO: renamed from: lambda$handleMessage$0$com-google-maps-android-clustering-view-DefaultClusterRenderer$ViewModifier, reason: not valid java name */ /* synthetic */ void m7763xef9a7a7f() { sendEmptyMessage(1); } public void queue(Set> set) { synchronized (this) { this.mNextClusters = new RenderTask(set); } sendEmptyMessage(0); } } protected boolean shouldRenderAsCluster(Cluster cluster) { return cluster.getSize() >= this.mMinClusterSize; } protected boolean shouldRender(Set> set, Set> set2) { return !set2.equals(set); } private class RenderTask implements Runnable { final Set> clusters; private Runnable mCallback; private float mMapZoom; private Projection mProjection; private SphericalMercatorProjection mSphericalMercatorProjection; private RenderTask(Set> set) { this.clusters = set; } public void setCallback(Runnable runnable) { this.mCallback = runnable; } public void setProjection(Projection projection) { this.mProjection = projection; } public void setMapZoom(float f) { this.mMapZoom = f; this.mSphericalMercatorProjection = new SphericalMercatorProjection(Math.pow(2.0d, Math.min(f, DefaultClusterRenderer.this.mZoom)) * 256.0d); } @Override // java.lang.Runnable public void run() { LatLngBounds latLngBoundsBuild; ArrayList arrayList; DefaultClusterRenderer defaultClusterRenderer = DefaultClusterRenderer.this; if (!defaultClusterRenderer.shouldRender(defaultClusterRenderer.immutableOf(defaultClusterRenderer.mClusters), DefaultClusterRenderer.this.immutableOf(this.clusters))) { this.mCallback.run(); return; } ArrayList arrayList2 = null; MarkerModifier markerModifier = new MarkerModifier(); float f = this.mMapZoom; boolean z = f > DefaultClusterRenderer.this.mZoom; float f2 = f - DefaultClusterRenderer.this.mZoom; Set set = DefaultClusterRenderer.this.mMarkers; try { latLngBoundsBuild = this.mProjection.getVisibleRegion().latLngBounds; } catch (Exception e) { e.printStackTrace(); latLngBoundsBuild = LatLngBounds.builder().include(new LatLng(0.0d, 0.0d)).build(); } if (DefaultClusterRenderer.this.mClusters == null || !DefaultClusterRenderer.this.mAnimate) { arrayList = null; } else { arrayList = new ArrayList(); for (Cluster cluster : DefaultClusterRenderer.this.mClusters) { if (DefaultClusterRenderer.this.shouldRenderAsCluster(cluster) && latLngBoundsBuild.contains(cluster.getPosition())) { arrayList.add(this.mSphericalMercatorProjection.toPoint(cluster.getPosition())); } } } Set setNewSetFromMap = Collections.newSetFromMap(new ConcurrentHashMap()); for (Cluster cluster2 : this.clusters) { boolean zContains = latLngBoundsBuild.contains(cluster2.getPosition()); if (z && zContains && DefaultClusterRenderer.this.mAnimate) { Point pointFindClosestCluster = DefaultClusterRenderer.this.findClosestCluster(arrayList, this.mSphericalMercatorProjection.toPoint(cluster2.getPosition())); if (pointFindClosestCluster != null) { markerModifier.add(true, new CreateMarkerTask(cluster2, setNewSetFromMap, this.mSphericalMercatorProjection.toLatLng(pointFindClosestCluster))); } else { markerModifier.add(true, new CreateMarkerTask(cluster2, setNewSetFromMap, null)); } } else { markerModifier.add(zContains, new CreateMarkerTask(cluster2, setNewSetFromMap, null)); } } markerModifier.waitUntilFree(); set.removeAll(setNewSetFromMap); if (DefaultClusterRenderer.this.mAnimate) { arrayList2 = new ArrayList(); for (Cluster cluster3 : this.clusters) { if (DefaultClusterRenderer.this.shouldRenderAsCluster(cluster3) && latLngBoundsBuild.contains(cluster3.getPosition())) { arrayList2.add(this.mSphericalMercatorProjection.toPoint(cluster3.getPosition())); } } } for (MarkerWithPosition markerWithPosition : set) { boolean zContains2 = latLngBoundsBuild.contains(markerWithPosition.position); if (!z && f2 > -3.0f && zContains2 && DefaultClusterRenderer.this.mAnimate) { Point pointFindClosestCluster2 = DefaultClusterRenderer.this.findClosestCluster(arrayList2, this.mSphericalMercatorProjection.toPoint(markerWithPosition.position)); if (pointFindClosestCluster2 != null) { markerModifier.animateThenRemove(markerWithPosition, markerWithPosition.position, this.mSphericalMercatorProjection.toLatLng(pointFindClosestCluster2)); } else { markerModifier.remove(true, markerWithPosition.marker); } } else { markerModifier.remove(zContains2, markerWithPosition.marker); } } markerModifier.waitUntilFree(); DefaultClusterRenderer.this.mMarkers = setNewSetFromMap; DefaultClusterRenderer.this.mClusters = this.clusters; DefaultClusterRenderer.this.mZoom = f; this.mCallback.run(); } } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void onClustersChanged(Set> set) { this.mViewModifier.queue(set); } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void setOnClusterClickListener(ClusterManager.OnClusterClickListener onClusterClickListener) { this.mClickListener = onClusterClickListener; } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void setOnClusterInfoWindowClickListener(ClusterManager.OnClusterInfoWindowClickListener onClusterInfoWindowClickListener) { this.mInfoWindowClickListener = onClusterInfoWindowClickListener; } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void setOnClusterInfoWindowLongClickListener(ClusterManager.OnClusterInfoWindowLongClickListener onClusterInfoWindowLongClickListener) { this.mInfoWindowLongClickListener = onClusterInfoWindowLongClickListener; } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void setOnClusterItemClickListener(ClusterManager.OnClusterItemClickListener onClusterItemClickListener) { this.mItemClickListener = onClusterItemClickListener; } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void setOnClusterItemInfoWindowClickListener(ClusterManager.OnClusterItemInfoWindowClickListener onClusterItemInfoWindowClickListener) { this.mItemInfoWindowClickListener = onClusterItemInfoWindowClickListener; } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void setOnClusterItemInfoWindowLongClickListener(ClusterManager.OnClusterItemInfoWindowLongClickListener onClusterItemInfoWindowLongClickListener) { this.mItemInfoWindowLongClickListener = onClusterItemInfoWindowLongClickListener; } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void setAnimation(boolean z) { this.mAnimate = z; } @Override // com.google.maps.android.clustering.view.ClusterRenderer public void setAnimationDuration(long j) { this.mAnimationDurationMs = j; } /* JADX INFO: Access modifiers changed from: private */ public Set> immutableOf(Set> set) { return set != null ? Collections.unmodifiableSet(set) : Collections.emptySet(); } private static double distanceSquared(Point point, Point point2) { return ((point.x - point2.x) * (point.x - point2.x)) + ((point.y - point2.y) * (point.y - point2.y)); } /* JADX INFO: Access modifiers changed from: private */ public Point findClosestCluster(List list, Point point) { Point point2 = null; if (list != null && !list.isEmpty()) { int maxDistanceBetweenClusteredItems = this.mClusterManager.getAlgorithm().getMaxDistanceBetweenClusteredItems(); double d = maxDistanceBetweenClusteredItems * maxDistanceBetweenClusteredItems; for (Point point3 : list) { double dDistanceSquared = distanceSquared(point3, point); if (dDistanceSquared < d) { point2 = point3; d = dDistanceSquared; } } } return point2; } private class MarkerModifier extends Handler implements MessageQueue.IdleHandler { private static final int BLANK = 0; private final Condition busyCondition; private final Lock lock; private Queue.AnimationTask> mAnimationTasks; private Queue.CreateMarkerTask> mCreateMarkerTasks; private boolean mListenerAdded; private Queue.CreateMarkerTask> mOnScreenCreateMarkerTasks; private Queue mOnScreenRemoveMarkerTasks; private Queue mRemoveMarkerTasks; private MarkerModifier() { super(Looper.getMainLooper()); ReentrantLock reentrantLock = new ReentrantLock(); this.lock = reentrantLock; this.busyCondition = reentrantLock.newCondition(); this.mCreateMarkerTasks = new LinkedList(); this.mOnScreenCreateMarkerTasks = new LinkedList(); this.mRemoveMarkerTasks = new LinkedList(); this.mOnScreenRemoveMarkerTasks = new LinkedList(); this.mAnimationTasks = new LinkedList(); } public void add(boolean z, DefaultClusterRenderer.CreateMarkerTask createMarkerTask) { this.lock.lock(); sendEmptyMessage(0); if (z) { this.mOnScreenCreateMarkerTasks.add(createMarkerTask); } else { this.mCreateMarkerTasks.add(createMarkerTask); } this.lock.unlock(); } public void remove(boolean z, Marker marker) { this.lock.lock(); sendEmptyMessage(0); if (z) { this.mOnScreenRemoveMarkerTasks.add(marker); } else { this.mRemoveMarkerTasks.add(marker); } this.lock.unlock(); } public void animate(MarkerWithPosition markerWithPosition, LatLng latLng, LatLng latLng2) { this.lock.lock(); this.mAnimationTasks.add(new AnimationTask(markerWithPosition, latLng, latLng2)); this.lock.unlock(); } public void animateThenRemove(MarkerWithPosition markerWithPosition, LatLng latLng, LatLng latLng2) { this.lock.lock(); DefaultClusterRenderer.AnimationTask animationTask = new AnimationTask(markerWithPosition, latLng, latLng2); animationTask.removeOnAnimationComplete(DefaultClusterRenderer.this.mClusterManager.getMarkerManager()); this.mAnimationTasks.add(animationTask); this.lock.unlock(); } @Override // android.os.Handler public void handleMessage(Message message) { if (!this.mListenerAdded) { Looper.myQueue().addIdleHandler(this); this.mListenerAdded = true; } removeMessages(0); this.lock.lock(); for (int i = 0; i < 10; i++) { try { performNextTask(); } finally { this.lock.unlock(); } } if (!isBusy()) { this.mListenerAdded = false; Looper.myQueue().removeIdleHandler(this); this.busyCondition.signalAll(); } else { sendEmptyMessageDelayed(0, 10L); } } private void performNextTask() { if (!this.mOnScreenRemoveMarkerTasks.isEmpty()) { removeMarker(this.mOnScreenRemoveMarkerTasks.poll()); return; } if (!this.mAnimationTasks.isEmpty()) { this.mAnimationTasks.poll().perform(); return; } if (this.mOnScreenCreateMarkerTasks.isEmpty()) { if (this.mCreateMarkerTasks.isEmpty()) { if (this.mRemoveMarkerTasks.isEmpty()) { return; } removeMarker(this.mRemoveMarkerTasks.poll()); return; } this.mCreateMarkerTasks.poll().perform(this); return; } this.mOnScreenCreateMarkerTasks.poll().perform(this); } private void removeMarker(Marker marker) { DefaultClusterRenderer.this.mMarkerCache.remove(marker); DefaultClusterRenderer.this.mClusterMarkerCache.remove(marker); DefaultClusterRenderer.this.mClusterManager.getMarkerManager().remove(marker); } /* JADX WARN: Removed duplicated region for block: B:14:0x0030 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public boolean isBusy() { /* r2 = this; java.util.concurrent.locks.Lock r0 = r2.lock // Catch: java.lang.Throwable -> L37 r0.lock() // Catch: java.lang.Throwable -> L37 java.util.Queue$CreateMarkerTask> r0 = r2.mCreateMarkerTasks // Catch: java.lang.Throwable -> L37 boolean r0 = r0.isEmpty() // Catch: java.lang.Throwable -> L37 if (r0 == 0) goto L30 java.util.Queue$CreateMarkerTask> r0 = r2.mOnScreenCreateMarkerTasks // Catch: java.lang.Throwable -> L37 boolean r0 = r0.isEmpty() // Catch: java.lang.Throwable -> L37 if (r0 == 0) goto L30 java.util.Queue r0 = r2.mOnScreenRemoveMarkerTasks // Catch: java.lang.Throwable -> L37 boolean r0 = r0.isEmpty() // Catch: java.lang.Throwable -> L37 if (r0 == 0) goto L30 java.util.Queue r0 = r2.mRemoveMarkerTasks // Catch: java.lang.Throwable -> L37 boolean r0 = r0.isEmpty() // Catch: java.lang.Throwable -> L37 if (r0 == 0) goto L30 java.util.Queue$AnimationTask> r0 = r2.mAnimationTasks // Catch: java.lang.Throwable -> L37 boolean r0 = r0.isEmpty() // Catch: java.lang.Throwable -> L37 if (r0 != 0) goto L2e goto L30 L2e: r0 = 0 goto L31 L30: r0 = 1 L31: java.util.concurrent.locks.Lock r1 = r2.lock r1.unlock() return r0 L37: r0 = move-exception java.util.concurrent.locks.Lock r1 = r2.lock r1.unlock() throw r0 */ throw new UnsupportedOperationException("Method not decompiled: com.google.maps.android.clustering.view.DefaultClusterRenderer.MarkerModifier.isBusy():boolean"); } public void waitUntilFree() { while (isBusy()) { sendEmptyMessage(0); this.lock.lock(); try { try { if (isBusy()) { this.busyCondition.await(); } } catch (InterruptedException e) { throw new RuntimeException(e); } } finally { this.lock.unlock(); } } } @Override // android.os.MessageQueue.IdleHandler public boolean queueIdle() { sendEmptyMessage(0); return true; } } private static class MarkerCache { private Map mCache; private Map mCacheReverse; private MarkerCache() { this.mCache = new HashMap(); this.mCacheReverse = new HashMap(); } public Marker get(T t) { return this.mCache.get(t); } public T get(Marker marker) { return this.mCacheReverse.get(marker); } public void put(T t, Marker marker) { this.mCache.put(t, marker); this.mCacheReverse.put(marker, t); } public void remove(Marker marker) { T t = this.mCacheReverse.get(marker); this.mCacheReverse.remove(marker); this.mCache.remove(t); } } protected void onBeforeClusterItemRendered(T t, MarkerOptions markerOptions) { if (t.getTitle() != null && t.getSnippet() != null) { markerOptions.title(t.getTitle()); markerOptions.snippet(t.getSnippet()); } else if (t.getTitle() != null) { markerOptions.title(t.getTitle()); } else if (t.getSnippet() != null) { markerOptions.title(t.getSnippet()); } } protected void onClusterItemUpdated(T t, Marker marker) { boolean z = true; boolean z2 = false; if (t.getTitle() != null && t.getSnippet() != null) { if (!t.getTitle().equals(marker.getTitle())) { marker.setTitle(t.getTitle()); z2 = true; } if (!t.getSnippet().equals(marker.getSnippet())) { marker.setSnippet(t.getSnippet()); z2 = true; } } else { if (t.getSnippet() != null && !t.getSnippet().equals(marker.getTitle())) { marker.setTitle(t.getSnippet()); } else if (t.getTitle() != null && !t.getTitle().equals(marker.getTitle())) { marker.setTitle(t.getTitle()); } z2 = true; } if (marker.getPosition().equals(t.getPosition())) { z = z2; } else { marker.setPosition(t.getPosition()); if (t.getZIndex() != null) { marker.setZIndex(t.getZIndex().floatValue()); } } if (z && marker.isInfoWindowShown()) { marker.showInfoWindow(); } } protected void onBeforeClusterRendered(Cluster cluster, MarkerOptions markerOptions) { markerOptions.icon(getDescriptorForCluster(cluster)); } protected BitmapDescriptor getDescriptorForCluster(Cluster cluster) { int bucket = getBucket(cluster); BitmapDescriptor bitmapDescriptor = this.mIcons.get(bucket); if (bitmapDescriptor != null) { return bitmapDescriptor; } this.mColoredCircleBackground.getPaint().setColor(getColor(bucket)); this.mIconGenerator.setTextAppearance(getClusterTextAppearance(bucket)); BitmapDescriptor bitmapDescriptorFromBitmap = BitmapDescriptorFactory.fromBitmap(this.mIconGenerator.makeIcon(getClusterText(bucket))); this.mIcons.put(bucket, bitmapDescriptorFromBitmap); return bitmapDescriptorFromBitmap; } protected void onClusterUpdated(Cluster cluster, Marker marker) { marker.setIcon(getDescriptorForCluster(cluster)); } public Marker getMarker(T t) { return this.mMarkerCache.get(t); } public T getClusterItem(Marker marker) { return this.mMarkerCache.get(marker); } public Marker getMarker(Cluster cluster) { return this.mClusterMarkerCache.get(cluster); } public Cluster getCluster(Marker marker) { return this.mClusterMarkerCache.get(marker); } private class CreateMarkerTask { private final LatLng animateFrom; private final Cluster cluster; private final Set newMarkers; public CreateMarkerTask(Cluster cluster, Set set, LatLng latLng) { this.cluster = cluster; this.newMarkers = set; this.animateFrom = latLng; } /* JADX INFO: Access modifiers changed from: private */ public void perform(DefaultClusterRenderer.MarkerModifier markerModifier) { MarkerWithPosition markerWithPosition; MarkerWithPosition markerWithPosition2; if (DefaultClusterRenderer.this.shouldRenderAsCluster(this.cluster)) { Marker markerAddMarker = DefaultClusterRenderer.this.mClusterMarkerCache.get(this.cluster); if (markerAddMarker == null) { MarkerOptions markerOptions = new MarkerOptions(); LatLng position = this.animateFrom; if (position == null) { position = this.cluster.getPosition(); } MarkerOptions markerOptionsPosition = markerOptions.position(position); DefaultClusterRenderer.this.onBeforeClusterRendered(this.cluster, markerOptionsPosition); markerAddMarker = DefaultClusterRenderer.this.mClusterManager.getClusterMarkerCollection().addMarker(markerOptionsPosition); DefaultClusterRenderer.this.mClusterMarkerCache.put(this.cluster, markerAddMarker); markerWithPosition = new MarkerWithPosition(markerAddMarker); LatLng latLng = this.animateFrom; if (latLng != null) { markerModifier.animate(markerWithPosition, latLng, this.cluster.getPosition()); } } else { markerWithPosition = new MarkerWithPosition(markerAddMarker); DefaultClusterRenderer.this.onClusterUpdated(this.cluster, markerAddMarker); } DefaultClusterRenderer.this.onClusterRendered(this.cluster, markerAddMarker); this.newMarkers.add(markerWithPosition); return; } for (T t : this.cluster.getItems()) { Marker markerAddMarker2 = DefaultClusterRenderer.this.mMarkerCache.get(t); if (markerAddMarker2 == null) { MarkerOptions markerOptions2 = new MarkerOptions(); LatLng latLng2 = this.animateFrom; if (latLng2 != null) { markerOptions2.position(latLng2); } else { markerOptions2.position(t.getPosition()); if (t.getZIndex() != null) { markerOptions2.zIndex(t.getZIndex().floatValue()); } } DefaultClusterRenderer.this.onBeforeClusterItemRendered(t, markerOptions2); markerAddMarker2 = DefaultClusterRenderer.this.mClusterManager.getMarkerCollection().addMarker(markerOptions2); markerWithPosition2 = new MarkerWithPosition(markerAddMarker2); DefaultClusterRenderer.this.mMarkerCache.put(t, markerAddMarker2); LatLng latLng3 = this.animateFrom; if (latLng3 != null) { markerModifier.animate(markerWithPosition2, latLng3, t.getPosition()); } } else { markerWithPosition2 = new MarkerWithPosition(markerAddMarker2); DefaultClusterRenderer.this.onClusterItemUpdated(t, markerAddMarker2); } DefaultClusterRenderer.this.onClusterItemRendered(t, markerAddMarker2); this.newMarkers.add(markerWithPosition2); } } } private static class MarkerWithPosition { private final Marker marker; private LatLng position; private MarkerWithPosition(Marker marker) { this.marker = marker; this.position = marker.getPosition(); } public boolean equals(Object obj) { if (obj instanceof MarkerWithPosition) { return this.marker.equals(((MarkerWithPosition) obj).marker); } return false; } public int hashCode() { return this.marker.hashCode(); } } private class AnimationTask extends AnimatorListenerAdapter implements ValueAnimator.AnimatorUpdateListener { private final LatLng from; private MarkerManager mMarkerManager; private boolean mRemoveOnComplete; private final Marker marker; private final MarkerWithPosition markerWithPosition; private final LatLng to; private AnimationTask(MarkerWithPosition markerWithPosition, LatLng latLng, LatLng latLng2) { this.markerWithPosition = markerWithPosition; this.marker = markerWithPosition.marker; this.from = latLng; this.to = latLng2; } public void perform() { ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f); valueAnimatorOfFloat.setInterpolator(DefaultClusterRenderer.ANIMATION_INTERP); valueAnimatorOfFloat.setDuration(DefaultClusterRenderer.this.mAnimationDurationMs); valueAnimatorOfFloat.addUpdateListener(this); valueAnimatorOfFloat.addListener(this); valueAnimatorOfFloat.start(); } @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener public void onAnimationEnd(Animator animator) { if (this.mRemoveOnComplete) { DefaultClusterRenderer.this.mMarkerCache.remove(this.marker); DefaultClusterRenderer.this.mClusterMarkerCache.remove(this.marker); this.mMarkerManager.remove(this.marker); } this.markerWithPosition.position = this.to; } public void removeOnAnimationComplete(MarkerManager markerManager) { this.mMarkerManager = markerManager; this.mRemoveOnComplete = true; } @Override // android.animation.ValueAnimator.AnimatorUpdateListener public void onAnimationUpdate(ValueAnimator valueAnimator) { if (this.to == null || this.from == null || this.marker == null) { return; } double animatedFraction = valueAnimator.getAnimatedFraction(); double d = ((this.to.latitude - this.from.latitude) * animatedFraction) + this.from.latitude; double dSignum = this.to.longitude - this.from.longitude; if (Math.abs(dSignum) > 180.0d) { dSignum -= Math.signum(dSignum) * 360.0d; } this.marker.setPosition(new LatLng(d, (dSignum * animatedFraction) + this.from.longitude)); } } }