android - How to animate an Icon in markerOptions? [GoogleMaps API] -
is there way how animate icon? need apply "wave" animation custom drawable marker on google map. suggestions welcomed!
note.: plan run handler worker thread call "seticon" method , animate icon.
desired effect:
my icon drawable:
xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#0093e8"/> <size android:width="120dp" android:height="120dp"/> </shape>
this onmapready method:
@override public void onmapready(googlemap googlemap) { mmap = googlemap; mdotmarkerbitmap = generatebitmapfromdrawable(); markeroptions = new markeroptions() .position(xdesign) .title("xdesign in edinburgh") .icon(bitmapdescriptorfactory.frombitmap(mdotmarkerbitmap)); mxdesignmarker = mmap.addmarker(markeroptions); bitmapdescriptor bitmapdescriptor = markeroptions.geticon(); animation fadeout = new alphaanimation(1, 0); fadeout.setduration(1000); animationset animation = new animationset(true); animation.addanimation(fadeout); // icons dont have animate method icon.setanimation(animation); mmap.movecamera(cameraupdatefactory.newlatlngzoom(xdesign, 15)); }
my generatebitmapfromdrawable method:
private bitmap generatebitmapfromdrawable() { int px = getresources().getdimensionpixelsize(r.dimen.map_dot_marker_size); bitmap mdotmarkerbitmap = bitmap.createbitmap(px, px, bitmap.config.argb_8888); canvas canvas = new canvas(mdotmarkerbitmap); drawable shape = getresources().getdrawable(r.drawable.circle_drawable); shape.setbounds(0, 0, mdotmarkerbitmap.getwidth(), mdotmarkerbitmap.getheight()); shape.draw(canvas); return mdotmarkerbitmap; }
what did used custom animation class:
public class radiusanimation extends animation { private groundoverlay groundoverlay; private final int startingsize = 100; public radiusanimation(groundoverlay groundoverlay) { this.groundoverlay = groundoverlay; } @override protected void applytransformation(float interpolatedtime, transformation t) { groundoverlay.setdimensions((startingsize * interpolatedtime)); groundoverlay.settransparency(interpolatedtime); } @override public void initialize(int width, int height, int parentwidth, int parentheight) { super.initialize(width, height, parentwidth, parentheight); } }
and in mapfragment:
public class mapfragment extends fragment implements onmapreadycallback { private radiusanimation groundanimation; private animationset breadinganimations; @override public void onviewcreated(view view, @nullable bundle savedinstancestate) { super.onviewcreated(view, savedinstancestate); ripplebackground = new ripplebackground(getactivity()); ripplebackground.setbackgroundcolor(contextcompat.getcolor(getactivity(), r.color.pulsemarker1)); mapfragment = (supportmapfragment) getchildfragmentmanager().findfragmentbyid(r.id.map); mapfragment.getmapasync(this); breadinganimations = new animationset(false); } @override public void onmapready(googlemap googlemap) { mmap = googlemap; //add smallest image drawable overlay bitmap mdotmarkerbitmap1 = generatebitmapfromdrawable(r.drawable.circle_drawable); final int widthone = 80; final int animationdurationone = 1200; groundoverlay groundoverlay1 = mmap.addgroundoverlay(new groundoverlayoptions() .image(bitmapdescriptorfactory.frombitmap(mdotmarkerbitmap1)) .position(xdesign, widthone)); groundanimation = new radiusanimation(groundoverlay1); groundanimation.setrepeatcount(animation.infinite); groundanimation.setrepeatmode(animation.restart); groundanimation.setduration(animationdurationone); // groundanimation.setstartoffset(700); breadinganimations.addanimation(groundanimation); bitmap mdotmarkerbitmap2 = generatebitmapfromdrawable(r.drawable.circle_drawable2); final int widthtwo = 200; final int animationdurationtwo = 2000; groundoverlay groundoverlay2 = mmap.addgroundoverlay(new groundoverlayoptions() .image(bitmapdescriptorfactory.frombitmap(mdotmarkerbitmap2)) .position(xdesign, widthtwo)); animation groundanimation2 = new radiusanimation(groundoverlay2); groundanimation2.setrepeatcount(animation.infinite); groundanimation2.setrepeatmode(animation.restart); groundanimation2.setduration(animationdurationtwo); // groundanimation2.setstartoffset(1500); breadinganimations.addanimation(groundanimation2); bitmap mdotmarkerbitmap3 = generatebitmapfromdrawable(r.drawable.circle_drawable3); final int widththree = 300; final int animationdurationthree = 3000; groundoverlay groundoverlay3 = mmap.addgroundoverlay(new groundoverlayoptions() .image(bitmapdescriptorfactory.frombitmap(mdotmarkerbitmap3)) .position(xdesign, widththree)); animation groundanimation3 = new radiusanimation(groundoverlay3); groundanimation3.setrepeatcount(animation.infinite); groundanimation3.setrepeatmode(animation.restart); // groundanimation3.setstartoffset(500); groundanimation3.setduration(animationdurationthree); breadinganimations.addanimation(groundanimation3); mapfragment.getview().startanimation(breadinganimations); // start animation mmap.movecamera(cameraupdatefactory.newlatlngzoom(xdesign, zoomleval)); } private void logthis(string message) { log.d(tag, message); } @nonnull private bitmap generatebitmapfromdrawable(int drawablesres) { int px = getresources().getdimensionpixelsize(r.dimen.map_dot_marker_size); bitmap mdotmarkerbitmap = bitmap.createbitmap(px, px, bitmap.config.argb_8888); canvas canvas = new canvas(mdotmarkerbitmap); drawable shape = getresources().getdrawable(drawablesres); shape.setbounds(0, 0, mdotmarkerbitmap.getwidth(), mdotmarkerbitmap.getheight()); shape.draw(canvas); return mdotmarkerbitmap; } }
Comments
Post a Comment