Skip to content

Commit 1f41c79

Browse files
author
erickbmr
committed
initial commit
1 parent aee53a0 commit 1f41c79

34 files changed

+1080
-0
lines changed

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdk 31
7+
8+
defaultConfig {
9+
applicationId "com.example.calculateimc"
10+
minSdk 23
11+
targetSdk 31
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
28+
}
29+
30+
dependencies {
31+
32+
implementation 'androidx.appcompat:appcompat:1.3.1'
33+
implementation 'com.google.android.material:material:1.4.0'
34+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
35+
testImplementation 'junit:junit:4.+'
36+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
37+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
38+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.calculateimc;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.example.calculateimc", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.calculateimc">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.CalculateIMC">
12+
<activity
13+
android:name=".MainActivity"
14+
android:exported="true">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
</application>
22+
23+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
package com.example.calculateimc;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.content.res.ColorStateList;
6+
import android.graphics.PorterDuff;
7+
import android.os.Bundle;
8+
import android.view.View;
9+
import android.view.inputmethod.InputMethod;
10+
import android.view.inputmethod.InputMethodManager;
11+
import android.widget.Button;
12+
import android.widget.EditText;
13+
import android.widget.TextView;
14+
import android.widget.Toast;
15+
16+
import com.example.calculateimc.statics.StaticInfo;
17+
18+
public class MainActivity extends AppCompatActivity {
19+
20+
private EditText peso;
21+
private EditText altura;
22+
private Button calcular;
23+
private Button limpar;
24+
private Button resultadoCor;
25+
private TextView resultadoImc;
26+
private TextView resultadoClassificacao;
27+
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
setContentView(R.layout.activity_main);
32+
33+
initComponents();
34+
handleEvents();
35+
}
36+
37+
private void initComponents()
38+
{
39+
try {
40+
peso = findViewById(R.id.peso);
41+
altura = findViewById(R.id.altura);
42+
calcular = findViewById(R.id.calcBtn);
43+
limpar = findViewById(R.id.cleanBtn);
44+
resultadoCor = findViewById(R.id.btnResult);
45+
resultadoImc = findViewById(R.id.imc);
46+
resultadoClassificacao = findViewById(R.id.classificacao);
47+
}
48+
catch (Exception ex){
49+
System.out.println("initComponents(): " + ex.getMessage());
50+
}
51+
}
52+
53+
private void handleEvents()
54+
{
55+
try {
56+
handleCalculateBtn();
57+
handleCleanBtn();
58+
}
59+
catch (Exception ex) {
60+
System.out.println("handleEvents(): " + ex.getMessage());
61+
}
62+
}
63+
64+
private void handleCalculateBtn()
65+
{
66+
try {
67+
cleanFields();
68+
calcular.setOnClickListener(new View.OnClickListener() {
69+
@Override
70+
public void onClick(View view) {
71+
if(!testEditTextIsValid(peso) || !testEditTextIsValid(altura))
72+
Toast.makeText(MainActivity.this, "É necessário preencher todos os campos.", Toast.LENGTH_LONG).show();
73+
else
74+
{
75+
closeInputKeyboard(view);
76+
String weightInput = peso.getText().toString();
77+
String heightInput = altura.getText().toString();
78+
double weight = Double.parseDouble(weightInput);
79+
double height = Double.parseDouble(heightInput);
80+
81+
double result = (weight / Math.pow(height, 2));
82+
resultadoImc.setText(String.format("%.2f", result));
83+
setLabelAndButtonColor(result);
84+
}
85+
}
86+
});
87+
}
88+
catch (Exception ex){
89+
System.out.println("handleCalculateBtn(): " + ex.getMessage());
90+
}
91+
}
92+
93+
private void closeInputKeyboard(View view)
94+
{
95+
try {
96+
InputMethodManager input = (InputMethodManager) getSystemService(MainActivity.INPUT_METHOD_SERVICE);
97+
input.hideSoftInputFromWindow(view.getWindowToken(), 0);
98+
}
99+
catch(Exception ex){
100+
System.out.println("closeInputKeyboard(): " + ex.getMessage());
101+
}
102+
}
103+
104+
private void handleCleanBtn()
105+
{
106+
try {
107+
limpar.setOnClickListener(new View.OnClickListener() {
108+
@Override
109+
public void onClick(View view) {
110+
cleanFields();
111+
closeInputKeyboard(view);
112+
}
113+
});
114+
}
115+
catch (Exception ex){
116+
System.out.println("handleCleanBtn(): " + ex.getMessage());
117+
}
118+
}
119+
120+
private void cleanFields()
121+
{
122+
try {
123+
peso.setText("");
124+
altura.setText("");
125+
resultadoCor.setBackgroundColor(getResources().getColor(R.color.white));
126+
resultadoImc.setText("");
127+
resultadoClassificacao.setText("");
128+
}
129+
catch (Exception ex){
130+
System.out.println("cleanFields(): " + ex.getMessage());
131+
}
132+
}
133+
134+
private boolean testEditTextIsValid(EditText editText)
135+
{
136+
try {
137+
String text = editText.getText().toString();
138+
return !text.isEmpty();
139+
}
140+
catch (Exception ex){
141+
System.out.println("testEditTextDouble(): " + ex.getMessage());
142+
return false;
143+
}
144+
}
145+
146+
private void setLabelAndButtonColor(double result)
147+
{
148+
try {
149+
if(result < 16.0)
150+
{
151+
resultadoCor.setBackgroundColor(getResources().getColor(R.color.magrezaIII));
152+
resultadoClassificacao.setText(StaticInfo.MagrezaIII);
153+
}
154+
else if(result >= 16.0 && result <= 16.9)
155+
{
156+
resultadoCor.setBackgroundColor(getResources().getColor(R.color.magrezaII));
157+
resultadoClassificacao.setText(StaticInfo.MagrezaII);
158+
}
159+
else if(result > 16.9 && result <= 18.4)
160+
{
161+
resultadoCor.setBackgroundColor(getResources().getColor(R.color.magrezaI));
162+
resultadoClassificacao.setText(StaticInfo.MagrezaI);
163+
}
164+
else if(result > 18.4 && result <= 24.9)
165+
{
166+
resultadoCor.setBackgroundColor(getResources().getColor(R.color.eutrofia));
167+
resultadoClassificacao.setText(StaticInfo.Eutrofia);
168+
}
169+
else if(result > 24.9 && result <= 29.9)
170+
{
171+
resultadoCor.setBackgroundColor(getResources().getColor(R.color.preObesidade));
172+
resultadoClassificacao.setText(StaticInfo.PreObesidade);
173+
}
174+
else if(result > 29.9 && result <= 34.9)
175+
{
176+
resultadoCor.setBackgroundColor(getResources().getColor(R.color.moderada));
177+
resultadoClassificacao.setText(StaticInfo.ObesidadeModerada);
178+
}
179+
else if(result > 34.9 && result <= 39.9)
180+
{
181+
resultadoCor.setBackgroundColor(getResources().getColor(R.color.severa));
182+
resultadoClassificacao.setText(StaticInfo.ObesidadeSevera);
183+
}
184+
else
185+
{
186+
resultadoCor.setBackgroundColor(getResources().getColor(R.color.muitoSevera));
187+
resultadoClassificacao.setText(StaticInfo.ObesidadeMuitoSevera);
188+
}
189+
}
190+
catch (Exception ex){
191+
System.out.println("setLabelAndButtonColor(): " + ex.getMessage());
192+
}
193+
}
194+
195+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.calculateimc.statics;
2+
3+
public class StaticInfo
4+
{
5+
public static String MagrezaIII = "Magreza Grau III";
6+
public static String MagrezaII = "Magreza Grau II";
7+
public static String MagrezaI = "Magreza Grau I";
8+
public static String Eutrofia = "Eutrofia(saudável)";
9+
public static String PreObesidade = "Pré-obesidade";
10+
public static String ObesidadeModerada = "Obesidade Moderada (grau I)";
11+
public static String ObesidadeSevera = "Obesidade Severa (grau II)";
12+
public static String ObesidadeMuitoSevera = "Obesidade Muito Severa (grau III)";
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportWidth="108"
6+
android:viewportHeight="108">
7+
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
8+
<aapt:attr name="android:fillColor">
9+
<gradient
10+
android:endX="85.84757"
11+
android:endY="92.4963"
12+
android:startX="42.9492"
13+
android:startY="49.59793"
14+
android:type="linear">
15+
<item
16+
android:color="#44000000"
17+
android:offset="0.0" />
18+
<item
19+
android:color="#00000000"
20+
android:offset="1.0" />
21+
</gradient>
22+
</aapt:attr>
23+
</path>
24+
<path
25+
android:fillColor="#FFFFFF"
26+
android:fillType="nonZero"
27+
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
28+
android:strokeWidth="1"
29+
android:strokeColor="#00000000" />
30+
</vector>

0 commit comments

Comments
 (0)