1. Check out our companion app, Forums for Android! Download from Google Play

hello everyone. seek help! GestureOverlay's problem

Discussion in 'Application Development' started by BoneLee, Nov 7, 2010.

  1. BoneLee

    BoneLee New Member
    Thread Starter
    5

    Nov 7, 2010
    2
    0
    5
    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.
     

    Advertisement

  2. BoneLee

    BoneLee New Member
    Thread Starter
    5

    Nov 7, 2010
    2
    0
    5
    anyone knows?
     
  3. NightAngel79

    NightAngel79 Bounty Hunter Administrator
    Moderator
    1,433

    May 11, 2010
    22,460
    7,856
    1,433
    Male
    Systems Administrator
    Northern Ky
    moved to developer section
     
  4. codelurker

    codelurker New Member
    5

    Jan 20, 2011
    1
    0
    5
    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.
     
  5. dogster

    dogster New Member
    5

    Jan 27, 2011
    1
    0
    5
    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 {
    }
     

Share This Page

Loading...