android - How to make Rotate3dAnimation more smoother? -


in app using rotate3danimation show google map. code working fine, animation not smooth, lines visible while rotating view. please take @ code , suggest me how can make animation more smoother? suggestion on achieving type of animation in other efficient way highly appreciated. enter image description here

public class eventsactivity extends mapactivity implements dialoginterface.ondismisslistener {          private eventsitemmodel     eventsitemmodel;         private integer             eventitemid;         private integer             eventcategoryid;         private static mapoverlay   mapoverlay;         drawable                    marker;         context                     context;         private static string       my_location = "my location";         private viewgroup           mcontainer;         private imageview           mimageview;         private mapview             mmapview;         private static boolean      isflipped   = false;          @override         public void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.event_item_detail);             mcontainer = (viewgroup) findviewbyid(r.id.event_container);             // since caching large views, want keep cache             // between each animation             mcontainer.setpersistentdrawingcache(viewgroup.persistent_animation_cache);             mmapview = (mapview) findviewbyid(r.id.mapview);             mimageview = (imageview) findviewbyid(r.id.mappreview);              mimageview.setonclicklistener(new onclicklistener() {                  @override                 public void onclick(view v) {                     isflipped = true;                     applyrotation(1, 0, 90);                 }             });              try {                 eventcategoryid = getintent().getintextra(appconstants.event_category, 0);                 eventitemid = getintent().getintextra(appconstants.event_id, 0);             }             catch (exception e) {                 e.printstacktrace();             }          }          public void onresume() {             super.onresume();             weakreference<eventsactivity> weakcontext = new weakreference<eventsactivity>(this);             eventsasynctask task = new eventsasynctask(weakcontext);             task.execute(eventitemid, eventcategoryid);         }          public void ontaskcomplete(eventsitemmodel eimodel) {             this.eventsitemmodel = eimodel;             textview caltitle = (textview) findviewbyid(r.id.news_title);             textview eventtitle = (textview) findviewbyid(r.id.cal_event_title);             textview caldate = (textview) findviewbyid(r.id.cal_date);             textview caltime = (textview) findviewbyid(r.id.cal_time);             textview caladdress = (textview) findviewbyid(r.id.cal_address);             textview caldescription = (textview) findviewbyid(r.id.cal_description);              try {                 caltitle.settext(eventsitemmodel.geteventscategory().gettitle());                 caltitle.setvisibility(view.visible);                 eventtitle.settext(eventsitemmodel.geteventtitle());                 caldate.settext(eventsitemmodel.getformatteddaterange());                 // todo:format start , end time                 caltime.settext("time: " + eventsitemmodel.getformattedstarttime() + " - " + eventsitemmodel.getformattedendtime());                 caladdress.settext(eventsitemmodel.getaddress());                 caldescription.settext(eventsitemmodel.getdescription());                 system.out.println("<<<<<<<<< eventsactivity >>>>>>>>> isread? " + eventsitemmodel.getreadunread());                 eventsitemmodel.setreadunread(true);                 system.out.println("<<<<<<<<<< eventsactivity >>>>>>>>>> isread? " + eventsitemmodel.getreadunread());             }             catch (exception e) {                 e.printstacktrace();             }              mmapview.setbuiltinzoomcontrols(true);             setmapparameters();             createitemizedoverlay();             setlocationmarker(createmarker(r.drawable.location_marker));             showlocationpointonmap();         }          @override         public void ondismiss(dialoginterface dialog) {          }          @override         protected boolean isroutedisplayed() {             return false;         }          public void createitemizedoverlay() {             mapoverlay = new mapoverlay(this);         }          public void setlocationmarker(drawable marker) {             mapoverlay.setlocationmarker(marker);         }          public void showlocationpointonmap() {              geopoint geopoint = new geopoint(0, 0);             if (eventsitemmodel != null && eventsitemmodel.getlatitude() != null && eventsitemmodel.getlatitude().length() > 0 && eventsitemmodel.getlongitude() != null                     && eventsitemmodel.getlongitude().length() > 0) {                 try {                     geopoint = new geopoint((int) (double.parsedouble(eventsitemmodel.getlatitude()) * 1e6), (int) (double.parsedouble(eventsitemmodel.getlongitude()) * 1e6));                 }                 catch (numberformatexception e) {                     e.printstacktrace();                 }                 overlayitem item = new overlayitem(geopoint, my_location, null);                 mapoverlay.additem(item);                 mmapview.getoverlays().add(mapoverlay);                  // move location                 mmapview.getcontroller().animateto(geopoint);                 // redraw map                 mmapview.postinvalidate();             }          }          public void setstreetview(boolean isstreetview) {             mmapview.setstreetview(isstreetview);         }          public void setsatelliteview(boolean issatelliteview) {             mmapview.setsatellite(issatelliteview);         }          public void setzoom(int zoomlevel) {             mmapview.getcontroller().setzoom(zoomlevel);         }          private void setmapparameters() {             // setstreetview(true);             // setsatelliteview(false);             setzoom(17);         }          private drawable createmarker(int iconid) {             // initialize icon             drawable icon = getresources().getdrawable(iconid);             icon.setbounds(0, 0, icon.getintrinsicwidth(), icon.getintrinsicheight());             return icon;         }          @override         protected void onstop() {             // todo auto-generated method stub             super.onstop();         }          @override         protected void onpause() {             // todo auto-generated method stub             super.onpause();         }          /**          * setup new 3d rotation on container view.          *           * @param position          *            item clicked show picture, or -1 show list          * @param start          *            start angle @ rotation must begin          * @param end          *            end angle of rotation          */         private void applyrotation(int position, float start, float end) {             // find center of container             final float centerx = mcontainer.getwidth() / 2.0f;             final float centery = mcontainer.getheight() / 2.0f;              // create new 3d rotation supplied parameter             // animation listener used trigger next animation             final rotate3danimation rotation = new rotate3danimation(start, end, centerx, centery, 310.0f, true);             rotation.setduration(500);             rotation.setfillafter(true);             rotation.setinterpolator(new accelerateinterpolator());             rotation.setanimationlistener(new displaynextview(position));              mcontainer.startanimation(rotation);         }          /**          * class listens end of first half of animation. posts new action swaps views when container rotated 90 degrees , invisible.          */         private final class displaynextview implements animation.animationlistener {             private final int   mposition;              private displaynextview(int position) {                 mposition = position;             }              public void onanimationstart(animation animation) {             }              public void onanimationend(animation animation) {                 mcontainer.post(new swapviews(mposition));             }              public void onanimationrepeat(animation animation) {                 // nothing!!             }         }          /**          * class responsible swapping views , start second half of animation.          */         private final class swapviews implements runnable {             private final int   mposition;              public swapviews(int position) {                 mposition = position;             }              public void run() {                 final float centerx = mcontainer.getwidth() / 2.0f;                 final float centery = mcontainer.getheight() / 2.0f;                 rotate3danimation rotation;                  if (mposition > -1) {                     mimageview.setvisibility(view.gone);                     mmapview.setvisibility(view.visible);                     mmapview.requestfocus();                      rotation = new rotate3danimation(-90, 180, centerx, centery, 310.0f, false);                     rotation.reset();                 }                 else {                     mmapview.setvisibility(view.gone);                     mimageview.setvisibility(view.visible);                     mimageview.requestfocus();                      rotation = new rotate3danimation(90, 0, centerx, centery, 310.0f, false);                 }                  rotation.setduration(100);                 rotation.setfillafter(true);                 rotation.setinterpolator(new decelerateinterpolator());                  mcontainer.startanimation(rotation);             }         }          @override         public void onbackpressed() {             if (isflipped) {                 applyrotation(-1, 0, -90);                 isflipped = false;             }             else {                 super.onbackpressed();             }         }      } 

my xml layout follows:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/event_container"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="#426773" >      <include         android:id="@+id/news_header"         layout="@layout/news_header" />      <textview         android:id="@+id/cal_event_title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_below="@id/news_header"         android:padding="5dp"         android:textcolor="@android:color/white"         android:textsize="22sp"         android:textstyle="bold"         android:typeface="sans" />      <relativelayout          android:id="@+id/date_time_container"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_below="@id/cal_event_title">      <textview         android:id="@+id/cal_date"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:padding="5dp"         android:textcolor="@android:color/white" />      <textview         android:id="@+id/cal_time"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_below="@id/cal_date"         android:padding="5dp"         android:textcolor="@android:color/white" />     </relativelayout>      <imageview         android:id="@+id/mappreview"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@id/cal_event_title"         android:layout_alignparentright="true"         android:paddingright="5dp"                android:clickable="true"         android:src="@drawable/ic_event_map"         android:onclick="showmap"         android:background="@drawable/textview_border"         android:layout_marginright="5dp"/>      <textview         android:id="@+id/cal_address"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_below="@id/date_time_container"         android:padding="5dp"         android:textcolor="@android:color/white"         android:textsize="16sp"         android:textstyle="bold"         android:typeface="sans" />      <scrollview         android:id="@+id/scroll_description"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@id/cal_address"         android:padding="5dp"         android:scrollbars="vertical" >          <relativelayout             android:id="@+id/map_container"             android:layout_width="match_parent"             android:layout_height="wrap_content" >              <textview                 android:id="@+id/cal_description"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:textcolor="@android:color/white"/>         </relativelayout>      </scrollview>      <com.google.android.maps.mapview         android:id="@+id/mapview"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_centerinparent="true"         android:apikey="your_google_api_key"         android:clickable="true"         android:visibility="gone" />  </relativelayout> 

i give small hint; right busy @ work can not implement this.

the steps are

  • get drawing cache bitmap
  • set content imageview bitmap
  • apply animation imageview
  • at end of animation re set content

this believe maximize performance.

i try write code later.

code

view longlivingreference; //keep reference private void applyrotation(int position, float start, float end) {     longlivingreference = findviewbyid(r.id.event_container);     longlivingreference .setdrawingcacheenabled(true);     bitmap bitmapforanimation = bitmap.createbitmap(longlivingreference.getdrawingcache());     imageview iv = new imageview(mcontext);     iv = new imageview(mcontext);     iv.setimagebitmap(bitmapforanimation);     setcontentview(iv);      final float centerx = mcontainer.getwidth() / 2.0f;     final float centery = mcontainer.getheight() / 2.0f;     final rotate3danimation rotation = new rotate3danimation(start, end, centerx, centery, 310.0f, true);     rotation.setduration(500);     rotation.setfillafter(true);     rotation.setinterpolator(new accelerateinterpolator());     rotation.setanimationlistener(youranimationlistener {         //whatever animationlistener is, can call super.onanimationend if needed         @override         public void onanimationend(animation animation) {             setcontentview(longlivingreference);         }     });     iv.startanimation(rotation); } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -