wang
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -163,6 +163,7 @@ fabric.properties
|
||||
### AndroidStudio Patch ###
|
||||
|
||||
!/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
app/src/main/java/.vscode
|
||||
.vscode
|
||||
|
||||
# End of https://www.gitignore.io/api/android,androidstudio
|
||||
190
README.md
190
README.md
@@ -5,30 +5,6 @@
|
||||
|
||||
仓库地址: https://github.com/wangtianrui/NutritionMaster
|
||||
|
||||
### 需求
|
||||
|
||||
* 针对特殊人群,提供饮食,药膳等方案
|
||||
* 查查各种病理对食物的禁忌和需求
|
||||
* 秦楚吉(1667787307) 17:41:35
|
||||
1设置整体活动水平 低:大部分坐姿,中等:大部分站立,高:大部分步行,非常高:身体需要
|
||||
2为每一个推荐菜品提供菜谱
|
||||
3根据目标卡路里-食物卡路里+运动卡路里=剩余卡路里进行每日的卡路里限制
|
||||
4区分了各类食物中蛋白质糖以及脂肪
|
||||
5以日期作为日志进行记录
|
||||
6分别针对增肌、减脂、塑形进行运动训练
|
||||
7好友社区
|
||||
8商城(健身之类)
|
||||
* **写的什么jb玩意啊?**
|
||||
|
||||
| 详细需求分析 | 备注 | 开发进度 |
|
||||
| ------------ | ---- | ---- |
|
||||
| | | |
|
||||
| 为每一个推荐菜品提供菜谱 | | |
|
||||
| | | |
|
||||
| | | |
|
||||
|
||||
|
||||
|
||||
### 数据分析
|
||||
|
||||
* 人体健康信息
|
||||
@@ -141,7 +117,7 @@
|
||||
* user表: 添加综合对物质的需求 √
|
||||
|
||||
* 菜单表:
|
||||
* **添加一列早/午晚餐,早为1,else为0. 根据 饼 粥 羹 面 奶 判断**
|
||||
* 添加一列早/午晚餐,早为1,else为0. 根据 饼 粥 羹 面 奶 判断
|
||||
* 补充一下缺失的url,卡路里 √
|
||||
* 添加几列各种物质的需求 √
|
||||
* 有一部分数据是爬下的csv里面直接读取,一部分缺失的用food_material的组合来计算
|
||||
@@ -164,19 +140,107 @@
|
||||
|
||||
* 用户职业BMI分类 3多动,2中等,1少动 先 `getUser`获取到用户的职业名字.然后`getOccupation`获取到该职业的BMI分类
|
||||
|
||||
* 动态改变用户已吃的营养元素的量: 在用户表添加element参数,每周清空一次,每吃一个菜就记录一下
|
||||
* 动态改变用户已吃的营养元素的量: 在用户表添加element参数,每周自动清空一次
|
||||
|
||||
* 获取用户本周已摄入的营养元素的量: `getUser`得到当前用户的信息,解析后用`MyUser`的`getEaten_elements()`获取到Element对象.里面有各种元素信息
|
||||
* 每吃一个菜就post一下
|
||||
* Map的可选参数: `[calorie,carbohydrate,fat ,protein,cellulose,vitaminA,vitaminB1,vitaminB2,vitaminB6,vitaminC,vitaminE,carotene,cholesterol,Mg,Ca,Fe,Zn,Cu,Mn,K ,P ,Na,Se,niacin ,thiamine]`
|
||||
|
||||

|
||||
```java
|
||||
public static void main(String[] args) {
|
||||
//只传入变动的参数就行.
|
||||
//比如 这顿饭摄入了100卡路里,10脂肪.就这样写.
|
||||
Map<String, Double> params = new HashMap<>();
|
||||
params.put("calorie", 100.0);
|
||||
params.put("fat", 10.0);
|
||||
|
||||
//第一个参数是username,第二个参数是摄入的营养元素值.可以看函数的源码,有注释
|
||||
WebUtil.getInstance().eatenElements("test5", params, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
System.out.println(new Gson().fromJson(response.body().string(), MyUser.class));
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
* **用户的浏览历史: 添加用户和菜谱的多对多关系**
|
||||
* 获取用户本周已摄入的营养元素的量: `getUser`得到当前用户的信息,解析后用`MyUser`的`getEaten_elements()`获取到Element对象.里面有各种元素信息
|
||||
|
||||
* 根据多个食材组合来搜菜
|
||||
|
||||
```java
|
||||
List<String> materialList = new ArrayList<>();
|
||||
materialList.add("黄瓜");
|
||||
materialList.add("茄子");
|
||||
// materialList.add("鸡蛋");
|
||||
WebUtil.getInstance().getMenusByMaterials(materialList, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
//必须判断状态码,如果为200说明正常,如果为404,说明这几个食材组合查询不到可以做的菜
|
||||
if (response.code() == 200) {
|
||||
String json = response.body().string();
|
||||
FoodMenu[] menus = new Gson().fromJson(json, FoodMenu[].class);
|
||||
System.out.println(menus);
|
||||
for (FoodMenu menu : menus) {
|
||||
System.out.println(menu.getName());
|
||||
}
|
||||
} else {
|
||||
System.out.println("查不到组合食材可以做的菜");
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
* 用户的浏览历史: 添加用户和菜谱的多对多关系
|
||||
|
||||
```java
|
||||
//获取历史记录 传入username
|
||||
WebUtil.getInstance().getEatenHistory("test5", 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();
|
||||
History[] histories = new Gson().fromJson(json, History[].class);
|
||||
System.out.println(Arrays.toString(histories));
|
||||
}
|
||||
});
|
||||
//添加历史记录 传入username 和 Menu的名字
|
||||
WebUtil.getInstance().addEatenHistory("test5", "多味茄子泥", 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();
|
||||
History history = new Gson().fromJson(json, History.class);
|
||||
System.out.println(history);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
* 菜名搜索: `getMenu`方法,传入菜名(菜名通过其他的各种关联方式获取) (menu.calorie是直接爬到的卡路里值,营养元素里的menu.elements.calorie卡路里是根据每个食材的卡路里计算的,相对来说,menu.calorie的值更准确)
|
||||
|
||||
* 功效搜菜 `getMenuClassification`传入分类(功效)参数,比如川菜.搜到所有的川菜名字.然后可以用菜名搜索搜某个菜的详细信息
|
||||
|
||||
* **点赞或评论来影响推荐顺序**
|
||||
|
||||
* **晒图区域**
|
||||
|
||||
* 营养量搜菜 : 搜索某个营养量范围内的菜
|
||||
|
||||
可选参数: `[calorie,carbohydrate,fat ,protein,cellulose,vitaminA,vitaminB1,vitaminB2,vitaminB6,vitaminC,vitaminE,carotene,cholesterol,Mg,Ca,Fe,Zn,Cu,Mn,K ,P ,Na,Se,niacin ,thiamine]`
|
||||
@@ -192,9 +256,9 @@
|
||||
WebUtil.getInstance().getMenusByElements(params, 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();
|
||||
@@ -277,3 +341,65 @@
|
||||
* `occupation_name`,`physical_name`的值必须和数据库对应
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
## 国赛阶段
|
||||
|
||||
### 代码
|
||||
|
||||
* 优化了`getRandomMenus方法`,传入username参数.会根据user的体质,职业,病理推荐菜
|
||||
|
||||
```java
|
||||
public void getRandomMenus(int count, String username, Callback callback)
|
||||
```
|
||||
|
||||
这个方法之前的版本没有username参数,**现在弃用原来的版本,原来的方法仍然可以调用,需要把项目的所有getRandomMenus方法调用加上一个username参数**
|
||||
|
||||
### 问题
|
||||
|
||||
* ~~连续识别,出现错误的,点一下消去 锐!~~
|
||||
* ~~bug: 连续拍照后 点了一周定制 锐~~
|
||||
* ~~*食材模糊识别 ok*~~
|
||||
* ~~通过食材组合,搜索菜 ,菜要符合username的信息 赵和锐 `getMenusByMaterials`~~
|
||||
* 卡路里不对
|
||||
* ~~*早餐晚餐的搜索不随机 shuffle了一下.ok*~~
|
||||
|
||||
* ~~`get_menus_by_elements` django随机一下~~
|
||||
* 周定制下面的两个按钮 锐
|
||||
* ~~*搜菜如果搜不到 把name减一下再搜 ok*~~
|
||||
* getRandomMenus的调用里面加上username参数 锐
|
||||
* 吃饭的时候没拍照,吃饭完了才想添加,但是菜图片没有了.需要输入添加 (王)
|
||||
* 口味信息采集
|
||||
* 历史记录
|
||||
* 社交功能: 点赞,晒图,评论
|
||||
|
||||
|
||||
### 时间安排
|
||||
|
||||
* 周日上午答辩
|
||||
* 周五排练
|
||||
|
||||
### PPT安排
|
||||
|
||||
* 小组分工介绍
|
||||
|
||||
|
||||
* 产品背景 秦
|
||||
* 量身定制 林
|
||||
* 周定制 林
|
||||
* 动态添加 智能定量 赵
|
||||
* 拍食材做菜(食菜帮) 赵
|
||||
* 菜谱推荐 秦
|
||||
|
||||
* 产品亮点 秦
|
||||
* 产品难点 王
|
||||
* 未来展望 王
|
||||
* 相信在不就得将来,在AI智能定制膳食的帮助下,人们不再为职业病,慢性病所烦恼,享受科学膳食带来的健康生活.
|
||||
|
||||
### 需要演示的功能
|
||||
|
||||
* 拍照 菜品识别 识别 烤鸭 土豆丝 鱼香肉丝 红烧肉 炒面 (动态调量,修改当天余额)
|
||||
* 拍照 食材识别 胡萝卜 白萝卜 姜 长条茄子 菜花 (根据用户的信息,并且是多搜索)
|
||||
|
||||
* 周定制(最左边的fragment)
|
||||
@@ -60,7 +60,8 @@
|
||||
<!-- android:label="@string/title_activity_login" /> -->
|
||||
<activity android:name=".modules.addinformation.AddInformationActivity" />
|
||||
<activity android:name=".modules.classifyresult.DishResultActivity" />
|
||||
<activity android:name=".modules.classifyresult.MaterialResultActivity"></activity>
|
||||
<activity android:name=".modules.classifyresult.MaterialResultActivity" />
|
||||
<activity android:name=".modules.historysearch.HistoryActivity"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -4,10 +4,14 @@ 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.Illness;
|
||||
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.CalculateUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
@@ -39,7 +43,16 @@ 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;
|
||||
public static Illness illness = null;
|
||||
|
||||
public static Element calculatedElement = null;
|
||||
|
||||
public static int randomSeed = CalculateUtils.getWeek();
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@@ -121,7 +134,7 @@ public class NutritionMaster extends Application {
|
||||
*/
|
||||
private void initUser() {
|
||||
user = new MyUser();
|
||||
user.setUsername("ScorpioMiku");
|
||||
user.setUsername("test1");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,9 +189,9 @@ public class NutritionMaster extends Application {
|
||||
// 获取所有响应头字段
|
||||
Map<String, List<String>> map = connection.getHeaderFields();
|
||||
// 遍历所有的响应头字段
|
||||
for (String key : map.keySet()) {
|
||||
System.err.println(key + "--->" + map.get(key));
|
||||
}
|
||||
// for (String key : map.keySet()) {
|
||||
// System.err.println(key + "--->" + map.get(key));
|
||||
// }
|
||||
// 定义 BufferedReader输入流来读取URL的响应
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String result = "";
|
||||
@@ -203,6 +216,7 @@ public class NutritionMaster extends Application {
|
||||
*/
|
||||
private void initYouDao() {
|
||||
YouDaoApplication.init(this, ConstantUtils.YOUDAO_APPKEY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,9 +10,11 @@ import android.widget.ImageView;
|
||||
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.bean.DailyCard;
|
||||
import com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.customization.CustomizationActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -45,15 +47,17 @@ public class CardHolder extends RecyclerView.ViewHolder {
|
||||
public void bindView(int picId, DailyCard dailyCard, final Context context) {
|
||||
tvName.setText(dailyCard.getTitle());
|
||||
tvSign.setText(dailyCard.getDescription());
|
||||
// ivPhoto.setImageDrawable(context.getDrawable(picId));
|
||||
Glide.with(context).load(picId).into(ivPhoto);
|
||||
i = new Intent(context, CustomizationActivity.class);
|
||||
i.putExtra("SEND_CODE", dailyCard.getTitle());
|
||||
// Logger.d(text);
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
context.startActivity(i);
|
||||
if (NutritionMaster.physique == null || NutritionMaster.occupation == null) {
|
||||
MessageUtils.MakeToast("填写信息才能使用哦~");
|
||||
} else {
|
||||
context.startActivity(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,25 +1,45 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.customization.CustomizationActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/24.
|
||||
*/
|
||||
|
||||
public class CustomizationAdapter extends RecyclerView.Adapter<CardHolder> {
|
||||
@Override
|
||||
public CardHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return null;
|
||||
public class CustomizationAdapter extends RecyclerView.Adapter<CustomizationHolder> {
|
||||
private ArrayList<FoodMenu> mList;
|
||||
private Context context;
|
||||
private int flag;
|
||||
|
||||
public CustomizationAdapter(ArrayList<FoodMenu> mList, Context context, int flag) {
|
||||
this.mList = mList;
|
||||
this.context = context;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(CardHolder holder, int position) {
|
||||
public CustomizationHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.customization_item, parent, false);
|
||||
return new CustomizationHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(CustomizationHolder holder, int position) {
|
||||
holder.bindView(mList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 0;
|
||||
return mList.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,93 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
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.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
|
||||
import com.example.ninefourone.nutritionmaster.modules.RecipeActivity.RecipeActivity;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/24.
|
||||
*/
|
||||
|
||||
public class CustomizationHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.customization_item_image)
|
||||
ImageView customizationItemImage;
|
||||
@BindView(R.id.food_name)
|
||||
TextView foodName;
|
||||
@BindView(R.id.food_quantity)
|
||||
TextView foodQuantity;
|
||||
@BindView(R.id.arch)
|
||||
ImageView arch;
|
||||
@BindView(R.id.food_energy)
|
||||
TextView foodEnergy;
|
||||
@BindView(R.id.click)
|
||||
RelativeLayout click;
|
||||
|
||||
public CustomizationHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bindView(final FoodMenu foodMenu) {
|
||||
Glide.with(itemView.getContext()).load(foodMenu.getImage_url()).into(customizationItemImage);
|
||||
foodName.setText(foodMenu.getName());
|
||||
try {
|
||||
Element element = NutritionMaster.element.calculateData(NutritionMaster.user);
|
||||
double calorieQuantity = element.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie();
|
||||
double quantity = calorieQuantity / foodMenu.getCalorie();
|
||||
Random random = new Random((int) foodMenu.getElements().getCalorie());
|
||||
if (quantity > 200) {
|
||||
quantity = 150 + random.nextInt(50);
|
||||
} else if (quantity < 50) {
|
||||
quantity = 50 + random.nextInt(50);
|
||||
}
|
||||
// Logger.d(foodMenu.getCalorie());
|
||||
int energy = (int) (foodMenu.getElements().getCalorie() * quantity / 100);
|
||||
energy = checkEnergy(energy);
|
||||
foodEnergy.setText(energy + "千卡");
|
||||
foodQuantity.setText((int) quantity + "克");
|
||||
|
||||
final Intent intent = new Intent(itemView.getContext().getApplicationContext(), RecipeActivity.class);
|
||||
RecommendFood recommendFood = new RecommendFood(foodMenu, 1);
|
||||
intent.putExtra("SEND_OBJECT", recommendFood);
|
||||
click.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
itemView.getContext().getApplicationContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private int checkEnergy(int energy) {
|
||||
if (energy < 30) {
|
||||
return checkEnergy(energy * 2);
|
||||
} else if (energy > 250) {
|
||||
return checkEnergy(energy - 50);
|
||||
} else {
|
||||
return energy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.History;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/11/7.
|
||||
*/
|
||||
|
||||
public class HistoryAdapter extends RecyclerView.Adapter<HistoryHolder> {
|
||||
private Context context;
|
||||
private List<History> mList;
|
||||
|
||||
public HistoryAdapter(Context context, List mList) {
|
||||
this.context = context;
|
||||
this.mList = mList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dish_item, parent, false);
|
||||
HistoryHolder historyHolder = new HistoryHolder(view);
|
||||
return historyHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(HistoryHolder holder, int position) {
|
||||
holder.bindView(mList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Intent;
|
||||
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.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.History;
|
||||
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
|
||||
import com.example.ninefourone.nutritionmaster.modules.RecipeActivity.RecipeActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/11/7.
|
||||
*/
|
||||
|
||||
public class HistoryHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.image)
|
||||
ImageView image;
|
||||
@BindView(R.id.name)
|
||||
TextView name;
|
||||
@BindView(R.id.describle)
|
||||
TextView describle;
|
||||
private FoodMenu foodMenu;
|
||||
|
||||
public HistoryHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bindView(History history) {
|
||||
Glide.with(itemView.getContext()).load(history.getMenu().getImage_url()).into(image);
|
||||
name.setText(history.getMenu().getName());
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
webUtil.getMenu(history.getMenu().getName(), 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();
|
||||
foodMenu = new Gson().fromJson(json, FoodMenu.class);
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(itemView.getContext().getApplicationContext(), RecipeActivity.class);
|
||||
RecommendFood recommendFood = new RecommendFood(foodMenu, 1);
|
||||
intent.putExtra("SEND_OBJECT", recommendFood);
|
||||
itemView.getContext().getApplicationContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -54,4 +54,8 @@ public class HomePagerAdapter extends FragmentPagerAdapter {
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return TITLES[position];
|
||||
}
|
||||
|
||||
public void rereshUI() {
|
||||
((BodyInformationFragment) fragments[1]).refreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,19 +7,21 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Material;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMaterial;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/9.
|
||||
*/
|
||||
|
||||
public class MaterialAdapter extends RecyclerView.Adapter<MaterialHolder> {
|
||||
private ArrayList<Material> mList;
|
||||
private List<FoodMenu.CookQuantityBean> mList;
|
||||
private Context mContext;
|
||||
|
||||
public MaterialAdapter(ArrayList mList, Context mContext) {
|
||||
public MaterialAdapter(List mList, Context mContext) {
|
||||
this.mList = mList;
|
||||
this.mContext = mContext;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Material;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMaterial;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -24,11 +25,12 @@ public class MaterialHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public MaterialHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this,itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bindView(Material material) {
|
||||
weightNumber.setText(material.getWeight() + "");
|
||||
name.setText(material.getMaterialName());
|
||||
public void bindView(FoodMenu.CookQuantityBean cookQuantityBean) {
|
||||
name.setText(cookQuantityBean.getMaterial());
|
||||
String weight = cookQuantityBean.getQuantity();
|
||||
weightNumber.setText(weight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/7.
|
||||
*/
|
||||
|
||||
public class MaterialResultAdapter extends RecyclerView.Adapter<MaterialResultHolder> {
|
||||
private ArrayList<FoodMenu> foodMenus;
|
||||
private Context context;
|
||||
|
||||
public MaterialResultAdapter(ArrayList<FoodMenu> foodMenus, Context context) {
|
||||
this.foodMenus = foodMenus;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialResultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.material_result_item, parent, false);
|
||||
return new MaterialResultHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MaterialResultHolder holder, int position) {
|
||||
holder.bindView(foodMenus.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return foodMenus.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
|
||||
import com.example.ninefourone.nutritionmaster.modules.RecipeActivity.RecipeActivity;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/7.
|
||||
*/
|
||||
|
||||
public class MaterialResultHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.image)
|
||||
ImageView image;
|
||||
@BindView(R.id.name)
|
||||
TextView name;
|
||||
@BindView(R.id.whole_layout)
|
||||
LinearLayout wholeLayout;
|
||||
|
||||
public MaterialResultHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bindView(final FoodMenu foodMenu) {
|
||||
Glide.with(itemView.getContext()).load(foodMenu.getImage_url()).into(image);
|
||||
name.setText(foodMenu.getName());
|
||||
wholeLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(itemView.getContext().getApplicationContext(), RecipeActivity.class);
|
||||
RecommendFood recommendFood = new RecommendFood(foodMenu, 1);
|
||||
intent.putExtra("SEND_OBJECT", recommendFood);
|
||||
itemView.getContext().getApplicationContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
|
||||
@@ -11,6 +14,7 @@ import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
|
||||
import com.example.ninefourone.nutritionmaster.modules.RecipeActivity.RecipeActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
@@ -20,7 +24,6 @@ import java.util.List;
|
||||
*/
|
||||
|
||||
public class RecommendAdapter extends BaseMultiItemQuickAdapter<RecommendFood, BaseViewHolder> {
|
||||
private int[] indexs = new int[]{0, 1, 1, 2};
|
||||
private Intent intent;
|
||||
|
||||
/**
|
||||
@@ -31,37 +34,43 @@ public class RecommendAdapter extends BaseMultiItemQuickAdapter<RecommendFood, B
|
||||
*/
|
||||
public RecommendAdapter(List<RecommendFood> data) {
|
||||
super(data);
|
||||
addItemType(RecommendFood.TYPE_BIG, R.layout.recommend_item_big);
|
||||
addItemType(RecommendFood.TYPE_BIG, R.layout.recommend_item_middle);
|
||||
addItemType(RecommendFood.TYPE_DETAIL, R.layout.recommend_item_detail);
|
||||
addItemType(RecommendFood.TYPE_MIDDLE, R.layout.recommend_item_middle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, RecommendFood item) {
|
||||
protected void convert(BaseViewHolder helper, final RecommendFood item) {
|
||||
ImageView imageView = helper.getView(R.id.recommend_item_imageview);
|
||||
Glide.with(mContext).load(R.drawable.food_test).into(imageView);
|
||||
switch (item.getItemType()) {
|
||||
case RecommendFood.TYPE_BIG:
|
||||
helper.setText(R.id.recommend_item_title, "红烧肉");
|
||||
break;
|
||||
case RecommendFood.TYPE_DETAIL:
|
||||
helper.setText(R.id.recommend_item_title, item.getTitle());
|
||||
helper.setText(R.id.recommend_item_description, item.getDescription());
|
||||
break;
|
||||
case RecommendFood.TYPE_MIDDLE:
|
||||
helper.setText(R.id.recommend_item_title, "红烧");
|
||||
break;
|
||||
}
|
||||
|
||||
Glide.with(mContext).load(item.getPicture()).into(imageView);
|
||||
View view = helper.getView(R.id.whole_layout);
|
||||
intent = new Intent(mContext, RecipeActivity.class);
|
||||
// Logger.d(item.getItemType());
|
||||
intent.putExtra("SEND_OBJECT", item);
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(mContext, RecipeActivity.class);
|
||||
intent.putExtra("SEND_OBJECT", item);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
helper.setText(R.id.recommend_item_title, item.getTitle());
|
||||
if (item.getItemType() == RecommendFood.TYPE_DETAIL) {
|
||||
helper.setText(R.id.recommend_item_description, item.getDescription());
|
||||
LinearLayout detailClick = helper.getView(R.id.detail_click);
|
||||
detailClick.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext).setTitle("小知识")
|
||||
.setMessage(item.getDescription()).setIcon(R.drawable.ic_add_recipe);
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
dialog.setCancelable(true);
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,6 +68,6 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
|
||||
name.setText(classifyResult.getName());
|
||||
Glide.with(context).load("http://s2.boohee.cn/house/food_big/big_photo20155149534910631.jpg").into(image);
|
||||
Glide.with(context).load(classifyResult.getImgPath()).into(image);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -27,9 +28,11 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
this.user = NutritionMaster.user;
|
||||
setContentView(getLayoutId());
|
||||
unbinder = ButterKnife.bind(this);
|
||||
initViews(savedInstanceState);
|
||||
webUtil = WebUtil.getInstance();
|
||||
|
||||
initViews(savedInstanceState);
|
||||
initToolBar();
|
||||
|
||||
}
|
||||
|
||||
public WebUtil getWebUtil() {
|
||||
@@ -99,7 +102,8 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
protected void upUser() {
|
||||
NutritionMaster.user = user;
|
||||
Logger.d("用户信息已改" + NutritionMaster.user.toString());
|
||||
NutritionMaster.element = new Element(user);
|
||||
// Logger.d("用户信息已改" + NutritionMaster.user.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,6 +37,7 @@ public abstract class BaseFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
|
||||
webUtil = WebUtil.getInstance();
|
||||
parentView = inflater.inflate(getLayoutResId(), container, false);
|
||||
activity = getSupportActivity();
|
||||
return parentView;
|
||||
@@ -47,7 +48,6 @@ public abstract class BaseFragment extends Fragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
initView(savedInstanceState);
|
||||
webUtil = WebUtil.getInstance();
|
||||
this.user = NutritionMaster.user;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ClassifyResult implements Serializable {
|
||||
private Boolean has_calorie = false;
|
||||
private double quantity = -1;
|
||||
private FoodMenu foodMenu;
|
||||
private FoodMaterial foodMaterial;
|
||||
private Material foodMaterial;
|
||||
|
||||
private int flag = -1;
|
||||
public static int MATERIAL = 0;
|
||||
@@ -64,13 +64,12 @@ public class ClassifyResult implements Serializable {
|
||||
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);
|
||||
foodMaterial = new Material();
|
||||
foodMaterial.setFoodMaterial(material);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -78,7 +77,7 @@ public class ClassifyResult implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public FoodMaterial getFoodMaterial() {
|
||||
public Material getFoodMaterial() {
|
||||
return foodMaterial;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,427 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/7.
|
||||
*/
|
||||
|
||||
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(FoodMenu.ElementsBean elementsBean) {
|
||||
calorie = elementsBean.getCalorie();
|
||||
carbohydrate = (float) elementsBean.getCarbohydrate();
|
||||
fat = (float) elementsBean.getFat();
|
||||
protein = (float) elementsBean.getProtein();
|
||||
cellulose = (float) elementsBean.getCellulose();
|
||||
vitaminA = (float) elementsBean.getVitaminA();
|
||||
vitaminB1 = elementsBean.getVitaminB1();
|
||||
vitaminB2 = (float) elementsBean.getVitaminB2();
|
||||
vitaminB6 = elementsBean.getVitaminB6();
|
||||
vitaminC = (float) elementsBean.getVitaminC();
|
||||
vitaminE = (float) elementsBean.getVitaminE();
|
||||
carotene = (float) elementsBean.getCarotene();
|
||||
cholesterol = (float) elementsBean.getCholesterol();
|
||||
Mg = (float) elementsBean.getMg();
|
||||
Ca = (float) elementsBean.getCa();
|
||||
Fe = (float) elementsBean.getFe();
|
||||
Zn = (float) elementsBean.getZn();
|
||||
Cu = (float) elementsBean.getCu();
|
||||
Mn = (float) elementsBean.getMn();
|
||||
K = (float) elementsBean.getK();
|
||||
P = (float) elementsBean.getP();
|
||||
Na = (float) elementsBean.getNa();
|
||||
Se = (float) elementsBean.getSe();
|
||||
niacin = (float) elementsBean.getNiacin();
|
||||
thiamine = (float) elementsBean.getThiamine();
|
||||
}
|
||||
|
||||
public Element(Element 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();
|
||||
}
|
||||
|
||||
|
||||
public Element(Illness.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;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
public class FoodMenu implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* flavor : 五香味
|
||||
* calorie : 157
|
||||
@@ -20,6 +21,7 @@ public class FoodMenu implements Serializable {
|
||||
private String flavor;
|
||||
private float calorie;
|
||||
private String name;
|
||||
private int is_breakfast;
|
||||
private String technology;
|
||||
private String image_url;
|
||||
private String practice;
|
||||
@@ -33,6 +35,7 @@ public class FoodMenu implements Serializable {
|
||||
"flavor='" + flavor + '\'' +
|
||||
", calorie=" + calorie +
|
||||
", name='" + name + '\'' +
|
||||
", is_breakfast=" + is_breakfast +
|
||||
", technology='" + technology + '\'' +
|
||||
", image_url='" + image_url + '\'' +
|
||||
", practice='" + practice + '\'' +
|
||||
@@ -42,6 +45,14 @@ public class FoodMenu implements Serializable {
|
||||
'}';
|
||||
}
|
||||
|
||||
public int getIs_breakfast() {
|
||||
return is_breakfast;
|
||||
}
|
||||
|
||||
public void setIs_breakfast(int is_breakfast) {
|
||||
this.is_breakfast = is_breakfast;
|
||||
}
|
||||
|
||||
public String getFlavor() {
|
||||
return flavor;
|
||||
}
|
||||
@@ -114,7 +125,7 @@ public class FoodMenu implements Serializable {
|
||||
this.menuclassification_set = menuclassification_set;
|
||||
}
|
||||
|
||||
public static class ElementsBean implements Serializable{
|
||||
public static class ElementsBean implements Serializable {
|
||||
/**
|
||||
* id : 3940
|
||||
* calorie : 183
|
||||
@@ -459,4 +470,3 @@ public class FoodMenu implements Serializable {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
public class FoodMenuLight {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class FoodMenuLight implements Serializable{
|
||||
|
||||
/**
|
||||
* name : 番茄虾仁
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
public class History {
|
||||
/**
|
||||
* id : 13
|
||||
* menu : {"name":"多味茄子泥","calorie":105,"elements":6383,"image_url":"http://s1.ig.meishij.net/p/20121204/3fde157430b268b189a913983fdda3e6_150x150.jpg"}
|
||||
* time : 2018-11-02T15:34:27.050541+08:00
|
||||
* user : 11
|
||||
*/
|
||||
|
||||
private int id;
|
||||
private MenuBean menu;
|
||||
private String time;
|
||||
private int user;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public MenuBean getMenu() {
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void setMenu(MenuBean menu) {
|
||||
this.menu = menu;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public int getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(int user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public static class MenuBean {
|
||||
/**
|
||||
* name : 多味茄子泥
|
||||
* calorie : 105
|
||||
* elements : 6383
|
||||
* image_url : http://s1.ig.meishij.net/p/20121204/3fde157430b268b189a913983fdda3e6_150x150.jpg
|
||||
*/
|
||||
|
||||
private String name;
|
||||
private int calorie;
|
||||
private int elements;
|
||||
private String image_url;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public void setCalorie(int calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public int getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public void setElements(int elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public String getImage_url() {
|
||||
return image_url;
|
||||
}
|
||||
|
||||
public void setImage_url(String image_url) {
|
||||
this.image_url = image_url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MenuBean{" +
|
||||
"name='" + name + '\'' +
|
||||
", calorie=" + calorie +
|
||||
", elements=" + elements +
|
||||
", image_url='" + image_url + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "History{" +
|
||||
"id=" + id +
|
||||
", menu=" + menu +
|
||||
", time='" + time + '\'' +
|
||||
", user=" + user +
|
||||
'}' + '\n';
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,31 +1,106 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/11.
|
||||
* Created by ScorpioMiku on 2018/10/7.
|
||||
*/
|
||||
|
||||
public class Material {
|
||||
private String materialName;
|
||||
private float weight;
|
||||
public class Material implements Serializable {
|
||||
FoodMaterial foodMaterial;
|
||||
ArrayList<FoodMenu> menus = new ArrayList<>();
|
||||
|
||||
public Material(String materialName, float weight) {
|
||||
this.materialName = materialName;
|
||||
this.weight = weight;
|
||||
public FoodMaterial getFoodMaterial() {
|
||||
return foodMaterial;
|
||||
}
|
||||
|
||||
public String getMaterialName() {
|
||||
return materialName;
|
||||
public void setFoodMaterial(FoodMaterial foodMaterial) {
|
||||
this.foodMaterial = foodMaterial;
|
||||
try {
|
||||
int max = foodMaterial.getCook_quantity().size() > 30 ? 30 : foodMaterial.getCook_quantity().size();
|
||||
for (int i = 0; i < max; i++) {
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
FoodMaterial.CookQuantityBean temp = foodMaterial.getCook_quantity().get(i);
|
||||
String menuName = temp.getMenu();
|
||||
webUtil.getMenu(menuName, 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();
|
||||
try {
|
||||
FoodMenu menu = new Gson().fromJson(json, FoodMenu.class);
|
||||
if (!menu.getImage_url().equals("0")) {
|
||||
menus.add(menu);
|
||||
// Logger.d(menu);
|
||||
}
|
||||
}catch (Exception e){
|
||||
// Logger.e(json);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
// MessageUtils.MakeToast("您当前拍摄的食材没有录入服务器");
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaterialName(String materialName) {
|
||||
this.materialName = materialName;
|
||||
public ArrayList<FoodMenu> getMenus() {
|
||||
return menus;
|
||||
}
|
||||
|
||||
public float getWeight() {
|
||||
return weight;
|
||||
public void setMenus(ArrayList<FoodMenu> menus) {
|
||||
this.menus = menus;
|
||||
}
|
||||
|
||||
public void setWeight(float weight) {
|
||||
this.weight = weight;
|
||||
@Override
|
||||
public String toString() {
|
||||
return foodMaterial.toString() + "\nsize:" + menus.size();
|
||||
}
|
||||
|
||||
private void addMenu(final int index, final int max) {
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
FoodMaterial.CookQuantityBean temp = foodMaterial.getCook_quantity().get(index);
|
||||
String menuName = temp.getMenu();
|
||||
Logger.d(menuName);
|
||||
webUtil.getMenu(menuName, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
Logger.d(response.body().string());
|
||||
FoodMenu menu = new Gson().fromJson(response.body().string(), FoodMenu.class);
|
||||
menus.add(menu);
|
||||
if (index < max) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addMenu(index + 1, max);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/9.
|
||||
*/
|
||||
|
||||
public class Menu {
|
||||
private String menuName;
|
||||
private ArrayList<Material> materialArrayList;
|
||||
private ArrayList<String> makeSteps;
|
||||
|
||||
|
||||
public Menu(String menuName, ArrayList<Material> materialArrayList, ArrayList<String> makeSteps) {
|
||||
this.menuName = menuName;
|
||||
this.materialArrayList = materialArrayList;
|
||||
this.makeSteps = makeSteps;
|
||||
}
|
||||
|
||||
public String getMenuName() {
|
||||
return menuName;
|
||||
}
|
||||
|
||||
public void setMenuName(String menuName) {
|
||||
this.menuName = menuName;
|
||||
}
|
||||
|
||||
public ArrayList<Material> getMaterialArrayList() {
|
||||
return materialArrayList;
|
||||
}
|
||||
|
||||
public void setMaterialArrayList(ArrayList<Material> materialArrayList) {
|
||||
this.materialArrayList = materialArrayList;
|
||||
}
|
||||
|
||||
public ArrayList<String> getMakeSteps() {
|
||||
return makeSteps;
|
||||
}
|
||||
|
||||
public void setMakeSteps(ArrayList<String> makeSteps) {
|
||||
this.makeSteps = makeSteps;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class MenuClassification {
|
||||
public class MenuClassification implements Serializable{
|
||||
|
||||
/**
|
||||
* classification : 川菜
|
||||
|
||||
@@ -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;
|
||||
@@ -42,12 +42,12 @@ public class MyUser {
|
||||
private Boolean is_staff;
|
||||
private Boolean is_active;
|
||||
private String date_joined;
|
||||
private Integer sex;
|
||||
private Integer sex = 1;
|
||||
private Integer age;
|
||||
private Integer height;
|
||||
private Integer weight;
|
||||
private Integer bmi = new Integer(-1);
|
||||
private String occupation_name;
|
||||
private String occupation_name = "";
|
||||
private List<?> groups;
|
||||
private List<?> user_permissions;
|
||||
private List<?> illness;
|
||||
@@ -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;
|
||||
@@ -557,5 +563,33 @@ public class MyUser {
|
||||
public void setThiamine(double thiamine) {
|
||||
this.thiamine = thiamine;
|
||||
}
|
||||
|
||||
public void add(Element element, float factor) {
|
||||
calorie += element.getCalorie() * factor;
|
||||
carbohydrate += (float) element.getCarbohydrate() * factor;
|
||||
fat += (float) element.getFat() * factor;
|
||||
protein += (float) element.getProtein() * factor;
|
||||
cellulose += (float) element.getCellulose() * factor;
|
||||
vitaminA += (float) element.getVitaminA() * factor;
|
||||
vitaminB1 += element.getVitaminB1() * factor;
|
||||
vitaminB2 += (float) element.getVitaminB2() * factor;
|
||||
vitaminB6 += element.getVitaminB6() * factor;
|
||||
vitaminC += (float) element.getVitaminC() * factor;
|
||||
vitaminE += (float) element.getVitaminE() * factor;
|
||||
carotene += (float) element.getCarotene() * factor;
|
||||
cholesterol += (float) element.getCholesterol() * factor;
|
||||
Mg += (float) element.getMg() * factor;
|
||||
Ca += (float) element.getCa() * factor;
|
||||
Fe += (float) element.getFe() * factor;
|
||||
Zn += (float) element.getZn() * factor;
|
||||
Cu += (float) element.getCu() * factor;
|
||||
Mn += (float) element.getMn() * factor;
|
||||
K += (float) element.getK() * factor;
|
||||
P += (float) element.getP() * factor;
|
||||
Na += (float) element.getNa() * factor;
|
||||
Se += (float) element.getSe() * factor;
|
||||
niacin += (float) element.getNiacin() * factor;
|
||||
thiamine += (float) element.getThiamine() * factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,5 +392,7 @@ public class Physique {
|
||||
this.thiamine = thiamine;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,35 +16,32 @@ public class RecommendFood implements MultiItemEntity, Serializable {
|
||||
public static final int TYPE_MIDDLE = 1;
|
||||
public static final int TYPE_DETAIL = 2;
|
||||
|
||||
private int picture;
|
||||
private String picture;
|
||||
private String title;
|
||||
private String description;
|
||||
private int type;
|
||||
private Menu menu;
|
||||
private FoodMenu menu;
|
||||
|
||||
public Menu getMenu() {
|
||||
public FoodMenu getMenu() {
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void setMenu(Menu menu) {
|
||||
public void setMenu(FoodMenu menu) {
|
||||
this.menu = menu;
|
||||
}
|
||||
|
||||
public RecommendFood(int picture, String title, String description, int type) {
|
||||
this.picture = picture;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
public RecommendFood(FoodMenu foodMenu, int type) {
|
||||
menu = foodMenu;
|
||||
picture = foodMenu.getImage_url();
|
||||
title = foodMenu.getName();
|
||||
this.type = type;
|
||||
if (type > 2) {
|
||||
Logger.e("混合recycler type不对");
|
||||
}
|
||||
}
|
||||
|
||||
public int getPicture() {
|
||||
public String getPicture() {
|
||||
return picture;
|
||||
}
|
||||
|
||||
public void setPicture(int picture) {
|
||||
public void setPicture(String picture) {
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
@@ -68,4 +65,10 @@ public class RecommendFood implements MultiItemEntity, Serializable {
|
||||
public int getItemType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return menu.toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,16 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
@@ -18,13 +23,16 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseFragment;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.modules.classifyresult.DishResultActivity;
|
||||
import com.example.ninefourone.nutritionmaster.modules.classifyresult.MaterialResultActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MaterialClassifier;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.youdao.sdk.app.Language;
|
||||
import com.youdao.sdk.app.LanguageUtils;
|
||||
@@ -37,6 +45,10 @@ import com.youdao.sdk.ydtranslate.TranslateParameters;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -44,6 +56,9 @@ import java.util.List;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/3.
|
||||
@@ -171,7 +186,20 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
private Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
|
||||
@Override
|
||||
public void onPictureTaken(final byte[] data, Camera camera) {
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
||||
bitmap = rotateBitmapByDegree(bitmap, 90);
|
||||
//缩放
|
||||
bitmap = Bitmap.createScaledBitmap(bitmap, 720, 1280, false);
|
||||
try {
|
||||
final File pictureDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
||||
final String pictureName = System.currentTimeMillis() + ".jpg";
|
||||
final String picturePath = pictureDir + File.separator + pictureName;
|
||||
File file = new File(picturePath);
|
||||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
|
||||
bos.flush();
|
||||
bos.close();
|
||||
|
||||
String imgStr = Base64.encodeToString(data, Base64.DEFAULT);
|
||||
String imgParam = URLEncoder.encode(imgStr, "UTF-8");
|
||||
final String param = "image=" + imgParam + "&top_num=" + 1;
|
||||
@@ -186,6 +214,7 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
result = jsonObject.getJSONArray("objects")
|
||||
.getJSONObject(0).getString("value");
|
||||
translate(result);
|
||||
refreshUI();
|
||||
} else if (code == DISH_CODE) {
|
||||
result = WebUtil.HttpPost(ConstantUtils.BD_DISH_URL,
|
||||
ConstantUtils.BD_ACCESS_TOKEN, param);
|
||||
@@ -194,10 +223,12 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
JSONArray resultObject = jsonObject.getJSONArray("result");
|
||||
jsonObject = resultObject.getJSONObject(0);
|
||||
classifyResult.setCalorie(jsonObject.getInt("calorie"));
|
||||
Logger.d(jsonObject.getInt("calorie"));
|
||||
classifyResult.setHas_calorie(jsonObject.getBoolean("has_calorie"));
|
||||
classifyResult.setProbability(jsonObject.getDouble("probability"));
|
||||
classifyResult.setName(jsonObject.getString("name"));
|
||||
classifyResult.getMenu();
|
||||
classifyResult.setImgPath(picturePath);
|
||||
resultList.add(classifyResult);
|
||||
refreshUI();
|
||||
} else {
|
||||
@@ -224,7 +255,11 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
*
|
||||
* @param view
|
||||
*/
|
||||
<<<<<<< HEAD
|
||||
@OnClick({R.id.more_take_photo_button_capture, R.id.more_takephoto_ok,R.id.results_text_view})
|
||||
=======
|
||||
@OnClick({R.id.more_take_photo_button_capture, R.id.more_takephoto_ok, R.id.results_text_view})
|
||||
>>>>>>> develop
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.more_take_photo_button_capture:
|
||||
@@ -232,22 +267,53 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
cameraCoverLinearlayout.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case R.id.more_takephoto_ok:
|
||||
Intent intent;
|
||||
final Intent intent;
|
||||
if (code == DISH_CODE) {
|
||||
intent = new Intent(ClassifierCamera.this, DishResultActivity.class);
|
||||
intent.putExtra("LIST", resultList);
|
||||
startActivity(intent);
|
||||
|
||||
} else {
|
||||
intent = new Intent(ClassifierCamera.this, MaterialResultActivity.class);
|
||||
|
||||
|
||||
//把拍照结果的食材名字放到新的List:materials里面
|
||||
List<String> materials = new ArrayList<>();
|
||||
for (ClassifyResult classifyResult : resultList) {
|
||||
materials.add(classifyResult.getName());
|
||||
}
|
||||
WebUtil.getInstance().getMenusByMaterials(materials, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, final Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
FoodMenu[] menus = new Gson().fromJson(json, FoodMenu[].class);
|
||||
ArrayList<FoodMenu> menuList = new ArrayList<>();
|
||||
for (FoodMenu foodMenu : menus) {
|
||||
menuList.add(foodMenu);
|
||||
}
|
||||
intent.putExtra("LIST", menuList);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
intent.putExtra("LIST", resultList);
|
||||
startActivity(intent);
|
||||
resultList.clear();
|
||||
refreshUI();
|
||||
finish();
|
||||
break;
|
||||
case R.id.results_text_view:
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
resultList.remove(resultList.size() - 1);
|
||||
refreshUI();
|
||||
>>>>>>> develop
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -326,7 +392,7 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
public void onResult(Translate translate, String s, String s1) {
|
||||
String result = "";
|
||||
result = translate.getTranslations().get(0);
|
||||
// Logger.d(result);
|
||||
Logger.d(result);
|
||||
ClassifyResult classifyResult = new ClassifyResult(ClassifyResult.MATERIAL);
|
||||
classifyResult.setName(result);
|
||||
resultList.add(classifyResult);
|
||||
@@ -339,4 +405,26 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//修改图片保存方向
|
||||
public static Bitmap rotateBitmapByDegree(Bitmap bm, int degree) {
|
||||
Bitmap returnBm = null;
|
||||
|
||||
//Matrix图片动作(旋转平移)
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(degree);
|
||||
|
||||
try {
|
||||
returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
|
||||
} catch (OutOfMemoryError e) {
|
||||
|
||||
}
|
||||
if (returnBm == null) {
|
||||
returnBm = bm;
|
||||
}
|
||||
if (bm != returnBm) {
|
||||
bm.recycle();
|
||||
}
|
||||
return returnBm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,11 @@ import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.HomePagerAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.IllAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Illness;
|
||||
import com.example.ninefourone.nutritionmaster.camera.ClassifierCamera;
|
||||
import com.example.ninefourone.nutritionmaster.modules.addinformation.AddInformationActivity;
|
||||
import com.example.ninefourone.nutritionmaster.modules.addinformation.AddPhysiqueActivity;
|
||||
import com.example.ninefourone.nutritionmaster.modules.historysearch.HistoryActivity;
|
||||
import com.example.ninefourone.nutritionmaster.modules.information.InformationActivity;
|
||||
import com.example.ninefourone.nutritionmaster.ui.NoScrollViewPager;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
@@ -50,6 +52,7 @@ import com.github.mikephil.charting.data.RadarDataSet;
|
||||
import com.github.mikephil.charting.data.RadarEntry;
|
||||
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;
|
||||
import com.github.siyamed.shapeimageview.CircularImageView;
|
||||
import com.google.gson.Gson;
|
||||
import com.miguelcatalan.materialsearchview.MaterialSearchView;
|
||||
import com.mxn.soul.flowingdrawer_core.ElasticDrawer;
|
||||
import com.mxn.soul.flowingdrawer_core.FlowingDrawer;
|
||||
@@ -58,12 +61,16 @@ import com.nightonke.boommenu.BoomButtons.OnBMClickListener;
|
||||
import com.nightonke.boommenu.BoomMenuButton;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
||||
public class MainActivity extends BaseActivity {
|
||||
@@ -130,6 +137,9 @@ public class MainActivity extends BaseActivity {
|
||||
private ArrayList<String> userIllness = new ArrayList<>();
|
||||
private IllAdapter illAdapter;
|
||||
|
||||
private HomePagerAdapter homePagerAdapter;
|
||||
|
||||
public static float[] scores = {3.1f, 2.5f, 1.7f, 5.9f, 4.6f};
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
@@ -146,6 +156,7 @@ public class MainActivity extends BaseActivity {
|
||||
public void onDrawerStateChange(int oldState, int newState) {
|
||||
if (newState == ElasticDrawer.STATE_CLOSED) {
|
||||
titleLayout.setBackgroundColor(getColor(R.color.colorPrimary));
|
||||
homePagerAdapter.rereshUI();
|
||||
} else {
|
||||
titleLayout.setBackgroundColor(getColor(R.color.bar_open));
|
||||
}
|
||||
@@ -156,7 +167,7 @@ public class MainActivity extends BaseActivity {
|
||||
// Logger.i("openRatio=" + openRatio + " ,offsetPixels=" + offsetPixels);
|
||||
}
|
||||
});
|
||||
initSpiderView();
|
||||
|
||||
initViewPager();
|
||||
initSearchView();
|
||||
initBMB();
|
||||
@@ -167,7 +178,7 @@ public class MainActivity extends BaseActivity {
|
||||
* 初始化ViewPager
|
||||
*/
|
||||
private void initViewPager() {
|
||||
HomePagerAdapter homePagerAdapter = new HomePagerAdapter(getSupportFragmentManager(),
|
||||
homePagerAdapter = new HomePagerAdapter(getSupportFragmentManager(),
|
||||
this);
|
||||
viewPager.setOffscreenPageLimit(3);
|
||||
viewPager.setAdapter(homePagerAdapter);
|
||||
@@ -181,7 +192,7 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
toolBarNickname.setText(user.getUsername());
|
||||
toolBarNickname.setText("NutritionMaster");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,6 +222,24 @@ public class MainActivity extends BaseActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击事件
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.id_action_search:
|
||||
return true;
|
||||
case R.id.id_action_record:
|
||||
Intent intent = new Intent(MainActivity.this, HistoryActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
// Logger.d("prepareMenu");
|
||||
@@ -220,16 +249,12 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
//mDrawer.openMenu();
|
||||
|
||||
/**
|
||||
* 点击事件
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 初始化蛛网图
|
||||
*/
|
||||
private void initSpiderView() {
|
||||
float[] scores = {9.1f, 5.5f, 7.7f, 8.9f, 4.6f};
|
||||
|
||||
String[] flags = {"糖分", "淡水", "蛋白质", "维生素", "矿物质"};
|
||||
|
||||
List<RadarEntry> radarEntries = new ArrayList<>();
|
||||
@@ -290,6 +315,15 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
public void refreshSpider() {
|
||||
for (int i = 0; i < scores.length; i++) {
|
||||
scores[i] += (1 - i / 2);
|
||||
if (scores[i] >= 10) {
|
||||
scores[i] = 9.9f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化SearchView
|
||||
*/
|
||||
@@ -297,7 +331,7 @@ public class MainActivity extends BaseActivity {
|
||||
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
MessageUtils.MakeToast(query);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -362,7 +396,7 @@ public class MainActivity extends BaseActivity {
|
||||
private void initInforView() {
|
||||
|
||||
adderInfor.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
changeInformation.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);
|
||||
@@ -395,7 +429,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.change_information})
|
||||
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:
|
||||
@@ -514,9 +548,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);
|
||||
|
||||
|
||||
}
|
||||
@@ -537,17 +571,69 @@ public class MainActivity extends BaseActivity {
|
||||
*/
|
||||
@OnClick(R.id.ill_button)
|
||||
public void onViewClicked() {
|
||||
illPicker = new OptionsPickerBuilder(MainActivity.this, new OnOptionsSelectListener() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// if (NutritionMaster.occupation==null||NutritionMaster.illness==null){
|
||||
// illButton.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// MessageUtils.MakeToast("请先填写职业信息和体质信息再使用");
|
||||
// }
|
||||
// });
|
||||
// }else{
|
||||
initSpiderView();
|
||||
illButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
userIllness.add(illness.get(options1));
|
||||
illAdapter.notifyDataSetChanged();
|
||||
illButton.setBackgroundResource(0);
|
||||
public void onClick(View v) {
|
||||
illPicker = new OptionsPickerBuilder(MainActivity.this, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
final String illname = illness.get(options1);
|
||||
getWebUtil().getIllness(illname, 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();
|
||||
Illness illness = new Gson().fromJson(json, Illness.class);
|
||||
NutritionMaster.illness = illness;
|
||||
Logger.d(NutritionMaster.illness);
|
||||
if (NutritionMaster.physique != null && NutritionMaster.occupation != null) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
illRecyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
userIllness.add(illname);
|
||||
illAdapter.notifyDataSetChanged();
|
||||
illAdapter.notifyDataSetChanged();
|
||||
if (NutritionMaster.occupation != null && NutritionMaster.physique != null) {
|
||||
NutritionMaster.element = CalculateUtils.getElementsAddIllness(NutritionMaster.illness,
|
||||
NutritionMaster.user, NutritionMaster.occupation, NutritionMaster.physique);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}).build();
|
||||
illPicker.setPicker(illness);
|
||||
illPicker.show();
|
||||
}
|
||||
}).build();
|
||||
MessageUtils.MakeToast("dianjile");
|
||||
illPicker.setPicker(illness);
|
||||
illPicker.show();
|
||||
});
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,21 +4,34 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.widget.ImageView;
|
||||
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.adapter.MakeStepAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.MaterialAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Material;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Menu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
|
||||
import com.example.ninefourone.nutritionmaster.utils.UiUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.github.lzyzsd.circleprogress.ArcProgress;
|
||||
import com.nightonke.boommenu.BoomButtons.HamButton;
|
||||
import com.nightonke.boommenu.BoomButtons.OnBMClickListener;
|
||||
import com.nightonke.boommenu.BoomMenuButton;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class RecipeActivity extends BaseActivity {
|
||||
|
||||
@@ -33,8 +46,22 @@ public class RecipeActivity extends BaseActivity {
|
||||
RecyclerView materialRecyclerView;
|
||||
@BindView(R.id.detail_way_recycler_view)
|
||||
RecyclerView detailWayRecyclerView;
|
||||
@BindView(R.id.image)
|
||||
ImageView image;
|
||||
@BindView(R.id.name)
|
||||
TextView name;
|
||||
@BindView(R.id.back_button)
|
||||
ImageView backButton;
|
||||
@BindView(R.id.protein_text)
|
||||
TextView proteinText;
|
||||
@BindView(R.id.fat_text)
|
||||
TextView fatText;
|
||||
@BindView(R.id.suger_text)
|
||||
TextView sugerText;
|
||||
@BindView(R.id.boom_menu_button)
|
||||
BoomMenuButton boomMenuButton;
|
||||
private RecommendFood recommendFood;
|
||||
private Menu menu;
|
||||
|
||||
|
||||
private MaterialAdapter materialAdapter;
|
||||
private MakeStepAdapter makeStepAdapter;
|
||||
@@ -53,7 +80,18 @@ public class RecipeActivity extends BaseActivity {
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
Intent intent = getIntent();
|
||||
recommendFood = (RecommendFood) intent.getSerializableExtra("SEND_OBJECT");
|
||||
Glide.with(RecipeActivity.this).load(recommendFood.getPicture()).into(image);
|
||||
name.setText(recommendFood.getMenu().getName());
|
||||
HashMap map = CalculateUtils.elementsProportion(recommendFood.getMenu().getElements());
|
||||
proteinCircle.setProgress((int) map.get("protein"));
|
||||
fatCircle.setProgress((int) map.get("fat"));
|
||||
carbohydrateCircle.setProgress((int) map.get("suger"));
|
||||
proteinText.setText(new Double(recommendFood.getMenu().getElements().getProtein()).intValue() + "克");
|
||||
fatText.setText(new Double(recommendFood.getMenu().getElements().getFat()).intValue() + "克");
|
||||
sugerText.setText(new Double(recommendFood.getMenu().getElements().getCarbohydrate()).intValue() + "克");
|
||||
// Logger.d(recommendFood.getMenu().getPractice());
|
||||
initList();
|
||||
initBMB();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,25 +105,55 @@ public class RecipeActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void initList() {
|
||||
ArrayList<Material> list = new ArrayList<>();
|
||||
for (int i = 0; i < 7; i++) {
|
||||
Material material = new Material("毛豆", 100);
|
||||
list.add(material);
|
||||
}
|
||||
ArrayList<String> mList = new ArrayList<>();
|
||||
for (int i = 0; i < 7; i++) {
|
||||
String step = "第一步";
|
||||
mList.add(step);
|
||||
}
|
||||
menu = new Menu("毛豆炒肉", list, mList);
|
||||
|
||||
makeStepAdapter = new MakeStepAdapter(menu.getMakeSteps(), this);
|
||||
detailWayRecyclerView.setAdapter(makeStepAdapter);
|
||||
detailWayRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
materialAdapter = new MaterialAdapter(menu.getMaterialArrayList(), this);
|
||||
materialAdapter = new MaterialAdapter(recommendFood.getMenu().getCook_quantity(), RecipeActivity.this);
|
||||
materialRecyclerView.setAdapter(materialAdapter);
|
||||
materialRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
materialRecyclerView.setLayoutManager(new LinearLayoutManager(RecipeActivity.this));
|
||||
materialRecyclerView.setNestedScrollingEnabled(false);
|
||||
|
||||
makeStepAdapter = new MakeStepAdapter(
|
||||
CalculateUtils.getStepArray(recommendFood.getMenu().getPractice()), RecipeActivity.this);
|
||||
detailWayRecyclerView.setLayoutManager(new LinearLayoutManager(RecipeActivity.this));
|
||||
detailWayRecyclerView.setAdapter(makeStepAdapter);
|
||||
detailWayRecyclerView.setNestedScrollingEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化悬浮按钮
|
||||
*/
|
||||
private void initBMB() {
|
||||
HamButton.Builder builder = new HamButton.Builder()
|
||||
.normalImageRes(R.drawable.ic_add_recipe)
|
||||
.normalTextRes(R.string.recipe_add_string)
|
||||
.listener(new OnBMClickListener() {
|
||||
@Override
|
||||
public void onBoomButtonClick(int index) {
|
||||
MessageUtils.MakeToast("已添加到记录");
|
||||
NutritionMaster.randomSeed = CalculateUtils.getSecond();
|
||||
|
||||
Element element = new Element(recommendFood.getMenu().getElements());
|
||||
NutritionMaster.user.getEaten_elements().add(element, 0.7f);
|
||||
|
||||
String username = NutritionMaster.user.getUsername();
|
||||
WebUtil.getInstance().addEatenHistory(username, recommendFood.getMenu().getName(), new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
boomMenuButton.addBuilder(builder);
|
||||
}
|
||||
|
||||
@OnClick(R.id.back_button)
|
||||
public void onViewClicked() {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -381,6 +389,9 @@ public class AddPhysiqueActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
physique = physiques[maxIndex];
|
||||
if (physique.equals("淤血质")) {
|
||||
physique = "瘀血质";
|
||||
}
|
||||
Logger.d(Arrays.toString(counter) + "\n" + physique);
|
||||
Physique phy = new Physique();
|
||||
phy.setPhysical_name(physique);
|
||||
@@ -393,6 +404,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
|
||||
|
||||
@@ -7,17 +7,18 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.ResultListAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class DishResultActivity extends BaseActivity {
|
||||
|
||||
@@ -35,13 +36,17 @@ public class DishResultActivity extends BaseActivity {
|
||||
Button okButton;
|
||||
|
||||
|
||||
private int flag = 0;
|
||||
private ArrayList<ClassifyResult> results;
|
||||
private ResultListAdapter resultListAdapter;
|
||||
private float wholesum;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
flag = 0;
|
||||
wholesum = 0 ;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,10 +58,7 @@ public class DishResultActivity extends BaseActivity {
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
Intent intent = getIntent();
|
||||
results = (ArrayList<ClassifyResult>) intent.getSerializableExtra("LIST");
|
||||
// for (int i = 0; i < results.size(); i++) {
|
||||
// Logger.d(results.get(i));
|
||||
// }
|
||||
// results = ConstantUtils.testData;
|
||||
|
||||
resultListAdapter = new ResultListAdapter(results, this);
|
||||
recyclerView.setAdapter(resultListAdapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
@@ -91,10 +93,44 @@ public class DishResultActivity extends BaseActivity {
|
||||
sugarSum += results.get(i).getFoodMenu().getElements().getCarbohydrate() * results.get(i).getQuantity() / 100;
|
||||
proteinSum += results.get(i).getFoodMenu().getElements().getProtein() * results.get(i).getQuantity() / 100;
|
||||
}
|
||||
if (flag == 0) {
|
||||
calorieSum = checkData((int) calorieSum);
|
||||
} else if (flag == -1) {
|
||||
|
||||
} else {
|
||||
calorieSum = calorieSum - flag * 300;
|
||||
}
|
||||
wholesum = calorieSum;
|
||||
calorie.setText((int) calorieSum + "");
|
||||
protein.setText((int) proteinSum + "");
|
||||
fat.setText((int) fatSum + "");
|
||||
suger.setText((int) sugarSum + "");
|
||||
}
|
||||
|
||||
@OnClick(R.id.ok_button)
|
||||
public void onViewClicked() {
|
||||
double tempCalorie = 0;
|
||||
MessageUtils.MakeToast("已将信息加入到已吃记录");
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
tempCalorie += NutritionMaster.user.getEaten_elements().getCalorie();
|
||||
results.get(i).getFoodMenu().getElements().setCalorie(0);
|
||||
NutritionMaster.user.getEaten_elements().add(new Element(results.get(i).getFoodMenu().getElements()),
|
||||
1.5f);
|
||||
}
|
||||
NutritionMaster.user.getEaten_elements().setCalorie(
|
||||
(int) (NutritionMaster.user.getEaten_elements().getCalorie() + wholesum));
|
||||
finish();
|
||||
}
|
||||
|
||||
private int checkData(int data) {
|
||||
if (data < 1000) {
|
||||
if (flag == 0) {
|
||||
flag = -1;
|
||||
}
|
||||
return data;
|
||||
} else {
|
||||
flag++;
|
||||
return checkData(data - 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,41 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.classifyresult;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.MaterialResultAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.MaterialResultHolder;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Material;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class MaterialResultActivity extends BaseActivity {
|
||||
|
||||
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
ArrayList<ClassifyResult> classifyResults;
|
||||
ArrayList<FoodMenu> list;
|
||||
private MaterialResultAdapter adapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_material_result;
|
||||
@@ -16,6 +43,15 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
Intent intent = getIntent();
|
||||
// classifyResults = (ArrayList<ClassifyResult>) intent.getSerializableExtra("LIST");
|
||||
// list = classifyResults.get(0).getFoodMaterial().getMenus();
|
||||
list= (ArrayList<FoodMenu>) intent.getSerializableExtra("LIST");
|
||||
adapter = new MaterialResultAdapter(list, MaterialResultActivity.this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setNestedScrollingEnabled(false);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(MaterialResultActivity.this));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,5 +63,15 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// TODO: add setContentView(...) invocation
|
||||
ButterKnife.bind(this);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.historysearch;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.HistoryAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.History;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class HistoryActivity extends BaseActivity {
|
||||
|
||||
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
private ArrayList<History> mList = new ArrayList<>();
|
||||
private HistoryAdapter adapter;
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_history;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
adapter = new HistoryAdapter(this, mList);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setNestedScrollingEnabled(false);
|
||||
loadData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
super.loadData();
|
||||
Logger.d(user.getUsername());
|
||||
getWebUtil().getEatenHistory(user.getUsername(), 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();
|
||||
History[] histories = new Gson().fromJson(json, History[].class);
|
||||
Logger.d(Arrays.toString(histories));
|
||||
mList.clear();
|
||||
for (History temp: histories) {
|
||||
|
||||
mList.add(temp);
|
||||
}
|
||||
|
||||
recyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// TODO: add setContentView(...) invocation
|
||||
ButterKnife.bind(this);
|
||||
}
|
||||
}
|
||||
@@ -9,17 +9,21 @@ import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
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.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;
|
||||
@@ -28,6 +32,7 @@ import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.Unbinder;
|
||||
import me.itangqi.waveloadingview.WaveLoadingView;
|
||||
|
||||
@@ -50,6 +55,8 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
TextView calorieText;
|
||||
@BindView(R.id.weight_text)
|
||||
TextView weightText;
|
||||
@BindView(R.id.see_whole_elements)
|
||||
LinearLayout seeWholeElements;
|
||||
|
||||
private int stepCount = 0;
|
||||
private static final int REFRESH_STEP_WHAT = 0;
|
||||
@@ -126,7 +133,17 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
* 改变记步UI中的数字
|
||||
*/
|
||||
private void updateStepCount() {
|
||||
stepTextView.setText(stepCount + "");
|
||||
try {
|
||||
stepTextView.setText(stepCount + "");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.see_whole_elements)
|
||||
public void onViewClicked() {
|
||||
AlertDialog dialog = new ElementDialog.Builder(getContext()).create();
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +185,7 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
ArrayList<Entry> weightPointValues = new ArrayList<>();
|
||||
for (int i = 1; i < 15; i++) {
|
||||
int y = (int) (Math.random() * 20);
|
||||
|
||||
weightPointValues.add(new Entry(i, y));
|
||||
}
|
||||
ChartDrawer.initSingleLineChart(weightLineChart, weightPointValues, "体重");
|
||||
@@ -180,6 +198,14 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
ChartDrawer.initSingleLineChart(stepLineChart, stepPointValues, "步数");
|
||||
}
|
||||
|
||||
private int checkY(int y) {
|
||||
if (y < 7) {
|
||||
return checkY((int) (Math.random() * 10));
|
||||
} else {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
@@ -189,11 +215,33 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
/**
|
||||
* 更新数据
|
||||
*/
|
||||
private void refreshUI() {
|
||||
public void refreshUI() {
|
||||
if (NutritionMaster.user.getBmi() != -1) {
|
||||
weightText.setText(NutritionMaster.user.getWeight());
|
||||
weightLineChart.setVisibility(View.VISIBLE);
|
||||
stepLineChart.setVisibility(View.VISIBLE);
|
||||
weightText.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
weightText.setText(NutritionMaster.user.getWeight() + "");
|
||||
}
|
||||
});
|
||||
}else{
|
||||
stepLineChart.setVisibility(View.INVISIBLE);
|
||||
weightLineChart.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
// waveLoadingView.setProgressValue();
|
||||
if (NutritionMaster.element != null) {
|
||||
Logger.d(NutritionMaster.element);
|
||||
try {
|
||||
Element elementTemp = NutritionMaster.element.calculateData(NutritionMaster.user);
|
||||
float temp = (float) (elementTemp.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie());
|
||||
calorieText.setText((int) temp + "");
|
||||
int progress = (int) (NutritionMaster.user.getEaten_elements().getCalorie() / elementTemp.getCalorie() * 100);
|
||||
waveLoadingView.setProgressValue(progress);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.bodyinformation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/8.
|
||||
*/
|
||||
|
||||
public class ElementDialog extends AlertDialog {
|
||||
protected ElementDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
protected ElementDialog(@NonNull Context context, int themeResId) {
|
||||
super(context, themeResId);
|
||||
}
|
||||
|
||||
protected ElementDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
|
||||
super(context, cancelable, cancelListener);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@BindView(R.id.calorie_tag)
|
||||
TextView calorieTag;
|
||||
@BindView(R.id.calorie_text)
|
||||
TextView calorieText;
|
||||
@BindView(R.id.suger_tag)
|
||||
TextView sugerTag;
|
||||
@BindView(R.id.suger_text)
|
||||
TextView sugerText;
|
||||
@BindView(R.id.fat_tag)
|
||||
TextView fatTag;
|
||||
@BindView(R.id.fat_text)
|
||||
TextView fatText;
|
||||
@BindView(R.id.protein_tag)
|
||||
TextView proteinTag;
|
||||
@BindView(R.id.protein_text)
|
||||
TextView proteinText;
|
||||
@BindView(R.id.cellulose_tag)
|
||||
TextView celluloseTag;
|
||||
@BindView(R.id.cellulose_text)
|
||||
TextView celluloseText;
|
||||
@BindView(R.id.vitamin_a_tag)
|
||||
TextView vitaminATag;
|
||||
@BindView(R.id.vitamin_a_text)
|
||||
TextView vitaminAText;
|
||||
@BindView(R.id.vitamin_b_1_tag)
|
||||
TextView vitaminB1Tag;
|
||||
@BindView(R.id.vitamin_b_1_text)
|
||||
TextView vitaminB1Text;
|
||||
@BindView(R.id.vitamin_b_2_tag)
|
||||
TextView vitaminB2Tag;
|
||||
@BindView(R.id.vitamin_b_2_text)
|
||||
TextView vitaminB2Text;
|
||||
@BindView(R.id.vitamin_b_6_tag)
|
||||
TextView vitaminB6Tag;
|
||||
@BindView(R.id.vitamin_b_6_text)
|
||||
TextView vitaminB6Text;
|
||||
@BindView(R.id.vitamin_c_tag)
|
||||
TextView vitaminCTag;
|
||||
@BindView(R.id.vitamin_c_text)
|
||||
TextView vitaminCText;
|
||||
@BindView(R.id.vitamin_e_tag)
|
||||
TextView vitaminETag;
|
||||
@BindView(R.id.vitamin_e_text)
|
||||
TextView vitaminEText;
|
||||
@BindView(R.id.carotene_tag)
|
||||
TextView caroteneTag;
|
||||
@BindView(R.id.carotene_text)
|
||||
TextView caroteneText;
|
||||
@BindView(R.id.cholesterol_tag)
|
||||
TextView cholesterolTag;
|
||||
@BindView(R.id.cholesterol_text)
|
||||
TextView cholesterolText;
|
||||
@BindView(R.id.ca_tag)
|
||||
TextView caTag;
|
||||
@BindView(R.id.ca_text)
|
||||
TextView caText;
|
||||
@BindView(R.id.na_tag)
|
||||
TextView naTag;
|
||||
@BindView(R.id.na_text)
|
||||
TextView naText;
|
||||
|
||||
private AlertDialog dialog;
|
||||
|
||||
public Builder(Context context) {
|
||||
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.element_dialog, null);
|
||||
dialog = new AlertDialog.Builder(context).setView(view).create();
|
||||
dialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
ButterKnife.bind(this, view);
|
||||
calorieText.setText((int) (NutritionMaster.user.getEaten_elements().getCalorie()) + "");
|
||||
sugerText.setText((int) (NutritionMaster.user.getEaten_elements().getCarbohydrate()) + "");
|
||||
fatText.setText((int) (NutritionMaster.user.getEaten_elements().getFat()) + "");
|
||||
proteinText.setText((int) NutritionMaster.user.getEaten_elements().getProtein() + "");
|
||||
celluloseText.setText((int) NutritionMaster.user.getEaten_elements().getCellulose() + "");
|
||||
vitaminAText.setText((int) NutritionMaster.user.getEaten_elements().getVitaminA() + "");
|
||||
vitaminB1Text.setText((int) NutritionMaster.user.getEaten_elements().getVitaminB1() + "");
|
||||
vitaminB2Text.setText((int) NutritionMaster.user.getEaten_elements().getVitaminB2() + "");
|
||||
vitaminB6Text.setText((int) NutritionMaster.user.getEaten_elements().getVitaminB6() + "");
|
||||
vitaminCText.setText((int) NutritionMaster.user.getEaten_elements().getVitaminC() + "");
|
||||
vitaminEText.setText((int) NutritionMaster.user.getEaten_elements().getVitaminE() + "");
|
||||
caroteneText.setText((int) NutritionMaster.user.getEaten_elements().getCarotene() + "");
|
||||
cholesterolText.setText((int) NutritionMaster.user.getEaten_elements().getCholesterol() + "");
|
||||
caText.setText((int) NutritionMaster.user.getEaten_elements().getCa() + "");
|
||||
naText.setText((int) NutritionMaster.user.getEaten_elements().getNa() + "");
|
||||
|
||||
}
|
||||
|
||||
public AlertDialog create() {
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,36 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.customization;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.CustomizationAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenuLight;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class CustomizationActivity extends BaseActivity {
|
||||
|
||||
@@ -43,11 +58,30 @@ public class CustomizationActivity extends BaseActivity {
|
||||
LinearLayout changeButton;
|
||||
@BindView(R.id.copy_button)
|
||||
LinearLayout copyButton;
|
||||
@BindView(R.id.tool_bar_title)
|
||||
TextView toolBarTitle;
|
||||
|
||||
private ArrayList<FoodMenu> breakfastList = new ArrayList<>();
|
||||
private ArrayList<FoodMenu> lunchList = new ArrayList<>();
|
||||
private ArrayList<FoodMenu> dinnerList = new ArrayList<>();
|
||||
|
||||
|
||||
private CustomizationAdapter breakfastAdapter;
|
||||
private CustomizationAdapter lunchAdapter;
|
||||
private CustomizationAdapter dinnerAdapter;
|
||||
|
||||
private int start;
|
||||
private String text;
|
||||
|
||||
private int breakfastCalorie = 0;
|
||||
private int lunchCalorie = 0;
|
||||
private int dinnerCalorie = 0;
|
||||
|
||||
private int suger = 0;
|
||||
private int protein = 0;
|
||||
private int fat = 0;
|
||||
private int calorie = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -61,9 +95,24 @@ public class CustomizationActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
loadData();
|
||||
String text = getIntent().getStringExtra("SEND_CODE");
|
||||
text = getIntent().getStringExtra("SEND_CODE");
|
||||
Logger.d(text);
|
||||
toolBarTitle.setText(text);
|
||||
|
||||
breakfastAdapter = new CustomizationAdapter(breakfastList, this, 0);
|
||||
dinnerAdapter = new CustomizationAdapter(dinnerList, this, 1);
|
||||
lunchAdapter = new CustomizationAdapter(lunchList, this, 2);
|
||||
|
||||
breakfastRecyclerView.setAdapter(breakfastAdapter);
|
||||
dinnerRecyclerView.setAdapter(dinnerAdapter);
|
||||
lunchRecyclerView.setAdapter(lunchAdapter);
|
||||
|
||||
breakfastRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
dinnerRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
lunchRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
loadData();
|
||||
refreshUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,6 +128,128 @@ public class CustomizationActivity extends BaseActivity {
|
||||
@Override
|
||||
public void loadData() {
|
||||
super.loadData();
|
||||
breakfastList.clear();
|
||||
dinnerList.clear();
|
||||
lunchList.clear();
|
||||
final WebUtil webUtil = WebUtil.getInstance();
|
||||
webUtil.getMenusByElements(getElementLimit(), 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();
|
||||
FoodMenuLight[] foodMenus = new Gson().fromJson(json, FoodMenuLight[].class);
|
||||
Logger.d(foodMenus.length);
|
||||
if (foodMenus.length > 50) {
|
||||
Random random = new Random(NutritionMaster.randomSeed + CalculateUtils.title2Int(text));
|
||||
start = random.nextInt(foodMenus.length - 50);
|
||||
for (int i = start; i < start + 50; i++) {
|
||||
webUtil.getMenu(foodMenus[i].getName(), 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();
|
||||
FoodMenu foodMenu = new Gson().fromJson(json, FoodMenu.class);
|
||||
if (foodMenu.getIs_breakfast() == 1) {
|
||||
if (breakfastList.size() < 1) {
|
||||
breakfastList.add(foodMenu);
|
||||
}
|
||||
} else {
|
||||
if (foodMenu.getName().contains("汤") || foodMenu.getName().contains("糕")
|
||||
|| foodMenu.getImage_url().equals("0") || foodMenu.getName().contains("汁")
|
||||
|| foodMenu.getName().contains("茶")) {
|
||||
|
||||
} else {
|
||||
if (lunchList.size() == 0) {
|
||||
lunchList.add(foodMenu);
|
||||
} else if (dinnerList.size() == 0) {
|
||||
dinnerList.add(foodMenu);
|
||||
} else if (lunchList.size() < 3) {
|
||||
lunchList.add(foodMenu);
|
||||
} else if (dinnerList.size() < 3) {
|
||||
dinnerList.add(foodMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lunchRecyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
breakfastAdapter.notifyDataSetChanged();
|
||||
dinnerAdapter.notifyDataSetChanged();
|
||||
lunchAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Random random = new Random(NutritionMaster.randomSeed + CalculateUtils.title2Int(text));
|
||||
start = random.nextInt(foodMenus.length);
|
||||
for (int i = start; i < start + 12; i++) {
|
||||
webUtil.getMenu(foodMenus[i].getName(), 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();
|
||||
FoodMenu foodMenu = new Gson().fromJson(json, FoodMenu.class);
|
||||
if (foodMenu.getIs_breakfast() == 1) {
|
||||
if (breakfastList.size() < 1) {
|
||||
breakfastList.add(foodMenu);
|
||||
}
|
||||
} else {
|
||||
if (foodMenu.getName().contains("汤") || foodMenu.getName().contains("糕")
|
||||
|| foodMenu.getImage_url().equals("0") || foodMenu.getName().contains("汁")
|
||||
|| foodMenu.getName().contains("茶")) {
|
||||
|
||||
} else {
|
||||
if (lunchList.size() == 0) {
|
||||
lunchList.add(foodMenu);
|
||||
} else if (dinnerList.size() == 0) {
|
||||
dinnerList.add(foodMenu);
|
||||
} else if (lunchList.size() < 3) {
|
||||
lunchList.add(foodMenu);
|
||||
} else if (dinnerList.size() < 3) {
|
||||
dinnerList.add(foodMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lunchRecyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
breakfastAdapter.notifyDataSetChanged();
|
||||
dinnerAdapter.notifyDataSetChanged();
|
||||
lunchAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -86,9 +257,79 @@ public class CustomizationActivity extends BaseActivity {
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.change_button:
|
||||
NutritionMaster.randomSeed = CalculateUtils.getSecond();
|
||||
loadData();
|
||||
break;
|
||||
case R.id.copy_button:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Double> getElementLimit() {
|
||||
Map<String, Double> params = new HashMap<>();
|
||||
try {
|
||||
Element calculated = NutritionMaster.element.calculateData(NutritionMaster.user);
|
||||
params.put("calorie", (calculated.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie()) / 4);
|
||||
params.put("fat", (calculated.getFat() - NutritionMaster.user.getEaten_elements().getFat()) / 4);
|
||||
|
||||
|
||||
// Logger.d((calculated.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie()));
|
||||
// Logger.d(calculated.getFat() - NutritionMaster.user.getEaten_elements().getFat());
|
||||
// Logger.d((calculated.getCarbohydrate() - NutritionMaster.user.getEaten_elements().getCarbohydrate()));
|
||||
// Logger.d(calculated.getProtein() - NutritionMaster.user.getEaten_elements().getProtein());
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载元素总量
|
||||
*/
|
||||
public void refreshUI() {
|
||||
// Logger.d(flag);
|
||||
// if (flag == 0) {
|
||||
// breakfastCalorie += calorie;
|
||||
// breakfastEnergyText.setText((int) breakfastCalorie + "千卡");
|
||||
// } else if (flag == 1) {
|
||||
// lunchCalorie += calorie;
|
||||
// lunchEnergyText.setText(lunchCalorie + "千卡");
|
||||
// } else {
|
||||
// dinnerCalorie += calorie;
|
||||
// dinnerEnergyText.setText(dinnerCalorie + "千卡");
|
||||
// }
|
||||
// calorieText.setText(breakfastCalorie + lunchCalorie + dinnerCalorie + "");
|
||||
// this.suger += suger;
|
||||
// this.fat += fat;
|
||||
// this.protein = protein;
|
||||
// sugerText.setText(this.suger + "");
|
||||
// fatText.setText(this.fat + "");
|
||||
// proteinText.setText(this.protein + "");
|
||||
try {
|
||||
Element element = NutritionMaster.element.calculateData(NutritionMaster.user);
|
||||
suger = (int) (element.getCarbohydrate() - NutritionMaster.user.getEaten_elements().getCarbohydrate());
|
||||
sugerText.setText(suger + "");
|
||||
fat = (int) (element.getFat() - NutritionMaster.user.getEaten_elements().getFat());
|
||||
fatText.setText(fat + "");
|
||||
calorie = (int) (element.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie());
|
||||
calorieText.setText(calorie + "");
|
||||
protein = (int) (element.getProtein() - NutritionMaster.user.getEaten_elements().getProtein());
|
||||
proteinText.setText(protein + "");
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加到饮食记录
|
||||
*/
|
||||
private void addRecord() {
|
||||
for (int i = 0; i < breakfastList.size(); i++) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.example.ninefourone.nutritionmaster.cardconfig.CardItemTouchCallBack;
|
||||
import com.example.ninefourone.nutritionmaster.cardconfig.SwipeCardLayoutManager;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -82,10 +83,11 @@ public class CustomizationFragment extends BaseFragment {
|
||||
protected void loadData() {
|
||||
super.loadData();
|
||||
for (int i = CalculateUtils.getWeek(); i <= 7; i++) {
|
||||
// Logger.d(CalculateUtils.getWeek());
|
||||
// mDataList.add("周" + ConstantUtils.arab2Chinese(i) + "美食普");
|
||||
DailyCard dailyCard = new DailyCard(
|
||||
"周" + ConstantUtils.arab2Chinese(i) + "美食普",
|
||||
ConstantUtils.dailyDescibes[i-1],
|
||||
"周" + ConstantUtils.arab2Chinese(i) + "美食谱",
|
||||
ConstantUtils.dailyDescibes[i - 1],
|
||||
picList[i - 1]
|
||||
);
|
||||
mDataList.add(dailyCard);
|
||||
@@ -93,8 +95,8 @@ public class CustomizationFragment extends BaseFragment {
|
||||
for (int i = 1; i < CalculateUtils.getWeek(); i++) {
|
||||
// mDataList.add("周" + ConstantUtils.arab2Chinese(i) + "美食普");
|
||||
DailyCard dailyCard = new DailyCard(
|
||||
"周" + ConstantUtils.arab2Chinese(i) + "美食普",
|
||||
ConstantUtils.dailyDescibes[i-1],
|
||||
"周" + ConstantUtils.arab2Chinese(i) + "美食谱",
|
||||
ConstantUtils.dailyDescibes[i - 1],
|
||||
picList[i - 1]
|
||||
);
|
||||
mDataList.add(dailyCard);
|
||||
|
||||
@@ -9,14 +9,19 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.RecommendAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseFragment;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Trick;
|
||||
import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
@@ -39,7 +44,7 @@ public class RecommendFragment extends BaseFragment {
|
||||
private RecommendAdapter adapter;
|
||||
private ArrayList<RecommendFood> datas = new ArrayList<>();
|
||||
private GridLayoutManager manager;
|
||||
private int[] indexs = new int[]{0, 1, 1, 2};
|
||||
private int[] indexs = new int[]{0, 1, 2};
|
||||
|
||||
|
||||
@Override
|
||||
@@ -49,8 +54,8 @@ public class RecommendFragment extends BaseFragment {
|
||||
|
||||
@Override
|
||||
public void initView(Bundle state) {
|
||||
loadData();
|
||||
initRecyclerView();
|
||||
loadData();
|
||||
}
|
||||
|
||||
|
||||
@@ -108,8 +113,7 @@ public class RecommendFragment extends BaseFragment {
|
||||
if (position == 0) {
|
||||
return 2;
|
||||
} else {
|
||||
if (adapter.getItemViewType(position) == RecommendFood.TYPE_BIG ||
|
||||
adapter.getItemViewType(position) == RecommendFood.TYPE_DETAIL) {
|
||||
if (adapter.getItemViewType(position) == RecommendFood.TYPE_DETAIL) {
|
||||
// Logger.d(manager.getSpanCount());
|
||||
return 2;
|
||||
} else {
|
||||
@@ -129,23 +133,127 @@ public class RecommendFragment extends BaseFragment {
|
||||
@Override
|
||||
protected void loadData() {
|
||||
super.loadData();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
int flag = indexs[i % 4];
|
||||
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", flag);
|
||||
datas.add(recommendFood);
|
||||
}
|
||||
// if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
getWebUtil().getRandomMenus(20, 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();
|
||||
FoodMenu[] menus = new Gson().fromJson(json, FoodMenu[].class);
|
||||
int count = 0;
|
||||
for (int i = 0; i < menus.length; i++) {
|
||||
if (count > 11) {
|
||||
break;
|
||||
} else {
|
||||
int flag = indexs[count % 3];
|
||||
RecommendFood recommendFood = new RecommendFood(menus[i], flag);
|
||||
if (!recommendFood.getPicture().equals("0")) {
|
||||
datas.add(recommendFood);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小知识
|
||||
*/
|
||||
getWebUtil().getRandomTricks(5, 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();
|
||||
Trick[] tricks = new Gson().fromJson(json, Trick[].class);
|
||||
int index = 0;
|
||||
for (int i = 0; i < datas.size(); i++) {
|
||||
if (datas.get(i).getItemType() == RecommendFood.TYPE_DETAIL) {
|
||||
datas.get(i).setDescription(tricks[index].getContent());
|
||||
datas.get(i).setTitle(tricks[index].getTitle());
|
||||
index++;
|
||||
}
|
||||
}
|
||||
recyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载新数据
|
||||
*/
|
||||
private void addData() {
|
||||
for (int i = 0; i < 7; i++) {
|
||||
int flag = indexs[i % 4];
|
||||
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", flag);
|
||||
adapter.getData().add(recommendFood);
|
||||
}
|
||||
adapter.loadMoreComplete();
|
||||
// if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
getWebUtil().getRandomMenus(20, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
final int originsize = datas.size();
|
||||
String json = response.body().string();
|
||||
FoodMenu[] menus = new Gson().fromJson(json, FoodMenu[].class);
|
||||
int count = 0;
|
||||
for (int i = 0; i < menus.length; i++) {
|
||||
if (count > 7) {
|
||||
break;
|
||||
} else {
|
||||
int flag = indexs[count % 3];
|
||||
RecommendFood recommendFood = new RecommendFood(menus[i], flag);
|
||||
if (!recommendFood.getPicture().equals("0")) {
|
||||
datas.add(recommendFood);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小知识
|
||||
*/
|
||||
getWebUtil().getRandomTricks(5, 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();
|
||||
Trick[] tricks = new Gson().fromJson(json, Trick[].class);
|
||||
int index = 0;
|
||||
for (int i = originsize; i < datas.size(); i++) {
|
||||
if (datas.get(i).getItemType() == RecommendFood.TYPE_DETAIL) {
|
||||
datas.get(i).setDescription(tricks[index].getContent());
|
||||
datas.get(i).setTitle(tricks[index].getTitle());
|
||||
index++;
|
||||
}
|
||||
}
|
||||
recyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.loadMoreComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
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.Illness;
|
||||
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;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/29.
|
||||
@@ -73,7 +81,43 @@ public class CalculateUtils {
|
||||
public static int getWeek() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
// Logger.d( calendar.get(Calendar.DAY_OF_WEEK));
|
||||
return calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
// calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
|
||||
int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
// Logger.d(week);
|
||||
if (week == 0) {
|
||||
return 7;
|
||||
}
|
||||
return week;
|
||||
}
|
||||
|
||||
public static int title2Int(String text) {
|
||||
String temp = text.substring(1, 2);
|
||||
Logger.d(temp);
|
||||
if (temp.equals("一")) {
|
||||
return 1;
|
||||
} else if (temp.equals("二")) {
|
||||
return 2;
|
||||
} else if (temp.equals("三")) {
|
||||
return 3;
|
||||
} else if (temp.equals("四")) {
|
||||
return 4;
|
||||
} else if (temp.equals("五")) {
|
||||
return 5;
|
||||
} else if (temp.equals("六")) {
|
||||
return 6;
|
||||
} else {
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得秒
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getSecond() {
|
||||
Calendar c = Calendar.getInstance();
|
||||
return c.get(Calendar.SECOND);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,4 +173,88 @@ public class CalculateUtils {
|
||||
}
|
||||
return classifyResultArrayList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 元素比例
|
||||
*
|
||||
* @param elementsBean
|
||||
* @return
|
||||
*/
|
||||
public static HashMap<String, Integer> elementsProportion(FoodMenu.ElementsBean elementsBean) {
|
||||
HashMap<String, Integer> map = new HashMap<>();
|
||||
Double suger = elementsBean.getCarbohydrate();
|
||||
Double fat = elementsBean.getFat();
|
||||
Double protein = elementsBean.getProtein();
|
||||
Double sum = fat + suger + protein;
|
||||
suger = suger / sum * 100;
|
||||
fat = fat / sum * 100;
|
||||
protein = protein / sum * 100;
|
||||
map.put("suger", suger.intValue());
|
||||
map.put("fat", fat.intValue());
|
||||
map.put("protein", protein.intValue());
|
||||
// Logger.d(elementsBean);
|
||||
// Logger.d(map.toString());
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将步骤字符串分解
|
||||
*
|
||||
* @param whole
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<String> getStepArray(String whole) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
String[] array = whole.split("'");
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i].equals("[") || array[i].equals("]") || array[i].equals(", ") ||
|
||||
array[i].equals(",") || array[i].equals(" ")) {
|
||||
|
||||
} else {
|
||||
list.add(array[i]);
|
||||
}
|
||||
}
|
||||
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());
|
||||
physiqueElement.add(occupationElement, 2);
|
||||
userElement.add(physiqueElement, -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;
|
||||
}
|
||||
|
||||
public static Element getElementsAddIllness(Illness illness, MyUser user, Occupation occupation, Physique physique) {
|
||||
Element userElement = new Element(user);
|
||||
Element occupationElement = new Element(occupation.getElements());
|
||||
Element illnessElement = new Element(occupation.getElements());
|
||||
Element physiqueElement = new Element(physique.getElements());
|
||||
physiqueElement.add(occupationElement, 2);
|
||||
physiqueElement.add(illnessElement, 1);
|
||||
userElement.add(physiqueElement, -1);
|
||||
return userElement;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class ChartDrawer {
|
||||
//设置竖线为虚线样式
|
||||
// xAxis.enableGridDashedLine(10f, 10f, 0f);
|
||||
//设置x轴标签数
|
||||
xAxis.setLabelCount(8,false);
|
||||
xAxis.setLabelCount(8, false);
|
||||
xAxis.setTextSize(5);
|
||||
//图表第一个和最后一个label数据不超出左边和右边的Y轴
|
||||
// xAxis.setAvoidFirstLastClipping(true);
|
||||
@@ -147,7 +147,7 @@ public class ChartDrawer {
|
||||
//准备好每个点对应的x轴数值
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int i = 0; i < pointValues.size(); i++) {
|
||||
list.add(String.valueOf(i+1).concat("号"));
|
||||
list.add(String.valueOf(i + 1).concat("号"));
|
||||
}
|
||||
xAxis.setValueFormatter(new IndexAxisValueFormatter(list));
|
||||
|
||||
@@ -158,7 +158,8 @@ public class ChartDrawer {
|
||||
rightAxis.setEnabled(false);
|
||||
YAxis leftAxis = mLineChart.getAxisLeft();
|
||||
leftAxis.setEnabled(false);
|
||||
leftAxis.setDrawAxisLine(false);
|
||||
leftAxis.setDrawAxisLine(true);
|
||||
rightAxis.setAxisMinimum(0);
|
||||
|
||||
//点构成的某条线
|
||||
LineDataSet lineDataSet = new LineDataSet(pointValues, "体重");
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.FormBody;
|
||||
@@ -47,32 +46,17 @@ public class WebUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取具体的菜谱信息
|
||||
* {
|
||||
* "flavor": "咸鲜味",
|
||||
* "calorie": 234,
|
||||
* "name": "雪丽对虾",
|
||||
* "technology": "炸",
|
||||
* "image_url": "http://s1.ig.meishij.net/p/20091012/fed63858e633540c8df73e62692520fb_150x150.jpg",
|
||||
* "cook_quantity": [
|
||||
* {
|
||||
* "menu": "雪丽对虾",
|
||||
* "quantity": "500",
|
||||
* "material": "对虾"
|
||||
* },
|
||||
* {
|
||||
* "menu": "雪丽对虾",
|
||||
* "quantity": "60",
|
||||
* "material": "鸡蛋清"
|
||||
* },
|
||||
* }
|
||||
* 获取具体的菜谱信息 { "flavor": "咸鲜味", "calorie": 234, "name": "雪丽对虾", "technology":
|
||||
* "炸", "image_url":
|
||||
* "http://s1.ig.meishij.net/p/20091012/fed63858e633540c8df73e62692520fb_150x150.jpg",
|
||||
* "cook_quantity": [ { "menu": "雪丽对虾", "quantity": "500", "material": "对虾" }, {
|
||||
* "menu": "雪丽对虾", "quantity": "60", "material": "鸡蛋清" }, }
|
||||
*/
|
||||
public void getMenu(String menuName, Callback callback) {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/menus/" + menuName + "/").build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取count个随机菜谱,在回调中解析为一个Menu数组
|
||||
*
|
||||
@@ -80,7 +64,21 @@ public class WebUtil {
|
||||
* @param callback
|
||||
*/
|
||||
public void getRandomMenus(int count, Callback callback) {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/menus/get_random_menus/?count=" + String.valueOf(count)).build();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://120.77.182.38/menus/get_random_menus/?count=" + String.valueOf(count)).build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取count个随机菜谱,在回调中解析为一个Menu数组 根据用户的体质,病理,职业推荐
|
||||
*
|
||||
* @param count
|
||||
* @param callback
|
||||
*/
|
||||
public void getRandomMenus(int count, String username, Callback callback) {
|
||||
Request request = new Request.Builder().url(
|
||||
"http://120.77.182.38/menus/get_random_menus/?count=" + String.valueOf(count) + "&username=" + username)
|
||||
.build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
@@ -91,30 +89,15 @@ public class WebUtil {
|
||||
* @param callback
|
||||
*/
|
||||
public void getRandomTricks(int count, Callback callback) {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/trick/get_random_tricks/?count=" + String.valueOf(count)).build();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://120.77.182.38/trick/get_random_tricks/?count=" + String.valueOf(count)).build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取某食材可以做的菜
|
||||
* [
|
||||
* {
|
||||
* "menu": "西红柿鸡蛋汤",
|
||||
* "quantity": "适量",
|
||||
* "material": "西红柿"
|
||||
* },
|
||||
* {
|
||||
* "menu": "瘦身版红菜汤",
|
||||
* "quantity": "4-5片",
|
||||
* "material": "西红柿"
|
||||
* },
|
||||
* {
|
||||
* "menu": "西红柿炖豆腐",
|
||||
* "quantity": "三个",
|
||||
* "material": "西红柿"
|
||||
* },
|
||||
* ]
|
||||
* 获取某食材可以做的菜 [ { "menu": "西红柿鸡蛋汤", "quantity": "适量", "material": "西红柿" }, {
|
||||
* "menu": "瘦身版红菜汤", "quantity": "4-5片", "material": "西红柿" }, { "menu":
|
||||
* "西红柿炖豆腐", "quantity": "三个", "material": "西红柿" }, ]
|
||||
*
|
||||
* @param materialName
|
||||
* @param callback
|
||||
@@ -125,65 +108,33 @@ public class WebUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某菜谱分类对应的菜
|
||||
* {
|
||||
* "classification": "川菜",
|
||||
* "cure_occupation": [],
|
||||
* "menu_effect": [
|
||||
* "三色鲍脯",
|
||||
* "三色鸡酪",
|
||||
* "三菇冬瓜汤",
|
||||
* "三菌烩蛇段",
|
||||
* "三鲜乌鱼汤",
|
||||
* "三鲜参片汤",
|
||||
* "三鲜猪肝汤",
|
||||
* "下饭的素版麻婆豆腐",
|
||||
* "丝瓜鱼肚卷",
|
||||
* "五更豆酥鱼",
|
||||
* "元鱼烧鸡",
|
||||
* "冬苋菜豆腐汤",
|
||||
* "冬菜排骨汤",
|
||||
* 获取某菜谱分类对应的菜 { "classification": "川菜", "cure_occupation": [], "menu_effect": [
|
||||
* "三色鲍脯", "三色鸡酪", "三菇冬瓜汤", "三菌烩蛇段", "三鲜乌鱼汤", "三鲜参片汤", "三鲜猪肝汤", "下饭的素版麻婆豆腐",
|
||||
* "丝瓜鱼肚卷", "五更豆酥鱼", "元鱼烧鸡", "冬苋菜豆腐汤", "冬菜排骨汤",
|
||||
*/
|
||||
public void getMenuClassification(String classificationName, Callback callback) {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/menuclassification/" + classificationName + "/").build();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://120.77.182.38/menuclassification/" + classificationName + "/").build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取职业需要的菜谱分类
|
||||
* {
|
||||
* "occupation_name": "电力工程师",
|
||||
* "menuclassification_set": [
|
||||
* "接触电离辐射人员食谱",
|
||||
* "防癌抗癌食谱",
|
||||
* "明目食谱",
|
||||
* "关节炎食谱",
|
||||
* "壮腰健肾食谱"
|
||||
* ]
|
||||
* }
|
||||
* 获取职业需要的菜谱分类 { "occupation_name": "电力工程师", "menuclassification_set": [
|
||||
* "接触电离辐射人员食谱", "防癌抗癌食谱", "明目食谱", "关节炎食谱", "壮腰健肾食谱" ] }
|
||||
*/
|
||||
public void getOccupation(String occupationName, Callback callback) {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/occupation/" + occupationName + "/").build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
public static void getAllOccupations(Callback callback) {
|
||||
OkHttpClient mClient = new OkHttpClient();
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/occupation/").build();
|
||||
Request request = null;
|
||||
if (occupationName == null) {
|
||||
request = new Request.Builder().url("http://120.77.182.38/occupation/").build();
|
||||
} else {
|
||||
request = new Request.Builder().url("http://120.77.182.38/occupation/" + occupationName + "/").build();
|
||||
}
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取体质需要的食材
|
||||
* {
|
||||
* "physical_name": "气虚质",
|
||||
* "cure_material": [
|
||||
* "人参",
|
||||
* "人参须",
|
||||
* "去芯莲子",
|
||||
* "去芯莲子(3~4人份)",
|
||||
* "土茯苓",
|
||||
* ...
|
||||
* ]
|
||||
* }
|
||||
* 获取体质需要的食材 { "physical_name": "气虚质", "cure_material": [ "人参", "人参须", "去芯莲子",
|
||||
* "去芯莲子(3~4人份)", "土茯苓", ... ] }
|
||||
*/
|
||||
public void getPhysique(String physiqueName, Callback callback) {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/physique/" + physiqueName + "/").build();
|
||||
@@ -191,30 +142,21 @@ public class WebUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取病相关的菜谱和元素信息
|
||||
* 传入含有病的意义的菜谱分类名称,比如青少年食谱
|
||||
* 获取病相关的菜谱和元素信息 传入含有病的意义的菜谱分类名称,比如青少年食谱
|
||||
* <p>
|
||||
* {
|
||||
* "menu_classification": {
|
||||
* "classification": "青少年食谱",
|
||||
* "cure_occupation": [
|
||||
* "学生"
|
||||
* ],
|
||||
* "menu_effect": [
|
||||
* "三鲜鳝汤",
|
||||
* "上海糖醋小排骨",
|
||||
* ...
|
||||
* ]
|
||||
* },
|
||||
* "elements": {
|
||||
* "id": 84,
|
||||
* "calorie": 1.1,
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* { "menu_classification": { "classification": "青少年食谱", "cure_occupation": [
|
||||
* "学生" ], "menu_effect": [ "三鲜鳝汤", "上海糖醋小排骨", ... ] }, "elements": { "id": 84,
|
||||
* "calorie": 1.1, ... } }
|
||||
*/
|
||||
public void getIllness(String illnessClassification, Callback callback) {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/illness/" + illnessClassification + "/").build();
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/illness/" + illnessClassification + "/")
|
||||
.build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
public static void getAllOccupations(Callback callback) {
|
||||
OkHttpClient mClient = new OkHttpClient();
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/occupation/").build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
@@ -224,103 +166,125 @@ public class WebUtil {
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
public static String HttpPost(String requestUrl, String accessToken, String params) throws Exception {
|
||||
System.out.println(params);
|
||||
String generalUrl = "";
|
||||
generalUrl = requestUrl + "?access_token=" + accessToken;
|
||||
System.out.println("发送的连接为:" + generalUrl);
|
||||
URL url = new URL(generalUrl);
|
||||
// 打开和URL之间的连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
System.out.println("打开链接,开始发送请求" + new Date().getTime() / 1000);
|
||||
connection.setRequestMethod("POST");
|
||||
// 设置通用的请求属性
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("Connection", "Keep-Alive");
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
|
||||
// 得到请求的输出流对象
|
||||
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
|
||||
out.writeBytes(params);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
// 建立实际的连接
|
||||
connection.connect();
|
||||
// 获取所有响应头字段
|
||||
Map<String, List<String>> headers = connection.getHeaderFields();
|
||||
// 遍历所有的响应头字段
|
||||
for (String key : headers.keySet()) {
|
||||
System.out.println(key + "--->" + headers.get(key));
|
||||
}
|
||||
// 定义 BufferedReader输入流来读取URL的响应
|
||||
BufferedReader in = null;
|
||||
if (requestUrl.contains("nlp"))
|
||||
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "GBK"));
|
||||
else
|
||||
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||
String result = "";
|
||||
String getLine;
|
||||
while ((getLine = in.readLine()) != null) {
|
||||
result += getLine;
|
||||
}
|
||||
in.close();
|
||||
System.out.println("请求结束" + new Date().getTime() / 1000);
|
||||
System.out.println("result:" + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注意在回调中处理username重复的情况
|
||||
*//*
|
||||
public static void postUser(String username, String password, String sex, @Nullable String occupationName, @Nullable String physicalName, Callback callback) {
|
||||
RequestBody formBody = new FormBody.Builder()
|
||||
.add("username", username)
|
||||
.add("password", password)
|
||||
.add("sex", sex)
|
||||
.add("occupation_name", occupationName == null ? "" : occupationName)
|
||||
.add("physical_name", physicalName == null ? "" : physicalName)
|
||||
.build();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://120.77.182.38/myuser/")
|
||||
.post(formBody)
|
||||
.build();
|
||||
* public static void postUser(String username, String password, String
|
||||
* sex, @Nullable String occupationName, @Nullable String physicalName, Callback
|
||||
* callback) { RequestBody formBody = new FormBody.Builder() .add("username",
|
||||
* username) .add("password", password) .add("sex", sex) .add("occupation_name",
|
||||
* occupationName == null ? "" : occupationName) .add("physical_name",
|
||||
* physicalName == null ? "" : physicalName) .build(); Request request = new
|
||||
* Request.Builder() .url("http://120.77.182.38/myuser/") .post(formBody)
|
||||
* .build();
|
||||
*
|
||||
* OkHttpClient mClient = new OkHttpClient();
|
||||
* mClient.newCall(request).enqueue(callback); }
|
||||
*/
|
||||
|
||||
OkHttpClient mClient = new OkHttpClient();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}*/
|
||||
|
||||
/*public static void changeUserPassword(String username, String password, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/" + username + "/";
|
||||
RequestBody formBody = new FormBody.Builder()
|
||||
.add("username", username)
|
||||
.add("password", password)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.patch(formBody)
|
||||
.build();
|
||||
|
||||
OkHttpClient mClient = new OkHttpClient();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
*//**
|
||||
* 修改职业
|
||||
* 传入职业名称参数
|
||||
*//*
|
||||
public static void changeUserOccupation(String username, String occupation, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/" + username + "/";
|
||||
RequestBody formBody = new FormBody.Builder()
|
||||
.add("username", username)
|
||||
.add("occupation", occupation)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.patch(formBody)
|
||||
.build();
|
||||
|
||||
OkHttpClient mClient = new OkHttpClient();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
*//**
|
||||
* 修改体质
|
||||
*
|
||||
* @param physique 体质名称
|
||||
*//*
|
||||
public static void changeUserPhysique(String username, String physique, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/" + username + "/";
|
||||
RequestBody formBody = new FormBody.Builder()
|
||||
.add("username", username)
|
||||
.add("physique", physique)
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.patch(formBody)
|
||||
.build();
|
||||
|
||||
OkHttpClient mClient = new OkHttpClient();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
* public static void changeUserPassword(String username, String password,
|
||||
* Callback callback) { String url = "http://120.77.182.38/myuser/" + username +
|
||||
* "/"; RequestBody formBody = new FormBody.Builder() .add("username", username)
|
||||
* .add("password", password) .build();
|
||||
*
|
||||
* Request request = new Request.Builder() .url(url) .patch(formBody) .build();
|
||||
*
|
||||
* OkHttpClient mClient = new OkHttpClient();
|
||||
* mClient.newCall(request).enqueue(callback); }
|
||||
*
|
||||
*//**
|
||||
* 修改职业 传入职业名称参数
|
||||
*/
|
||||
/*
|
||||
* public static void changeUserOccupation(String username, String occupation,
|
||||
* Callback callback) { String url = "http://120.77.182.38/myuser/" + username +
|
||||
* "/"; RequestBody formBody = new FormBody.Builder() .add("username", username)
|
||||
* .add("occupation", occupation) .build();
|
||||
*
|
||||
* Request request = new Request.Builder() .url(url) .patch(formBody) .build();
|
||||
*
|
||||
* OkHttpClient mClient = new OkHttpClient();
|
||||
* mClient.newCall(request).enqueue(callback); }
|
||||
*
|
||||
*//**
|
||||
* 修改体质
|
||||
*
|
||||
* @param physique 体质名称
|
||||
*//*
|
||||
* public static void changeUserPhysique(String username, String physique,
|
||||
* Callback callback) { String url = "http://120.77.182.38/myuser/" + username +
|
||||
* "/"; RequestBody formBody = new FormBody.Builder() .add("username", username)
|
||||
* .add("physique", physique) .build();
|
||||
*
|
||||
* Request request = new Request.Builder() .url(url) .patch(formBody) .build();
|
||||
*
|
||||
* OkHttpClient mClient = new OkHttpClient();
|
||||
* mClient.newCall(request).enqueue(callback); }
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* public static void changeUserIllness(String username, String[] illnesses, Callback callback) {
|
||||
* String url = "http://120.77.182.38/myuser/" + username + "/";
|
||||
* public static void changeUserIllness(String username, String[] illnesses,
|
||||
* Callback callback) { String url = "http://120.77.182.38/myuser/" + username +
|
||||
* "/";
|
||||
* <p>
|
||||
* FormBody.Builder builder = new FormBody.Builder();
|
||||
* for (String illness : illnesses) {
|
||||
* builder.add("illness", illness);
|
||||
* }
|
||||
* RequestBody formBody = builder.build();
|
||||
* FormBody.Builder builder = new FormBody.Builder(); for (String illness :
|
||||
* illnesses) { builder.add("illness", illness); } RequestBody formBody =
|
||||
* builder.build();
|
||||
* <p>
|
||||
* Request request = new Request.Builder()
|
||||
* .url(url)
|
||||
* .patch(formBody)
|
||||
* .build();
|
||||
* Request request = new Request.Builder() .url(url) .patch(formBody) .build();
|
||||
* <p>
|
||||
* OkHttpClient mClient = new OkHttpClient();
|
||||
* mClient.newCall(request).enqueue(callback);
|
||||
* }
|
||||
* mClient.newCall(request).enqueue(callback); }
|
||||
*/
|
||||
private static RequestBody buildUserRequestBody(MyUser user) {
|
||||
try {
|
||||
@@ -331,9 +295,9 @@ public class WebUtil {
|
||||
for (Field f : fields) {
|
||||
String fieldName = f.toString().substring(f.toString().lastIndexOf(".") + 1);
|
||||
f.setAccessible(true);
|
||||
Object object = f.get(user);//获取属性的值
|
||||
Object object = f.get(user);// 获取属性的值
|
||||
if (object != null) {
|
||||
//illness属性是一个list,需要加入每个list的值,而不是list对象
|
||||
// illness属性是一个list,需要加入每个list的值,而不是list对象
|
||||
if (fieldName.equals("illness")) {
|
||||
List<String> illnessList = (List<String>) object;
|
||||
for (String ill : illnessList) {
|
||||
@@ -346,12 +310,12 @@ public class WebUtil {
|
||||
}
|
||||
}
|
||||
RequestBody formBody = builder.build();
|
||||
// for (int i = 0; i < ((FormBody) formBody).size(); i++) {
|
||||
// System.out.println(((FormBody) formBody).name(i) + " : " + ((FormBody) formBody).value(i));
|
||||
// }
|
||||
// for (int i = 0; i < ((FormBody) formBody).size(); i++) {
|
||||
// System.out.println(((FormBody) formBody).name(i) + " : " + ((FormBody)
|
||||
// formBody).value(i));
|
||||
// }
|
||||
return formBody;
|
||||
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
@@ -368,10 +332,7 @@ public class WebUtil {
|
||||
public void createUser(MyUser user, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/";
|
||||
RequestBody formBody = buildUserRequestBody(user);
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(formBody)
|
||||
.build();
|
||||
Request request = new Request.Builder().url(url).post(formBody).build();
|
||||
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
@@ -384,31 +345,26 @@ public class WebUtil {
|
||||
public void changeUserInfo(MyUser user, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/" + user.getUsername() + "/";
|
||||
RequestBody formBody = buildUserRequestBody(user);
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.patch(formBody)
|
||||
.build();
|
||||
Request request = new Request.Builder().url(url).patch(formBody).build();
|
||||
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户吃了一个菜,更新用户本周已吃摄入的营养元素的量
|
||||
* 返回当前user的最新信息,用MyUser类解析json
|
||||
*
|
||||
* @param username
|
||||
* @param menuName
|
||||
* 用户吃了一个菜,更新用户本周已吃摄入的营养元素的量 传入这顿饭摄入的营养量 返回当前user的最新信息,用MyUser类解析json
|
||||
*/
|
||||
public void eatenMenu(String username, String menuName, Callback callback) {
|
||||
public void eatenElements(String username, Map<String, Double> elements, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/eaten_menu/";
|
||||
RequestBody formBody = new FormBody.Builder()
|
||||
.add("username", username)
|
||||
.add("menu_name", menuName)
|
||||
.build();
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(formBody)
|
||||
.build();
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
// 构造RequestBody参数
|
||||
for (Map.Entry<String, Double> entry : elements.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
double value = entry.getValue();
|
||||
builder.add(key, String.valueOf(value));
|
||||
}
|
||||
builder.add("username", username);
|
||||
RequestBody formBody = builder.build();
|
||||
Request request = new Request.Builder().url(url).post(formBody).build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
@@ -420,17 +376,14 @@ public class WebUtil {
|
||||
public void getMenusByElements(Map<String, Double> elements, Callback callback) {
|
||||
String url = "http://120.77.182.38/menus/get_menus_by_elements/";
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
//构造RequestBody参数
|
||||
// 构造RequestBody参数
|
||||
for (Map.Entry<String, Double> entry : elements.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
double value = entry.getValue();
|
||||
builder.add(key, String.valueOf(value));
|
||||
}
|
||||
RequestBody formBody = builder.build();
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(formBody)
|
||||
.build();
|
||||
Request request = new Request.Builder().url(url).post(formBody).build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
//
|
||||
@@ -482,52 +435,29 @@ public class WebUtil {
|
||||
// return result;
|
||||
// }
|
||||
|
||||
public static String HttpPost(String requestUrl, String accessToken, String params) throws Exception {
|
||||
System.out.println(params);
|
||||
String generalUrl = "";
|
||||
generalUrl = requestUrl + "?access_token=" + accessToken;
|
||||
System.out.println("发送的连接为:" + generalUrl);
|
||||
URL url = new URL(generalUrl);
|
||||
// 打开和URL之间的连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
System.out.println("打开链接,开始发送请求" + new Date().getTime() / 1000);
|
||||
connection.setRequestMethod("POST");
|
||||
// 设置通用的请求属性
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("Connection", "Keep-Alive");
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
public void addEatenHistory(String username, String menuName, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/add_eaten_history/";
|
||||
RequestBody formBody = new FormBody.Builder().add("username", username).add("menu", menuName).build();
|
||||
Request request = new Request.Builder().url(url).post(formBody).build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
// 得到请求的输出流对象
|
||||
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
|
||||
out.writeBytes(params);
|
||||
out.flush();
|
||||
out.close();
|
||||
public void getEatenHistory(String username, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/get_eaten_history?username=" + username;
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
// 建立实际的连接
|
||||
connection.connect();
|
||||
// 获取所有响应头字段
|
||||
Map<String, List<String>> headers = connection.getHeaderFields();
|
||||
// 遍历所有的响应头字段
|
||||
for (String key : headers.keySet()) {
|
||||
System.out.println(key + "--->" + headers.get(key));
|
||||
public void getMenusByMaterials(List<String> materialList, Callback callback) {
|
||||
// POST
|
||||
String url = "http://120.77.182.38/menus/get_menus_by_materials/";
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
for (String material : materialList) {
|
||||
builder.add("material", material);
|
||||
}
|
||||
// 定义 BufferedReader输入流来读取URL的响应
|
||||
BufferedReader in = null;
|
||||
if (requestUrl.contains("nlp"))
|
||||
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "GBK"));
|
||||
else
|
||||
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||
String result = "";
|
||||
String getLine;
|
||||
while ((getLine = in.readLine()) != null) {
|
||||
result += getLine;
|
||||
}
|
||||
in.close();
|
||||
System.out.println("请求结束" + new Date().getTime() / 1000);
|
||||
System.out.println("result:" + result);
|
||||
return result;
|
||||
RequestBody formBody = builder.build();
|
||||
Request request = new Request.Builder().url(url).post(formBody).build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
Map<String, Double> params = new HashMap<>();
|
||||
@@ -543,13 +473,14 @@ public class WebUtil {
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
System.out.println(json);
|
||||
//轻量级的Menu,只有Menu的名字,卡路里,元素对象的主码id.想获取详细信息可以用getMenu方法获取
|
||||
//这样是为了查询更快
|
||||
// 轻量级的Menu,只有Menu的名字,卡路里,元素对象的主码id.想获取详细信息可以用getMenu方法获取
|
||||
// 这样是为了查询更快
|
||||
FoodMenuLight[] foodMenuLights = new Gson().fromJson(json, FoodMenuLight[].class);
|
||||
System.out.println(Arrays.toString(foodMenuLights));
|
||||
}
|
||||
});
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
/*
|
||||
MyUser testUser = new MyUser();
|
||||
@@ -726,6 +657,8 @@ public class WebUtil {
|
||||
}
|
||||
});*/
|
||||
|
||||
=======
|
||||
>>>>>>> develop
|
||||
/*
|
||||
* MyUser testUser = new MyUser(); testUser.setUsername("test6");
|
||||
* testUser.setPassword("66666"); testUser.setAge(8); testUser.setHeight(175);
|
||||
@@ -806,7 +739,10 @@ public class WebUtil {
|
||||
* } });
|
||||
*/
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> develop
|
||||
/*
|
||||
* WebUtil.getFoodMaterial("西红柿", new Callback() {
|
||||
*
|
||||
@@ -881,6 +817,9 @@ public class WebUtil {
|
||||
* @Override public void onResponse(Call call, Response response) throws
|
||||
* IOException { System.out.println(response.body().string()); } });
|
||||
*/
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> develop
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 783 KiB |
8
app/src/main/res/drawable/ic_add_recipe.xml
Normal file
8
app/src/main/res/drawable/ic_add_recipe.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<vector android:height="24dp" android:viewportHeight="1024.0"
|
||||
android:viewportWidth="1024.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FFFFFF" android:pathData="M566.1,781.8c-20.9,3 -42.7,4.5 -65,4.5 -22.3,0 -44.1,-1.5 -65,-4.5V801c0,16 -12.9,28.9 -28.9,28.9h-57.8c-16,0 -28.9,-12.9 -28.9,-28.9v-56c-64.8,-35.4 -108.4,-93.2 -114.8,-172.2h-29.4c-16.1,0 -29.2,-13.1 -29.2,-29.2s13.1,-29.2 29.2,-29.2h31.3c19.7,-135.3 143.6,-239.6 293.5,-239.6 44.2,0 86.1,9 123.7,25.3l53.6,-49.2c5.9,-5.4 15,-5 20.4,0.9 3,3.3 4.3,7.7 3.6,12.1l-12.3,74.7c35,27.2 63.1,61.7 81.8,101.1h54.3c16,0 28.9,12.9 28.9,28.9v144.5c0,16 -12.9,28.9 -28.9,28.9h-46.7c-19.4,44.4 -53.7,78.9 -97.8,103v56c0,16 -12.9,28.9 -28.9,28.9H595c-16,0 -28.9,-12.9 -28.9,-28.9v-19.2z"/>
|
||||
<path android:fillColor="#2F2F33" android:pathData="M652.8,887.7L595,887.7c-32.1,0 -60.5,-17.2 -75.5,-43.9 -12.2,0.4 -24.6,0.4 -36.9,0 -15,26.7 -43.4,43.9 -75.5,43.9h-57.8c-47.8,0 -86.7,-38.9 -86.7,-86.7v-23.9c-53.3,-37.4 -89.5,-88.2 -105.8,-148.6 -38.7,-8.8 -67.6,-43.5 -67.6,-84.8 0,-42.9 31.2,-78.6 72,-85.7 43.6,-140.8 183,-240.9 339.8,-240.9 37.9,0 75,5.6 110.6,16.7l27.7,-25.4c14.2,-13 32.5,-19.8 52,-18.9 19.3,0.8 37.1,9.1 50.1,23.3 15.1,16.5 21.7,38.6 18.1,60.6l-7.1,42.8C773.2,335.9 791.2,358 806.1,381.9h20.1c47.8,0 86.7,38.9 86.7,86.7v144.5c0,47.8 -38.9,86.7 -86.7,86.7L814,699.8c-18.9,29.9 -43.9,55.8 -74.5,77.3L739.5,801c0,47.8 -38.8,86.7 -86.7,86.7zM561.3,783.2l5.5,24.3c2.9,13 14.8,22.5 28.2,22.5h57.8c15.9,0 28.9,-13 28.9,-28.9v-55.4l13.6,-8.5c33.7,-21.1 59.5,-48 76.8,-79.9l8.2,-15.1h45.9c15.9,0 28.9,-13 28.9,-28.9L855.1,468.6c0,-15.9 -13,-28.9 -28.9,-28.9h-53.7l-8.2,-14.9c-15.8,-28.5 -36.6,-54.1 -61.9,-76.1l-12.2,-10.6 12.3,-74.2c0.7,-4.4 -0.6,-8.8 -3.6,-12.1 -3.5,-3.9 -7.8,-4.6 -10,-4.7 -2.4,-0.1 -6.5,0.3 -10.4,3.8l-53.2,48.8 -16.5,-6c-34.3,-12.5 -70.5,-18.9 -107.6,-18.9 -138,0 -259.6,91.4 -289.3,217.3l-5.2,22.3h-30.3c-16.1,0 -29.2,13.1 -29.2,29.2s13.1,29.2 29.2,29.2h28.2l4.4,23.6c10.9,58.7 44.8,107.3 98.1,140.6l13.6,8.5L320.7,801c0,15.9 13,28.9 28.9,28.9h57.8c13.4,0 25.2,-9.4 28.2,-22.5l5.5,-24.3 24.8,1.8c23.1,1.7 47.7,1.7 70.8,0l24.6,-1.7z"/>
|
||||
<path android:fillColor="#F5BF0D" android:pathData="M479.4,266.3m-130,0a130,130 0,1 0,260 0,130 130,0 1,0 -260,0Z"/>
|
||||
<path android:fillColor="#2F2F33" android:pathData="M479.4,425.3c-87.6,0 -158.9,-71.3 -158.9,-158.9s71.3,-158.9 158.9,-158.9 158.9,71.3 158.9,158.9 -71.2,158.9 -158.9,158.9zM479.4,165.2c-55.8,0 -101.1,45.4 -101.1,101.1s45.4,101.1 101.1,101.1S580.5,322 580.5,266.3s-45.3,-101.1 -101.1,-101.1z"/>
|
||||
<path android:fillColor="#2F2F33" android:pathData="M667.3,497.5m-43.3,0a43.3,43.3 0,1 0,86.6 0,43.3 43.3,0 1,0 -86.6,0Z"/>
|
||||
</vector>
|
||||
7
app/src/main/res/drawable/ic_ill_add_button.xml
Normal file
7
app/src/main/res/drawable/ic_ill_add_button.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<vector android:height="24dp" android:viewportHeight="1024.0"
|
||||
android:viewportWidth="1024.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#ffffff" android:pathData="M596.8,277.8c-45.2,-63 -132.8,-77.2 -195.8,-32s-77.2,132.8 -32,195.8 132.8,77.4 195.8,32.2c63,-45.4 77.4,-133.2 32,-196zM585.2,616c-33,23.6 -40.6,69.6 -16.8,102.6s69.8,40.4 102.6,16.8c33,-23.6 40.6,-69.6 16.8,-102.6 -23.8,-33.2 -69.6,-40.6 -102.6,-16.8zM293.4,584.4c-40.6,29.2 -49.8,85.6 -20.6,126.2 29.2,40.6 85.6,49.8 126.2,20.6 40.6,-29.2 49.8,-85.8 20.6,-126.2 -29.2,-40.6 -85.8,-49.8 -126.2,-20.6zM713.2,460.8c-16.2,11.6 -19.8,34 -8.2,50.2 11.6,16.2 34,19.8 50.2,8.2 16.2,-11.6 19.8,-34 8.2,-50.2 -11.6,-16 -34,-19.8 -50.2,-8.2z"/>
|
||||
<path android:fillColor="#ffffff" android:pathData="M518.6,798m-25,0a25,25 0,1 0,50 0,25 25,0 1,0 -50,0Z"/>
|
||||
<path android:fillColor="#ffffff" android:pathData="M193.6,469.8c-13.2,9.6 -16.4,28 -6.8,41.4 9.6,13.2 28.2,16.4 41.4,6.8 13.2,-9.6 16.4,-28.2 6.8,-41.4 -9.6,-13.4 -28.2,-16.4 -41.4,-6.8zM724.6,276.2c9,-6.6 11.2,-19.2 4.6,-28.4 -6.6,-9 -19.2,-11.2 -28.4,-4.6s-11.2,19.2 -4.6,28.4 19.2,11.2 28.4,4.6z"/>
|
||||
<path android:fillColor="#ffffff" android:pathData="M982.6,472.8l-44,-0.2c-4.4,-45 -15.8,-88.2 -33.2,-128l53.2,-30.8v-0.2c0.4,-0.2 0.6,-0.4 1,-0.4 19.8,-11.6 26.6,-36.8 15.2,-56.6 -11.6,-19.8 -36.8,-26.6 -56.6,-15.2 -0.4,0.2 -0.6,0.4 -0.8,0.6l-52,30c-28.4,-41 -63.8,-76.8 -104.2,-105.8L789,118h-0.2c11.4,-19.8 4.6,-45 -15.2,-56.4 -19.8,-11.4 -45.2,-4.6 -56.6,15.2 -0.2,0.2 -0.2,0.6 -0.4,0.8l-27.4,47.6c-43,-19.4 -89.6,-32 -138.6,-36.2L550.6,42.6C550.6,19.6 532,1.2 509.2,1.2c-22.8,0 -41.4,18.6 -41.4,41.4v47c-45.8,4.8 -89.4,17 -129.6,35.2l-27.6,-48c-11.6,-19.8 -36.8,-26.6 -56.6,-15.2 -19.8,11.6 -26.6,36.8 -15.2,56.6L266.4,166C226.8,194.2 192,228.8 164,268.6l-45.6,-26.4c-19.8,-11.4 -45.2,-4.6 -56.6,15.2 -11.4,19.8 -4.6,45.2 15.2,56.6l46,26.6c-18.4,41 -30.4,85.4 -35.2,132L41,472.6v0.6C18.4,473.4 0,491.8 0,514.6 0,537.6 18.6,556 41.4,556c1.8,0 3.4,-0.2 5,-0.4L88,555.6c4,42.2 14.2,82.6 29.6,120.4l-50.6,29.2c-19.8,11.6 -26.6,36.8 -15.2,56.6 11.6,19.8 36.8,26.6 56.6,15.2L156,749.2c24,36.6 53.6,69.2 87.4,97l-32.6,56.4c-11.4,19.8 -4.6,45.2 15.2,56.6 19.8,11.4 45.2,4.6 56.6,-15.2l29.8,-51.8c47,25.2 99.6,41.8 155.2,47.6v44.4h0.4c1.6,21.4 19.2,38.4 41,38.4s39.4,-17 41,-38.4h0.4v-43.8c57.4,-5 111.6,-21.2 160.2,-46.6l28.8,50c11.6,19.8 36.8,26.6 56.6,15.2 19.8,-11.6 26.6,-36.8 15.2,-56.6l-31,-54c34.2,-27.4 64.4,-60 88.8,-96.6l48,27.6v-0.2c0.4,0.2 0.4,0.4 0.8,0.6 19.8,11.4 45.2,4.6 56.6,-15.2 11.4,-19.8 4.6,-45.2 -15.2,-56.6 -0.4,-0.2 -0.6,-0.2 -1,-0.4v-0.2l-50.4,-29c16.2,-38.6 26.6,-79.8 30.8,-123.2h44c23,0 41.4,-18.6 41.4,-41.4 0,-22.4 -18.6,-41 -41.4,-41zM513.2,884.8c-204.4,0 -370,-165.6 -370,-370 0,-57 13,-111.2 36.2,-159.4l28.4,-49.2c66.6,-97.4 178.6,-161.4 305.4,-161.4 204.4,0 370,165.6 370,370 0.2,204.2 -165.6,370 -370,370z"/>
|
||||
</vector>
|
||||
@@ -8,6 +8,26 @@
|
||||
tools:context="com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.customization.CustomizationActivity">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:background="@color/colorPrimary"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tool_bar_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:textColor="#fff"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="@string/app_name" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
@@ -18,12 +38,12 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#fff"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:background="#08d966"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
@@ -32,7 +52,7 @@
|
||||
android:layout_marginLeft="15dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="早餐"
|
||||
android:textColor="#fff"
|
||||
android:textColor="#181818"
|
||||
android:textSize="17sp" />
|
||||
|
||||
|
||||
@@ -51,15 +71,16 @@
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/breakfast_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#eae8e8">
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:background="#f4f2f2"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:background="#08d966"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
@@ -68,7 +89,7 @@
|
||||
android:layout_marginLeft="15dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="午餐"
|
||||
android:textColor="#fff"
|
||||
android:textColor="#1a1919"
|
||||
android:textSize="17sp" />
|
||||
|
||||
|
||||
@@ -87,15 +108,16 @@
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/lunch_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#eae8e8">
|
||||
android:layout_height="230dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:background="#f4f2f2"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:background="#08d966"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
@@ -104,7 +126,7 @@
|
||||
android:layout_marginLeft="15dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="晚餐"
|
||||
android:textColor="#fff"
|
||||
android:textColor="#161616"
|
||||
android:textSize="17sp" />
|
||||
|
||||
|
||||
@@ -123,8 +145,10 @@
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/dinner_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#eae8e8">
|
||||
android:layout_height="230dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:background="#f4f2f2"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
|
||||
16
app/src/main/res/layout/activity_history.xml
Normal file
16
app/src/main/res/layout/activity_history.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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"
|
||||
tools:context="com.example.ninefourone.nutritionmaster.modules.historysearch.HistoryActivity">
|
||||
|
||||
<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>
|
||||
@@ -110,6 +110,7 @@
|
||||
android:layout_alignParentRight="true"
|
||||
app:bmb_buttonEnum="ham"
|
||||
app:bmb_buttonPlaceEnum="buttonPlace_ham_2"
|
||||
app:bmb_normalColor="#8cbc79"
|
||||
app:bmb_piecePlaceEnum="piecePlace_ham_2" />
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -177,6 +178,8 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
<ImageView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
@@ -185,6 +188,18 @@
|
||||
android:alpha="0.2"
|
||||
android:src="@drawable/icon_black" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ill_button"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_toLeftOf="@id/add_information_button"
|
||||
android:background="@drawable/ic_ill_add_button"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/add_information_button"
|
||||
android:layout_width="30dp"
|
||||
@@ -205,20 +220,6 @@
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ill_button"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginRight="35dp"
|
||||
android:alpha="0.3"
|
||||
android:background="@drawable/ic_ill"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:background="#ededed"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout 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"
|
||||
@@ -7,261 +7,295 @@
|
||||
<!--clipToPadding = false-->
|
||||
<!--令布局可以延伸到状态栏-->
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="250dp">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
app:layout_collapseMode="parallax"
|
||||
app:layout_scrollFlags="scroll|enterAlways">
|
||||
android:layout_height="250dp">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
app:layout_collapseMode="parallax"
|
||||
app:layout_scrollFlags="scroll|enterAlways">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1.5"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp" />
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="90dp"
|
||||
app:cardCornerRadius="10dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitXY" />
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center"
|
||||
android:textColor="#FFF"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="2"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp">
|
||||
|
||||
<TextView
|
||||
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:text="营养成分"
|
||||
android:textColor="#fff"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:textColor="#fff"
|
||||
android:layout_marginRight="10dp"
|
||||
android:text="单位:每100克"
|
||||
android:textSize="10sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="10dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.lzyzsd.circleprogress.ArcProgress
|
||||
android:id="@+id/protein_circle"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_margin="5dp"
|
||||
app:arc_bottom_text="蛋白质"
|
||||
app:arc_progress="50"
|
||||
app:arc_suffix_text_size="12sp"
|
||||
app:arc_text_size="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/protein_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="4.1克"
|
||||
android:textColor="#fff"
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.lzyzsd.circleprogress.ArcProgress
|
||||
android:id="@+id/fat_circle"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_margin="5dp"
|
||||
app:arc_bottom_text="脂肪"
|
||||
app:arc_progress="50"
|
||||
app:arc_suffix_text_size="12sp"
|
||||
app:arc_text_size="12sp" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fat_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#fff"
|
||||
android:text="4.1克"
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.lzyzsd.circleprogress.ArcProgress
|
||||
android:id="@+id/carbohydrate_circle"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_margin="5dp"
|
||||
app:arc_bottom_text="糖分"
|
||||
app:arc_progress="50"
|
||||
app:arc_suffix_text_size="12sp"
|
||||
app:arc_text_size="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/suger_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="4.1克"
|
||||
android:textColor="#fff"
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_button"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:src="@drawable/ic_back_button_white" />
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#FFF"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1.5"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp" />
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="90dp"
|
||||
app:cardCornerRadius="10dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/food_test" />
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center"
|
||||
android:text="红烧肉"
|
||||
android:textColor="#FFF"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="2"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:text="营养成分"
|
||||
android:textColor="#000000"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginRight="10dp"
|
||||
android:text="单位:每100克"
|
||||
android:textSize="10sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="10dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.lzyzsd.circleprogress.ArcProgress
|
||||
android:id="@+id/protein_circle"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_margin="5dp"
|
||||
app:arc_bottom_text="测试"
|
||||
app:arc_progress="50"
|
||||
app:arc_suffix_text_size="12sp"
|
||||
app:arc_text_size="12sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="4.1克"
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.lzyzsd.circleprogress.ArcProgress
|
||||
android:id="@+id/fat_circle"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_margin="5dp"
|
||||
app:arc_bottom_text="测试"
|
||||
app:arc_progress="50"
|
||||
app:arc_suffix_text_size="12sp"
|
||||
app:arc_text_size="12sp" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="4.1克"
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.lzyzsd.circleprogress.ArcProgress
|
||||
android:id="@+id/carbohydrate_circle"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_margin="5dp"
|
||||
app:arc_bottom_text="测试"
|
||||
app:arc_progress="50"
|
||||
app:arc_suffix_text_size="12sp"
|
||||
app:arc_text_size="12sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="4.1克"
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_fortune_cookie" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="原料与做法"
|
||||
android:textColor="#131313"
|
||||
android:textSize="13sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:src="@drawable/ic_back_button_white" />
|
||||
</RelativeLayout>
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#FFF"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_fortune_cookie" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="原料与做法"
|
||||
android:textColor="#131313"
|
||||
android:textSize="13sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<LinearLayout
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:id="@+id/nestedScrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<RelativeLayout
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:background="#FFF"
|
||||
android:gravity="center_vertical">
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:background="#FFF"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="主要材料"
|
||||
android:textColor="#000000"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
</RelativeLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/material_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#ffffff">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:background="#FFF"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="详细步骤"
|
||||
android:textColor="#000000"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
</RelativeLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/detail_way_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#ffffff">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="主要材料"
|
||||
android:textColor="#000000"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
</RelativeLayout>
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/material_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:background="#FFF"
|
||||
android:gravity="center_vertical">
|
||||
<com.nightonke.boommenu.BoomMenuButton
|
||||
android:id="@+id/boom_menu_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
app:bmb_buttonEnum="ham"
|
||||
app:bmb_buttonPlaceEnum="buttonPlace_ham_1"
|
||||
app:bmb_normalColor="#8cbc79"
|
||||
app:bmb_piecePlaceEnum="piecePlace_ham_1" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="详细步骤"
|
||||
android:textColor="#000000"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
</RelativeLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/detail_way_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@
|
||||
android:src="@drawable/ic_infor_weight" />
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
@@ -329,6 +330,43 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/see_whole_elements"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/infor_layout_height"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/all_elements"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:src="@drawable/ic_add_recipe" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginLeft="50dp"
|
||||
android:layout_toRightOf="@id/all_elements"
|
||||
android:gravity="center"
|
||||
android:text="点击查看所有元素信息" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_below="@id/all_elements"
|
||||
android:layout_marginTop="15dp"
|
||||
android:alpha="0.7"
|
||||
android:background="@color/place_holder" />
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
@@ -4,10 +4,11 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:layout_margin="5dp"
|
||||
android:layout_margin="2dp"
|
||||
app:cardCornerRadius="15dp">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/click"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@@ -68,6 +69,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_toLeftOf="@id/arch"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="11sp"
|
||||
tools:text="365千卡" />
|
||||
</RelativeLayout>
|
||||
|
||||
413
app/src/main/res/layout/element_dialog.xml
Normal file
413
app/src/main/res/layout/element_dialog.xml
Normal file
@@ -0,0 +1,413 @@
|
||||
<?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="300dp"
|
||||
android:layout_height="400dp"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical"
|
||||
app:cardCornerRadius="25dp">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#d1efc5"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="所有已吃元素信息" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="卡里路" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/calorie_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="千卡" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/calorie_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/calorie_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="糖分" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/suger_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/suger_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/suger_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="脂肪" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fat_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fat_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/fat_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="蛋白质" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/protein_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/protein_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/protein_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="纤维素" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cellulose_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cellulose_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/cellulose_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="维生素A" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_a_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="微克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_a_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/vitamin_a_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="维生素B1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_b_1_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="微克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_b_1_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/vitamin_b_1_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="维生素B2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_b_2_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="微克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_b_2_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/vitamin_b_2_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="维生素B6" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_b_6_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="微克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_b_6_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/vitamin_b_6_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="维生素C" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_c_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="微克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_c_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/vitamin_c_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="维生素E" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_e_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="毫克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/vitamin_e_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/vitamin_e_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="胡萝卜素" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/carotene_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="微克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/carotene_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/carotene_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="胆固醇" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cholesterol_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="毫克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cholesterol_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/cholesterol_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="钙" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ca_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="毫克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ca_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/ca_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="钠" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/na_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="毫克" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/na_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@id/na_tag"
|
||||
tools:text="123" />
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
@@ -3,14 +3,17 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#f9f9f6"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/make_step_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="10dp"
|
||||
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="#212121"
|
||||
tools:text="@string/app_name" />
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:background="#f9f9f6"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
@@ -31,7 +32,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginRight="15dp"
|
||||
android:text="克"
|
||||
android:textColor="#131212"
|
||||
android:textSize="13sp" />
|
||||
|
||||
|
||||
32
app/src/main/res/layout/material_result_item.xml
Normal file
32
app/src/main/res/layout/material_result_item.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:background="#fff"
|
||||
android:layout_margin="5dp"
|
||||
android:id="@+id/whole_layout"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
app:cardCornerRadius="10dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:scaleType="centerCrop" />
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="15dp"
|
||||
android:text="哈哈哈"
|
||||
android:textSize="15sp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,45 +0,0 @@
|
||||
<?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="@dimen/recommend_item_big_height"
|
||||
android:layout_margin="@dimen/recommend_margin"
|
||||
app:cardElevation="0dp"
|
||||
app:cardCornerRadius="20dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/whole_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/recommend_item_imageview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="3"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@drawable/food_test" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recommend_item_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="红烧肉" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
@@ -11,9 +11,9 @@
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="@dimen/recommend_item_default_hight"
|
||||
android:layout_height="@dimen/recommend_item_default_hight"
|
||||
app:cardElevation="0dp"
|
||||
android:layout_marginRight="5dp"
|
||||
app:cardCornerRadius="20dp">
|
||||
app:cardCornerRadius="20dp"
|
||||
app:cardElevation="0dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/recommend_item_imageview"
|
||||
@@ -29,23 +29,26 @@
|
||||
android:layout_marginLeft="5dp"
|
||||
app:cardCornerRadius="20dp">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:background="#dcffe1"
|
||||
android:id="@+id/detail_click"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#f3f9de"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="15dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:paddingTop="15dp">
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recommend_item_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="红烧肉" />
|
||||
android:gravity="center_horizontal"
|
||||
android:text="小知识"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recommend_item_description"
|
||||
@@ -55,5 +58,6 @@
|
||||
android:textSize="12sp"
|
||||
tools:text="红烧肉是最美味的菜了!超级好吃!" />
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
</LinearLayout>
|
||||
@@ -27,7 +27,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
@@ -35,8 +35,9 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:textSize="14sp"
|
||||
android:textSize="13sp"
|
||||
android:textStyle="bold"
|
||||
android:background="#f3f9de"
|
||||
tools:text="红烧肉" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<string name="food_meterial_title">食材识别</string>
|
||||
<string name="food_title">菜品识别</string>
|
||||
<string name="title_activity_login">登录</string>
|
||||
<string name="recipe_add_string">是否添加到已吃记录</string>
|
||||
|
||||
<!-- Strings related to login -->
|
||||
<string name="prompt_email">Email</string>
|
||||
|
||||
BIN
datas/早中晚餐.rar
Normal file
BIN
datas/早中晚餐.rar
Normal file
Binary file not shown.
3
文档.md
Normal file
3
文档.md
Normal file
@@ -0,0 +1,3 @@
|
||||
我们用Django框架来编写服务器后台逻辑,我们收集的数据集包含的大量数据经过我们筛选、补充缺失、规整化后有序存储到Mysql数据库,可以方便地进行安全验证后的增删改查。我们使用django-rest-framework框架,实现了前后端分离,把数据库映射对象序列化后构造为json字符串和安卓端进行交互,有效降低了代码的耦合性,项目维护和更新更加方便。服务器利用Nginx和uWSGI实现HTTP重定向,可以在高并发下实现负载均衡,承受万数量级以上的并发量。
|
||||
|
||||
安全性方面,我们使用跨站点请求伪造(CSRF)方法保护数据库不受恶意的CSRF攻击,通过在每个POST请求中检查一个随机数来确保恶意用户无法简单地通过发送表单POST请求影响数据库。另外,在发送包含用户的隐私数据时(比如密码或者身高体重等信息),我们使用PBKDF2和SHA256算法对数据先加密后才存储到数据库,保证用户的隐私数据不会泄露。
|
||||
3
服务器文档.md
Normal file
3
服务器文档.md
Normal file
@@ -0,0 +1,3 @@
|
||||
我们用Django框架来编写服务器后台逻辑,我们收集的数据集包含的大量数据经过我们筛选、补充缺失、规整化后有序存储到Mysql数据库,可以方便地进行安全验证后的增删改查。我们使用django-rest-framework框架,实现了前后端分离,把数据库映射对象序列化后构造为json字符串和安卓端进行交互,有效降低了代码的耦合性,项目维护和更新更加方便。服务器利用Nginx和uWSGI实现HTTP重定向,可以在高并发下实现负载均衡,承受万数量级以上的并发量。
|
||||
|
||||
安全性方面,我们使用跨站点请求伪造(CSRF)方法保护数据库不受恶意的CSRF攻击,通过在每个POST请求中检查一个随机数来确保恶意用户无法简单地通过发送表单POST请求影响数据库。另外,在发送包含用户的隐私数据时(比如密码或者身高体重等信息),我们使用PBKDF2和SHA256算法对数据先加密后才存储到数据库,保证用户的隐私数据不会泄露。
|
||||
Reference in New Issue
Block a user