package com.example.chipsea.demo235_android;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import com.example.chipsea.demo235_android.R;
import chipsea.bias.v235.CSBiasAPI;


/*
测试数据
身高， 体重，阻抗，性别， 年龄
{170,    500,      4080,         1,        30},
{170,    1000,    4280,    1,    30},
{170,    1500,    4480,    1,    30},
{170,    500,    4080,    0,    30},
{170,    1000,    4280,    0,    30},
{170,    1500,    4480,    0,    30},
{170,    509,    4547,    1,    28},
{164,    790,    3797,    1,    28},
{174,    669,    4221,    1,    24},
{158,    603,    4388,    0,    21},
{163,    474,    4759,    0,    22},
{160,    553,    4549,    1,    26},
*/
/*
测试结果
BFP		SLM		BWP		BMC		VFR		PP		SMM		BMR		BMI		SBW		MC		WC		FC		age	score
5.0		45.3	62.9	2.2		1.0		27.7	26.0	1324	17.3	62.3	4.2		12.3	8.1		15	60
33.0	64.8	50.2	2.3		20.5	14.5	34.8	1981	34.6	62.3	- 15.3	- 37.7	- 22.4	56	50
42.7	84.2	46.0	1.7		41.5	10.1	43.5	2639	51.9	62.3	- 34.2	- 87.7	- 53.5	80	50
15.3	40.4	55.6	1.9		1.0		25.3	23.6	1239	17.3	60.4	3.0		10.4	7.4		15	66
45.0	51.0	42.6	4.0		13.5	8.4		32.3	1737	34.6	60.4	- 9.7	- 39.6	- 29.9	80	49
45.0	78.5	38.3	4.0		26.5	14.0	41.1	2235	51.9	60.4	- 37.2	- 89.5	- 52.4	80	50
6.1		44.7	61.4	3.1		1		26.5	24.9	1318	17.6	62.3	3.9		11.4	7.5		15	63
27		55.7	53.5	1.9		12		17.1	30.7	1692	29.4	58		- 9.5	- 21	- 11.5	37	56
16.6	53.1	57		2.7		5		22.4	29.9	1598	22.1	65.3	- 1.6	- 1.6	0		21	86
32.4	38.2	48.8	2.6		4.5		14.5	21.7	1269	24.2	52.2	- 1.6	- 8.1	- 6.5	33	68
18.4	36.3	54		2.3		1		22.6	19.5	1153	17.8	55.6	3		8.2		5.2		15	70
*/
public class MainActivity extends AppCompatActivity {

    private EditText txtHeight, txtAge, txtWeight, txtR;
    private RadioButton radioMale;
    private TextView txtTest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txtHeight = (EditText) findViewById(R.id.txtHeight);
        txtAge = (EditText) findViewById(R.id.txtAge);
        txtWeight = (EditText) findViewById(R.id.txtWeight);
        txtR = (EditText) findViewById(R.id.txtR);
        radioMale = (RadioButton) findViewById(R.id.radioMale);
        txtTest=findViewById(R.id.txtTest);

    }


    public void newClick(View view) {
        float height = Float.parseFloat(txtHeight.getText().toString());
        int age = Integer.parseInt(txtAge.getText().toString());
        float weight = Float.parseFloat(txtWeight.getText().toString());
        float r = Float.parseFloat(txtR.getText().toString());
        byte sex = 0;
        if (radioMale.isChecked()) {
            sex = 1;
        }

        CSBiasAPI.CSBiasV235Resp cSBiasV235Resp = CSBiasAPI.cs_bias_v235(0, sex, age,
                (int) height, (int) (weight*10), (int) (r*10), 2018);

        StringBuilder sb = new StringBuilder();

        if (cSBiasV235Resp.result == CSBiasAPI.CSBIAS_OK) {
            //计算
            try {
                sb.append("输入\r\n");
                sb.append("性别:" + sex + " 身高:" + height + " 年龄:" + age + " 电阻:" + r + " 体重:" + weight + "\r\n");
                sb.append("**************************************\r\n");
                sb.append("**************************************\r\n");
                sb.append("脂肪率%:" + cSBiasV235Resp.data.BFP + "\r\n");
                sb.append("肌肉重kg:" + cSBiasV235Resp.data.SLM + "\r\n");
                sb.append("水含量%:" + cSBiasV235Resp.data.BWP  + "\r\n");
                sb.append("骨盐量:" + cSBiasV235Resp.data.BMC + "\r\n");
                sb.append("内脏脂肪等级:" + cSBiasV235Resp.data.VFR + "\r\n");
                sb.append("蛋白质%:" + cSBiasV235Resp.data.PP+ "\r\n");
                sb.append("骨骼肌kg:" + cSBiasV235Resp.data.SMM+ "\r\n");
                sb.append("基础代谢:" + cSBiasV235Resp.data.BMR + "\r\n");
                sb.append("身体质量指数:" + cSBiasV235Resp.data.BMI + "\r\n");
                sb.append("标准体重kg:" + cSBiasV235Resp.data.SBW + "\r\n");
                sb.append("肌肉控制:" + cSBiasV235Resp.data.MC + "\r\n");
                sb.append("体重控制:" + cSBiasV235Resp.data.WC + "\r\n");
                sb.append("脂肪控制:" + cSBiasV235Resp.data.FC + "\r\n");
                sb.append("身体年龄:" + cSBiasV235Resp.data.MA + "\r\n");
                sb.append("评分:" + cSBiasV235Resp.data.SBC + "\r\n");


//            sb.append("脂肪重:" + builderEx.getFM()  +"\r\n");
//            sb.append("瘦体重kg:" + builderEx.getLBM()  + "\r\n");
//            sb.append("水重kg:" + builderEx.getTF() + "\r\n");
//            sb.append("肥胖度:" + builderEx.getOD() + "\r\n");
                sb.append("**************************************\r\n");

//           sb.append("反查电阻:" + CsAlgoBuilderEx.getResistance(100f,(byte)0,38.0f,18,20.2f));
            } catch (Exception ex) {
                sb.append("输入错误，错误码：" + ex.getLocalizedMessage());
            }
        } else {
            sb.append("输入错误，错误码：" + cSBiasV235Resp.result);
        }
        txtTest.setText(sb.toString());
    }
}
