<commit_before>/**
 * @author <NAME>
 */

var self, db, mapview, containerView, backgroundView, clueLabel, hotColdImage;
var firstlocation;
var clue = [];
var currentLocation;
var tabGroup;
var ResearchQuestionsWindow, rqWindow, rqView, rqSubmitButton;
var sliderValues = ['Strongly disagree', 'Disagree', 'Somewhat disagree', 'Neither agree nor disagree', 'Somewhat agree', 'Agree', 'Strongly Agree'];
var android_toolbar_setup = false;
var answeredResearchQuestions = false;
var currentClue;
var locationUpdates = 0;
var debugLabel;

Ti.include("/lib/version.js");

function updateResearchQuestions()
{
	var rqArray = db.getResearchQuestions(clue.id);
	Ti.API.info("UpdateResearchQuestions(): " + rqArray.length + " research questions available.");
	if (rqArray.length == 0) {
		return;
	}

	var labels = [];
	var children = rqView.getChildren();
	for (var i = 0; i < children.length; i++) {
		if (children[i].title && children[i].title === "Submit") continue;
		rqView.remove(children[i]);
	}
	
	for (var i = 0; i < rqArray.length; i++) {
		if (i > 0) {
			var hr = Titanium.UI.createView({
				width: '100%',
				height: 1,
				borderWidth: 1,
				borderColor: "black"
			});
			rqView.add(hr);
		}
		var questionLabel = Titanium.UI.createLabel({
			text: rqArray[i].questiontext,
			height:Ti.UI.SIZE,
			left:'10dp',
			right:'10dp',
			font: {fontSize: '17dp'},
			touchEnabled:false,
			top:'15dp',
			color:'black'
		});
		rqView.add(questionLabel);
		var slider;
		// FIXME: Handle question types properly
		//if (rqArray[i].questiontype == 1) {
			slider = Titanium.UI.createSlider({
				min:1,
				max:7,
				value:4,
				width:'90%',
				height:'auto',
				top:'4dp',
				bottom:'15dp',
				oldvalue:-1,
				id:rqArray[i].id,
				labelid:i
			});
			slider.addEventListener('change', function(e) {
				if (Math.round(e.value) != e.source.oldvalue) {
					Ti.API.info("slider " + e.source.id + " has a value of " + Math.round(e.value));
					db.saveResearchQuestion(e.source.id, sliderValues[Math.round(e.value)-1]);
					e.source.oldvalue = Math.round(e.value);
					labels[e.source.labelid].text = sliderValues[Math.round(e.value)-1];
				}
			});
			labels[i] = Titanium.UI.createLabel({
				text:sliderValues[slider.value],
				top:'10dp',
				touchEnabled:false,
				color:'#777777',
				font:{fontSize:'14dp'}
			});
			rqView.add(labels[i]);
			rqView.add(slider);
		//}
	}

	Ti.App.addEventListener("researchQuestionsSubmitted", function(e) {
		db.startClue(clue.id);
		db.uploadClueData(clue.id, false);
		var newHeight = clueLabel.size.height + clueLabel.rect.y*2;
		Ti.API.info("height: ", newHeight);
		backgroundView.height = newHeight;
	});
	
	rqWindow.open();
};

function fireUpTheCamera() {
	Titanium.Media.showCamera({
	
		success:function(event)
		{
			var image = (android) ? event.media.file.read() : event.media;
			//var cropRect = event.cropRect;
			Ti.API.info('fireUpTheCamera(): Successfully took picture. Our type was: '+event.mediaType);
			if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
			{
				// FIXME: Verify that camera operation works and it saves image properly
				Ti.API.info("Got picture. Finishing hunt and saving image");
				Ti.API.info("Picture size: " + image.width + "x" + image.height);
				var resizedImage;
				
				/*if (android) {
					var maxsize = Math.max(cropRect.width, cropRect.height);
					var multiplier = (maxsize / 400) + 1;
					resizedImage = Ti.UI.createImageView({image:image,height:cropRect.height / multiplier,width:cropRect.width / multiplier,canScale:true}).toImage();
				} else {*/
					var multiplier = 1;
					if(image.height > image.width && image.height > 400)
						multiplier = 400 / image.height;
					else if(image.height < image.width && image.width > 400)
						multiplier = 400 / image.width;
					//var maxsize = Math.max(image.width, image.height);
					//var multiplier = (maxsize / 400) + 1;
					resizedImage = image.imageAsResized(image.width * multiplier, image.height * multiplier);
				//}
				Ti.API.info("fireUpTheCamera(): Finishing hunt. huntId: " + clue.huntid + " clueOnlineId: " + clue.OnlineId);
				//Ti.API.info("Resized picture size: " + resizedImage.width + "x" + resizedImage.height);
				currentClue = -1;
				db.finishClue(clue.id);
				db.uploadClueData(clue.id, true);
				db.finishHunt(clue.huntid, clue.OnlineId, resizedImage);
				clue = db.getCurrentClue();
				clueLabel.text = "Please select a new hunt.";
				tabGroup.setActiveTab(0);
				Ti.App.fireEvent('forceHuntRefresh');
				// Go back to SelectHunt tab
				/*
				var imageView = Ti.UI.createImageView({
					width:self.width,
					height:self.height,
					image:event.media
				});
				self.add(imageView);
				*/
			}
			else
			{
				alert("Camera had an error taking the picture. Please report this.");
			}
		},
		cancel:function()
		{
		},
		error:function(error)
		{<commit_msg>Made a few changes to FireUpTheCamera in order to hopefully prevent users from being able to continue when the camera fails. Need to look into this further.<commit_after>/**
 * @author <NAME>
 */

var self, db, mapview, containerView, backgroundView, clueLabel, hotColdImage;
var firstlocation;
var clue = [];
var currentLocation;
var tabGroup;
var ResearchQuestionsWindow, rqWindow, rqView, rqSubmitButton;
var sliderValues = ['Strongly disagree', 'Disagree', 'Somewhat disagree', 'Neither agree nor disagree', 'Somewhat agree', 'Agree', 'Strongly Agree'];
var android_toolbar_setup = false;
var answeredResearchQuestions = false;
var currentClue;
var locationUpdates = 0;
var debugLabel;

Ti.include("/lib/version.js");

function updateResearchQuestions()
{
	var rqArray = db.getResearchQuestions(clue.id);
	Ti.API.info("UpdateResearchQuestions(): " + rqArray.length + " research questions available.");
	if (rqArray.length == 0) {
		return;
	}

	var labels = [];
	var children = rqView.getChildren();
	for (var i = 0; i < children.length; i++) {
		if (children[i].title && children[i].title === "Submit") continue;
		rqView.remove(children[i]);
	}
	
	for (var i = 0; i < rqArray.length; i++) {
		if (i > 0) {
			var hr = Titanium.UI.createView({
				width: '100%',
				height: 1,
				borderWidth: 1,
				borderColor: "black"
			});
			rqView.add(hr);
		}
		var questionLabel = Titanium.UI.createLabel({
			text: rqArray[i].questiontext,
			height:Ti.UI.SIZE,
			left:'10dp',
			right:'10dp',
			font: {fontSize: '17dp'},
			touchEnabled:false,
			top:'15dp',
			color:'black'
		});
		rqView.add(questionLabel);
		var slider;
		// FIXME: Handle question types properly
		//if (rqArray[i].questiontype == 1) {
			slider = Titanium.UI.createSlider({
				min:1,
				max:7,
				value:4,
				width:'90%',
				height:'auto',
				top:'4dp',
				bottom:'15dp',
				oldvalue:-1,
				id:rqArray[i].id,
				labelid:i
			});
			slider.addEventListener('change', function(e) {
				if (Math.round(e.value) != e.source.oldvalue) {
					Ti.API.info("slider " + e.source.id + " has a value of " + Math.round(e.value));
					db.saveResearchQuestion(e.source.id, sliderValues[Math.round(e.value)-1]);
					e.source.oldvalue = Math.round(e.value);
					labels[e.source.labelid].text = sliderValues[Math.round(e.value)-1];
				}
			});
			labels[i] = Titanium.UI.createLabel({
				text:sliderValues[slider.value],
				top:'10dp',
				touchEnabled:false,
				color:'#777777',
				font:{fontSize:'14dp'}
			});
			rqView.add(labels[i]);
			rqView.add(slider);
		//}
	}

	Ti.App.addEventListener("researchQuestionsSubmitted", function(e) {
		db.startClue(clue.id);
		db.uploadClueData(clue.id, false);
		var newHeight = clueLabel.size.height + clueLabel.rect.y*2;
		Ti.API.info("height: ", newHeight);
		backgroundView.height = newHeight;
	});
	
	rqWindow.open();
};

function fireUpTheCamera() {
	Titanium.Media.showCamera({
	
		success:function(event) {
			var image = (android && event.media.file && event.media.file.exists()) ? event.media.file.read() : event.media;
			//var cropRect = event.cropRect;
			Ti.API.info('fireUpTheCamera(): Successfully took picture. Our type was: '+event.mediaType);
			if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
				if(image) {
					// FIXME: Verify that camera operation works and it saves image properly
					Ti.API.info("Got picture. Finishing hunt and saving image");
					Ti.API.info("Picture size: " + image.width + "x" + image.height);
					
					/*if (android) {
						var maxsize = Math.max(cropRect.width, cropRect.height);
						var multiplier = (maxsize / 400) + 1;
						resizedImage = Ti.UI.createImageView({image:image,height:cropRect.height / multiplier,width:cropRect.width / multiplier,canScale:true}).toImage();
					} else {*/
						var multiplier = 1;
						if(image.height > image.width && image.height > 400)
							multiplier = 400 / image.height;
						else if(image.height < image.width && image.width > 400)
							multiplier = 400 / image.width;
						//var maxsize = Math.max(image.width, image.height);
						//var multiplier = (maxsize / 400) + 1;
						var resizedImage = image.imageAsResized(image.width * multiplier, image.height * multiplier);
					//}
					Ti.API.info("fireUpTheCamera(): Finishing hunt. huntId: " + clue.huntid + " clueOnlineId: " + clue.OnlineId);
					//Ti.API.info("Resized picture size: " + resizedImage.width + "x" + resizedImage.height);
				}
				else {
					var resizedImage = null;
					alert("Error obtaining image from camera. Please report this.");
				}
				currentClue = -1;
				db.finishClue(clue.id);
				db.uploadClueData(clue.id, true);
				db.finishHunt(clue.huntid, clue.OnlineId, resizedImage);
				clue = db.getCurrentClue();
				clueLabel.text = "Please select a new hunt.";
				tabGroup.setActiveTab(0);
				Ti.App.fireEvent('forceHuntRefresh');
			}
			else{
				alert("Camera had an error taking the picture. Please report this.");
			}
		},
		cancel:function(){
		},
		error:function(error){
{'fraction_non_alphanumeric': 0.15536637275767712, 'fraction_numerical': 0.012972534711665146, 'mean_word_length': 3.489535941765241, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '796259', 'n_tokens_mistral': 4103, 'n_tokens_neox': 3322, 'n_words': 702}