package com.example.sendfile01;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity
 {
	//http://lakjeewa.blogspot.fr/2012/03/simple-android-application-to-send-file.html
    
	//http://helloraspberrypi.blogspot.fr/2013/12/communication-between-android-raspberry.html
	
	private Socket client;
    private FileInputStream fileInputStream;
    private BufferedInputStream bufferedInputStream;
    private OutputStream outputStream;
    private Button button;
    private TextView text;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = (Button) findViewById(R.id.button1);   //reference to the send button
       

        //Button press event listener
        button.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v) 
            {

                //File file = new File("/mnt/sdcard/filename.txt"); //create file instance
                
                Toast.makeText(getApplicationContext(), 
                        "Button is clicked", Toast.LENGTH_LONG).show();
               // text = (TextView) findViewById(R.id.textView1);
                
/*
                try {

                    client = new Socket("82.234.53.234", 8081);

                    byte[] mybytearray = new byte[(int) file.length()]; //create a byte array to file

                    fileInputStream = new FileInputStream(file);
                    bufferedInputStream = new BufferedInputStream(fileInputStream);

                    bufferedInputStream.read(mybytearray, 0, mybytearray.length); //read the file

                    outputStream = client.getOutputStream();

                    outputStream.write(mybytearray, 0, mybytearray.length); //write file to the output stream byte by byte
                    outputStream.flush();
                    bufferedInputStream.close();
                    outputStream.close();
                    client.close();

                    text.setText("File Sent");


                } 
                
                catch (UnknownHostException e) 
                {
                    e.printStackTrace();
                } 
                
                catch (IOException e) 
                {
                    e.printStackTrace();
                }
                */
            }
        });

    }
}