package com.camera.simplemjpeg;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class login extends Activity {

	//On déclare toutes les variables dont on aura besoin
	
	Button button1;
	Button button2;
	Button button3;
	Button button4;
	Button button5;
	Button button6;
	Button button7;
	Button button8;
	Button button9;
	Button button0;
	Button buttonCorriger;
	Button buttonEffacer;
	Button buttonValider;
	Button buttonQuitter;
	
	EditText ecran;

	private double chiffre1;
	private boolean clicOperateur = false;
	private boolean update = false;
	private String operateur = "";
	private String code = "";
	private String passcode = "301278"; //301278 // 531

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
     
	  super.onCreate(savedInstanceState);
      setContentView(R.layout.login);

      button0 = (Button) findViewById(R.id.button0);
      button1 = (Button) findViewById(R.id.button1);
      button2 = (Button) findViewById(R.id.button2);
      button3 = (Button) findViewById(R.id.button3);
      button4 = (Button) findViewById(R.id.button4);
      button5 = (Button) findViewById(R.id.button5);
      button6 = (Button) findViewById(R.id.button6);
      button7 = (Button) findViewById(R.id.button7);
      button8 = (Button) findViewById(R.id.button8);
      button9 = (Button) findViewById(R.id.button9);
      
      buttonCorriger = (Button) findViewById(R.id.button_corriger);
      buttonEffacer = (Button) findViewById(R.id.button_effacer);
      buttonValider = (Button) findViewById(R.id.button_valider);
      buttonQuitter = (Button) findViewById(R.id.button_quitter);

      ecran = (EditText) findViewById(R.id.EditText01);
      
      resetClick();

      buttonCorriger.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		correctionClick();
      	}
      });

      buttonEffacer.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		resetClick();
      	}
      });

      buttonValider.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		valideClick();
      	}
      });

      
      button0.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		chiffreClick("0");
        	}
        });
      
      button1.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		chiffreClick("1");
      	}
      });

      button2.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		chiffreClick("2");
      	}
      });

      button3.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		chiffreClick("3");
      	}
      });

      button4.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		chiffreClick("4");
      	}
      });

      button5.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		chiffreClick("5");
      	}
      });

      button6.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		chiffreClick("6");
      	}
      });

      button7.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		chiffreClick("7");
      	}
      });

      button8.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		chiffreClick("8");
      	}
      });

      button9.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		chiffreClick("9");
      	}
      });
      
      
      buttonQuitter.setOnClickListener(new View.OnClickListener() {
      	public void onClick(View v) {
      		finish();
      		System.exit(0);
      	}
      });

  }

  //traitement des boutons
  public void chiffreClick(String str)
  {
      if(update)
      {
           update = false;
      }
      else
      {
          if(!ecran.getText().equals("0"))
          	str = ecran.getText() + str;
      }
      ecran.setText(str);
  }

  public void correctionClick()
  {
      int length = ecran.getText().length();
      if (length > 0)
      {
          ecran.getText().delete(length - 1, length);
      }
  }
  
  public void resetClick(){
      ecran.setText("");
 }

  public void valideClick()
  {
  	 String saisie = ecran.getText().toString();
  	 String bla = "301278"; // "531"
  	 
  	 if(saisie.equals(bla))
  	 {   resetClick();
  	  	 Intent intent = new Intent(login.this,pipo.class);
  	  	 startActivity(intent);
  	 }
  	 else
  	 {
  		 resetClick();
  		 Toast.makeText(getApplicationContext(), "Password Incorrect !", Toast.LENGTH_SHORT).show();
  	 }
  }




 

  
}