Back to project page WhichFuel.
The source code is released under:
MIT License
If you think the Android project WhichFuel listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package control; /* w w w . ja v a 2s.c om*/ import android.content.Context; import android.content.SharedPreferences; import android.util.Log; import android.widget.Toast; public class Control { private final String TAG = "DevMode"; private boolean put_gas; private boolean put_alcool; private float alcool_price = 0; private float gas_price = 0; private Context context; private boolean isFieldGasEmpty; private boolean isFieldAlcoolEmpty; public enum FUEL { GAS, ALCOOL } private FUEL best; public Control(Context context) { this.context = context; init(); } public FUEL getBest() { return best; } // Init booleans private void init() { isFieldAlcoolEmpty = true; isFieldGasEmpty = true; } private boolean isFieldEmpty(FUEL fuel) { switch (fuel) { case GAS: return isFieldGasEmpty; case ALCOOL: return isFieldAlcoolEmpty; } Log.e(TAG, "ERROR..."); return true; } public void setGasFieldEmpty(boolean empty) { isFieldGasEmpty = empty; } public boolean isGasFieldEmpty() { return isFieldGasEmpty; } public void setAlcoolFieldEmpty(boolean empty) { isFieldAlcoolEmpty = empty; } public boolean isAlcoolFieldEmpty() { return isFieldAlcoolEmpty; } public boolean isAbleToContinue() { return (!isFieldGasEmpty && !isFieldAlcoolEmpty); } public void comparePrices(float gas, float alcool, Toast toast) { best = calculate(gas, alcool); if(best == FUEL.ALCOOL) { Log.i(TAG, "Alcool is best!"); } else { Log.i(TAG, "Gas is best!"); } } public float getPercentage() { Log.i(TAG, ((alcool_price / gas_price) * 100)+"%"); return ((alcool_price / gas_price) * 100); } private FUEL calculate(float gas, float alcool) { alcool_price = alcool; gas_price = gas; return ((alcool / gas) * 100 > 70) ? FUEL.GAS : FUEL.ALCOOL; } }