view - How to implement the ScrollImageView class in my Android application -


i found class:

 import android.content.context; import android.graphics.bitmap; import android.graphics.canvas; import android.graphics.paint; import android.util.attributeset; import android.view.display; import android.view.motionevent; import android.view.view; import android.view.windowmanager;   // borrowed https://sites.google.com/site/androidhowto/how-to-1/custom-scrollable-image-view public class scrollimageview extends view {     private final int default_padding = 10;     private display mdisplay;     private bitmap mimage;      /* current x , y of touch */     private float mcurrentx = 0;     private float mcurrenty = 0;      private float mtotalx = 0;     private float mtotaly = 0;     /* touch distance change current touch */     private float mdeltax = 0;     private float mdeltay = 0;      int mdisplaywidth;     int mdisplayheight;     int mpadding;      public scrollimageview(context context) {         super(context);         initscrollimageview(context);     }      public scrollimageview(context context, attributeset attributeset) {         super(context);         initscrollimageview(context);     }      private void initscrollimageview(context context) {         mdisplay = ((windowmanager)context.getsystemservice(context.window_service)).getdefaultdisplay();         mpadding = default_padding;     }      @override     protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {         int width = measuredim(widthmeasurespec, mdisplay.getwidth());         int height = measuredim(heightmeasurespec, mdisplay.getheight());         setmeasureddimension(width, height);     }      private int measuredim(int measurespec, int size) {         int result = 0;         int specmode = measurespec.getmode(measurespec);         int specsize = measurespec.getsize(measurespec);          if (specmode == measurespec.exactly) {             result = specsize;         } else {             result = size;             if (specmode == measurespec.at_most) {                result = math.min(result, specsize);             }         }         return result;     }      public bitmap getimage() {         return mimage;     }      public void setimage(bitmap image) {         mimage = image;     }      public int getpadding() {         return mpadding;     }      public void setpadding(int padding) {         this.mpadding = padding;     }      @override     public boolean ontouchevent(motionevent event) {         if (event.getaction() == motionevent.action_down) {             mcurrentx = event.getrawx();             mcurrenty = event.getrawy();         }          else if (event.getaction() == motionevent.action_move) {             float x = event.getrawx();             float y = event.getrawy();              // update how touch moved             mdeltax = x - mcurrentx;             mdeltay = y - mcurrenty;              mcurrentx = x;             mcurrenty = y;              invalidate();         }         // consume event         return true;     }      @override     protected void ondraw(canvas canvas) {         if (mimage == null) {             return;         }          float newtotalx = mtotalx + mdeltax;          // don't scroll off left or right edges of bitmap.         if (mpadding > newtotalx && newtotalx > getmeasuredwidth() - mimage.getwidth() - mpadding)             mtotalx += mdeltax;          float newtotaly = mtotaly + mdeltay;          // don't scroll off top or bottom edges of bitmap.         if (mpadding > newtotaly && newtotaly > getmeasuredheight() - mimage.getheight() - mpadding)             mtotaly += mdeltay;          paint paint = new paint();         canvas.drawbitmap(mimage, mtotalx, mtotaly, paint);     } }

and stumped how use application.

i want application when in landscape orientation display bitmap image scrollable vertically , horizontally. pull image url , programatically make bitmap. call method returns bitmap image.

any ideas?

the setimage methods takes bitmap. so, should able programmatically create view in activity, set image bitmap , place view layout.

i've never seen class before, mileage may vary ;)


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -