1

I am developing an app to interact with android interfaces for the people who has not able to interact with his hands on mobile devices.

The algorithm is based on head tracking, and I solved this issue.

So, I need to know how I could move an android pointer,or how could I set drawable or any view position through layout whether I get the position coords from another thread.

Observations:

  • I get the x and y position from ndk (c++ to java) which is in another thread. function -> public void sendPointerCoords(float x, float y) using a runnable.

  • I can't use Canvas or surface view, because after I am going to
    implement clicking using head tracking gestures.

code:

public void sendPointerCoords(float x, float y) {
        // TODO Auto-generated method stub
        final float xPos=x;
        final  float yPos=y;

        Log.v(LOG_TAG,"This are the coords ["+x+", "+y+"]");
        runOnUiThread(new Runnable() 
        {
            public void run() 
            {
                //red pointer is an image view and here chrashed when I try to move
                /*red_pointer.setPivotX(xPos);
                red_pointer.setPivotY(yPos);*/

            }
        });![enter image description here][1]

I googled but I have not found a solution which solves my needs.

faceTrackingThumbnail

2
  • Why are you using setpivotX?
    – vgonisanz
    Jun 2, 2015 at 8:48
  • setPivotX line is commented because of this, I changed the line for red_pointer.setX() and red_pointer.setY() and I found the solution but the pointer is able to move in layout not in whole device screen.
    – uelordi
    Jun 2, 2015 at 9:03

1 Answer 1

1

If you get a Image view like:

ImageView myImageView = (ImageView)findViewById(R.id.myImageViewId);

You get it with the Xml layout properties.

If you want to change their atrributes, you need store the variable ImageView _myImageView in your activity and modify it. Like:

runOnUiThread(new Runnable()
{
   public void run()
   {
      _myImageView.setX(xPos);
      _myImageView.setY(yPos);
   }
});
}

Must change your image view position and stay. If you try to findViewById again it will reset its values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.