<commit_before>package com.eegeo.photos;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;

import com.eegeo.helpers.IActivityIntentResultHandler;
import com.eegeo.mobileexampleapp.MainActivity;

// This class handles the dispatching of intents related to fetching an image via photo or gallery selection.
public class PhotoIntentDispatcher 
{
	public static final int REQUEST_IMAGE_CAPTURE = 1;
	public static final int SELECT_PHOTO_FROM_GALLERY = 2;
	
	private MainActivity m_activity = null;
	private List<IActivityIntentResultHandler> m_activityCallbacks = new ArrayList<IActivityIntentResultHandler>();
	private Uri m_currentPhotoPath;
	
	public PhotoIntentDispatcher(MainActivity activity)
	{
		m_activity = activity;
	}
	
	public void takePhoto()
	{
		Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		if(takePictureIntent.resolveActivity(m_activity.getPackageManager()) != null)
		{
			String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
			String filePath = timeStamp + ".jpg";
			File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), filePath);
			m_currentPhotoPath = Uri.fromFile(file);
			takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, m_currentPhotoPath);
			m_activity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
		}
	}
	
	public void selectPhotoFromGallery()
	{
		Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
		m_activity.startActivityForResult(intent, SELECT_PHOTO_FROM_GALLERY);
	}
	
	public void addActivityIntentResultHandler(IActivityIntentResultHandler handler)
	{
		if(!m_activityCallbacks.contains(handler))
		{
			m_activityCallbacks.add(handler);
		}
	}
	
	public void removeActivityIntentResultHandler(IActivityIntentResultHandler handler)
	{
		if(m_activityCallbacks.contains(handler))
		{
			m_activityCallbacks.remove(handler);
		}
	}
	
	public void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		if(requestCode != REQUEST_IMAGE_CAPTURE && requestCode != SELECT_PHOTO_FROM_GALLERY)
			return;
		<commit_msg>Selecting photo intent now filters to type 'image/*'. Should fix MPLY-5237. Buddy: Salva<commit_after>package com.eegeo.photos;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;

import com.eegeo.helpers.IActivityIntentResultHandler;
import com.eegeo.mobileexampleapp.MainActivity;

// This class handles the dispatching of intents related to fetching an image via photo or gallery selection.
public class PhotoIntentDispatcher 
{
	public static final int REQUEST_IMAGE_CAPTURE = 1;
	public static final int SELECT_PHOTO_FROM_GALLERY = 2;
	
	private MainActivity m_activity = null;
	private List<IActivityIntentResultHandler> m_activityCallbacks = new ArrayList<IActivityIntentResultHandler>();
	private Uri m_currentPhotoPath;
	
	public PhotoIntentDispatcher(MainActivity activity)
	{
		m_activity = activity;
	}
	
	public void takePhoto()
	{
		Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		if(takePictureIntent.resolveActivity(m_activity.getPackageManager()) != null)
		{
			String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
			String filePath = timeStamp + ".jpg";
			File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), filePath);
			m_currentPhotoPath = Uri.fromFile(file);
			takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, m_currentPhotoPath);
			m_activity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
		}
	}
	
	public void selectPhotoFromGallery()
	{
		Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
		intent.setType("image/*");
		m_activity.startActivityForResult(intent, SELECT_PHOTO_FROM_GALLERY);
	}
	
	public void addActivityIntentResultHandler(IActivityIntentResultHandler handler)
	{
		if(!m_activityCallbacks.contains(handler))
		{
			m_activityCallbacks.add(handler);
		}
	}
	
	public void removeActivityIntentResultHandler(IActivityIntentResultHandler handler)
	{
		if(m_activityCallbacks.contains(handler))
		{
			m_activityCallbacks.remove(handler);
		}
	}
	
	public void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		if(requestCode != REQUEST_IMAGE_CAPTURE && requestCode != SELECT_PHOTO_FROM_GALLERY)
			return;
		
{'fraction_non_alphanumeric': 0.08530612244897959, 'fraction_numerical': 0.0016326530612244899, 'mean_word_length': 6.25, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6885150', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1468, 'n_words': 293}