Skip to content

Commit

Permalink
Tweaks du layout
Browse files Browse the repository at this point in the history
  • Loading branch information
corenting committed Aug 13, 2014
1 parent 183f163 commit a41314c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -46,14 +47,21 @@ protected void onCreate(Bundle savedInstanceState) {
//Convert when the button is clicked
Button convertButton = (Button) findViewById(R.id.convertButton);
final EditText resultEditText = (EditText) findViewById(R.id.resultEditText);
resultEditText.setKeyListener(null);
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) {
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)));
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();
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ static float getMultiplier(int year)
case 2001:
multiplier = 0.18665f;
break;
case 2000:
multiplier = 0.18976f;
break;
default:
multiplier = 1f;
}
Expand Down
237 changes: 126 additions & 111 deletions app/src/main/res/layout/activity_converter.xml
Original file line number Diff line number Diff line change
@@ -1,124 +1,139 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".Converter">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sumToConvert"
android:id="@+id/sumToConvertTextView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".Converter">

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/amountEditText"
android:layout_marginTop="24dp"
android:layout_below="@+id/sumToConvertTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/currencyOriginTextView"
android:layout_toStartOf="@+id/currencyOriginTextView"
android:inputType="numberDecimal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sumToConvert"
android:id="@+id/sumToConvertTextView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/yearOfOrigin"
android:id="@+id/yearOfOriginTextView"
android:layout_alignBottom="@+id/yearOfOriginSpinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/yearOfResultTextView"
android:layout_alignEnd="@+id/yearOfResultTextView" />

<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/yearOfOriginSpinner"
android:layout_toEndOf="@+id/convertButton"
android:layout_below="@+id/amountEditText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/amountEditText"
android:inputType="numberDecimal"
android:layout_below="@+id/sumToConvertTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/resultEditText"
android:layout_alignEnd="@+id/resultEditText" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/yearOfResult"
android:id="@+id/yearOfResultTextView"
android:layout_toEndOf="@+id/resultTextView"
android:layout_alignBottom="@+id/yearOfResultSpinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
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_toRightOf="@+id/amountEditText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/yearOfResultSpinner"
android:layout_toEndOf="@+id/convertButton"
android:layout_below="@+id/yearOfOriginSpinner"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/yearOfOrigin"
android:id="@+id/yearOfOriginTextView"
android:layout_alignBaseline="@+id/yearOfOriginSpinner"
android:layout_alignBottom="@+id/yearOfOriginSpinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/yearOfResultTextView"
android:layout_alignEnd="@+id/yearOfResultTextView" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/convertButton"
android:id="@+id/convertButton"
android:layout_below="@+id/yearOfResultTextView"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/yearOfOriginSpinner"
android:layout_toEndOf="@+id/yearOfOriginTextView"
android:layout_below="@+id/amountEditText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/yearOfOriginTextView" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultTextView"
android:layout_marginTop="22dp"
android:layout_below="@+id/convertButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="@string/resultText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/yearOfResult"
android:id="@+id/yearOfResultTextView"
android:layout_alignBaseline="@+id/yearOfResultSpinner"
android:layout_toEndOf="@+id/resultTextView"
android:layout_alignBottom="@+id/yearOfResultSpinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="@+id/currencyOriginTextView"
android:layout_alignBottom="@+id/amountEditText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/yearOfResultSpinner"
android:layout_toEndOf="@+id/yearOfResultTextView"
android:layout_below="@+id/yearOfOriginSpinner"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/yearOfResultTextView" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="@+id/resultEditText"
android:layout_below="@+id/resultTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="24dp"
android:layout_toLeftOf="@+id/currencyResultTextView"
android:layout_toStartOf="@+id/currencyResultTextView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/convertButton"
android:id="@+id/convertButton"
android:layout_below="@+id/yearOfResultTextView"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="@+id/currencyResultTextView"
android:layout_alignBottom="@+id/resultEditText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultTextView"
android:layout_marginTop="12dp"
android:layout_below="@+id/convertButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="@string/resultText" />

</RelativeLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="@+id/resultEditText"
android:layout_toStartOf="@+id/currencyResultTextView"
android:layout_below="@+id/resultTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/currencyResultTextView" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="@+id/currencyResultTextView"
android:layout_alignBaseline="@+id/resultEditText"
android:layout_alignBottom="@+id/resultEditText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

</RelativeLayout>
</ScrollView>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<string name="resultText">Résultat :</string>

<string name="about_text"><![CDATA[Une application créée par corenting.<br><a href="http://www.corenting.fr">Site web</a><br><br>Version :&nbsp;]]></string>
<string name="errorToast">Erreur lors de la conversion !</string>

</resources>

0 comments on commit a41314c

Please sign in to comment.