Skip to content

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
corenting committed Aug 19, 2014
1 parent a41314c commit 4d7de19
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 179 deletions.
13 changes: 12 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ android {
versionCode 1
versionName "1.0"
}

signingConfigs {
release {
storeFile file("")
storePassword ""
keyAlias ""
keyPassword ""
}
}

buildTypes {
release {
runProguard false
signingConfig signingConfigs.release
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package fr.corenting.convertisseureurofranc;

import android.app.Activity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class ButtonsStuff {

static void ButtonsInit(Activity activity) {
//Convert when the button is clicked
final Button convertButton = (Button) activity.findViewById(R.id.convertButton);
convertButton.setImeActionLabel(activity.getString(R.string.convertButton), KeyEvent.KEYCODE_ENTER);
final EditText resultEditText = (EditText) activity.findViewById(R.id.resultEditText);
resultEditText.setKeyListener(null); //Make the EditText widget read only
}

public static void amountEditTextOnKeyInit(final Activity activity) {
final EditText amountEditText = (EditText) activity.findViewById(R.id.amountEditText);
amountEditText.setOnKeyListener(new View.OnKeyListener() {

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
activity.findViewById(R.id.convertButton).performClick();
return false;
}

return false;
}
});
}

public static void convertButtonOnClick(final Activity activity, final ConvertCalc convertCalc) {
final Spinner originSpinner = (Spinner) activity.findViewById(R.id.yearOfOriginSpinner);
final Spinner resultSpinner = (Spinner) activity.findViewById(R.id.yearOfResultSpinner);
final TextView amountEditText = (TextView) activity.findViewById(R.id.amountEditText);
final TextView resultEditText = (TextView) activity.findViewById(R.id.resultEditText);
Button convertButton = (Button) activity.findViewById(R.id.convertButton);

convertButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
Utils.hideSoftKeyboard(v);
int yearOfOrigin = Integer.parseInt(originSpinner.getSelectedItem().toString());
int yearOfResult = Integer.parseInt(resultSpinner.getSelectedItem().toString());
float amount = Float.parseFloat(amountEditText.getText().toString());
resultEditText.setText(String.valueOf(convertCalc.convertFunction(yearOfOrigin, yearOfResult, amount)));
} catch (Exception e) {
Toast errorToast = Toast.makeText(activity.getApplicationContext(), activity.getString(R.string.errorToast), Toast.LENGTH_SHORT);
errorToast.show();
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package fr.corenting.convertisseureurofranc;

import android.content.Context;
import android.util.Log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedHashMap;

public class ConvertCalc {

HashMap<Integer, Float> values = new LinkedHashMap<Integer, Float>(115);

ConvertCalc(Context context) {
//Load the values from the csv file
InputStream inputStream = context.getResources().openRawResource(R.raw.converter_values);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
try {
while ((line = reader.readLine()) != null) {
String[] separatedLine = line.split(";");
values.put(Integer.parseInt(separatedLine[0]), Float.parseFloat(separatedLine[1]));
}
reader.close();
} catch (IOException e) {
Log.d("ConvertCalc", e.getMessage());
e.printStackTrace();
}

}

public float convertFunction(int yearOfOrigin, int yearOfResult, float amount) {
float amountInEuroToday = amount * values.get(yearOfOrigin);
return amountInEuroToday / values.get(yearOfResult);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
package fr.corenting.convertisseureurofranc;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.util.LinkedList;
import java.util.List;


public class Converter extends ActionBarActivity {

Expand All @@ -27,47 +12,18 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_converter);

final Spinner originSpinner = (Spinner) findViewById(R.id.yearOfOriginSpinner);
final Spinner resultSpinner = (Spinner) findViewById(R.id.yearOfResultSpinner);
//Initialize the spinners with the Init class
SpinnersStuff.Init(this);

//Populate the spinners with a list of years
List<Integer> yearsList = new LinkedList<Integer>();
for (int i = 2013; i >= 1901; i--) {
yearsList.add(i);
}
ArrayAdapter<Integer> spinnerArray = new ArrayAdapter<Integer>(this, android.R.layout.simple_spinner_item, yearsList);
spinnerArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
originSpinner.setAdapter(spinnerArray);
resultSpinner.setAdapter(spinnerArray);

//Add an onItemSelected listener to change the currency text according to the year
Utils.setSpinnerListener(this, originSpinner, (TextView) findViewById(R.id.currencyOriginTextView));
Utils.setSpinnerListener(this, resultSpinner,(TextView) findViewById(R.id.currencyResultTextView));
//Initialize the ConvertCalc class
final ConvertCalc convertCalc = new ConvertCalc(getApplicationContext());

//Convert when the button is clicked
Button convertButton = (Button) findViewById(R.id.convertButton);
final EditText resultEditText = (EditText) findViewById(R.id.resultEditText);
resultEditText.setKeyListener(null); //Make the EditText widget read only
final EditText amountEditText = (EditText) findViewById(R.id.amountEditText);
convertButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
int yearOfOrigin = Integer.parseInt(originSpinner.getSelectedItem().toString());
int yearOfResult = Integer.parseInt(resultSpinner.getSelectedItem().toString());
float amount = Float.parseFloat(amountEditText.getText().toString());
resultEditText.setText(String.valueOf(Utils.convertFunction(yearOfOrigin, yearOfResult, amount)));
}
catch (Exception e)
{
Toast errorToast = Toast.makeText(getApplicationContext(),getString(R.string.errorToast), Toast.LENGTH_SHORT);
errorToast.show();
}
}
});

ButtonsStuff.ButtonsInit(this);
ButtonsStuff.amountEditTextOnKeyInit(this);
ButtonsStuff.convertButtonOnClick(this, convertCalc);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Expand All @@ -81,18 +37,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
if (item.getItemId() == R.id.action_about) {
((TextView) new AlertDialog.Builder(this)
.setTitle(R.string.appName)
.setIcon(R.drawable.ic_launcher)
.setMessage(Html.fromHtml(getString(R.string.about_text) + BuildConfig.VERSION_NAME))
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show()
.findViewById(android.R.id.message))
.setMovementMethod(LinkMovementMethod.getInstance());
Utils.showCredits(this);
}
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package fr.corenting.convertisseureurofranc;

import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.LinkedList;
import java.util.List;

public class SpinnersStuff {

static void Init(Activity activity) {
Spinner originSpinner = (Spinner) activity.findViewById(R.id.yearOfOriginSpinner);
Spinner resultSpinner = (Spinner) activity.findViewById(R.id.yearOfResultSpinner);
TextView currencyOriginTextView = (TextView) activity.findViewById(R.id.currencyOriginTextView);
TextView currencyResultTextView = (TextView) activity.findViewById(R.id.currencyResultTextView);

//Initialize the spinners
fillSpinnerWithYears(activity, originSpinner, 2013);
fillSpinnerWithYears(activity, resultSpinner, 2013);

//Add an onItemSelected listener to change the currency text according to the year
setListeners(originSpinner, currencyOriginTextView);
setListeners(resultSpinner, currencyResultTextView);
}

static void setListeners(Spinner spinner, final TextView textView) {
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
int year = Integer.parseInt(parent.getItemAtPosition(pos).toString());
textView.setText(Utils.getCurrencyFromYear(year));
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}

static void fillSpinnerWithYears(Activity activity, Spinner spinner, int maxYear) {
//Populate the spinners with a list of years
List<Integer> yearsList = new LinkedList<Integer>();
for (int i = maxYear; i >= 1901; i--) {
yearsList.add(i);
}
ArrayAdapter<Integer> spinnerArray = new ArrayAdapter<Integer>(activity, android.R.layout.simple_spinner_item, yearsList);
spinnerArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerArray);
}
}
Loading

0 comments on commit 4d7de19

Please sign in to comment.