4

Is there a public or private API that would let application get the surface that was touched? I am interested in Android and/or iOS.

In other words, I am intrested in shape of the finger that touched the screen.

A solution that would return a matrix of touched rectangles would be ok too.

(I am 90% positive there is no such thing, but I hope someone can prove me wrong)

johndodo
  • 17,247
  • 15
  • 96
  • 113
  • I do not know of anything like that on iOS. iOS detects where your fingers are itself, I don't think you can get access to the raw sensor information. – fishinear Jan 08 '12 at 19:14
  • Unless someone has found a way, I don't think this is available on Android. Android registers touches in single pixel coordinates and I'd think you'd have to bypass the OS and get to the hardware level. – DeeV Jan 23 '12 at 18:12
  • 1
    On Android, I should think that the best you can do is use the MotionEvent.getSize(), which returns the size of the finger (not the shape though). http://developer.android.com/reference/android/view/MotionEvent.html#getSize%28int%29 – Jave Jan 24 '12 at 09:01
  • @Deev, fishinear: it is possible on both platforms, see my answer... but I would still like to find some other method, hack, additional info under what conditions can be done... I will give bounty to anyone who provides the most additional information. – johndodo Jan 26 '12 at 12:26
  • @Jave: care to post it as a separate answer? – johndodo Jan 26 '12 at 12:26

3 Answers3

3

Answer as per request:
On Android, I should think that the best you can do is use the MotionEvent.getSize(), which returns the size of the finger (not the shape though). The API demo TouchPaint uses this.

Jave
  • 31,598
  • 14
  • 77
  • 90
1

This code is an idea about how to get the touched rectangles. For each new rectangle touched a counter will be added 1, so there is easier track the touch movement (if needed). For more accuracy, change the values for the constants ROWS and COLS

#define ROWS 15
#define COLS ROWS

int matrix[ROWS][COLS];
int squareCounter;


- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];

    int col = floor((location.x * COLS) / self.view.frame.size.width);
    int row = floor((location.y * ROWS) / self.view.frame.size.height);
    if (matrix[col][row] == 0) matrix [col][row] = ++ squareCounter;

    [label setText:[NSString stringWithFormat:@"[%d][%d] -> %d", col, row, matrix[col][row]]];
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSString *matrixStr = @"";
    for (int i = 0; i < COLS; i++) {
        for (int j = 0; j < ROWS; j++) {
            matrixStr = [matrixStr stringByAppendingFormat:@"%d\t", matrix[j][i]];
        }
        matrixStr = [matrixStr stringByAppendingString:@"\n"];
    }

    NSLog(@"Matrix:\n%@", matrixStr);
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    squareCounter = 0;
    for (int i = 0; i < ROWS; i++) {
        for (int j = 0; j < COLS; j++) {
            matrix[i][j] = 0;
        }
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

It must be placed on the view controller whose view you want to detect the touch shape.

Esepakuto
  • 1,332
  • 9
  • 12
  • If I understand correctly, only the center of the touch is reported by iOS? So this code follows the center of the finger and saves its path (and not shape) in matrix? – johndodo Jan 24 '12 at 06:47
  • That's it. In iOS the touch recognizers send only an X and an Y by touch. If you want to track two fingers the only that you have to do is to have a matrix by finger and relation between that matrix and the touch – Esepakuto Jan 24 '12 at 08:38
  • Ok, so if I want the shape of a **single** finger when **not** moving around, I am out of luck? BTW, even the size of area covered by finger would help... Android seems to support this (see my answer), how about iOS? – johndodo Jan 24 '12 at 09:00
  • I think that's a problen related with screen thechnology. The resistive screen can give something like the matrix of points pressed. But capacitive screens works in other way, I seriously doubt that you can get the aproximate shape because of the big number of points you need to define the shape. – Esepakuto Jan 24 '12 at 10:21
  • Approximate size of touch area would be enough for me - is this possible on iOS? Note that Android seems to support this, so I guess it should be possible (hardware-wise). – johndodo Jan 24 '12 at 10:25
  • I gess Android suports it because of the resistive screen devices. Did you get it work on a capacitive device? – Esepakuto Jan 24 '12 at 10:29
  • Actually, even iPhone **does** support this - I have updated my own answer. We are just not *allowed* to use it. :( – johndodo Jan 24 '12 at 10:59
1

I have found the solution for Android: https://stackoverflow.com/questions/8977510/motionevent-pointercoords-gettouchmajor-device-support. I still need to find out how supported it is though...

And for iPhone: Is there any way at all that I can tell how hard the screen is being pressed (see accepted answer). It seems there is no official way, however.

Still, I would appreciate if someone added some official or unofficial / hackish methods.

Community
  • 1
  • 1
johndodo
  • 17,247
  • 15
  • 96
  • 113