|
@@ -0,0 +1,310 @@
|
|
|
|
|
+package com.siningsoft.e85mixcalc;
|
|
|
|
|
+
|
|
|
|
|
+import android.app.Activity;
|
|
|
|
|
+import android.graphics.Color;
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.util.Log;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.View.OnClickListener;
|
|
|
|
|
+import android.widget.Button;
|
|
|
|
|
+import android.widget.EditText;
|
|
|
|
|
+import android.widget.RadioButton;
|
|
|
|
|
+import android.widget.Toast;
|
|
|
|
|
+
|
|
|
|
|
+public class main extends Activity {
|
|
|
|
|
+ /** Called when the activity is first created. */
|
|
|
|
|
+
|
|
|
|
|
+ //noch schnell ein paar Variablen definieren
|
|
|
|
|
+ double ethanolInhaltS = 0.10;
|
|
|
|
|
+ String ethanolInhaltST = "E10";
|
|
|
|
|
+ int mode = 0;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
+
|
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
+
|
|
|
|
|
+ setContentView(R.layout.main);
|
|
|
|
|
+
|
|
|
|
|
+ Button calcbutton = (Button) findViewById(R.id.calcbutton);
|
|
|
|
|
+ calcbutton.setOnClickListener(calcbuttonlistener);
|
|
|
|
|
+
|
|
|
|
|
+ //vorwaertskalkulation
|
|
|
|
|
+ RadioButton rbfor = (RadioButton)findViewById(R.id.rbfor);
|
|
|
|
|
+ rbfor.setOnClickListener(rbforL);
|
|
|
|
|
+
|
|
|
|
|
+ //rueckwaertskalkulation
|
|
|
|
|
+ RadioButton rbbac = (RadioButton)findViewById(R.id.rbbac);
|
|
|
|
|
+ rbbac.setOnClickListener(rbbacL);
|
|
|
|
|
+
|
|
|
|
|
+ //5 Prozent Ethanol im Super
|
|
|
|
|
+ RadioButton rbe5 = (RadioButton)findViewById(R.id.rbe5);
|
|
|
|
|
+ rbe5.setOnClickListener(rbe5L);
|
|
|
|
|
+
|
|
|
|
|
+ //10 Prozent Ethanol im Super
|
|
|
|
|
+ RadioButton rbe10 = (RadioButton)findViewById(R.id.rbe10);
|
|
|
|
|
+ rbe10.setOnClickListener(rbe10L);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public OnClickListener rbforL = new OnClickListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ //Vorwärtskalkulation deaktiviert die Rückwärtsfelder und verwendet sie als Ausgabefelder
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_affair)).setEnabled(false);
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_affair)).setTextColor(getResources().getColorStateList(R.color.green));
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_affair)).setText("");
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_full)).setEnabled(false);
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_full)).setTextColor(getResources().getColorStateList(R.color.green));
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_full)).setText("");
|
|
|
|
|
+
|
|
|
|
|
+ //Vorwärtskalkulation aktiviert alle vorwärtsfelder
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_bio)).setEnabled(true);
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_bio)).setTextColor(Color.parseColor("#000000"));
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_bio)).setText("");
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_super)).setEnabled(true);
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_super)).setTextColor(Color.parseColor("#000000"));
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_super)).setText("");
|
|
|
|
|
+
|
|
|
|
|
+ //a = vorwärts
|
|
|
|
|
+ mode = 0;
|
|
|
|
|
+
|
|
|
|
|
+ Log.i("Berechnungsmodus", "Vorwärts");
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ public OnClickListener rbbacL = new OnClickListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ //Rückwärtskalkulation deaktiviert alle vorwärtsfelder
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_bio)).setEnabled(false);
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_bio)).setTextColor(getResources().getColorStateList(R.color.green));
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_bio)).setText("");
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_super)).setEnabled(false);
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_super)).setTextColor(getResources().getColorStateList(R.color.green));
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_super)).setText("");
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_affair)).setEnabled(true);
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_affair)).setTextColor(Color.parseColor("#000000"));
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_affair)).setText("");
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_full)).setEnabled(true);
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_full)).setTextColor(Color.parseColor("#000000"));
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_full)).setText("");
|
|
|
|
|
+
|
|
|
|
|
+ //b = rückwärts
|
|
|
|
|
+ mode = 1;
|
|
|
|
|
+
|
|
|
|
|
+ Log.i("Berechnungsmodus", "Rückwärts");
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ public OnClickListener rbe5L = new OnClickListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ // Wenn dieser Butten geclickt wird, verwenden wir 5 Prozent Ethanol
|
|
|
|
|
+ ethanolInhaltS = 0.05;
|
|
|
|
|
+ ethanolInhaltST = "E5";
|
|
|
|
|
+
|
|
|
|
|
+ Log.i("Supersorte", ethanolInhaltST);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ public OnClickListener rbe10L = new OnClickListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ // Wenn dieser Butten geclickt wird, verwenden wir 10 Prozent Ethanol
|
|
|
|
|
+ ethanolInhaltS = 0.10;
|
|
|
|
|
+ ethanolInhaltST = "E10";
|
|
|
|
|
+
|
|
|
|
|
+ Log.i("Supersorte", ethanolInhaltST);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public OnClickListener calcbuttonlistener = new OnClickListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ /*der Code fuer den gedrueckten button
|
|
|
|
|
+ * wir weisen die Inhalte der Edit-Texts Variablen zu
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ //wir nullen die Berechnungswerte
|
|
|
|
|
+ Double v_super = 0.0;
|
|
|
|
|
+ Double v_bio = 0.0;
|
|
|
|
|
+ Double v_affair = 0.0;
|
|
|
|
|
+ Double v_full = 0.0;
|
|
|
|
|
+ Double a_ethanol = 0.0;
|
|
|
|
|
+ Double a_super = 0.0;
|
|
|
|
|
+ Double r_ethanol = 0.0;
|
|
|
|
|
+ int sammelcnt = 0;
|
|
|
|
|
+
|
|
|
|
|
+ switch (mode)
|
|
|
|
|
+ {
|
|
|
|
|
+ //diese switch klausel prueft, ob die Werte fuer die berechnung eingegeben wurden.
|
|
|
|
|
+ case 0:
|
|
|
|
|
+
|
|
|
|
|
+ //abfrage, ob eingabewert leer oder keine Zahl
|
|
|
|
|
+ if (String.valueOf(((EditText) findViewById(R.id.for_enter_super)).getText()).length() > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ v_super = Double.parseDouble(String.valueOf(((EditText) findViewById(R.id.for_enter_super)).getText()));
|
|
|
|
|
+ sammelcnt ++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (String.valueOf(((EditText) findViewById(R.id.for_enter_bio)).getText()).length() > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ v_bio = Double.parseDouble(String.valueOf(((EditText) findViewById(R.id.for_enter_bio)).getText()));
|
|
|
|
|
+ sammelcnt ++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case 1:
|
|
|
|
|
+
|
|
|
|
|
+ //abfrage, ob eingabewert leer oder keine Zahl
|
|
|
|
|
+ if (String.valueOf(((EditText) findViewById(R.id.bac_enter_affair)).getText()).length() > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ v_affair = Double.parseDouble(String.valueOf(((EditText) findViewById(R.id.bac_enter_affair)).getText()));
|
|
|
|
|
+ sammelcnt ++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (String.valueOf(((EditText) findViewById(R.id.bac_enter_full)).getText()).length() > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ v_full = Double.parseDouble(String.valueOf(((EditText) findViewById(R.id.bac_enter_full)).getText()));
|
|
|
|
|
+ sammelcnt ++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /*1. es muss immer ein feld leer sein und das wird dann berechnet
|
|
|
|
|
+ * also wird als erstes geprueft, ob alle felder belegt sind, wenn nicht, dann geht es weiter
|
|
|
|
|
+ * sonst gibt es einen Toast
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ Log.d("calc", v_super.toString());
|
|
|
|
|
+ Log.d("calc", v_bio.toString());
|
|
|
|
|
+ Log.d("calc", v_affair.toString());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ switch (sammelcnt)
|
|
|
|
|
+ {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ //keine Werte
|
|
|
|
|
+ Toast.makeText(v.getContext(), R.string.allenterless , Toast.LENGTH_SHORT).show();
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ //zu wenig werte
|
|
|
|
|
+ Toast.makeText(v.getContext(), R.string.allenterless , Toast.LENGTH_SHORT).show();
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ //genau richtig ab hier wird gerechnet
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ switch (mode)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ case 0:
|
|
|
|
|
+
|
|
|
|
|
+ // errechnen gesamtmenge an Ethanol
|
|
|
|
|
+ a_ethanol = (v_super * ethanolInhaltS) + (v_bio * 0.85);
|
|
|
|
|
+ Log.i("absolut ethanol in Liter", a_ethanol.toString());
|
|
|
|
|
+
|
|
|
|
|
+ a_super = (v_super * (1-ethanolInhaltS)) + (v_bio * 0.15);
|
|
|
|
|
+ Log.i("absolut super in Liter", a_super.toString());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //Berechnung Gemischverhaeltnis anhand Spritmengen
|
|
|
|
|
+ if ( v_super > 0.0 && v_bio > 0.0)
|
|
|
|
|
+ {
|
|
|
|
|
+ //relativer Alkoholanteil
|
|
|
|
|
+ r_ethanol = (a_ethanol * 100) / (v_super + v_bio);
|
|
|
|
|
+ v_full = v_super + v_bio;
|
|
|
|
|
+
|
|
|
|
|
+ Log.i("relativ ethanol in Prozent", r_ethanol.toString());
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_affair)).setText("E" + String.valueOf(Math.round(r_ethanol)));
|
|
|
|
|
+ ((EditText)findViewById(R.id.bac_enter_full)).setText(v_full.toString() + " l");
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case 1:
|
|
|
|
|
+
|
|
|
|
|
+ Boolean calcdone = false;
|
|
|
|
|
+ Double calc_a_super = v_full;
|
|
|
|
|
+ Double calc_a_bio = 0.0;
|
|
|
|
|
+
|
|
|
|
|
+ //rueckwärtsrechnung gemischverhältnis und gesamtmenge
|
|
|
|
|
+ while ( calcdone == false )
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ // errechnen gesamtmenge an Ethanol
|
|
|
|
|
+ a_ethanol = (calc_a_super * ethanolInhaltS) + (calc_a_bio * 0.85);
|
|
|
|
|
+ //Log.i("absolut ethanol in Liter", a_ethanol.toString());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //relativer Alkoholanteil
|
|
|
|
|
+ r_ethanol = (a_ethanol * 100) / v_full;
|
|
|
|
|
+ //Log.i("relativ ethanol in prozent", r_ethanol.toString());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (Math.round(r_ethanol) != Math.round(v_affair) && r_ethanol < 100.0) //errechneter Anteil ist ungleich dem gewünschten
|
|
|
|
|
+ {
|
|
|
|
|
+ calc_a_super = calc_a_super - 0.01; //super - 0.01
|
|
|
|
|
+ calc_a_bio = calc_a_bio + 0.01; //bio + 0.01
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //hier nur ausgabe
|
|
|
|
|
+
|
|
|
|
|
+ Log.i("E5 in Liter",String.valueOf(Math.round(calc_a_super)));
|
|
|
|
|
+ Log.i("E85 in Liter",String.valueOf(Math.round(calc_a_bio)));
|
|
|
|
|
+
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_super)).setText(String.valueOf(Math.round(calc_a_super)) + " l " + ethanolInhaltST);
|
|
|
|
|
+ ((EditText)findViewById(R.id.for_enter_bio)).setText(String.valueOf(Math.round(calc_a_bio)) + " l E85");
|
|
|
|
|
+
|
|
|
|
|
+ calcdone = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|