summaryrefslogtreecommitdiff
path: root/src/com/replica/replicaisland/MultiTouchFilter.java
blob: 4df2030c3b9392d64c8866da81e5034daf49ff7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.replica.replicaisland;

import android.content.Context;
import android.content.pm.PackageManager;
import android.view.MotionEvent;

public class MultiTouchFilter extends SingleTouchFilter {
	private boolean mCheckedForMultitouch = false;
	private boolean mSupportsMultitouch = false;
	
    @Override
    public void updateTouch(MotionEvent event) {
		ContextParameters params = sSystemRegistry.contextParameters;
    	final int pointerCount = event.getPointerCount();
    	for (int x = 0; x < pointerCount; x++) {
    		final int action = event.getAction();
    		final int actualEvent = action & MotionEvent.ACTION_MASK;
    		final int id = event.getPointerId(x);
    		if (actualEvent == MotionEvent.ACTION_POINTER_UP || 
    				actualEvent == MotionEvent.ACTION_UP || 
    				actualEvent == MotionEvent.ACTION_CANCEL) {
        		BaseObject.sSystemRegistry.inputSystem.touchUp(id, 
        				event.getX(x) * (1.0f / params.viewScaleX), 
        				event.getY(x) * (1.0f / params.viewScaleY));
        	} else {
        		BaseObject.sSystemRegistry.inputSystem.touchDown(id, 
        				event.getX(x) * (1.0f / params.viewScaleX),
        				event.getY(x) * (1.0f / params.viewScaleY));
        	}
    	}
    }
    
    @Override
    public boolean supportsMultitouch(Context context) {
    	if (!mCheckedForMultitouch) {
    		PackageManager packageManager = context.getPackageManager();
    		mSupportsMultitouch = packageManager.hasSystemFeature("android.hardware.touchscreen.multitouch");
    		mCheckedForMultitouch = true;
    	}
    	
    	return mSupportsMultitouch;
    }
}