1
This commit is contained in:
@@ -112,4 +112,7 @@ dependencies {
|
||||
implementation files('libs/YoudaoCnDictOffline.jar')
|
||||
implementation files('libs/YoudaoTranslateOffline.jar')
|
||||
implementation files('libs/YoudaoTranslateOnline.jar')
|
||||
|
||||
//图片压缩
|
||||
implementation 'com.github.nanchen2251:CompressHelper:1.0.5'
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
@@ -33,6 +35,7 @@ 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.nanchen.compresshelper.CompressHelper;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.youdao.sdk.app.Language;
|
||||
import com.youdao.sdk.app.LanguageUtils;
|
||||
@@ -46,6 +49,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -184,6 +188,7 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
* 拍照回调
|
||||
*/
|
||||
private Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
|
||||
@RequiresApi(api = Build.VERSION_CODES.FROYO)
|
||||
@Override
|
||||
public void onPictureTaken(final byte[] data, Camera camera) {
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
||||
@@ -199,8 +204,11 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
|
||||
bos.flush();
|
||||
bos.close();
|
||||
|
||||
String imgStr = Base64.encodeToString(data, Base64.DEFAULT);
|
||||
bitmap = CompressHelper.getDefault(getApplicationContext()).compressToBitmap(file);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
|
||||
byte[] dat = baos.toByteArray();
|
||||
String imgStr = Base64.encodeToString(dat, Base64.DEFAULT);
|
||||
String imgParam = URLEncoder.encode(imgStr, "UTF-8");
|
||||
final String param = "image=" + imgParam + "&top_num=" + 1;
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
||||
@@ -130,6 +130,20 @@ public class MainActivity extends BaseActivity {
|
||||
LinearLayout illButton;
|
||||
@BindView(R.id.change_information)
|
||||
TextView changeInformation;
|
||||
@BindView(R.id.add_flavour_button)
|
||||
ImageView addFlavourButton;
|
||||
@BindView(R.id.bmi_self)
|
||||
TextView bmiSelf;
|
||||
@BindView(R.id.bmi_standard)
|
||||
TextView bmiStandard;
|
||||
@BindView(R.id.height_self)
|
||||
TextView heightSelf;
|
||||
@BindView(R.id.height_standard)
|
||||
TextView heightStandard;
|
||||
@BindView(R.id.weight_self)
|
||||
TextView weightSelf;
|
||||
@BindView(R.id.weight_standard)
|
||||
TextView weightStandard;
|
||||
|
||||
|
||||
private OptionsPickerView illPicker;
|
||||
@@ -511,21 +525,24 @@ public class MainActivity extends BaseActivity {
|
||||
bmiBar.setSecondaryProgress(bmiAverage);
|
||||
bmiBar.setProgress(bmiSelf);
|
||||
} else {
|
||||
changeColor("bmi");
|
||||
bmiBar.setMax(100);
|
||||
bmiBar.setSecondaryProgress(bmiSelf);
|
||||
bmiBar.setProgress(bmiAverage);
|
||||
bmiBar.setProgressColor(getColor(R.color.color_bar_deeper));
|
||||
bmiBar.setSecondaryProgressColor(getColor(R.color.color_bar_self));
|
||||
}
|
||||
|
||||
// NutritionMaster.user.setBmi(bmiSelf);
|
||||
|
||||
float heightAverage = averageHeight / maxHeight * 100.0f;
|
||||
float heightSelf = height / maxHeight * 100.0f;
|
||||
if (heightAverage > heightSelf) {
|
||||
|
||||
heightBar.setMax(100);
|
||||
heightBar.setSecondaryProgress(heightAverage);
|
||||
heightBar.setProgress(heightSelf);
|
||||
} else {
|
||||
changeColor("height");
|
||||
heightBar.setMax(100);
|
||||
heightBar.setSecondaryProgress(heightSelf);
|
||||
heightBar.setProgress(heightAverage);
|
||||
@@ -537,10 +554,12 @@ public class MainActivity extends BaseActivity {
|
||||
float weightAverage = averageWeight / maxWeight * 100.0f;
|
||||
float weightSelf = weight / maxWeight * 100.0f;
|
||||
if (weightAverage > weightSelf) {
|
||||
|
||||
weightBar.setMax(100);
|
||||
weightBar.setSecondaryProgress(weightAverage);
|
||||
weightBar.setProgress(weightSelf);
|
||||
} else {
|
||||
changeColor("weight");
|
||||
weightBar.setMax(100);
|
||||
weightBar.setSecondaryProgress(weightSelf);
|
||||
weightBar.setProgress(weightAverage);
|
||||
@@ -556,6 +575,23 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换bar的颜色
|
||||
*/
|
||||
@SuppressLint("ResourceAsColor")
|
||||
private void changeColor(String flag) {
|
||||
if (flag.equals("bmi")) {
|
||||
bmiSelf.setBackgroundColor(R.color.color_bar_deeper);
|
||||
bmiStandard.setBackgroundColor(R.color.color_bar_self);
|
||||
} else if (flag.equals("height")) {
|
||||
heightBar.setBackgroundColor(R.color.color_bar_deeper);
|
||||
heightStandard.setBackgroundColor(R.color.color_bar_self);
|
||||
} else if (flag.equals("weight")) {
|
||||
weightSelf.setBackgroundColor(R.color.color_bar_deeper);
|
||||
weightStandard.setBackgroundColor(R.color.color_bar_self);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化用户疾病list
|
||||
@@ -633,7 +669,13 @@ public class MainActivity extends BaseActivity {
|
||||
illPicker.show();
|
||||
}
|
||||
});
|
||||
// }
|
||||
|
||||
addFlavourButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -134,61 +134,61 @@ public class RecommendFragment extends BaseFragment {
|
||||
protected void loadData() {
|
||||
super.loadData();
|
||||
// if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
getWebUtil().getRandomMenus(20, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
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++;
|
||||
}
|
||||
@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();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取小知识
|
||||
*/
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -197,62 +197,62 @@ public class RecommendFragment extends BaseFragment {
|
||||
*/
|
||||
private void addData() {
|
||||
// if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
getWebUtil().getRandomMenus(20, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
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++;
|
||||
}
|
||||
@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();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取小知识
|
||||
*/
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ConstantUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 全国平均体重 index 0 对应 3岁
|
||||
* 全国平均身高 index 0 对应 3岁
|
||||
*/
|
||||
public static ArrayList<Float> averageBoyHeight = new ArrayList<>();
|
||||
|
||||
|
||||
6
app/src/main/res/drawable/ic_flavour.xml
Normal file
6
app/src/main/res/drawable/ic_flavour.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<vector android:height="24dp" android:viewportHeight="1024.0"
|
||||
android:viewportWidth="1024.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#ffffff" android:pathData="M900.3,220.6c-8.6,0 -17.2,-3.5 -23.6,-10.4 -84.6,-93 -205.2,-146.2 -330.8,-146.2 -123.7,0 -239,49.4 -324.2,139.1 -12.1,12.7 -32.2,13.1 -44.9,1 -12.7,-11.9 -13.1,-31.9 -1,-44.6 47.3,-49.6 102.8,-88.7 165.3,-116.1C405.9,15 474.9,0.4 546,0.4c73.1,0 143.8,15.2 209.9,45.1 63.9,28.9 120.4,69.8 167.7,121.9 11.9,12.9 10.9,33 -2,44.9 -5.9,5.5 -13.7,8.4 -21.3,8.4zM900.3,220.6M546,1022.2c-69,0 -135.8,-13.5 -198.9,-40.1 -60.8,-25.8 -115.5,-62.7 -162.4,-109.6s-83.8,-101.6 -109.6,-162.4c-26.6,-63.1 -40.1,-129.8 -40.1,-198.9 0,-29.5 2.5,-59.2 7.6,-88.1 3.1,-17.2 19.5,-28.9 36.7,-25.8 17.2,3.1 28.9,19.5 25.8,36.7 -4.3,25.2 -6.6,51.2 -6.6,77.2 0,246.8 200.7,447.5 447.5,447.5 155.4,0 297.6,-78.8 379.9,-210.9 9.2,-15 28.9,-19.5 43.6,-10 15,9.2 19.5,28.9 10,43.6 -45.1,72.3 -107.9,132.7 -182.1,174.7 -76.2,43.4 -163.2,66.2 -251.5,66.2zM546,1022.2"/>
|
||||
<path android:fillColor="#ffffff" android:pathData="M956.8,789.9c-7.8,0 -15.4,-2.9 -21.5,-8.4L649.6,518.3c-11.9,-11.1 -13.7,-29.3 -3.9,-42.4L874.9,169.8c10.4,-14.1 30.3,-17 44.4,-6.3 14.1,10.4 17,30.3 6.3,44.4L713.7,491.1l264.6,243.7c12.9,11.9 13.7,31.9 1.8,44.9 -6.3,6.8 -14.7,10.2 -23.3,10.2zM956.8,789.9"/>
|
||||
<path android:fillColor="#ffffff" android:pathData="M558.5,349.4c-55.3,0 -100.6,-45.1 -100.6,-100.6 0,-55.3 45.1,-100.4 100.6,-100.4 55.3,0 100.4,45.1 100.4,100.4 0.2,55.5 -44.9,100.6 -100.4,100.6zM558.5,212c-20.5,0 -37.1,16.6 -37.1,37.1s16.6,37.1 37.1,37.1c20.5,0 37.1,-16.6 37.1,-37.1s-16.6,-37.1 -37.1,-37.1zM558.5,212"/>
|
||||
</vector>
|
||||
@@ -190,8 +190,8 @@
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ill_button"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_toLeftOf="@id/add_information_button"
|
||||
@@ -202,13 +202,22 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/add_information_button"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginRight="25dp"
|
||||
android:layout_marginRight="15dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:src="@drawable/ic_data_add" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/add_flavour_button"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_toLeftOf="@id/ill_button"
|
||||
android:layout_marginRight="15dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:src="@drawable/ic_flavour" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/ill_recycler_view"
|
||||
android:layout_width="100dp"
|
||||
@@ -369,6 +378,7 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bmi_self"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:background="@color/color_bar_self" />
|
||||
@@ -380,6 +390,7 @@
|
||||
android:textSize="5sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bmi_standard"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:background="@color/color_bar_deeper" />
|
||||
@@ -453,6 +464,7 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/height_self"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:background="@color/color_bar_self" />
|
||||
@@ -464,6 +476,7 @@
|
||||
android:textSize="5sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/height_standard"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:background="@color/color_bar_deeper" />
|
||||
@@ -537,6 +550,7 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/weight_self"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:background="@color/color_bar_self" />
|
||||
@@ -548,6 +562,7 @@
|
||||
android:textSize="5sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/weight_standard"
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:background="@color/color_bar_deeper" />
|
||||
|
||||
Reference in New Issue
Block a user