varun
varun

Reputation: 778

change gesture color at run time

I want to change gesture color at run time.
I am able to change gesture color using layout XML but not using code.
I have tried

private class GesturesProcessor implements GestureOverlayView.OnGestureListener {
    public GesturesProcessor() {
        GestureOverlayView overlay = (GestureOverlayView) findViewById(R.id.gestures_overlay);
        Log.i("on", "constructor");
        overlay.setGestureColor(R.color.lightblue);
    }

    public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) {
        mDoneButton.setEnabled(false);
        mGesture = null;
        Log.i("on", "ongesture started");
    }

    public void onGesture(GestureOverlayView overlay, MotionEvent event) {
    }

    public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) {
        mGesture = overlay.getGesture();
        Log.i("on", "gesture ended");
        /*if (mGesture.getLength() < LENGTH_THRESHOLD) {
           overlay.clear(false);
        }*/
        mDoneButton.setEnabled(true);
    }

    public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) {
        Log.i("on", "gesture ended");
    }
}

but it's not working

Upvotes: 4

Views: 1892

Answers (2)

Arvind Kumar
Arvind Kumar

Reputation: 21

All you need to do is just override onGesturePerformed() method and then try to change the color as I have done below.

       @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    gestureView = (GestureOverlayView)findViewById(R.id.gvDrawingPadOrange);
    gestureView.setFadeOffset(3600000);
    gestureView.setEnabled(true);
    gestureView.setDrawingCacheEnabled(true);

    gestureView.addOnGesturePerformedListener(new GestureOverlayView.OnGesturePerformedListener() {

        public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {


        }
    });
    gestureView.setUncertainGestureColor(getResources().getColor(R.color.colorPrimary));
    gestureView.setGestureColor(Color.BLUE);
}

Upvotes: 2

Tofeeq Ahmad
Tofeeq Ahmad

Reputation: 11975

To change Gesture color use

gestureOverlayView.setGestureColor(Color.BLACK);

where gestureOverlayView is the object of GestureOverLayView.

From resource use this if you have hex string value for color

gestureOverlayView.setGestureColor(Color.parseColor(R.string.Color));

Upvotes: 3

Related Questions