This commit is contained in:
ScorpioMiku
2018-10-06 21:44:44 +08:00
parent 1817d66cc5
commit 4d979725cb
22 changed files with 9480 additions and 68 deletions

View File

@@ -0,0 +1,35 @@
package com.example.ninefourone.nutritionmaster.adapter;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.ninefourone.nutritionmaster.R;
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Created by ScorpioMiku on 2018/10/6.
*/
public class DishHolder extends RecyclerView.ViewHolder {
@BindView(R.id.image)
ImageView image;
@BindView(R.id.name)
TextView name;
@BindView(R.id.describle)
TextView describle;
public DishHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
public void bindView(ClassifyResult classifyResult) {
// Glide.with();
}
}

View File

@@ -11,6 +11,7 @@ import com.example.ninefourone.nutritionmaster.R;
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
import com.example.ninefourone.nutritionmaster.modules.classifyresult.DishResultActivity;
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
import com.orhanobut.logger.Logger;
import java.util.ArrayList;
@@ -27,9 +28,9 @@ public class ResultListAdapter extends RecyclerView.Adapter<ResultListHolder> {
public ResultListAdapter(ArrayList<ClassifyResult> list, Context context) {
super();
mList = list;
this.context = context;
mList = CalculateUtils.getDishQuantity(mList, NutritionMaster.user);
Logger.d(NutritionMaster.user);
mList = CalculateUtils.getDishQuantity(list, NutritionMaster.user);
}
@Override

View File

@@ -15,6 +15,7 @@ import com.example.ninefourone.nutritionmaster.modules.classifyresult.DishResult
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
import com.github.siyamed.shapeimageview.CircularImageView;
import com.orhanobut.logger.Logger;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -42,7 +43,8 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
}
public void bindView(ClassifyResult classifyResult, PickerLayoutManager pickerLayoutManager,
final DishResultActivity dishResultActivity,final int position) {
final DishResultActivity dishResultActivity, final int position) {
int index = (int) classifyResult.getQuantity() / 2 - 2;
pickerLayoutManager.setChangeAlpha(true);
pickerLayoutManager.setScaleDownBy(0.99f);
pickerLayoutManager.setScaleDownDistance(0.8f);
@@ -52,7 +54,7 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
pickerAdapter = new PickerAdapter(ConstantUtils.dishPicerData, context);
picker.setAdapter(pickerAdapter);
picker.setNestedScrollingEnabled(false);
picker.scrollToPosition(48);
picker.scrollToPosition(index);
picker.smoothScrollBy(10, 0);
pickerLayoutManager.setOnScrollStopListener(new PickerLayoutManager.onScrollStopListener() {
@@ -60,7 +62,7 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
public void selectedView(View view) {
String text = ((TextView) view).getText().toString();
// MessageUtils.MakeToast(text);
dishResultActivity.refreshData(Integer.valueOf(text),position);
dishResultActivity.refreshData(Integer.valueOf(text), position);
}
});

View File

@@ -24,24 +24,62 @@ public class ClassifyResult implements Serializable {
private Boolean has_calorie = false;
private double quantity = -1;
private FoodMenu foodMenu;
private FoodMaterial foodMaterial;
private int flag = -1;
public static int MATERIAL = 0;
public static int DISH = 1;
public ClassifyResult(int flag) {
this.flag = flag;
}
public void getMenu() {
WebUtil webUtil = WebUtil.getInstance();
webUtil.getMenu("素红烧肉", new Callback() {
@Override
public void onFailure(Call call, IOException e) {
name = "-1";
Logger.e("我们数据库没有这个菜");
}
if (flag == DISH) {
WebUtil webUtil = WebUtil.getInstance();
webUtil.getMenu(name, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
name = "-1";
Logger.e("我们数据库没有这个菜");
}
@Override
public void onResponse(Call call, Response response) throws IOException {
FoodMenu menu = new Gson().fromJson(response.body().string(), FoodMenu.class);
foodMenu = menu;
Logger.d(name + "|" + menu);
}
});
@Override
public void onResponse(Call call, Response response) throws IOException {
FoodMenu menu = new Gson().fromJson(response.body().string(), FoodMenu.class);
foodMenu = menu;
Logger.d(name + "|" + menu);
}
});
} else {
Logger.e("flag 为材料的");
}
}
public void getMaterial() {
if (flag == MATERIAL) {
WebUtil webUtil = WebUtil.getInstance();
webUtil.getFoodMaterial(name, 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();
FoodMaterial material = new Gson().fromJson(json, FoodMaterial.class);
foodMaterial = material;
Logger.d(name + "|" + foodMaterial);
}
});
} else {
Logger.e("flag 为菜谱的");
}
}
public FoodMaterial getFoodMaterial() {
return foodMaterial;
}
public FoodMenu getFoodMenu() {
@@ -82,6 +120,11 @@ public class ClassifyResult implements Serializable {
public void setName(String name) {
this.name = name;
if (flag == MATERIAL) {
getMaterial();
} else {
getMenu();
}
}
public double getCalorie() {

View File

@@ -1,8 +1,9 @@
package com.example.ninefourone.nutritionmaster.bean;
import java.io.Serializable;
import java.util.List;
public class FoodMaterial {
public class FoodMaterial implements Serializable {
/**
* material_name : 西红柿
@@ -47,7 +48,7 @@ public class FoodMaterial {
'}';
}
public static class ElementsBean {
public static class ElementsBean implements Serializable {
/**
* id : 1162
* calorie : 20
@@ -345,13 +346,12 @@ public class FoodMaterial {
}
}
public static class CookQuantityBean {
public static class CookQuantityBean implements Serializable{
/**
* menu : 西红柿鸡蛋汤
* quantity : 适量
* material : 西红柿
*/
private String menu;
private String quantity;
private String material;

View File

@@ -114,7 +114,7 @@ public class FoodMenu implements Serializable {
this.menuclassification_set = menuclassification_set;
}
public static class ElementsBean {
public static class ElementsBean implements Serializable{
/**
* id : 3940
* calorie : 183
@@ -412,7 +412,7 @@ public class FoodMenu implements Serializable {
}
}
public static class CookQuantityBean {
public static class CookQuantityBean implements Serializable{
/**
* menu : 五香酥鱼
* quantity : 500

View File

@@ -46,7 +46,7 @@ public class MyUser {
private Integer age;
private Integer height;
private Integer weight;
private Integer bmi;
private Integer bmi = new Integer(-1);
private String occupation_name;
private List<?> groups;
private List<?> user_permissions;

View File

@@ -190,7 +190,7 @@ public class ClassifierCamera extends AppCompatActivity {
result = WebUtil.HttpPost(ConstantUtils.BD_DISH_URL,
ConstantUtils.BD_ACCESS_TOKEN, param);
JSONObject jsonObject = new JSONObject(result);
ClassifyResult classifyResult = new ClassifyResult();
ClassifyResult classifyResult = new ClassifyResult(ClassifyResult.DISH);
JSONArray resultObject = jsonObject.getJSONArray("result");
jsonObject = resultObject.getJSONObject(0);
classifyResult.setCalorie(jsonObject.getInt("calorie"));
@@ -324,7 +324,7 @@ public class ClassifierCamera extends AppCompatActivity {
String result = "";
result = translate.getTranslations().get(0);
// Logger.d(result);
ClassifyResult classifyResult = new ClassifyResult();
ClassifyResult classifyResult = new ClassifyResult(ClassifyResult.MATERIAL);
classifyResult.setName(result);
resultList.add(classifyResult);
refreshUI();

View File

@@ -121,6 +121,8 @@ public class MainActivity extends BaseActivity {
RecyclerView illRecyclerView;
@BindView(R.id.ill_button)
LinearLayout illButton;
@BindView(R.id.change_information)
TextView changeInformation;
private OptionsPickerView illPicker;
@@ -360,6 +362,7 @@ public class MainActivity extends BaseActivity {
private void initInforView() {
adderInfor.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
changeInformation.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
if (NutritionMaster.user.getHeight() != 0) {
showInformation.setVisibility(View.VISIBLE);
adderInfor.setVisibility(View.INVISIBLE);
@@ -392,7 +395,7 @@ public class MainActivity extends BaseActivity {
*/
@OnClick({R.id.navigation_layout, R.id.add_information_button, R.id.information_layout,
R.id.user_occupation_text, R.id.adder_infor})
R.id.user_occupation_text, R.id.adder_infor,R.id.change_information})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.navigation_layout:
@@ -410,6 +413,10 @@ public class MainActivity extends BaseActivity {
Intent i = new Intent(MainActivity.this, AddInformationActivity.class);
startActivity(i);
break;
case R.id.change_information:
Intent i2 = new Intent(MainActivity.this, AddInformationActivity.class);
startActivity(i2);
break;
}
}
@@ -542,4 +549,6 @@ public class MainActivity extends BaseActivity {
illPicker.setPicker(illness);
illPicker.show();
}
}

View File

@@ -158,6 +158,8 @@ 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));
upUser();
MessageUtils.MakeToast("信息填写成功");
finish();

View File

@@ -208,7 +208,7 @@ public class AddPhysiqueActivity extends BaseActivity {
*/
private void getResult() {
float margin = 0.75f;
float margin = 0.6f;
String code = result.substring(1);
char[] codes = code.toCharArray();
@@ -230,9 +230,9 @@ public class AddPhysiqueActivity extends BaseActivity {
counter[3] += margin;
break;
case 3:
counter[6]++;
counter[7]++;
counter[6] += margin;
counter[3] += margin;
break;
default:
@@ -244,23 +244,22 @@ public class AddPhysiqueActivity extends BaseActivity {
counter[2] += margin;
counter[3] += margin;
counter[6] += margin;
break;
case 2:
counter[4]++;
counter[2] += margin;
counter[3] += margin;
counter[6] += margin;
break;
case 3:
counter[1]++;
counter[5]++;
counter[7]++;
counter[6]++;
counter[2] += margin;
counter[3] += margin;
counter[6] += margin;
break;
}
switch ((int) (codes[2]) - 48) {
@@ -294,7 +293,6 @@ public class AddPhysiqueActivity extends BaseActivity {
switch ((int) (codes[3]) - 48) {
case 1:
counter[0]++;
counter[2]++;
counter[5]++;
counter[6]++;
@@ -356,6 +354,7 @@ public class AddPhysiqueActivity extends BaseActivity {
case 2:
counter[1]++;
counter[1]++;
counter[1]++;
counter[0] += margin;
counter[3] += margin;

View File

@@ -56,7 +56,7 @@ public class DishResultActivity extends BaseActivity {
// for (int i = 0; i < results.size(); i++) {
// Logger.d(results.get(i));
// }
results = ConstantUtils.testData;
// results = ConstantUtils.testData;
resultListAdapter = new ResultListAdapter(results, this);
recyclerView.setAdapter(resultListAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
@@ -87,14 +87,14 @@ public class DishResultActivity extends BaseActivity {
results.set(positon, temp);
for (int i = 0; i < results.size(); i++) {
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
fatSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
fatSum += results.get(i).getFoodMenu().getElements().getFat() * results.get(i).getQuantity() / 100;
sugarSum += results.get(i).getFoodMenu().getElements().getCarbohydrate() * results.get(i).getQuantity() / 100;
proteinSum += results.get(i).getFoodMenu().getElements().getProtein() * results.get(i).getQuantity() / 100;
}
calorie.setText((int)calorieSum + "");
protein.setText((int)proteinSum + "");
fat.setText((int)fatSum + "");
suger.setText((int)sugarSum + "");
calorie.setText((int) calorieSum + "");
protein.setText((int) proteinSum + "");
fat.setText((int) fatSum + "");
suger.setText((int) sugarSum + "");
}
}

View File

@@ -14,6 +14,7 @@ import android.view.View;
import android.view.ViewGroup;
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.utils.ChartDrawer;
@@ -45,6 +46,10 @@ public class BodyInformationFragment extends BaseFragment {
LineChart weightLineChart;
@BindView(R.id.step_line_chart)
LineChart stepLineChart;
@BindView(R.id.calorie_text)
TextView calorieText;
@BindView(R.id.weight_text)
TextView weightText;
private int stepCount = 0;
private static final int REFRESH_STEP_WHAT = 0;
@@ -180,4 +185,20 @@ public class BodyInformationFragment extends BaseFragment {
super.onDestroy();
getActivity().unbindService(coon);
}
/**
* 更新数据
*/
private void refreshUI() {
if (NutritionMaster.user.getBmi() != -1) {
weightText.setText(NutritionMaster.user.getWeight());
}
// waveLoadingView.setProgressValue();
}
@Override
public void onResume() {
super.onResume();
refreshUI();
}
}

View File

@@ -78,6 +78,7 @@ public class CalculateUtils {
/**
* 性别转数字
*
* @param sex
* @return
*/
@@ -104,14 +105,27 @@ public class CalculateUtils {
ArrayList<ClassifyResult> classifyResultArrayList, MyUser user) {
double calorieSum = 0;
double[] calories = new double[classifyResultArrayList.size()];
double[] quantitys = new double[classifyResultArrayList.size()];
float baseQuantity = 600f;
float factor = 1;
if (user.getBmi().intValue() == -1) {
MessageUtils.MakeToast("检测到未填写个人信息,按成人标准进行计算");
} else {
if (user.getAge() <= 60) {
factor = 1 - (Math.abs(user.getAge() - 30)) / 30.0f;
} else {
factor = 1 - (Math.abs(user.getAge() - 30)) / 70.0f;
}
factor = factor * (user.getBmi().intValue() / 21.0f) - (factor - 1.0f) / 5;
Logger.d(factor);
}
for (int i = 0; i < classifyResultArrayList.size(); i++) {
calorieSum += classifyResultArrayList.get(i).getCalorie();
calories[i] = classifyResultArrayList.get(i).getCalorie();
}
for (int i = 0; i < classifyResultArrayList.size(); i++) {
classifyResultArrayList.get(i).setQuantity(calories[i] / calorieSum * baseQuantity);
classifyResultArrayList.get(i).setQuantity(calories[i] / calorieSum * baseQuantity * factor);
}
return classifyResultArrayList;
}

View File

@@ -279,22 +279,22 @@ public class ConstantUtils {
public static String BD_DISH_URL = "https://aip.baidubce.com/rest/2.0/image-classify/v2/dish";
public static ArrayList<ClassifyResult> testData = new ArrayList<>();
static {
for (int i = 0; i < 7; i++) {
ClassifyResult classifyResult = new ClassifyResult();
classifyResult.setName("酱肉丝" + i);
classifyResult.setProbability(0.5 + i);
classifyResult.setCalorie(274 + i * 10);
testData.add(classifyResult);
}
}
// public static ArrayList<ClassifyResult> testData = new ArrayList<>();
//
// static {
// for (int i = 0; i < 7; i++) {
// ClassifyResult classifyResult = new ClassifyResult();
// classifyResult.setName("酱肉丝" + i);
// classifyResult.setProbability(0.5 + i);
// classifyResult.setCalorie(274 + i * 10);
// testData.add(classifyResult);
// }
// }
public static ArrayList<String> dishPicerData = new ArrayList<>();
static {
for (int i = 0; i <= 700; i++) {
for (int i = 0; i <= 1000; i++) {
if (i % 2 == 0) {
dishPicerData.add(i + "");
}

View File

@@ -18,6 +18,43 @@
android:textColor="#fff"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="食物名"
android:textColor="#fff" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_weight="0.01"
android:background="#fff"
android:gravity="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="预估食用量(克)"
android:textColor="#fff" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
@@ -74,7 +111,6 @@
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:layout_toLeftOf="@+id/calorie_tag"
android:text="大卡"
android:textColor="#fff" />
</RelativeLayout>
@@ -107,7 +143,6 @@
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:layout_toLeftOf="@+id/sugar_tag"
android:text="大卡"
android:textColor="#fff" />
</RelativeLayout>
@@ -158,7 +193,6 @@
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:layout_toLeftOf="@+id/fat_tag"
android:text="大卡"
android:textColor="#fff" />
</RelativeLayout>
@@ -191,7 +225,6 @@
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:layout_toLeftOf="@+id/protein_tag"
android:text="大卡"
android:textColor="#fff" />
</RelativeLayout>

View File

@@ -201,8 +201,7 @@
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="25dp"
>
android:layout_marginRight="25dp">
</android.support.v7.widget.RecyclerView>
@@ -581,6 +580,13 @@
</RelativeLayout>
<TextView
android:id="@+id/change_information"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="修改信息" />
</LinearLayout>
</RelativeLayout>
</ScrollView>

View File

@@ -1,9 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#f4f4f4"
tools:context="com.example.ninefourone.nutritionmaster.modules.classifyresult.MaterialResultActivity">
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>

View File

@@ -77,10 +77,10 @@
android:orientation="horizontal">
<TextView
android:id="@+id/calorie_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="1804"
android:textSize="20sp"
android:textStyle="bold" />
@@ -185,10 +185,10 @@
android:orientation="horizontal">
<TextView
android:id="@+id/weight_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="1804"
android:textSize="20sp"
android:textStyle="bold" />

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_margin="5dp"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/image"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_margin="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:textSize="16sp"
tools:text="红烧肉" />
<TextView
android:id="@+id/describle"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:text="红烧肉" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@@ -5,12 +5,13 @@
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_margin="5dp"
android:alpha="0.9"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:background="#bde2b7"
android:gravity="center_vertical"
android:orientation="horizontal">

9194
datas/new_menu_names.csv Normal file

File diff suppressed because it is too large Load Diff