Guest User

Untitled

a guest
Apr 20th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.39 KB | None | 0 0
  1. package com.example.stealth2017;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. //import android.content.Intent;
  6. import android.os.Bundle;
  7. //import android.view.Menu;
  8. //import android.view.MenuItem;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.TextView;
  14.  
  15. public class Stealth2017MainActivity extends Activity {
  16.  
  17. EditText editTextComprimento;
  18. EditText editTextLargura;
  19. EditText editTextAltura;
  20.  
  21. TextView TextFieldComprimento;
  22. TextView TextFieldRLargura;
  23. TextView TextFieldRAltura;
  24.  
  25. Button buttonVerificarMedidas;
  26. Button buttonCalculaAV;
  27. EditText editTextArea;
  28. EditText editTextVolume;
  29.  
  30. @Override
  31. protected void onCreate(Bundle savedInstanceState) {
  32. super.onCreate(savedInstanceState);
  33. setContentView(R.layout.activity_stealth2017_main);
  34.  
  35. final AlertDialog.Builder alerta = new AlertDialog.Builder(Stealth2017MainActivity.this);
  36.  
  37. editTextComprimento = (EditText) findViewById(R.id.EditTextComprimento);
  38. editTextLargura = (EditText) findViewById(R.id.EditTextLargura);
  39. editTextAltura = (EditText) findViewById(R.id.EditTextAltura);
  40. editTextArea = (EditText) findViewById(R.id.editTextArea);
  41. editTextVolume = (EditText) findViewById(R.id.editTextVolume);
  42.  
  43. buttonCalculaAV = (Button) findViewById(R.id.buttonCalculaAV);
  44. buttonVerificarMedidas = (Button) findViewById(R.id.buttonVerificarMedidas);
  45.  
  46. TextFieldComprimento = (TextView) findViewById(R.id.TextFieldComprimento);
  47. TextFieldRLargura = (TextView) findViewById(R.id.TextFieldLargura);
  48. TextFieldRAltura = (TextView) findViewById(R.id.TextFieldAltura);
  49.  
  50.  
  51. buttonVerificarMedidas.setOnClickListener(new OnClickListener() {
  52. @Override
  53. public void onClick(View v) {
  54.  
  55.  
  56. double Altura, Comprimento, Largura;
  57.  
  58. Altura = Double.parseDouble(editTextAltura.getText().toString());
  59. Comprimento = Double.parseDouble(editTextComprimento.getText().toString());
  60. Largura = Double.parseDouble(editTextLargura.getText().toString());
  61.  
  62.  
  63. if (Comprimento >= 3.0) {
  64. editTextComprimento.setText(String.valueOf(Comprimento));
  65. } else {
  66. alerta.setTitle("Atenção");
  67. alerta.setMessage("Comprimento mínimo 3 metros !");
  68. alerta.setNeutralButton("OK", null);
  69. alerta.show();
  70. editTextComprimento.setText("");
  71. }
  72.  
  73.  
  74. if (Altura >= 3.5) {
  75. editTextAltura.setText(String.valueOf(Altura));
  76. } else {
  77. alerta.setTitle("Atenção");
  78. alerta.setMessage("Altura mínima 3.5 metros !");
  79. alerta.setNeutralButton("OK", null);
  80. alerta.show();
  81. editTextAltura.setText("");
  82. }
  83.  
  84.  
  85. if (Largura >= 3.0) {
  86. editTextLargura.setText(String.valueOf(Largura));
  87. } else {
  88. alerta.setTitle("Atenção");
  89. alerta.setMessage("Largura mínima 3 metros !");
  90. alerta.setNeutralButton("OK", null);
  91. alerta.show();
  92. editTextLargura.setText("");
  93. }
  94. buttonCalculaAV.setOnClickListener(new OnClickListener() {
  95. @Override
  96. public void onClick(View arg0) {
  97. double Altura, Comprimento, Largura, Area, Volume;
  98.  
  99. Altura = Double.parseDouble(editTextAltura.getText().toString());
  100. Comprimento = Double.parseDouble(editTextComprimento.getText().toString());
  101. Largura = Double.parseDouble(editTextLargura.getText().toString());
  102.  
  103. if (Largura >= 3.0 && Altura >= 3.5 && Comprimento >= 3.0){
  104.  
  105. Area = Comprimento * Altura;
  106. Volume = Comprimento * Altura * Largura;
  107.  
  108. if (Area >= 10.5) {
  109. Volume = Double.parseDouble(editTextVolume.getText().toString());
  110. Area = Double.parseDouble(editTextArea.getText().toString());
  111. editTextArea.setText(String.format("%1$.2f", Area));
  112. //editTextArea.setText(String.valueOf(Area));
  113. editTextVolume.setText(String.format("%1$.2f", Volume));
  114. //editTextVolume.setText(String.valueOf(Volume));
  115. } else {
  116. alerta.setTitle("Atenção");
  117. alerta.setMessage("Área mínima 10.5 metros² !");
  118. alerta.setNeutralButton("OK", null);
  119. alerta.show();
  120. editTextArea.setText("");
  121. editTextVolume.setText("");
  122. editTextComprimento.setText("");
  123. editTextLargura.setText("");
  124. editTextAltura.setText("");
  125. }
  126. }
  127. }
  128. });
  129. };
  130.  
  131. });
  132.  
  133. }
  134. }
  135.  
  136. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  137. xmlns:tools="http://schemas.android.com/tools"
  138. android:layout_width="match_parent"
  139. android:layout_height="match_parent"
  140. tools:context="${relativePackage}.${activityClass}" >
  141.  
  142. <LinearLayout
  143. android:id="@+id/LinearLayoutAltura"
  144. android:layout_width="match_parent"
  145. android:layout_height="wrap_content"
  146. android:layout_alignParentLeft="true"
  147. android:layout_below="@+id/LinearLayoutComprimento" >
  148.  
  149. <TextView
  150. android:id="@+id/TextFieldAltura"
  151. android:layout_width="wrap_content"
  152. android:layout_height="wrap_content"
  153. android:text="Altura: " />
  154.  
  155. <EditText
  156. android:id="@+id/EditTextAltura"
  157. android:layout_width="180dp"
  158. android:layout_height="wrap_content"
  159. android:layout_weight="1"
  160. android:ems="10" >
  161.  
  162. <requestFocus />
  163. </EditText>
  164. </LinearLayout>
  165.  
  166. <LinearLayout
  167. android:id="@+id/LinearLayoutLargura"
  168. android:layout_width="match_parent"
  169. android:layout_height="wrap_content"
  170. android:layout_alignParentLeft="true"
  171. android:layout_below="@+id/LinearLayoutAltura" >
  172.  
  173. <TextView
  174. android:id="@+id/TextFieldLargura"
  175. android:layout_width="wrap_content"
  176. android:layout_height="wrap_content"
  177. android:text="Largura: " />
  178.  
  179. <EditText
  180. android:id="@+id/EditTextLargura"
  181. android:layout_width="78dp"
  182. android:layout_height="wrap_content"
  183. android:layout_weight="0.99"
  184. android:ems="10" />
  185. </LinearLayout>
  186.  
  187. <LinearLayout
  188. android:id="@+id/LinearLayoutComprimento"
  189. android:layout_width="match_parent"
  190. android:layout_height="wrap_content"
  191. android:layout_alignParentLeft="true"
  192. android:layout_alignParentTop="true"
  193. android:layout_marginTop="34dp" >
  194.  
  195. <TextView
  196. android:id="@+id/TextFieldComprimento"
  197. android:layout_width="wrap_content"
  198. android:layout_height="wrap_content"
  199. android:text="Comprimento: " />
  200.  
  201. <EditText
  202. android:id="@+id/EditTextComprimento"
  203. android:layout_width="118dp"
  204. android:layout_height="wrap_content"
  205. android:layout_weight="1.42"
  206. android:ems="10" />
  207. </LinearLayout>
  208.  
  209. <LinearLayout
  210. android:id="@+id/LinearLayoutTecnicos"
  211. android:layout_width="match_parent"
  212. android:layout_height="wrap_content"
  213. android:layout_alignParentLeft="true"
  214. android:layout_below="@+id/LinearLayoutLargura"
  215. android:layout_marginTop="115dp" >
  216.  
  217. <TextView
  218. android:id="@+id/TextFieldTecnicos"
  219. android:layout_width="wrap_content"
  220. android:layout_height="wrap_content"
  221. android:text="Qtd. Técnicos: " />
  222.  
  223. <EditText
  224. android:id="@+id/EditTextTecnicos"
  225. android:layout_width="75dp"
  226. android:layout_height="wrap_content"
  227. android:layout_weight="0.16"
  228. android:ems="10"
  229. android:focusable="false"
  230. android:focusableInTouchMode="false" />
  231.  
  232. <Button
  233. android:id="@+id/ButtonTecnicos"
  234. style="?android:attr/buttonStyleSmall"
  235. android:layout_width="wrap_content"
  236. android:layout_height="34dp"
  237. android:text="Confirmar" />
  238. </LinearLayout>
  239.  
  240. <LinearLayout
  241. android:id="@+id/LinearLayoutMainframes"
  242. android:layout_width="match_parent"
  243. android:layout_height="wrap_content"
  244. android:layout_alignParentLeft="true"
  245. android:layout_below="@+id/LinearLayoutTecnicos"
  246. android:gravity="center" >
  247.  
  248. <TextView
  249. android:id="@+id/TextFieldMainframes"
  250. android:layout_width="wrap_content"
  251. android:layout_height="wrap_content"
  252. android:text="Qtd. Mainframes: " />
  253.  
  254. <EditText
  255. android:id="@+id/EditTextMainframes"
  256. android:layout_width="75dp"
  257. android:layout_height="wrap_content"
  258. android:layout_weight="1"
  259. android:ems="10" />
  260.  
  261. <Button
  262. android:id="@+id/ButtonMainframes"
  263. style="?android:attr/buttonStyleSmall"
  264. android:layout_width="wrap_content"
  265. android:layout_height="34dp"
  266. android:text="Confirmar" />
  267. </LinearLayout>
  268.  
  269. <LinearLayout
  270. android:id="@+id/LinearLayoutCalcular"
  271. android:layout_width="wrap_content"
  272. android:layout_height="wrap_content"
  273. android:layout_below="@+id/LinearLayoutLargura"
  274. android:layout_centerHorizontal="true"
  275. android:layout_marginTop="54dp"
  276. android:gravity="center" >
  277.  
  278. <Button
  279. android:id="@+id/buttonCalculaAV"
  280. android:layout_width="wrap_content"
  281. android:layout_height="34dp"
  282. android:minWidth="48dp"
  283. android:text="Calcular medidas"
  284. android:textSize="12sp" />
  285.  
  286. <EditText
  287. android:id="@+id/editTextArea"
  288. android:layout_width="62dp"
  289. android:layout_height="wrap_content"
  290. android:ems="10"
  291. android:hint="Área" />
  292.  
  293. <EditText
  294. android:id="@+id/editTextVolume"
  295. android:layout_width="wrap_content"
  296. android:layout_height="wrap_content"
  297. android:hint="Volume" />
  298. </LinearLayout>
  299.  
  300. <Button
  301. android:id="@+id/buttonVerificarMedidas"
  302. android:layout_width="wrap_content"
  303. android:layout_height="wrap_content"
  304. android:layout_below="@+id/LinearLayoutLargura"
  305. android:layout_centerHorizontal="true"
  306. android:text="Verificar medidas" />
  307.  
  308. </RelativeLayout>
Add Comment
Please, Sign In to add comment