• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps hello everyone. seek help! GestureOverlay's problem

BoneLee

Lurker
Hello everybody. when I am in the development of android application about gesture,I encountered a problem.
When I use GestureOverlay's function setGestureColor to change the gesture's color,but that does not work? I can only set the xml attributes "android: gestureColor" to change the gesture's stroke color!
This is my code:
GestureOverlayView overlay=(GestureOverlayView)findViewById(R.id.gestures_overlay);
overlay.setBackgroundColor(Color.MAGENTA);//It works!!!
overlay.setGestureColor(Color.BLUE);//Not work
overlay.setGestureStrokeWidth(12);//It works
Am I wrong? Because I want to dynamically change the color of gesture stroke, please help me, thanks a lot.
 
I've been having the same problem and I finally found the solution. If you look at the source code for GestureOverlayView, you'll notice a boolean test for mHandleGestureActions at line 559 (and others) that makes a call to [private void] setCurrentColor when drawing the gesture. Unfortunately mHandleGestureActions is only set when you use the OnGesturePerformedListener listener.

This is a total hack; but it works:

Create a stub view that implements the OnGesturePerformedListener and add that to your overlay's list of OnGesturePerformedListeners. You don't have to
do anything with the listener; but it needs to be a separate view from the one you're using as the REAL listener (or you'll crash your app). Then add your
OnGesturingListener or OnGestureListener view that does the REAL work.
 
codelurker, thank you for your post. It helped me to solve the same problem with the gesture color, though I was able to add the OnGesturePerformedListener as another interface to my listener class and did not need to create a stubView as follows:

class
GesturesProcessor implements GestureOverlayView.OnGestureListener,

OnGesturePerformedListener {
}
 
Back
Top Bottom