Skip to content

Commit

Permalink
Version 1.3 : format numbers & layout fix
Browse files Browse the repository at this point in the history
  • Loading branch information
corenting committed Feb 6, 2015
1 parent f43b939 commit 3074780
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "fr.corenting.convertisseureurofranc"
minSdkVersion 9
targetSdkVersion 21
versionCode 3
versionName "1.2"
versionCode 4
versionName "1.3"
}

signingConfigs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void onClick(View 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).toPlainString()));
resultEditText.setText(Utils.formatNumber(activity, convertCalc.convertFunction(yearOfOrigin, yearOfResult, amount)));
} catch (Exception e) {
Toast errorToast = Toast.makeText(activity.getApplicationContext(), activity.getString(R.string.errorToast), Toast.LENGTH_SHORT);
errorToast.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,23 @@ public class ConvertCalc {

}

public BigDecimal convertFunction(int yearOfOrigin, int yearOfResult, float amount) {
if(yearOfOrigin == yearOfResult) return BigDecimal.valueOf(amount);
public double convertFunction(int yearOfOrigin, int yearOfResult, float amount) {
if (yearOfOrigin == yearOfResult) return amount;
double multiplier = values.get(yearOfResult) / values.get(yearOfOrigin);
//Convert values to €
if (yearOfResult < 1960)
{
if (yearOfResult < 1960) {
amount *= 100;
}
if (yearOfOrigin < 1960)
{
if (yearOfOrigin < 1960) {
amount /= 100;
}
if(yearOfResult < 2002)
{
if (yearOfResult < 2002) {
amount *= 6.55957;
}
if(yearOfOrigin < 2002)
{
if (yearOfOrigin < 2002) {
amount *= 0.15244;
}

double result = amount * multiplier;
return BigDecimal.valueOf(result);
return amount * multiplier;
}
}
12 changes: 10 additions & 2 deletions app/src/main/java/fr/corenting/convertisseureurofranc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Utils {

static String getCurrencyFromYear(int year) {
if(year >= 2002) return "€";
if(year >= 1960) return "F";
if (year >= 2002) return "€";
if (year >= 1960) return "F";
return "AF";
}

Expand All @@ -37,4 +40,9 @@ public void onClick(DialogInterface dialog, int which) {
.findViewById(android.R.id.message))
.setMovementMethod(LinkMovementMethod.getInstance());
}

static String formatNumber(Context c, double number) {
DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(c.getResources().getConfiguration().locale);
return formatter.format(number);
}
}
20 changes: 9 additions & 11 deletions app/src/main/res/layout/activity_converter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,19 @@
android:layout_below="@+id/sumToConvertTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/resultEditText"
android:layout_alignEnd="@+id/resultEditText" />
android:layout_alignRight="@+id/yearOfOriginSpinner"
android:layout_alignEnd="@+id/yearOfOriginSpinner" />

<TextView
android:layout_width="wrap_content"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/AF"
android:id="@+id/currencyOriginTextView"
android:layout_alignBaseline="@+id/amountEditText"
android:layout_toStartOf="@+id/yearOfOriginSpinner"
android:layout_toEndOf="@+id/amountEditText"
android:layout_above="@+id/yearOfOriginSpinner"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/amountEditText" />
android:layout_alignParentEnd="true" />

<TextView
android:layout_width="wrap_content"
Expand All @@ -68,8 +65,8 @@
android:id="@+id/yearOfOriginSpinner"
android:layout_below="@+id/amountEditText"
android:layout_toRightOf="@+id/yearOfOriginTextView"
android:layout_alignRight="@+id/currencyResultTextView"
android:layout_alignEnd="@+id/currencyResultTextView" />
android:layout_toLeftOf="@+id/currencyOriginTextView"
android:layout_toStartOf="@+id/currencyOriginTextView" />

<TextView
android:layout_width="wrap_content"
Expand Down Expand Up @@ -121,10 +118,11 @@
android:layout_below="@+id/resultTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/currencyResultTextView" />
android:layout_alignRight="@+id/yearOfResultSpinner"
android:layout_alignEnd="@+id/yearOfResultSpinner" />

<TextView
android:layout_width="wrap_content"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/AF"
Expand Down

0 comments on commit 3074780

Please sign in to comment.