Android Drag and Drop, Click, and Scroll in a Listview -
so have layout such:
i using listview right , each row has imageview , 2 textviews.
i want able 3 things on page:
- clicking on row (or clicking on imageview in row works me too) brings me fragment.
- you can drag image in each listview row. uses dragshadowbuilder , therefore can detect if drop darker gray zone in bottom.
- you can scroll , down in listview other items overflowing right now.
as can imagine, these 3 cases difficult capture because hard differentiate between 3 (bc of overlaps in functionality).
i prefer not use onitemlongclicklistener drag , drop bc users don't think hold fingers down long time start drag , drop.
any suggestions on how implement capture 3 use cases? actually, can thought of 2 use cases because if dropped image original container, count click me. complex part make somehow work scrolling , down listview...
thanks in advance!
p.s. entire view rendered in fragment , clicking on view or dropping 1 gray area opens separate fragment.
/** * call drag source view. */ @suppresslint("newapi") public boolean ontouchevent(motionevent ev) { if (!mdragging) { return false; } final int action = ev.getaction(); final int screenx = clamp((int)ev.getrawx(), 0, mdisplaymetrics.widthpixels); final int screeny = clamp((int)ev.getrawy(), 0, mdisplaymetrics.heightpixels); switch (action) { case motionevent.action_down: // remember motion event started mmotiondownx = screenx; mmotiondowny = screeny; break; case motionevent.action_move: //set background color of remove comment box layout if(((int)ev.gety() <= 50)) imageeditingactivitynew.rl_remove.setbackgroundcolor(color.red); else imageeditingactivitynew.rl_remove.setbackgroundcolor(color.transparent); // update drag view. don't use clamped pos here dragging looks // goes off screen little, intead of bumping against edge. mdragview.move((int)ev.getrawx(), (int)ev.getrawy()); // drop on someone? final int[] coordinates = mcoordinatestemp; droptarget droptarget = finddroptarget(screenx, screeny, coordinates); if (droptarget != null) { if (mlastdroptarget == droptarget) { droptarget.ondragover(mdragsource, coordinates[0], coordinates[1],(int) mtouchoffsetx, (int) mtouchoffsety, mdragview, mdraginfo); } else { if (mlastdroptarget != null) { mlastdroptarget.ondragexit(mdragsource, coordinates[0], coordinates[1],(int) mtouchoffsetx, (int) mtouchoffsety, mdragview, mdraginfo); } droptarget.ondragenter(mdragsource, coordinates[0], coordinates[1], (int) mtouchoffsetx, (int) mtouchoffsety, mdragview, mdraginfo); } } else { if (mlastdroptarget != null) { mlastdroptarget.ondragexit(mdragsource, coordinates[0], coordinates[1], (int) mtouchoffsetx, (int) mtouchoffsety, mdragview, mdraginfo); } } mlastdroptarget = droptarget; /* original launcher activity supports delete region , scrolling. not needed in example. // scroll, maybe, not if we're in delete region. boolean indeleteregion = false; if (mdeleteregion != null) { indeleteregion = mdeleteregion.contains(screenx, screeny); } //log.d(tag, "indeleteregion=" + indeleteregion + " screenx=" + screenx // + " mscrollzone=" + mscrollzone); if (!indeleteregion && screenx < mscrollzone) { if (mscrollstate == scroll_outside_zone) { mscrollstate = scroll_waiting_in_zone; mscrollrunnable.setdirection(scroll_left); mhandler.postdelayed(mscrollrunnable, scroll_delay); } } else if (!indeleteregion && screenx > scrollview.getwidth() - mscrollzone) { if (mscrollstate == scroll_outside_zone) { mscrollstate = scroll_waiting_in_zone; mscrollrunnable.setdirection(scroll_right); mhandler.postdelayed(mscrollrunnable, scroll_delay); } } else { if (mscrollstate == scroll_waiting_in_zone) { mscrollstate = scroll_outside_zone; mscrollrunnable.setdirection(scroll_right); mhandler.removecallbacks(mscrollrunnable); } } */ break; case motionevent.action_up: //when touch remove comment box if(((int)ev.gety() <= 50)) { imageeditingactivity.rl_imageedit_comment.removeallviews(); imageeditingactivity.rl_imageedit_comment.invalidate(); //imageeditingactivity.mdraglayer.removeview(imageeditingactivity.rl_imageedit_comment); imageeditingactivity.addcomment = true; imageeditingactivity.changeiconbackground("remove"); imageeditingactivity.editparam.addrule(relativelayout.align_parent_bottom); } if (mdragging) { drop(screenx, screeny); } enddrag(); break; case motionevent.action_cancel: canceldrag(); } return true; }
Comments
Post a Comment