package fr.iutfbleau.temperatures;

import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;


public class ControleurEditTextCelsius implements OnEditorActionListener {

    private TextView fahrenheit;

    public ControleurEditTextCelsius(TextView fahrenheit) {
        this.fahrenheit = fahrenheit;
    }

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

            this.fahrenheit.invalidate();
            return true;
        }
        return false;

    }
}
