android - How to use canvas.drawCircle with Scale Detector -


i used below code. works fine need draw circle instead of image. below code image(drawable) need draw circe using cnvas.drawcircle(). plz show me way this

import android.content.context; import android.graphics.canvas; import android.graphics.drawable.bitmapdrawable; import android.util.attributeset; import android.util.log; import android.view.motionevent; import android.view.scalegesturedetector;  import android.view.view;  public class myimageview extends view {  private static final int invalid_pointer_id = -1;  private drawable mimage; private float mposx; private float mposy;  private float mlasttouchx; private float mlasttouchy; private int mactivepointerid = invalid_pointer_id;  private scalegesturedetector mscaledetector; private float mscalefactor = 1.f;  public myimageview(context context) {     this(context, null, 0); mimage=act.getresources().getdrawable(context.getresources().getidentifier("imag­ename", "drawable", "packagename"));      mimage.setbounds(0, 0, mimage.getintrinsicwidth(), mimage.getintrinsicheight()); }  public myimageview(context context, attributeset attrs) {     this(context, attrs, 0); }  public myimageview(context context, attributeset attrs, int defstyle) {     super(context, attrs, defstyle);     mscaledetector = new scalegesturedetector(context, new scalelistener()); }  @override public boolean ontouchevent(motionevent ev) {     // let scalegesturedetector inspect events.     mscaledetector.ontouchevent(ev);      final int action = ev.getaction();     switch (action & motionevent.action_mask) {     case motionevent.action_down: {         final float x = ev.getx();         final float y = ev.gety();          mlasttouchx = x;         mlasttouchy = y;         mactivepointerid = ev.getpointerid(0);         break;     }      case motionevent.action_move: {         final int pointerindex = ev.findpointerindex(mactivepointerid);         final float x = ev.getx(pointerindex);         final float y = ev.gety(pointerindex);          // move if scalegesturedetector isn't processing gesture.         if (!mscaledetector.isinprogress()) {             final float dx = x - mlasttouchx;             final float dy = y - mlasttouchy;              mposx += dx;             mposy += dy;              invalidate();         }          mlasttouchx = x;         mlasttouchy = y;          break;     }      case motionevent.action_up: {         mactivepointerid = invalid_pointer_id;         break;     }      case motionevent.action_cancel: {         mactivepointerid = invalid_pointer_id;         break;     }      case motionevent.action_pointer_up: {         final int pointerindex = (ev.getaction() & motionevent.action_pointer_index_mask)                  >> motionevent.action_pointer_index_shift;         final int pointerid = ev.getpointerid(pointerindex);         if (pointerid == mactivepointerid) {             // our active pointer going up. choose new             // active pointer , adjust accordingly.             final int newpointerindex = pointerindex == 0 ? 1 : 0;             mlasttouchx = ev.getx(newpointerindex);             mlasttouchy = ev.gety(newpointerindex);             mactivepointerid = ev.getpointerid(newpointerindex);         }         break;     }     }      return true; }  @override public void ondraw(canvas canvas) {     super.ondraw(canvas);      canvas.save();     log.d("debug", "x: "+mposx+" y: "+mposy);     canvas.translate(mposx, mposy);     canvas.scale(mscalefactor, mscalefactor);     mimage.draw(canvas);     canvas.restore(); }  private class scalelistener extends scalegesturedetector.simpleonscalegesturelistener {     @override     public boolean onscale(scalegesturedetector detector) {         mscalefactor *= detector.getscalefactor();          // don't let object small or large.         mscalefactor = math.max(0.1f, math.min(mscalefactor, 10.0f));          invalidate();         return true;     } }  } 


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

node.js - How to mock a third-party api calls in the backend -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -