<commit_before>(function(api){
	// Interfaces
	Ti._5.EventDriven(api);
	
	var _lastOrient = null;
	
	var _orientation = Ti.UI.UNKNOWN;
	Object.defineProperty(api, 'orientation', {
		get: function(){return _orientation;},
		set: function(val){return _orientation = val;}
	});

	function getWindowOrientation() {
		_orientation = Ti.UI.PORTRAIT;
		switch (window.orientation) {
			case 90:
				_orientation = Ti.UI.LANDSCAPE_LEFT;
				break;
			case -90:
				_orientation = Ti.UI.LANDSCAPE_RIGHT;
				break;
			case 180:
				_orientation = Ti.UI.UPSIDE_PORTRAIT;
				break;
		}
		return _orientation;
	}
	getWindowOrientation();

	window.addEventListener("orientationchange", function(event) {
		getWindowOrientation();
		if (_lastOrient != _orientation) {
			_lastOrient = _orientation;
			api.fireEvent('orientationchange', {
				orientation: _orientation,
				source: event.source,
				type: 'orientationchange'
			})
		}
	}, false);

	window.addEventListener("deviceorientation", function(event) {
		var orient = null,
			_deltaOrient = 5,
			_deltaTop = 170,
			angles = {
				alpha: event.alpha || event.x,
				beta: event.beta || event.y,
				gamma: event.gamma || event.z
			};
		if (
			Math.abs(angles.beta) < _deltaOrient &&
			Math.abs(angles.gamma) > _deltaTop
		){
			orient = Ti.UI.FACE_DOWN;
		}
		if (
			Math.abs(angles.beta) < _deltaOrient &&
			Math.abs(angles.gamma) < _deltaOrient
		){
			orient = Ti.UI.FACE_UP;
		}
		if (
			Math.abs(angles.beta) > 50 && 
			0 > angles.beta &&
			_lastOrient != orient
		){
			orient = Ti.UI.UPSIDE_PORTRAIT;
		}
		if (null != orient && _lastOrient != orient) {
			_lastOrient = orient;
			api.fireEvent('orientationchange', {
				orientation: orient,
				source: event.source,
				type: 'orientationchange'
			});
		}
    }, false);

	var _tLastShake = new Date(),
		_lastAccel = {},
		_delta = 10; // need some delta for coordinates changed
	window.addEventListener("devicemotion", function(event) {
		var e = event.acceleration || event.accelerationIncludingGravity,
			accel = e && {
				x: e.x,
				y: e.y,
				z: e.z
			};
		if (accel) {
			if (_lastAccel.x || _lastAccel.y || _lastAccel.z) {
				if (
					((Math.abs(_lastAccel.x - accel.x) > _delta) && (Math.abs(_lastAccel.y - accel.y) > _delta)) || 
					((Math.abs(_lastAccel.x - accel.x) > _delta) && (Math.abs(_lastAccel.z - accel.z) > _delta)) || 
					((Math.abs(_lastAccel.y - accel.y) > _delta) && (Math.abs(_lastAccel.z - accel.z) > _delta))
				) {
					var currentTime = new Date();
					var timeDifference = currentTime.getTime() - _tLastShake.getTime();
					if (timeDifference > 300) {
						_tLastShake = currentTime;
						
						api.fireEvent('shake', {
							source: event.source,
							timestamp: timeDifference,
							type: 'shake'
						})
					}
				}
			}
			_lastAccel = accel;
		}
	}, false);
			
})(Ti._5.createClass('Titanium.Gesture'));<commit_msg>[TIMOB-6275] Cleaned up Ti.Gesture and fixed bug with orientation not being initialized properly.<commit_after>(function(api){
	var on = require.on,
		lastOrient = null,
		lastShake = new Date(),
		lastAccel = {};

	// Interfaces
	Ti._5.EventDriven(api);

	//Ti._5.prop(api, 'orientation', Ti.UI.UNKNOWN);
	api.orientation = Ti.UI.UNKNOWN;

	function getWindowOrientation() {
		api.orientation = Ti.UI.PORTRAIT;
		switch (window.orientation) {
			case 90:
				api.orientation = Ti.UI.LANDSCAPE_LEFT;
				break;
			case -90:
				api.orientation = Ti.UI.LANDSCAPE_RIGHT;
				break;
			case 180:
				api.orientation = Ti.UI.UPSIDE_PORTRAIT;
				break;
		}
		return api.orientation;
	}
	getWindowOrientation();

	on(window, "orientationchange", function(evt) {
		getWindowOrientation();
		lastOrient !== api.orientation && api.fireEvent('orientationchange', {
			orientation: lastOrient = api.orientation,
			source: evt.source
		});
	});

	function deviceOrientation(evt) {
		var orient = null,
			beta = Math.abs(evt.beta || evt.y|0 * 90),
			gamma = Math.abs(evt.gamma || evt.x|0 * 90);

		beta < 5 && gamma > 170 && (orient = Ti.UI.FACE_DOWN);
		beta < 5 && gamma < 5 && (orient = Ti.UI.FACE_UP);
		beta > 50 && 0 > beta && lastOrient != orient && (orient = Ti.UI.UPSIDE_PORTRAIT);

		if (orient !== null && lastOrient !== orient) {
			api.fireEvent('orientationchange', {
				orientation: lastOrient = orient,
				source: evt.source
			});
		}
	}

	on(window, "MozOrientation", deviceOrientation);
	on(window, "deviceorientation", deviceOrientation);

	on(window, "devicemotion", function(evt) {
		var e = evt.acceleration || evt.accelerationIncludingGravity,
			x, y, z,
			currentTime,
			accel = e && {
				x: e.x,
				y: e.y,
				z: e.z,
				source: evt.source
			};

		if (accel) {
			if (lastAccel.x || lastAccel.y || lastAccel.z) {
				x = Math.abs(lastAccel.x - accel.x) > 10;
				y = Math.abs(lastAccel.y - accel.y) > 10;
				z = Math.abs(lastAccel.z - accel.z) > 10;
				if ((x && (y || z)) || (y && z)) {
					currentTime = (new Date()).getTime();
					if ((accel.timestamp = currentTime - lastShake) > 300) {
						lastShake = currentTime;
						api.fireEvent('shake', accel);
					}
				}
			}
			lastAccel = accel;
		}
	});

})(Ti._5.createClass('Titanium.Gesture'));
{'fraction_non_alphanumeric': 0.15552550231839257, 'fraction_numerical': 0.011398763523956723, 'mean_word_length': 3.0382215288611545, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, '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': '5813191', 'n_tokens_mistral': 2315, 'n_tokens_neox': 1846, 'n_words': 365}