touch - Blackberry custom slideshow-style BitmapField manager -


right now, i'm trying figure out how implement following:

suppose have custom manager has 10 or bitmapfields layed out in horizontal manner (similar slideshow contained in hfm ) . want achieve able move image hfm via touchevent horizontally, bitmapfield take focus on left-hand side of custom manager. in other words, have give value sethorizontalscroll , if so, matter of incrementing value when user makes left or right touch event. also, how can focus of field within given position on screen (i.e. left-most field on hfm) when hfm scrolling sideways via touchevent?

1 - yes, sethorizontalscroll should work, don't forget use horizontal_scroll in manager constructor

2 - try test each field getcontentrect() eventtouch getx(int) , gety(int)

update

to simplify global field position calculation use

    public xypoint getglobalxy(field field) {         xypoint result = new xypoint(field.getleft(), field.gettop());         if (field.getmanager() != null) {             result.translate(getglobalxy(field.getmanager()));         }         return result;     } 

thread safe message dialog:

    public void showmessage(final string message) {         uiapplication.getuiapplication().invokelater(new runnable() {             public void run() {                 dialog.inform(message);             }         });      } 

sample code:

class scr extends mainscreen {     horizontalfieldmanager hfm;         public scr() {         add(new labelfield("asdfsad"));         hfm = new horizontalfieldmanager(horizontal_scroll);         (int = 0; < 5; i++) {             bitmap bmp = new bitmap(100, 100);             graphics g = graphics.create(bmp);             g.setfont(g.getfont().derive(100));             string txt = string.valueof(i);             int x = g.getfont().getadvance(txt);             g.drawtext(txt, x, 0);             bitmapfield bf = new bitmapfield(bmp);             hfm.add(bf);         }         add(hfm);     }              protected boolean touchevent(touchevent message) {         if (message.getevent() == touchevent.click) {             int x = message.getx(1);             int y = message.gety(1);             xyrect r = hfm.getextent();             r.setlocation(getglobalxy(hfm));                 if (r.contains(x, y)) {                 xyrect rf = hfm.getfield(2).getextent();                 rf.setlocation(getglobalxy(hfm.getfield(2)));                     if (x < rf.x) {                     showmessage("left side");                 } else if (x > rf.x2()) {                     showmessage("right side");                 } else {                     showmessage("field");                 }             }         }         return super.touchevent(message);     } } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -