package ssrmarcsautelet.automation.appli.ssrmarcsautelet;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity
{
    //public static final int DIALOG_DOWNLOAD_PROGRESS = 1;
    private Button startBtn;
    /*private ProgressDialog progressDialog;
    final String url = "http://192.168.43.197/documents/";

    public static File CreateFile()
    {
        File path = new File(Environment.getExternalStorageDirectory(),"/SSR_docs/");
        path.mkdirs();
        return path;
    }

    String[] dir = {
            "contact_map.html",
            "fiche_amb1.html",
            "fiche_amb2.html",
            "fiche_amb3.html",
            "fiche_ane1.html",
            "fiche_ane2.html",
            "fiche_ane3.html",
            "fiche_assist1.html",
            "fiche_assist2.html",
            "fiche_assist3.html",
            "fiche_educ1.html",
            "fiche_educ2.html",
            "fiche_educ3.html",
            "fiche_ergo1.html",
            "fiche_ergo2.html",
            "fiche_ergo3.html",
            "fiche_inf1.html",
            "fiche_inf2.html",
            "fiche_inf3.html",
            "fiche_kine1.html",
            "fiche_kine2.html",
            "fiche_kine3.html",
            "fiche_medecin1.html",
            "fiche_medecin2.html",
            "fiche_medecin3.html",
            "fiche_ortho1.html",
            "fiche_ortho2.html",
            "fiche_ortho3.html",
            "fiche_orthoptiste1.html",
            "fiche_orthoptiste2.html",
            "fiche_orthoptiste3.html",
            "fiche_psycho1.html",
            "fiche_psycho2.html",
            "fiche_psycho3.html",
            "fiche_secret1.html",
            "fiche_secret2.html",
            "fiche_secret3.html",
            "google_map.html",
            "orga_accueil.html",
            "orga_apa.html",
            "orga_appareilleur.html" ,
            "orga_assist.html",
            "orga_cadre.html",
            "orga_doc.html",
            "orga_ergo.html",
            "orga_grands.html",
            "orga_inf.html",
            "orga_kine.html",
            "orga_moyens.html",
            "orga_ortho.html",
            "orga_orthoptiste.html",
            "orga_petits.html",
            "orga_psy.html",
            "orga_psychomo.html" ,
            "orga_secret.html" ,
            "orga_standard.html",
            "Ambulancier.jpg",
            "Kine.jpg",
            "ane.jpg",
            "assistante.jpg",
            "educateur.jpg",
            "ergo.jpg",
            "inf.jpg",
            "medecin.jpg",
            "ortho.jpg",
            "orthoptiste.jpg",
            "psychologue.jpg",
            "secretaire.jpg",
            "accueil1.png",
            "accueil2.png",
            "accueil3.png",
            "accueil4.png",
            "apa1.png",
            "appareillage1.png",
            "assist1.png",
            "dame1.png",
            "dame2.png",
            "doc1.png",
            "doc2.png",
            "ecole1.png",
            "ecole2.png",
            "ergo1.png",
            "ergo2.png",
            "ergo3.png",
            "ergo4.png",
            "ergo5.png",
            "grands1.png",
            "grands2.png",
            "grands3.png",
            "inf1.png",
            "inf2.png",
            "inf3.png",
            "kine1.png",
            "kine10.png",
            "kine11.png",
            "kine12.png",
            "kine2.png",
            "kine3.png",
            "kine4.png",
            "kine5.png",
            "kine6.png",
            "kine7.png",
            "kine8.png",
            "kine9.png",
            "moyens1.png",
            "moyens2.png",
            "moyens3.png",
            "moyens4.png",
            "moyens5.png",
            "ortho1.png",
            "ortho2.png",
            "ortho3.png",
            "orthopto1.png",
            "pediatre1.png",
            "petits1.png",
            "petits2.png",
            "petits3.png",
            "petits4.png",
            "psy1.png",
            "psy2.png",
            "psy3.png",
            "psychomo1.png",
            "secret1.png",
            "secret2.png"};*/

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

        //startBtn = (Button) findViewById(R.id.telechargement);
        //startBtn.setOnClickListener(new View.OnClickListener() {

           // @Override
            //public void onClick(View v) {
                // TODO Auto-generated method stub
              //  Intent activity_val = new Intent(MainActivity.this, activity_val.class);
                //startActivity(activity_val);
                /*CreateFile();
                new DownloadFileAsync().execute(
                        url+dir[0] ,url+dir[1], url+dir[2], url+dir[3], url+dir[4], url+dir[5],
                        url+dir[6], url+dir[7], url+dir[8], url+dir[9], url+dir[10], url+dir[11],
                        url+dir[12], url+dir[13], url+dir[14], url+dir[15],url+dir[16], url+dir[17],
                        url+dir[18], url+dir[19], url+dir[20], url+dir[21], url+dir[22],
                        url+dir[23], url+dir[24], url+dir[25], url+dir[26], url+dir[27], url+dir[28], url+dir[29],
                        url+dir[30], url+dir[31], url+dir[32], url+dir[33], url+dir[34], url+dir[35], url+dir[36],
                        url+dir[37], url+dir[38], url+dir[39], url+dir[40], url+dir[41], url+dir[42], url+dir[43],
                        url+dir[44], url+dir[45], url+dir[46], url+dir[47], url+dir[48], url+dir[49], url+dir[50],
                        url+dir[51], url+dir[52], url+dir[53], url+dir[54],url+dir[55] ,url+dir[56], url+dir[57], url+dir[58],
                        url+dir[59], url+dir[60], url+dir[61], url+dir[62], url+dir[63], url+dir[64],
                        url+dir[65], url+dir[66], url+dir[67], url+dir[68], url+dir[69], url+dir[70],
                        url+dir[71], url+dir[72], url+dir[73], url+dir[74], url+dir[75], url+dir[76],
                        url+dir[77], url+dir[78], url+dir[79], url+dir[80], url+dir[81], url+dir[82], url+dir[83],
                        url+dir[84], url+dir[85], url+dir[86], url+dir[87], url+dir[88], url+dir[89], url+dir[90],
                        url+dir[91], url+dir[92], url+dir[93], url+dir[94], url+dir[95], url+dir[96], url+dir[97],
                        url+dir[98], url+dir[99], url+dir[100], url+dir[101], url+dir[102], url+dir[103], url+dir[104],
                        url+dir[105], url+dir[106], url+dir[107], url+dir[108],url + dir[109] ,url+dir[110], url+dir[111], url+dir[112],
                        url+dir[113], url+dir[114], url+dir[115], url+dir[116], url+dir[117], url+dir[118],
                        url+dir[119], url+dir[120], url+dir[121], url+dir[122]);//OK*/


           // }
        //});
    }
    /*
    @Override
    @Deprecated
    protected Dialog onCreateDialog(int id) {
        // TODO Auto-generated method stub
        switch (id) {
            case DIALOG_DOWNLOAD_PROGRESS:
                progressDialog = new ProgressDialog(this);
                progressDialog.setMessage("Téléchargement des fichiers");
                progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                progressDialog.setCancelable(false);
                progressDialog.show();
                return progressDialog;
            default:
                return null;
        }
    }

    class DownloadFileAsync extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            int count;
            for (int i = 0; i < dir.length; i++) {
                try {

                    URL url = new URL(params[i]);
                    URLConnection connexion = url.openConnection();
                    connexion.connect();

                    int lengthofFile = connexion.getContentLength();
                    Log.d("ANDRO_ASYNC", "Length of file: " + lengthofFile);

                    InputStream input = new BufferedInputStream(url.openStream());
                    OutputStream output = new FileOutputStream("/sdcard/SSR_docs/" + dir[i]);

                    byte data[] = new byte[1024];

                    long total = 0;

                    while ((count = input.read(data)) != -1) {
                        total += count;
                        publishProgress("" + (int) ((total * 100) / lengthofFile));
                        output.write(data, 0, count);
                    }

                    output.flush();
                    output.close();
                    input.close();
                } catch (Exception e) {
                    Log.i("FAIL", "Problème de téléchargement");
                    // TODO: handle exception
                }

            }return null;
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
        }

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            showDialog(DIALOG_DOWNLOAD_PROGRESS);
        }

        @Override
        protected void onProgressUpdate(String... values) {
            // TODO Auto-generated method stub
            Log.d("ANDRO_ASYNC", values[0]);
            progressDialog.setProgress(Integer.parseInt(values[0]));
        }

    }*/

    public void send_savoirplus(View v)
    {
        Intent intent = new Intent(MainActivity.this, savoirplus.class);
        startActivity(intent);
    }

    public void send_age1(View v)
    {
        Intent intent1 = new Intent(MainActivity.this, activity_age1.class);
        startActivity(intent1);
    }

    public void send_age2(View v)
    {
        Intent intent2 = new Intent(MainActivity.this, activity_age2.class);
        startActivity(intent2);
    }

    public void send_age3(View v)
    {
        Intent intent3 = new Intent(MainActivity.this, activity_age3.class);
        startActivity(intent3);
    }


    public void send_hop(View v)
    {
        Intent intent4 = new Intent(MainActivity.this, plan_hospital.class);
        startActivity(intent4);
    }

    public void demande_mdp(View v)
    {
        Intent intent5 = new Intent(MainActivity.this, activity_val.class);
        startActivity(intent5);
    }
}