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 NoticiaCreadaAfegirVideo extends Activity implements OnClickListener{
	private static final int SELECT_VIDEO = 3;
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        Intent mediaChooser = new Intent(Intent.ACTION_PICK);
	      //comma-separated MIME types
	      //mediaChooser.setType("video/*, images/*"); AIXO FUNCONA
          mediaChooser.setType("video/*");
	      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();

	        	Log.d("aki","SELECT_VIDEO Path : ");
	            String[] filePath = { MediaStore.Video.Media.DATA};
	            Log.d("aki","SELECT_VIDEO Path : " );
	            Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
	            cursor.moveToFirst();
	            
	            String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));

	        	Log.d("aki","despres imagePath");

	            // ----------AIXO FUNCIONA----- (linia d sota)
	            //image.setImageBitmap(BitmapFactory.decodeFile(imagePath));
	            
	            //image.setImageBitmap(imatge.imatge);
	             
	            // AIXO ESTAVA
	        	//Foto.stringPathFoto=imagePath;
	        	//-----------
	        	NoticiaCreadaGAVideos.mThumbIds.add(imagePath);
	        	NoticiaCreada.videos.add(imagePath);
	        	Log.d("aki","longitud adapter "+NoticiaCreadaGAVideos.mThumbIds.size());
	        	EscriureNoticiaMedia.adapterVideos.notifyDataSetChanged();
	            cursor.close();
	            finish();
	            
	        }      
	    }
	}
	
	
	
	@Override
    public void onClick(View v) {
		
        /*
		Intent intent = new Intent();
		intent.setType("video/*");
		intent.setAction(Intent.ACTION_GET_CONTENT);
		startActivityForResult(Intent.createChooser(intent,"Select a Video "), SELECT_VIDEO);*/
    }
	
	

	
}