android - i am working on media player i want to chnage the brightness of the screen when user slide on the left sideof the screen -
i use following code detect side user slide user not working @ suppose work
relay.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent touchevent) { switch (touchevent.getaction()) { // when user first touches screen x , y coordinate case motionevent.action_down: { x1 = touchevent.getx(); y1 = touchevent.gety(); toast.maketext(videoplay.this, x1+""+x2, toast.length_short).show(); break; } case motionevent.action_up: { x2 = touchevent.getx(); y2 = touchevent.gety(); //if left right sweep event on screen if (x1 < x2) { toast.maketext(videoplay.this, "left right swap performed", toast.length_long).show(); } // if right left sweep event on screen if (x1 > x2) { toast.maketext(videoplay.this, "right left swap performed", toast.length_long).show(); } // if down sweep event on screen if (y1 < y2) { toast.maketext(videoplay.this, "up down swap performed", toast.length_long).show(); } //if down sweep event on screen if (y1 > y2) { toast.maketext(videoplay.this, "down swap performed", toast.length_long).show(); } break; } } return false; } // return super.ontouchevent(event); });
can me how can detect user has slide on right side of activity in upward or downward direction
use below code in activity
private float startpoint,endpoint; static final int min_swipe_distance = 150; @override public boolean ontouchevent(motionevent event) { switch(event.getaction()) { case motionevent.action_down: startpoint = event.getx(); break; case motionevent.action_up: endpoint = event.getx(); float dx = endpoint- startpoint; if (math.abs(dx) > min_swipe_distance) { //left right swipe } break; } return super.ontouchevent(event); }
Comments
Post a Comment