Compare commits

..

No commits in common. "master" and "V1" have entirely different histories.
master ... V1

3 changed files with 38 additions and 37 deletions

View File

@ -1,23 +1,29 @@
package io.n0x.android.java_mot_testing;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import io.n0x.android.java_mot_testing.databinding.Ex9DataBindingBinding;
import io.n0x.android.java_mot_testing.helper.Converter;
public class MainActivity extends AppCompatActivity{
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
// For debugging
private static final String TAG = MainActivity.class.getName();
// Local calculator instance
private FractionCalculator calc;
private int test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Local calculator instance
FractionCalculator calc = new FractionCalculator();
// create calculator instance
calc = new FractionCalculator();
// set a value for testing
calc.setEnumResult(0);
@ -26,16 +32,37 @@ public class MainActivity extends AppCompatActivity{
// Bind instance of FractionCalculator to view
Ex9DataBindingBinding binding = DataBindingUtil.setContentView(this, R.layout.ex9_data_binding);
binding.setCalc(calc);
// set initial value for the arithmetical method
calc.setArithMethod(FractionCalculator.ARTIH.ADD);
/*
// Converter to get null values
Converter conv = new Converter();
binding.setConv(conv);
//*/
// Button Listeners
findViewById(R.id.button_add).setOnClickListener(this);
findViewById(R.id.button_sub).setOnClickListener(this);
findViewById(R.id.button_mult).setOnClickListener(this);
findViewById(R.id.button_div).setOnClickListener(this);
findViewById(R.id.button_calc).setOnClickListener(this);
// Log create action
Log.d(TAG, "MainActivity started");
}
@SuppressLint("NonConstantResourceId")
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button_add:
calc.setArithMethod(FractionCalculator.ARTIH.ADD);
break;
case R.id.button_sub:
calc.setArithMethod(FractionCalculator.ARTIH.SUBTRACT);
break;
case R.id.button_mult:
calc.setArithMethod(FractionCalculator.ARTIH.MULTIPLICATE);
break;
case R.id.button_div:
calc.setArithMethod(FractionCalculator.ARTIH.DIVIDE);
break;
case R.id.button_calc:
calc.calculateResult();
break;
}
}
}

View File

@ -1,18 +0,0 @@
package io.n0x.android.java_mot_testing.helper;
import androidx.databinding.InverseMethod;
public class Converter {
@InverseMethod("toInt")
public static String toString(int val){
if(val == 0){
return null;
}
return String.valueOf(val);
}
public static int toInt(String val){
if(val == null || val.isEmpty())
return 0;
return Integer.parseInt(val);
}
}

View File

@ -7,9 +7,6 @@
<variable
name="calc"
type="io.n0x.android.java_mot_testing.FractionCalculator" />
<variable
name="conv"
type="io.n0x.android.java_mot_testing.helper.Converter" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
@ -17,7 +14,6 @@
android:layout_height="match_parent">
<Button
android:onClick="@{() -> calc.setArithMethod(io.n0x.android.java_mot_testing.FractionCalculator.ARTIH.ADD)}"
android:id="@+id/button_add"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -30,7 +26,6 @@
app:layout_constraintTop_toTopOf="parent" />
<Button
android:onClick="@{() -> calc.setArithMethod(io.n0x.android.java_mot_testing.FractionCalculator.ARTIH.SUBTRACT)}"
android:id="@+id/button_sub"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -41,7 +36,6 @@
app:layout_constraintTop_toTopOf="parent" />
<Button
android:onClick="@{() -> calc.setArithMethod(io.n0x.android.java_mot_testing.FractionCalculator.ARTIH.MULTIPLICATE)}"
android:id="@+id/button_mult"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -52,7 +46,6 @@
app:layout_constraintTop_toTopOf="parent" />
<Button
android:onClick="@{() -> calc.setArithMethod(io.n0x.android.java_mot_testing.FractionCalculator.ARTIH.DIVIDE)}"
android:id="@+id/button_div"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -143,7 +136,6 @@
app:layout_constraintTop_toBottomOf="@+id/enumRight" />
<Button
android:onClick="@{() -> calc.calculateResult()}"
android:id="@+id/button_calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"