package com.example.TreballFiGrau;

import java.util.concurrent.TimeUnit;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

public class CanviarFotoPerfil extends Activity implements OnClickListener{
	private static final int SELECT_VIDEO = 3;
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("aki","comensa");
        Intent mediaChooser = new Intent(Intent.ACTION_PICK);
        mediaChooser.setType("image/*");
	    startActivityForResult(mediaChooser, SELECT_VIDEO);  
    }
	
	@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
		Log.d("aki","despres thread");
	    if (resultCode == RESULT_OK) {
	        if (requestCode == SELECT_VIDEO) {
	        	
	        	Uri pickedImage = data.getData();
	            String[] filePath = { MediaStore.Images.Media.DATA};
	            Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
	            cursor.moveToFirst();
	            
	            String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));

	            User.fotoPerfil=imagePath;
	           
	            cursor.close();
	            Log.d("aki","acaba");
	            finish();
	            
	        }      
	    }
	}
	
	@Override
    public void onClick(View v) {
		Log.d("aki","on click");
    }
	
	

	
}