Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92ee55ad2d | ||
|
|
b8507aa536 | ||
|
|
1c55b40f9e | ||
|
|
a5e5c526a9 | ||
|
|
f9ed1012f2 | ||
|
|
d140116e1f | ||
|
|
a36b92d7f2 | ||
|
|
e86e8c4c4e | ||
|
|
f935532b22 | ||
|
|
5bcb752a6b | ||
|
|
af70737e6e | ||
|
|
deefa86cd3 | ||
|
|
be3abe90b1 | ||
|
|
e9f7839348 | ||
|
|
f207ad2768 | ||
|
|
d8ae182023 | ||
|
|
87c2335b4c | ||
|
|
711494fdd0 | ||
|
|
8f8a98a775 | ||
|
|
028fc613b8 | ||
|
|
9708b65292 | ||
|
|
31d3171102 | ||
|
|
a0d34e04d9 | ||
|
|
a19f3347b7 | ||
|
|
18d04a3a78 | ||
|
|
a02323d7be | ||
|
|
a5acd866c6 | ||
|
|
a7dd7fb69c | ||
|
|
57b9bcfd4c | ||
|
|
ae3451f4ca | ||
|
|
bcb948de95 | ||
|
|
d79cf541aa | ||
|
|
a0db58816b | ||
|
|
0b1f2d9772 | ||
|
|
1e15caa3dc | ||
|
|
d12c53f519 |
0
.gitignore → NutritionMaster/.gitignore
vendored
405
NutritionMaster/README.md
Normal file
@@ -0,0 +1,405 @@
|
||||
|
||||
## 营养大师
|
||||
|
||||
一款基于数据分析的智能饮食推荐APP
|
||||
|
||||
仓库地址: https://github.com/wangtianrui/NutritionMaster
|
||||
|
||||
### 数据分析
|
||||
|
||||
* 人体健康信息
|
||||
* 体重
|
||||
* 身高
|
||||
* 年龄
|
||||
* 菜品信息
|
||||
* 菜的名称
|
||||
* 卡路里
|
||||
* 蛋白质,脂肪等
|
||||
* 推荐的食用量
|
||||
* 某个人群对应的改善体质(减肥,塑性,增肌等)的方案
|
||||
* 菜谱
|
||||
* 运动方式
|
||||
|
||||
### 数据集和api
|
||||
|
||||
**赵励志收集的资料**
|
||||
|
||||
* 图像识别食物,获取卡路里: https://cloud.baidu.com/product/imagerecognition/fine_grained
|
||||
* **nutrition facts** from food : https://www.kaggle.com/openfoodfacts/world-food-facts#en.openfoodfacts.org.products.tsv
|
||||
* https://world.openfoodfacts.org/ 数据集官网
|
||||
* 456赞,目前为止发现的最高的相关数据集
|
||||
* nutrition facts for **McDonald’s** : https://www.kaggle.com/mcdonalds/nutrition-facts
|
||||
* Calories, fat, and sugar for every cheeseburger, fries, and milkshake on menu
|
||||
* 更牛逼的食材分析和菜谱推荐: http://pic2recipe.csail.mit.edu/ 加强版百度API
|
||||
* 莫须有数据集
|
||||
* 糖尿病 时间-血糖含量关系数据 : https://archive.ics.uci.edu/ml/datasets/diabetes
|
||||
* GPA和饮食习惯的关系 : https://www.kaggle.com/borapajo/food-choices
|
||||
|
||||
**王天锐收集的资料**
|
||||
|
||||
0、9种体质 //暂定
|
||||
1、根据用户的体质来进行推荐菜谱与制定营养计划 ---- 两种模式:9体模式和普通健身模式
|
||||
2、用户可以随时输入自己当前吃的食物的名字与量 ---- 随时记
|
||||
3、动态爬虫——http://www.boohee.com/ 每种食材的卡路里等信息(优先kaggle)
|
||||
4、卡路里累加器及其可视化、每天个人信息可视化
|
||||
5、https://www.xinshipu.com/ 菜谱信息
|
||||
6、通过照片提取出食物的卡路里等信息 百度api
|
||||
7、http://www.zyyssl.com/cookbook.html //中药食材信息、药膳信息、9体、各种病针对的药膳
|
||||
8、照片识菜帮
|
||||
9、http://www.ttmeishi.com/CaiXi/YaoShan/ //病人对应的食谱
|
||||
10、测算http://www.chinacaipu.com/zt/sccs.html 体质算法
|
||||
11、http://www.chinacaipu.com/menu/jianya/ 特殊人群(压力之类的)
|
||||
|
||||
|
||||
|
||||
### 需求分析
|
||||
|
||||
* 登陆、注册
|
||||
* 输入基本信息信息(身高、体重、性别、年龄)
|
||||
* 额外信息(工作、周均运动时间、睡眠段、九体、病史)
|
||||
* 针对没有填写额外信息的用户:选择减肥、增肌、塑形 、保持
|
||||
* 可视化(自己的信息和目标标准的比较、根据上述选择改变)每天的量(手环、手机计步器),近几天的曲线
|
||||
* 推荐菜谱:两个tab,一个定制菜谱,一个是随机智能推送
|
||||
* 单一菜推荐
|
||||
* 组合推荐
|
||||
* 一周大菜谱推荐(根据每日你自己加的一些信息动态改变)
|
||||
* 如果填了额外信息的,就是药膳推荐(一周药膳、周二普通、周三药膳。。。。)(注意可能不想减肥啥的)
|
||||
* 百度api->动态录入每顿饭的信息(防抖处理,这里吹牛逼算法,推测吃了多少卡路里),识别后把,动态改变一周定制计划
|
||||
* 做菜环节加入识菜帮所有功能,并加入详细食材信息卡路里等
|
||||
* 针对特殊人群,混到推荐里推送有利于健康的**方法**信息(敷黄瓜方法)
|
||||
* 特殊病人群体每日相关东西的摄取量的一个限定区间显示
|
||||
* ocr体检单信息录入
|
||||
* **针对照片中菜的数量分析吃了多少菜,包含多少卡路里**
|
||||
|
||||
|
||||
|
||||
### 10-6更新:小细节
|
||||
|
||||
* BMI小数
|
||||
* 需不需要为每个用户加一个用于存放一周定制的类,(这个应该不是特别需要,只是想想)
|
||||
* 模糊搜索
|
||||
* 食材对应menu
|
||||
|
||||
|
||||
|
||||
#### 24日更新内容
|
||||
|
||||
|
||||
|
||||
粉尘接触得多的 吃纤维素
|
||||
|
||||
* 职业,某种病对各种物质的需求
|
||||
* 修改职业,病(一些菜谱分类),体质 表
|
||||
* 把职业分为几类(多动的,少动的)用于BMI标准
|
||||
* https://www.google.com/search?q=%E8%90%A5%E5%85%BB%E5%85%83%E7%B4%A0%E9%9C%80%E6%B1%82&oq=%E8%90%A5%E5%85%BB%E5%85%83%E7%B4%A0&aqs=chrome.1.69i57j69i59j0l4.5781j0j1&sourceid=chrome&ie=UTF-8
|
||||
* 职业\病\九体\体质(BMI) 结合起来的**物质需求标准** (要求有 **卡路里** 六芒星),以周为单位计算需求量
|
||||
* 特殊职业(比如运动员)对身体素质(BMI)标准
|
||||
* 早 中晚餐分类:
|
||||
* 早: 饼 粥 羹 面 奶
|
||||
* **加入季节方案(比如夏天就推荐防暑的,冬天推荐暖身的)**
|
||||
* 蒋:
|
||||
* 补充菜谱: url补充缺失值,卡路里,热量,脂肪,蛋白质等
|
||||
* 爬卡路里时,原来的菜名是一列,新爬到的是一列,后面几列就是卡路里,脂肪等,注意数据规整
|
||||
* 爬不到就先空下,根据食材的信息计算
|
||||
* 食材的信息(包括卡路里等)
|
||||
* http://www.boohee.com/food/search?keyword=%E8%8C%B6%E5%8F%B6%EF%BC%88%E7%BA%A650%E5%85%8B%EF%BC%89
|
||||
* 菜谱的简单介绍
|
||||
* 浏览记录(post username和menuname和时间)
|
||||
|
||||
王:定制( 需要蒋给我比如:蛋白质在100-200范围内的菜谱)
|
||||
|
||||
蒋:
|
||||
|
||||
* 体质表: 添加几列对某种物质的需求 √
|
||||
|
||||
* 职业表: 添加几列对某种物质的需求,添加一列BMI的需求 √
|
||||
|
||||
* user表: 添加综合对物质的需求 √
|
||||
|
||||
* 菜单表:
|
||||
* 添加一列早/午晚餐,早为1,else为0. 根据 饼 粥 羹 面 奶 判断
|
||||
* 补充一下缺失的url,卡路里 √
|
||||
* 添加几列各种物质的需求 √
|
||||
* 有一部分数据是爬下的csv里面直接读取,一部分缺失的用food_material的组合来计算
|
||||
|
||||
* **对接任务**: 接口使用方法可以参尻main函数里面的注释和数据库ER图
|
||||
|
||||
* WebUtil改成了单例,一些方法注意一下
|
||||
|
||||
* 注册: `createUser`.注意年龄应该让用户填出生年,获取年龄时每次都根据年份计算一下
|
||||
|
||||
* 直接set设置用户的各种信息,不需要的就空着不用set,特殊的一点是病有多个值,要用一个List
|
||||
|
||||

|
||||
|
||||
* 修改用户信息 `changeUserInfo`,注意username必须设置,其他的是需要改的值.**修改会覆盖之前的内容**.比如用户之前illness是健忘食谱,想增加一个高血压食谱, 就需要把之前的也写上,就是一起传 `健忘食谱,高血压食谱`这两个参数.写到List里面. 具体参考main函数里面的
|
||||
|
||||
* 获取九体信息 `getPhysique`方法
|
||||
|
||||
* 获取用户营养元素所需的量: 先`getUser`获取到用户的病/职业/体质名字,然后根据这些名字查询每个 病/职业/体质信息对应的元素需求,最后加权计算 (这里是不是麻烦了点?)
|
||||
|
||||
* 用户职业BMI分类 3多动,2中等,1少动 先 `getUser`获取到用户的职业名字.然后`getOccupation`获取到该职业的BMI分类
|
||||
|
||||
* 动态改变用户已吃的营养元素的量: 在用户表添加element参数,每周自动清空一次
|
||||
|
||||
* 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]`
|
||||
|
||||
```java
|
||||
public static void main(String[] args) {
|
||||
//首先构造一个Map, key是参数的名字,value是参数的值.用不到的参数不用写.
|
||||
//我在服务器端根据这些参数构造一个sql,就是 ... WHERE key1 <= val1 AND ...这样的.
|
||||
//所以你只传入需要作为搜索条件的参数就可以了.
|
||||
Map<String, Double> params = new HashMap<>();
|
||||
params.put("calorie", 100.0);
|
||||
params.put("fat", 10.0);
|
||||
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();
|
||||
System.out.println(json);
|
||||
//用轻量级的菜单类MenuLight解析json,这个类只有Menu的[名字,卡路里,元素对象的主码id]这三个域.想获取详细信息可以用getMenu方法获取
|
||||
//这样是为了查询更快
|
||||
FoodMenuLight[] foodMenuLights = new Gson().fromJson(json, FoodMenuLight[].class);
|
||||
System.out.println(Arrays.toString(foodMenuLights));
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
* **季节搜菜**
|
||||
|
||||
* 小知识获取 : `getRandomTricks`
|
||||
|
||||
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
#### 又想到的补充内容
|
||||
|
||||
- 根据口味推荐,或者口味混合搭配推荐
|
||||
- 注意冬天不推荐夏天的菜谱
|
||||
|
||||
### 数据库设计
|
||||
|
||||

|
||||
|
||||
**加下划线为主码,加粗为外码,默认not null**
|
||||
|
||||
* **菜谱**(<u>str菜名</u>, **nullable str体质_名称**(对应最优菜谱的效果) ,int卡路里,int制作时间(分钟),str口味,str工艺,str做法,str图片url)
|
||||
* menu
|
||||
* **食材**( <u>str名称</u>)
|
||||
* material
|
||||
* **体质**(<u>str体质名称</u>,str体质特点,str运动调理方式)
|
||||
* physique
|
||||
* **体质性状**(<u>str性状名称</u>)
|
||||
* Physical properties
|
||||
* **菜谱功能和分类**( <u>str分类名称</u>)
|
||||
* menu classification
|
||||
* **用户**( <u>str用户名</u>,str密码, **nullable str 体质-名称**,**nullable str特殊职业**)
|
||||
* User
|
||||
* **特殊职业**( <u>str职业名称</u>)
|
||||
* Occupation
|
||||
* 菜谱功能分类_可治愈的职业\_特殊职业( <u> **特殊职业-str职业名称**</u>, <u> **菜谱功能和分类-str分类名称**</u>)
|
||||
* 菜谱\_做菜_食材 ( <u>**str菜谱-菜名**</u>,**<u>str食材-名称**</u>,int用量)
|
||||
* cook quantity
|
||||
* 食材\_效果_体质(<u> **str食材-名称**</u>,<u> **nullable str体质-名称**</u>,int效果(1有利于,0不利于))
|
||||
* Material effect
|
||||
* 体质\_身体状态_体质性状( <u> **str体质-名称**</u>, <u> **str体质性状-性状名称**</u>)
|
||||
* physical_state
|
||||
* 菜谱\_菜谱效果_菜谱功能和分类( <u> **str菜谱-菜名**</u>, <u> **str菜谱功能和分类-分类名称**</u>)
|
||||
* menu_effect
|
||||
|
||||
|
||||
|
||||
### 服务器请求
|
||||
|
||||
| 说明 | 方法 | 请求示例 | 备注 |
|
||||
| ------ | ---- | ---------------------------------------- | ----------------------------- |
|
||||
| 查询菜单信息 | GET | http://120.77.182.38/menus/某菜名/ | 不加菜名默认请求所有菜单(服务器可能扛不住) |
|
||||
| 查询食材信息 | GET | http://120.77.182.38/foodmaterial/西红柿/ | 同上 |
|
||||
| 查询用户信息 | GET | http://120.77.182.38/myuser/zhaolizhi/ | 同上 |
|
||||
| 新建用户信息 | POST | http://120.77.182.38/myuser/ | 参数见下图 |
|
||||
| 查询菜谱分类 | GET | http://120.77.182.38/menuclassification/糖尿病食谱/ | 不加分类名默认请求所有分类(和对应的菜谱),响应时间较长 |
|
||||
| 查询职业信息 | GET | http://120.77.182.38/occupation/电力工程师/ | 不加职业名默认查询所有,响应较快 返回职业对应的菜单分类 |
|
||||
| 查询体质信息 | GET | http://120.77.182.38/physique/气虚质/ | 返回体质需要的食材 |
|
||||
| | | | |
|
||||
| | | | |
|
||||
|
||||
* POST新建用户信息`params`示例
|
||||
|
||||
* 1♂ 0♀
|
||||
* `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)
|
||||
@@ -112,4 +112,6 @@ dependencies {
|
||||
implementation files('libs/YoudaoCnDictOffline.jar')
|
||||
implementation files('libs/YoudaoTranslateOffline.jar')
|
||||
implementation files('libs/YoudaoTranslateOnline.jar')
|
||||
|
||||
|
||||
}
|
||||
@@ -30,11 +30,12 @@
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
|
||||
<application
|
||||
|
||||
android:name=".NutritionMaster"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:icon="@mipmap/ic"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:roundIcon="@mipmap/ic"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".modules.MainActivity">
|
||||
@@ -61,6 +62,7 @@
|
||||
<activity android:name=".modules.addinformation.AddInformationActivity" />
|
||||
<activity android:name=".modules.classifyresult.DishResultActivity" />
|
||||
<activity android:name=".modules.classifyresult.MaterialResultActivity" />
|
||||
<activity android:name=".modules.historysearch.HistoryActivity"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -27,6 +27,8 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -48,6 +50,7 @@ public class NutritionMaster extends Application {
|
||||
public static Occupation occupation = null;
|
||||
public static Element element = null;
|
||||
public static Illness illness = null;
|
||||
public static int flavourCount = 0;
|
||||
|
||||
public static Element calculatedElement = null;
|
||||
|
||||
@@ -155,6 +158,7 @@ public class NutritionMaster extends Application {
|
||||
for (int i = 0; i < occupations.length; i++) {
|
||||
ConstantUtils.occupationList.add(occupations[i].getOccupation_name());
|
||||
}
|
||||
Collections.shuffle(ConstantUtils.occupationList);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,12 @@ import android.view.View;
|
||||
import android.widget.Adapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Illness;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -29,7 +33,7 @@ public class IllnessHolder extends RecyclerView.ViewHolder {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
public void bindView(String illness, final int position) {
|
||||
public void bindView(final String illness, final int position) {
|
||||
text.setText(illness);
|
||||
text.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -46,6 +50,10 @@ public class IllnessHolder extends RecyclerView.ViewHolder {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
adapter.deleteItem(position);
|
||||
if (ConstantUtils.getFlavour().contains(illness)) {
|
||||
NutritionMaster.flavourCount -= (ConstantUtils.getFlavour().indexOf(illness) + 1);
|
||||
// Logger.d(NutritionMaster.flavourCount);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -28,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() {
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,11 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
@@ -46,6 +48,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -184,6 +187,7 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
* 拍照回调
|
||||
*/
|
||||
private Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
|
||||
@RequiresApi(api = Build.VERSION_CODES.FROYO)
|
||||
@Override
|
||||
public void onPictureTaken(final byte[] data, Camera camera) {
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
||||
@@ -208,29 +212,31 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
public void run() {
|
||||
String result = null;
|
||||
try {
|
||||
if (code == MATERAIL_CODE) {
|
||||
MaterialClassifier materialClassifier = new MaterialClassifier();
|
||||
JSONObject jsonObject = materialClassifier.plantDetect(data);
|
||||
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);
|
||||
JSONObject jsonObject = new JSONObject(result);
|
||||
ClassifyResult classifyResult = new ClassifyResult(ClassifyResult.DISH);
|
||||
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();
|
||||
// if (code == MATERAIL_CODE) {
|
||||
// // MaterialClassifier materialClassifier = new MaterialClassifier();
|
||||
// // JSONObject jsonObject = materialClassifier.plantDetect(data);
|
||||
// //
|
||||
// Logger.d(result);
|
||||
// JSONObject jsonObject = new JSONObject(result);
|
||||
// JSONArray resultObject = jsonObject.getJSONArray("result");
|
||||
// jsonObject = resultObject.getJSONObject(0);
|
||||
// ClassifyResult classifyResult = new ClassifyResult(ClassifyResult.MATERIAL);
|
||||
// classifyResult.setName(jsonObject.getString("name"));
|
||||
// resultList.add(classifyResult);
|
||||
// refreshUI();
|
||||
// } else if (code == DISH_CODE) {
|
||||
// ClassifyResult classifyResult = new ClassifyResult(ClassifyResult.DISH);
|
||||
// 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 {
|
||||
Logger.e("拍照code为-1");
|
||||
}
|
||||
@@ -255,6 +261,7 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
*
|
||||
* @param view
|
||||
*/
|
||||
|
||||
@OnClick({R.id.more_take_photo_button_capture, R.id.more_takephoto_ok, R.id.results_text_view})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
@@ -274,28 +281,30 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
|
||||
|
||||
//把拍照结果的食材名字放到新的List:materials里面
|
||||
List<String> materials = new ArrayList<>();
|
||||
ArrayList<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);
|
||||
}
|
||||
});
|
||||
// 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", materials);
|
||||
startActivity(intent);
|
||||
|
||||
|
||||
}
|
||||
@@ -34,6 +34,7 @@ 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;
|
||||
@@ -62,6 +63,8 @@ import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
@@ -129,15 +132,33 @@ public class MainActivity extends BaseActivity {
|
||||
LinearLayout illButton;
|
||||
@BindView(R.id.change_information)
|
||||
TextView changeInformation;
|
||||
@BindView(R.id.add_flavour_button)
|
||||
ImageView addFlavourButton;
|
||||
@BindView(R.id.bmi_self)
|
||||
TextView bmiSelf;
|
||||
@BindView(R.id.bmi_standard)
|
||||
TextView bmiStandard;
|
||||
@BindView(R.id.height_self)
|
||||
TextView heightSelf;
|
||||
@BindView(R.id.height_standard)
|
||||
TextView heightStandard;
|
||||
@BindView(R.id.weight_self)
|
||||
TextView weightSelf;
|
||||
@BindView(R.id.weight_standard)
|
||||
TextView weightStandard;
|
||||
|
||||
|
||||
private OptionsPickerView illPicker;
|
||||
private OptionsPickerView flavourPicker;
|
||||
private ArrayList<String> illness = ConstantUtils.getIllness();
|
||||
private ArrayList<String> flavours = ConstantUtils.getFlavour();
|
||||
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() {
|
||||
return R.layout.activity_main;
|
||||
@@ -164,7 +185,7 @@ public class MainActivity extends BaseActivity {
|
||||
// Logger.i("openRatio=" + openRatio + " ,offsetPixels=" + offsetPixels);
|
||||
}
|
||||
});
|
||||
initSpiderView();
|
||||
|
||||
initViewPager();
|
||||
initSearchView();
|
||||
initBMB();
|
||||
@@ -189,7 +210,7 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
toolBarNickname.setText(user.getUsername());
|
||||
toolBarNickname.setText("NutritionMaster");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -219,6 +240,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");
|
||||
@@ -228,16 +267,12 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
//mDrawer.openMenu();
|
||||
|
||||
/**
|
||||
* 点击事件
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 初始化蛛网图
|
||||
*/
|
||||
private void initSpiderView() {
|
||||
float[] scores = {9.1f, 6.5f, 7.7f, 8.9f, 8.6f};
|
||||
|
||||
String[] flags = {"糖分", "淡水", "蛋白质", "维生素", "矿物质"};
|
||||
|
||||
List<RadarEntry> radarEntries = new ArrayList<>();
|
||||
@@ -298,6 +333,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
|
||||
*/
|
||||
@@ -305,7 +349,7 @@ public class MainActivity extends BaseActivity {
|
||||
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
MessageUtils.MakeToast(query);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -485,21 +529,24 @@ public class MainActivity extends BaseActivity {
|
||||
bmiBar.setSecondaryProgress(bmiAverage);
|
||||
bmiBar.setProgress(bmiSelf);
|
||||
} else {
|
||||
changeColor("bmi");
|
||||
bmiBar.setMax(100);
|
||||
bmiBar.setSecondaryProgress(bmiSelf);
|
||||
bmiBar.setProgress(bmiAverage);
|
||||
bmiBar.setProgressColor(getColor(R.color.color_bar_deeper));
|
||||
bmiBar.setSecondaryProgressColor(getColor(R.color.color_bar_self));
|
||||
}
|
||||
|
||||
// NutritionMaster.user.setBmi(bmiSelf);
|
||||
|
||||
float heightAverage = averageHeight / maxHeight * 100.0f;
|
||||
float heightSelf = height / maxHeight * 100.0f;
|
||||
if (heightAverage > heightSelf) {
|
||||
|
||||
heightBar.setMax(100);
|
||||
heightBar.setSecondaryProgress(heightAverage);
|
||||
heightBar.setProgress(heightSelf);
|
||||
} else {
|
||||
changeColor("height");
|
||||
heightBar.setMax(100);
|
||||
heightBar.setSecondaryProgress(heightSelf);
|
||||
heightBar.setProgress(heightAverage);
|
||||
@@ -511,10 +558,12 @@ public class MainActivity extends BaseActivity {
|
||||
float weightAverage = averageWeight / maxWeight * 100.0f;
|
||||
float weightSelf = weight / maxWeight * 100.0f;
|
||||
if (weightAverage > weightSelf) {
|
||||
|
||||
weightBar.setMax(100);
|
||||
weightBar.setSecondaryProgress(weightAverage);
|
||||
weightBar.setProgress(weightSelf);
|
||||
} else {
|
||||
changeColor("weight");
|
||||
weightBar.setMax(100);
|
||||
weightBar.setSecondaryProgress(weightSelf);
|
||||
weightBar.setProgress(weightAverage);
|
||||
@@ -530,6 +579,23 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换bar的颜色
|
||||
*/
|
||||
@SuppressLint("ResourceAsColor")
|
||||
private void changeColor(String flag) {
|
||||
if (flag.equals("bmi")) {
|
||||
bmiSelf.setBackgroundColor(R.color.color_bar_deeper);
|
||||
bmiStandard.setBackgroundColor(R.color.color_bar_self);
|
||||
} else if (flag.equals("height")) {
|
||||
heightBar.setBackgroundColor(R.color.color_bar_deeper);
|
||||
heightStandard.setBackgroundColor(R.color.color_bar_self);
|
||||
} else if (flag.equals("weight")) {
|
||||
weightSelf.setBackgroundColor(R.color.color_bar_deeper);
|
||||
weightStandard.setBackgroundColor(R.color.color_bar_self);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化用户疾病list
|
||||
@@ -559,6 +625,7 @@ public class MainActivity extends BaseActivity {
|
||||
// }
|
||||
// });
|
||||
// }else{
|
||||
initSpiderView();
|
||||
illButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -585,8 +652,9 @@ public class MainActivity extends BaseActivity {
|
||||
illRecyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
userIllness.add(illname);
|
||||
illAdapter.notifyDataSetChanged();
|
||||
if (!userIllness.contains(illname)) {
|
||||
userIllness.add(illname);
|
||||
}
|
||||
illAdapter.notifyDataSetChanged();
|
||||
if (NutritionMaster.occupation != null && NutritionMaster.physique != null) {
|
||||
NutritionMaster.element = CalculateUtils.getElementsAddIllness(NutritionMaster.illness,
|
||||
@@ -606,6 +674,27 @@ public class MainActivity extends BaseActivity {
|
||||
illPicker.show();
|
||||
}
|
||||
});
|
||||
// }
|
||||
|
||||
addFlavourButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
flavourPicker = new OptionsPickerBuilder(MainActivity.this, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
final String flavourString = flavours.get(options1);
|
||||
if (!userIllness.contains(flavourString)) {
|
||||
userIllness.add(flavourString);
|
||||
}
|
||||
NutritionMaster.flavourCount += (options1 + 1);
|
||||
illAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}).build();
|
||||
flavourPicker.setPicker(flavours);
|
||||
flavourPicker.setTitleText("请选择你喜欢的口味");
|
||||
flavourPicker.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -17,16 +17,21 @@ import com.example.ninefourone.nutritionmaster.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
|
||||
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.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 {
|
||||
|
||||
@@ -128,6 +133,20 @@ public class RecipeActivity extends BaseActivity {
|
||||
|
||||
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);
|
||||
@@ -34,6 +34,7 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
RecyclerView recyclerView;
|
||||
ArrayList<ClassifyResult> classifyResults;
|
||||
ArrayList<FoodMenu> list;
|
||||
private ArrayList<String> nameList;
|
||||
private MaterialResultAdapter adapter;
|
||||
|
||||
@Override
|
||||
@@ -46,13 +47,33 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
Intent intent = getIntent();
|
||||
// classifyResults = (ArrayList<ClassifyResult>) intent.getSerializableExtra("LIST");
|
||||
// list = classifyResults.get(0).getFoodMaterial().getMenus();
|
||||
list= (ArrayList<FoodMenu>) intent.getSerializableExtra("LIST");
|
||||
nameList = (ArrayList<String>) intent.getSerializableExtra("LIST");
|
||||
adapter = new MaterialResultAdapter(list, MaterialResultActivity.this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setNestedScrollingEnabled(false);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(MaterialResultActivity.this));
|
||||
|
||||
WebUtil.getInstance().getMenusByMaterials(nameList, 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);
|
||||
for (FoodMenu foodMenu : menus) {
|
||||
list.add(foodMenu);
|
||||
}
|
||||
recyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,6 +93,5 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -230,7 +230,7 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
weightLineChart.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
if (NutritionMaster.element != null) {
|
||||
Logger.d(NutritionMaster.element);
|
||||
// Logger.d(NutritionMaster.element);
|
||||
try {
|
||||
Element elementTemp = NutritionMaster.element.calculateData(NutritionMaster.user);
|
||||
float temp = (float) (elementTemp.getCalorie() - NutritionMaster.user.getEaten_elements().getCalorie());
|
||||
@@ -128,6 +128,9 @@ 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
|
||||
@@ -192,9 +195,9 @@ public class CustomizationActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
Random random = new Random(NutritionMaster.randomSeed + CalculateUtils.title2Int(text));
|
||||
start = random.nextInt(foodMenus.length );
|
||||
start = random.nextInt(foodMenus.length);
|
||||
for (int i = start; i < start + 12; i++) {
|
||||
webUtil.getMenu(foodMenus[i].getName(), new Callback() {
|
||||
@Override
|
||||
@@ -254,6 +257,8 @@ 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;
|
||||
@@ -317,5 +322,14 @@ public class CustomizationActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加到饮食记录
|
||||
*/
|
||||
private void addRecord() {
|
||||
for (int i = 0; i < breakfastList.size(); i++) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.recommend;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
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 java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public class RecommendFragment extends BaseFragment {
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
Unbinder unbinder;
|
||||
@BindView(R.id.swipe_refresh_layout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
private RecommendAdapter adapter;
|
||||
private ArrayList<RecommendFood> datas = new ArrayList<>();
|
||||
private GridLayoutManager manager;
|
||||
private int[] indexs = new int[]{0, 1, 2};
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutResId() {
|
||||
return R.layout.normal_recommend_fragment_layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView(Bundle state) {
|
||||
initRecyclerView();
|
||||
loadData();
|
||||
}
|
||||
|
||||
|
||||
public static BaseFragment getInstance() {
|
||||
return new RecommendFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// TODO: inflate a fragment view
|
||||
View rootView = super.onCreateView(inflater, container, savedInstanceState);
|
||||
unbinder = ButterKnife.bind(this, rootView);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
unbinder.unbind();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化recyclerview
|
||||
*/
|
||||
@Override
|
||||
protected void initRecyclerView() {
|
||||
adapter = new RecommendAdapter(datas);
|
||||
adapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
|
||||
adapter.isFirstOnly(false);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
|
||||
@Override
|
||||
public void onLoadMoreRequested() {
|
||||
recyclerView.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addData();
|
||||
}
|
||||
|
||||
}, 1000);
|
||||
}
|
||||
}, recyclerView);
|
||||
adapter.setEnableLoadMore(true);
|
||||
adapter.setHeaderView(LayoutInflater.from(getContext()).
|
||||
inflate(R.layout.recommend_head, (ViewGroup) recyclerView.getParent(), false));
|
||||
adapter.setPreLoadNumber(1);
|
||||
recyclerView.setNestedScrollingEnabled(false);
|
||||
manager = new GridLayoutManager(getContext(), 2);
|
||||
adapter.setHeaderViewAsFlow(false);
|
||||
|
||||
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
||||
@Override
|
||||
public int getSpanSize(int position) {
|
||||
if (position == 0) {
|
||||
return 2;
|
||||
} else {
|
||||
if (adapter.getItemViewType(position) == RecommendFood.TYPE_DETAIL) {
|
||||
// Logger.d(manager.getSpanCount());
|
||||
return 2;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
recyclerView.setLayoutManager(manager);
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
changeInfor();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
* 病 、 体质 、 职业
|
||||
* 0-4 5-7 8-10
|
||||
*/
|
||||
@Override
|
||||
protected void loadData() {
|
||||
super.loadData();
|
||||
// if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
getWebUtil().getRandomMenus(20, NutritionMaster.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();
|
||||
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();
|
||||
if (swipeRefreshLayout.isRefreshing()){
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载新数据
|
||||
*/
|
||||
private void addData() {
|
||||
// if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
getWebUtil().getRandomMenus(20, NutritionMaster.user.getUsername(), 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数据是否加载完了(服务器没了)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private boolean isDataOverCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改信息后修改推荐
|
||||
*/
|
||||
public void changeInfor() {
|
||||
datas.clear();
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,8 @@ public class CalculateUtils {
|
||||
calories[i] = classifyResultArrayList.get(i).getCalorie();
|
||||
}
|
||||
for (int i = 0; i < classifyResultArrayList.size(); i++) {
|
||||
classifyResultArrayList.get(i).setQuantity(calories[i] / calorieSum * baseQuantity * factor);
|
||||
classifyResultArrayList.get(i).setQuantity(calories[i] / calorieSum * baseQuantity * factor
|
||||
+ NutritionMaster.flavourCount * 5);
|
||||
}
|
||||
return classifyResultArrayList;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class ConstantUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 全国平均体重 index 0 对应 3岁
|
||||
* 全国平均身高 index 0 对应 3岁
|
||||
*/
|
||||
public static ArrayList<Float> averageBoyHeight = new ArrayList<>();
|
||||
|
||||
@@ -277,8 +277,6 @@ public class ConstantUtils {
|
||||
public static String BD_SECRET_KEY = "EEXe6pG7QGVdrqDM8eR0S3RY2WPf4Gwn";
|
||||
public static String BD_ACCESS_TOKEN = "";
|
||||
|
||||
public static String BD_DISH_URL = "https://aip.baidubce.com/rest/2.0/image-classify/v2/dish";
|
||||
|
||||
// public static ArrayList<ClassifyResult> testData = new ArrayList<>();
|
||||
//
|
||||
// static {
|
||||
@@ -342,5 +340,15 @@ public class ConstantUtils {
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getFlavour() {
|
||||
ArrayList<String> arrayList = new ArrayList<>();
|
||||
arrayList.add("苦");
|
||||
arrayList.add("甜");
|
||||
arrayList.add("咸");
|
||||
arrayList.add("辣");
|
||||
arrayList.add("酸");
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
public static String YOUDAO_APPKEY = "3ea8061348a6bdd6";
|
||||
}
|
||||
@@ -46,11 +46,11 @@ public class WebUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取具体的菜谱信息 { "flavor": "咸鲜味", "calorie": 234, "name": "雪丽对虾",
|
||||
* "technology": "炸", "image_url":
|
||||
* 获取具体的菜谱信息 { "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": "鸡蛋清" }, }
|
||||
* "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();
|
||||
@@ -95,9 +95,9 @@ public class WebUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某食材可以做的菜 [ { "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
|
||||
@@ -108,10 +108,9 @@ 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()
|
||||
@@ -120,8 +119,8 @@ public class WebUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取职业需要的菜谱分类 { "occupation_name": "电力工程师", "menuclassification_set":
|
||||
* [ "接触电离辐射人员食谱", "防癌抗癌食谱", "明目食谱", "关节炎食谱", "壮腰健肾食谱" ] }
|
||||
* 获取职业需要的菜谱分类 { "occupation_name": "电力工程师", "menuclassification_set": [
|
||||
* "接触电离辐射人员食谱", "防癌抗癌食谱", "明目食谱", "关节炎食谱", "壮腰健肾食谱" ] }
|
||||
*/
|
||||
public void getOccupation(String occupationName, Callback callback) {
|
||||
Request request = null;
|
||||
@@ -134,8 +133,8 @@ public class WebUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取体质需要的食材 { "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();
|
||||
@@ -146,8 +145,8 @@ public class WebUtil {
|
||||
* 获取病相关的菜谱和元素信息 传入含有病的意义的菜谱分类名称,比如青少年食谱
|
||||
* <p>
|
||||
* { "menu_classification": { "classification": "青少年食谱", "cure_occupation": [
|
||||
* "学生" ], "menu_effect": [ "三鲜鳝汤", "上海糖醋小排骨", ... ] }, "elements": {
|
||||
* "id": 84, "calorie": 1.1, ... } }
|
||||
* "学生" ], "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 + "/")
|
||||
@@ -352,8 +351,7 @@ public class WebUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户吃了一个菜,更新用户本周已吃摄入的营养元素的量 传入这顿饭摄入的营养量
|
||||
* 返回当前user的最新信息,用MyUser类解析json
|
||||
* 用户吃了一个菜,更新用户本周已吃摄入的营养元素的量 传入这顿饭摄入的营养量 返回当前user的最新信息,用MyUser类解析json
|
||||
*/
|
||||
public void eatenElements(String username, Map<String, Double> elements, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/eaten_menu/";
|
||||
@@ -388,6 +386,54 @@ public class WebUtil {
|
||||
Request request = new Request.Builder().url(url).post(formBody).build();
|
||||
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;
|
||||
// }
|
||||
|
||||
public void addEatenHistory(String username, String menuName, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/add_eaten_history/";
|
||||
@@ -413,7 +459,6 @@ public class WebUtil {
|
||||
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<>();
|
||||
params.put("calorie", 100.0);
|
||||
@@ -435,6 +480,184 @@ public class WebUtil {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
MyUser testUser = new MyUser();
|
||||
testUser.setUsername("test6");
|
||||
testUser.setPassword("66666");
|
||||
testUser.setAge(8);
|
||||
testUser.setHeight(175);
|
||||
testUser.setPhysical_name("平和质");
|
||||
List<String> ills = new ArrayList<>();
|
||||
ills.add("乌发食谱");
|
||||
ills.add("失眠食谱");
|
||||
testUser.setIllness(ills);
|
||||
|
||||
//创建用户
|
||||
WebUtil.getInstance().createUser(testUser, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String responseJson = response.body().string();
|
||||
System.out.println(new Gson().fromJson(responseJson, MyUser.class));
|
||||
}
|
||||
});
|
||||
|
||||
//修改用户信息
|
||||
WebUtil.getInstance().changeUserInfo(testUser, 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));
|
||||
}
|
||||
});*/
|
||||
|
||||
|
||||
|
||||
/*WebUtil.getInstance().eatenMenu("test5", "软熘虾片", new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String responseJson = response.body().string();
|
||||
System.out.println(responseJson);
|
||||
MyUser testUser = new Gson().fromJson(responseJson, MyUser.class);
|
||||
System.out.println(testUser);
|
||||
}
|
||||
});*/
|
||||
|
||||
/*WebUtil.getIllness("青少年食谱", 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(),Illness.class));
|
||||
}
|
||||
});*/
|
||||
|
||||
|
||||
/* WebUtil.getMenu("雪丽对虾", new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
FoodMenu menu = new Gson().fromJson(response.body().string(), FoodMenu.class);
|
||||
System.out.println(menu);
|
||||
}
|
||||
});*/
|
||||
|
||||
/*WebUtil.getRandomMenus(10, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
FoodMenu[] menus = new Gson().fromJson(response.body().string(), FoodMenu[].class);
|
||||
System.out.println(Arrays.toString(menus));
|
||||
System.out.println(menus.length);
|
||||
|
||||
}
|
||||
});*/
|
||||
|
||||
/*WebUtil.getFoodMaterial("西红柿", new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
FoodMaterial foodMaterial = new Gson().fromJson(json, FoodMaterial.class);
|
||||
System.out.println(foodMaterial);
|
||||
}
|
||||
});*/
|
||||
|
||||
/*WebUtil.getMenuClassification("川菜", new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
MenuClassification classification = new Gson().fromJson(response.body().string(), MenuClassification.class);
|
||||
System.out.println(classification);
|
||||
}
|
||||
});*/
|
||||
|
||||
/*WebUtil.getOccupation("程序员", 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();
|
||||
System.out.println(new Gson().fromJson(json, Occupation.class));
|
||||
|
||||
}
|
||||
});*/
|
||||
|
||||
/*WebUtil.getPhysique("气虚质", 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(), Physique.class));
|
||||
}
|
||||
});*/
|
||||
|
||||
/*WebUtil.instance.getUser("test5", 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));
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
/* WebUtil.getRandomTricks(10, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
System.out.println(response.body().string());
|
||||
}
|
||||
});*/
|
||||
|
||||
|
||||
/*
|
||||
* MyUser testUser = new MyUser(); testUser.setUsername("test6");
|
||||
* testUser.setPassword("66666"); testUser.setAge(8); testUser.setHeight(175);
|
||||
@@ -515,6 +738,7 @@ public class WebUtil {
|
||||
* } });
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* WebUtil.getFoodMaterial("西红柿", new Callback() {
|
||||
*
|
||||
@@ -589,5 +813,6 @@ public class WebUtil {
|
||||
* @Override public void onResponse(Call call, Response response) throws
|
||||
* IOException { System.out.println(response.body().string()); } });
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 108 B After Width: | Height: | Size: 108 B |
|
Before Width: | Height: | Size: 783 KiB After Width: | Height: | Size: 783 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 137 KiB After Width: | Height: | Size: 137 KiB |