Compare commits
178 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 | ||
|
|
bb0292f484 | ||
|
|
5dbfe25238 | ||
|
|
326dcbf7a0 | ||
|
|
eb75d2945a | ||
|
|
a954624abe | ||
|
|
f040a45c5a | ||
|
|
51d2bf95dc | ||
|
|
7d0037e10c | ||
|
|
1e15caa3dc | ||
|
|
d12c53f519 | ||
|
|
635b7c0289 | ||
|
|
f0fd84553b | ||
|
|
972dcccb88 | ||
|
|
814a335fd0 | ||
|
|
000246671d | ||
|
|
de72ed5abd | ||
|
|
e5c27211bc | ||
|
|
b562d35d82 | ||
|
|
a409c2a010 | ||
|
|
9b2f4df365 | ||
|
|
8fbf311d1d | ||
|
|
e84c182cd5 | ||
|
|
b308f27154 | ||
|
|
fadd2ba1a6 | ||
|
|
7e1c9aa755 | ||
|
|
c628931e62 | ||
|
|
4fd0da3f4c | ||
|
|
2f2e143494 | ||
|
|
3959bac0b2 | ||
|
|
cdf699a8d5 | ||
|
|
d98235fb0a | ||
|
|
6025ec37e4 | ||
|
|
3c83a4bfa5 | ||
|
|
b72fcf0732 | ||
|
|
e424d14565 | ||
|
|
74e6d23cd6 | ||
|
|
9858485c47 | ||
|
|
4d979725cb | ||
|
|
1817d66cc5 | ||
|
|
dd780cdb72 | ||
|
|
73cb1db3d8 | ||
|
|
1752f13d61 | ||
|
|
dafcf5583e | ||
|
|
861d76d4cc | ||
|
|
1ea891f765 | ||
|
|
164beaef04 | ||
|
|
ccd3e0633c | ||
|
|
c49044a0f6 | ||
|
|
6c6ae71d64 | ||
|
|
9aa0625e67 | ||
|
|
5db14fcf04 | ||
|
|
92f4b56f64 | ||
|
|
9762633ecd | ||
|
|
1b3ac3c501 | ||
|
|
80869c4c7f | ||
|
|
45030adc91 | ||
|
|
1612b9f7ea | ||
|
|
886cb247af | ||
|
|
fb4654e24a | ||
|
|
47aea25966 | ||
|
|
83406a8e0b | ||
|
|
b1fd6bbdd9 | ||
|
|
6293416764 | ||
|
|
fd225f4da2 | ||
|
|
7c4bbb2f27 | ||
|
|
e8a1ef4066 | ||
|
|
a0483f33e6 | ||
|
|
660320d900 | ||
|
|
c438c7d21d | ||
|
|
0dcde3dad8 | ||
|
|
4097e8f435 | ||
|
|
b5bccec04a | ||
|
|
52fd782c5d | ||
|
|
b1e145b895 | ||
|
|
84c014f667 | ||
|
|
5665910305 | ||
|
|
734a2de0f3 | ||
|
|
4111626670 | ||
|
|
f4fc6039f4 | ||
|
|
51004fc9eb | ||
|
|
ced1e200fd | ||
|
|
335be670bc | ||
|
|
52a25ac1fd | ||
|
|
eee387cba7 | ||
|
|
6e60f7a338 | ||
|
|
aba473fe49 | ||
|
|
be04693e4d | ||
|
|
f808c5dea6 | ||
|
|
efac56b197 | ||
|
|
523b921c3a | ||
|
|
ee422d33b1 | ||
|
|
e992f3feb0 | ||
|
|
79dc039d8e | ||
|
|
ec41925d18 | ||
|
|
0d8214d19b | ||
|
|
e486c07ad5 | ||
|
|
ffa74dd12f | ||
|
|
6a59c73bba | ||
|
|
2a98c39fbd | ||
|
|
8bb20ff9c0 | ||
|
|
98bc144e31 | ||
|
|
16d6afce5b | ||
|
|
d173cc351e | ||
|
|
1cc3330a92 | ||
|
|
c1a0ea6e6c | ||
|
|
ab0c947242 | ||
|
|
6d9d321243 | ||
|
|
9e05de2636 | ||
|
|
ed89bec66d | ||
|
|
ee8dfcf1b3 | ||
|
|
c5157f9a02 | ||
|
|
e50c80694f | ||
|
|
c5595d4d15 | ||
|
|
ff78b1b314 | ||
|
|
750d0bfabc | ||
|
|
02ff5ecc97 | ||
|
|
06e16847b0 | ||
|
|
d73ad163d5 | ||
|
|
06a8aca2f6 | ||
|
|
f9142b1326 | ||
|
|
cde71dbe6f | ||
|
|
7e35c2dc00 | ||
|
|
06ecb1770f | ||
|
|
9ffae4a84d | ||
|
|
659be48a31 | ||
|
|
6e8b39001d | ||
|
|
ea403e5994 | ||
|
|
6e0b877d1d | ||
|
|
19f959bc80 | ||
|
|
c57388dc94 | ||
|
|
1e03292d60 | ||
|
|
bbf1b5b398 | ||
|
|
8b1d6a6527 | ||
|
|
92476c7a2e | ||
|
|
6738616580 | ||
|
|
c16d0d6972 | ||
|
|
3c614af2ff | ||
|
|
aa49f6f02f | ||
|
|
b504741257 | ||
|
|
9ece16e6ea | ||
|
|
f1a5f3dd33 | ||
|
|
711a3e6788 | ||
|
|
d02e06ad63 | ||
|
|
06c3d8af82 |
3
.gitignore → NutritionMaster/.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
|
||||
29
NutritionMaster/.idea/codeStyles/Project.xml
generated
Normal file
@@ -0,0 +1,29 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<Objective-C-extensions>
|
||||
<file>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
||||
</file>
|
||||
<class>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
||||
</class>
|
||||
<extensions>
|
||||
<pair source="cpp" header="h" fileNamingConvention="NONE" />
|
||||
<pair source="c" header="h" fileNamingConvention="NONE" />
|
||||
</extensions>
|
||||
</Objective-C-extensions>
|
||||
</code_scheme>
|
||||
</component>
|
||||
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)
|
||||
117
NutritionMaster/app/build.gradle
Normal file
@@ -0,0 +1,117 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
|
||||
compileSdkVersion 26
|
||||
|
||||
defaultConfig {
|
||||
|
||||
applicationId "com.example.ninefourone.nutritionmaster"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 26
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
main {
|
||||
jniLibs.srcDirs = ['libs']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'com.android.support:appcompat-v7:26.1.0'
|
||||
implementation 'com.android.support:design:26.1.0'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
|
||||
//butterknife
|
||||
implementation 'com.jakewharton:butterknife:8.8.1'
|
||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
||||
|
||||
//logger
|
||||
implementation 'com.orhanobut:logger:2.2.0'
|
||||
|
||||
//超帅侧拉ui
|
||||
implementation 'com.mxn.soul:flowingdrawer-core:2.0.0'
|
||||
implementation 'com.nineoldandroids:library:2.4.0'
|
||||
|
||||
//图片形状库
|
||||
implementation 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
|
||||
|
||||
//cardview
|
||||
implementation 'com.android.support:cardview-v7:26.1.0'
|
||||
|
||||
//tablayout
|
||||
implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.0.0@aar'
|
||||
|
||||
//viewpager transforms
|
||||
implementation 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32@aar'
|
||||
|
||||
//个人信息的那个条条
|
||||
implementation 'com.akexorcist:RoundCornerProgressBar:2.0.3'
|
||||
|
||||
//wave
|
||||
implementation 'me.itangqi.waveloadingview:library:0.3.5'
|
||||
|
||||
//计步
|
||||
implementation project(':todaystepcounterlib')
|
||||
|
||||
//打分ui
|
||||
implementation 'com.github.CB-ysx:CBRatingBar:3.0.1'
|
||||
|
||||
//折线
|
||||
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
|
||||
|
||||
//searchview
|
||||
implementation 'com.miguelcatalan:materialsearchview:1.4.0'
|
||||
|
||||
//floatbuttom
|
||||
implementation 'com.nightonke:boommenu:2.1.1'
|
||||
|
||||
//recycler and card
|
||||
implementation 'com.android.support:recyclerview-v7:26.1.0'
|
||||
implementation 'com.android.support:cardview-v7:26.1.0'
|
||||
|
||||
//混合式recyclerview
|
||||
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
|
||||
|
||||
//翻页view
|
||||
implementation 'com.github.czy1121:turncardlistview:1.0.0'
|
||||
|
||||
//油表盘
|
||||
implementation 'com.github.lzyzsd:circleprogress:1.2.1'
|
||||
|
||||
//glide
|
||||
implementation 'com.github.bumptech.glide:glide:3.8.0'
|
||||
implementation 'com.android.support:support-v4:19.1.0'
|
||||
|
||||
//picker
|
||||
implementation 'com.contrarywind:Android-PickerView:4.1.6'
|
||||
|
||||
//okhttp 网络通信库
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
|
||||
|
||||
// json解析库
|
||||
implementation 'com.google.code.gson:gson:2.8.5'
|
||||
|
||||
//横向picker
|
||||
implementation 'com.github.adityagohad:HorizontalPicker:1.0.1'
|
||||
implementation files('libs/YoudaoBase.jar')
|
||||
implementation files('libs/YoudaoCnDictOffline.jar')
|
||||
implementation files('libs/YoudaoTranslateOffline.jar')
|
||||
implementation files('libs/YoudaoTranslateOnline.jar')
|
||||
|
||||
|
||||
}
|
||||
BIN
NutritionMaster/app/libs/YoudaoBase.jar
Normal file
BIN
NutritionMaster/app/libs/YoudaoCnDictOffline.jar
Normal file
BIN
NutritionMaster/app/libs/YoudaoTranslateOffline.jar
Normal file
BIN
NutritionMaster/app/libs/YoudaoTranslateOnline.jar
Normal file
BIN
NutritionMaster/app/libs/arm64-v8a/libdict-parser.so
Normal file
BIN
NutritionMaster/app/libs/armeabi-v7a/libdict-parser.so
Normal file
BIN
NutritionMaster/app/libs/armeabi/libdict-parser.so
Normal file
BIN
NutritionMaster/app/libs/mips/libdict-parser.so
Normal file
BIN
NutritionMaster/app/libs/mips64/libdict-parser.so
Normal file
BIN
NutritionMaster/app/libs/x86/libdict-parser.so
Normal file
BIN
NutritionMaster/app/libs/x86_64/libdict-parser.so
Normal file
@@ -19,3 +19,13 @@
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
-ignorewarnings
|
||||
-libraryjars libs/ YoudaoBase.jar
|
||||
-libraryjars libs/ YoudaoCnDictOffline.jar
|
||||
-libraryjars libs/ YoudaoTranslateOnline.jar
|
||||
-libraryjars libs/ YoudaoTranslateOffline.jar
|
||||
|
||||
-keep class com.youdao.sdk.ydtranslate.** { *;}
|
||||
-keep class com.youdao.sdk.chdict.** { *;}
|
||||
-keep class com.youdao.localtransengine.** { *;}
|
||||
-keep class com.youdao.sdk.ydonlinetranslate.** { *;}
|
||||
68
NutritionMaster/app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.ninefourone.nutritionmaster">
|
||||
|
||||
<!-- 允许联网 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- 获取GSM(2g)、WCDMA(联通3g)等网络状态的信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<!-- 获取wifi网络状态的信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<!-- 保持CPU 运转,屏幕和键盘灯有可能是关闭的,用于文件上传和下载 -->
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<!-- 获取sd卡写的权限,用于文件上传和下载 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<!-- 允许读取手机状态 用于创建BmobInstallation -->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
|
||||
<!-- 相机权限 -->
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.camera"
|
||||
android:required="false" />
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<!-- To auto-complete the email text field in the login form with the user's emails -->
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.READ_PROFILE" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
|
||||
<application
|
||||
|
||||
android:name=".NutritionMaster"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".modules.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".camera.ClassifierCamera" />
|
||||
|
||||
<receiver
|
||||
android:name=".step.StepStarter"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
|
||||
<activity android:name=".modules.addinformation.AddPhysiqueActivity" />
|
||||
<activity android:name=".modules.viewpagerfragments.customization.CustomizationActivity" />
|
||||
<activity android:name=".modules.information.InformationActivity" />
|
||||
<activity android:name=".modules.RecipeActivity.RecipeActivity" />
|
||||
<!-- <activity -->
|
||||
<!-- android:name=".LoginActivity" -->
|
||||
<!-- 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 android:name=".modules.historysearch.HistoryActivity"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,227 @@
|
||||
package com.example.ninefourone.nutritionmaster;
|
||||
|
||||
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;
|
||||
import com.orhanobut.logger.AndroidLogAdapter;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.youdao.sdk.app.YouDaoApplication;
|
||||
import com.youdao.sdk.chdict.ChDictor;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
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;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public class NutritionMaster extends Application {
|
||||
public static NutritionMaster mInstance;
|
||||
private int appCount = 0;
|
||||
|
||||
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 int flavourCount = 0;
|
||||
|
||||
public static Element calculatedElement = null;
|
||||
|
||||
public static int randomSeed = CalculateUtils.getWeek();
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mInstance = this;
|
||||
init();
|
||||
initYouDao();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化所有基础的东西
|
||||
*/
|
||||
private void init() {
|
||||
Logger.addLogAdapter(new AndroidLogAdapter());
|
||||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
appCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {
|
||||
appCount--;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
|
||||
}
|
||||
});
|
||||
initOccupations();
|
||||
initUser();
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initBD();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
|
||||
}
|
||||
|
||||
public static NutritionMaster getInstance() {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* app是否在前台
|
||||
*
|
||||
* @return true前台,false后台
|
||||
*/
|
||||
public boolean isForeground() {
|
||||
return appCount > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化用户信息
|
||||
*/
|
||||
private void initUser() {
|
||||
user = new MyUser();
|
||||
user.setUsername("test1");
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化职业常量
|
||||
*/
|
||||
private void initOccupations() {
|
||||
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
webUtil.getAllOccupations(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
Occupation[] occupations = new Gson().fromJson(response.body().string(), Occupation[].class);
|
||||
for (int i = 0; i < occupations.length; i++) {
|
||||
ConstantUtils.occupationList.add(occupations[i].getOccupation_name());
|
||||
}
|
||||
Collections.shuffle(ConstantUtils.occupationList);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* BDAPI init
|
||||
*/
|
||||
private void initBD() {
|
||||
ConstantUtils.BD_ACCESS_TOKEN = getAccessToken();
|
||||
}
|
||||
|
||||
|
||||
private String getAccessToken() {
|
||||
String authHost = "https://aip.baidubce.com/oauth/2.0/token?";
|
||||
String ak = ConstantUtils.BD_API_KEY;
|
||||
String sk = ConstantUtils.BD_SECRET_KEY;
|
||||
String getAccessTokenUrl = authHost
|
||||
// 1. grant_type为固定参数
|
||||
+ "grant_type=client_credentials"
|
||||
// 2. 官网获取的 API Key
|
||||
+ "&client_id=" + ak
|
||||
// 3. 官网获取的 Secret Key
|
||||
+ "&client_secret=" + sk;
|
||||
try {
|
||||
URL realUrl = new URL(getAccessTokenUrl);
|
||||
// 打开和URL之间的连接
|
||||
HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.connect();
|
||||
// 获取所有响应头字段
|
||||
Map<String, List<String>> map = connection.getHeaderFields();
|
||||
// 遍历所有的响应头字段
|
||||
// for (String key : map.keySet()) {
|
||||
// System.err.println(key + "--->" + map.get(key));
|
||||
// }
|
||||
// 定义 BufferedReader输入流来读取URL的响应
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String result = "";
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
result += line;
|
||||
}
|
||||
/**
|
||||
* 返回结果示例
|
||||
*/
|
||||
JSONObject jsonObject = new JSONObject(result);
|
||||
String access_token = jsonObject.getString("access_token");
|
||||
return access_token;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* YD init
|
||||
*/
|
||||
private void initYouDao() {
|
||||
YouDaoApplication.init(this, ConstantUtils.YOUDAO_APPKEY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
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.DailyCard;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/2.
|
||||
*/
|
||||
|
||||
public class CardAdapter extends RecyclerView.Adapter<CardHolder> {
|
||||
private Context context;
|
||||
private ArrayList<DailyCard> mList;
|
||||
|
||||
|
||||
public CardAdapter(Context context, ArrayList<DailyCard> mList) {
|
||||
this.context = context;
|
||||
this.mList = mList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CardHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.card_item, parent, false);
|
||||
CardHolder cardHolder = new CardHolder(view);
|
||||
return cardHolder;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onBindViewHolder(CardHolder holder, int position) {
|
||||
holder.bindView(mList.get(position).getPictureId(), mList.get(position), context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 右划
|
||||
*/
|
||||
public void swipe2Right() {
|
||||
// Logger.d("右划");
|
||||
}
|
||||
|
||||
/**
|
||||
* 左划
|
||||
*/
|
||||
public void swipe2left() {
|
||||
// Logger.d("左划");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
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.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;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/2.
|
||||
*/
|
||||
|
||||
public class CardHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.iv_photo)
|
||||
ImageView ivPhoto;
|
||||
@BindView(R.id.tv_name)
|
||||
TextView tvName;
|
||||
@BindView(R.id.tv_sign)
|
||||
TextView tvSign;
|
||||
|
||||
private View itemView;
|
||||
private Intent i;
|
||||
|
||||
public CardHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
this.itemView = itemView;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public void bindView(int picId, DailyCard dailyCard, final Context context) {
|
||||
tvName.setText(dailyCard.getTitle());
|
||||
tvSign.setText(dailyCard.getDescription());
|
||||
Glide.with(context).load(picId).into(ivPhoto);
|
||||
i = new Intent(context, CustomizationActivity.class);
|
||||
i.putExtra("SEND_CODE", dailyCard.getTitle());
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (NutritionMaster.physique == null || NutritionMaster.occupation == null) {
|
||||
MessageUtils.MakeToast("填写信息才能使用哦~");
|
||||
} else {
|
||||
context.startActivity(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +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<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 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 mList.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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,35 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/6.
|
||||
*/
|
||||
|
||||
public class DishHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.image)
|
||||
ImageView image;
|
||||
@BindView(R.id.name)
|
||||
TextView name;
|
||||
@BindView(R.id.describle)
|
||||
TextView describle;
|
||||
|
||||
public DishHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bindView(ClassifyResult classifyResult) {
|
||||
// Glide.with();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.customization.CustomizationFragment;
|
||||
import com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.bodyinformation.BodyInformationFragment;
|
||||
import com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.recommend.RecommendFragment;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Wangtianrui on 2018/5/1.
|
||||
*/
|
||||
|
||||
public class HomePagerAdapter extends FragmentPagerAdapter {
|
||||
private final String[] TITLES;
|
||||
private Fragment[] fragments;
|
||||
|
||||
public HomePagerAdapter(FragmentManager fm, Context context) {
|
||||
super(fm);
|
||||
TITLES = context.getResources().getStringArray(R.array.sections);
|
||||
fragments = new Fragment[TITLES.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (fragments[position] == null) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
fragments[position] = CustomizationFragment.getInstance();
|
||||
break;
|
||||
case 1:
|
||||
fragments[position] = BodyInformationFragment.getInstance();
|
||||
break;
|
||||
case 2:
|
||||
fragments[position] = RecommendFragment.getInstance();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return fragments[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return TITLES.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return TITLES[position];
|
||||
}
|
||||
|
||||
public void rereshUI() {
|
||||
((BodyInformationFragment) fragments[1]).refreshUI();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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.Illness;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/6.
|
||||
*/
|
||||
|
||||
public class IllAdapter extends RecyclerView.Adapter<IllnessHolder> {
|
||||
private List<String> mList;
|
||||
private Context context;
|
||||
|
||||
public IllAdapter(List<String> mList, Context context) {
|
||||
this.mList = mList;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IllnessHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(context).inflate(R.layout.ill_item, parent, false);
|
||||
return new IllnessHolder(v, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(IllnessHolder holder, int position) {
|
||||
holder.bindView(mList.get(position), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
|
||||
public void deleteItem(int position) {
|
||||
mList.remove(position);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/6.
|
||||
*/
|
||||
|
||||
public class IllnessHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.text)
|
||||
TextView text;
|
||||
|
||||
private IllAdapter adapter;
|
||||
|
||||
public IllnessHolder(View itemView, IllAdapter adapter) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
public void bindView(final String illness, final int position) {
|
||||
text.setText(illness);
|
||||
text.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(itemView.getContext())
|
||||
.setTitle("删除").setMessage("确定删除该项?");
|
||||
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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 java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/9.
|
||||
*/
|
||||
|
||||
public class MakeStepAdapter extends RecyclerView.Adapter<MakeStepHolder> {
|
||||
private ArrayList<String> mList;
|
||||
private Context mContext;
|
||||
|
||||
public MakeStepAdapter(ArrayList mList, Context mContext) {
|
||||
this.mList = mList;
|
||||
this.mContext = mContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MakeStepHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.make_step_item, parent, false);
|
||||
return new MakeStepHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MakeStepHolder holder, int position) {
|
||||
holder.bindView(mList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/9.
|
||||
*/
|
||||
|
||||
public class MakeStepHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
|
||||
@BindView(R.id.make_step_text_view)
|
||||
TextView makeStepTextView;
|
||||
|
||||
public MakeStepHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bindView(String text) {
|
||||
makeStepTextView.setText(text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
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.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 List<FoodMenu.CookQuantityBean> mList;
|
||||
private Context mContext;
|
||||
|
||||
public MaterialAdapter(List mList, Context mContext) {
|
||||
this.mList = mList;
|
||||
this.mContext = mContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.material_item, parent, false);
|
||||
return new MaterialHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MaterialHolder holder, int position) {
|
||||
holder.bindView(mList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMaterial;
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenu;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/9.
|
||||
*/
|
||||
|
||||
public class MaterialHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
|
||||
@BindView(R.id.weight_number)
|
||||
TextView weightNumber;
|
||||
@BindView(R.id.name)
|
||||
TextView name;
|
||||
|
||||
public MaterialHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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 java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/5.
|
||||
*/
|
||||
|
||||
public class PickerAdapter extends RecyclerView.Adapter<PickerHolder> {
|
||||
private ArrayList<String> list;
|
||||
private Context context;
|
||||
|
||||
public PickerAdapter(ArrayList<String> list, Context context) {
|
||||
super();
|
||||
this.list = list;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PickerHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.picker_item, parent, false);
|
||||
return new PickerHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PickerHolder holder, int position) {
|
||||
holder.bindView(list.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/5.
|
||||
*/
|
||||
|
||||
public class PickerHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.picker_item)
|
||||
TextView pickerItem;
|
||||
|
||||
public PickerHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bindView(String text) {
|
||||
pickerItem.setText(text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
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;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/3.
|
||||
*/
|
||||
|
||||
public class RecommendAdapter extends BaseMultiItemQuickAdapter<RecommendFood, BaseViewHolder> {
|
||||
private Intent intent;
|
||||
|
||||
/**
|
||||
* Same as QuickAdapter#QuickAdapter(Context,int) but with
|
||||
* some initialization data.
|
||||
*
|
||||
* @param data A new list is created out of this one to avoid mutable list
|
||||
*/
|
||||
public RecommendAdapter(List<RecommendFood> data) {
|
||||
super(data);
|
||||
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, final RecommendFood item) {
|
||||
ImageView imageView = helper.getView(R.id.recommend_item_imageview);
|
||||
|
||||
Glide.with(mContext).load(item.getPicture()).into(imageView);
|
||||
View view = helper.getView(R.id.whole_layout);
|
||||
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
|
||||
public void loadMoreComplete() {
|
||||
super.loadMoreComplete();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMoreEnd() {
|
||||
super.loadMoreEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMoreFail() {
|
||||
super.loadMoreFail();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
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.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.modules.classifyresult.DishResultActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import travel.ithaka.android.horizontalpickerlib.PickerLayoutManager;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/5.
|
||||
*/
|
||||
|
||||
public class ResultListAdapter extends RecyclerView.Adapter<ResultListHolder> {
|
||||
private ArrayList<ClassifyResult> mList;
|
||||
private Context context;
|
||||
private PickerLayoutManager pickerLayoutManager;
|
||||
|
||||
public ResultListAdapter(ArrayList<ClassifyResult> list, Context context) {
|
||||
super();
|
||||
this.context = context;
|
||||
Logger.d(NutritionMaster.user);
|
||||
mList = CalculateUtils.getDishQuantity(list, NutritionMaster.user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dish_result_item, parent, false);
|
||||
pickerLayoutManager = new PickerLayoutManager(context, PickerLayoutManager.HORIZONTAL, false);
|
||||
return new ResultListHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ResultListHolder holder, int position) {
|
||||
holder.bindView(mList.get(position), pickerLayoutManager, (DishResultActivity) context, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.example.ninefourone.nutritionmaster.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.LinearSnapHelper;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SnapHelper;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.modules.classifyresult.DishResultActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.github.siyamed.shapeimageview.CircularImageView;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import travel.ithaka.android.horizontalpickerlib.PickerLayoutManager;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/5.
|
||||
*/
|
||||
|
||||
public class ResultListHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.image)
|
||||
ImageView image;
|
||||
@BindView(R.id.name)
|
||||
TextView name;
|
||||
@BindView(R.id.picker)
|
||||
RecyclerView picker;
|
||||
|
||||
private PickerAdapter pickerAdapter;
|
||||
private Context context;
|
||||
|
||||
public ResultListHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
context = itemView.getContext();
|
||||
}
|
||||
|
||||
public void bindView(ClassifyResult classifyResult, PickerLayoutManager pickerLayoutManager,
|
||||
final DishResultActivity dishResultActivity, final int position) {
|
||||
int index = (int) classifyResult.getQuantity() / 2 - 2;
|
||||
pickerLayoutManager.setChangeAlpha(true);
|
||||
pickerLayoutManager.setScaleDownBy(0.99f);
|
||||
pickerLayoutManager.setScaleDownDistance(0.8f);
|
||||
picker.setLayoutManager(pickerLayoutManager);
|
||||
SnapHelper snapHelper = new LinearSnapHelper();
|
||||
snapHelper.attachToRecyclerView(picker);
|
||||
pickerAdapter = new PickerAdapter(ConstantUtils.dishPicerData, context);
|
||||
picker.setAdapter(pickerAdapter);
|
||||
picker.setNestedScrollingEnabled(false);
|
||||
picker.scrollToPosition(index);
|
||||
picker.smoothScrollBy(10, 0);
|
||||
|
||||
pickerLayoutManager.setOnScrollStopListener(new PickerLayoutManager.onScrollStopListener() {
|
||||
@Override
|
||||
public void selectedView(View view) {
|
||||
String text = ((TextView) view).getText().toString();
|
||||
// MessageUtils.MakeToast(text);
|
||||
dishResultActivity.refreshData(Integer.valueOf(text), position);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
name.setText(classifyResult.getName());
|
||||
Glide.with(context).load(classifyResult.getImgPath()).into(image);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.example.ninefourone.nutritionmaster.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
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;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
private Unbinder unbinder;
|
||||
protected MyUser user;
|
||||
private WebUtil webUtil;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.user = NutritionMaster.user;
|
||||
setContentView(getLayoutId());
|
||||
unbinder = ButterKnife.bind(this);
|
||||
webUtil = WebUtil.getInstance();
|
||||
|
||||
initViews(savedInstanceState);
|
||||
initToolBar();
|
||||
|
||||
}
|
||||
|
||||
public WebUtil getWebUtil() {
|
||||
return webUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局layout
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化views
|
||||
*
|
||||
* @param savedInstanceState
|
||||
*/
|
||||
public abstract void initViews(Bundle savedInstanceState);
|
||||
|
||||
/**
|
||||
* 初始化toolbar
|
||||
*/
|
||||
public abstract void initToolBar();
|
||||
|
||||
/**
|
||||
* 加载数据
|
||||
*/
|
||||
public void loadData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示进度条
|
||||
*/
|
||||
public void showProgressBar() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏进度条
|
||||
*/
|
||||
public void hideProgressBar() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化recyclerView
|
||||
*/
|
||||
public void initRecyclerView() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化refreshLayout
|
||||
*/
|
||||
public void initRefreshLayout() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置数据显示
|
||||
*/
|
||||
public void finishTask() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unbinder.unbind();
|
||||
}
|
||||
|
||||
protected void upUser() {
|
||||
NutritionMaster.user = user;
|
||||
NutritionMaster.element = new Element(user);
|
||||
// Logger.d("用户信息已改" + NutritionMaster.user.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
backChangeData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 填写完信息返回Activity调用
|
||||
*/
|
||||
protected void backChangeData() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.example.ninefourone.nutritionmaster.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.bean.MyUser;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/1.
|
||||
*/
|
||||
|
||||
public abstract class BaseDialog extends AlertDialog.Builder {
|
||||
|
||||
protected AlertDialog dialog;
|
||||
|
||||
public BaseDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
protected void upUser(MyUser user) {
|
||||
NutritionMaster.user = user;
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.example.ninefourone.nutritionmaster.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.bean.MyUser;
|
||||
import com.example.ninefourone.nutritionmaster.utils.WebUtil;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
private MyUser user;
|
||||
private View parentView;
|
||||
private FragmentActivity activity;
|
||||
protected boolean isPrepared;
|
||||
protected boolean isVisible;
|
||||
private Unbinder unbinder;
|
||||
private WebUtil webUtil;
|
||||
|
||||
|
||||
public abstract
|
||||
@LayoutRes
|
||||
int getLayoutResId();
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
|
||||
webUtil = WebUtil.getInstance();
|
||||
parentView = inflater.inflate(getLayoutResId(), container, false);
|
||||
activity = getSupportActivity();
|
||||
return parentView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
initView(savedInstanceState);
|
||||
this.user = NutritionMaster.user;
|
||||
}
|
||||
|
||||
|
||||
public WebUtil getWebUtil() {
|
||||
return webUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化自己的ui
|
||||
*
|
||||
* @param state
|
||||
*/
|
||||
public abstract void initView(Bundle state);
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
unbinder.unbind();
|
||||
}
|
||||
|
||||
|
||||
public FragmentActivity getSupportActivity() {
|
||||
return super.getActivity();
|
||||
}
|
||||
|
||||
|
||||
public android.app.ActionBar getSupportActionBar() {
|
||||
return getSupportActivity().getActionBar();
|
||||
}
|
||||
|
||||
|
||||
public Context getApplicationContext() {
|
||||
return this.activity == null ? (getActivity() == null ?
|
||||
null : getActivity().getApplicationContext()) : this.activity.getApplicationContext();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fragment数据的懒加载
|
||||
*/
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (getUserVisibleHint()) {
|
||||
isVisible = true;
|
||||
onVisible();
|
||||
} else {
|
||||
isVisible = false;
|
||||
onInvisible();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fragment显示时才加载数据
|
||||
*/
|
||||
protected void onVisible() {
|
||||
lazyLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* fragment懒加载方法
|
||||
*/
|
||||
protected void lazyLoad() {
|
||||
}
|
||||
|
||||
/**
|
||||
* fragment隐藏
|
||||
*/
|
||||
protected void onInvisible() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载数据
|
||||
*/
|
||||
protected void loadData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示进度条
|
||||
*/
|
||||
protected void showProgressBar() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏进度条
|
||||
*/
|
||||
protected void hideProgressBar() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化recyclerView
|
||||
*/
|
||||
protected void initRecyclerView() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化refreshLayout
|
||||
*/
|
||||
protected void initRefreshLayout() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置数据显示
|
||||
*/
|
||||
protected void finishTask() {
|
||||
}
|
||||
|
||||
protected void upUser() {
|
||||
NutritionMaster.user = user;
|
||||
Logger.d("用户信息已改" + NutritionMaster.user.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
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 okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/4.
|
||||
*/
|
||||
|
||||
public class ClassifyResult implements Serializable {
|
||||
|
||||
private String imgPath;
|
||||
private double probability;
|
||||
private String name;
|
||||
private double calorie = 0;
|
||||
private Boolean has_calorie = false;
|
||||
private double quantity = -1;
|
||||
private FoodMenu foodMenu;
|
||||
private Material foodMaterial;
|
||||
|
||||
private int flag = -1;
|
||||
public static int MATERIAL = 0;
|
||||
public static int DISH = 1;
|
||||
|
||||
public ClassifyResult(int flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public void getMenu() {
|
||||
if (flag == DISH) {
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
webUtil.getMenu(name, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
name = "-1";
|
||||
Logger.e("我们数据库没有这个菜");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
FoodMenu menu = new Gson().fromJson(response.body().string(), FoodMenu.class);
|
||||
foodMenu = menu;
|
||||
Logger.d(name + "|" + menu);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Logger.e("flag 为材料的");
|
||||
}
|
||||
}
|
||||
|
||||
public void getMaterial() {
|
||||
if (flag == MATERIAL) {
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
webUtil.getFoodMaterial(name, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
FoodMaterial material = new Gson().fromJson(json, FoodMaterial.class);
|
||||
foodMaterial = new Material();
|
||||
foodMaterial.setFoodMaterial(material);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Logger.e("flag 为菜谱的");
|
||||
}
|
||||
}
|
||||
|
||||
public Material getFoodMaterial() {
|
||||
return foodMaterial;
|
||||
}
|
||||
|
||||
public FoodMenu getFoodMenu() {
|
||||
return foodMenu;
|
||||
}
|
||||
|
||||
public void setFoodMenu(FoodMenu foodMenu) {
|
||||
this.foodMenu = foodMenu;
|
||||
}
|
||||
|
||||
public double getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(double quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getImgPath() {
|
||||
return imgPath;
|
||||
}
|
||||
|
||||
public void setImgPath(String imgPath) {
|
||||
this.imgPath = imgPath;
|
||||
}
|
||||
|
||||
public double getProbability() {
|
||||
return probability;
|
||||
}
|
||||
|
||||
public void setProbability(double probability) {
|
||||
this.probability = probability;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
if (flag == MATERIAL) {
|
||||
getMaterial();
|
||||
} else {
|
||||
getMenu();
|
||||
}
|
||||
}
|
||||
|
||||
public double getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public void setCalorie(double calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public Boolean getHas_calorie() {
|
||||
return has_calorie;
|
||||
}
|
||||
|
||||
public void setHas_calorie(Boolean has_calorie) {
|
||||
this.has_calorie = has_calorie;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + ";置信度" + probability + ";卡路里" + calorie;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/3.
|
||||
*/
|
||||
|
||||
public class DailyCard {
|
||||
/***
|
||||
* 每日卡片bean类
|
||||
*/
|
||||
private String title;
|
||||
private String description;
|
||||
private int pictureId;
|
||||
|
||||
public DailyCard(String title, String description, int pictureId) {
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.pictureId = pictureId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getPictureId() {
|
||||
return pictureId;
|
||||
}
|
||||
|
||||
public void setPictureId(int pictureId) {
|
||||
this.pictureId = pictureId;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class FoodMaterial implements Serializable {
|
||||
|
||||
/**
|
||||
* material_name : 西红柿
|
||||
* cook_quantity : [{"menu":"西红柿鸡蛋汤","quantity":"适量","material":"西红柿"},{"menu":"瘦身版红菜汤","quantity":"4-5片","material":"西红柿"},{"menu":"西红柿炖豆腐","quantity":"三个","material":"西红柿"},{"menu":"傣味凉拌黄瓜","quantity":"一个","material":"西红柿"},{"menu":"健康早餐竹炭三明治","quantity":"适量","material":"西红柿"},{"menu":"豆腐卤","quantity":"一粒","material":"西红柿"},{"menu":"减肥美食蕃薯芦笋鱼柳","quantity":"适量","material":"西红柿"},{"menu":"瘦身美食凤尾香梨番茄盅","quantity":"适量","material":"西红柿"},{"menu":"低脂美味快手的番茄烤大比目鱼","quantity":"900g","material":"西红柿"},{"menu":"田园蔬菜养生汤","quantity":"适量","material":"西红柿"},{"menu":"抗衰老的番茄鲜藕橙杯","quantity":"适量","material":"西红柿"},{"menu":"抗衰老美食菠菜三文鱼芥末堆","quantity":"适量","material":"西红柿"},{"menu":"凉拌莜面","quantity":"3g","material":"西红柿"},{"menu":"夏季护发防晒美食-苏子烤鸡腿配玉米奶酪西红柿","quantity":"适量","material":"西红柿"},{"menu":"美白防晒的番茄双笋银杏果","quantity":"适量","material":"西红柿"},{"menu":"家庭自制大西北风味羊肉粉汤","quantity":"两勺","material":"西红柿"}]
|
||||
* elements : {"id":1162,"calorie":20,"carbohydrate":3.5,"fat":0.2,"protein":0.9,"cellulose":0.5,"vitaminA":92,"vitaminB1":0,"vitaminB2":0.03,"vitaminB6":0,"vitaminC":19,"vitaminE":0.57,"carotene":550,"cholesterol":0,"Mg":9,"Ca":10,"Fe":0.4,"Zn":0.13,"Cu":0.06,"Mn":0.08,"K":163,"P":23,"Na":5,"Se":0.15,"niacin":0.6,"thiamine":0.03}
|
||||
*/
|
||||
|
||||
private String material_name;
|
||||
private ElementsBean elements;
|
||||
private List<CookQuantityBean> cook_quantity;
|
||||
|
||||
public String getMaterial_name() {
|
||||
return material_name;
|
||||
}
|
||||
|
||||
public void setMaterial_name(String material_name) {
|
||||
this.material_name = material_name;
|
||||
}
|
||||
|
||||
public ElementsBean getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public void setElements(ElementsBean elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public List<CookQuantityBean> getCook_quantity() {
|
||||
return cook_quantity;
|
||||
}
|
||||
|
||||
public void setCook_quantity(List<CookQuantityBean> cook_quantity) {
|
||||
this.cook_quantity = cook_quantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FoodMaterial{" +
|
||||
"material_name='" + material_name + '\'' +
|
||||
", elements=" + elements +
|
||||
", cook_quantity=" + cook_quantity +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class ElementsBean implements Serializable {
|
||||
/**
|
||||
* id : 1162
|
||||
* calorie : 20
|
||||
* carbohydrate : 3.5
|
||||
* fat : 0.2
|
||||
* protein : 0.9
|
||||
* cellulose : 0.5
|
||||
* vitaminA : 92
|
||||
* vitaminB1 : 0
|
||||
* vitaminB2 : 0.03
|
||||
* vitaminB6 : 0
|
||||
* vitaminC : 19
|
||||
* vitaminE : 0.57
|
||||
* carotene : 550
|
||||
* cholesterol : 0
|
||||
* Mg : 9
|
||||
* Ca : 10
|
||||
* Fe : 0.4
|
||||
* Zn : 0.13
|
||||
* Cu : 0.06
|
||||
* Mn : 0.08
|
||||
* K : 163
|
||||
* P : 23
|
||||
* Na : 5
|
||||
* Se : 0.15
|
||||
* niacin : 0.6
|
||||
* thiamine : 0.03
|
||||
*/
|
||||
|
||||
private float id;
|
||||
private float calorie;
|
||||
private double carbohydrate;
|
||||
private double fat;
|
||||
private double protein;
|
||||
private double cellulose;
|
||||
private float vitaminA;
|
||||
private float vitaminB1;
|
||||
private double vitaminB2;
|
||||
private float vitaminB6;
|
||||
private float vitaminC;
|
||||
private double vitaminE;
|
||||
private float carotene;
|
||||
private float cholesterol;
|
||||
private float Mg;
|
||||
private float Ca;
|
||||
private double Fe;
|
||||
private double Zn;
|
||||
private double Cu;
|
||||
private double Mn;
|
||||
private float K;
|
||||
private float P;
|
||||
private float Na;
|
||||
private double Se;
|
||||
private double niacin;
|
||||
private double thiamine;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ElementsBean{" +
|
||||
"id=" + id +
|
||||
", 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 float getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(float id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public float getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public void setCalorie(float calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public double getCarbohydrate() {
|
||||
return carbohydrate;
|
||||
}
|
||||
|
||||
public void setCarbohydrate(double carbohydrate) {
|
||||
this.carbohydrate = carbohydrate;
|
||||
}
|
||||
|
||||
public double getFat() {
|
||||
return fat;
|
||||
}
|
||||
|
||||
public void setFat(double fat) {
|
||||
this.fat = fat;
|
||||
}
|
||||
|
||||
public double getProtein() {
|
||||
return protein;
|
||||
}
|
||||
|
||||
public void setProtein(double protein) {
|
||||
this.protein = protein;
|
||||
}
|
||||
|
||||
public double getCellulose() {
|
||||
return cellulose;
|
||||
}
|
||||
|
||||
public void setCellulose(double cellulose) {
|
||||
this.cellulose = cellulose;
|
||||
}
|
||||
|
||||
public float getVitaminA() {
|
||||
return vitaminA;
|
||||
}
|
||||
|
||||
public void setVitaminA(float vitaminA) {
|
||||
this.vitaminA = vitaminA;
|
||||
}
|
||||
|
||||
public float getVitaminB1() {
|
||||
return vitaminB1;
|
||||
}
|
||||
|
||||
public void setVitaminB1(float vitaminB1) {
|
||||
this.vitaminB1 = vitaminB1;
|
||||
}
|
||||
|
||||
public double getVitaminB2() {
|
||||
return vitaminB2;
|
||||
}
|
||||
|
||||
public void setVitaminB2(double vitaminB2) {
|
||||
this.vitaminB2 = vitaminB2;
|
||||
}
|
||||
|
||||
public float getVitaminB6() {
|
||||
return vitaminB6;
|
||||
}
|
||||
|
||||
public void setVitaminB6(float vitaminB6) {
|
||||
this.vitaminB6 = vitaminB6;
|
||||
}
|
||||
|
||||
public float getVitaminC() {
|
||||
return vitaminC;
|
||||
}
|
||||
|
||||
public void setVitaminC(float vitaminC) {
|
||||
this.vitaminC = vitaminC;
|
||||
}
|
||||
|
||||
public double getVitaminE() {
|
||||
return vitaminE;
|
||||
}
|
||||
|
||||
public void setVitaminE(double vitaminE) {
|
||||
this.vitaminE = vitaminE;
|
||||
}
|
||||
|
||||
public float getCarotene() {
|
||||
return carotene;
|
||||
}
|
||||
|
||||
public void setCarotene(float carotene) {
|
||||
this.carotene = carotene;
|
||||
}
|
||||
|
||||
public float getCholesterol() {
|
||||
return cholesterol;
|
||||
}
|
||||
|
||||
public void setCholesterol(float cholesterol) {
|
||||
this.cholesterol = cholesterol;
|
||||
}
|
||||
|
||||
public float getMg() {
|
||||
return Mg;
|
||||
}
|
||||
|
||||
public void setMg(float Mg) {
|
||||
this.Mg = Mg;
|
||||
}
|
||||
|
||||
public float getCa() {
|
||||
return Ca;
|
||||
}
|
||||
|
||||
public void setCa(float Ca) {
|
||||
this.Ca = Ca;
|
||||
}
|
||||
|
||||
public double getFe() {
|
||||
return Fe;
|
||||
}
|
||||
|
||||
public void setFe(double Fe) {
|
||||
this.Fe = Fe;
|
||||
}
|
||||
|
||||
public double getZn() {
|
||||
return Zn;
|
||||
}
|
||||
|
||||
public void setZn(double Zn) {
|
||||
this.Zn = Zn;
|
||||
}
|
||||
|
||||
public double getCu() {
|
||||
return Cu;
|
||||
}
|
||||
|
||||
public void setCu(double Cu) {
|
||||
this.Cu = Cu;
|
||||
}
|
||||
|
||||
public double getMn() {
|
||||
return Mn;
|
||||
}
|
||||
|
||||
public void setMn(double Mn) {
|
||||
this.Mn = Mn;
|
||||
}
|
||||
|
||||
public float getK() {
|
||||
return K;
|
||||
}
|
||||
|
||||
public void setK(float K) {
|
||||
this.K = K;
|
||||
}
|
||||
|
||||
public float getP() {
|
||||
return P;
|
||||
}
|
||||
|
||||
public void setP(float P) {
|
||||
this.P = P;
|
||||
}
|
||||
|
||||
public float getNa() {
|
||||
return Na;
|
||||
}
|
||||
|
||||
public void setNa(float Na) {
|
||||
this.Na = Na;
|
||||
}
|
||||
|
||||
public double getSe() {
|
||||
return Se;
|
||||
}
|
||||
|
||||
public void setSe(double Se) {
|
||||
this.Se = Se;
|
||||
}
|
||||
|
||||
public double getNiacin() {
|
||||
return niacin;
|
||||
}
|
||||
|
||||
public void setNiacin(double niacin) {
|
||||
this.niacin = niacin;
|
||||
}
|
||||
|
||||
public double getThiamine() {
|
||||
return thiamine;
|
||||
}
|
||||
|
||||
public void setThiamine(double thiamine) {
|
||||
this.thiamine = thiamine;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CookQuantityBean implements Serializable{
|
||||
/**
|
||||
* menu : 西红柿鸡蛋汤
|
||||
* quantity : 适量
|
||||
* material : 西红柿
|
||||
*/
|
||||
private String menu;
|
||||
private String quantity;
|
||||
private String material;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CookQuantityBean{" +
|
||||
"menu='" + menu + '\'' +
|
||||
", quantity='" + quantity + '\'' +
|
||||
", material='" + material + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getMenu() {
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void setMenu(String menu) {
|
||||
this.menu = menu;
|
||||
}
|
||||
|
||||
public String getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(String quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public void setMaterial(String material) {
|
||||
this.material = material;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,472 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class FoodMenu implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* flavor : 五香味
|
||||
* calorie : 157
|
||||
* name : 五香酥鱼
|
||||
* technology : 卤
|
||||
* image_url : http://s1.st.meishij.net/r/26/70/2392526/a2392526_144672974229833.jpg
|
||||
* cook_quantity : [{"menu":"五香酥鱼","quantity":"500","material":"鲫鱼"},{"menu":"五香酥鱼","quantity":"250","material":"大葱"},{"menu":"五香酥鱼","quantity":"50","material":"姜"},{"menu":"五香酥鱼","quantity":"50","material":"大蒜(白皮)"},{"menu":"五香酥鱼","quantity":"2","material":"桂皮"},{"menu":"五香酥鱼","quantity":"2","material":"茴香粉"},{"menu":"五香酥鱼","quantity":"3","material":"料酒"},{"menu":"五香酥鱼","quantity":"75","material":"酱油"},{"menu":"五香酥鱼","quantity":"75","material":"醋"},{"menu":"五香酥鱼","quantity":"75","material":"香油"},{"menu":"五香酥鱼","quantity":"100","material":"白砂糖"}]
|
||||
* practice : ['1. 将鲫鱼刮洗干净;', '2. 大葱洗净切段;姜、蒜洗净切片备用;', '3. 将锅底里垫上一层竹垫,先将鲫鱼放在竹垫上整齐排列(头朝外、肚朝上,侧放),把各种香料均匀地铺放一层在鱼身上,再放一层鱼,再放一层调料 ,就这样直至把鱼和调料放完;', '4. 加黄酒、酱油、米醋、白糖、鲜汤、然后盖上锅盖,使其尽量密封;', '5. 用大火烧沸后,转用小火焖烧五小时;', '6. 待鱼骨酥烂时,淋上麻油,用大火收稠卤汁,然后离火冷却,待结冻后再小心取出装盘。']
|
||||
* menuclassification_set : ["京菜","健脾开胃食谱","补虚养身食谱","产后调理食谱","肾炎食谱"]
|
||||
* elements : {"id":3940,"calorie":183,"carbohydrate":17.5,"fat":9.727272727272727,"protein":4.254545454545454,"cellulose":4.2272727272727275,"vitaminA":42,"vitaminB1":0,"vitaminB2":0.05454545454545456,"vitaminB6":0,"vitaminC":4.909090909090909,"vitaminE":0.9899999999999999,"carotene":242.72727272727272,"cholesterol":11.818181818181818,"Mg":31.181818181818183,"Ca":47.18181818181818,"Fe":1.9454545454545455,"Zn":0.6363636363636362,"Cu":0.12090909090909091,"Mn":1.7381818181818183,"K":185.45454545454547,"P":64.0909090909091,"Na":571.5363636363636,"Se":2.183636363636364,"niacin":0.7545454545454544,"thiamine":0.025454545454545455}
|
||||
*/
|
||||
|
||||
private String flavor;
|
||||
private float calorie;
|
||||
private String name;
|
||||
private int is_breakfast;
|
||||
private String technology;
|
||||
private String image_url;
|
||||
private String practice;
|
||||
private ElementsBean elements;
|
||||
private List<CookQuantityBean> cook_quantity;
|
||||
private List<String> menuclassification_set;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FoodMenu{" +
|
||||
"flavor='" + flavor + '\'' +
|
||||
", calorie=" + calorie +
|
||||
", name='" + name + '\'' +
|
||||
", is_breakfast=" + is_breakfast +
|
||||
", technology='" + technology + '\'' +
|
||||
", image_url='" + image_url + '\'' +
|
||||
", practice='" + practice + '\'' +
|
||||
", elements=" + elements +
|
||||
", cook_quantity=" + cook_quantity +
|
||||
", menuclassification_set=" + menuclassification_set +
|
||||
'}';
|
||||
}
|
||||
|
||||
public int getIs_breakfast() {
|
||||
return is_breakfast;
|
||||
}
|
||||
|
||||
public void setIs_breakfast(int is_breakfast) {
|
||||
this.is_breakfast = is_breakfast;
|
||||
}
|
||||
|
||||
public String getFlavor() {
|
||||
return flavor;
|
||||
}
|
||||
|
||||
public void setFlavor(String flavor) {
|
||||
this.flavor = flavor;
|
||||
}
|
||||
|
||||
public float getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public void setCalorie(float calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTechnology() {
|
||||
return technology;
|
||||
}
|
||||
|
||||
public void setTechnology(String technology) {
|
||||
this.technology = technology;
|
||||
}
|
||||
|
||||
public String getImage_url() {
|
||||
return image_url;
|
||||
}
|
||||
|
||||
public void setImage_url(String image_url) {
|
||||
this.image_url = image_url;
|
||||
}
|
||||
|
||||
public String getPractice() {
|
||||
return practice;
|
||||
}
|
||||
|
||||
public void setPractice(String practice) {
|
||||
this.practice = practice;
|
||||
}
|
||||
|
||||
public ElementsBean getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public void setElements(ElementsBean elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public List<CookQuantityBean> getCook_quantity() {
|
||||
return cook_quantity;
|
||||
}
|
||||
|
||||
public void setCook_quantity(List<CookQuantityBean> cook_quantity) {
|
||||
this.cook_quantity = cook_quantity;
|
||||
}
|
||||
|
||||
public List<String> getMenuclassification_set() {
|
||||
return menuclassification_set;
|
||||
}
|
||||
|
||||
public void setMenuclassification_set(List<String> menuclassification_set) {
|
||||
this.menuclassification_set = menuclassification_set;
|
||||
}
|
||||
|
||||
public static class ElementsBean implements Serializable {
|
||||
/**
|
||||
* id : 3940
|
||||
* calorie : 183
|
||||
* carbohydrate : 17.5
|
||||
* fat : 9.727272727272727
|
||||
* protein : 4.254545454545454
|
||||
* cellulose : 4.2272727272727275
|
||||
* vitaminA : 42
|
||||
* vitaminB1 : 0
|
||||
* vitaminB2 : 0.05454545454545456
|
||||
* vitaminB6 : 0
|
||||
* vitaminC : 4.909090909090909
|
||||
* vitaminE : 0.9899999999999999
|
||||
* carotene : 242.72727272727272
|
||||
* cholesterol : 11.818181818181818
|
||||
* Mg : 31.181818181818183
|
||||
* Ca : 47.18181818181818
|
||||
* Fe : 1.9454545454545455
|
||||
* Zn : 0.6363636363636362
|
||||
* Cu : 0.12090909090909091
|
||||
* Mn : 1.7381818181818183
|
||||
* K : 185.45454545454547
|
||||
* P : 64.0909090909091
|
||||
* Na : 571.5363636363636
|
||||
* Se : 2.183636363636364
|
||||
* niacin : 0.7545454545454544
|
||||
* thiamine : 0.025454545454545455
|
||||
*/
|
||||
|
||||
private float id;
|
||||
private float calorie;
|
||||
private double carbohydrate;
|
||||
private double fat;
|
||||
private double protein;
|
||||
private double cellulose;
|
||||
private float vitaminA;
|
||||
private float vitaminB1;
|
||||
private double vitaminB2;
|
||||
private float vitaminB6;
|
||||
private double vitaminC;
|
||||
private double vitaminE;
|
||||
private double carotene;
|
||||
private double cholesterol;
|
||||
private double Mg;
|
||||
private double Ca;
|
||||
private double Fe;
|
||||
private double Zn;
|
||||
private double Cu;
|
||||
private double Mn;
|
||||
private double K;
|
||||
private double P;
|
||||
private double Na;
|
||||
private double Se;
|
||||
private double niacin;
|
||||
private double thiamine;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ElementsBean{" +
|
||||
"id=" + id +
|
||||
", 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 float getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(float id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public float getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public void setCalorie(float calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public double getCarbohydrate() {
|
||||
return carbohydrate;
|
||||
}
|
||||
|
||||
public void setCarbohydrate(double carbohydrate) {
|
||||
this.carbohydrate = carbohydrate;
|
||||
}
|
||||
|
||||
public double getFat() {
|
||||
return fat;
|
||||
}
|
||||
|
||||
public void setFat(double fat) {
|
||||
this.fat = fat;
|
||||
}
|
||||
|
||||
public double getProtein() {
|
||||
return protein;
|
||||
}
|
||||
|
||||
public void setProtein(double protein) {
|
||||
this.protein = protein;
|
||||
}
|
||||
|
||||
public double getCellulose() {
|
||||
return cellulose;
|
||||
}
|
||||
|
||||
public void setCellulose(double cellulose) {
|
||||
this.cellulose = cellulose;
|
||||
}
|
||||
|
||||
public float getVitaminA() {
|
||||
return vitaminA;
|
||||
}
|
||||
|
||||
public void setVitaminA(float vitaminA) {
|
||||
this.vitaminA = vitaminA;
|
||||
}
|
||||
|
||||
public float getVitaminB1() {
|
||||
return vitaminB1;
|
||||
}
|
||||
|
||||
public void setVitaminB1(float vitaminB1) {
|
||||
this.vitaminB1 = vitaminB1;
|
||||
}
|
||||
|
||||
public double getVitaminB2() {
|
||||
return vitaminB2;
|
||||
}
|
||||
|
||||
public void setVitaminB2(double vitaminB2) {
|
||||
this.vitaminB2 = vitaminB2;
|
||||
}
|
||||
|
||||
public float getVitaminB6() {
|
||||
return vitaminB6;
|
||||
}
|
||||
|
||||
public void setVitaminB6(float vitaminB6) {
|
||||
this.vitaminB6 = vitaminB6;
|
||||
}
|
||||
|
||||
public double getVitaminC() {
|
||||
return vitaminC;
|
||||
}
|
||||
|
||||
public void setVitaminC(double vitaminC) {
|
||||
this.vitaminC = vitaminC;
|
||||
}
|
||||
|
||||
public double getVitaminE() {
|
||||
return vitaminE;
|
||||
}
|
||||
|
||||
public void setVitaminE(double vitaminE) {
|
||||
this.vitaminE = vitaminE;
|
||||
}
|
||||
|
||||
public double getCarotene() {
|
||||
return carotene;
|
||||
}
|
||||
|
||||
public void setCarotene(double carotene) {
|
||||
this.carotene = carotene;
|
||||
}
|
||||
|
||||
public double getCholesterol() {
|
||||
return cholesterol;
|
||||
}
|
||||
|
||||
public void setCholesterol(double cholesterol) {
|
||||
this.cholesterol = cholesterol;
|
||||
}
|
||||
|
||||
public double getMg() {
|
||||
return Mg;
|
||||
}
|
||||
|
||||
public void setMg(double Mg) {
|
||||
this.Mg = Mg;
|
||||
}
|
||||
|
||||
public double getCa() {
|
||||
return Ca;
|
||||
}
|
||||
|
||||
public void setCa(double Ca) {
|
||||
this.Ca = Ca;
|
||||
}
|
||||
|
||||
public double getFe() {
|
||||
return Fe;
|
||||
}
|
||||
|
||||
public void setFe(double Fe) {
|
||||
this.Fe = Fe;
|
||||
}
|
||||
|
||||
public double getZn() {
|
||||
return Zn;
|
||||
}
|
||||
|
||||
public void setZn(double Zn) {
|
||||
this.Zn = Zn;
|
||||
}
|
||||
|
||||
public double getCu() {
|
||||
return Cu;
|
||||
}
|
||||
|
||||
public void setCu(double Cu) {
|
||||
this.Cu = Cu;
|
||||
}
|
||||
|
||||
public double getMn() {
|
||||
return Mn;
|
||||
}
|
||||
|
||||
public void setMn(double Mn) {
|
||||
this.Mn = Mn;
|
||||
}
|
||||
|
||||
public double getK() {
|
||||
return K;
|
||||
}
|
||||
|
||||
public void setK(double K) {
|
||||
this.K = K;
|
||||
}
|
||||
|
||||
public double getP() {
|
||||
return P;
|
||||
}
|
||||
|
||||
public void setP(double P) {
|
||||
this.P = P;
|
||||
}
|
||||
|
||||
public double getNa() {
|
||||
return Na;
|
||||
}
|
||||
|
||||
public void setNa(double Na) {
|
||||
this.Na = Na;
|
||||
}
|
||||
|
||||
public double getSe() {
|
||||
return Se;
|
||||
}
|
||||
|
||||
public void setSe(double Se) {
|
||||
this.Se = Se;
|
||||
}
|
||||
|
||||
public double getNiacin() {
|
||||
return niacin;
|
||||
}
|
||||
|
||||
public void setNiacin(double niacin) {
|
||||
this.niacin = niacin;
|
||||
}
|
||||
|
||||
public double getThiamine() {
|
||||
return thiamine;
|
||||
}
|
||||
|
||||
public void setThiamine(double thiamine) {
|
||||
this.thiamine = thiamine;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CookQuantityBean implements Serializable{
|
||||
/**
|
||||
* menu : 五香酥鱼
|
||||
* quantity : 500
|
||||
* material : 鲫鱼
|
||||
*/
|
||||
|
||||
private String menu;
|
||||
private String quantity;
|
||||
private String material;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CookQuantityBean{" +
|
||||
"menu='" + menu + '\'' +
|
||||
", quantity='" + quantity + '\'' +
|
||||
", material='" + material + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getMenu() {
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void setMenu(String menu) {
|
||||
this.menu = menu;
|
||||
}
|
||||
|
||||
public String getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(String quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public void setMaterial(String material) {
|
||||
this.material = material;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class FoodMenuLight implements Serializable{
|
||||
|
||||
/**
|
||||
* name : 番茄虾仁
|
||||
* calorie : 20
|
||||
* elements : 2953
|
||||
*/
|
||||
|
||||
private String name;
|
||||
private double calorie;
|
||||
private int elements;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public void setCalorie(int calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public double getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public void setElements(int elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FoodMenuLight{" +
|
||||
"name='" + name + '\'' +
|
||||
", calorie=" + calorie +
|
||||
", elements=" + elements +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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/10/7.
|
||||
*/
|
||||
|
||||
public class Material implements Serializable {
|
||||
FoodMaterial foodMaterial;
|
||||
ArrayList<FoodMenu> menus = new ArrayList<>();
|
||||
|
||||
public FoodMaterial getFoodMaterial() {
|
||||
return foodMaterial;
|
||||
}
|
||||
|
||||
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 ArrayList<FoodMenu> getMenus() {
|
||||
return menus;
|
||||
}
|
||||
|
||||
public void setMenus(ArrayList<FoodMenu> menus) {
|
||||
this.menus = menus;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class MenuClassification implements Serializable{
|
||||
|
||||
/**
|
||||
* classification : 川菜
|
||||
* cure_occupation : []
|
||||
* menu_effect : ["三色鲍脯","三色鸡酪","三菇冬瓜汤","三菌烩蛇段","三鲜乌鱼汤","三鲜参片汤","三鲜猪肝汤","下饭的素版麻婆豆腐","丝瓜鱼肚卷","五更豆酥鱼","元鱼烧鸡","冬苋菜豆腐汤","冬菜排骨汤","凉拌马齿苋","凉粉","十全乌鸡汤","南瓜蹄花汤","南瓜鲜带","咖喱兔肉","四川凉面","四川水煮牛肉","四川腊味香肠","回锅肉","园林香液鸡","多味瓜卷","大蒜烧鳝鱼","天麻乳鸽盅","奶油鱼肚","姜汁墨斗鱼丝","姜汁蹄花","姜芽炒兔丝","宫保肉丁","家常热味肘子","家常牛蹄筋","家常田鸡","家常臊子鱼","小笼牛肉","小米椒爆仔兔","尖椒北极贝","尖椒炒鲫鱼","川味砂锅之萝卜羊排","川蒜烧鲶鱼","巴国三菌蛇段汤","巴国冬瓜盅","巴国南瓜汤","巴国大排","巴国家常扣肉","巴国寨子鸡","巴国燕翅羹","巴国片皮鸭","巴国腊味拼盘","巴国辣香蛇","巴国钵钵兔","巴国风味兔","带丝全鸭","干煸兔丝","干煸冬笋","干煸青椒苦瓜","干豇豆排骨汤","干贝三圆","开水菜头","怪味鹿肉","扣肉仔兔","拌侧耳根","拌猪耳朵","旱蒸全鸡","时蔬肉丸汤","明炉三菌甲鱼汤","明炉三鲜鱼头汤","明炉什锦菊花锅","明炉酸萝卜鱼片汤","明虾烧粉丝","朝天锅","松仁鸡米","板栗烧凤翅","果味脯酥鱼","果蔬牛蛙","椒盐八炸鸡","椒盐脆鳝","椒盐蛇衣","椒盐鹅黄肉","椒麻腰片","正宗经典川菜麻婆豆腐","水煮牛柳","水煮财鱼","水豆豉鸭舌","永川豉汁排骨","泡椒圣子王","泡椒羊杂","泡椒鳝鱼","泡蛋汤","泡豇豆煸鲫鱼","洋参乌鸡汤","活捉青笋尖","海带卷","海带肘子汤","海白菜烧猪耳","淮杞牛鞭汤","清水菜头","清汤燕窝","清汤鱿鱼方","清炖羊肉汤","清蒸花鲢鱼头","清蒸鲫鱼3","滑嫩牛肉丝","滑炒蟹肉","火爆腰花2","火锅鸡","炖节瓜盅","炝圆白菜卷","炝豆芽菜","炮筒鳝鱼","炸桃腰","炸脆鳝","烩三色鱼丸","烩两色虾丸","煎焖虾饼","煎苦瓜鸡粒饼","熏豆腐干","熘鸡丝","猕猴桃甜烧白","玛瑙豆腐汤","珊瑚鱼条","生菜大明虾","番茄土豆丝","番茄炖兔","番茄炖鸡","番茄虾仁","番茄鸡蛋竹荪汤","白果乌鸡汤","白油猪肝","盐烧蟹","盐白菜爆鸭舌","砂锅鱼头汤","空心菜炝玉米","竹荪蝴蝶鱼肚汤","粉蒸泥鳅","粉蒸肥肠","粉蒸辣鲫鱼","糖醋茄饼","素牛肉","素蒸咸烧白","素鸡豆花","红烧刺参","红烧豆腐鳝段","红烧鱼肉","红烧鸭/红烧鸭子","红苕粉烧鳝鱼","绍子海参","羊杂汤","老干妈爆鸭舌","肉片汤","肚条豆芽汤","脆皮肠头","腊肉炖萝卜","腊肉绿豆汤","芙蓉红","芙蓉蒸海蟹","芝麻海参排","芝麻脊片","芥末扇贝","花椒油拌鲜芦笋","花菇油菜心","芳香排骨","芽菜烧肚条","苦瓜蒸肉丸","萝卜炖羊排","葱油滑菇","葱烧鲫鱼","葱茸竹荪","葱辣大虾","蒜汁时蔬","蒜烧海蟹","蒸渣肉","蒸芋头","蕉条茄子","虫草龟蛇汤","蜜柚烧牛蛙","西芹香辣兔","解馋瘦身菜宫保杏鲍菇","豆瓣活鲤","豆瓣鲜鱼面","豆瓣鲤鱼","豆腐丸子","豆腐虾仁","豆腐鲤鱼","豆花鱼","豆茸扣肉","豆豉鱼","豉汁蟠龙鳗","贵妃鸡翼","软炸兔糕","软炸烧白","辣味狗肉","辣味茄子","酒醉桃仁","酥炸大豆糕","酥炸茄饼","酥炸虾排","酥炸金片","酥炸鸭片","酱油鸡","酱烧冬笋","酱烧小黄鱼","酱蛤蜊","酸菜双瓜汤","酸菜蹄筋汤","酸菜鲈鱼汤","酸萝卜马蹄炖鸭","酸辣五丝汤","酸辣韭黄蛋花汤","醋烹土豆丝","金钩烘蛋","金银脑花","银鱼掐菜","锅烧肉","雪银虾饼","雪魔芋烧鹅掌","青椒玉米","青椒茄泥","青菜狮子头","香炸粉蒸肉","香炸麻辣牛排","香菇鱼块","香辣鲫鱼","香酥蛇段","魔芋海参","鱼仔蛋烩萝卜","鱼香回锅鸭","鱼香排骨","鱼香煎羊排","鱼香瓦块鱼","鱼香番茄过江","鱼香虾糕","鲍鱼鸽蛋","鲜熘竹荪蛋","鲜菜鱼皮","鸡蓉鲍片","麻辣牛筋","麻辣牛肉丁","麻辣牛肉干","麻辣牛肉条","麻辣香水鱼","麻香耗儿鱼","黄焖海参","黄瓜皮蛋汤","黄豆芽排骨汤","龙井鲍片"]
|
||||
*/
|
||||
|
||||
private String classification;
|
||||
private List<?> cure_occupation;
|
||||
private List<String> menu_effect;
|
||||
|
||||
public String getClassification() {
|
||||
return classification;
|
||||
}
|
||||
|
||||
public void setClassification(String classification) {
|
||||
this.classification = classification;
|
||||
}
|
||||
|
||||
public List<?> getCure_occupation() {
|
||||
return cure_occupation;
|
||||
}
|
||||
|
||||
public void setCure_occupation(List<?> cure_occupation) {
|
||||
this.cure_occupation = cure_occupation;
|
||||
}
|
||||
|
||||
public List<String> getMenu_effect() {
|
||||
return menu_effect;
|
||||
}
|
||||
|
||||
public void setMenu_effect(List<String> menu_effect) {
|
||||
this.menu_effect = menu_effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MenuClassification{" +
|
||||
"classification='" + classification + '\'' +
|
||||
", cure_occupation=" + cure_occupation +
|
||||
", menu_effect=" + menu_effect +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,595 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MyUser {
|
||||
|
||||
/**
|
||||
* id : 2
|
||||
* eaten_elements : {"id":12127,"calorie":1046,"carbohydrate":33.56923076923077,"fat":17.138461538461538,"protein":13.492307692307692,"cellulose":5.723076923076923,"vitaminA":16.307692307692307,"vitaminB1":0,"vitaminB2":0.16,"vitaminB6":0,"vitaminC":9.692307692307692,"vitaminE":7.483076923076923,"carotene":84.61538461538461,"cholesterol":29.692307692307693,"Mg":116.61538461538461,"Ca":230.76923076923077,"Fe":7.523076923076923,"Zn":1.209230769230769,"Cu":0.4138461538461539,"Mn":1.5138461538461538,"K":285.6923076923077,"P":92,"Na":15580.876923076923,"Se":7.636923076923078,"niacin":1.169230769230769,"thiamine":0.06307692307692307}
|
||||
* physical_name : 瘀血质
|
||||
* password : updata
|
||||
* last_login : null
|
||||
* is_superuser : false
|
||||
* username : updatatest
|
||||
* first_name :
|
||||
* last_name :
|
||||
* email :
|
||||
* is_staff : false
|
||||
* is_active : false
|
||||
* date_joined : 2018-09-16T20:21:40.466423+08:00
|
||||
* sex : 1
|
||||
* age : 0
|
||||
* height : 0
|
||||
* weight : 0
|
||||
* bmi : -1
|
||||
* occupation_name : null
|
||||
* groups : []
|
||||
* user_permissions : []
|
||||
* illness : []
|
||||
*/
|
||||
|
||||
private Integer id;
|
||||
private EatenElementsBean eaten_elements = new EatenElementsBean();
|
||||
private String physical_name;
|
||||
private String password;
|
||||
private Object last_login;
|
||||
private Boolean is_superuser;
|
||||
private String username;
|
||||
private String first_name;
|
||||
private String last_name;
|
||||
private String email;
|
||||
private Boolean is_staff;
|
||||
private Boolean is_active;
|
||||
private String date_joined;
|
||||
private Integer sex = 1;
|
||||
private Integer age;
|
||||
private Integer height;
|
||||
private Integer weight;
|
||||
private Integer bmi = new Integer(-1);
|
||||
private String occupation_name = "";
|
||||
private List<?> groups;
|
||||
private List<?> user_permissions;
|
||||
private List<?> illness;
|
||||
|
||||
public MyUser() {
|
||||
height = new Integer(0);
|
||||
occupation_name = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MyUser{" +
|
||||
"id=" + id +
|
||||
", eaten_elements=" + eaten_elements +
|
||||
", physical_name='" + physical_name + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", last_login=" + last_login +
|
||||
", is_superuser=" + is_superuser +
|
||||
", username='" + username + '\'' +
|
||||
", first_name='" + first_name + '\'' +
|
||||
", last_name='" + last_name + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", is_staff=" + is_staff +
|
||||
", is_active=" + is_active +
|
||||
", date_joined='" + date_joined + '\'' +
|
||||
", sex=" + sex +
|
||||
", age=" + age +
|
||||
", height=" + height +
|
||||
", weight=" + weight +
|
||||
", bmi=" + bmi +
|
||||
", occupation_name=" + occupation_name +
|
||||
", groups=" + groups +
|
||||
", user_permissions=" + user_permissions +
|
||||
", illness=" + illness +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
public void changeElement(EatenElementsBean eaten_elements) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public EatenElementsBean getEaten_elements() {
|
||||
return eaten_elements;
|
||||
}
|
||||
|
||||
public void setEaten_elements(EatenElementsBean eaten_elements) {
|
||||
this.eaten_elements = eaten_elements;
|
||||
}
|
||||
|
||||
public String getPhysical_name() {
|
||||
return physical_name;
|
||||
}
|
||||
|
||||
public void setPhysical_name(String physical_name) {
|
||||
this.physical_name = physical_name;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Object getLast_login() {
|
||||
return last_login;
|
||||
}
|
||||
|
||||
public void setLast_login(Object last_login) {
|
||||
this.last_login = last_login;
|
||||
}
|
||||
|
||||
public Boolean getIs_superuser() {
|
||||
return is_superuser;
|
||||
}
|
||||
|
||||
public void setIs_superuser(Boolean is_superuser) {
|
||||
this.is_superuser = is_superuser;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getFirst_name() {
|
||||
return first_name;
|
||||
}
|
||||
|
||||
public void setFirst_name(String first_name) {
|
||||
this.first_name = first_name;
|
||||
}
|
||||
|
||||
public String getLast_name() {
|
||||
return last_name;
|
||||
}
|
||||
|
||||
public void setLast_name(String last_name) {
|
||||
this.last_name = last_name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Boolean getIs_staff() {
|
||||
return is_staff;
|
||||
}
|
||||
|
||||
public void setIs_staff(Boolean is_staff) {
|
||||
this.is_staff = is_staff;
|
||||
}
|
||||
|
||||
public Boolean getIs_active() {
|
||||
return is_active;
|
||||
}
|
||||
|
||||
public void setIs_active(Boolean is_active) {
|
||||
this.is_active = is_active;
|
||||
}
|
||||
|
||||
public String getDate_joined() {
|
||||
return date_joined;
|
||||
}
|
||||
|
||||
public void setDate_joined(String date_joined) {
|
||||
this.date_joined = date_joined;
|
||||
}
|
||||
|
||||
public Integer getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(Integer sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Integer getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(Integer height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Integer getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(Integer weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public Integer getBmi() {
|
||||
return bmi;
|
||||
}
|
||||
|
||||
public void setBmi(Integer bmi) {
|
||||
this.bmi = bmi;
|
||||
}
|
||||
|
||||
public String getOccupation_name() {
|
||||
return occupation_name;
|
||||
}
|
||||
|
||||
public void setOccupation_name(String occupation_name) {
|
||||
this.occupation_name = occupation_name;
|
||||
}
|
||||
|
||||
public List<?> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void setGroups(List<?> groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
public List<?> getUser_permissions() {
|
||||
return user_permissions;
|
||||
}
|
||||
|
||||
public void setUser_permissions(List<?> user_permissions) {
|
||||
this.user_permissions = user_permissions;
|
||||
}
|
||||
|
||||
public List<?> getIllness() {
|
||||
return illness;
|
||||
}
|
||||
|
||||
public void setIllness(List<?> illness) {
|
||||
this.illness = illness;
|
||||
}
|
||||
|
||||
public static class EatenElementsBean {
|
||||
/**
|
||||
* id : 12127
|
||||
* calorie : 1046
|
||||
* carbohydrate : 33.56923076923077
|
||||
* fat : 17.138461538461538
|
||||
* protein : 13.492307692307692
|
||||
* cellulose : 5.723076923076923
|
||||
* vitaminA : 16.307692307692307
|
||||
* vitaminB1 : 0
|
||||
* vitaminB2 : 0.16
|
||||
* vitaminB6 : 0
|
||||
* vitaminC : 9.692307692307692
|
||||
* vitaminE : 7.483076923076923
|
||||
* carotene : 84.61538461538461
|
||||
* cholesterol : 29.692307692307693
|
||||
* Mg : 116.61538461538461
|
||||
* Ca : 230.76923076923077
|
||||
* Fe : 7.523076923076923
|
||||
* Zn : 1.209230769230769
|
||||
* Cu : 0.4138461538461539
|
||||
* Mn : 1.5138461538461538
|
||||
* K : 285.6923076923077
|
||||
* P : 92
|
||||
* Na : 15580.876923076923
|
||||
* Se : 7.636923076923078
|
||||
* niacin : 1.169230769230769
|
||||
* thiamine : 0.06307692307692307
|
||||
*/
|
||||
|
||||
private double id;
|
||||
private double calorie = 1;
|
||||
private double carbohydrate;
|
||||
private double fat;
|
||||
private double protein;
|
||||
private double cellulose;
|
||||
private double vitaminA;
|
||||
private double vitaminB1;
|
||||
private double vitaminB2;
|
||||
private double vitaminB6;
|
||||
private double vitaminC;
|
||||
private double vitaminE;
|
||||
private double carotene;
|
||||
private double cholesterol;
|
||||
private double Mg;
|
||||
private double Ca;
|
||||
private double Fe;
|
||||
private double Zn;
|
||||
private double Cu;
|
||||
private double Mn;
|
||||
private double K;
|
||||
private double P;
|
||||
private double Na;
|
||||
private double Se;
|
||||
private double niacin;
|
||||
private double thiamine;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EatenElementsBean{" +
|
||||
"id=" + id +
|
||||
", 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 double getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public double getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public void setCalorie(int calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public double getCarbohydrate() {
|
||||
return carbohydrate;
|
||||
}
|
||||
|
||||
public void setCarbohydrate(double carbohydrate) {
|
||||
this.carbohydrate = carbohydrate;
|
||||
}
|
||||
|
||||
public double getFat() {
|
||||
return fat;
|
||||
}
|
||||
|
||||
public void setFat(double fat) {
|
||||
this.fat = fat;
|
||||
}
|
||||
|
||||
public double getProtein() {
|
||||
return protein;
|
||||
}
|
||||
|
||||
public void setProtein(double protein) {
|
||||
this.protein = protein;
|
||||
}
|
||||
|
||||
public double getCellulose() {
|
||||
return cellulose;
|
||||
}
|
||||
|
||||
public void setCellulose(double cellulose) {
|
||||
this.cellulose = cellulose;
|
||||
}
|
||||
|
||||
public double getVitaminA() {
|
||||
return vitaminA;
|
||||
}
|
||||
|
||||
public void setVitaminA(double vitaminA) {
|
||||
this.vitaminA = vitaminA;
|
||||
}
|
||||
|
||||
public double getVitaminB1() {
|
||||
return vitaminB1;
|
||||
}
|
||||
|
||||
public void setVitaminB1(int vitaminB1) {
|
||||
this.vitaminB1 = vitaminB1;
|
||||
}
|
||||
|
||||
public double getVitaminB2() {
|
||||
return vitaminB2;
|
||||
}
|
||||
|
||||
public void setVitaminB2(double vitaminB2) {
|
||||
this.vitaminB2 = vitaminB2;
|
||||
}
|
||||
|
||||
public double getVitaminB6() {
|
||||
return vitaminB6;
|
||||
}
|
||||
|
||||
public void setVitaminB6(int vitaminB6) {
|
||||
this.vitaminB6 = vitaminB6;
|
||||
}
|
||||
|
||||
public double getVitaminC() {
|
||||
return vitaminC;
|
||||
}
|
||||
|
||||
public void setVitaminC(double vitaminC) {
|
||||
this.vitaminC = vitaminC;
|
||||
}
|
||||
|
||||
public double getVitaminE() {
|
||||
return vitaminE;
|
||||
}
|
||||
|
||||
public void setVitaminE(double vitaminE) {
|
||||
this.vitaminE = vitaminE;
|
||||
}
|
||||
|
||||
public double getCarotene() {
|
||||
return carotene;
|
||||
}
|
||||
|
||||
public void setCarotene(double carotene) {
|
||||
this.carotene = carotene;
|
||||
}
|
||||
|
||||
public double getCholesterol() {
|
||||
return cholesterol;
|
||||
}
|
||||
|
||||
public void setCholesterol(double cholesterol) {
|
||||
this.cholesterol = cholesterol;
|
||||
}
|
||||
|
||||
public double getMg() {
|
||||
return Mg;
|
||||
}
|
||||
|
||||
public void setMg(double Mg) {
|
||||
this.Mg = Mg;
|
||||
}
|
||||
|
||||
public double getCa() {
|
||||
return Ca;
|
||||
}
|
||||
|
||||
public void setCa(double Ca) {
|
||||
this.Ca = Ca;
|
||||
}
|
||||
|
||||
public double getFe() {
|
||||
return Fe;
|
||||
}
|
||||
|
||||
public void setFe(double Fe) {
|
||||
this.Fe = Fe;
|
||||
}
|
||||
|
||||
public double getZn() {
|
||||
return Zn;
|
||||
}
|
||||
|
||||
public void setZn(double Zn) {
|
||||
this.Zn = Zn;
|
||||
}
|
||||
|
||||
public double getCu() {
|
||||
return Cu;
|
||||
}
|
||||
|
||||
public void setCu(double Cu) {
|
||||
this.Cu = Cu;
|
||||
}
|
||||
|
||||
public double getMn() {
|
||||
return Mn;
|
||||
}
|
||||
|
||||
public void setMn(double Mn) {
|
||||
this.Mn = Mn;
|
||||
}
|
||||
|
||||
public double getK() {
|
||||
return K;
|
||||
}
|
||||
|
||||
public void setK(double K) {
|
||||
this.K = K;
|
||||
}
|
||||
|
||||
public double getP() {
|
||||
return P;
|
||||
}
|
||||
|
||||
public void setP(int P) {
|
||||
this.P = P;
|
||||
}
|
||||
|
||||
public double getNa() {
|
||||
return Na;
|
||||
}
|
||||
|
||||
public void setNa(double Na) {
|
||||
this.Na = Na;
|
||||
}
|
||||
|
||||
public double getSe() {
|
||||
return Se;
|
||||
}
|
||||
|
||||
public void setSe(double Se) {
|
||||
this.Se = Se;
|
||||
}
|
||||
|
||||
public double getNiacin() {
|
||||
return niacin;
|
||||
}
|
||||
|
||||
public void setNiacin(double niacin) {
|
||||
this.niacin = niacin;
|
||||
}
|
||||
|
||||
public double getThiamine() {
|
||||
return thiamine;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Occupation {
|
||||
/**
|
||||
* occupation_name : 电力工程师
|
||||
* menuclassification_set : ["接触电离辐射人员食谱","防癌抗癌食谱","明目食谱","关节炎食谱","壮腰健肾食谱"]
|
||||
* elements : {"id":35,"calorie":1.11,"carbohydrate":0,"fat":0,"protein":0,"cellulose":7,"vitaminA":0,"vitaminB1":0,"vitaminB2":0,"vitaminB6":200,"vitaminC":0,"vitaminE":2,"carotene":500,"cholesterol":0,"Mg":0,"Ca":0,"Fe":0,"Zn":0,"Cu":0,"Mn":0,"K":0,"P":0,"Na":0,"Se":0,"niacin":0,"thiamine":0}
|
||||
* bmi_classification : 2
|
||||
*/
|
||||
|
||||
private String occupation_name;
|
||||
private ElementsBean elements;
|
||||
private int bmi_classification;
|
||||
private List<String> menuclassification_set;
|
||||
|
||||
public String getOccupation_name() {
|
||||
return occupation_name;
|
||||
}
|
||||
|
||||
public void setOccupation_name(String occupation_name) {
|
||||
this.occupation_name = occupation_name;
|
||||
}
|
||||
|
||||
public ElementsBean getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public void setElements(ElementsBean elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public int getBmi_classification() {
|
||||
return bmi_classification;
|
||||
}
|
||||
|
||||
public void setBmi_classification(int bmi_classification) {
|
||||
this.bmi_classification = bmi_classification;
|
||||
}
|
||||
|
||||
public List<String> getMenuclassification_set() {
|
||||
return menuclassification_set;
|
||||
}
|
||||
|
||||
public void setMenuclassification_set(List<String> menuclassification_set) {
|
||||
this.menuclassification_set = menuclassification_set;
|
||||
}
|
||||
|
||||
public static class ElementsBean {
|
||||
/**
|
||||
* id : 35
|
||||
* calorie : 1.11
|
||||
* carbohydrate : 0
|
||||
* fat : 0
|
||||
* protein : 0
|
||||
* cellulose : 7
|
||||
* vitaminA : 0
|
||||
* vitaminB1 : 0
|
||||
* vitaminB2 : 0
|
||||
* vitaminB6 : 200
|
||||
* vitaminC : 0
|
||||
* vitaminE : 2
|
||||
* carotene : 500
|
||||
* cholesterol : 0
|
||||
* Mg : 0
|
||||
* Ca : 0
|
||||
* Fe : 0
|
||||
* Zn : 0
|
||||
* Cu : 0
|
||||
* Mn : 0
|
||||
* K : 0
|
||||
* P : 0
|
||||
* Na : 0
|
||||
* Se : 0
|
||||
* niacin : 0
|
||||
* thiamine : 0
|
||||
*/
|
||||
|
||||
private float id;
|
||||
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;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ElementsBean{" +
|
||||
"id=" + id +
|
||||
", 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 float getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(float id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public double getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public void setCalorie(double calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public float getCarbohydrate() {
|
||||
return carbohydrate;
|
||||
}
|
||||
|
||||
public void setCarbohydrate(float carbohydrate) {
|
||||
this.carbohydrate = carbohydrate;
|
||||
}
|
||||
|
||||
public float getFat() {
|
||||
return fat;
|
||||
}
|
||||
|
||||
public void setFat(float fat) {
|
||||
this.fat = fat;
|
||||
}
|
||||
|
||||
public float getProtein() {
|
||||
return protein;
|
||||
}
|
||||
|
||||
public void setProtein(float protein) {
|
||||
this.protein = protein;
|
||||
}
|
||||
|
||||
public float getCellulose() {
|
||||
return cellulose;
|
||||
}
|
||||
|
||||
public void setCellulose(float cellulose) {
|
||||
this.cellulose = cellulose;
|
||||
}
|
||||
|
||||
public float getVitaminA() {
|
||||
return vitaminA;
|
||||
}
|
||||
|
||||
public void setVitaminA(float vitaminA) {
|
||||
this.vitaminA = vitaminA;
|
||||
}
|
||||
|
||||
public float getVitaminB1() {
|
||||
return vitaminB1;
|
||||
}
|
||||
|
||||
public void setVitaminB1(float vitaminB1) {
|
||||
this.vitaminB1 = vitaminB1;
|
||||
}
|
||||
|
||||
public float getVitaminB2() {
|
||||
return vitaminB2;
|
||||
}
|
||||
|
||||
public void setVitaminB2(float vitaminB2) {
|
||||
this.vitaminB2 = vitaminB2;
|
||||
}
|
||||
|
||||
public float getVitaminB6() {
|
||||
return vitaminB6;
|
||||
}
|
||||
|
||||
public void setVitaminB6(float vitaminB6) {
|
||||
this.vitaminB6 = vitaminB6;
|
||||
}
|
||||
|
||||
public float getVitaminC() {
|
||||
return vitaminC;
|
||||
}
|
||||
|
||||
public void setVitaminC(float vitaminC) {
|
||||
this.vitaminC = vitaminC;
|
||||
}
|
||||
|
||||
public float getVitaminE() {
|
||||
return vitaminE;
|
||||
}
|
||||
|
||||
public void setVitaminE(float vitaminE) {
|
||||
this.vitaminE = vitaminE;
|
||||
}
|
||||
|
||||
public float getCarotene() {
|
||||
return carotene;
|
||||
}
|
||||
|
||||
public void setCarotene(float carotene) {
|
||||
this.carotene = carotene;
|
||||
}
|
||||
|
||||
public float getCholesterol() {
|
||||
return cholesterol;
|
||||
}
|
||||
|
||||
public void setCholesterol(float cholesterol) {
|
||||
this.cholesterol = cholesterol;
|
||||
}
|
||||
|
||||
public float getMg() {
|
||||
return Mg;
|
||||
}
|
||||
|
||||
public void setMg(float Mg) {
|
||||
this.Mg = Mg;
|
||||
}
|
||||
|
||||
public float getCa() {
|
||||
return Ca;
|
||||
}
|
||||
|
||||
public void setCa(float Ca) {
|
||||
this.Ca = Ca;
|
||||
}
|
||||
|
||||
public float getFe() {
|
||||
return Fe;
|
||||
}
|
||||
|
||||
public void setFe(float Fe) {
|
||||
this.Fe = Fe;
|
||||
}
|
||||
|
||||
public float getZn() {
|
||||
return Zn;
|
||||
}
|
||||
|
||||
public void setZn(float Zn) {
|
||||
this.Zn = Zn;
|
||||
}
|
||||
|
||||
public float getCu() {
|
||||
return Cu;
|
||||
}
|
||||
|
||||
public void setCu(float Cu) {
|
||||
this.Cu = Cu;
|
||||
}
|
||||
|
||||
public float getMn() {
|
||||
return Mn;
|
||||
}
|
||||
|
||||
public void setMn(float Mn) {
|
||||
this.Mn = Mn;
|
||||
}
|
||||
|
||||
public float getK() {
|
||||
return K;
|
||||
}
|
||||
|
||||
public void setK(float K) {
|
||||
this.K = K;
|
||||
}
|
||||
|
||||
public float getP() {
|
||||
return P;
|
||||
}
|
||||
|
||||
public void setP(float P) {
|
||||
this.P = P;
|
||||
}
|
||||
|
||||
public float getNa() {
|
||||
return Na;
|
||||
}
|
||||
|
||||
public void setNa(float Na) {
|
||||
this.Na = Na;
|
||||
}
|
||||
|
||||
public float getSe() {
|
||||
return Se;
|
||||
}
|
||||
|
||||
public void setSe(float Se) {
|
||||
this.Se = Se;
|
||||
}
|
||||
|
||||
public float getNiacin() {
|
||||
return niacin;
|
||||
}
|
||||
|
||||
public void setNiacin(float niacin) {
|
||||
this.niacin = niacin;
|
||||
}
|
||||
|
||||
public float getThiamine() {
|
||||
return thiamine;
|
||||
}
|
||||
|
||||
public void setThiamine(float thiamine) {
|
||||
this.thiamine = thiamine;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Occupation{" +
|
||||
"occupation_name='" + occupation_name + '\'' +
|
||||
", elements=" + elements +
|
||||
", bmi_classification=" + bmi_classification +
|
||||
", menuclassification_set=" + menuclassification_set +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Physique {
|
||||
|
||||
/**
|
||||
* physical_name : 气虚质
|
||||
* cure_material : ["人参","人参须","去芯莲子","去芯莲子(3~4人份)","土茯苓","土茯苓(4~5个人量)","山药","山药(干)","山药(或淮山)","山药,薏米,芡实1:1:1","已经去芯的莲子","干莲子","怀山药","扁豆","新鲜人参","新鲜莲子","无心莲子","毛山药","淮山药片","清补凉(淮山、枸杞、莲子、百合、玉竹、薏米、红枣)","炒扁豆","炒白术","焦白术","白扁豆","白术","白茯苓","白莲子","福建建宁莲子(想安神效果莲子可多放)","芡实","芡实米","芡实米(鲜)","花旗参","花旗参(西洋参)","茯苓","茯苓(2人份)","莲子","莲子心","铁杆山药","铁棍山药","鲜莲子 \u2026\u2026","黄芪"]
|
||||
* elements : {"id":81,"calorie":1.2,"carbohydrate":0,"fat":0,"protein":0,"cellulose":0,"vitaminA":500,"vitaminB1":0,"vitaminB2":0,"vitaminB6":1500,"vitaminC":100,"vitaminE":0,"carotene":1500,"cholesterol":0,"Mg":0,"Ca":0,"Fe":0,"Zn":0,"Cu":0,"Mn":0,"K":0,"P":500,"Na":1000,"Se":0,"niacin":0,"thiamine":0}
|
||||
*/
|
||||
|
||||
private String physical_name;
|
||||
private ElementsBean elements;
|
||||
private List<String> cure_material;
|
||||
|
||||
|
||||
public String getPhysical_name() {
|
||||
return physical_name;
|
||||
}
|
||||
|
||||
public void setPhysical_name(String physical_name) {
|
||||
this.physical_name = physical_name;
|
||||
}
|
||||
|
||||
public ElementsBean getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public void setElements(ElementsBean elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public List<String> getCure_material() {
|
||||
return cure_material;
|
||||
}
|
||||
|
||||
public void setCure_material(List<String> cure_material) {
|
||||
this.cure_material = cure_material;
|
||||
}
|
||||
|
||||
|
||||
private String imageUrl;
|
||||
private String expression;
|
||||
private String characteristic;
|
||||
private String mentality;
|
||||
private String matters;
|
||||
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void setImageUrl(String imageUrl) {
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
public void setExpression(String expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
public String getCharacteristic() {
|
||||
return characteristic;
|
||||
}
|
||||
|
||||
public void setCharacteristic(String characteristic) {
|
||||
this.characteristic = characteristic;
|
||||
}
|
||||
|
||||
public String getMentality() {
|
||||
return mentality;
|
||||
}
|
||||
|
||||
public void setMentality(String mentality) {
|
||||
this.mentality = mentality;
|
||||
}
|
||||
|
||||
public String getMatters() {
|
||||
return matters;
|
||||
}
|
||||
|
||||
public void setMatters(String matters) {
|
||||
this.matters = matters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Physique{" +
|
||||
"physical_name='" + physical_name + '\'' +
|
||||
", cure_material=" + cure_material +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class ElementsBean {
|
||||
/**
|
||||
* id : 81
|
||||
* calorie : 1.2
|
||||
* carbohydrate : 0
|
||||
* fat : 0
|
||||
* protein : 0
|
||||
* cellulose : 0
|
||||
* vitaminA : 500
|
||||
* vitaminB1 : 0
|
||||
* vitaminB2 : 0
|
||||
* vitaminB6 : 1500
|
||||
* vitaminC : 100
|
||||
* vitaminE : 0
|
||||
* carotene : 1500
|
||||
* cholesterol : 0
|
||||
* Mg : 0
|
||||
* Ca : 0
|
||||
* Fe : 0
|
||||
* Zn : 0
|
||||
* Cu : 0
|
||||
* Mn : 0
|
||||
* K : 0
|
||||
* P : 500
|
||||
* Na : 1000
|
||||
* Se : 0
|
||||
* niacin : 0
|
||||
* thiamine : 0
|
||||
*/
|
||||
|
||||
private float id;
|
||||
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;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ElementsBean{" +
|
||||
"id=" + id +
|
||||
", 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 float getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(float id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public double getCalorie() {
|
||||
return calorie;
|
||||
}
|
||||
|
||||
public void setCalorie(double calorie) {
|
||||
this.calorie = calorie;
|
||||
}
|
||||
|
||||
public float getCarbohydrate() {
|
||||
return carbohydrate;
|
||||
}
|
||||
|
||||
public void setCarbohydrate(float carbohydrate) {
|
||||
this.carbohydrate = carbohydrate;
|
||||
}
|
||||
|
||||
public float getFat() {
|
||||
return fat;
|
||||
}
|
||||
|
||||
public void setFat(float fat) {
|
||||
this.fat = fat;
|
||||
}
|
||||
|
||||
public float getProtein() {
|
||||
return protein;
|
||||
}
|
||||
|
||||
public void setProtein(float protein) {
|
||||
this.protein = protein;
|
||||
}
|
||||
|
||||
public float getCellulose() {
|
||||
return cellulose;
|
||||
}
|
||||
|
||||
public void setCellulose(float cellulose) {
|
||||
this.cellulose = cellulose;
|
||||
}
|
||||
|
||||
public float getVitaminA() {
|
||||
return vitaminA;
|
||||
}
|
||||
|
||||
public void setVitaminA(float vitaminA) {
|
||||
this.vitaminA = vitaminA;
|
||||
}
|
||||
|
||||
public float getVitaminB1() {
|
||||
return vitaminB1;
|
||||
}
|
||||
|
||||
public void setVitaminB1(float vitaminB1) {
|
||||
this.vitaminB1 = vitaminB1;
|
||||
}
|
||||
|
||||
public float getVitaminB2() {
|
||||
return vitaminB2;
|
||||
}
|
||||
|
||||
public void setVitaminB2(float vitaminB2) {
|
||||
this.vitaminB2 = vitaminB2;
|
||||
}
|
||||
|
||||
public float getVitaminB6() {
|
||||
return vitaminB6;
|
||||
}
|
||||
|
||||
public void setVitaminB6(float vitaminB6) {
|
||||
this.vitaminB6 = vitaminB6;
|
||||
}
|
||||
|
||||
public float getVitaminC() {
|
||||
return vitaminC;
|
||||
}
|
||||
|
||||
public void setVitaminC(float vitaminC) {
|
||||
this.vitaminC = vitaminC;
|
||||
}
|
||||
|
||||
public float getVitaminE() {
|
||||
return vitaminE;
|
||||
}
|
||||
|
||||
public void setVitaminE(float vitaminE) {
|
||||
this.vitaminE = vitaminE;
|
||||
}
|
||||
|
||||
public float getCarotene() {
|
||||
return carotene;
|
||||
}
|
||||
|
||||
public void setCarotene(float carotene) {
|
||||
this.carotene = carotene;
|
||||
}
|
||||
|
||||
public float getCholesterol() {
|
||||
return cholesterol;
|
||||
}
|
||||
|
||||
public void setCholesterol(float cholesterol) {
|
||||
this.cholesterol = cholesterol;
|
||||
}
|
||||
|
||||
public float getMg() {
|
||||
return Mg;
|
||||
}
|
||||
|
||||
public void setMg(float Mg) {
|
||||
this.Mg = Mg;
|
||||
}
|
||||
|
||||
public float getCa() {
|
||||
return Ca;
|
||||
}
|
||||
|
||||
public void setCa(float Ca) {
|
||||
this.Ca = Ca;
|
||||
}
|
||||
|
||||
public float getFe() {
|
||||
return Fe;
|
||||
}
|
||||
|
||||
public void setFe(float Fe) {
|
||||
this.Fe = Fe;
|
||||
}
|
||||
|
||||
public float getZn() {
|
||||
return Zn;
|
||||
}
|
||||
|
||||
public void setZn(float Zn) {
|
||||
this.Zn = Zn;
|
||||
}
|
||||
|
||||
public float getCu() {
|
||||
return Cu;
|
||||
}
|
||||
|
||||
public void setCu(float Cu) {
|
||||
this.Cu = Cu;
|
||||
}
|
||||
|
||||
public float getMn() {
|
||||
return Mn;
|
||||
}
|
||||
|
||||
public void setMn(float Mn) {
|
||||
this.Mn = Mn;
|
||||
}
|
||||
|
||||
public float getK() {
|
||||
return K;
|
||||
}
|
||||
|
||||
public void setK(float K) {
|
||||
this.K = K;
|
||||
}
|
||||
|
||||
public float getP() {
|
||||
return P;
|
||||
}
|
||||
|
||||
public void setP(float P) {
|
||||
this.P = P;
|
||||
}
|
||||
|
||||
public float getNa() {
|
||||
return Na;
|
||||
}
|
||||
|
||||
public void setNa(float Na) {
|
||||
this.Na = Na;
|
||||
}
|
||||
|
||||
public float getSe() {
|
||||
return Se;
|
||||
}
|
||||
|
||||
public void setSe(float Se) {
|
||||
this.Se = Se;
|
||||
}
|
||||
|
||||
public float getNiacin() {
|
||||
return niacin;
|
||||
}
|
||||
|
||||
public void setNiacin(float niacin) {
|
||||
this.niacin = niacin;
|
||||
}
|
||||
|
||||
public float getThiamine() {
|
||||
return thiamine;
|
||||
}
|
||||
|
||||
public void setThiamine(float thiamine) {
|
||||
this.thiamine = thiamine;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import com.chad.library.adapter.base.entity.MultiItemEntity;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/3.
|
||||
*/
|
||||
|
||||
public class RecommendFood implements MultiItemEntity, Serializable {
|
||||
|
||||
//三种view
|
||||
public static final int TYPE_BIG = 0;
|
||||
public static final int TYPE_MIDDLE = 1;
|
||||
public static final int TYPE_DETAIL = 2;
|
||||
|
||||
private String picture;
|
||||
private String title;
|
||||
private String description;
|
||||
private int type;
|
||||
private FoodMenu menu;
|
||||
|
||||
public FoodMenu getMenu() {
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void setMenu(FoodMenu menu) {
|
||||
this.menu = menu;
|
||||
}
|
||||
|
||||
public RecommendFood(FoodMenu foodMenu, int type) {
|
||||
menu = foodMenu;
|
||||
picture = foodMenu.getImage_url();
|
||||
title = foodMenu.getName();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getPicture() {
|
||||
return picture;
|
||||
}
|
||||
|
||||
public void setPicture(String picture) {
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return menu.toString();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/5.
|
||||
*/
|
||||
|
||||
public class ResultList implements Serializable {
|
||||
|
||||
private ArrayList<ClassifyResult> results;
|
||||
|
||||
public ResultList(ArrayList<ClassifyResult> results) {
|
||||
super();
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
public ArrayList<ClassifyResult> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(ArrayList<ClassifyResult> results) {
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于Intent传递
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String log = "";
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
log += results.get(i).getName() + ";卡路里" +results.get(i).getCalorie() + "\n";
|
||||
}
|
||||
return log;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
public class Trick {
|
||||
|
||||
/**
|
||||
* id : 124
|
||||
* title : 一天喝一杯红酒 真能降血脂降固醇吗
|
||||
* content : 随着高血脂、高固醇患者人数不但增长,关于如何对这类疾病进行有效地预防,成了越来越多人关注的问题,坊间关于预防的方式也多种多样,让人眼花缭乱,真假难辨。其中每天坚持喝一杯
|
||||
能降血脂降固醇的说法被很多人奉为圭臬,并在生活中践行。
|
||||
事实果真如此吗?红酒有这么突出的功效吗?下面为大家详细解答一番。
|
||||
首先,可以确定的是,红酒的确是一种健康饮品,它含有丰富的营养物质,
|
||||
功效也不容忽视。红酒中所含的多酚、白藜芦醇、花色苷等营养物质,的确有助于降低体内的胆固醇、血脂;非但如此,这些物质还能起到软化血管的作用;此外,红酒中的有机酸,还能增强我们的消化系统,帮助我们消化食物。再者,红酒中含有的多酚、黄酮等植物化学成分,有助于清除体内自由基,预防衰老。
|
||||
由此可见,饮用红酒的确对我们降脂、降固醇有很大的帮助,但是要想完全通过每天一杯红酒的方式实现预防目的,并不可取,因为红酒虽好,但同样存在下面这些隐患。
|
||||
首先对红酒的选择,市场上各种质量的红酒类型鱼目混杂,如果选择了低劣的红酒,不但不能起到养生作用,反而会危害健康;此外,红酒中含有酒精,一旦饮用过量,对高血脂、高固醇患者的健康也会造成影响;再者,红酒中能降血脂、降固醇的营养物质含量较低,每天仅喝一杯,很难奏效。
|
||||
可见,仅仅通过每天饮用一杯红酒的方式降血脂、降固醇并不是明智之选。那么,还有哪些方式可以帮助我们更好地实现养生目标呢?
|
||||
在日常饮食方面,做到膳食结构完整,营养摄入全面,保证肉质、蔬菜、水果、蛋类等各类食材的均衡摄入;再此基础上,减少食盐、食用油的摄入量,还可以尝试用鸡肉、鱼肉等“白肉”取代猪肉等“红肉”。
|
||||
高血脂、高固醇的出现,和体内过量的脂肪密不可分,每天坚持适量的体育锻炼,将体内多余的热量和脂肪消耗掉,对降低体内的血脂、固醇也大有裨益。
|
||||
养生是一个循序渐进的过程,不能急功近利,更不能偏信,某一种食材具有特殊功效这种说法,只有长期坚持健康的生活方式才能拥有健康的身体。
|
||||
*/
|
||||
|
||||
private int id;
|
||||
private String title;
|
||||
private String content;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.example.ninefourone.nutritionmaster.camera;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Camera;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/3.
|
||||
*/
|
||||
|
||||
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
|
||||
|
||||
private SurfaceHolder mHolder;
|
||||
private Camera camera;
|
||||
|
||||
public CameraPreview(Context context, Camera camera) {
|
||||
super(context);
|
||||
this.camera = camera;
|
||||
mHolder = getHolder();
|
||||
mHolder.addCallback(this);
|
||||
// mHolder.setType();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
try {
|
||||
camera.setPreviewDisplay(holder);
|
||||
camera.startPreview();
|
||||
} catch (IOException e) {
|
||||
Logger.e(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
if (mHolder.getSurface() == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
camera.stopPreview();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
camera.setPreviewDisplay(mHolder);
|
||||
camera.startPreview();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,431 @@
|
||||
package com.example.ninefourone.nutritionmaster.camera;
|
||||
|
||||
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.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;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
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;
|
||||
import com.youdao.sdk.ydonlinetranslate.Translator;
|
||||
import com.youdao.sdk.ydtranslate.Translate;
|
||||
import com.youdao.sdk.ydtranslate.TranslateErrorCode;
|
||||
import com.youdao.sdk.ydtranslate.TranslateListener;
|
||||
import com.youdao.sdk.ydtranslate.TranslateParameters;
|
||||
|
||||
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;
|
||||
import java.net.URLEncoder;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/3.
|
||||
*/
|
||||
|
||||
public class ClassifierCamera extends AppCompatActivity {
|
||||
|
||||
public static int MATERAIL_CODE = 0;
|
||||
public static int DISH_CODE = 1;
|
||||
|
||||
@BindView(R.id.camera_preview)
|
||||
FrameLayout mCameraLayout;
|
||||
@BindView(R.id.results_text_view)
|
||||
TextView resultsTextView;
|
||||
@BindView(R.id.more_take_photo_button_capture)
|
||||
ImageView moreTakePhotoButtonCapture;
|
||||
@BindView(R.id.more_takephoto_ok)
|
||||
ImageView moreTakephotoOk;
|
||||
@BindView(R.id.camera_cover_linearlayout)
|
||||
FrameLayout cameraCoverLinearlayout;
|
||||
|
||||
private Camera mCamera;
|
||||
private CameraPreview mPreview;
|
||||
private int mCameraId = Camera.CameraInfo.CAMERA_FACING_BACK;
|
||||
|
||||
private ArrayList<ClassifyResult> resultList = new ArrayList<>();
|
||||
|
||||
private int code = -1;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Intent intent = getIntent();
|
||||
code = intent.getIntExtra("CODE", -1);
|
||||
//取消toolbar
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
//设置全屏
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
//注意:上面两个设置必须写在setContentView前面
|
||||
setContentView(R.layout.cameras_layout);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
if (!checkCameraHardware(this)) {
|
||||
MessageUtils.MakeToast("不支持相机");
|
||||
} else {
|
||||
openCamera();
|
||||
}
|
||||
|
||||
setCameraDisplayOrientation(this, mCameraId, mCamera);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当前设备是否有相机
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
private boolean checkCameraHardware(Context context) {
|
||||
if (context.getPackageManager().hasSystemFeature(
|
||||
PackageManager.FEATURE_CAMERA)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 打开相机
|
||||
*/
|
||||
private void openCamera() {
|
||||
if (null == mCamera) {
|
||||
mCamera = getCameraInstance();
|
||||
mPreview = new CameraPreview(this, mCamera);
|
||||
mCameraLayout.addView(mPreview);
|
||||
mCamera.startPreview();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相机
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Camera getCameraInstance() {
|
||||
Camera c = null;
|
||||
try {
|
||||
c = Camera.open();
|
||||
|
||||
Camera.Parameters mParameters = c.getParameters();
|
||||
List<Camera.Size> sizes = mParameters.getSupportedPreviewSizes();
|
||||
|
||||
mParameters.setPictureSize(2048, 1536);
|
||||
mParameters.setPreviewSize(2048, 1536);
|
||||
c.setParameters(mParameters);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对焦回调,对焦完成后进行拍照
|
||||
*/
|
||||
private Camera.AutoFocusCallback mAutoFocusCallback = new Camera.AutoFocusCallback() {
|
||||
@Override
|
||||
public void onAutoFocus(boolean success, Camera camera) {
|
||||
if (success) {
|
||||
mCamera.takePicture(null, null, mPictureCallback);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 拍照回调
|
||||
*/
|
||||
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);
|
||||
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;
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String result = null;
|
||||
try {
|
||||
// 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");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// MessageUtils.MakeToast("拍照!");
|
||||
mCamera.startPreview();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 两个按钮的事件
|
||||
*
|
||||
* @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()) {
|
||||
case R.id.more_take_photo_button_capture:
|
||||
mCamera.autoFocus(mAutoFocusCallback);
|
||||
cameraCoverLinearlayout.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case R.id.more_takephoto_ok:
|
||||
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里面
|
||||
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);
|
||||
// }
|
||||
// });
|
||||
intent.putExtra("LIST", materials);
|
||||
startActivity(intent);
|
||||
|
||||
|
||||
}
|
||||
resultList.clear();
|
||||
refreshUI();
|
||||
finish();
|
||||
break;
|
||||
case R.id.results_text_view:
|
||||
resultList.remove(resultList.size() - 1);
|
||||
refreshUI();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//将相机设置成竖屏
|
||||
public static void setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) {
|
||||
|
||||
int degrees = 0;
|
||||
|
||||
//可以获得摄像头信息
|
||||
Camera.CameraInfo info = new Camera.CameraInfo();
|
||||
Camera.getCameraInfo(cameraId, info);
|
||||
|
||||
//获取屏幕旋转方向
|
||||
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
|
||||
|
||||
switch (rotation) {
|
||||
case Surface.ROTATION_0:
|
||||
degrees = 0;
|
||||
break;
|
||||
case Surface.ROTATION_90:
|
||||
degrees = 90;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
degrees = 180;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
degrees = 270;
|
||||
break;
|
||||
}
|
||||
int result;
|
||||
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
||||
result = (info.orientation + degrees) % 360;
|
||||
result = (360 - result) % 360;
|
||||
} else {
|
||||
result = (info.orientation - degrees + 360) % 360;
|
||||
}
|
||||
camera.setDisplayOrientation(result);
|
||||
}
|
||||
|
||||
|
||||
private void refreshUI() {
|
||||
resultsTextView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String text = "";
|
||||
for (int i = 0; i < resultList.size(); i++) {
|
||||
text += resultList.get(i).getName() + " ";
|
||||
}
|
||||
resultsTextView.setText(text);
|
||||
cameraCoverLinearlayout.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* YOUDAO
|
||||
*
|
||||
* @param english
|
||||
*/
|
||||
private void translate(String english) {
|
||||
Language languageFrom = LanguageUtils.getLangByName("英文");
|
||||
Language languageTo = LanguageUtils.getLangByName("中文");
|
||||
|
||||
TranslateParameters tps = new TranslateParameters.Builder()
|
||||
.source("NM")
|
||||
.from(languageFrom).to(languageTo).build();
|
||||
Translator translator = Translator.getInstance(tps);
|
||||
translator.lookup(english, "5c0e8adb488ba180", new TranslateListener() {
|
||||
@Override
|
||||
public void onError(TranslateErrorCode translateErrorCode, String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(Translate translate, String s, String s1) {
|
||||
String result = "";
|
||||
result = translate.getTranslations().get(0);
|
||||
Logger.d(result);
|
||||
ClassifyResult classifyResult = new ClassifyResult(ClassifyResult.MATERIAL);
|
||||
classifyResult.setName(result);
|
||||
resultList.add(classifyResult);
|
||||
refreshUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(List<Translate> list, List<String> list1, List<TranslateErrorCode> list2, String s) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//修改图片保存方向
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.example.ninefourone.nutritionmaster.cardconfig;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.TypedValue;
|
||||
|
||||
/**
|
||||
* 初始化一些配置信息、固定数据
|
||||
*/
|
||||
public class CardConfig {
|
||||
//屏幕上最多同时显示几个Item
|
||||
public static int MAX_SHOW_COUNT;
|
||||
|
||||
//每一级Scale相差0.05f,translationY相差15dp,translationZ相差0.5dp左右
|
||||
public static float SCALE_GAP;
|
||||
public static int TRANS_Y_GAP;
|
||||
public static int TRANS_Z_GAP;
|
||||
|
||||
public static void initConfig(Context context) {
|
||||
MAX_SHOW_COUNT = 4;
|
||||
SCALE_GAP = 0.05f;
|
||||
//这里是把dp转换成px
|
||||
TRANS_Y_GAP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15f, context.getResources().getDisplayMetrics());
|
||||
TRANS_Z_GAP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.5f, context.getResources().getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package com.example.ninefourone.nutritionmaster.cardconfig;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.adapter.CardAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.CardHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/2.
|
||||
*/
|
||||
|
||||
public class CardItemTouchCallBack extends ItemTouchHelper.Callback {
|
||||
|
||||
private static final String TAG = "CardItemTouchCallBack";
|
||||
private RecyclerView mRecyclerView;
|
||||
private CardAdapter mAdapter;
|
||||
private List mDatas;
|
||||
|
||||
public CardItemTouchCallBack(RecyclerView recyclerView, CardAdapter adapter, List datas) {
|
||||
this.mRecyclerView = recyclerView;
|
||||
this.mAdapter = adapter;
|
||||
this.mDatas = datas;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否开启长按拖拽
|
||||
* true,开启
|
||||
* false,不开启长按退拽
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isLongPressDragEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否开启滑动
|
||||
* true,开启
|
||||
* false,不开启长按退拽
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemViewSwipeEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* ItemTouchHelper支持设置事件方向,并且必须重写当前getMovementFlags来指定支持的方向
|
||||
* dragFlags 表示拖拽的方向,有六个类型的值:LEFT、RIGHT、START、END、UP、DOWN
|
||||
* swipeFlags 表示滑动的方向,有六个类型的值:LEFT、RIGHT、START、END、UP、DOWN
|
||||
* 最后要通过makeMovementFlags(dragFlag,swipe)创建方向的Flag
|
||||
*/
|
||||
@Override
|
||||
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
/**
|
||||
* 由于我们不需要长按拖拽,所以直接传入0即可,传入0代表不监听
|
||||
*/
|
||||
int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT | ItemTouchHelper.UP | ItemTouchHelper.DOWN;
|
||||
return makeMovementFlags(0, swipeFlags);
|
||||
}
|
||||
|
||||
/**
|
||||
* 长按item就可以拖动,然后拖动到其他item的时候触发onMove
|
||||
* 这里我们不需要
|
||||
*
|
||||
* @param recyclerView
|
||||
* @param viewHolder 拖动的viewholder
|
||||
* @param target 目标位置的viewholder
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把item滑走(飞出屏幕)的时候调用
|
||||
*
|
||||
* @param viewHolder 滑动的viewholder
|
||||
* @param direction 滑动的方向
|
||||
*/
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
//这里来判断画出的方向,左边是4,右边是8,然后可以做一些数据操作
|
||||
Log.d(TAG, "onSwiped: " + direction);
|
||||
switch (direction) {
|
||||
case 4:
|
||||
Log.d(TAG, "onSwiped: 左边滑出");
|
||||
mAdapter.swipe2left();
|
||||
break;
|
||||
case 8:
|
||||
Log.d(TAG, "onSwiped: 右边滑出");
|
||||
mAdapter.swipe2Right();
|
||||
break;
|
||||
}
|
||||
//移除这条数据
|
||||
Object remove = mDatas.remove(viewHolder.getLayoutPosition());
|
||||
|
||||
/** 这个位置可以用来加载数据,当滑到还剩4个或者多少个时可以在后面加载数据,添加到mDatas中*/
|
||||
//这里就为了方便,直接循环了,把移除的元素再添加到末尾
|
||||
mDatas.add(mDatas.size(), remove);
|
||||
|
||||
//刷新
|
||||
mAdapter.notifyDataSetChanged();
|
||||
//复位
|
||||
viewHolder.itemView.setRotation(0);
|
||||
if (viewHolder instanceof CardHolder) {
|
||||
CardHolder holder = (CardHolder) viewHolder;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 只要拖动、滑动了item,就会触发这个方法,而且是动的过程中会一直触发
|
||||
* 所以动画效果就是在这个方法中来实现的
|
||||
*
|
||||
* @param c
|
||||
* @param recyclerView
|
||||
* @param viewHolder
|
||||
* @param dX
|
||||
* @param dY
|
||||
* @param actionState
|
||||
* @param isCurrentlyActive
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
|
||||
float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
double swipeValue = Math.sqrt(dX * dX + dY * dY); //滑动离中心的距离
|
||||
double fraction = swipeValue / (mRecyclerView.getWidth() * 0.5f);
|
||||
//边界修正 最大为1
|
||||
if (fraction > 1) {
|
||||
fraction = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整每个子view的缩放、位移之类的
|
||||
*/
|
||||
int childCount = recyclerView.getChildCount(); //拿到子view的数量
|
||||
isUpOrDown(mRecyclerView.getChildAt(childCount - 1));
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
/** 拿到子view 注意这里,先绘制的i=0,所以最下面一层view的i=0,最上面的i=3*/
|
||||
View childView = recyclerView.getChildAt(i);
|
||||
int level = childCount - i - 1; //转换一下,level代表层数,最上面是第0层
|
||||
if (level > 0) {
|
||||
//下面层,每一层的水平方向都要增大
|
||||
childView.setScaleX((float) (1 - CardConfig.SCALE_GAP * level + fraction * CardConfig.SCALE_GAP));
|
||||
if (level < CardConfig.MAX_SHOW_COUNT - 1) {
|
||||
//1 2层
|
||||
childView.setScaleY((float) (1 - CardConfig.SCALE_GAP * level + fraction * CardConfig.SCALE_GAP));
|
||||
childView.setTranslationY((float) (CardConfig.TRANS_Y_GAP * level - fraction * CardConfig.TRANS_Y_GAP));
|
||||
childView.setTranslationZ((float) (CardConfig.TRANS_Z_GAP * (CardConfig.MAX_SHOW_COUNT - 1 - level)
|
||||
+ fraction * CardConfig.TRANS_Z_GAP));
|
||||
} else {
|
||||
//最下面一层,3层,这层不用变,所以这里不用写
|
||||
}
|
||||
} else {
|
||||
//第0层
|
||||
//拿到水平方向的偏移比率
|
||||
float xFraction = dX / (mRecyclerView.getWidth() * 0.5f);
|
||||
//边界修正,有正有负,因为旋转有两个方向
|
||||
if (xFraction > 1) {
|
||||
xFraction = 1;
|
||||
} else if (xFraction < -1) {
|
||||
xFraction = -1;
|
||||
}
|
||||
//第一层左右滑动的时候稍微有点旋转
|
||||
childView.setRotation(xFraction * 15); //这里最多旋转15度
|
||||
|
||||
if (viewHolder instanceof CardHolder) {
|
||||
CardHolder holder = (CardHolder) viewHolder;
|
||||
if (dX > 0) {
|
||||
//右滑,显示爱心
|
||||
// holder.iv_love.setAlpha(xFraction);
|
||||
} else if (dX < 0) {
|
||||
//左滑,显示叉,注意这里xFraction为负数,所以要取反
|
||||
// holder.iv_del.setAlpha(-xFraction);
|
||||
} else {
|
||||
// holder.iv_love.setAlpha(0f);
|
||||
// holder.iv_del.setAlpha(0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) {
|
||||
// Log.i(TAG, "getSwipeThreshold: ");
|
||||
// if (isUpOrDown(viewHolder.itemView)) { //如果是向上或者向下滑动
|
||||
// return Float.MAX_VALUE; //就返回阈值为很大
|
||||
// }
|
||||
return super.getSwipeThreshold(viewHolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得逃脱(swipe)速度
|
||||
*
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public float getSwipeEscapeVelocity(float defaultValue) {
|
||||
// Log.d(TAG, "getSwipeEscapeVelocity: " + defaultValue);
|
||||
// View topView = mRecyclerView.getChildAt(mRecyclerView.getChildCount() - 1);
|
||||
// if (isUpOrDown(topView)) { //如果是向上或者向下滑动
|
||||
// return Float.MAX_VALUE; //就返回阈值为很大
|
||||
// }
|
||||
return super.getSwipeEscapeVelocity(defaultValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得swipe的速度阈值
|
||||
*
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public float getSwipeVelocityThreshold(float defaultValue) {
|
||||
Log.d(TAG, "getSwipeVelocityThreshold: " + defaultValue);
|
||||
View topView = mRecyclerView.getChildAt(mRecyclerView.getChildCount() - 1);
|
||||
if (isUpOrDown(topView)) { //如果是向上或者向下滑动
|
||||
return Float.MAX_VALUE; //就返回阈值为很大
|
||||
}
|
||||
return super.getSwipeVelocityThreshold(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是向上滑或者向下滑
|
||||
*/
|
||||
private boolean isUpOrDown(View topView) {
|
||||
float x = topView.getX();
|
||||
float y = topView.getY();
|
||||
int left = topView.getLeft();
|
||||
int top = topView.getTop();
|
||||
if (Math.pow(x - left, 2) > Math.pow(y - top, 2)) {
|
||||
//水平方向大于垂直方向
|
||||
// Log.i(TAG, "isUpOrDown: 不是");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
// Log.i(TAG, "isUpOrDown: 是");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.example.ninefourone.nutritionmaster.cardconfig;
|
||||
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/2.
|
||||
*/
|
||||
|
||||
public class SwipeCardLayoutManager extends RecyclerView.LayoutManager {
|
||||
@Override
|
||||
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
|
||||
return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在这里面给子view布局,也就是item
|
||||
*
|
||||
* @param recycler
|
||||
* @param state
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
//在布局之前,将所有的子View先Detach掉,放入到Scrap缓存中
|
||||
detachAndScrapAttachedViews(recycler);
|
||||
|
||||
//拿到总item数量
|
||||
int itemCount = getItemCount();
|
||||
if (itemCount < 1) {//没有item当然就没必要布局了
|
||||
return;
|
||||
}
|
||||
int bottomPosition; //用来记录最底层view的postion
|
||||
|
||||
if (itemCount < CardConfig.MAX_SHOW_COUNT) { //如果不足最大数量(4个)
|
||||
//那么最底层就是最后一条数据对应的position
|
||||
bottomPosition = itemCount - 1;
|
||||
} else {
|
||||
//否则最底层就是第MAX_SHOW_COUNT(4)条数据对应的position
|
||||
bottomPosition = CardConfig.MAX_SHOW_COUNT - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 这里开始布局且绘制子view
|
||||
* 注意:这里要先从最底层开始绘制,因为后绘制的才能覆盖先绘制的,
|
||||
* 滑动的时候是滑最上面一层的,也就是后绘制的
|
||||
* position也是层数
|
||||
*/
|
||||
for (int position = bottomPosition; position >= 0; position--) {
|
||||
//根据position找recycler要itemview
|
||||
View view = recycler.getViewForPosition(position);
|
||||
//将子View添加至RecyclerView中
|
||||
addView(view);
|
||||
//测量子view并且把Margin也作为子控件的一部分
|
||||
measureChildWithMargins(view, 0, 0);
|
||||
//宽度空隙 getWidth()得到Recycler控件的宽度,getDecoratedMeasuredWidth(view)拿到子view的宽度
|
||||
int widthSpace = getWidth() - getDecoratedMeasuredWidth(view);
|
||||
//高度空隙
|
||||
int heightSpace = getHeight() - getDecoratedMeasuredHeight(view);
|
||||
//给子view布局,这里居中了
|
||||
layoutDecoratedWithMargins(view, widthSpace / 2, 0,
|
||||
widthSpace / 2 + getDecoratedMeasuredWidth(view),
|
||||
getDecoratedMeasuredHeight(view) + 0);
|
||||
|
||||
/**
|
||||
* 下面要调整每一层itemview的的大小及Y轴和Z轴的偏移
|
||||
* 最上面一层(第0层)的Scale为1,translationY为0
|
||||
* 依次往下,每层比上面一层:
|
||||
* (1)Scale相差0.05f
|
||||
* (2)translationY相差7dp
|
||||
* (3)translationZ相差1dp
|
||||
*
|
||||
* 注意:最后一层,除了水平方向的大小其他都与上一层一样,所以要特殊判断
|
||||
*/
|
||||
if (position > 0) { //大于0就是不是最上面那层
|
||||
//依次往下,每层都要水平方向缩小
|
||||
view.setScaleX(1 - CardConfig.SCALE_GAP * position);
|
||||
if (position < CardConfig.MAX_SHOW_COUNT - 1) {
|
||||
//如果,不是最后一层,就都要调整
|
||||
view.setScaleY(1 - CardConfig.SCALE_GAP * position); //垂直方向缩小
|
||||
view.setTranslationY(CardConfig.TRANS_Y_GAP * position); //向下平移
|
||||
view.setTranslationZ(CardConfig.TRANS_Z_GAP * (CardConfig.MAX_SHOW_COUNT - 1 - position)); //Z轴方向的平移
|
||||
} else {
|
||||
//否则,就是最后一层,与上一层保持一致
|
||||
view.setScaleY(1 - CardConfig.SCALE_GAP * (position - 1)); //垂直方向缩小
|
||||
view.setTranslationY(CardConfig.TRANS_Y_GAP * (position - 1)); //向下平移
|
||||
view.setTranslationZ(CardConfig.TRANS_Z_GAP * (CardConfig.MAX_SHOW_COUNT - 1 - (position - 1))); //Z轴方向的平移
|
||||
}
|
||||
} else {
|
||||
//否则,是第0层(最上面那层),只需调整Z轴高度
|
||||
view.setTranslationZ(CardConfig.TRANS_Z_GAP * (CardConfig.MAX_SHOW_COUNT - 1)); //Z轴方向的平移
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,700 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.ToxicBakery.viewpager.transforms.CubeOutTransformer;
|
||||
import com.akexorcist.roundcornerprogressbar.RoundCornerProgressBar;
|
||||
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
|
||||
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
|
||||
import com.bigkoo.pickerview.view.OptionsPickerView;
|
||||
import com.cb.ratingbar.CBRatingBar;
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
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;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.PermissionUtils;
|
||||
import com.flyco.tablayout.SlidingTabLayout;
|
||||
import com.github.mikephil.charting.charts.RadarChart;
|
||||
import com.github.mikephil.charting.components.Description;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.data.RadarData;
|
||||
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;
|
||||
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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
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 {
|
||||
|
||||
@BindView(R.id.drawerlayout)
|
||||
FlowingDrawer mDrawer;
|
||||
@BindView(R.id.navigation_layout)
|
||||
LinearLayout navigationLayout;
|
||||
@BindView(R.id.view_pager)
|
||||
NoScrollViewPager viewPager;
|
||||
@BindView(R.id.sliding_tab_layout)
|
||||
SlidingTabLayout slidingTabLayout;
|
||||
@BindView(R.id.score_bar)
|
||||
CBRatingBar scoreBar;
|
||||
@BindView(R.id.toolbar_user_avatar)
|
||||
CircularImageView toolbarUserAvatar;
|
||||
@BindView(R.id.drawer_user_avatar)
|
||||
CircularImageView drawerUserAvatar;
|
||||
|
||||
@BindView(R.id.search_view)
|
||||
MaterialSearchView searchView;
|
||||
@BindView(R.id.tool_bar)
|
||||
Toolbar toolBar;
|
||||
@BindView(R.id.boom_menu_button)
|
||||
BoomMenuButton boomMenuButton;
|
||||
@BindView(R.id.spider_view)
|
||||
RadarChart spiderView;
|
||||
@BindView(R.id.add_information_button)
|
||||
ImageView addInformationButton;
|
||||
@BindView(R.id.information_layout)
|
||||
LinearLayout informationLayout;
|
||||
@BindView(R.id.title_layout)
|
||||
AppBarLayout titleLayout;
|
||||
@BindView(R.id.user_nick_name)
|
||||
TextView userNickName;
|
||||
@BindView(R.id.user_occupation_text)
|
||||
TextView userOccupationText;
|
||||
@BindView(R.id.container)
|
||||
RelativeLayout container;
|
||||
@BindView(R.id.adder_infor)
|
||||
TextView adderInfor;
|
||||
@BindView(R.id.add_infor_ll)
|
||||
LinearLayout addInforLl;
|
||||
@BindView(R.id.show_information)
|
||||
LinearLayout showInformation;
|
||||
@BindView(R.id.bmi_bar)
|
||||
RoundCornerProgressBar bmiBar;
|
||||
@BindView(R.id.height_bar)
|
||||
RoundCornerProgressBar heightBar;
|
||||
@BindView(R.id.weight_bar)
|
||||
RoundCornerProgressBar weightBar;
|
||||
@BindView(R.id.tool_bar_nickname)
|
||||
TextView toolBarNickname;
|
||||
@BindView(R.id.ill_recycler_view)
|
||||
RecyclerView illRecyclerView;
|
||||
@BindView(R.id.ill_button)
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
mDrawer.setTouchMode(ElasticDrawer.TOUCH_MODE_BEZEL);
|
||||
mDrawer.setOnDrawerStateChangeListener(new ElasticDrawer.OnDrawerStateChangeListener() {
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
@SuppressLint("ResourceAsColor")
|
||||
@Override
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerSlide(float openRatio, int offsetPixels) {
|
||||
// Logger.i("openRatio=" + openRatio + " ,offsetPixels=" + offsetPixels);
|
||||
}
|
||||
});
|
||||
|
||||
initViewPager();
|
||||
initSearchView();
|
||||
initBMB();
|
||||
initIllnessRecycler();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化ViewPager
|
||||
*/
|
||||
private void initViewPager() {
|
||||
homePagerAdapter = new HomePagerAdapter(getSupportFragmentManager(),
|
||||
this);
|
||||
viewPager.setOffscreenPageLimit(3);
|
||||
viewPager.setAdapter(homePagerAdapter);
|
||||
//CubeInTransformer 内旋
|
||||
//FlipHorizontalTransformer 像翻书一样
|
||||
//AccordionTransformer 风琴 拉压
|
||||
viewPager.setPageTransformer(true, new CubeOutTransformer());
|
||||
slidingTabLayout.setViewPager(viewPager);
|
||||
viewPager.setCurrentItem(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
toolBarNickname.setText("NutritionMaster");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
// TODO: add setContentView(...) invocation
|
||||
ButterKnife.bind(this);
|
||||
// Logger.d("oncreate");
|
||||
setSupportActionBar(toolBar);
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
askPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Logger.d("oncreateMenu");
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
MenuItem item = menu.findItem(R.id.id_action_search);
|
||||
searchView.setMenuItem(item);
|
||||
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");
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
|
||||
//mDrawer.openMenu();
|
||||
|
||||
|
||||
/**
|
||||
* 初始化蛛网图
|
||||
*/
|
||||
private void initSpiderView() {
|
||||
|
||||
String[] flags = {"糖分", "淡水", "蛋白质", "维生素", "矿物质"};
|
||||
|
||||
List<RadarEntry> radarEntries = new ArrayList<>();
|
||||
for (int i = 0; i < flags.length; i++) {
|
||||
RadarEntry radarEntry = new RadarEntry(scores[i], flags[i]);
|
||||
radarEntries.add(radarEntry);
|
||||
}
|
||||
|
||||
Description description = new Description();
|
||||
description.setText("");
|
||||
spiderView.setDescription(description);
|
||||
|
||||
|
||||
spiderView.setWebLineWidth(1.5f);
|
||||
// 内部线条宽度,外面的环状线条
|
||||
spiderView.setWebLineWidthInner(1.5f);
|
||||
// 所有线条WebLine透明度
|
||||
spiderView.setWebAlpha(300);
|
||||
|
||||
|
||||
Legend legend = spiderView.getLegend();
|
||||
legend.setEnabled(false);
|
||||
|
||||
XAxis xAxis = spiderView.getXAxis();
|
||||
// X坐标值字体样式
|
||||
// xAxis.setTypeface(tf);
|
||||
// X坐标值字体大小
|
||||
xAxis.setTextSize(8f);
|
||||
ArrayList<String> xVals = new ArrayList<String>();
|
||||
for (String flag : flags) {
|
||||
xVals.add(flag);
|
||||
}
|
||||
xAxis.setValueFormatter(new IndexAxisValueFormatter(xVals));
|
||||
|
||||
|
||||
YAxis yAxis = spiderView.getYAxis();
|
||||
// Y坐标值字体样式
|
||||
// yAxis.setTypeface(tf);
|
||||
// Y坐标值字体大小
|
||||
yAxis.setTextSize(0f);
|
||||
// Y坐标值是否从0开始
|
||||
yAxis.setStartAtZero(true);
|
||||
// 是否显示y值在图表上
|
||||
yAxis.setDrawLabels(false);
|
||||
yAxis.setAxisLineWidth(2f);
|
||||
RadarDataSet set = new RadarDataSet(radarEntries, "体质情况");
|
||||
// set.setColor(R.color.bar_open);
|
||||
set.setLineWidth(0.5f);
|
||||
set.setDrawFilled(true);
|
||||
// set.setFillColor(R.color.spider_view_color);
|
||||
// set.resetColors();
|
||||
RadarData data = new RadarData(set);
|
||||
data.setDrawValues(false);
|
||||
spiderView.setData(data);
|
||||
spiderView.setTouchEnabled(false);
|
||||
spiderView.invalidate();
|
||||
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
private void initSearchView() {
|
||||
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
// MessageUtils.MakeToast(newText);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
|
||||
@Override
|
||||
public void onSearchViewShown() {
|
||||
// MessageUtils.MakeToast("Shown");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchViewClosed() {
|
||||
// MessageUtils.MakeToast("closed");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化悬浮按钮
|
||||
*/
|
||||
private void initBMB() {
|
||||
HamButton.Builder builder = new HamButton.Builder()
|
||||
.normalImageRes(R.drawable.food_material)
|
||||
.normalTextRes(R.string.food_meterial_title)
|
||||
.listener(new OnBMClickListener() {
|
||||
@Override
|
||||
public void onBoomButtonClick(int index) {
|
||||
Intent cameraIntent = new Intent(MainActivity.this,
|
||||
ClassifierCamera.class);
|
||||
cameraIntent.putExtra("CODE", ClassifierCamera.MATERAIL_CODE);
|
||||
startActivity(cameraIntent);
|
||||
}
|
||||
});
|
||||
boomMenuButton.addBuilder(builder);
|
||||
HamButton.Builder builder2 = new HamButton.Builder()
|
||||
.normalImageRes(R.drawable.foods)
|
||||
.normalTextRes(R.string.food_title)
|
||||
.listener(new OnBMClickListener() {
|
||||
@Override
|
||||
public void onBoomButtonClick(int index) {
|
||||
Intent cameraIntent = new Intent(MainActivity.this,
|
||||
ClassifierCamera.class);
|
||||
cameraIntent.putExtra("CODE", ClassifierCamera.DISH_CODE);
|
||||
startActivity(cameraIntent);
|
||||
}
|
||||
});
|
||||
boomMenuButton.addBuilder(builder2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化个人信息界面(UI)
|
||||
*/
|
||||
private void initInforView() {
|
||||
|
||||
adderInfor.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
changeInformation.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
if (NutritionMaster.user.getHeight() != 0) {
|
||||
showInformation.setVisibility(View.VISIBLE);
|
||||
adderInfor.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
showInformation.setVisibility(View.INVISIBLE);
|
||||
adderInfor.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求权限
|
||||
*/
|
||||
private void askPermission() {
|
||||
PermissionUtils.requestCameraPermission(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||
@NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
MessageUtils.MakeToast("权限赋予成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 点击事件
|
||||
*
|
||||
* @param view
|
||||
*/
|
||||
|
||||
@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})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.navigation_layout:
|
||||
mDrawer.openMenu();
|
||||
break;
|
||||
case R.id.add_information_button:
|
||||
Intent intent = new Intent(MainActivity.this, AddPhysiqueActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.information_layout:
|
||||
Intent informationIntent = new Intent(MainActivity.this, InformationActivity.class);
|
||||
startActivity(informationIntent);
|
||||
break;
|
||||
case R.id.adder_infor:
|
||||
Intent i = new Intent(MainActivity.this, AddInformationActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.change_information:
|
||||
Intent i2 = new Intent(MainActivity.this, AddInformationActivity.class);
|
||||
startActivity(i2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
@Override
|
||||
protected void backChangeData() {
|
||||
super.backChangeData();
|
||||
initInforView();
|
||||
if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
|
||||
} else {
|
||||
userOccupationText.setText("职业: " + NutritionMaster.user.getOccupation_name());
|
||||
}
|
||||
initInformationBar();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化个人信息的条状bar还有状态星级的UI
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
private void initInformationBar() {
|
||||
|
||||
scoreBar.setCanTouch(false);
|
||||
if (NutritionMaster.user.getHeight() != 0 && NutritionMaster.user.getAge() != 0) {
|
||||
|
||||
float maxBmi = 40.0f;
|
||||
float maxHeight = 250.0f;
|
||||
float maxWeight = 130.0f;
|
||||
|
||||
float height = NutritionMaster.user.getHeight();
|
||||
float weight = NutritionMaster.user.getWeight();
|
||||
float age = NutritionMaster.user.getAge();
|
||||
float averageWeight = 0;
|
||||
float averageHeight = 0;
|
||||
float averageBmi = 0;
|
||||
int index = (int) (age >= 20 ? ((age - 20) / 5 + 17) : (age - 3));
|
||||
if (NutritionMaster.user.getSex() == 0) {
|
||||
//女性
|
||||
averageWeight = ConstantUtils.averageGirlWeight.get(index);
|
||||
averageHeight = ConstantUtils.averageGirlHeight.get(index);
|
||||
averageBmi = CalculateUtils.BMI(averageHeight, averageWeight);
|
||||
} else if (NutritionMaster.user.getSex() == 1) {
|
||||
averageWeight = ConstantUtils.averageBoyWeight.get(index);
|
||||
averageHeight = ConstantUtils.averageBoyHeight.get(index);
|
||||
averageBmi = CalculateUtils.BMI(averageHeight, averageWeight);
|
||||
} else {
|
||||
Logger.e("非男非女?");
|
||||
return;
|
||||
}
|
||||
float bmi = CalculateUtils.BMI(height, weight);
|
||||
|
||||
float bmiAverage = averageBmi / maxBmi * 100.0f;
|
||||
float bmiSelf = bmi / maxBmi * 100.0f;
|
||||
|
||||
if (bmiAverage > bmiSelf) {
|
||||
bmiBar.setMax(100);
|
||||
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);
|
||||
heightBar.setProgressColor(getColor(R.color.color_bar_deeper));
|
||||
heightBar.setSecondaryProgressColor(getColor(R.color.color_bar_self));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
weightBar.setProgressColor(getColor(R.color.color_bar_deeper));
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换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
|
||||
*/
|
||||
private void initIllnessRecycler() {
|
||||
illAdapter = new IllAdapter(userIllness, MainActivity.this);
|
||||
illRecyclerView.setLayoutManager(new GridLayoutManager(MainActivity.this, 2));
|
||||
illRecyclerView.setAdapter(illAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 疾病list点击事件
|
||||
*/
|
||||
@OnClick(R.id.ill_button)
|
||||
public void onViewClicked() {
|
||||
|
||||
}
|
||||
|
||||
@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 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() {
|
||||
if (!userIllness.contains(illname)) {
|
||||
userIllness.add(illname);
|
||||
}
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.RecipeActivity;
|
||||
|
||||
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.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 {
|
||||
|
||||
|
||||
@BindView(R.id.protein_circle)
|
||||
ArcProgress proteinCircle;
|
||||
@BindView(R.id.fat_circle)
|
||||
ArcProgress fatCircle;
|
||||
@BindView(R.id.carbohydrate_circle)
|
||||
ArcProgress carbohydrateCircle;
|
||||
@BindView(R.id.material_recycler_view)
|
||||
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 MaterialAdapter materialAdapter;
|
||||
private MakeStepAdapter makeStepAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
public void initToolBar() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
private void initList() {
|
||||
materialAdapter = new MaterialAdapter(recommendFood.getMenu().getCook_quantity(), RecipeActivity.this);
|
||||
materialRecyclerView.setAdapter(materialAdapter);
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.addinformation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
|
||||
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
|
||||
import com.bigkoo.pickerview.view.OptionsPickerView;
|
||||
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;
|
||||
private TextView heightTextView;
|
||||
private TextView weightTextView;
|
||||
private TextView sexTextView;
|
||||
private TextView occupationTextView;
|
||||
|
||||
private ImageView ageImageView;
|
||||
private ImageView sexImageView;
|
||||
private ImageView heightImageView;
|
||||
private ImageView weightImageView;
|
||||
private ImageView occupationImageView;
|
||||
|
||||
private Button okButton;
|
||||
|
||||
private OptionsPickerView agePicker;
|
||||
private OptionsPickerView weightPicker;
|
||||
private OptionsPickerView heightPicker;
|
||||
private OptionsPickerView sexPicker;
|
||||
private OptionsPickerView occupationPicker;
|
||||
|
||||
private Context context;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.add_information_activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
|
||||
context = this;
|
||||
ageImageView = findViewById(R.id.age_image_view);
|
||||
sexImageView = findViewById(R.id.sex_image_view);
|
||||
heightImageView = findViewById(R.id.height_image_view);
|
||||
weightImageView = findViewById(R.id.weight_image_view);
|
||||
occupationImageView = findViewById(R.id.occupation_image_view);
|
||||
|
||||
|
||||
ageTextView = findViewById(R.id.age_text_view);
|
||||
sexTextView = findViewById(R.id.sex_text_view);
|
||||
weightTextView = findViewById(R.id.weight_text_view);
|
||||
heightTextView = findViewById(R.id.height_text_view);
|
||||
occupationTextView = findViewById(R.id.occupation_text_view);
|
||||
|
||||
okButton = findViewById(R.id.ok_button);
|
||||
|
||||
occupationPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
|
||||
@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);
|
||||
|
||||
agePicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
ageTextView.setText(ConstantUtils.ageList.get(options1));
|
||||
}
|
||||
}).build();
|
||||
agePicker.setPicker(ConstantUtils.ageList);
|
||||
agePicker.setSelectOptions(25);
|
||||
|
||||
|
||||
sexPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
sexTextView.setText(ConstantUtils.sexList.get(options1));
|
||||
}
|
||||
}).build();
|
||||
sexPicker.setPicker(ConstantUtils.sexList);
|
||||
|
||||
|
||||
heightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
heightTextView.setText(ConstantUtils.heightList.get(options1));
|
||||
}
|
||||
}).build();
|
||||
heightPicker.setPicker(ConstantUtils.heightList);
|
||||
heightPicker.setSelectOptions(119);
|
||||
|
||||
weightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
weightTextView.setText(ConstantUtils.weightList.get(options1));
|
||||
}
|
||||
}).build();
|
||||
weightPicker.setPicker(ConstantUtils.weightList);
|
||||
weightPicker.setSelectOptions(59);
|
||||
|
||||
|
||||
occupationImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
occupationPicker.show();
|
||||
}
|
||||
});
|
||||
|
||||
ageImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
agePicker.show();
|
||||
}
|
||||
});
|
||||
sexImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sexPicker.show();
|
||||
}
|
||||
});
|
||||
heightImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
heightPicker.show();
|
||||
}
|
||||
});
|
||||
weightImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
weightPicker.show();
|
||||
}
|
||||
});
|
||||
|
||||
okButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (ageTextView.getText().toString().equals("年龄") || weightTextView.getText().toString().equals("体重")
|
||||
|| sexTextView.getText().toString().equals("性别") || heightTextView.getText().toString().equals("身高") ||
|
||||
occupationTextView.getText().toString().equals("职业")) {
|
||||
MessageUtils.MakeToast("请点击图片填写所有信息");
|
||||
} else {
|
||||
user.setHeight(Integer.valueOf(heightTextView.getText().toString().split("c")[0]));
|
||||
user.setWeight(Integer.valueOf(weightTextView.getText().toString().split("k")[0]));
|
||||
user.setAge(Integer.valueOf(ageTextView.getText().toString().split("岁")[0]));
|
||||
user.setSex(CalculateUtils.sex2int(sexTextView.getText().toString()));
|
||||
user.setOccupation_name(occupationTextView.getText().toString());
|
||||
float BMI = CalculateUtils.BMI(user.getHeight().floatValue(), user.getWeight().floatValue());
|
||||
user.setBmi(Integer.valueOf((int) BMI));
|
||||
upUser();
|
||||
MessageUtils.MakeToast("信息填写成功");
|
||||
if (NutritionMaster.physique == null) {
|
||||
NutritionMaster.element =
|
||||
CalculateUtils.getElementsByOccupation(NutritionMaster.user, NutritionMaster.occupation);
|
||||
} else {
|
||||
NutritionMaster.element =
|
||||
CalculateUtils.getElementsByOccupationAndPhysique(NutritionMaster.user,
|
||||
NutritionMaster.occupation, NutritionMaster.physique);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,463 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.addinformation;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
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.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 {
|
||||
|
||||
|
||||
@BindView(R.id.card_list)
|
||||
TurnCardListView cardList;
|
||||
@BindView(R.id.back_button)
|
||||
ImageView backButton;
|
||||
@BindView(R.id.result_layout)
|
||||
CardView resultLayout;
|
||||
@BindView(R.id.bottom_content)
|
||||
RelativeLayout bottomContent;
|
||||
@BindView(R.id.physique_image)
|
||||
CircularImageView physiqueImage;
|
||||
@BindView(R.id.physique_name_text_view)
|
||||
TextView physiqueNameTextView;
|
||||
@BindView(R.id.expression_text_view)
|
||||
TextView expressionTextView;
|
||||
@BindView(R.id.characteristic_text_view)
|
||||
TextView characteristicTextView;
|
||||
@BindView(R.id.mentality_text_view)
|
||||
TextView mentalityTextView;
|
||||
@BindView(R.id.matters_text_view)
|
||||
TextView mattersTextView;
|
||||
|
||||
|
||||
private String result = "";
|
||||
private String physique = "平和质";
|
||||
private float[] counter = {0, 0, 0, 0, 0, 0, 0, 0, -1};
|
||||
private String[] physiques = {"淤血质", "阴虚质", "阳虚质", "痰湿质", "湿热质", "气郁质", "气虚质", "平和质"};
|
||||
|
||||
// private int[] colors = {0xff3F51B5, 0xff673AB7, 0xff006064, 0xffC51162, 0xffFFEB3B, 0xff795548, 0xff9E9E9E};
|
||||
private int[] colors = {0xffdef6f9, 0xffd6eeec, 0xffB2EBF2, 0xffB2DFDB, 0xff8ed0ca, 0xff80CBC4, 0xff4DB6AC, 0xff3c948b};
|
||||
private Button[] firstButtons = new Button[ConstantUtils.questionList.length];
|
||||
private Button[] secondButtons = new Button[ConstantUtils.questionList.length];
|
||||
private Button[] thirdButtons = new Button[ConstantUtils.questionList.length];
|
||||
private TextView[] titleViews = new TextView[ConstantUtils.questionList.length];
|
||||
|
||||
private Button[][] buttonList;
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_add;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
// setContentView();
|
||||
ButterKnife.bind(this);
|
||||
buttonList = new Button[][]{
|
||||
firstButtons,
|
||||
secondButtons,
|
||||
thirdButtons
|
||||
};
|
||||
initAddView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
|
||||
}
|
||||
|
||||
private void initAddView() {
|
||||
BaseAdapter adapter = new BaseAdapter() {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return colors.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View child, ViewGroup parent) {
|
||||
|
||||
|
||||
child = LayoutInflater.from(parent.getContext()).inflate(R.layout.add_item, parent,
|
||||
false);
|
||||
child.findViewById(R.id.image).setBackgroundColor(colors[position]);
|
||||
titleViews[position] = child.findViewById(R.id.title_view);
|
||||
titleViews[position].setText(ConstantUtils.questionList[position]);
|
||||
|
||||
firstButtons[position] = child.findViewById(R.id.choose_first);
|
||||
firstButtons[position].setBackgroundColor(colors[position] + 30);
|
||||
|
||||
|
||||
secondButtons[position] = child.findViewById(R.id.choose_second);
|
||||
secondButtons[position].setBackgroundColor(colors[position] + 30);
|
||||
|
||||
|
||||
thirdButtons[position] = child.findViewById(R.id.choose_third);
|
||||
thirdButtons[position].setBackgroundColor(colors[position] + 30);
|
||||
|
||||
|
||||
if (position != ConstantUtils.questionList.length - 1) {
|
||||
firstButtons[position].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
firstButtons[position].setBackgroundColor(colors[position] - 60);
|
||||
secondButtons[position].setBackgroundColor(colors[position] + 30);
|
||||
thirdButtons[position].setBackgroundColor(colors[position] + 30);
|
||||
cardList.turnTo(position + 1);
|
||||
result += "1";
|
||||
}
|
||||
});
|
||||
} else {
|
||||
firstButtons[position].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getResult();
|
||||
resultLayout.setVisibility(View.VISIBLE);
|
||||
cardList.setVisibility(View.INVISIBLE);
|
||||
MessageUtils.MakeToast("已将体质信息上传至个人信息");
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
secondButtons[position].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
firstButtons[position].setBackgroundColor(colors[position] + 30);
|
||||
thirdButtons[position].setBackgroundColor(colors[position] + 30);
|
||||
secondButtons[position].setBackgroundColor(colors[position] - 60);
|
||||
cardList.turnTo(position + 1);
|
||||
result += "2";
|
||||
}
|
||||
});
|
||||
thirdButtons[position].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
firstButtons[position].setBackgroundColor(colors[position] + 30);
|
||||
secondButtons[position].setBackgroundColor(colors[position] + 30);
|
||||
thirdButtons[position].setBackgroundColor(colors[position] - 60);
|
||||
cardList.turnTo(position + 1);
|
||||
result += "3";
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < ConstantUtils.answerList[position].length; i++) {
|
||||
buttonList[i][position].setText(ConstantUtils.answerList[position][i]);
|
||||
buttonList[i][position].setVisibility(View.VISIBLE);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
cardList.setAdapter(adapter);
|
||||
cardList.setOnTurnListener(new TurnCardListView.OnTurnListener() {
|
||||
@Override
|
||||
public void onTurned(int position) {
|
||||
bottomContent.setBackgroundColor(colors[position] - 60);
|
||||
firstButtons[position].setEnabled(true);
|
||||
secondButtons[position].setEnabled(true);
|
||||
thirdButtons[position].setEnabled(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@OnClick(R.id.back_button)
|
||||
public void onViewClicked() {
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断体质
|
||||
*/
|
||||
private void getResult() {
|
||||
|
||||
float margin = 0.6f;
|
||||
|
||||
String code = result.substring(1);
|
||||
char[] codes = code.toCharArray();
|
||||
Logger.d(Arrays.toString(codes));
|
||||
|
||||
switch ((int) (codes[0]) - 48) {
|
||||
case 1:
|
||||
counter[0]++;
|
||||
counter[1]++;
|
||||
|
||||
counter[3] += margin;
|
||||
break;
|
||||
case 2:
|
||||
counter[2]++;
|
||||
counter[4]++;
|
||||
counter[5]++;
|
||||
counter[5] += 0.3;
|
||||
|
||||
counter[3] += margin;
|
||||
break;
|
||||
case 3:
|
||||
counter[7]++;
|
||||
|
||||
counter[6] += margin;
|
||||
counter[3] += margin;
|
||||
break;
|
||||
default:
|
||||
Logger.e((int) (codes[0]) + " 没执行");
|
||||
}
|
||||
switch ((int) (codes[1]) - 48) {
|
||||
case 1:
|
||||
counter[0]++;
|
||||
|
||||
counter[2] += margin;
|
||||
counter[3] += margin;
|
||||
break;
|
||||
case 2:
|
||||
counter[4]++;
|
||||
|
||||
counter[2] += margin;
|
||||
counter[3] += margin;
|
||||
break;
|
||||
case 3:
|
||||
counter[1]++;
|
||||
counter[5]++;
|
||||
counter[7]++;
|
||||
counter[6]++;
|
||||
|
||||
counter[2] += margin;
|
||||
counter[3] += margin;
|
||||
|
||||
break;
|
||||
}
|
||||
switch ((int) (codes[2]) - 48) {
|
||||
case 1:
|
||||
counter[1]++;
|
||||
counter[4]++;
|
||||
|
||||
counter[0] += margin;
|
||||
counter[2] += margin;
|
||||
counter[5] += margin;
|
||||
counter[6] += margin;
|
||||
|
||||
break;
|
||||
case 2:
|
||||
counter[3]++;
|
||||
|
||||
counter[0] += margin;
|
||||
counter[2] += margin;
|
||||
counter[5] += margin;
|
||||
counter[6] += margin;
|
||||
break;
|
||||
case 3:
|
||||
counter[7]++;
|
||||
|
||||
counter[0] += margin;
|
||||
counter[2] += margin;
|
||||
counter[5] += margin;
|
||||
counter[6] += margin;
|
||||
break;
|
||||
}
|
||||
switch ((int) (codes[3]) - 48) {
|
||||
case 1:
|
||||
counter[0]++;
|
||||
counter[2]++;
|
||||
counter[5]++;
|
||||
counter[6]++;
|
||||
|
||||
counter[3] += margin;
|
||||
counter[4] += margin;
|
||||
break;
|
||||
case 2:
|
||||
counter[7]++;
|
||||
counter[1]++;
|
||||
|
||||
counter[3] += margin;
|
||||
counter[4] += margin;
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
}
|
||||
switch ((int) (codes[4]) - 48) {
|
||||
case 1:
|
||||
counter[3]++;
|
||||
|
||||
counter[1] += margin;
|
||||
counter[2] += margin;
|
||||
counter[4] += margin;
|
||||
counter[5] += margin;
|
||||
counter[6] += margin;
|
||||
break;
|
||||
case 2:
|
||||
counter[5]++;
|
||||
|
||||
counter[1] += margin;
|
||||
counter[2] += margin;
|
||||
counter[4] += margin;
|
||||
counter[5] += margin;
|
||||
counter[6] += margin;
|
||||
|
||||
break;
|
||||
case 3:
|
||||
counter[7]++;
|
||||
|
||||
counter[1] += margin;
|
||||
counter[2] += margin;
|
||||
counter[4] += margin;
|
||||
counter[5] += margin;
|
||||
counter[6] += margin;
|
||||
break;
|
||||
}
|
||||
switch ((int) (codes[5]) - 48) {
|
||||
case 1:
|
||||
counter[2]++;
|
||||
counter[2]++;
|
||||
|
||||
counter[0] += margin;
|
||||
counter[3] += margin;
|
||||
counter[4] += margin;
|
||||
counter[5] += margin;
|
||||
counter[6] += margin;
|
||||
break;
|
||||
case 2:
|
||||
counter[1]++;
|
||||
counter[1]++;
|
||||
counter[1]++;
|
||||
|
||||
counter[0] += margin;
|
||||
counter[3] += margin;
|
||||
counter[4] += margin;
|
||||
counter[5] += margin;
|
||||
counter[6] += margin;
|
||||
break;
|
||||
case 3:
|
||||
counter[7]++;
|
||||
|
||||
counter[0] += margin;
|
||||
counter[3] += margin;
|
||||
counter[4] += margin;
|
||||
counter[5] += margin;
|
||||
counter[6] += margin;
|
||||
break;
|
||||
}
|
||||
|
||||
int maxIndex = -1;
|
||||
for (int i = 0; i < counter.length; i++) {
|
||||
if (counter[i] > counter[8]) {
|
||||
maxIndex = i;
|
||||
counter[8] = counter[i];
|
||||
}
|
||||
}
|
||||
physique = physiques[maxIndex];
|
||||
if (physique.equals("淤血质")) {
|
||||
physique = "瘀血质";
|
||||
}
|
||||
Logger.d(Arrays.toString(counter) + "\n" + physique);
|
||||
Physique phy = new Physique();
|
||||
phy.setPhysical_name(physique);
|
||||
phy.setCharacteristic(ConstantUtils.physiquesCharacteristics[maxIndex]);
|
||||
phy.setExpression(ConstantUtils.physiquesExpressions[maxIndex]);
|
||||
phy.setMentality(ConstantUtils.physiquesMentalitys[maxIndex]);
|
||||
phy.setMatters(ConstantUtils.physiquesMatters[maxIndex]);
|
||||
phy.setImageUrl(ConstantUtils.physiquesImageUrls[maxIndex]);
|
||||
user.setPhysical_name(physique);
|
||||
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
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
//设置全屏
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
super.onCreate(savedInstanceState);
|
||||
// TODO: add setContentView(...) invocation
|
||||
ButterKnife.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载显示的信息
|
||||
*
|
||||
* @param physique
|
||||
*/
|
||||
private void loadInformation(Physique physique) {
|
||||
Glide.with(AddPhysiqueActivity.this).load(physique.getImageUrl()).into(physiqueImage);
|
||||
physiqueNameTextView.setText(physique.getPhysical_name());
|
||||
expressionTextView.setText(physique.getExpression());
|
||||
characteristicTextView.setText(physique.getCharacteristic());
|
||||
mentalityTextView.setText(physique.getMentality());
|
||||
mattersTextView.setText(physique.getMatters());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.classifyresult;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
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.bean.Element;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class DishResultActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.calorie)
|
||||
TextView calorie;
|
||||
@BindView(R.id.suger)
|
||||
TextView suger;
|
||||
@BindView(R.id.fat)
|
||||
TextView fat;
|
||||
@BindView(R.id.protein)
|
||||
TextView protein;
|
||||
@BindView(R.id.ok_button)
|
||||
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
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_dish_result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
Intent intent = getIntent();
|
||||
results = (ArrayList<ClassifyResult>) intent.getSerializableExtra("LIST");
|
||||
|
||||
resultListAdapter = new ResultListAdapter(results, this);
|
||||
recyclerView.setAdapter(resultListAdapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 能量根据选择的来变
|
||||
*
|
||||
* @param quantity
|
||||
*/
|
||||
public void refreshData(int quantity, int positon) {
|
||||
float calorieSum = 0;
|
||||
float fatSum = 0;
|
||||
float sugarSum = 0;
|
||||
float proteinSum = 0;
|
||||
ClassifyResult temp = results.get(positon);
|
||||
temp.setQuantity(quantity);
|
||||
results.set(positon, temp);
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
|
||||
fatSum += results.get(i).getFoodMenu().getElements().getFat() * results.get(i).getQuantity() / 100;
|
||||
sugarSum += results.get(i).getFoodMenu().getElements().getCarbohydrate() * results.get(i).getQuantity() / 100;
|
||||
proteinSum += results.get(i).getFoodMenu().getElements().getProtein() * results.get(i).getQuantity() / 100;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.classifyresult;
|
||||
|
||||
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 ArrayList<String> nameList;
|
||||
private MaterialResultAdapter adapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_material_result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
Intent intent = getIntent();
|
||||
// classifyResults = (ArrayList<ClassifyResult>) intent.getSerializableExtra("LIST");
|
||||
// list = classifyResults.get(0).getFoodMaterial().getMenus();
|
||||
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
|
||||
public void initToolBar() {
|
||||
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.information;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class InformationActivity extends AppCompatActivity {
|
||||
|
||||
@BindView(R.id.back_button)
|
||||
ImageView backButton;
|
||||
@BindView(R.id.title_text)
|
||||
TextView titleText;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_information);
|
||||
ButterKnife.bind(this);
|
||||
}
|
||||
|
||||
@OnClick(R.id.back_button)
|
||||
public void onViewClicked() {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.login;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.app.LoaderManager.LoaderCallbacks;
|
||||
|
||||
import android.content.CursorLoader;
|
||||
import android.content.Loader;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
|
||||
import static android.Manifest.permission.READ_CONTACTS;
|
||||
|
||||
/**
|
||||
* A login screen that offers login via email/password.
|
||||
*/
|
||||
public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<Cursor> {
|
||||
|
||||
/**
|
||||
* Id to identity READ_CONTACTS permission request.
|
||||
*/
|
||||
private static final int REQUEST_READ_CONTACTS = 0;
|
||||
|
||||
/**
|
||||
* A dummy authentication store containing known user names and passwords.
|
||||
* TODO: remove after connecting to a real authentication system.
|
||||
*/
|
||||
private static final String[] DUMMY_CREDENTIALS = new String[]{
|
||||
"foo@example.com:hello", "bar@example.com:world"
|
||||
};
|
||||
/**
|
||||
* Keep track of the login task to ensure we can cancel it if requested.
|
||||
*/
|
||||
private UserLoginTask mAuthTask = null;
|
||||
|
||||
// UI references.
|
||||
private AutoCompleteTextView mEmailView;
|
||||
private EditText mPasswordView;
|
||||
private View mProgressView;
|
||||
private View mLoginFormView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
// Set up the login form.
|
||||
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
|
||||
populateAutoComplete();
|
||||
|
||||
mPasswordView = (EditText) findViewById(R.id.password);
|
||||
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
|
||||
if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
|
||||
attemptLogin();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
|
||||
mEmailSignInButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
attemptLogin();
|
||||
}
|
||||
});
|
||||
|
||||
mLoginFormView = findViewById(R.id.login_form);
|
||||
mProgressView = findViewById(R.id.login_progress);
|
||||
}
|
||||
|
||||
private void populateAutoComplete() {
|
||||
if (!mayRequestContacts()) {
|
||||
return;
|
||||
}
|
||||
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
private boolean mayRequestContacts() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
return true;
|
||||
}
|
||||
if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
||||
return true;
|
||||
}
|
||||
if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
|
||||
Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
|
||||
.setAction(android.R.string.ok, new View.OnClickListener() {
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
public void onClick(View v) {
|
||||
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback received when a permissions request has been completed.
|
||||
*/
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||
@NonNull int[] grantResults) {
|
||||
if (requestCode == REQUEST_READ_CONTACTS) {
|
||||
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
populateAutoComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to sign in or register the account specified by the login form.
|
||||
* If there are form errors (invalid email, missing fields, etc.), the
|
||||
* errors are presented and no actual login attempt is made.
|
||||
*/
|
||||
private void attemptLogin() {
|
||||
if (mAuthTask != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset errors.
|
||||
mEmailView.setError(null);
|
||||
mPasswordView.setError(null);
|
||||
|
||||
// Store values at the time of the login attempt.
|
||||
String email = mEmailView.getText().toString();
|
||||
String password = mPasswordView.getText().toString();
|
||||
|
||||
boolean cancel = false;
|
||||
View focusView = null;
|
||||
|
||||
// Check for a valid password, if the user entered one.
|
||||
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
|
||||
mPasswordView.setError(getString(R.string.error_invalid_password));
|
||||
focusView = mPasswordView;
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
// Check for a valid email address.
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
mEmailView.setError(getString(R.string.error_field_required));
|
||||
focusView = mEmailView;
|
||||
cancel = true;
|
||||
} else if (!isEmailValid(email)) {
|
||||
mEmailView.setError(getString(R.string.error_invalid_email));
|
||||
focusView = mEmailView;
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
if (cancel) {
|
||||
// There was an error; don't attempt login and focus the first
|
||||
// form field with an error.
|
||||
focusView.requestFocus();
|
||||
} else {
|
||||
// Show a progress spinner, and kick off a background task to
|
||||
// perform the user login attempt.
|
||||
showProgress(true);
|
||||
mAuthTask = new UserLoginTask(email, password);
|
||||
mAuthTask.execute((Void) null);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEmailValid(String email) {
|
||||
//TODO: Replace this with your own logic
|
||||
return email.contains("@");
|
||||
}
|
||||
|
||||
private boolean isPasswordValid(String password) {
|
||||
//TODO: Replace this with your own logic
|
||||
return password.length() > 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the progress UI and hides the login form.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
|
||||
private void showProgress(final boolean show) {
|
||||
// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
|
||||
// for very easy animations. If available, use these APIs to fade-in
|
||||
// the progress spinner.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
|
||||
int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
|
||||
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
mLoginFormView.animate().setDuration(shortAnimTime).alpha(
|
||||
show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
mProgressView.animate().setDuration(shortAnimTime).alpha(
|
||||
show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// The ViewPropertyAnimator APIs are not available, so simply show
|
||||
// and hide the relevant UI components.
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
||||
return new CursorLoader(this,
|
||||
// Retrieve data rows for the device user's 'profile' contact.
|
||||
Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
|
||||
ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
|
||||
|
||||
// Select only email addresses.
|
||||
ContactsContract.Contacts.Data.MIMETYPE +
|
||||
" = ?", new String[]{ContactsContract.CommonDataKinds.Email
|
||||
.CONTENT_ITEM_TYPE},
|
||||
|
||||
// Show primary email addresses first. Note that there won't be
|
||||
// a primary email address if the user hasn't specified one.
|
||||
ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
|
||||
List<String> emails = new ArrayList<>();
|
||||
cursor.moveToFirst();
|
||||
while (!cursor.isAfterLast()) {
|
||||
emails.add(cursor.getString(ProfileQuery.ADDRESS));
|
||||
cursor.moveToNext();
|
||||
}
|
||||
|
||||
addEmailsToAutoComplete(emails);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> cursorLoader) {
|
||||
|
||||
}
|
||||
|
||||
private void addEmailsToAutoComplete(List<String> emailAddressCollection) {
|
||||
//Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
|
||||
ArrayAdapter<String> adapter =
|
||||
new ArrayAdapter<>(LoginActivity.this,
|
||||
android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
|
||||
|
||||
mEmailView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
||||
private interface ProfileQuery {
|
||||
String[] PROJECTION = {
|
||||
ContactsContract.CommonDataKinds.Email.ADDRESS,
|
||||
ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
|
||||
};
|
||||
|
||||
int ADDRESS = 0;
|
||||
int IS_PRIMARY = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an asynchronous login/registration task used to authenticate
|
||||
* the user.
|
||||
*/
|
||||
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private final String mEmail;
|
||||
private final String mPassword;
|
||||
|
||||
UserLoginTask(String email, String password) {
|
||||
mEmail = email;
|
||||
mPassword = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
// TODO: attempt authentication against a network service.
|
||||
|
||||
try {
|
||||
// Simulate network access.
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String credential : DUMMY_CREDENTIALS) {
|
||||
String[] pieces = credential.split(":");
|
||||
if (pieces[0].equals(mEmail)) {
|
||||
// Account exists, return true if the password matches.
|
||||
return pieces[1].equals(mPassword);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: register the new account here.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(final Boolean success) {
|
||||
mAuthTask = null;
|
||||
showProgress(false);
|
||||
|
||||
if (success) {
|
||||
finish();
|
||||
} else {
|
||||
mPasswordView.setError(getString(R.string.error_incorrect_password));
|
||||
mPasswordView.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
mAuthTask = null;
|
||||
showProgress(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.bodyinformation;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.Unbinder;
|
||||
import me.itangqi.waveloadingview.WaveLoadingView;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public class BodyInformationFragment extends BaseFragment {
|
||||
|
||||
Unbinder unbinder;
|
||||
@BindView(R.id.step_text_view)
|
||||
TextView stepTextView;
|
||||
@BindView(R.id.waveLoadingView)
|
||||
WaveLoadingView waveLoadingView;
|
||||
@BindView(R.id.weight_line_chart)
|
||||
LineChart weightLineChart;
|
||||
@BindView(R.id.step_line_chart)
|
||||
LineChart stepLineChart;
|
||||
@BindView(R.id.calorie_text)
|
||||
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;
|
||||
|
||||
//循环取当前时刻的步数中间的间隔时间
|
||||
private long TIME_INTERVAL_REFRESH = 500;
|
||||
|
||||
private Handler mDelayHandler = new Handler(new TodayStepCounterCall());
|
||||
|
||||
private ISportStepInterface iSportStepInterface;
|
||||
|
||||
private ServiceConnection coon;
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutResId() {
|
||||
return R.layout.body_information_fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView(Bundle state) {
|
||||
initStepCounter();
|
||||
initChart();
|
||||
}
|
||||
|
||||
public static BaseFragment getInstance() {
|
||||
return new BodyInformationFragment();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计步器初始化
|
||||
*/
|
||||
private void initStepCounter() {
|
||||
TodayStepManager.init(getActivity().getApplication());
|
||||
//开启计步
|
||||
Intent stepCounterStart = new Intent(getActivity(), TodayStepService.class);
|
||||
getActivity().startService(stepCounterStart);
|
||||
coon = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
iSportStepInterface = ISportStepInterface.Stub.asInterface(service);
|
||||
try {
|
||||
stepCount = iSportStepInterface.getCurrentTimeSportStep();
|
||||
updateStepCount();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mDelayHandler.sendEmptyMessageDelayed(REFRESH_STEP_WHAT, TIME_INTERVAL_REFRESH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
|
||||
}
|
||||
};
|
||||
getActivity().bindService(stepCounterStart, coon, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 改变记步UI中的数字
|
||||
*/
|
||||
private void updateStepCount() {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定时器,修改UI
|
||||
*/
|
||||
class TodayStepCounterCall implements Handler.Callback {
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case REFRESH_STEP_WHAT: {
|
||||
//每隔500毫秒获取一次计步数据刷新UI
|
||||
if (null != iSportStepInterface) {
|
||||
int step = 0;
|
||||
try {
|
||||
step = iSportStepInterface.getCurrentTimeSportStep();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (stepCount != step) {
|
||||
stepCount = step;
|
||||
updateStepCount();
|
||||
}
|
||||
}
|
||||
mDelayHandler.sendEmptyMessageDelayed(REFRESH_STEP_WHAT, TIME_INTERVAL_REFRESH);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化表格
|
||||
*/
|
||||
private void initChart() {
|
||||
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, "体重");
|
||||
|
||||
ArrayList<Entry> stepPointValues = new ArrayList<>();
|
||||
for (int i = 1; i < 15; i++) {
|
||||
int y = (int) (Math.random() * 20);
|
||||
stepPointValues.add(new Entry(i, y));
|
||||
}
|
||||
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();
|
||||
getActivity().unbindService(coon);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*/
|
||||
public void refreshUI() {
|
||||
if (NutritionMaster.user.getBmi() != -1) {
|
||||
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);
|
||||
}
|
||||
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
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
refreshUI();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
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 {
|
||||
|
||||
@BindView(R.id.breakfast_energy_text)
|
||||
TextView breakfastEnergyText;
|
||||
@BindView(R.id.breakfast_recycler_view)
|
||||
RecyclerView breakfastRecyclerView;
|
||||
@BindView(R.id.lunch_energy_text)
|
||||
TextView lunchEnergyText;
|
||||
@BindView(R.id.lunch_recycler_view)
|
||||
RecyclerView lunchRecyclerView;
|
||||
@BindView(R.id.dinner_energy_text)
|
||||
TextView dinnerEnergyText;
|
||||
@BindView(R.id.dinner_recycler_view)
|
||||
RecyclerView dinnerRecyclerView;
|
||||
@BindView(R.id.calorie_text)
|
||||
TextView calorieText;
|
||||
@BindView(R.id.fat_text)
|
||||
TextView fatText;
|
||||
@BindView(R.id.suger_text)
|
||||
TextView sugerText;
|
||||
@BindView(R.id.protein_text)
|
||||
TextView proteinText;
|
||||
@BindView(R.id.change_button)
|
||||
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);
|
||||
ButterKnife.bind(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_customization;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
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
|
||||
public void initToolBar() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@OnClick({R.id.change_button, R.id.copy_button})
|
||||
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++) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.viewpagerfragments.customization;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.CardAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.CardHolder;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseFragment;
|
||||
import com.example.ninefourone.nutritionmaster.bean.DailyCard;
|
||||
import com.example.ninefourone.nutritionmaster.cardconfig.CardConfig;
|
||||
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;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public class CustomizationFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.card_recycler_view)
|
||||
RecyclerView cardRecyclerView;
|
||||
Unbinder unbinder;
|
||||
|
||||
private CardAdapter cardAdapter;
|
||||
private ArrayList<DailyCard> mDataList = new ArrayList<>();
|
||||
|
||||
private int[] picList = new int[]{
|
||||
R.drawable.monday,
|
||||
R.drawable.tuesday,
|
||||
R.drawable.wednesday,
|
||||
R.drawable.thursday,
|
||||
R.drawable.friday,
|
||||
R.drawable.saturday,
|
||||
R.drawable.sunday
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutResId() {
|
||||
return R.layout.customization;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView(Bundle state) {
|
||||
loadData();
|
||||
initCardRecyclerView();
|
||||
}
|
||||
|
||||
|
||||
public static BaseFragment getInstance() {
|
||||
return new CustomizationFragment();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Override
|
||||
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],
|
||||
picList[i - 1]
|
||||
);
|
||||
mDataList.add(dailyCard);
|
||||
}
|
||||
for (int i = 1; i < CalculateUtils.getWeek(); i++) {
|
||||
// mDataList.add("周" + ConstantUtils.arab2Chinese(i) + "美食普");
|
||||
DailyCard dailyCard = new DailyCard(
|
||||
"周" + ConstantUtils.arab2Chinese(i) + "美食谱",
|
||||
ConstantUtils.dailyDescibes[i - 1],
|
||||
picList[i - 1]
|
||||
);
|
||||
mDataList.add(dailyCard);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化card recyclerview
|
||||
*/
|
||||
private void initCardRecyclerView() {
|
||||
CardConfig.initConfig(getContext());
|
||||
cardRecyclerView.setLayoutManager(new SwipeCardLayoutManager());
|
||||
cardAdapter = new CardAdapter(getContext(), mDataList);
|
||||
cardRecyclerView.setAdapter(cardAdapter);
|
||||
|
||||
CardItemTouchCallBack callBack = new CardItemTouchCallBack(cardRecyclerView, cardAdapter, mDataList);
|
||||
//2.创建ItemTouchHelper并把callBack传进去
|
||||
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callBack);
|
||||
//3.与RecyclerView关联起来
|
||||
itemTouchHelper.attachToRecyclerView(cardRecyclerView);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.example.ninefourone.nutritionmaster.step;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.modules.MainActivity;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
|
||||
public class StepStarter extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// TODO: This method is called when the BroadcastReceiver is receiving
|
||||
// an Intent broadcast.
|
||||
// throw new UnsupportedOperationException("Not yet implemented");
|
||||
NutritionMaster nutritionMaster = (NutritionMaster) context.getApplicationContext();
|
||||
if (!nutritionMaster.isForeground()) {
|
||||
Intent mainIntent = new Intent(context, MainActivity.class);
|
||||
mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(mainIntent);
|
||||
}else {
|
||||
Logger.d("已经在计步了");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.example.ninefourone.nutritionmaster.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
|
||||
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
|
||||
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
|
||||
import com.bigkoo.pickerview.view.OptionsPickerView;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseDialog;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/1.
|
||||
*/
|
||||
|
||||
public class InformationDialog extends BaseDialog {
|
||||
|
||||
|
||||
private TextView ageTextView;
|
||||
private TextView heightTextView;
|
||||
private TextView weightTextView;
|
||||
private TextView sexTextView;
|
||||
|
||||
private ImageView ageImageView;
|
||||
private ImageView sexImageView;
|
||||
private ImageView heightImageView;
|
||||
private ImageView weightImageView;
|
||||
|
||||
private Button okButton;
|
||||
|
||||
private OptionsPickerView agePicker;
|
||||
private OptionsPickerView weightPicker;
|
||||
private OptionsPickerView heightPicker;
|
||||
private OptionsPickerView sexPicker;
|
||||
|
||||
|
||||
public InformationDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
dialog = create();
|
||||
|
||||
|
||||
View view = View.inflate(context, R.layout.add_information_activity, null);
|
||||
dialog.setView(view);
|
||||
|
||||
ageImageView = view.findViewById(R.id.age_image_view);
|
||||
sexImageView = view.findViewById(R.id.sex_image_view);
|
||||
heightImageView = view.findViewById(R.id.height_image_view);
|
||||
weightImageView = view.findViewById(R.id.weight_image_view);
|
||||
|
||||
|
||||
ageTextView = view.findViewById(R.id.age_text_view);
|
||||
sexTextView = view.findViewById(R.id.sex_text_view);
|
||||
weightTextView = view.findViewById(R.id.weight_text_view);
|
||||
heightTextView = view.findViewById(R.id.height_text_view);
|
||||
|
||||
okButton = view.findViewById(R.id.ok_button);
|
||||
|
||||
agePicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
ageTextView.setText(ConstantUtils.ageList.get(options1));
|
||||
}
|
||||
}).build();
|
||||
agePicker.setPicker(ConstantUtils.ageList);
|
||||
|
||||
|
||||
sexPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
sexTextView.setText(ConstantUtils.ageList.get(options1));
|
||||
}
|
||||
}).build();
|
||||
sexPicker.setPicker(ConstantUtils.sexList);
|
||||
|
||||
|
||||
heightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
heightTextView.setText(ConstantUtils.ageList.get(options1));
|
||||
}
|
||||
}).build();
|
||||
heightPicker.setPicker(ConstantUtils.heightList);
|
||||
|
||||
|
||||
weightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
weightTextView.setText(ConstantUtils.ageList.get(options1));
|
||||
}
|
||||
}).build();
|
||||
weightPicker.setPicker(ConstantUtils.weightList);
|
||||
|
||||
|
||||
ageImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
agePicker.show();
|
||||
}
|
||||
});
|
||||
sexImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sexPicker.show();
|
||||
}
|
||||
});
|
||||
heightImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
heightPicker.show();
|
||||
}
|
||||
});
|
||||
weightImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
weightPicker.show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.example.ninefourone.nutritionmaster.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
/**
|
||||
* Created by Wangtianrui on 2018/5/1.
|
||||
* 重写Viewpager解决点击tab去除滑动动画效果的问题
|
||||
*/
|
||||
public class NoScrollViewPager extends ViewPager {
|
||||
public NoScrollViewPager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public NoScrollViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollTo(int x, int y) {
|
||||
super.scrollTo(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItem(int item, boolean smoothScroll) {
|
||||
super.setCurrentItem(item, smoothScroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItem(int item) {
|
||||
super.setCurrentItem(item, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
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.
|
||||
*/
|
||||
|
||||
public class CalculateUtils {
|
||||
/**
|
||||
* 计算BMI值 BMI值計算公式: BMI = 體重(公斤) / 身高2(公尺2)
|
||||
*
|
||||
* @param height
|
||||
* @param weight
|
||||
* @return
|
||||
*/
|
||||
public static float BMI(float height, float weight) {
|
||||
if (height > 10) {
|
||||
height = height / 100.0f;
|
||||
}
|
||||
// Logger.d(height+"|"+weight / (height * height));
|
||||
return weight / (height * height);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过身高获得健康的体重
|
||||
*
|
||||
* @param height
|
||||
* @return
|
||||
*/
|
||||
public static float[] standardH2W(float height) {
|
||||
if (height > 10) {
|
||||
height = height / 100;
|
||||
}
|
||||
float min;
|
||||
float max;
|
||||
min = (float) 18.5 * height * height;
|
||||
max = (float) 14 * height * height;
|
||||
float[] re = {min, max};
|
||||
return re;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据BMI得到体质情况
|
||||
*
|
||||
* @param BMI
|
||||
* @return
|
||||
*/
|
||||
public static String bodyStatus(float BMI) {
|
||||
if (BMI < 18.5) {
|
||||
return "轻体重";
|
||||
} else if (BMI < 24) {
|
||||
return "健康体重";
|
||||
} else if (BMI < 27) {
|
||||
return "轻度肥胖";
|
||||
} else if (BMI < 30) {
|
||||
return "中度肥胖";
|
||||
} else {
|
||||
return "重度肥胖";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取星期几
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getWeek() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
// Logger.d( calendar.get(Calendar.DAY_OF_WEEK));
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 性别转数字
|
||||
*
|
||||
* @param sex
|
||||
* @return
|
||||
*/
|
||||
public static int sex2int(String sex) {
|
||||
if (sex.equals("男")) {
|
||||
return 1;
|
||||
} else if (sex.equals("女")) {
|
||||
return 0;
|
||||
} else {
|
||||
Logger.e("不男不女");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算每个食物吃多少
|
||||
*
|
||||
* @param classifyResultArrayList
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static ArrayList<ClassifyResult> getDishQuantity(
|
||||
ArrayList<ClassifyResult> classifyResultArrayList, MyUser user) {
|
||||
double calorieSum = 0;
|
||||
double[] calories = new double[classifyResultArrayList.size()];
|
||||
float baseQuantity = 600f;
|
||||
float factor = 1;
|
||||
|
||||
if (user.getBmi().intValue() == -1) {
|
||||
MessageUtils.MakeToast("检测到未填写个人信息,按成人标准进行计算");
|
||||
} else {
|
||||
if (user.getAge() <= 60) {
|
||||
factor = 1 - (Math.abs(user.getAge() - 30)) / 30.0f;
|
||||
} else {
|
||||
factor = 1 - (Math.abs(user.getAge() - 30)) / 70.0f;
|
||||
}
|
||||
factor = factor * (user.getBmi().intValue() / 21.0f) - (factor - 1.0f) / 5;
|
||||
Logger.d(factor);
|
||||
}
|
||||
|
||||
for (int i = 0; i < classifyResultArrayList.size(); i++) {
|
||||
calorieSum += classifyResultArrayList.get(i).getCalorie();
|
||||
calories[i] = classifyResultArrayList.get(i).getCalorie();
|
||||
}
|
||||
for (int i = 0; i < classifyResultArrayList.size(); i++) {
|
||||
classifyResultArrayList.get(i).setQuantity(calories[i] / calorieSum * baseQuantity * factor
|
||||
+ NutritionMaster.flavourCount * 5);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
import com.github.mikephil.charting.components.AxisBase;
|
||||
import com.github.mikephil.charting.components.Description;
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.LineData;
|
||||
import com.github.mikephil.charting.data.LineDataSet;
|
||||
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
|
||||
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/30.
|
||||
*/
|
||||
|
||||
public class ChartDrawer {
|
||||
|
||||
/**
|
||||
* 创建一条折线
|
||||
*
|
||||
* @param index
|
||||
* @param datas
|
||||
* @param linename
|
||||
* @return
|
||||
*/
|
||||
public static void initSingleLineChart(LineChart mLineChart, ArrayList<Entry> pointValues, String linename) {
|
||||
// if (index.length != datas.length) {
|
||||
// MessageUtils.MakeToast("index长度与datas长度不符");
|
||||
// Logger.d("长度不符");
|
||||
// return;
|
||||
// } else {
|
||||
// ArrayList<String> xValues = new ArrayList<>();
|
||||
// for (int i = 0; i < datas.length; i++) {
|
||||
// xValues.add(index[i] + "");
|
||||
// }
|
||||
// ArrayList<Entry> pointValues = new ArrayList<>();
|
||||
// for (int i = 0; i < datas.length; i++) {
|
||||
// pointValues.add(new Entry(datas[i], i));
|
||||
// }
|
||||
// LineDataSet dataSet = new LineDataSet(pointValues, linename);
|
||||
// dataSet.setLineWidth(1.75f);
|
||||
// dataSet.setColor(R.color.colorPrimary);
|
||||
//
|
||||
// ArrayList<ILineDataSet> dataSetArrayList = new ArrayList<>();
|
||||
// dataSetArrayList.add(dataSet);
|
||||
//
|
||||
// LineData lineData = new LineData(dataSetArrayList);
|
||||
|
||||
//表格属性
|
||||
// lineChart.setDrawBorders(false);
|
||||
// lineChart.setDrawGridBackground(false); //表格颜色
|
||||
// lineChart.setGridBackgroundColor(Color.GRAY & 0x70FFFFFF); //表格的颜色,设置一个透明度
|
||||
// lineChart.setTouchEnabled(true); //可点击
|
||||
// lineChart.setDragEnabled(true); //可拖拽
|
||||
// lineChart.setScaleEnabled(true); //可缩放
|
||||
// lineChart.setPinchZoom(false);
|
||||
// lineChart.setBackgroundColor(Color.WHITE); //设置背景颜色
|
||||
//
|
||||
// lineChart.setData(lineData);
|
||||
//
|
||||
// Legend mLegend = lineChart.getLegend(); //设置标示,就是那个一组y的value的
|
||||
// mLegend.setForm(Legend.LegendForm.SQUARE); //样式
|
||||
// mLegend.setFormSize(6f); //字体
|
||||
// mLegend.setTextColor(Color.GRAY); //颜色
|
||||
// lineChart.setVisibleXRange(0, 4); //x轴可显示的坐标范围
|
||||
// XAxis xAxis = lineChart.getXAxis(); //x轴的标示
|
||||
// xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); //x轴位置
|
||||
// xAxis.setTextColor(Color.GRAY); //字体的颜色
|
||||
// xAxis.setTextSize(10f); //字体大小
|
||||
// xAxis.setGridColor(Color.GRAY);//网格线颜色
|
||||
// xAxis.setDrawGridLines(false); //不显示网格线
|
||||
// YAxis axisLeft = lineChart.getAxisLeft(); //y轴左边标示
|
||||
// YAxis axisRight = lineChart.getAxisRight(); //y轴右边标示
|
||||
// axisLeft.setTextColor(Color.GRAY); //字体颜色
|
||||
// axisLeft.setTextSize(10f); //字体大小
|
||||
// //axisLeft.setAxisMaxValue(800f); //最大值
|
||||
// axisLeft.setLabelCount(5, true); //显示格数
|
||||
// axisLeft.setGridColor(Color.GRAY); //网格线颜色
|
||||
//
|
||||
// axisRight.setDrawAxisLine(false);
|
||||
// axisRight.setDrawGridLines(false);
|
||||
// axisRight.setDrawLabels(false);
|
||||
//
|
||||
// //设置动画效果
|
||||
// lineChart.animateY(2000, Easing.EasingOption.Linear);
|
||||
// lineChart.animateX(2000, Easing.EasingOption.Linear);
|
||||
// lineChart.invalidate();
|
||||
mLineChart.setNoDataText("没有数据喔~~");
|
||||
//设置是否绘制chart边框的线
|
||||
mLineChart.setDrawBorders(true);
|
||||
//设置chart边框线颜色
|
||||
mLineChart.setBorderColor(Color.GRAY);
|
||||
//设置chart边框线宽度
|
||||
mLineChart.setBorderWidth(1f);
|
||||
//设置chart是否可以触摸
|
||||
mLineChart.setTouchEnabled(true);
|
||||
//设置是否可以拖拽
|
||||
mLineChart.setDragEnabled(true);
|
||||
//设置是否可以缩放 x和y,默认true
|
||||
mLineChart.setScaleEnabled(false);
|
||||
//设置是否可以通过双击屏幕放大图表。默认是true
|
||||
mLineChart.setDoubleTapToZoomEnabled(false);
|
||||
//设置chart动画
|
||||
mLineChart.animateXY(1000, 1000);
|
||||
|
||||
//=========================设置图例=========================
|
||||
// 像"□ xxx"就是图例
|
||||
Legend legend = mLineChart.getLegend();
|
||||
legend.setEnabled(false);
|
||||
|
||||
|
||||
//=======================设置X轴显示效果==================
|
||||
XAxis xAxis = mLineChart.getXAxis();
|
||||
//是否启用X轴
|
||||
xAxis.setEnabled(true);
|
||||
//是否绘制X轴线
|
||||
xAxis.setDrawAxisLine(true);
|
||||
//设置X轴上每个竖线是否显示
|
||||
xAxis.setDrawGridLines(true);
|
||||
//设置是否绘制X轴上的对应值(标签)
|
||||
xAxis.setDrawLabels(true);
|
||||
//设置X轴显示位置
|
||||
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
|
||||
//设置竖线为虚线样式
|
||||
// xAxis.enableGridDashedLine(10f, 10f, 0f);
|
||||
//设置x轴标签数
|
||||
xAxis.setLabelCount(8, false);
|
||||
xAxis.setTextSize(5);
|
||||
//图表第一个和最后一个label数据不超出左边和右边的Y轴
|
||||
// xAxis.setAvoidFirstLastClipping(true);
|
||||
xAxis.setDrawGridLines(false);//设置x轴上每个点对应的线
|
||||
|
||||
//修改横轴
|
||||
//准备好每个点对应的x轴数值
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int i = 0; i < pointValues.size(); i++) {
|
||||
list.add(String.valueOf(i + 1).concat("号"));
|
||||
}
|
||||
xAxis.setValueFormatter(new IndexAxisValueFormatter(list));
|
||||
|
||||
|
||||
YAxis rightAxis = mLineChart.getAxisRight();
|
||||
rightAxis.setDrawAxisLine(false);
|
||||
rightAxis.setDrawGridLines(false);
|
||||
rightAxis.setEnabled(false);
|
||||
YAxis leftAxis = mLineChart.getAxisLeft();
|
||||
leftAxis.setEnabled(false);
|
||||
leftAxis.setDrawAxisLine(true);
|
||||
rightAxis.setAxisMinimum(0);
|
||||
|
||||
//点构成的某条线
|
||||
LineDataSet lineDataSet = new LineDataSet(pointValues, "体重");
|
||||
//设置该线的颜色
|
||||
lineDataSet.setColor(R.color.color_bar_background);
|
||||
//设置每个点的颜色
|
||||
lineDataSet.setCircleColor(0xff0171c9);
|
||||
//设置该线的宽度
|
||||
lineDataSet.setLineWidth(0f);
|
||||
|
||||
//设置每个坐标点的圆大小
|
||||
//lineDataSet.setCircleRadius(1f);
|
||||
//设置是否画圆
|
||||
lineDataSet.setDrawCircles(false);
|
||||
// 设置平滑曲线模式
|
||||
// lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
|
||||
//设置线一面部分是否填充颜色
|
||||
lineDataSet.setDrawFilled(true);
|
||||
//设置填充的颜色
|
||||
lineDataSet.setFillColor(0x20A0FF);
|
||||
//设置是否显示点的坐标值
|
||||
lineDataSet.setDrawValues(false);
|
||||
|
||||
|
||||
//隐藏x轴描述
|
||||
Description description = new Description();
|
||||
description.setEnabled(false);
|
||||
mLineChart.setDescription(description);
|
||||
mLineChart.setDrawBorders(false);
|
||||
//线的集合(可单条或多条线)
|
||||
List<ILineDataSet> dataSets = new ArrayList<>();
|
||||
dataSets.add(lineDataSet);
|
||||
//把要画的所有线(线的集合)添加到LineData里
|
||||
LineData lineData = new LineData(dataSets);
|
||||
//把最终的数据setData
|
||||
mLineChart.setData(lineData);
|
||||
mLineChart.invalidate();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public class ConstantUtils {
|
||||
|
||||
public static String[] dailyDescibes = {"快乐陪周一", "幸运伴周二", "轻松有周三", "温馨携周四",
|
||||
"愉悦同周五", "休闲找周六", "潇洒属周日"};
|
||||
|
||||
|
||||
public static String arab2Chinese(int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
return "一";
|
||||
case 2:
|
||||
return "二";
|
||||
case 3:
|
||||
return "三";
|
||||
case 4:
|
||||
return "四";
|
||||
case 5:
|
||||
return "五";
|
||||
case 6:
|
||||
return "六";
|
||||
case 7:
|
||||
return "日";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String[] questionList = new String[]{
|
||||
"现在先去找个镜子吧" +
|
||||
"\n下面会用到哦",
|
||||
"你舌苔的颜色",
|
||||
"舌底经络颜色",
|
||||
"口腔整体情况",
|
||||
"整体生活精神状况",
|
||||
"生活中的小问题",
|
||||
"饮用水温度偏向",
|
||||
"揭晓结果"
|
||||
};
|
||||
|
||||
public static String[][] answerList = new String[][]{
|
||||
{"开始吧"},
|
||||
{"深红", "偏白", "淡红"},
|
||||
{"暗紫", "细红", "不明显"},
|
||||
{"口舌干燥", "口黏苔腻", "还算正常"},
|
||||
{"沉寂易疲劳", "精力充沛"},
|
||||
{"多汗无力、易胖", "多愁善感", "都不"},
|
||||
{"烫的", "冷的", "没有特别喜欢的"},
|
||||
{"查看"}
|
||||
};
|
||||
|
||||
public static ArrayList<String> occupationList = new ArrayList<>();
|
||||
|
||||
public static ArrayList<String> ageList = new ArrayList<>();
|
||||
|
||||
public static ArrayList<String> sexList = new ArrayList<>();
|
||||
|
||||
public static ArrayList<String> heightList = new ArrayList<>();
|
||||
|
||||
public static ArrayList<String> weightList = new ArrayList<>();
|
||||
|
||||
static {
|
||||
for (int i = 1; i <= 200; i++) {
|
||||
if (i < 100) {
|
||||
ageList.add(i + "岁");
|
||||
}
|
||||
heightList.add(i + 50 + "cm");
|
||||
if (i < 150) {
|
||||
weightList.add(i + "kg");
|
||||
}
|
||||
}
|
||||
sexList.add("男");
|
||||
sexList.add("女");
|
||||
}
|
||||
|
||||
/**
|
||||
* 全国平均身高 index 0 对应 3岁
|
||||
*/
|
||||
public static ArrayList<Float> averageBoyHeight = new ArrayList<>();
|
||||
|
||||
public static ArrayList<Float> averageGirlHeight = new ArrayList<>();
|
||||
|
||||
static {
|
||||
averageBoyHeight.add(new Float(102.2));
|
||||
averageBoyHeight.add(new Float(107.8));
|
||||
averageBoyHeight.add(new Float(114));
|
||||
averageBoyHeight.add(new Float(119.7));
|
||||
averageBoyHeight.add(new Float(126.6));
|
||||
averageBoyHeight.add(new Float(132));
|
||||
averageBoyHeight.add(new Float(137.2));
|
||||
averageBoyHeight.add(new Float(142.1));
|
||||
averageBoyHeight.add(new Float(148.1));
|
||||
averageBoyHeight.add(new Float(154.5));
|
||||
averageBoyHeight.add(new Float(161.4));
|
||||
averageBoyHeight.add(new Float(166.5));
|
||||
averageBoyHeight.add(new Float(169.8));
|
||||
averageBoyHeight.add(new Float(171.4));
|
||||
averageBoyHeight.add(new Float(172.1));
|
||||
averageBoyHeight.add(new Float(172));
|
||||
averageBoyHeight.add(new Float(172.4)); //index 16 age 19
|
||||
|
||||
averageBoyHeight.add(new Float(171.9));
|
||||
averageBoyHeight.add(new Float(171.6));
|
||||
averageBoyHeight.add(new Float(170.8));
|
||||
averageBoyHeight.add(new Float(169.9));
|
||||
averageBoyHeight.add(new Float(169));
|
||||
averageBoyHeight.add(new Float(168.7));
|
||||
averageBoyHeight.add(new Float(168.3));
|
||||
averageBoyHeight.add(new Float(167.5));
|
||||
|
||||
|
||||
averageGirlHeight.add(new Float(100.9));
|
||||
averageGirlHeight.add(new Float(106.5));
|
||||
averageGirlHeight.add(new Float(112.7));
|
||||
averageGirlHeight.add(new Float(118.1));
|
||||
averageGirlHeight.add(new Float(125.1));
|
||||
averageGirlHeight.add(new Float(130.5));
|
||||
averageGirlHeight.add(new Float(136.3));
|
||||
averageGirlHeight.add(new Float(142.6));
|
||||
averageGirlHeight.add(new Float(149.3));
|
||||
averageGirlHeight.add(new Float(153.7));
|
||||
averageGirlHeight.add(new Float(157));
|
||||
averageGirlHeight.add(new Float(158.7));
|
||||
averageGirlHeight.add(new Float(159.4));
|
||||
averageGirlHeight.add(new Float(159.8));
|
||||
averageGirlHeight.add(new Float(159.9));
|
||||
averageGirlHeight.add(new Float(159.4));
|
||||
averageGirlHeight.add(new Float(160.4));//index 16 age 19
|
||||
|
||||
|
||||
averageGirlHeight.add(new Float(159.9));//index 17 age 24
|
||||
averageGirlHeight.add(new Float(159.6));
|
||||
averageGirlHeight.add(new Float(159.1));
|
||||
averageGirlHeight.add(new Float(158.5));
|
||||
averageGirlHeight.add(new Float(157.8));
|
||||
averageGirlHeight.add(new Float(157.7));
|
||||
averageGirlHeight.add(new Float(157.7));// index 23 age 54
|
||||
averageGirlHeight.add(new Float(156.8)); //index 24 age 59
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 全国平均体重
|
||||
*/
|
||||
public static ArrayList<Float> averageBoyWeight = new ArrayList<>();
|
||||
public static ArrayList<Float> averageGirlWeight = new ArrayList<>();
|
||||
|
||||
static {
|
||||
averageBoyWeight.add(new Float(16.6));
|
||||
averageBoyWeight.add(new Float(18.3));
|
||||
averageBoyWeight.add(new Float(20.6));
|
||||
averageBoyWeight.add(new Float(23));
|
||||
averageBoyWeight.add(new Float(26.6));
|
||||
averageBoyWeight.add(new Float(29.9));
|
||||
averageBoyWeight.add(new Float(33.6));
|
||||
averageBoyWeight.add(new Float(37.2));
|
||||
averageBoyWeight.add(new Float(41.9));
|
||||
averageBoyWeight.add(new Float(16.6));
|
||||
averageBoyWeight.add(new Float(52));
|
||||
averageBoyWeight.add(new Float(56.2));
|
||||
averageBoyWeight.add(new Float(59.5));
|
||||
averageBoyWeight.add(new Float(61.5));
|
||||
averageBoyWeight.add(new Float(63.3));
|
||||
averageBoyWeight.add(new Float(63.5));
|
||||
averageBoyWeight.add(new Float(63.5));
|
||||
|
||||
averageBoyWeight.add(new Float(67.2));
|
||||
averageBoyWeight.add(new Float(70.4));
|
||||
averageBoyWeight.add(new Float(71.4));
|
||||
averageBoyWeight.add(new Float(71.5));
|
||||
averageBoyWeight.add(new Float(71.2));
|
||||
averageBoyWeight.add(new Float(71.2));
|
||||
averageBoyWeight.add(new Float(10.6));
|
||||
averageBoyWeight.add(new Float(69.1));
|
||||
|
||||
|
||||
averageGirlWeight.add(new Float(15.9));
|
||||
averageGirlWeight.add(new Float(17.5));
|
||||
averageGirlWeight.add(new Float(19.6));
|
||||
averageGirlWeight.add(new Float(21.6));
|
||||
averageGirlWeight.add(new Float(24.7));
|
||||
averageGirlWeight.add(new Float(27.6));
|
||||
averageGirlWeight.add(new Float(31.3));
|
||||
averageGirlWeight.add(new Float(35.5));
|
||||
averageGirlWeight.add(new Float(40.6));
|
||||
averageGirlWeight.add(new Float(44.5));
|
||||
averageGirlWeight.add(new Float(18));
|
||||
averageGirlWeight.add(new Float(50.4));
|
||||
averageGirlWeight.add(new Float(51.6));
|
||||
averageGirlWeight.add(new Float(52.7));
|
||||
averageGirlWeight.add(new Float(53));
|
||||
averageGirlWeight.add(new Float(52.6));
|
||||
averageGirlWeight.add(new Float(52.4));
|
||||
|
||||
averageGirlWeight.add(new Float(53.8));
|
||||
averageGirlWeight.add(new Float(55.3));
|
||||
averageGirlWeight.add(new Float(56.8));
|
||||
averageGirlWeight.add(new Float(57.8));
|
||||
averageGirlWeight.add(new Float(59));
|
||||
averageGirlWeight.add(new Float(59.7));
|
||||
averageGirlWeight.add(new Float(60.4));
|
||||
averageGirlWeight.add(new Float(59.6));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String[] physiquesImageUrls = {
|
||||
"https://ws1.sinaimg.cn/large/0067fcixly1fvtqro2rrhj30c90eydgu.jpg",
|
||||
"https://ws1.sinaimg.cn/large/0067fcixly1fvtqro060mj30c90go755.jpg",
|
||||
"https://ws1.sinaimg.cn/large/0067fcixly1fvtqrnxrnmj30c90go3zp.jpg",
|
||||
"https://ws1.sinaimg.cn/large/0067fcixly1fvtqwvxzwjj30c90goaav.jpg",
|
||||
"https://ws1.sinaimg.cn/large/0067fcixly1fvtqrnuqb3j30c90goaar.jpg",
|
||||
"https://ws1.sinaimg.cn/large/0067fcixly1fvtqrogotyj30c90goq3u.jpg",
|
||||
"https://ws1.sinaimg.cn/large/0067fcixly1fvtqrodvjij30b70cvdlq.jpg",
|
||||
"https://ws1.sinaimg.cn/large/0067fcixly1fvtqro7ij0j30970dpafy.jpg"
|
||||
};
|
||||
|
||||
public static String[] physiquesExpressions = {
|
||||
"平素面色晦暗,皮肤偏暗或色素沉着,容易出现瘀斑,易患疼痛,口唇暗淡或紫,舌质暗有点、片状瘀斑,舌下静脉曲张。" +
|
||||
"眼眶暗黑,鼻部暗滞,发易脱落,皮肤发干,或有出血倾向、吐血,女性多见痛经、闭经、或经血中多有血块,或经色紫黑有块。",
|
||||
"手足心热,平常容易口燥咽干,鼻微干,口渴喜冷饮,大便干燥,面色潮红、有烘热感,眼睛干涩视物昏花,唇红微干," +
|
||||
"皮肤偏干、易生皱纹,眩晕耳鸣,睡眠差,小便短涩。",
|
||||
"四季怕冷,手足不温,喜热饮食,精神不振,睡眠偏多。面色柔白,目周晦暗,口唇色淡,毛发易落,大便溏稀,小便清长。",
|
||||
"面部皮肤油脂较多,多汗且黏,胸闷,痰多,面色淡黄而暗,眼胞微浮,容易困倦,口黏腻或甜,身重不爽,喜食肥甘甜黏,大便正常或不实,小便不多或微混,平素舌体胖大。",
|
||||
"平素面垢油光,容易口苦口干,身重困倦,易生痤疮,体偏胖或苍瘦,心烦懈怠,眼目红赤,大便燥结或黏滞,小便短赤,男易阴囊潮湿,女易带下增多等。",
|
||||
"性格内向不稳定,忧郁脆弱,敏感多疑,对精神刺激适应能力较差,平常忧郁面貌,神情多烦闷不乐。胸胁胀满,或走窜疼痛,多伴善太息,或嗳气呃逆,或咽间有异物感,或乳房胀痛,睡眠较差,食欲减退,惊悸怔忡,健忘,痰多,大便多干,小便正常。",
|
||||
"平常说话语音低怯,气短懒言,容易疲乏,精神不振,易出汗。面色偏黄或晄白,目光少神,唇色少华,毛发不华,容易头晕,记忆力减退,大便不成形,或便后仍觉未尽,小便正常或偏多。",
|
||||
"面色、肤色润泽,头发稠密有光泽,目光有神,鼻色明润,嗅觉、味觉良好,唇色红润,不易疲劳,精力充沛,耐受寒热,睡眠良好,食欲好,二便正常。"
|
||||
};
|
||||
|
||||
public static String[] physiquesCharacteristics = {
|
||||
"瘀血质的人,血行不畅,临床常呈现肤色晦暗、色素沉着、瘀斑、性格抑郁、健忘,舌质紫黯或有瘀点、舌下络脉紫黯或增粗,脉涩。易患痛证、血证、症瘕等。",
|
||||
"阴虚质的人,阴液亏少,耐冬不耐夏,临床常呈现口燥咽干、手足心热、喜冷饮、大便干燥,舌红少津,脉细数。一般体形偏瘦,易患虚劳、遗精、失眠等。",
|
||||
"阳虚质的人,阳气不足,临床常呈现畏寒怕冷、手足不暖、喜热饮食、精神不振,舌淡胖嫩,脉迟沉。一般性格内向,易患痰饮、肿胀、泄泻等。",
|
||||
"痰湿质的人,痰湿凝聚,临床常以形体肥胖、多汗无力、胸闷痰多、腹部肥满、口黏苔腻等痰湿表现为主要特征。",
|
||||
"湿热质的人,湿热内蕴,临床常呈现面垢油光、口苦、心烦急躁、口苦口干、身重困倦、大便粘滞不畅或燥结、小便短黄、男性易阴囊潮湿、女性带下增多,易生痤疮,舌质偏红、苔黄腻,脉滑数。",
|
||||
"气郁质的人,气机郁滞,临床常呈现精神抑郁、忧虑脆弱、多愁善感、易患脏燥、梅核气、百合病等病症。舌淡红、苔薄白,脉弦。",
|
||||
"气虚质的人,元气不足,临床常呈现疲乏气短、自汗懒言、语音低弱、精神不振、肌肉松软不实,舌淡红、边有齿痕,脉虚。易患感冒、内脏下垂、病后康复缓慢等。",
|
||||
"平和质的人,阴阳气血调和,体态适中、面色红润、精力充沛、体形匀称健壮、耐受寒热、睡眠良好、患病较少,对自然环境和社会环境适应能力较强。"
|
||||
};
|
||||
|
||||
public static String[] physiquesMentalitys = {
|
||||
"性情急躁,心情易烦,健忘。",
|
||||
"性情急躁,外向好动,活泼。",
|
||||
"性格多沉静、内向。",
|
||||
"性格偏温和,稳重,恭谦,豁达,多善于忍耐。",
|
||||
"性情多急躁易怒。",
|
||||
"性格内向不稳定,忧郁脆弱,敏感多疑。",
|
||||
"情绪不稳定,胆小,不喜欢冒险。",
|
||||
"性格随和开朗。"
|
||||
};
|
||||
public static String[] physiquesMatters = {
|
||||
"瘀血质气机失调,血行不畅,应慎食雪糕、冰淇淋、冰冻饮料等寒凉之品,以免影响气血运行。保持心情舒畅,是淤血质调理的重要环节。",
|
||||
"阴虚质体内阴液不足,药膳应慎食辛辣刺激、煎炒爆炸以及羊肉、狗肉等温热之物,以免耗伤阴液。",
|
||||
"阳虚质阳气亏虚,药膳应忌生冷寒凉,即使盛夏,也不主张多吃诸如西瓜、梨、苦瓜等寒凉生冷之物,以免损伤阳气。",
|
||||
"痰湿质痰湿偏盛,药膳应慎食肥甘油腻、厚味滋补之物,以免助湿生痰。",
|
||||
"湿热质体内湿热偏盛,药膳应慎食牛肉、狗肉、鹿肉、辣椒、姜、葱及肥甘厚味之物,以免助湿生热。",
|
||||
"气郁质气机不畅,心情抑郁,,应慎食雪糕、冰淇淋、冰冻饮料等寒凉之品,以免影响气血运行。同淤血质一样,保持心情舒畅,也是气郁质调理的重要环节。",
|
||||
"气虚质中气不足,脾胃消化功能较弱,药膳应忌过于粘腻、寒凉或难以消化之物,以免食滞难化,影响脾胃功能。",
|
||||
"平和质人阴阳气血平衡,药膳调理不可偏补、贪补,以保持人体阴阳平衡状态最为紧要。所谓“不伤不扰,顺其自然”。"
|
||||
};
|
||||
|
||||
public static String BD_API_KEY = "GQfoj7AUUhj67ocHuwvA8G5q";
|
||||
public static String BD_APP_ID = "14346167";
|
||||
public static String BD_SECRET_KEY = "EEXe6pG7QGVdrqDM8eR0S3RY2WPf4Gwn";
|
||||
public static String BD_ACCESS_TOKEN = "";
|
||||
|
||||
// public static ArrayList<ClassifyResult> testData = new ArrayList<>();
|
||||
//
|
||||
// static {
|
||||
// for (int i = 0; i < 7; i++) {
|
||||
// ClassifyResult classifyResult = new ClassifyResult();
|
||||
// classifyResult.setName("酱肉丝" + i);
|
||||
// classifyResult.setProbability(0.5 + i);
|
||||
// classifyResult.setCalorie(274 + i * 10);
|
||||
// testData.add(classifyResult);
|
||||
// }
|
||||
// }
|
||||
|
||||
public static ArrayList<String> dishPicerData = new ArrayList<>();
|
||||
|
||||
static {
|
||||
for (int i = 0; i <= 1000; i++) {
|
||||
if (i % 2 == 0) {
|
||||
dishPicerData.add(i + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<String, String> illnessMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
illnessMap.put("补肾", "肾调养食谱");
|
||||
illnessMap.put("糖尿病", "糖尿病食谱");
|
||||
illnessMap.put("结核病", "结核病食谱");
|
||||
illnessMap.put("骨质酥松症", "骨质疏松食谱");
|
||||
illnessMap.put("营养不良", "营养不良食谱");
|
||||
illnessMap.put("便秘", "便秘食谱");
|
||||
illnessMap.put("高血压", "高血压食谱");
|
||||
illnessMap.put("消化不良", "消化不良食谱");
|
||||
illnessMap.put("神经衰弱", "神经衰弱食谱");
|
||||
illnessMap.put("肾炎", "肾炎食谱");
|
||||
illnessMap.put("月经不调", "月经不调食谱");
|
||||
illnessMap.put("上火", "清热解毒食谱");
|
||||
illnessMap.put("贫血", "贫血食谱");
|
||||
illnessMap.put("多汗", "自汗盗汗食谱");
|
||||
illnessMap.put("咳嗽", "咳喘食谱");
|
||||
illnessMap.put("防暑", "防暑食谱");
|
||||
illnessMap.put("健忘", "健忘食谱");
|
||||
illnessMap.put("耳鸣", "耳鸣食谱");
|
||||
illnessMap.put("肺病", "肺调养食谱");
|
||||
illnessMap.put("冻疮", "冻疮食谱");
|
||||
illnessMap.put("利尿", "利尿食谱");
|
||||
illnessMap.put("头疼", "头痛食谱");
|
||||
illnessMap.put("口腔溃疡", "口腔溃疡食谱");
|
||||
illnessMap.put("祛痱", "祛痱食谱");
|
||||
illnessMap.put("感冒", "感冒食谱");
|
||||
illnessMap.put("前内腺疾病", "前列腺疾病食谱");
|
||||
illnessMap.put("鼻炎", "鼻炎食谱");
|
||||
illnessMap.put("跌打骨折", "跌打骨折食谱");
|
||||
}
|
||||
|
||||
public static ArrayList<String> getIllness() {
|
||||
ArrayList<String> arrayList = new ArrayList<>();
|
||||
for (String key : illnessMap.keySet()) {
|
||||
arrayList.add(key);
|
||||
}
|
||||
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";
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/10/6.
|
||||
*/
|
||||
|
||||
public class MaterialClassifier {
|
||||
|
||||
private String TAG = "face";
|
||||
final String api_url = "https://api-cn.faceplusplus.com/imagepp/beta/detectsceneandobject";
|
||||
final String api_key = "waTeK75Yeqd4YsnyaXRgik_PAJ8bUMea";
|
||||
final String api_secret = "aQpFps5C-gqncIENA5ruPTwhV6fL9Rit";
|
||||
private HashMap<String, String> map = new HashMap<>();
|
||||
private HashMap<String, byte[]> byteMap = new HashMap<>();
|
||||
|
||||
|
||||
public JSONObject plantDetect(byte[] image) {
|
||||
String str = "没有训练该样本";
|
||||
JSONObject re = null;
|
||||
map.put("api_key", api_key);
|
||||
map.put("api_secret", api_secret);
|
||||
map.put("objects", "value,confidence");
|
||||
// file = new File(path);
|
||||
byteMap.put("image_file", image);
|
||||
try {
|
||||
byte[] bacd = post(api_url, map, byteMap);
|
||||
str = new String(bacd);
|
||||
re = new JSONObject(str);
|
||||
Log.d(TAG, "plantDetect: " + re);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return re;
|
||||
}
|
||||
|
||||
private final static int CONNECT_TIME_OUT = 30000;
|
||||
private final static int READ_OUT_TIME = 50000;
|
||||
private static String boundaryString = getBoundary();
|
||||
|
||||
protected static byte[] post(String url, HashMap<String, String> map, HashMap<String, byte[]> fileMap) throws Exception {
|
||||
HttpURLConnection conne;
|
||||
URL url1 = new URL(url);
|
||||
conne = (HttpURLConnection) url1.openConnection();
|
||||
conne.setDoOutput(true);
|
||||
conne.setUseCaches(false);
|
||||
conne.setRequestMethod("POST");
|
||||
conne.setConnectTimeout(CONNECT_TIME_OUT);
|
||||
conne.setReadTimeout(READ_OUT_TIME);
|
||||
conne.setRequestProperty("accept", "*/*");
|
||||
conne.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundaryString);
|
||||
conne.setRequestProperty("connection", "Keep-Alive");
|
||||
conne.setRequestProperty("user-agent", "Mozilla/4.0 (compatible;MSIE 6.0;Windows NT 5.1;SV1)");
|
||||
DataOutputStream obos = new DataOutputStream(conne.getOutputStream());
|
||||
Iterator iter = map.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, String> entry = (Map.Entry) iter.next();
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
obos.writeBytes("--" + boundaryString + "\r\n");
|
||||
obos.writeBytes("Content-Disposition: form-data; name=\"" + key
|
||||
+ "\"\r\n");
|
||||
obos.writeBytes("\r\n");
|
||||
obos.writeBytes(value + "\r\n");
|
||||
}
|
||||
if (fileMap != null && fileMap.size() > 0) {
|
||||
Iterator fileIter = fileMap.entrySet().iterator();
|
||||
while (fileIter.hasNext()) {
|
||||
Map.Entry<String, byte[]> fileEntry = (Map.Entry<String, byte[]>) fileIter.next();
|
||||
obos.writeBytes("--" + boundaryString + "\r\n");
|
||||
obos.writeBytes("Content-Disposition: form-data; name=\"" + fileEntry.getKey()
|
||||
+ "\"; filename=\"" + encode(" ") + "\"\r\n");
|
||||
obos.writeBytes("\r\n");
|
||||
obos.write(fileEntry.getValue());
|
||||
obos.writeBytes("\r\n");
|
||||
}
|
||||
}
|
||||
obos.writeBytes("--" + boundaryString + "--" + "\r\n");
|
||||
obos.writeBytes("\r\n");
|
||||
obos.flush();
|
||||
obos.close();
|
||||
InputStream ins = null;
|
||||
int code = conne.getResponseCode();
|
||||
try {
|
||||
if (code == 200) {
|
||||
ins = conne.getInputStream();
|
||||
} else {
|
||||
ins = conne.getErrorStream();
|
||||
}
|
||||
} catch (SSLException e) {
|
||||
e.printStackTrace();
|
||||
return new byte[0];
|
||||
}
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] buff = new byte[4096];
|
||||
int len;
|
||||
while ((len = ins.read(buff)) != -1) {
|
||||
baos.write(buff, 0, len);
|
||||
}
|
||||
byte[] bytes = baos.toByteArray();
|
||||
ins.close();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private static String getBoundary() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
sb.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-".charAt(random.nextInt("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_".length())));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String encode(String value) throws Exception {
|
||||
return URLEncoder.encode(value, "UTF-8");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public class MessageUtils {
|
||||
|
||||
public static void MakeToast(String message) {
|
||||
Toast.makeText(NutritionMaster.getInstance(), message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/9/3.
|
||||
*/
|
||||
|
||||
public class PermissionUtils {
|
||||
public static final int REQUEST_CAMERA = 1056;
|
||||
|
||||
/**
|
||||
* 动态获取相机权限
|
||||
*
|
||||
* @param activity
|
||||
*/
|
||||
public static void requestCameraPermission(Activity activity) {
|
||||
if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
/**
|
||||
* 直接请求四个权限
|
||||
*/
|
||||
ActivityCompat.requestPermissions(activity,
|
||||
new String[]{
|
||||
Manifest.permission.CAMERA,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_PHONE_STATE
|
||||
}, REQUEST_CAMERA);
|
||||
// MessageUtils.MakeToast("权限赋予成功");
|
||||
} else {
|
||||
/**
|
||||
* 否则
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
|
||||
public class UiUtils {
|
||||
|
||||
|
||||
/**
|
||||
* 动态获取屏幕的宽度
|
||||
* @param context context
|
||||
* @return
|
||||
*/
|
||||
public static int getDeviceWidth(Context context){
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
return metrics.widthPixels;
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态获取屏幕的高度
|
||||
* @param context context
|
||||
* @return
|
||||
*/
|
||||
public static int getDeviceHeight(Context context){
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
return metrics.heightPixels;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将dp转为px
|
||||
* @param context context
|
||||
* @param dpValue dp值
|
||||
* @return
|
||||
*/
|
||||
public static int dp2px(Context context, float dpValue){
|
||||
float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int)(dpValue * scale +0.5f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,818 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.bean.FoodMenuLight;
|
||||
import com.example.ninefourone.nutritionmaster.bean.MyUser;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class WebUtil {
|
||||
private static WebUtil instance = new WebUtil();
|
||||
private OkHttpClient mClient = new OkHttpClient();
|
||||
|
||||
private WebUtil() {
|
||||
}
|
||||
|
||||
public static WebUtil getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取具体的菜谱信息 { "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数组
|
||||
*
|
||||
* @param count
|
||||
* @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();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机获取一定数量的小知识
|
||||
*
|
||||
* @param count
|
||||
* @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();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某食材可以做的菜 [ { "menu": "西红柿鸡蛋汤", "quantity": "适量", "material": "西红柿" }, {
|
||||
* "menu": "瘦身版红菜汤", "quantity": "4-5片", "material": "西红柿" }, { "menu":
|
||||
* "西红柿炖豆腐", "quantity": "三个", "material": "西红柿" }, ]
|
||||
*
|
||||
* @param materialName
|
||||
* @param callback
|
||||
*/
|
||||
public void getFoodMaterial(String materialName, Callback callback) {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/foodmaterial/" + materialName + "/").build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某菜谱分类对应的菜 { "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();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取职业需要的菜谱分类 { "occupation_name": "电力工程师", "menuclassification_set": [
|
||||
* "接触电离辐射人员食谱", "防癌抗癌食谱", "明目食谱", "关节炎食谱", "壮腰健肾食谱" ] }
|
||||
*/
|
||||
public void getOccupation(String occupationName, Callback callback) {
|
||||
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人份)", "土茯苓", ... ] }
|
||||
*/
|
||||
public void getPhysique(String physiqueName, Callback callback) {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/physique/" + physiqueName + "/").build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取病相关的菜谱和元素信息 传入含有病的意义的菜谱分类名称,比如青少年食谱
|
||||
* <p>
|
||||
* { "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();
|
||||
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);
|
||||
}
|
||||
|
||||
public void getUser(String username, Callback callback) {
|
||||
mClient = new OkHttpClient();
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/myuser/" + username + "/").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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注意在回调中处理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();
|
||||
*
|
||||
* 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 +
|
||||
* "/";
|
||||
* <p>
|
||||
* 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();
|
||||
* <p>
|
||||
* OkHttpClient mClient = new OkHttpClient();
|
||||
* mClient.newCall(request).enqueue(callback); }
|
||||
*/
|
||||
private static RequestBody buildUserRequestBody(MyUser user) {
|
||||
try {
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
|
||||
Class<?> c = Class.forName("model.MyUser");
|
||||
Field[] fields = c.getDeclaredFields();
|
||||
for (Field f : fields) {
|
||||
String fieldName = f.toString().substring(f.toString().lastIndexOf(".") + 1);
|
||||
f.setAccessible(true);
|
||||
Object object = f.get(user);// 获取属性的值
|
||||
if (object != null) {
|
||||
// illness属性是一个list,需要加入每个list的值,而不是list对象
|
||||
if (fieldName.equals("illness")) {
|
||||
List<String> illnessList = (List<String>) object;
|
||||
for (String ill : illnessList) {
|
||||
builder.add("illness", ill);
|
||||
}
|
||||
} else {
|
||||
builder.add(fieldName, String.valueOf(object));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
RequestBody formBody = builder.build();
|
||||
// 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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册用户注意username必须要有
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
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();
|
||||
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把user要更新的信息传入, 注意username必须要有
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
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();
|
||||
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户吃了一个菜,更新用户本周已吃摄入的营养元素的量 传入这顿饭摄入的营养量 返回当前user的最新信息,用MyUser类解析json
|
||||
*/
|
||||
public void eatenElements(String username, Map<String, Double> elements, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/eaten_menu/";
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回符合元素信息的menus
|
||||
*
|
||||
* @param elements
|
||||
*/
|
||||
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参数
|
||||
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();
|
||||
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/";
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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<>();
|
||||
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);
|
||||
// 轻量级的Menu,只有Menu的名字,卡路里,元素对象的主码id.想获取详细信息可以用getMenu方法获取
|
||||
// 这样是为了查询更快
|
||||
FoodMenuLight[] foodMenuLights = new Gson().fromJson(json, FoodMenuLight[].class);
|
||||
System.out.println(Arrays.toString(foodMenuLights));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
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);
|
||||
* 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()); } });
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
BIN
NutritionMaster/app/src/main/res/drawable-v24/ic_drawer_home.png
Normal file
|
After Width: | Height: | Size: 108 B |
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="false" android:drawable="@mipmap/camera_button" />
|
||||
<item android:state_pressed="true" android:drawable="@mipmap/camera_button_pressed" />
|
||||
</selector>
|
||||
BIN
NutritionMaster/app/src/main/res/drawable/body_bg.png
Normal file
|
After Width: | Height: | Size: 783 KiB |
BIN
NutritionMaster/app/src/main/res/drawable/camera_bg.jpg
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
NutritionMaster/app/src/main/res/drawable/food_material.jpg
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
NutritionMaster/app/src/main/res/drawable/food_test.jpg
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
NutritionMaster/app/src/main/res/drawable/foods.jpg
Normal file
|
After Width: | Height: | Size: 6.9 KiB |
BIN
NutritionMaster/app/src/main/res/drawable/friday.jpg
Normal file
|
After Width: | Height: | Size: 137 KiB |