1

I have an Imageview with different number of touch points on them. It basically an app which is detecting the swipe between 2 touch points and not allowing the user to swipe any other point or in or out of other direction. It should constrict user to just swipe between two touch points.

Just take a look at following picture:

enter image description here

Now the user should start swiping from point 1 to point 2. if the swipe is not started from starting point 1, it should not color the path between point 1 and point 2.

But if the user successfully swipe between the point 1 and point 2 now swipe between point 2 to 3 should be enabled. Thus user should go through Point 1 to 2, Point 2 to 3 , Point 3 to 4 , point 4 to point 5 to complete round 1.

Please tell me how to achieve this functionality . I know about gestures, gesture overlay etc but none of them fits to my condition as they uses general touch events and gesture directions.

Please suggest me the way to achieve this and keep in mind I want to make this app to be able to run on all type of devices , so I can simply give the hard coded x,y values.

Edit : on Demand I am posting the link of the app on play store who has same functionality , But I do not know How they are achieving this functionality .

https://play.google.com/store/apps/details?id=al.trigonom.writeletters

Allay Khalil
  • 674
  • 3
  • 11
  • 31

2 Answers2

0

If each touch point can be created as individual views(e.g. ImageView), then you can create an inViewInBounds() function. I used code from here to create code where I needed to detect finger press movement over multiple imageViews:

Rect outRect = new Rect();
int[] location = new int[2];

//Determine if a touch movement is currently over a given view.
private boolean inViewInBounds(View view, int x, int y){
    view.getDrawingRect(outRect);
    view.getLocationOnScreen(location);
    outRect.offset(location[0], location[1]);
    return outRect.contains(x, y);
}

To use this function, on a parent view to all those child touch points, set the Click and Touch Listeners:

    //This might look redundant but is actually required: "The empty OnClickListener is required to keep OnTouchListener active until ACTION_UP"
    parentView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {}
    });
    //All the work gets done in this function:
    parentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            int x = (int)event.getRawX();
            int y = (int)event.getRawY();
            // ** myTouchPoint might be an array that you loop through here...
            if ( inViewInBounds(myTouchPoint, x, y) ) doLogic(myTouchPoint);
            return false;
        }
    });

The code above only shows detecting when one of your views are 'touched'. if none are 'touched' but a view is 'active' (e.g. When a touch is detected, set a variable like: viewLastTouched = myTouchPoint) then you would call something like drawingLine(viewLastTouched, x, y) function - for whatever it needed to do to draw the line and/or detect boundaries etc.

Community
  • 1
  • 1
Aaron
  • 214
  • 1
  • 7
  • I'm trying to do something similar, but once you swipe from point A to point B, I need to see whether or not the user is keeping their finger holding point B. Do you have any advice for something like this? – darkknightsds Sep 26 '18 at 18:50
0

They are not using android native java code to build this app.

The app is running with this code

import Runtime.MMFRuntime;
public class Main extends MMFRuntime {
}

This in turn is from https://github.com/ClickteamLLC/android/blob/master/docs/index.md

This is used to package apps / games written using - http://www.clickteam.com/clickteam-fusion-2-5

appbootup
  • 9,537
  • 3
  • 33
  • 65