package fr.iutfbleau.temperatures;

import android.view.KeyEvent;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;


public class ControleurEditTextFahrenheit implements OnEditorActionListener {

    private TextView celsius;

    public ControleurEditTextFahrenheit(TextView celsius) {
        this.celsius = celsius;
    }

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent e) {
        String texte = v.getText().toString();
        try {
            double valeur = (Double.parseDouble(texte) - 32) * 5 / 9;
            this.celsius.setText(valeur + "");
        } catch (NumberFormatException e1) {
            this.celsius.setText("???");
        }

        this.celsius.invalidate();
        return true;
    }
}
