1. Download our Official Android App: Forums for Android!

Apps hello everyone. seek help! GestureOverlay's problem

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

  1. BoneLee

    BoneLee Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Nov 7, 2010

    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 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Nov 7, 2010

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

    NightAngel79 Bounty Hunter Administrator
    Moderator
    Rank:
     #16
    Points:
    1,453
    Posts:
    22,517
    Joined:
    May 11, 2010

    May 11, 2010
    22,517
    7,962
    1,453
    Male
    Systems Administrator
    Northern Ky
    moved to developer section
     
  4. codelurker

    codelurker Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jan 20, 2011

    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 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jan 27, 2011

    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...