<commit_before>package jp.co.so2.pinch;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.view.View;

public class UIPinchView extends TiUIView 
{
	public PinchView tiPinchView;
	private float maxZoom = 5.f;
	private float minZoom = 0.1f;
	
	public UIPinchView(TiViewProxy proxy)
	{
		super(proxy);
		
		setNativeView(tiPinchView = new PinchView(proxy.getActivity()));
	}
	
	@Override
	public void processProperties(KrollDict d) {
		super.processProperties(d);
		if(d.containsKeyAndNotNull("maxZoomValue"))
			maxZoom = d.getDouble("maxZoomValue").floatValue();
		if(d.containsKeyAndNotNull("minZoomValue"))
			minZoom = d.getDouble("minZoomValue").floatValue();
		
		Log.d("UIPinchView", minZoom + " " + maxZoom);
	}
	
	public void setMaxZoomValue(float maxZoom)
	{
		this.maxZoom = maxZoom;
	}
	
	public void setMinZoomValue(float minZoom)
	{
		this.minZoom = minZoom;
	}
	
	public class PinchView extends View {
		private static final int INVALID_POINTER_ID = -1;
		private int activePointerId;
		private ScaleGestureDetector pinchDetector;
		private float scaleFactor = 1.f;
		private float lastX, lastY;
		
		public PinchView(Context c)
		{
			super(c);
			if(c.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH))
				pinchDetector = new ScaleGestureDetector(c, new ScaleListener());
		}
		
		@Override
		public boolean onTouchEvent(MotionEvent e)
		{
			if(pinchDetector != null)
				pinchDetector.onTouchEvent(e);
			
			final int action = e.getAction();
			KrollDict eventData = new KrollDict();
			
			
			switch(action & MotionEvent.ACTION_MASK) {
			case MotionEvent.ACTION_DOWN: {
				final float x = e.getX();
				final float y = e.getY();
				eventData.put("x", e.getX());
				eventData.put("y", e.getY());
				proxy.fireEvent("multiStart", eventData);
				activePointerId = e.getPointerId(0);
				lastX = x;
				lastY = y;
				break;
				}
			case MotionEvent.ACTION_MOVE: {
				final int pointerIndex = e.findPointerIndex(activePointerId);
				if(pointerIndex == INVALID_POINTER_ID)
					break;
				final float x = e.getX(pointerIndex);
				final float y = e.getY(pointerIndex);
				if(!pinchDetector.isInProgress())
				{
					eventData.put("x", x - lastX);
					eventData.put("y", y - lastY);
					proxy.fireEvent("multiMove", eventData);
				}
				lastX = x;
				lastY = y;
				break;
				}
			case MotionEvent.ACTION_UP: {
				activePointerId = INVALID_POINTER_ID;
				eventData.put("x", e.getX());
				eventData.put("y", e.getY());<commit_msg>Added a null check that was crashing single touch devices<commit_after>package jp.co.so2.pinch;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.view.View;

public class UIPinchView extends TiUIView 
{
	public PinchView tiPinchView;
	private float maxZoom = 5.f;
	private float minZoom = 0.1f;
	
	public UIPinchView(TiViewProxy proxy)
	{
		super(proxy);
		
		setNativeView(tiPinchView = new PinchView(proxy.getActivity()));
	}
	
	@Override
	public void processProperties(KrollDict d) {
		super.processProperties(d);
		if(d.containsKeyAndNotNull("maxZoomValue"))
			maxZoom = d.getDouble("maxZoomValue").floatValue();
		if(d.containsKeyAndNotNull("minZoomValue"))
			minZoom = d.getDouble("minZoomValue").floatValue();
		
		Log.d("UIPinchView", minZoom + " " + maxZoom);
	}
	
	public void setMaxZoomValue(float maxZoom)
	{
		this.maxZoom = maxZoom;
	}
	
	public void setMinZoomValue(float minZoom)
	{
		this.minZoom = minZoom;
	}
	
	public class PinchView extends View {
		private static final int INVALID_POINTER_ID = -1;
		private int activePointerId;
		private ScaleGestureDetector pinchDetector;
		private float scaleFactor = 1.f;
		private float lastX, lastY;
		
		public PinchView(Context c)
		{
			super(c);
			if(c.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH))
				pinchDetector = new ScaleGestureDetector(c, new ScaleListener());
		}
		
		@Override
		public boolean onTouchEvent(MotionEvent e)
		{
			if(pinchDetector != null)
				pinchDetector.onTouchEvent(e);
			
			final int action = e.getAction();
			KrollDict eventData = new KrollDict();
			
			
			switch(action & MotionEvent.ACTION_MASK) {
			case MotionEvent.ACTION_DOWN: {
				final float x = e.getX();
				final float y = e.getY();
				eventData.put("x", e.getX());
				eventData.put("y", e.getY());
				proxy.fireEvent("multiStart", eventData);
				activePointerId = e.getPointerId(0);
				lastX = x;
				lastY = y;
				break;
				}
			case MotionEvent.ACTION_MOVE: {
				final int pointerIndex = e.findPointerIndex(activePointerId);
				if(pointerIndex == INVALID_POINTER_ID)
					break;
				final float x = e.getX(pointerIndex);
				final float y = e.getY(pointerIndex);
				if(pinchDetector != null && !pinchDetector.isInProgress())
				{
					eventData.put("x", x - lastX);
					eventData.put("y", y - lastY);
					proxy.fireEvent("multiMove", eventData);
				}
				lastX = x;
				lastY = y;
				break;
				}
			case MotionEvent.ACTION_UP: {
				activePointerId = INVALID_POINTER_ID;
				eventData.put("x", e.getX());
				eventData.put("y", e.getY());
{'fraction_non_alphanumeric': 0.11579129831859941, 'fraction_numerical': 0.0024267637372161555, 'mean_word_length': 4.06140350877193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2216066', 'n_tokens_mistral': 2315, 'n_tokens_neox': 1941, 'n_words': 384}