Compare commits
No commits in common. "master" and "V1" have entirely different histories.
@ -1,23 +1,29 @@
|
|||||||
package io.n0x.android.java_mot_testing;
|
package io.n0x.android.java_mot_testing;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.databinding.DataBindingUtil;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
|
||||||
import io.n0x.android.java_mot_testing.databinding.Ex9DataBindingBinding;
|
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
|
// For debugging
|
||||||
private static final String TAG = MainActivity.class.getName();
|
private static final String TAG = MainActivity.class.getName();
|
||||||
|
// Local calculator instance
|
||||||
|
private FractionCalculator calc;
|
||||||
|
|
||||||
|
private int test;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
// Local calculator instance
|
// create calculator instance
|
||||||
FractionCalculator calc = new FractionCalculator();
|
calc = new FractionCalculator();
|
||||||
|
|
||||||
// set a value for testing
|
// set a value for testing
|
||||||
calc.setEnumResult(0);
|
calc.setEnumResult(0);
|
||||||
@ -26,16 +32,37 @@ public class MainActivity extends AppCompatActivity{
|
|||||||
// Bind instance of FractionCalculator to view
|
// Bind instance of FractionCalculator to view
|
||||||
Ex9DataBindingBinding binding = DataBindingUtil.setContentView(this, R.layout.ex9_data_binding);
|
Ex9DataBindingBinding binding = DataBindingUtil.setContentView(this, R.layout.ex9_data_binding);
|
||||||
binding.setCalc(calc);
|
binding.setCalc(calc);
|
||||||
// set initial value for the arithmetical method
|
|
||||||
calc.setArithMethod(FractionCalculator.ARTIH.ADD);
|
|
||||||
|
|
||||||
/*
|
// Button Listeners
|
||||||
// Converter to get null values
|
findViewById(R.id.button_add).setOnClickListener(this);
|
||||||
Converter conv = new Converter();
|
findViewById(R.id.button_sub).setOnClickListener(this);
|
||||||
binding.setConv(conv);
|
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 create action
|
||||||
Log.d(TAG, "MainActivity started");
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,9 +7,6 @@
|
|||||||
<variable
|
<variable
|
||||||
name="calc"
|
name="calc"
|
||||||
type="io.n0x.android.java_mot_testing.FractionCalculator" />
|
type="io.n0x.android.java_mot_testing.FractionCalculator" />
|
||||||
<variable
|
|
||||||
name="conv"
|
|
||||||
type="io.n0x.android.java_mot_testing.helper.Converter" />
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
@ -17,7 +14,6 @@
|
|||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:onClick="@{() -> calc.setArithMethod(io.n0x.android.java_mot_testing.FractionCalculator.ARTIH.ADD)}"
|
|
||||||
android:id="@+id/button_add"
|
android:id="@+id/button_add"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -30,7 +26,6 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:onClick="@{() -> calc.setArithMethod(io.n0x.android.java_mot_testing.FractionCalculator.ARTIH.SUBTRACT)}"
|
|
||||||
android:id="@+id/button_sub"
|
android:id="@+id/button_sub"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -41,7 +36,6 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:onClick="@{() -> calc.setArithMethod(io.n0x.android.java_mot_testing.FractionCalculator.ARTIH.MULTIPLICATE)}"
|
|
||||||
android:id="@+id/button_mult"
|
android:id="@+id/button_mult"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -52,7 +46,6 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:onClick="@{() -> calc.setArithMethod(io.n0x.android.java_mot_testing.FractionCalculator.ARTIH.DIVIDE)}"
|
|
||||||
android:id="@+id/button_div"
|
android:id="@+id/button_div"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -143,7 +136,6 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/enumRight" />
|
app:layout_constraintTop_toBottomOf="@+id/enumRight" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:onClick="@{() -> calc.calculateResult()}"
|
|
||||||
android:id="@+id/button_calc"
|
android:id="@+id/button_calc"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
Reference in New Issue
Block a user