From 5428ae08b054eba7bfde28f2912f029b02e54b12 Mon Sep 17 00:00:00 2001
From: adpth <adpth14@gmail.com>
Date: Wed, 4 Nov 2020 00:01:47 +0530
Subject: [PATCH] Now App supports Multiple Screens

---
 app/build.gradle                              |  12 +-
 .../com/adpth/bmicalculator/MainActivity.java |  75 ++++++----
 .../main/res/layout-land/activity_result.xml  | 136 ++++++++++++++++++
 app/src/main/res/layout/activity_result.xml   |  14 +-
 4 files changed, 192 insertions(+), 45 deletions(-)
 create mode 100644 app/src/main/res/layout-land/activity_result.xml

diff --git a/app/build.gradle b/app/build.gradle
index 410800e..f191a4e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,13 +1,13 @@
 apply plugin: 'com.android.application'
 
 android {
-    compileSdkVersion 29
+    compileSdkVersion 30
     buildToolsVersion "30.0.2"
 
     defaultConfig {
         applicationId "com.adpth.bmicalculator"
         minSdkVersion 16
-        targetSdkVersion 29
+        targetSdkVersion 30
         versionCode 1
         versionName "1.0"
 
@@ -21,18 +21,14 @@ android {
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
     }
-
-    buildFeatures {
-        viewBinding = true
-    }
 }
 
 dependencies {
     implementation fileTree(dir: "libs", include: ["*.jar"])
     implementation 'androidx.appcompat:appcompat:1.2.0'
-    implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
+    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
     implementation 'androidx.cardview:cardview:1.0.0'
-    testImplementation 'junit:junit:4.13'
+    testImplementation 'junit:junit:4.13.1'
     androidTestImplementation 'androidx.test.ext:junit:1.1.2'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
     implementation 'com.github.DanielMartinus:Stepper-Touch:0.6'
diff --git a/app/src/main/java/com/adpth/bmicalculator/MainActivity.java b/app/src/main/java/com/adpth/bmicalculator/MainActivity.java
index 9e44fd4..f680ab7 100644
--- a/app/src/main/java/com/adpth/bmicalculator/MainActivity.java
+++ b/app/src/main/java/com/adpth/bmicalculator/MainActivity.java
@@ -9,43 +9,54 @@ import android.graphics.Color;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
-import android.widget.ImageView;
 import android.widget.RelativeLayout;
 import android.widget.SeekBar;
 import android.widget.TextView;
 
-import com.adpth.bmicalculator.databinding.ActivityMainBinding;
 
 public class MainActivity extends AppCompatActivity {
 
     float height,weight;
+    TextView height_txt,age;
     int count_weight = 50,count_age = 19;
+    RelativeLayout weight_plus, weight_minus, age_plus, age_minus;
     boolean male_clk = true, female_clk = true, check1 = true, check2 = true;
-    private ActivityMainBinding binding;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        binding = ActivityMainBinding.inflate(getLayoutInflater());
-        View view = binding.getRoot();
-        setContentView(view);
+        setContentView(R.layout.activity_main);
 
-        binding.cardViewMale.setOnClickListener(new View.OnClickListener() {
+        height_txt = findViewById(R.id.height_txt);
+
+        final TextView female_text = findViewById(R.id.female);
+        final TextView male_text = findViewById(R.id.male);
+
+        CardView card_female = findViewById(R.id.cardView_female);
+        CardView card_male = findViewById(R.id.cardView_male);
+
+        age_minus = findViewById(R.id.age_minus);
+        age_plus = findViewById(R.id.age_plus);
+
+        weight_minus = findViewById(R.id.weight_minus);
+        weight_plus = findViewById(R.id.weight_plus);
+
+        card_male.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 if (check1) {
 
                     if (male_clk) {
 
-                        binding.male.setTextColor(Color.parseColor("#FFFFFF"));
-                        binding.male.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.male_white,0,0);
+                        male_text.setTextColor(Color.parseColor("#FFFFFF"));
+                        male_text.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.male_white,0,0);
                         male_clk = false;
                         check2 = false;
 
                     } else {
 
-                        binding.male.setTextColor(Color.parseColor("#8D8E99"));
-                        binding.male.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.male,0,0);
+                        male_text.setTextColor(Color.parseColor("#8D8E99"));
+                        male_text.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.male,0,0);
                         male_clk = true;
                         check2 = true;
                     }
@@ -53,20 +64,20 @@ public class MainActivity extends AppCompatActivity {
             }
         });
 
-        binding.cardViewFemale.setOnClickListener(new View.OnClickListener() {
+        card_female.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 if (check2) {
                     if (female_clk) {
-                        binding.female.setTextColor(Color.parseColor("#FFFFFF"));
-                        binding.female.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.female_white,0,0);
+                        female_text.setTextColor(Color.parseColor("#FFFFFF"));
+                        female_text.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.female_white,0,0);
                         female_clk = false;
                         check1 = false;
                     }
                     else  {
 
-                        binding.female.setTextColor(Color.parseColor("#8D8E99"));
-                        binding.female.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.female,0,0);
+                        female_text.setTextColor(Color.parseColor("#8D8E99"));
+                        female_text.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.female,0,0);
                         female_clk = true;
                         check1 = true;
                     }
@@ -80,7 +91,8 @@ public class MainActivity extends AppCompatActivity {
 
         CheckAge();
 
-        binding.calculate.setOnClickListener(new View.OnClickListener() {
+        Button calculate = findViewById(R.id.calculate);
+        calculate.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 CalculateBMI();
@@ -92,52 +104,57 @@ public class MainActivity extends AppCompatActivity {
 
     private void CheckAge() {
 
-        binding.agePlus.setOnClickListener(new View.OnClickListener() {
+        age = findViewById(R.id.age);
+
+        age_plus.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 count_age++;
-                binding.age.setText(String.valueOf(count_age));
+                age.setText(String.valueOf(count_age));
             }
         });
 
-        binding.ageMinus.setOnClickListener(new View.OnClickListener() {
+        age_minus.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 count_age--;
-                binding.age.setText(String.valueOf(count_age));
+                age.setText(String.valueOf(count_age));
             }
         });
     }
 
     private void CheckWeight() {
 
-        binding.weightPlus.setOnClickListener(new View.OnClickListener() {
+        final TextView weight_txt = findViewById(R.id.weight);
+
+        weight_plus.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 count_weight++;
-                binding.weight.setText(String.valueOf(count_weight));
+                weight_txt.setText(String.valueOf(count_weight));
             }
         });
 
-        binding.weightMinus.setOnClickListener(new View.OnClickListener() {
+        weight_minus.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 count_weight--;
-                binding.weight.setText(String.valueOf(count_weight));
+                weight_txt.setText(String.valueOf(count_weight));
             }
         });
 
-        weight = Float.parseFloat(binding.weight.getText().toString());
+        weight = Float.parseFloat(weight_txt.getText().toString());
 
     }
 
     private void CheckSeekbarStatus() {
 
-        binding.Seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+        SeekBar Seekbar = findViewById(R.id.Seekbar);
+        Seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                 String ht = progress + getResources().getString(R.string.cm);
-                binding.heightTxt.setText(ht);
+                height_txt.setText(ht);
                 height = (float)(progress)/100;
             }
 
@@ -158,7 +175,7 @@ public class MainActivity extends AppCompatActivity {
         float BMI = weight / (height * height);
         Intent intent = new Intent(MainActivity.this,ResultActivity.class);
         intent.putExtra("BMI",BMI);
-        intent.putExtra("age",binding.age.getText().toString());
+        intent.putExtra("age",age.getText().toString());
         startActivity(intent);
     }
 }
\ No newline at end of file
diff --git a/app/src/main/res/layout-land/activity_result.xml b/app/src/main/res/layout-land/activity_result.xml
new file mode 100644
index 0000000..934e6ce
--- /dev/null
+++ b/app/src/main/res/layout-land/activity_result.xml
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@color/background"
+    tools:context=".ResultActivity">
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <TextView
+            android:id="@+id/textView"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/your_result"
+            android:textColor="@android:color/white"
+            android:textSize="40sp"
+            android:layout_margin="16dp"
+            android:textStyle="bold"
+            android:layout_marginLeft="16dp"
+            android:layout_marginRight="16dp"
+            app:layout_constraintBottom_toTopOf="@+id/result_card"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+        <androidx.cardview.widget.CardView
+            android:id="@+id/result_card"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="16dp"
+            android:layout_marginTop="16dp"
+            android:layout_marginRight="16dp"
+            app:cardBackgroundColor="@color/card_background"
+            app:cardCornerRadius="20sp"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintHorizontal_bias="0.5"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/textView">
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:gravity="center"
+                android:orientation="vertical"
+                android:padding="20dp">
+
+                <TextView
+                    android:id="@+id/condition"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="20sp"
+                    android:textColor="#5ADC65"
+                    android:textSize="20sp"
+                    android:textStyle="bold" />
+
+                <TextView
+                    android:id="@+id/your_bmi"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="10dp"
+                    android:textColor="@android:color/white"
+                    android:textSize="50sp"
+                    android:textStyle="bold" />
+
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="16dp"
+                    android:text="@string/normal_bmi_range"
+                    android:textColor="#8D8E99"
+                    android:textSize="21sp"
+                    android:textStyle="bold" />
+
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="@string/_18_5_25_kg_m2"
+                    android:textColor="@android:color/white"
+                    android:textSize="20sp"
+                    android:textStyle="bold" />
+
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="16dp"
+                    android:text="@string/your_age"
+                    android:textColor="@color/colorAccent"
+                    android:textSize="20sp"
+                    android:textStyle="bold" />
+
+                <TextView
+                    android:id="@+id/age"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textColor="@android:color/white"
+                    android:textSize="20sp" />
+
+                <TextView
+                    android:id="@+id/category"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="16dp"
+                    android:layout_marginBottom="8dp"
+                    android:gravity="center_horizontal"
+                    android:textColor="@android:color/white"
+                    android:textSize="20sp" />
+
+            </LinearLayout>
+
+        </androidx.cardview.widget.CardView>
+
+        <Button
+            android:id="@+id/recalculate"
+            android:layout_width="match_parent"
+            android:layout_height="55dp"
+            android:layout_marginTop="32dp"
+            android:layout_marginLeft="16dp"
+            android:layout_marginRight="16dp"
+            android:layout_marginBottom="32dp"
+            android:background="@drawable/calculate_btn"
+            android:text="@string/recalculate"
+            android:textColor="@android:color/white"
+            android:textSize="17sp"
+            android:textStyle="bold"
+            app:layout_constraintTop_toBottomOf="@+id/result_card"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintHorizontal_bias="0.5"
+            app:layout_constraintStart_toStartOf="parent" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+</ScrollView>
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_result.xml b/app/src/main/res/layout/activity_result.xml
index f2d30fb..3ad6901 100644
--- a/app/src/main/res/layout/activity_result.xml
+++ b/app/src/main/res/layout/activity_result.xml
@@ -11,13 +11,13 @@
         android:id="@+id/textView"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_margin="16dp"
-        android:layout_marginLeft="16dp"
-        android:layout_marginRight="16dp"
         android:text="@string/your_result"
         android:textColor="@android:color/white"
         android:textSize="40sp"
+        android:layout_margin="16dp"
         android:textStyle="bold"
+        android:layout_marginLeft="16dp"
+        android:layout_marginRight="16dp"
         app:layout_constraintBottom_toTopOf="@+id/result_card"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
@@ -32,6 +32,7 @@
         app:cardBackgroundColor="@color/card_background"
         app:cardCornerRadius="20sp"
         app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.5"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toBottomOf="@+id/textView">
 
@@ -111,10 +112,7 @@
         android:id="@+id/recalculate"
         android:layout_width="match_parent"
         android:layout_height="55dp"
-        android:layout_marginStart="16dp"
         android:layout_marginLeft="16dp"
-        android:layout_marginTop="32dp"
-        android:layout_marginEnd="16dp"
         android:layout_marginRight="16dp"
         android:layout_marginBottom="32dp"
         android:background="@drawable/calculate_btn"
@@ -124,7 +122,7 @@
         android:textStyle="bold"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"/>
-
+        app:layout_constraintHorizontal_bias="0.5"
+        app:layout_constraintStart_toStartOf="parent" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file