diff --git a/app/build.gradle b/app/build.gradle index fbf8721..3cbe5f8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,6 +31,9 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.constraintlayout:constraintlayout:2.0.2' + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.1' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' diff --git a/app/src/main/java/com/scainitiative/kotlinscainitiativeproject/MainActivity.kt b/app/src/main/java/com/scainitiative/kotlinscainitiativeproject/MainActivity.kt index 2ae3088..22b4210 100644 --- a/app/src/main/java/com/scainitiative/kotlinscainitiativeproject/MainActivity.kt +++ b/app/src/main/java/com/scainitiative/kotlinscainitiativeproject/MainActivity.kt @@ -2,14 +2,87 @@ package com.scainitiative.kotlinscainitiativeproject import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.View import android.view.WindowManager +import android.widget.Button +import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { + var isOperator = true + var numbers = "" + var operators = "+" + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val w = window; w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) } + + fun numberClicked(view: View) { + if (isOperator) + displayEdittext.setText("") + isOperator = false + + var buttonClicked = displayEdittext.text.toString() + var buttonSelected = view as Button + when(buttonSelected.id){ + + cal_one.id -> {buttonClicked += "1"} + cal_two.id -> {buttonClicked += "2"} + cal_three.id -> {buttonClicked += "3"} + cal_four.id -> {buttonClicked += "4"} + cal_five.id -> {buttonClicked += "5"} + cal_six.id -> {buttonClicked += "6"} + cal_seven.id -> {buttonClicked += "7"} + cal_eight.id -> {buttonClicked += "8"} + cal_nine.id -> {buttonClicked += "9"} + cal_zero.id -> {buttonClicked += "0"} + cal_full_stop.id -> {buttonClicked += "."} + cal_add_minus.id -> {buttonClicked + "-$buttonClicked"} + + } + displayEdittext.setText(buttonClicked) + + } + + fun signOperation(view: View) { + isOperator = true + numbers = displayEdittext.text.toString() + var buttonSelected = view as Button + when (buttonSelected.id){ + cal_minus.id -> operators = "-" + cal_divide.id -> operators = "/" + cal_multiply.id -> operators = "*" + cal_plus.id -> operators = "+" + } + + + } + + fun equalTo(view: View) { + var anumber = displayEdittext.text.toString() + var result = 0.0 + when (operators){ + "+" -> {result = numbers.toDouble() + anumber.toDouble()} + "*" -> {result = numbers.toDouble() * anumber.toDouble()} + "-" -> {result = numbers.toDouble() - anumber.toDouble()} + "/" -> {result = numbers.toDouble() / anumber.toDouble()} + } + displayEdittext.setText(result.toString()) + + } + + fun clear(view: View) { + displayEdittext.setText("0") + isOperator = true + } + + fun percentage(view: View) { + var num = displayEdittext.text.toString().toDouble()/100 + displayEdittext.setText(num.toString()) + isOperator = true + + } } diff --git a/app/src/main/res/drawable/ic_baseline_arrow_downward_24.xml b/app/src/main/res/drawable/ic_baseline_arrow_downward_24.xml new file mode 100644 index 0000000..353eabc --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_arrow_downward_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 077f788..f486f63 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,65 +1,317 @@ - - + android:layout_height="270dp" + android:layout_marginTop="60dp" + android:layout_weight="1" + android:background="@color/white" + android:ems="10" + android:gravity="center|right" + android:inputType="number" + android:text="@string/_0" + android:textSize="40dp" + android:paddingEnd="8dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + android:id="@+id/linearLayout2" + android:layout_width="393dp" + android:layout_height="233dp" + android:layout_marginEnd="8dp" + android:layout_marginTop="8dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/displayEdittext"> - + android:layout_height="wrap_content" + android:layout_weight="1"> - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 030098f..7e4b5c6 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,8 @@ #6200EE #3700B3 #03DAC5 + #9C6BA5 + #fff + #FDA21B + #CFBCD3 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 2655e10..7e8d052 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,7 @@ 20dp + 50dp + 8dp + 15dp \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 39b53d6..60a4a80 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,4 +3,26 @@ Hey queen, congratulations on making it into the levelled membership programme being set up by the SCA community. \n\nBut you know you are on the wrong branch right? Head over to your respective level branch and start your project.\n\nWishing you best of luck!!! SCA Initiative - \nKotlin track sca_logo + + Hello blank fragment + 0 + C + % + +/- + / + 7 + 8 + 9 + * + 4 + 5 + 6 + - + 1 + 2 + 3 + + + 0 + . + = diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0eb88fe..41e5cc1 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -8,4 +8,5 @@ @color/colorAccent +