package com.alarm;

//import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

/*public class MainActivity extends Activity {

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

	}
*/

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

public class MainActivity 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 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 = "531";
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        //On récupère tout les éléments de notre interface graphique grâce aux ID
        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);
 
        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();
        	}
        });
 
        
        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);
        	}
        });
 
    }
 
    //voici la méthode qui est exécutée lorsque l'on clique sur un bouton chiffre
    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 = "531";
    	 
    	 if(saisie.equals(bla))
    	 {
    	  	 Intent intent = new Intent(MainActivity.this,  commande.class);
    	  	 startActivity(intent);
    	 }
    	 else
    	 {
    		 resetClick();
    		 Toast.makeText(getApplicationContext(), "Mauvaus code", Toast.LENGTH_LONG).show();
    	 }
    }
 
  
 

   
 
    
}