Advertisement
arnarg

MainActivity

Jan 7th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 KB | None | 0 0
  1. package com.caliper.fat;
  2.  
  3. import android.os.Bundle;
  4. import android.app.Activity;
  5. import android.content.Intent;
  6. import android.view.Menu;
  7. import android.view.MenuItem;
  8. import android.widget.EditText;
  9. import android.widget.RadioGroup;
  10.  
  11. public class MainActivity extends Activity {
  12.     EditText chest, axilla, tricep, subscapular, abdominal, suprailiac, thigh, age;
  13.     RadioGroup gender;
  14.     double sum, square, result;
  15.     int ageInt;
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.         initialize();
  21.     }
  22.  
  23.     private void initialize() {
  24.         // TODO Auto-generated method stub
  25.         chest = (EditText)findViewById(R.id.etChest);
  26.         axilla = (EditText)findViewById(R.id.etAxilla);
  27.         tricep = (EditText)findViewById(R.id.etTricep);
  28.         subscapular = (EditText)findViewById(R.id.etSubscapular);
  29.         abdominal = (EditText)findViewById(R.id.etAbdominal);
  30.         suprailiac = (EditText)findViewById(R.id.etSuprailiac);
  31.         thigh = (EditText)findViewById(R.id.etThigh);
  32.         gender = (RadioGroup)findViewById(R.id.rgGender);
  33.         age = (EditText)findViewById(R.id.etAge);
  34.     }
  35.  
  36.     @Override
  37.     public boolean onCreateOptionsMenu(Menu menu) {
  38.         // Inflate the menu; this adds items to the action bar if it is present.
  39.         getMenuInflater().inflate(R.menu.activity_main, menu);
  40.         return true;
  41.     }
  42.  
  43.     @Override
  44.     public boolean onOptionsItemSelected(MenuItem item) {
  45.         // TODO Auto-generated method stub
  46.         switch(item.getItemId()){
  47.         case R.id.menuCalculate:
  48.             calculate();
  49.             break;
  50.         }
  51.         return false;
  52.     }
  53.  
  54.     private void calculate() {
  55.         // TODO Auto-generated method stub
  56.         conversion();
  57.        
  58.         if(gender.getCheckedRadioButtonId() == R.id.rMale){
  59.             double step1 = 0.0008267 * sum;
  60.             double step2 = 0.00000055 * square;
  61.             double step3 = 0.00028826 * ageInt;
  62.             result = 1.112 - step1 + step2 - step3;
  63.         }
  64.         else if(gender.getCheckedRadioButtonId() == R.id.rFemale){
  65.             double step1 = 0.00046971 * sum;
  66.             double step2 = 0.00000056 * square;
  67.             double step3 = 0.00012828 * ageInt;
  68.             result = 1.097 - step1 + step2 - step3;
  69.         }
  70.         String resultString = Double.toString(result);
  71.         Bundle packet = new Bundle();
  72.         packet.putString("giveResults", resultString);
  73.         Intent a = new Intent(MainActivity.this, Display.class);
  74.         startActivity(a);
  75.     }
  76.  
  77.     private void conversion() {
  78.         // TODO Auto-generated method stub
  79.         String chestString = chest.getText().toString();
  80.         int chestInt = Integer.parseInt(chestString);
  81.         String axillaString = axilla.getText().toString();
  82.         int axillaInt = Integer.parseInt(axillaString);
  83.         String tricepString = tricep.getText().toString();
  84.         int tricepInt = Integer.parseInt(tricepString);
  85.         String subscapularString = subscapular.getText().toString();
  86.         int subscapularInt = Integer.parseInt(subscapularString);
  87.         String abdominalString = abdominal.getText().toString();
  88.         int abdominalInt = Integer.parseInt(abdominalString);
  89.         String suprailiacString = suprailiac.getText().toString();
  90.         int suprailiacInt = Integer.parseInt(suprailiacString);
  91.         String thighString = thigh.getText().toString();
  92.         int thighInt = Integer.parseInt(thighString);
  93.         String ageString = age.getText().toString();
  94.         ageInt = Integer.parseInt(ageString);
  95.         sum = chestInt + axillaInt + tricepInt + subscapularInt + abdominalInt + suprailiacInt + thighInt;
  96.         square = sum*sum;
  97.     }
  98.    
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement