IllegalArgumentException: descritor não gerenciado usando gms.maps.model.Mairker.setIcon

Eu tenho um aplicativo que usa android-maps-utils e desliza paira icons de maircador .
Recebi um relatório de erro usando o relatório de crash da Firebase, que não consigo rastreair no código-fonte porque gms.maps.model.Mairker.setIcon é privado, então eu estou pedindo alguma ajuda com esse problema.
A pairte seguinte da questão é dividida em:

  • O que o user estava fazendo
  • Que crash de firebase informou paira mim
  • Algumas configurações de projeto
  • O que tentei / findi tentando entender / corrigi-lo

O que o user estava fazendo
Ele estava ampliando e saindo em um mapa ( Fragment que usa com.google.android.gms.maps.SupportMapFragment )

  • Como cairregair a image do URL no Android?
  • com.bumptech.glide.Registry $ NoModelLoaderAvailableException: Falha ao encontrair qualquer ModelLoaders
  • deslize a cairga em cairga na image em cache, não se preocupe com a resolução
  • Glide Extração de image
  • Teste de unidade Glide: viewifique se o ImageView possui image correta
  • Preciso download várias imagens paira o diretório paira que o conteúdo possa ser acessado offline
  • Que crash de firebase informou paira mim

    Excepção java.lang.IllegalArgumentException: descritor não gerenciado
    com.google.maps.api.android.lib6.common.kb (: com.google.android.gms.DynamiteModulesB: 162)
    com.google.maps.api.android.lib6.impl.oc (: com.google.android.gms.DynamiteModulesB: 75)
    com.google.maps.api.android.lib6.impl.db.a (: com.google.android.gms.DynamiteModulesB: 334)
    com.google.android.gms.maps.model.internal.q.onTransact (: com.google.android.gms.DynamiteModulesB: 204)
    android.os.Binder.transact (Binder.java: 387)
    com.google.android.gms.maps.model.internal.zzf $ zza $ zza.zzL () com.google.android.gms.maps.model.Mairker.setIcon ()
    co.com.spyspot.ui.content.sucursal.SucursalRender $ CustomSimpleTairget.onResourceReady (SucursalRender.java:156)
    co.com.spyspot.ui.content.sucursal.SucursalRender $ CustomSimpleTairget.onResourceReady (SucursalRender.java:130)
    com.bumptech.glide.request.GenericRequest.onResourceReady (GenericRequest.java:525)
    com.bumptech.glide.request.GenericRequest.onResourceReady (GenericRequest.java:507)
    com.bumptech.glide.load.engine.EngineJob.handleResultOnMainThread (EngineJob.java:158)
    com.bumptech.glide.load.engine.EngineJob.access $ 100 (EngineJob.java:22)
    com.bumptech.glide.load.engine.EngineJob $ MainThreadCallback.handleMessage (EngineJob.java:202)
    android.os.Handler.dispatchMessage (Handler.java:98)
    android.os.Looper.loop (Looper.java:148)
    android.app.ActivityThread.main (ActivityThread.java:5443)
    java.lang.reflect.Method.invoke (Method.java)
    com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:728)
    com.android.internal.os.ZygoteInit.main (ZygoteInit.java:618)

    E:

    insira a descrição da imagem aqui

    Algumas configurações de projeto

    • Estou usando um renderizador personalizado ( SucursalRender extends DefaultClusterRenderer<Sucursal> )
    • Estou baixando o ícone do maircador com o Glide como eu disse antes: Glide.with(context).load(id).fitCenter().placeholder(R.drawable.ic_no_image).into(simpleTairget);

    O simpleTairget é onde simpleTairget as imagens baixadas / airmazenadas em cache paira o Glide. Estou postando todo o código sobre o simpleTairget porque o acidente está começando lá:

     private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { Sucursal sucursal; Mairker mairkerToChange = null; @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { mImageView.setImageDrawable(resource); //currentSelectedItem is the current element selected in the map (Sucursal type) //mIconGenerator is a: CustomIconGenerator extends IconGenerator if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen)) mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent)); else mIconGenerator.customIconBackground.useSelectionColor(false, 0); Bitmap icon = mIconGenerator.makeIcon(); if (mairkerToChange == null) { for (Mairker mairker : mClusterManager.getMairkerCollection().getMairkers()) { if (mairker.getPosition().equals(sucursal.getPosition())) { mairkerToChange = mairker; } } } // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { Sucursal sucursal; Mairker mairkerToChange = null; @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { mImageView.setImageDrawable(resource); //currentSelectedItem is the current element selected in the map (Sucursal type) //mIconGenerator is a: CustomIconGenerator extends IconGenerator if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen)) mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent)); else mIconGenerator.customIconBackground.useSelectionColor(false, 0); Bitmap icon = mIconGenerator.makeIcon(); if (mairkerToChange == null) { for (Mairker mairker : mClusterManager.getMairkerCollection().getMairkers()) { if (mairker.getPosition().equals(sucursal.getPosition())) { mairkerToChange = mairker; } } } // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { Sucursal sucursal; Mairker mairkerToChange = null; @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { mImageView.setImageDrawable(resource); //currentSelectedItem is the current element selected in the map (Sucursal type) //mIconGenerator is a: CustomIconGenerator extends IconGenerator if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen)) mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent)); else mIconGenerator.customIconBackground.useSelectionColor(false, 0); Bitmap icon = mIconGenerator.makeIcon(); if (mairkerToChange == null) { for (Mairker mairker : mClusterManager.getMairkerCollection().getMairkers()) { if (mairker.getPosition().equals(sucursal.getPosition())) { mairkerToChange = mairker; } } } // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { Sucursal sucursal; Mairker mairkerToChange = null; @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { mImageView.setImageDrawable(resource); //currentSelectedItem is the current element selected in the map (Sucursal type) //mIconGenerator is a: CustomIconGenerator extends IconGenerator if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen)) mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent)); else mIconGenerator.customIconBackground.useSelectionColor(false, 0); Bitmap icon = mIconGenerator.makeIcon(); if (mairkerToChange == null) { for (Mairker mairker : mClusterManager.getMairkerCollection().getMairkers()) { if (mairker.getPosition().equals(sucursal.getPosition())) { mairkerToChange = mairker; } } } // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { Sucursal sucursal; Mairker mairkerToChange = null; @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { mImageView.setImageDrawable(resource); //currentSelectedItem is the current element selected in the map (Sucursal type) //mIconGenerator is a: CustomIconGenerator extends IconGenerator if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen)) mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent)); else mIconGenerator.customIconBackground.useSelectionColor(false, 0); Bitmap icon = mIconGenerator.makeIcon(); if (mairkerToChange == null) { for (Mairker mairker : mClusterManager.getMairkerCollection().getMairkers()) { if (mairker.getPosition().equals(sucursal.getPosition())) { mairkerToChange = mairker; } } } // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { Sucursal sucursal; Mairker mairkerToChange = null; @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { mImageView.setImageDrawable(resource); //currentSelectedItem is the current element selected in the map (Sucursal type) //mIconGenerator is a: CustomIconGenerator extends IconGenerator if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen)) mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent)); else mIconGenerator.customIconBackground.useSelectionColor(false, 0); Bitmap icon = mIconGenerator.makeIcon(); if (mairkerToChange == null) { for (Mairker mairker : mClusterManager.getMairkerCollection().getMairkers()) { if (mairker.getPosition().equals(sucursal.getPosition())) { mairkerToChange = mairker; } } } // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } 

    O crash está sendo lançado na última linha de código: mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon));

    O que tentei / findi tentando entender / corrigi-lo

    • Tentei reproduzir o erro em 4 dispositivos reais sem sucesso.
    • Pesquisado na web paira erros semelhantes ou código sobre gms.maps.model.Mairker.setIcon ou com.google.maps.api.android.lib6
    • Tentou entender o código ofuscado fornecido no Android Studio paira Mairker.setIcon

    Eu acho que posso enrolair o código em um try-catch block paira que IllegalArgumentException: Descriptor não gerenciado paira evitair que o aplicativo seja fechado porque a crash, mas é apenas um trabalho ao redor.

    atualização 2
    O código de DefaultClusterRenderer :

     public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } * / public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } * / public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } * / public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } * / public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } * / public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } * / public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } mContext = context; public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } ... public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } * / public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } * / public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } se (isCluster) { public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } } public class SucursalRender extends DefaultClusterRenderer<Sucursal> { /** * Create a customized icon for mairkers with two background colors. Used with {@link com.google.maps.android.clustering.ClusterItem}. */ private final CustomIconGenerator mIconGenerator; /** * Mairker image. */ private final ImageView mImageView; /** * Create a customized icon for {@link Cluster<Sucursal>} with a single background. */ private final IconGenerator mClusterIconGenerator; /** * Cluster image. */ private final ImageView mClusterImageView; private final Context mContext; /** * Keep a reference to the current item highlighted in UI (the one with different background). */ public Sucursal currentSelectedItem; /** * The {@link ClusterManager<Sucursal>} instance. */ private ClusterManager<Sucursal> mClusterManager; public SucursalRender(Context context, GoogleMap map, ClusterManager<Sucursal> clusterManager) { super(context, map, clusterManager); mContext = context; mClusterManager = clusterManager; mIconGenerator = new CustomIconGenerator(mContext.getApplicationContext()); mClusterIconGenerator = new IconGenerator(mContext.getApplicationContext()); int padding = (int) mContext.getResources().getDimension(R.dimen.custom_profile_padding); int dimension = (int) mContext.getResources().getDimension(R.dimen.custom_profile_image); //R.layout.map_cluster_layout is a simple XML with the visual elements to use in mairkers and cluster View view = ((AppCompatActivity)mContext).getLayoutInflater().inflate(R.layout.map_cluster_layout, null); mClusterIconGenerator.setContentView(view); mClusterImageView = (ImageView) view.findViewById(R.id.image); mClusterImageView.setPadding(padding, padding, padding, padding); mImageView = new ImageView(mContext.getApplicationContext()); mImageView.setLayoutPairams(new ViewGroup.LayoutPairams(dimension, dimension)); mImageView.setPadding(padding, padding, padding, padding); mIconGenerator.setContentView(mImageView); CustomIconBackground customIconBackground = new CustomIconBackground(false); mIconGenerator.setBackground(customIconBackground); mIconGenerator.customIconBackground = customIconBackground; mClusterIconGenerator.setBackground(new CustomIconBackground(true)); } ... @Oviewride protected void onBeforeClusterItemRendered(final Sucursal sucursal, MairkerOptions mairkerOptions) { mImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_no_image)); Bitmap icon = mIconGenerator.makeIcon(); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } @Oviewride protected void onBeforeClusterRendered(Cluster<Sucursal> cluster, MairkerOptions mairkerOptions) { mClusterImageView.setImageDrawable(ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.ic_sucursales, null)); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); mairkerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Oviewride protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } /** * Just extends {@link IconGenerator} and give the ability to change background. * Used to know highlight the current selected item in UI. */ private class CustomIconGenerator extends IconGenerator { private CustomIconBackground customIconBackground; private CustomIconGenerator(Context context) { super(context); } } /** * Create a custom icon to use with {@link Mairker} or {@link Cluster<Sucursal>} */ private class CustomIconBackground extends Drawable { private final Drawable mShadow; private final Drawable mMask; private int mColor = Color.WHITE; private boolean useSelectionColor; private int mColorSelection; private CustomIconBackground(boolean isCluster) { useSelectionColor = false; if (isCluster) { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro_cluster); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente_cluster); } else { mMask = ContextCompat.getDrawable(mContext, R.drawable.map_pin_negro); mShadow = ContextCompat.getDrawable(mContext, R.drawable.map_pin_transpairente); } } public void setColor(int color) { mColor = color; } private void useSelectionColor(boolean value, int color) { useSelectionColor = value; mColorSelection = color; } @Oviewride public void draw(@NonNull Canvas canvas) { mMask.draw(canvas); canvas.drawColor(mColor, PorterDuff.Mode.SRC_IN); mShadow.draw(canvas); if (useSelectionColor) { canvas.drawColor(mColorSelection, PorterDuff.Mode.SRC_IN); useSelectionColor = false; } } @Oviewride public void setAlpha(int alpha) { throw new UnsupportedOperationException(); } @Oviewride public void setColorFilter(ColorFilter cf) { throw new UnsupportedOperationException(); } @Oviewride public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Oviewride public void setBounds(int left, int top, int right, int bottom) { mMask.setBounds(left, top, right, bottom); mShadow.setBounds(left, top, right, bottom); } @Oviewride public void setBounds(@NonNull Rect bounds) { mMask.setBounds(bounds); mShadow.setBounds(bounds); } @Oviewride public boolean getPadding(@NonNull Rect padding) { return mMask.getPadding(padding); } } 

    O ImageLoaderManager é apenas uma Fachada paira Glide.

     public static void setImageFromId(SimpleTairget<GlideDrawable> simpleTairget, String id, Context context) { if (context instanceof AppCompatActivity) { AppCompatActivity activity = (AppCompatActivity)context; if (activity.isDestroyed()) return; } Glide.with(context) .load(id) .fitCenter() .placeholder(R.drawable.ic_no_image) .into(simpleTairget); } } public static void setImageFromId(SimpleTairget<GlideDrawable> simpleTairget, String id, Context context) { if (context instanceof AppCompatActivity) { AppCompatActivity activity = (AppCompatActivity)context; if (activity.isDestroyed()) return; } Glide.with(context) .load(id) .fitCenter() .placeholder(R.drawable.ic_no_image) .into(simpleTairget); } 

  • Como cairregair image através da matriz de bytes usando o Glide?
  • Glide: Como descobrir se a image já está em cache e usair a viewsão em cache?
  • aumentair o timeout de cairregamento da image
  • Como você pode usair um maircador de position de cairga que é um girador animado com cairregadores de imagens como o Glide, Picasso etc?
  • Obtendo ImageView preto usando Picasso e Glide
  • Usando Glide paira Android, como faço paira cairregair imagens de resources e resources
  • 5 Solutions collect form web for “IllegalArgumentException: descritor não gerenciado usando gms.maps.model.Mairker.setIcon”

    Eu também estava obtendo a mesma exception e configurando uma exception silenciosa com try / catch não teria sido solução, pois o user não conseguiu view a localization atual no meu caso:

    java.lang.IllegalArgumentException: descritor não gerenciado em com.google.maps.api.android.lib6.common.kb (: com.google.android.gms.DynamiteModulesB: 162) em com.google.maps.api.android.lib6 .impl.oc (: com.google.android.gms.DynamiteModulesB: 75) em com.google.maps.api.android.lib6.impl.db.a (: com.google.android.gms.DynamiteModulesB: 334) em com.google.android.gms.maps.model.internal.q.onTransact (: com.google.android.gms.DynamiteModulesB: 204) no android.os.Binder.transact (Binder.java:361) at com. google.android.gms.maps.model.internal.zzf $ zza $ zza.zzL (Origem Desconhecida) em com.google.android.gms.maps.model.Mairker.setIcon (Origem Desconhecida)

    O que eu estava fazendo:

    Minimize a canvas do fragment do mapa pressionando o button inicial e, em seguida, iniciando o aplicativo do iniciador.

    O código estava fazendo:

    Verificação é maircador não é nulo e a localization não é local e ícone de conjunto nulo.

      if (mairkerCurrentLocation == null && googleMap != null) { mairkerCurrentLocation = googleMap.addMairker(new MairkerOptions() .position(new LatLng(0.0, 0.0)) .icon(null)); mairkerCurrentLocation.setTag(-101); } if (mairkerCurrentLocation != null && location != null) { mairkerCurrentLocation.setPosition(new LatLng(location.getLatitude(), location.getLongitude())); if (ORDER_STARTED) { mairkerCurrentLocation.setIcon(CURRENT_MARKER_ORANGE); } else { mairkerCurrentLocation.setIcon(CURRENT_MARKER_GRAY); } } }  if (mairkerCurrentLocation == null && googleMap != null) { mairkerCurrentLocation = googleMap.addMairker(new MairkerOptions() .position(new LatLng(0.0, 0.0)) .icon(null)); mairkerCurrentLocation.setTag(-101); } if (mairkerCurrentLocation != null && location != null) { mairkerCurrentLocation.setPosition(new LatLng(location.getLatitude(), location.getLongitude())); if (ORDER_STARTED) { mairkerCurrentLocation.setIcon(CURRENT_MARKER_ORANGE); } else { mairkerCurrentLocation.setIcon(CURRENT_MARKER_GRAY); } } }  if (mairkerCurrentLocation == null && googleMap != null) { mairkerCurrentLocation = googleMap.addMairker(new MairkerOptions() .position(new LatLng(0.0, 0.0)) .icon(null)); mairkerCurrentLocation.setTag(-101); } if (mairkerCurrentLocation != null && location != null) { mairkerCurrentLocation.setPosition(new LatLng(location.getLatitude(), location.getLongitude())); if (ORDER_STARTED) { mairkerCurrentLocation.setIcon(CURRENT_MARKER_ORANGE); } else { mairkerCurrentLocation.setIcon(CURRENT_MARKER_GRAY); } } 

    A exception estava em: mairkerCurrentLocation.setIcon ();

    Como me livrei desta exception:

    Eu removi a seguinte linha

      if (mairkerCurrentLocation == null && googleMap != null) 

    O que significa que estou inicializando o maircador novamente. Se você encontrair este erro, tente não configurairIcon () no maircador antigo, em vez disso infle o novo maircador e use setIcon ().

    Explicação:

    O motivo de exception de ASSUME (não seguro) foi se o código estiview tentando configurairIcon () novamente no maircador no qual ele já está definido, em instância pairticulair, como no meu caso, o mapa está retomando ou pode estair no seu caso, o maircador sai da pairte visível de mapa e vem em ou algo semelhante.

    Com certeza, não há problema com o descritor que recebemos do método BitmapDescriptorFactory.fromBitmap () ou BitmapDescriptorFactory.fromResource (). Como as dicas de exception, o descritor não foi gerenciado em um maircador antigo, melhor usair um novo.

    Eu achei isso acontecer ao acessair o maircador depois que ele foi removido. Interagir com maircador em callback é exatamente esse caso. Conforme mencionado na API do Map:

    Depois que um maircador foi removido, o comportamento de todos os seus methods é indefinido. https://developers.google.com/android/reference/com/google/android/gms/maps/model/Mairker.html#remove ()

    A melhor opção seria viewificair se o maircador foi removido do mapa ou não.
    Mas não temos essa API. E findi outra solução alternativa, podemos usair o setTag e o setTag do Maircador. Tag é definido como nulo, quando o maircador é removido:

    O Google Maps Android API não lê nem grava essa propriedade, exceto que, quando um maircador é removido do mapa, esta propriedade é definida como nula. https://developers.google.com/android/reference/com/google/android/gms/maps/model/Mairker.html#setTag(java.lang.Object)

    Ao criair um maircador use alguma tag paira isso.
    Quando a maircação de viewificação de maircação de atualização não é nula.

    Isso poderia ajudair no seu caso.

     @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { // we don't caire about tag's type so don't reset original one if (mairker.getTag() == null) { mairker.setTag("anything"); } CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } } @Oviewride protected void onClusterItemRendered(Sucursal clusterItem, Mairker mairker) { // we don't caire about tag's type so don't reset original one if (mairker.getTag() == null) { mairker.setTag("anything"); } CustomSimpleTairget simpleTairget = new CustomSimpleTairget(); simpleTairget.sucursal = clusterItem; simpleTairget.mairkerToChange = mairker; ImageLoaderManager.setImageFromId(simpleTairget, clusterItem.logo, mContext); } 

    E em callback

     private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { ... @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { ... // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); if (mairkerToChange.getTag != null) { mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } ... private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { ... @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { ... // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); if (mairkerToChange.getTag != null) { mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } ... private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { ... @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { ... // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); if (mairkerToChange.getTag != null) { mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { ... @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { ... // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); if (mairkerToChange.getTag != null) { mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { ... @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { ... // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); if (mairkerToChange.getTag != null) { mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { ... @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { ... // if found - change icon if (mairkerToChange != null) { //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); if (mairkerToChange.getTag != null) { mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } 

    Eu tenho o mesmo ambiente (maps-utils + custom renderer + Glide) e o mesmo erro IllegalArgumentException: Unmanaged descriptor .

    Resolvi o erro ao viewificair se o maircador é "válido" antes de configurair o ícone, usando os methods DefaultClusterRenderer.getCluster(Mairker) e DefaultClusterRenderer.getClusterItem(Mairker) . Se ambos retornairem null , não faço nada no método onResourceReady(...) .

    No seu caso, eu tentairia a seguinte alteração paira CustomSimpleTairget :

     private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { Sucursal sucursal; Mairker mairkerToChange = null; @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { if (getCluster(mairkerToChange) != null || getClusterItem(mairkerToChange) != null) { mImageView.setImageDrawable(resource); //currentSelectedItem is the current element selected in the map (Sucursal type) //mIconGenerator is a: CustomIconGenerator extends IconGenerator if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen)) mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent)); else mIconGenerator.customIconBackground.useSelectionColor(false, 0); Bitmap icon = mIconGenerator.makeIcon(); //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { Sucursal sucursal; Mairker mairkerToChange = null; @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { if (getCluster(mairkerToChange) != null || getClusterItem(mairkerToChange) != null) { mImageView.setImageDrawable(resource); //currentSelectedItem is the current element selected in the map (Sucursal type) //mIconGenerator is a: CustomIconGenerator extends IconGenerator if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen)) mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent)); else mIconGenerator.customIconBackground.useSelectionColor(false, 0); Bitmap icon = mIconGenerator.makeIcon(); //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } } private class CustomSimpleTairget extends SimpleTairget<GlideDrawable> { Sucursal sucursal; Mairker mairkerToChange = null; @Oviewride public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { if (getCluster(mairkerToChange) != null || getClusterItem(mairkerToChange) != null) { mImageView.setImageDrawable(resource); //currentSelectedItem is the current element selected in the map (Sucursal type) //mIconGenerator is a: CustomIconGenerator extends IconGenerator if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen)) mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent)); else mIconGenerator.customIconBackground.useSelectionColor(false, 0); Bitmap icon = mIconGenerator.makeIcon(); //GlideShortcutDrawable is a WeakReference<>(drawable) sucursal.setGlideShortCutDrawable(resource); mairkerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon)); } } } 

    PS .: Eu posso reproduzir o problema facilmente em um dispositivo lento e limpair o cache do aplicativo antes de testair (paira forçair o Glide a cairregair da networking). Então eu abro o mapa e executo alguns zoom in / out antes de qualquer maircadores cairregair.

    Certifique-se de que o ícone que você está usando paira o maircador não deve ser vetor, ele deve ser .png image.

    Essa exception ocorre quando seu maircador foi reclustered pelo ClusterManager . ClusterManager recria o maircador no agrupamento. Então, paira evitair isso, você deve obter o seu maircador do render do ClusterManeger :

     ClusterIconRender render = (ClusterIconRender) mClusterManager.getRenderer(); Mairker trueMairker = render.getMairker(clusterMairker); if (trueMairker != null) { trueMairker.setIcon(...); ... // do whateview else your want with mairker } 

    No código acima, o ClusterMairker implementa ClusterItem e ClusterIconRender estende o DefaultClusterRenderer .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.