package com.example.TreballFiGrau;


import com.google.android.gms.maps.GoogleMap;

import android.annotation.TargetApi;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

public class EscriureNoticiaContingut extends Fragment  {
	private String titolNoticia;
	private String contingutNoticia;
	ViewGroup rootView;
	EditText ETtitolNoticia;
	EditText ETcontingutNoticia; 
	private ViewPager mPager;
	private PagerAdapter mPagerAdapter;
	public GoogleMap mapa;
	
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
		Log.d("aki", "contingut");	
		rootView = (ViewGroup) inflater.inflate(R.layout.escriure_noticia_contingut, container, false);

		//Button sendButton = (Button) rootView.findViewById(R.id.titolNoticia);
		Log.d("aki", "contingut");	
    	ETtitolNoticia = (EditText) rootView.findViewById(R.id.titolNoticia);
    	ETtitolNoticia.setMaxWidth(ETtitolNoticia.getWidth());
    	
    	ETcontingutNoticia = (EditText) rootView.findViewById(R.id.contingutNoticia);
    	ETcontingutNoticia.setMaxWidth(ETcontingutNoticia.getWidth());
    	
    	
    	afegirListenerPublicar();
    	
    	//LocationManager mgr = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
    	//mgr.getLastKnownLocation(provider);
    	
 		 
    	return rootView;
   

    }
    public void afegirListenerPublicar(){
    	Log.d("aki", "afegir listener");
    	Button button = (Button) rootView.findViewById(R.id.publicar);
    	Log.d("aki", "afegir listener2");
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	NoticiaCreada.titol=ETtitolNoticia.getText().toString();
            	NoticiaCreada.contingut=ETcontingutNoticia.getText().toString();
        		
        
        
            	
            	
            	Runnable r = new AfegirNoticiaWeb(titolNoticia,contingutNoticia);
            	new Thread(r).start();
            	getActivity().finish();
            	
            	
            }
        });
    }
    
	
	
}