1
This commit is contained in:
@@ -4,10 +4,12 @@ import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.MyUser;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.bean.Occupation;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Physique;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
@@ -39,7 +41,10 @@ public class NutritionMaster extends Application {
|
||||
public static NutritionMaster mInstance;
|
||||
private int appCount = 0;
|
||||
|
||||
public static MyUser user;
|
||||
public static MyUser user =null;
|
||||
public static Physique physique = null;
|
||||
public static Occupation occupation = null;
|
||||
public static Element element = null;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@@ -203,19 +208,7 @@ public class NutritionMaster extends Application {
|
||||
*/
|
||||
private void initYouDao() {
|
||||
YouDaoApplication.init(this, ConstantUtils.YOUDAO_APPKEY);
|
||||
// WebUtil webUtil = WebUtil.getInstance();
|
||||
// webUtil.getMenu("雪丽对虾", new Callback() {
|
||||
// @Override
|
||||
// public void onFailure(Call call, IOException e) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onResponse(Call call, Response response) throws IOException {
|
||||
// FoodMenu menu = new Gson().fromJson(response.body().string(), FoodMenu.class);
|
||||
// Logger.d(menu);
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.bean.MyUser;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.orhanobut.logger.Logger;
|
||||
@@ -99,6 +100,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
protected void upUser() {
|
||||
NutritionMaster.user = user;
|
||||
NutritionMaster.element = new Element(user);
|
||||
Logger.d("用户信息已改" + NutritionMaster.user.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,342 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/7.
|
||||
*/
|
||||
|
||||
public class Element {
|
||||
public class Element implements Cloneable {
|
||||
|
||||
private double calorie;
|
||||
private float carbohydrate;
|
||||
private float fat;
|
||||
private float protein;
|
||||
private float cellulose;
|
||||
private float vitaminA;
|
||||
private float vitaminB1;
|
||||
private float vitaminB2;
|
||||
private float vitaminB6;
|
||||
private float vitaminC;
|
||||
private float vitaminE;
|
||||
private float carotene;
|
||||
private float cholesterol;
|
||||
private float Mg;
|
||||
private float Ca;
|
||||
private float Fe;
|
||||
private float Zn;
|
||||
private float Cu;
|
||||
private float Mn;
|
||||
private float K;
|
||||
private float P;
|
||||
private float Na;
|
||||
private float Se;
|
||||
private float niacin;
|
||||
private float thiamine;
|
||||
|
||||
|
||||
public Element calculateData(MyUser user) throws CloneNotSupportedException {
|
||||
double calorie = 655 + 9.6 * user.getWeight() + 1.9 * user.getHeight() - 4.7 * user.getAge();
|
||||
Element temp = (Element) this.clone();
|
||||
temp.setCalorie(calorie * this.calorie);
|
||||
temp.setCarbohydrate(user.getWeight() * this.carbohydrate);
|
||||
temp.setFat(user.getWeight() * this.fat);
|
||||
temp.setProtein(user.getWeight() * this.protein);
|
||||
return temp;
|
||||
}
|
||||
|
||||
public Element(MyUser user) {
|
||||
if (user.getSex() == 0) {
|
||||
calorie = 0f;
|
||||
carbohydrate = 7.5f;
|
||||
fat = 1.2f;
|
||||
protein = 1f;
|
||||
cellulose = 25f;
|
||||
vitaminA = 700f;
|
||||
vitaminB1 = 1200f;
|
||||
vitaminB2 = 1200f;
|
||||
vitaminB6 = 1400f;
|
||||
vitaminC = 100f;
|
||||
vitaminE = 14f;
|
||||
carotene = 3600f;
|
||||
cholesterol = 200f;
|
||||
Mg = 315f;
|
||||
Ca = 1200f;
|
||||
Fe = 15f;
|
||||
Zn = 12f;
|
||||
Cu = 2.3f;
|
||||
Mn = 3.5f;
|
||||
K = 2000f;
|
||||
P = 1000f;
|
||||
Na = 1500f;
|
||||
Se = 0.05f;
|
||||
niacin = 0f;
|
||||
thiamine = 0f;
|
||||
} else {
|
||||
calorie = 0f;
|
||||
carbohydrate = 7.5f;
|
||||
fat = 1.2f;
|
||||
protein = 1f;
|
||||
cellulose = 25f;
|
||||
vitaminA = 800f;
|
||||
vitaminB1 = 1400f;
|
||||
vitaminB2 = 1400f;
|
||||
vitaminB6 = 2000f;
|
||||
vitaminC = 100f;
|
||||
vitaminE = 14f;
|
||||
carotene = 3400f;
|
||||
cholesterol = 200f;
|
||||
Mg = 360f;
|
||||
Ca = 1200f;
|
||||
Fe = 10f;
|
||||
Zn = 15f;
|
||||
Cu = 2.3f;
|
||||
Mn = 3.5f;
|
||||
K = 2000f;
|
||||
P = 1000f;
|
||||
Na = 1500f;
|
||||
Se = 0.05f;
|
||||
niacin = 0f;
|
||||
thiamine = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public Element(Physique.ElementsBean elementsBean) {
|
||||
calorie = elementsBean.getCalorie();
|
||||
carbohydrate = elementsBean.getCarbohydrate();
|
||||
fat = elementsBean.getFat();
|
||||
protein = elementsBean.getProtein();
|
||||
cellulose = elementsBean.getCellulose();
|
||||
vitaminA = elementsBean.getVitaminA();
|
||||
vitaminB1 = elementsBean.getVitaminB1();
|
||||
vitaminB2 = elementsBean.getVitaminB2();
|
||||
vitaminB6 = elementsBean.getVitaminB6();
|
||||
vitaminC = elementsBean.getVitaminC();
|
||||
vitaminE = elementsBean.getVitaminE();
|
||||
carotene = elementsBean.getCarotene();
|
||||
cholesterol = elementsBean.getCholesterol();
|
||||
Mg = elementsBean.getMg();
|
||||
Ca = elementsBean.getCa();
|
||||
Fe = elementsBean.getFe();
|
||||
Zn = elementsBean.getZn();
|
||||
Cu = elementsBean.getCu();
|
||||
Mn = elementsBean.getMn();
|
||||
K = elementsBean.getK();
|
||||
P = elementsBean.getP();
|
||||
Na = elementsBean.getNa();
|
||||
Se = elementsBean.getSe();
|
||||
niacin = elementsBean.getNiacin();
|
||||
thiamine = elementsBean.getThiamine();
|
||||
}
|
||||
|
||||
public Element(Occupation.ElementsBean elementsBean) {
|
||||
calorie = elementsBean.getCalorie();
|
||||
carbohydrate = elementsBean.getCarbohydrate();
|
||||
fat = elementsBean.getFat();
|
||||
protein = elementsBean.getProtein();
|
||||
cellulose = elementsBean.getCellulose();
|
||||
vitaminA = elementsBean.getVitaminA();
|
||||
vitaminB1 = elementsBean.getVitaminB1();
|
||||
vitaminB2 = elementsBean.getVitaminB2();
|
||||
vitaminB6 = elementsBean.getVitaminB6();
|
||||
vitaminC = elementsBean.getVitaminC();
|
||||
vitaminE = elementsBean.getVitaminE();
|
||||
carotene = elementsBean.getCarotene();
|
||||
cholesterol = elementsBean.getCholesterol();
|
||||
Mg = elementsBean.getMg();
|
||||
Ca = elementsBean.getCa();
|
||||
Fe = elementsBean.getFe();
|
||||
Zn = elementsBean.getZn();
|
||||
Cu = elementsBean.getCu();
|
||||
Mn = elementsBean.getMn();
|
||||
K = elementsBean.getK();
|
||||
P = elementsBean.getP();
|
||||
Na = elementsBean.getNa();
|
||||
Se = elementsBean.getSe();
|
||||
niacin = elementsBean.getNiacin();
|
||||
thiamine = elementsBean.getThiamine();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ElementsBean{" +
|
||||
", calorie=" + calorie +
|
||||
", carbohydrate=" + carbohydrate +
|
||||
", fat=" + fat +
|
||||
", protein=" + protein +
|
||||
", cellulose=" + cellulose +
|
||||
", vitaminA=" + vitaminA +
|
||||
", vitaminB1=" + vitaminB1 +
|
||||
", vitaminB2=" + vitaminB2 +
|
||||
", vitaminB6=" + vitaminB6 +
|
||||
", vitaminC=" + vitaminC +
|
||||
", vitaminE=" + vitaminE +
|
||||
", carotene=" + carotene +
|
||||
", cholesterol=" + cholesterol +
|
||||
", Mg=" + Mg +
|
||||
", Ca=" + Ca +
|
||||
", Fe=" + Fe +
|
||||
", Zn=" + Zn +
|
||||
", Cu=" + Cu +
|
||||
", Mn=" + Mn +
|
||||
", K=" + K +
|
||||
", P=" + P +
|
||||
", Na=" + Na +
|
||||
", Se=" + Se +
|
||||
", niacin=" + niacin +
|
||||
", thiamine=" + thiamine +
|
||||
'}';
|
||||
}
|
||||
|
||||
public void add(Element elementsBean, float factor) {
|
||||
float divisor;
|
||||
if (factor == -1) {
|
||||
divisor = 1;
|
||||
factor = 1;
|
||||
} else {
|
||||
divisor = factor + 1.0f;
|
||||
}
|
||||
this.calorie = (factor * elementsBean.getCalorie() + this.calorie) / divisor;
|
||||
this.carbohydrate = (factor * elementsBean.getCarbohydrate() + this.carbohydrate) / divisor;
|
||||
this.fat = (factor * elementsBean.getFat() + this.fat) / divisor;
|
||||
this.protein = (factor * elementsBean.getProtein() + this.protein) / divisor;
|
||||
this.cellulose = (factor * elementsBean.getCellulose() + this.cellulose) / divisor;
|
||||
this.vitaminA = (factor * elementsBean.getVitaminA() + this.vitaminA) / divisor;
|
||||
this.vitaminB1 = (factor * elementsBean.getVitaminB1() + this.vitaminB1) / divisor;
|
||||
this.vitaminB2 = (factor * elementsBean.getVitaminB2() + this.vitaminB2) / divisor;
|
||||
this.vitaminB6 = (factor * elementsBean.getVitaminB6() + this.vitaminB6) / divisor;
|
||||
this.vitaminC = (factor * elementsBean.getVitaminC() + this.vitaminC) / divisor;
|
||||
this.vitaminE = (factor * elementsBean.getVitaminE() + this.vitaminE) / divisor;
|
||||
this.carotene = (factor * elementsBean.getCarotene() + this.carotene) / divisor;
|
||||
this.cholesterol = (factor * elementsBean.getMg() + this.Mg) / divisor;
|
||||
this.Mg = (factor * elementsBean.getCarbohydrate() + this.carbohydrate) / divisor;
|
||||
this.Ca = (factor * elementsBean.getCa() + this.Ca) / divisor;
|
||||
this.Fe = (factor * elementsBean.getFe() + this.Fe) / divisor;
|
||||
this.Zn = (factor * elementsBean.getZn() + this.Zn) / divisor;
|
||||
this.Cu = (factor * elementsBean.getCu() + this.Cu) / divisor;
|
||||
this.Mn = (factor * elementsBean.getMn() + this.Mn) / divisor;
|
||||
this.K = (factor * elementsBean.getK() + this.K) / divisor;
|
||||
this.P = (factor * elementsBean.getP() + this.P) / divisor;
|
||||
this.Na = (factor * elementsBean.getNa() + this.Na) / divisor;
|
||||
this.Se = (factor * elementsBean.getSe() + this.Se) / divisor;
|
||||
this.niacin = (factor * elementsBean.getNiacin() + this.niacin) / divisor;
|
||||
this.thiamine = (factor * elementsBean.getThiamine() + this.thiamine) / divisor;
|
||||
}
|
||||
|
||||
public double getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public float getCarbohydrate() {
|
||||
return carbohydrate;
|
||||
}
|
||||
|
||||
public float getFat() {
|
||||
return fat;
|
||||
}
|
||||
|
||||
public float getProtein() {
|
||||
return protein;
|
||||
}
|
||||
|
||||
public float getCellulose() {
|
||||
return cellulose;
|
||||
}
|
||||
|
||||
public float getVitaminA() {
|
||||
return vitaminA;
|
||||
}
|
||||
|
||||
public float getVitaminB1() {
|
||||
return vitaminB1;
|
||||
}
|
||||
|
||||
public float getVitaminB2() {
|
||||
return vitaminB2;
|
||||
}
|
||||
|
||||
public float getVitaminB6() {
|
||||
return vitaminB6;
|
||||
}
|
||||
|
||||
public float getVitaminC() {
|
||||
return vitaminC;
|
||||
}
|
||||
|
||||
public float getVitaminE() {
|
||||
return vitaminE;
|
||||
}
|
||||
|
||||
public float getCarotene() {
|
||||
return carotene;
|
||||
}
|
||||
|
||||
public float getCholesterol() {
|
||||
return cholesterol;
|
||||
}
|
||||
|
||||
public float getMg() {
|
||||
return Mg;
|
||||
}
|
||||
|
||||
public float getCa() {
|
||||
return Ca;
|
||||
}
|
||||
|
||||
public float getFe() {
|
||||
return Fe;
|
||||
}
|
||||
|
||||
public float getZn() {
|
||||
return Zn;
|
||||
}
|
||||
|
||||
public float getCu() {
|
||||
return Cu;
|
||||
}
|
||||
|
||||
public float getMn() {
|
||||
return Mn;
|
||||
}
|
||||
|
||||
public float getK() {
|
||||
return K;
|
||||
}
|
||||
|
||||
public float getP() {
|
||||
return P;
|
||||
}
|
||||
|
||||
public float getNa() {
|
||||
return Na;
|
||||
}
|
||||
|
||||
public float getSe() {
|
||||
return Se;
|
||||
}
|
||||
|
||||
public float getNiacin() {
|
||||
return niacin;
|
||||
}
|
||||
|
||||
public float getThiamine() {
|
||||
return thiamine;
|
||||
}
|
||||
|
||||
public void setCalorie(double calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public void setCarbohydrate(float carbohydrate) {
|
||||
this.carbohydrate = carbohydrate;
|
||||
}
|
||||
|
||||
public void setFat(float fat) {
|
||||
this.fat = fat;
|
||||
}
|
||||
|
||||
public void setProtein(float protein) {
|
||||
this.protein = protein;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class MyUser {
|
||||
*/
|
||||
|
||||
private Integer id;
|
||||
private EatenElementsBean eaten_elements;
|
||||
private EatenElementsBean eaten_elements = new EatenElementsBean();
|
||||
private String physical_name;
|
||||
private String password;
|
||||
private Object last_login;
|
||||
@@ -85,6 +85,12 @@ public class MyUser {
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
public void changeElement(EatenElementsBean eaten_elements) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -292,7 +298,7 @@ public class MyUser {
|
||||
*/
|
||||
|
||||
private double id;
|
||||
private double calorie;
|
||||
private double calorie = 1;
|
||||
private double carbohydrate;
|
||||
private double fat;
|
||||
private double protein;
|
||||
|
||||
@@ -392,5 +392,7 @@ public class Physique {
|
||||
this.thiamine = thiamine;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,9 +514,9 @@ public class MainActivity extends BaseActivity {
|
||||
weightBar.setSecondaryProgressColor(getColor(R.color.color_bar_self));
|
||||
}
|
||||
|
||||
Logger.d("bmi:" + averageBmi / maxBmi * 100.0f + "|" + bmi / maxBmi * 100.0f + "\n" +
|
||||
"height:" + averageHeight / maxHeight * 100.0f + "|" + height / maxHeight * 100.0f + "\n" +
|
||||
"weight" + averageWeight / maxWeight * 100.0f + "|" + weight / maxWeight * 100.0f);
|
||||
// Logger.d("bmi:" + averageBmi / maxBmi * 100.0f + "|" + bmi / maxBmi * 100.0f + "\n" +
|
||||
// "height:" + averageHeight / maxHeight * 100.0f + "|" + height / maxHeight * 100.0f + "\n" +
|
||||
// "weight" + averageWeight / maxWeight * 100.0f + "|" + weight / maxWeight * 100.0f);
|
||||
|
||||
|
||||
}
|
||||
@@ -545,7 +545,6 @@ public class MainActivity extends BaseActivity {
|
||||
illButton.setBackgroundResource(0);
|
||||
}
|
||||
}).build();
|
||||
MessageUtils.MakeToast("dianjile");
|
||||
illPicker.setPicker(illness);
|
||||
illPicker.show();
|
||||
}
|
||||
|
||||
@@ -14,10 +14,19 @@ import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.MyUser;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Occupation;
|
||||
import com.example.ninefourone.nutritionmaster.modules.MainActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class AddInformationActivity extends BaseActivity {
|
||||
private TextView ageTextView;
|
||||
@@ -70,6 +79,8 @@ public class AddInformationActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
occupationTextView.setText(ConstantUtils.occupationList.get(options1));
|
||||
getOccupation(ConstantUtils.occupationList.get(options1));
|
||||
|
||||
}
|
||||
}).build();
|
||||
occupationPicker.setPicker(ConstantUtils.occupationList);
|
||||
@@ -158,10 +169,18 @@ public class AddInformationActivity extends BaseActivity {
|
||||
user.setAge(Integer.valueOf(ageTextView.getText().toString().split("岁")[0]));
|
||||
user.setSex(CalculateUtils.sex2int(sexTextView.getText().toString()));
|
||||
user.setOccupation_name(occupationTextView.getText().toString());
|
||||
float BMI = CalculateUtils.BMI(user.getHeight().floatValue(),user.getWeight().floatValue());
|
||||
user.setBmi(Integer.valueOf((int)BMI));
|
||||
float BMI = CalculateUtils.BMI(user.getHeight().floatValue(), user.getWeight().floatValue());
|
||||
user.setBmi(Integer.valueOf((int) BMI));
|
||||
upUser();
|
||||
MessageUtils.MakeToast("信息填写成功");
|
||||
if (NutritionMaster.physique == null) {
|
||||
NutritionMaster.element =
|
||||
CalculateUtils.getElementsByOccupation(NutritionMaster.user, NutritionMaster.occupation);
|
||||
} else {
|
||||
NutritionMaster.element =
|
||||
CalculateUtils.getElementsByOccupationAndPhysique(NutritionMaster.user,
|
||||
NutritionMaster.occupation, NutritionMaster.physique);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -179,4 +198,21 @@ public class AddInformationActivity extends BaseActivity {
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
private void getOccupation(String text) {
|
||||
getWebUtil().getOccupation(text, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
Occupation occupation = new Gson().fromJson(json, Occupation.class);
|
||||
NutritionMaster.occupation = occupation;
|
||||
Logger.d(NutritionMaster.occupation);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,20 +14,28 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Physique;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.github.czy1121.view.TurnCardListView;
|
||||
import com.github.siyamed.shapeimageview.CircularImageView;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class AddPhysiqueActivity extends BaseActivity {
|
||||
|
||||
@@ -393,6 +401,31 @@ public class AddPhysiqueActivity extends BaseActivity {
|
||||
upUser();
|
||||
loadInformation(phy);
|
||||
|
||||
/**
|
||||
* 加载体质信息
|
||||
*/
|
||||
getWebUtil().getPhysique(physique, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
Physique physique = new Gson().fromJson(json, Physique.class);
|
||||
NutritionMaster.physique = physique;
|
||||
if (NutritionMaster.occupation == null) {
|
||||
NutritionMaster.element =
|
||||
CalculateUtils.getElementsByPhysique(NutritionMaster.user, NutritionMaster.physique);
|
||||
} else {
|
||||
NutritionMaster.element =
|
||||
CalculateUtils.getElementsByOccupationAndPhysique(NutritionMaster.user,
|
||||
NutritionMaster.occupation, NutritionMaster.physique);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,9 +17,12 @@ import android.widget.TextView;
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseFragment;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ChartDrawer;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.today.step.lib.ISportStepInterface;
|
||||
import com.today.step.lib.TodayStepManager;
|
||||
import com.today.step.lib.TodayStepService;
|
||||
@@ -128,7 +131,7 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
private void updateStepCount() {
|
||||
try {
|
||||
stepTextView.setText(stepCount + "");
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -195,9 +198,26 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
*/
|
||||
private void refreshUI() {
|
||||
if (NutritionMaster.user.getBmi() != -1) {
|
||||
weightText.setText(NutritionMaster.user.getWeight());
|
||||
weightText.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
weightText.setText(NutritionMaster.user.getWeight() + "");
|
||||
}
|
||||
});
|
||||
}
|
||||
// waveLoadingView.setProgressValue();
|
||||
if (NutritionMaster.element != null) {
|
||||
Logger.d(NutritionMaster.element);
|
||||
try {
|
||||
Element elementTemp = NutritionMaster.element.calculateData(NutritionMaster.user);
|
||||
int temp = (int) (elementTemp.getCalorie());
|
||||
calorieText.setText(temp + "");
|
||||
temp = (int) (NutritionMaster.user.getEaten_elements().getCalorie() / temp * 100);
|
||||
waveLoadingView.setProgressValue(temp);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.MyUser;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Occupation;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Physique;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -171,16 +174,40 @@ public class CalculateUtils {
|
||||
public static ArrayList<String> getStepArray(String whole) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
String[] array = whole.split("'");
|
||||
// Logger.d(Arrays.toString(array));
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i].equals("[") || array[i].equals("]") || array[i].equals(", ") ||
|
||||
array[i].equals(",")||array[i].equals(" ")) {
|
||||
array[i].equals(",") || array[i].equals(" ")) {
|
||||
|
||||
} else {
|
||||
list.add(array[i]);
|
||||
}
|
||||
}
|
||||
// Logger.d(Arrays.toString(list.toArray()));
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算元素需求
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Element getElementsByOccupationAndPhysique(MyUser user, Occupation occupation, Physique physique) {
|
||||
Element userElement = new Element(user);
|
||||
Element occupationElement = new Element(occupation.getElements());
|
||||
Element physiqueElement = new Element(physique.getElements());
|
||||
occupationElement.add(physiqueElement, 2);
|
||||
userElement.add(occupationElement, -1);
|
||||
return userElement;
|
||||
}
|
||||
public static Element getElementsByOccupation(MyUser user, Occupation occupation) {
|
||||
Element userElement = new Element(user);
|
||||
Element occupationElement = new Element(occupation.getElements());
|
||||
userElement.add(occupationElement, -1);
|
||||
return userElement;
|
||||
}
|
||||
public static Element getElementsByPhysique(MyUser user, Physique physique) {
|
||||
Element userElement = new Element(user);
|
||||
Element physiqueElement = new Element(physique.getElements());
|
||||
userElement.add(physiqueElement, -1);
|
||||
return userElement;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user