android - What are correct callback methods to implement custom toolbar with scrolling and various gesture features? -
implement toolbar control custom view regarding: goal achieve scrolling features using xamarin.android framework , without using actionbar according business requirement. required features left , right swipe, drag tool bar buttons, fling etc.
the scroll should work more accuracy ex: if user scrolls (or flings) tool bar fast left right or right left, should directly show last button. i.e. similar actionbar comes of modern android devices.
what correct call-back method achieve please
the high level design considerations are: toolbar button class implements imagebutton. toolbar button designed inner class of toolbarcontrol class custom view implementing viewgroup not want use actionbar @ moment. want override onmeasure, onlayout methods , implement ontouch() , onfling(). override onintercepttouchevent(motionevent ev), ontouchevent(motionevent ev). based on sample code in http://developer.android.com/training/gestures/index.html
code snippet:
//to implement scrolling //to watch events viewgroup dispatched child views public override bool onintercepttouchevent(motionevent e) { //system.out.println(...) console.writeline("onintercepttouchevent"); boolean intercept = false; viewconfiguration configuration = viewconfiguration .get(context); int mtouchslop = configuration.scaledtouchslop; try { switch (e.action) { case motioneventactions.move: { int xdiff = (int)math.abs(e.getx() - m_flastx); if (xdiff > mtouchslop) { m_ntouchstate = c_ntouchstatehorizontalscrolling; m_flastx = e.getx(); } int ydiff = (int)math.abs(e.gety() - m_flasty); if (ydiff > mtouchslop) { m_ntouchstate = -1; } if (math.abs(xdiff * 2) > math.abs(ydiff) && xdiff > mtouchslop) { intercept = true; } break; } case motioneventactions.cancel: case motioneventactions.up: // release drag. m_ntouchstate = c_ntouchstaterest; break; case motioneventactions.down: m_flasty = e.gety(); m_flastx = e.getx(); break; default: break; } } catch (exception ex) { } return intercept; } public override bool ontouchevent(motionevent e) { //system.out.println(...) console.writeline("tb ontouchevent"); try { float x = e.getx(); float y = e.gety(); switch (e.action) { case motioneventactions.down: if (!m_scroller.isfinished) { m_scroller.abortanimation(); } m_flastx = x; if (m_scroller.isfinished) { m_ntouchstate = c_ntouchstaterest; } else { m_ntouchstate = c_ntouchstatehorizontalscrolling; } break; case motioneventactions.move: int deltax = (int)(m_flastx - x); m_flastx = x; int scrollx = scrollx; // scroll right if (deltax < 0) { if (scrollx > 0) { scrollby(math.max(-scrollx, deltax), 0); } } // scroll left else if (deltax > 0) { // visible full icons without empty spaces int availabletoscroll = getchildat(childcount - 1).right - scrollx - (display.width - c_ntoolindent); if (availabletoscroll > 0) { scrollby(math.min(availabletoscroll, deltax), 0); } } break;
Comments
Post a Comment