eatenElements
This commit is contained in:
@@ -59,7 +59,8 @@
|
||||
<!-- android:name=".LoginActivity" -->
|
||||
<!-- android:label="@string/title_activity_login" /> -->
|
||||
<activity android:name=".modules.addinformation.AddInformationActivity" />
|
||||
<activity android:name=".modules.classifyresult.DishResultActivity"></activity>
|
||||
<activity android:name=".modules.classifyresult.DishResultActivity" />
|
||||
<activity android:name=".modules.classifyresult.MaterialResultActivity"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -13,6 +13,8 @@ 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;
|
||||
|
||||
@@ -44,6 +46,7 @@ public class NutritionMaster extends Application {
|
||||
super.onCreate();
|
||||
mInstance = this;
|
||||
init();
|
||||
initYouDao();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +129,8 @@ public class NutritionMaster extends Application {
|
||||
*/
|
||||
private void initOccupations() {
|
||||
|
||||
WebUtil.getAllOccupations(new Callback() {
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
webUtil.getAllOccupations(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -149,7 +153,6 @@ public class NutritionMaster extends Application {
|
||||
*/
|
||||
private void initBD() {
|
||||
ConstantUtils.BD_ACCESS_TOKEN = getAccessToken();
|
||||
// Logger.d(ConstantUtils.BD_ACCESS_TOKEN);
|
||||
}
|
||||
|
||||
|
||||
@@ -186,10 +189,8 @@ public class NutritionMaster extends Application {
|
||||
/**
|
||||
* 返回结果示例
|
||||
*/
|
||||
// System.err.println("result:" + result);
|
||||
JSONObject jsonObject = new JSONObject(result);
|
||||
String access_token = jsonObject.getString("access_token");
|
||||
// Logger.d(access_token);
|
||||
return access_token;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -197,5 +198,12 @@ public class NutritionMaster extends Application {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* YD init
|
||||
*/
|
||||
private void initYouDao() {
|
||||
YouDaoApplication.init(this, ConstantUtils.YOUDAO_APPKEY);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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,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,59 @@
|
||||
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.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.Illness;
|
||||
|
||||
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(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);
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.bean.ClassifyResult;
|
||||
import com.example.ninefourone.nutritionmaster.modules.classifyresult.DishResultActivity;
|
||||
import com.example.ninefourone.nutritionmaster.utils.CalculateUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -27,9 +28,9 @@ public class ResultListAdapter extends RecyclerView.Adapter<ResultListHolder> {
|
||||
|
||||
public ResultListAdapter(ArrayList<ClassifyResult> list, Context context) {
|
||||
super();
|
||||
mList = list;
|
||||
this.context = context;
|
||||
mList = CalculateUtils.getDishQuantity(mList, NutritionMaster.user);
|
||||
Logger.d(NutritionMaster.user);
|
||||
mList = CalculateUtils.getDishQuantity(list, NutritionMaster.user);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.example.ninefourone.nutritionmaster.modules.classifyresult.DishResult
|
||||
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
|
||||
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
|
||||
import com.github.siyamed.shapeimageview.CircularImageView;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -42,7 +43,8 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
|
||||
}
|
||||
|
||||
public void bindView(ClassifyResult classifyResult, PickerLayoutManager pickerLayoutManager,
|
||||
final DishResultActivity dishResultActivity,final int position) {
|
||||
final DishResultActivity dishResultActivity, final int position) {
|
||||
int index = (int) classifyResult.getQuantity() / 2 - 2;
|
||||
pickerLayoutManager.setChangeAlpha(true);
|
||||
pickerLayoutManager.setScaleDownBy(0.99f);
|
||||
pickerLayoutManager.setScaleDownDistance(0.8f);
|
||||
@@ -52,7 +54,7 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
|
||||
pickerAdapter = new PickerAdapter(ConstantUtils.dishPicerData, context);
|
||||
picker.setAdapter(pickerAdapter);
|
||||
picker.setNestedScrollingEnabled(false);
|
||||
picker.scrollToPosition(48);
|
||||
picker.scrollToPosition(index);
|
||||
picker.smoothScrollBy(10, 0);
|
||||
|
||||
pickerLayoutManager.setOnScrollStopListener(new PickerLayoutManager.onScrollStopListener() {
|
||||
@@ -60,7 +62,7 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
|
||||
public void selectedView(View view) {
|
||||
String text = ((TextView) view).getText().toString();
|
||||
// MessageUtils.MakeToast(text);
|
||||
dishResultActivity.refreshData(Integer.valueOf(text),position);
|
||||
dishResultActivity.refreshData(Integer.valueOf(text), position);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
setContentView(getLayoutId());
|
||||
unbinder = ButterKnife.bind(this);
|
||||
initViews(savedInstanceState);
|
||||
webUtil = new WebUtil();
|
||||
webUtil = WebUtil.getInstance();
|
||||
initToolBar();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public abstract class BaseFragment extends Fragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
initView(savedInstanceState);
|
||||
webUtil = new WebUtil();
|
||||
webUtil = WebUtil.getInstance();
|
||||
this.user = NutritionMaster.user;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,28 +20,66 @@ public class ClassifyResult implements Serializable {
|
||||
private String imgPath;
|
||||
private double probability;
|
||||
private String name;
|
||||
private double calorie;
|
||||
private Boolean has_calorie;
|
||||
private double calorie = 0;
|
||||
private Boolean has_calorie = false;
|
||||
private double quantity = -1;
|
||||
private FoodMenu foodMenu;
|
||||
private FoodMaterial foodMaterial;
|
||||
|
||||
private int flag = -1;
|
||||
public static int MATERIAL = 0;
|
||||
public static int DISH = 1;
|
||||
|
||||
public ClassifyResult(int flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public void getMenu() {
|
||||
WebUtil webUtil = new WebUtil();
|
||||
webUtil.getMenu("素红烧肉", new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
name = "-1";
|
||||
Logger.e("我们数据库没有这个菜");
|
||||
}
|
||||
if (flag == DISH) {
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
webUtil.getMenu(name, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
name = "-1";
|
||||
Logger.e("我们数据库没有这个菜");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
FoodMenu menu = new Gson().fromJson(response.body().string(), FoodMenu.class);
|
||||
foodMenu = menu;
|
||||
Logger.d(name + "|" + menu);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
FoodMenu menu = new Gson().fromJson(response.body().string(), FoodMenu.class);
|
||||
foodMenu = menu;
|
||||
Logger.d(name + "|" + menu);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Logger.e("flag 为材料的");
|
||||
}
|
||||
}
|
||||
|
||||
public void getMaterial() {
|
||||
if (flag == MATERIAL) {
|
||||
WebUtil webUtil = WebUtil.getInstance();
|
||||
webUtil.getFoodMaterial(name, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
FoodMaterial material = new Gson().fromJson(json, FoodMaterial.class);
|
||||
foodMaterial = material;
|
||||
Logger.d(name + "|" + foodMaterial);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Logger.e("flag 为菜谱的");
|
||||
}
|
||||
}
|
||||
|
||||
public FoodMaterial getFoodMaterial() {
|
||||
return foodMaterial;
|
||||
}
|
||||
|
||||
public FoodMenu getFoodMenu() {
|
||||
@@ -82,6 +120,11 @@ public class ClassifyResult implements Serializable {
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
if (flag == MATERIAL) {
|
||||
getMaterial();
|
||||
} else {
|
||||
getMenu();
|
||||
}
|
||||
}
|
||||
|
||||
public double getCalorie() {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.example.ninefourone.nutritionmaster.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class FoodMaterial {
|
||||
public class FoodMaterial implements Serializable {
|
||||
|
||||
/**
|
||||
* material_name : 西红柿
|
||||
@@ -47,7 +48,7 @@ public class FoodMaterial {
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class ElementsBean {
|
||||
public static class ElementsBean implements Serializable {
|
||||
/**
|
||||
* id : 1162
|
||||
* calorie : 20
|
||||
@@ -345,13 +346,12 @@ public class FoodMaterial {
|
||||
}
|
||||
}
|
||||
|
||||
public static class CookQuantityBean {
|
||||
public static class CookQuantityBean implements Serializable{
|
||||
/**
|
||||
* menu : 西红柿鸡蛋汤
|
||||
* quantity : 适量
|
||||
* material : 西红柿
|
||||
*/
|
||||
|
||||
private String menu;
|
||||
private String quantity;
|
||||
private String material;
|
||||
|
||||
@@ -114,7 +114,7 @@ public class FoodMenu implements Serializable {
|
||||
this.menuclassification_set = menuclassification_set;
|
||||
}
|
||||
|
||||
public static class ElementsBean {
|
||||
public static class ElementsBean implements Serializable{
|
||||
/**
|
||||
* id : 3940
|
||||
* calorie : 183
|
||||
@@ -412,7 +412,7 @@ public class FoodMenu implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public static class CookQuantityBean {
|
||||
public static class CookQuantityBean implements Serializable{
|
||||
/**
|
||||
* menu : 五香酥鱼
|
||||
* quantity : 500
|
||||
|
||||
@@ -46,7 +46,7 @@ public class MyUser {
|
||||
private Integer age;
|
||||
private Integer height;
|
||||
private Integer weight;
|
||||
private Integer bmi;
|
||||
private Integer bmi = new Integer(-1);
|
||||
private String occupation_name;
|
||||
private List<?> groups;
|
||||
private List<?> user_permissions;
|
||||
|
||||
@@ -20,10 +20,19 @@ import android.widget.TextView;
|
||||
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.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.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;
|
||||
@@ -171,27 +180,30 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
public void run() {
|
||||
String result = null;
|
||||
try {
|
||||
if (code == 0) {
|
||||
result = WebUtil.HttpPost(ConstantUtils.BD_DISH_URL,
|
||||
ConstantUtils.BD_ACCESS_TOKEN, param);
|
||||
} else if (code == 1) {
|
||||
if (code == MATERAIL_CODE) {
|
||||
MaterialClassifier materialClassifier = new MaterialClassifier();
|
||||
JSONObject jsonObject = materialClassifier.plantDetect(data);
|
||||
result = jsonObject.getJSONArray("objects")
|
||||
.getJSONObject(0).getString("value");
|
||||
translate(result);
|
||||
} else if (code == DISH_CODE) {
|
||||
result = WebUtil.HttpPost(ConstantUtils.BD_DISH_URL,
|
||||
ConstantUtils.BD_ACCESS_TOKEN, param);
|
||||
JSONObject jsonObject = new JSONObject(result);
|
||||
ClassifyResult classifyResult = new ClassifyResult(ClassifyResult.DISH);
|
||||
JSONArray resultObject = jsonObject.getJSONArray("result");
|
||||
jsonObject = resultObject.getJSONObject(0);
|
||||
classifyResult.setCalorie(jsonObject.getInt("calorie"));
|
||||
classifyResult.setHas_calorie(jsonObject.getBoolean("has_calorie"));
|
||||
classifyResult.setProbability(jsonObject.getDouble("probability"));
|
||||
classifyResult.setName(jsonObject.getString("name"));
|
||||
classifyResult.getMenu();
|
||||
resultList.add(classifyResult);
|
||||
refreshUI();
|
||||
} else {
|
||||
Logger.e("拍照code为-1");
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject(result);
|
||||
ClassifyResult classifyResult = new ClassifyResult();
|
||||
JSONArray resultObject = jsonObject.getJSONArray("result");
|
||||
jsonObject = resultObject.getJSONObject(0);
|
||||
classifyResult.setCalorie(jsonObject.getInt("calorie"));
|
||||
classifyResult.setHas_calorie(jsonObject.getBoolean("has_calorie"));
|
||||
classifyResult.setProbability(jsonObject.getDouble("probability"));
|
||||
classifyResult.setName(jsonObject.getString("name"));
|
||||
classifyResult.getMenu();
|
||||
// Logger.d(classifyResult);
|
||||
resultList.add(classifyResult);
|
||||
refreshUI();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -220,9 +232,15 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
cameraCoverLinearlayout.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case R.id.more_takephoto_ok:
|
||||
Intent intent = new Intent(ClassifierCamera.this, DishResultActivity.class);
|
||||
Intent intent;
|
||||
if (code == DISH_CODE) {
|
||||
intent = new Intent(ClassifierCamera.this, DishResultActivity.class);
|
||||
|
||||
} else {
|
||||
intent = new Intent(ClassifierCamera.this, MaterialResultActivity.class);
|
||||
|
||||
}
|
||||
intent.putExtra("LIST", resultList);
|
||||
// intent.putExtra("LIST", ConstantUtils.testData);
|
||||
startActivity(intent);
|
||||
resultList.clear();
|
||||
refreshUI();
|
||||
@@ -281,4 +299,41 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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;
|
||||
@@ -19,10 +21,14 @@ 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.camera.ClassifierCamera;
|
||||
import com.example.ninefourone.nutritionmaster.modules.addinformation.AddInformationActivity;
|
||||
@@ -111,6 +117,18 @@ public class MainActivity extends BaseActivity {
|
||||
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;
|
||||
|
||||
|
||||
private OptionsPickerView illPicker;
|
||||
private ArrayList<String> illness = ConstantUtils.getIllness();
|
||||
private ArrayList<String> userIllness = new ArrayList<>();
|
||||
private IllAdapter illAdapter;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -142,6 +160,7 @@ public class MainActivity extends BaseActivity {
|
||||
initViewPager();
|
||||
initSearchView();
|
||||
initBMB();
|
||||
initIllnessRecycler();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -343,6 +362,7 @@ public class MainActivity extends BaseActivity {
|
||||
private void initInforView() {
|
||||
|
||||
adderInfor.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||||
changeInformation.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
|
||||
if (NutritionMaster.user.getHeight() != 0) {
|
||||
showInformation.setVisibility(View.VISIBLE);
|
||||
adderInfor.setVisibility(View.INVISIBLE);
|
||||
@@ -375,7 +395,7 @@ public class MainActivity extends BaseActivity {
|
||||
*/
|
||||
|
||||
@OnClick({R.id.navigation_layout, R.id.add_information_button, R.id.information_layout,
|
||||
R.id.user_occupation_text, R.id.adder_infor})
|
||||
R.id.user_occupation_text, R.id.adder_infor,R.id.change_information})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.navigation_layout:
|
||||
@@ -393,6 +413,10 @@ public class MainActivity extends BaseActivity {
|
||||
Intent i = new Intent(MainActivity.this, AddInformationActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case R.id.change_information:
|
||||
Intent i2 = new Intent(MainActivity.this, AddInformationActivity.class);
|
||||
startActivity(i2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,4 +521,34 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化用户疾病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() {
|
||||
illPicker = new OptionsPickerBuilder(MainActivity.this, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
userIllness.add(illness.get(options1));
|
||||
illAdapter.notifyDataSetChanged();
|
||||
illButton.setBackgroundResource(0);
|
||||
}
|
||||
}).build();
|
||||
MessageUtils.MakeToast("dianjile");
|
||||
illPicker.setPicker(illness);
|
||||
illPicker.show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -158,6 +158,8 @@ public class AddInformationActivity extends BaseActivity {
|
||||
user.setAge(Integer.valueOf(ageTextView.getText().toString().split("岁")[0]));
|
||||
user.setSex(CalculateUtils.sex2int(sexTextView.getText().toString()));
|
||||
user.setOccupation_name(occupationTextView.getText().toString());
|
||||
float BMI = CalculateUtils.BMI(user.getHeight().floatValue(),user.getWeight().floatValue());
|
||||
user.setBmi(Integer.valueOf((int)BMI));
|
||||
upUser();
|
||||
MessageUtils.MakeToast("信息填写成功");
|
||||
finish();
|
||||
|
||||
@@ -208,7 +208,7 @@ public class AddPhysiqueActivity extends BaseActivity {
|
||||
*/
|
||||
private void getResult() {
|
||||
|
||||
float margin = 0.75f;
|
||||
float margin = 0.6f;
|
||||
|
||||
String code = result.substring(1);
|
||||
char[] codes = code.toCharArray();
|
||||
@@ -230,9 +230,9 @@ public class AddPhysiqueActivity extends BaseActivity {
|
||||
counter[3] += margin;
|
||||
break;
|
||||
case 3:
|
||||
counter[6]++;
|
||||
counter[7]++;
|
||||
|
||||
counter[6] += margin;
|
||||
counter[3] += margin;
|
||||
break;
|
||||
default:
|
||||
@@ -244,23 +244,22 @@ public class AddPhysiqueActivity extends BaseActivity {
|
||||
|
||||
counter[2] += margin;
|
||||
counter[3] += margin;
|
||||
counter[6] += margin;
|
||||
break;
|
||||
case 2:
|
||||
counter[4]++;
|
||||
|
||||
counter[2] += margin;
|
||||
counter[3] += margin;
|
||||
counter[6] += margin;
|
||||
break;
|
||||
case 3:
|
||||
counter[1]++;
|
||||
counter[5]++;
|
||||
counter[7]++;
|
||||
counter[6]++;
|
||||
|
||||
counter[2] += margin;
|
||||
counter[3] += margin;
|
||||
counter[6] += margin;
|
||||
|
||||
break;
|
||||
}
|
||||
switch ((int) (codes[2]) - 48) {
|
||||
@@ -294,7 +293,6 @@ public class AddPhysiqueActivity extends BaseActivity {
|
||||
switch ((int) (codes[3]) - 48) {
|
||||
case 1:
|
||||
counter[0]++;
|
||||
|
||||
counter[2]++;
|
||||
counter[5]++;
|
||||
counter[6]++;
|
||||
@@ -356,6 +354,7 @@ public class AddPhysiqueActivity extends BaseActivity {
|
||||
case 2:
|
||||
counter[1]++;
|
||||
counter[1]++;
|
||||
counter[1]++;
|
||||
|
||||
counter[0] += margin;
|
||||
counter[3] += margin;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class DishResultActivity extends BaseActivity {
|
||||
// for (int i = 0; i < results.size(); i++) {
|
||||
// Logger.d(results.get(i));
|
||||
// }
|
||||
results = ConstantUtils.testData;
|
||||
// results = ConstantUtils.testData;
|
||||
resultListAdapter = new ResultListAdapter(results, this);
|
||||
recyclerView.setAdapter(resultListAdapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
@@ -87,14 +87,14 @@ public class DishResultActivity extends BaseActivity {
|
||||
results.set(positon, temp);
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
|
||||
fatSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
|
||||
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
|
||||
calorieSum += results.get(i).getCalorie() * results.get(i).getQuantity() / 100;
|
||||
fatSum += results.get(i).getFoodMenu().getElements().getFat() * results.get(i).getQuantity() / 100;
|
||||
sugarSum += results.get(i).getFoodMenu().getElements().getCarbohydrate() * results.get(i).getQuantity() / 100;
|
||||
proteinSum += results.get(i).getFoodMenu().getElements().getProtein() * results.get(i).getQuantity() / 100;
|
||||
}
|
||||
calorie.setText((int)calorieSum + "");
|
||||
protein.setText((int)proteinSum + "");
|
||||
fat.setText((int)fatSum + "");
|
||||
suger.setText((int)sugarSum + "");
|
||||
calorie.setText((int) calorieSum + "");
|
||||
protein.setText((int) proteinSum + "");
|
||||
fat.setText((int) fatSum + "");
|
||||
suger.setText((int) sugarSum + "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.example.ninefourone.nutritionmaster.modules.classifyresult;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
|
||||
|
||||
public class MaterialResultActivity extends BaseActivity {
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_material_result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(Bundle savedInstanceState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initToolBar() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointerCaptureChanged(boolean hasCapture) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseFragment;
|
||||
import com.example.ninefourone.nutritionmaster.utils.ChartDrawer;
|
||||
@@ -45,6 +46,10 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
LineChart weightLineChart;
|
||||
@BindView(R.id.step_line_chart)
|
||||
LineChart stepLineChart;
|
||||
@BindView(R.id.calorie_text)
|
||||
TextView calorieText;
|
||||
@BindView(R.id.weight_text)
|
||||
TextView weightText;
|
||||
|
||||
private int stepCount = 0;
|
||||
private static final int REFRESH_STEP_WHAT = 0;
|
||||
@@ -180,4 +185,20 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
super.onDestroy();
|
||||
getActivity().unbindService(coon);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*/
|
||||
private void refreshUI() {
|
||||
if (NutritionMaster.user.getBmi() != -1) {
|
||||
weightText.setText(NutritionMaster.user.getWeight());
|
||||
}
|
||||
// waveLoadingView.setProgressValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
refreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,11 +133,6 @@ public class RecommendFragment extends BaseFragment {
|
||||
int flag = indexs[i % 4];
|
||||
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", flag);
|
||||
datas.add(recommendFood);
|
||||
// if (flag == 2) {
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,15 +140,10 @@ public class RecommendFragment extends BaseFragment {
|
||||
* 加载新数据
|
||||
*/
|
||||
private void addData() {
|
||||
// Logger.d("加载数据");
|
||||
for (int i = 0; i < 7; i++) {
|
||||
int flag = indexs[i % 4];
|
||||
if (flag == 2) {
|
||||
|
||||
} else {
|
||||
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", flag);
|
||||
adapter.getData().add(recommendFood);
|
||||
}
|
||||
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", flag);
|
||||
adapter.getData().add(recommendFood);
|
||||
}
|
||||
adapter.loadMoreComplete();
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ public class CalculateUtils {
|
||||
|
||||
/**
|
||||
* 性别转数字
|
||||
*
|
||||
* @param sex
|
||||
* @return
|
||||
*/
|
||||
@@ -104,14 +105,27 @@ public class CalculateUtils {
|
||||
ArrayList<ClassifyResult> classifyResultArrayList, MyUser user) {
|
||||
double calorieSum = 0;
|
||||
double[] calories = new double[classifyResultArrayList.size()];
|
||||
double[] quantitys = new double[classifyResultArrayList.size()];
|
||||
float baseQuantity = 600f;
|
||||
float factor = 1;
|
||||
|
||||
if (user.getBmi().intValue() == -1) {
|
||||
MessageUtils.MakeToast("检测到未填写个人信息,按成人标准进行计算");
|
||||
} else {
|
||||
if (user.getAge() <= 60) {
|
||||
factor = 1 - (Math.abs(user.getAge() - 30)) / 30.0f;
|
||||
} else {
|
||||
factor = 1 - (Math.abs(user.getAge() - 30)) / 70.0f;
|
||||
}
|
||||
factor = factor * (user.getBmi().intValue() / 21.0f) - (factor - 1.0f) / 5;
|
||||
Logger.d(factor);
|
||||
}
|
||||
|
||||
for (int i = 0; i < classifyResultArrayList.size(); i++) {
|
||||
calorieSum += classifyResultArrayList.get(i).getCalorie();
|
||||
calories[i] = classifyResultArrayList.get(i).getCalorie();
|
||||
}
|
||||
for (int i = 0; i < classifyResultArrayList.size(); i++) {
|
||||
classifyResultArrayList.get(i).setQuantity(calories[i] / calorieSum * baseQuantity);
|
||||
classifyResultArrayList.get(i).setQuantity(calories[i] / calorieSum * baseQuantity * factor);
|
||||
}
|
||||
return classifyResultArrayList;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ 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.
|
||||
@@ -277,25 +279,68 @@ public class ConstantUtils {
|
||||
|
||||
public static String BD_DISH_URL = "https://aip.baidubce.com/rest/2.0/image-classify/v2/dish";
|
||||
|
||||
public static ArrayList<ClassifyResult> testData = new ArrayList<>();
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 7; i++) {
|
||||
ClassifyResult classifyResult = new ClassifyResult();
|
||||
classifyResult.setName("酱肉丝" + i);
|
||||
classifyResult.setProbability(0.5 + i);
|
||||
classifyResult.setCalorie(274 + i * 10);
|
||||
testData.add(classifyResult);
|
||||
}
|
||||
}
|
||||
// public static ArrayList<ClassifyResult> testData = new ArrayList<>();
|
||||
//
|
||||
// static {
|
||||
// for (int i = 0; i < 7; i++) {
|
||||
// ClassifyResult classifyResult = new ClassifyResult();
|
||||
// classifyResult.setName("酱肉丝" + i);
|
||||
// classifyResult.setProbability(0.5 + i);
|
||||
// classifyResult.setCalorie(274 + i * 10);
|
||||
// testData.add(classifyResult);
|
||||
// }
|
||||
// }
|
||||
|
||||
public static ArrayList<String> dishPicerData = new ArrayList<>();
|
||||
|
||||
static {
|
||||
for (int i = 0; i <= 700; i++) {
|
||||
for (int i = 0; i <= 1000; i++) {
|
||||
if (i % 2 == 0) {
|
||||
dishPicerData.add(i + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
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;
|
||||
@@ -22,8 +26,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import model.FoodMenuLight;
|
||||
import model.MyUser;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.FormBody;
|
||||
@@ -36,7 +39,7 @@ public class WebUtil {
|
||||
private static WebUtil instance = new WebUtil();
|
||||
private OkHttpClient mClient = new OkHttpClient();
|
||||
|
||||
public WebUtil() {
|
||||
private WebUtil() {
|
||||
}
|
||||
|
||||
public static WebUtil getInstance() {
|
||||
@@ -69,6 +72,7 @@ public class WebUtil {
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取count个随机菜谱,在回调中解析为一个Menu数组
|
||||
*
|
||||
@@ -162,7 +166,11 @@ public class WebUtil {
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/occupation/" + occupationName + "/").build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
|
||||
public static void getAllOccupations(Callback callback) {
|
||||
OkHttpClient mClient = new OkHttpClient();
|
||||
Request request = new Request.Builder().url("http://120.77.182.38/occupation/").build();
|
||||
mClient.newCall(request).enqueue(callback);
|
||||
}
|
||||
/**
|
||||
* 获取体质需要的食材
|
||||
* {
|
||||
@@ -294,24 +302,26 @@ public class WebUtil {
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
public static void changeUserIllness(String username, String[] illnesses, Callback callback) {
|
||||
String url = "http://120.77.182.38/myuser/" + username + "/";
|
||||
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
for (String illness : illnesses) {
|
||||
builder.add("illness", illness);
|
||||
}
|
||||
RequestBody formBody = builder.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();
|
||||
@@ -322,7 +332,7 @@ public class WebUtil {
|
||||
String fieldName = f.toString().substring(f.toString().lastIndexOf(".") + 1);
|
||||
f.setAccessible(true);
|
||||
Object object = f.get(user);//获取属性的值
|
||||
if (object != null ) {
|
||||
if (object != null) {
|
||||
//illness属性是一个list,需要加入每个list的值,而不是list对象
|
||||
if (fieldName.equals("illness")) {
|
||||
List<String> illnessList = (List<String>) object;
|
||||
@@ -407,9 +417,10 @@ public class WebUtil {
|
||||
|
||||
/**
|
||||
* 返回符合元素信息的menus
|
||||
*
|
||||
* @param elements
|
||||
*/
|
||||
public void getMenusByElements(Map<String, Double> elements,Callback callback) {
|
||||
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参数
|
||||
|
||||
12
app/src/main/res/drawable/ic_ill.xml
Normal file
12
app/src/main/res/drawable/ic_ill.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<vector android:height="24dp" android:viewportHeight="1024.0"
|
||||
android:viewportWidth="1025.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#CAF0F3" android:pathData="M1016.3,565.8l-2.6,-2.6c-20.5,-35.8 -67.8,-48.6 -103.7,-28.2l-147.2,85.8c-37.1,21.8 -84.5,9 -106.2,-28.2L514.6,345.6c-21.8,-37.1 -9,-84.5 28.2,-105l134.4,-78.1c35.8,-20.5 48.6,-67.8 28.2,-103.7C684.8,23 637.4,10.2 601.6,30.7L37.1,357.1c-34.6,19.2 -46.1,64 -26.9,98.6l2.6,2.6c20.5,35.8 67.8,48.6 103.7,28.2l162.6,-93.4c37.1,-21.8 83.2,-9 105,28.2l143.4,248.3c21.8,37.1 9,84.5 -28.2,105l-148.5,85.8c-35.8,20.5 -48.6,67.8 -28.2,103.7l1.3,2.6c19.2,34.6 64,46.1 98.6,26.9L989.4,665.6c34.6,-20.5 46.1,-65.3 26.9,-99.8z"/>
|
||||
<path android:fillColor="#F6B5B8" android:pathData="M906.2,564.5l-21.8,-12.8c-3.8,-2.6 -7.7,-7.7 -7.7,-12.8v-25.6c0,-5.1 2.6,-10.2 7.7,-12.8l21.8,-12.8c3.8,-2.6 10.2,-2.6 14.1,0l21.8,12.8c3.8,2.6 7.7,7.7 7.7,12.8v25.6c0,5.1 -2.6,10.2 -7.7,12.8l-21.8,12.8c-3.8,2.6 -9,2.6 -14.1,0zM139.5,529.9l-24.3,5.1c-5.1,1.3 -10.2,0 -14.1,-3.8L84.5,512c-3.8,-3.8 -5.1,-9 -2.6,-14.1L89.6,473.6c1.3,-5.1 5.1,-9 10.2,-10.2l24.3,-5.1c5.1,-1.3 10.2,0 14.1,3.8l16.6,19.2c3.8,3.8 5.1,9 2.6,14.1l-7.7,24.3c0,5.1 -5.1,9 -10.2,10.2z"/>
|
||||
<path android:fillColor="#39BDC9" android:pathData="M311,879.4l-17.9,-7.7c-2.6,-1.3 -3.8,-3.8 -3.8,-6.4l-2.6,-19.2c0,-2.6 1.3,-5.1 2.6,-6.4l15.4,-11.5c2.6,-1.3 5.1,-1.3 7.7,-1.3l17.9,7.7c2.6,1.3 3.8,3.8 3.8,6.4l2.6,19.2c0,2.6 -1.3,5.1 -2.6,6.4l-15.4,11.5c-2.6,2.6 -5.1,2.6 -7.7,1.3z"/>
|
||||
<path android:fillColor="#F6777A" android:pathData="M802.6,561.9s0,1.3 0,0z"/>
|
||||
<path android:fillColor="#C3D2D9" android:pathData="M94.7,389.1m-14.1,0a14.1,14.1 0,1 0,28.2 0,14.1 14.1,0 1,0 -28.2,0Z"/>
|
||||
<path android:fillColor="#C3D2D9" android:pathData="M705.3,290.6L175.4,290.6c-41,0 -75.5,-34.6 -75.5,-75.5v-3.8c0,-41 34.6,-75.5 75.5,-75.5h529.9c41,0 75.5,34.6 75.5,75.5v3.8c0,42.2 -33.3,75.5 -75.5,75.5zM755.2,213.8c0,-28.2 -23,-51.2 -51.2,-51.2L176.6,162.6c-28.2,0 -51.2,23 -51.2,51.2s23,51.2 51.2,51.2L704,265c28.2,0 51.2,-23 51.2,-51.2zM354.6,409.6c-32,0 -58.9,26.9 -58.9,58.9 0,32 26.9,58.9 58.9,58.9 32,0 58.9,-26.9 58.9,-58.9 0,-33.3 -25.6,-58.9 -58.9,-58.9zM354.6,501.8c-17.9,0 -33.3,-15.4 -33.3,-33.3 0,-17.9 15.4,-33.3 33.3,-33.3 17.9,0 33.3,15.4 33.3,33.3 0,17.9 -15.4,33.3 -33.3,33.3zM641.3,409.6c-32,0 -58.9,26.9 -58.9,58.9 0,32 26.9,58.9 58.9,58.9 32,0 58.9,-26.9 58.9,-58.9 0,-33.3 -26.9,-58.9 -58.9,-58.9zM641.3,501.8c-17.9,0 -33.3,-15.4 -33.3,-33.3 0,-17.9 15.4,-33.3 33.3,-33.3 17.9,0 33.3,15.4 33.3,33.3 0,17.9 -15.4,33.3 -33.3,33.3z"/>
|
||||
<path android:fillColor="#C3D2D9" android:pathData="M716.8,285.4c56.3,67.8 87,156.2 80.6,253.4 -12.8,174.1 -154.9,314.9 -329,325.1C261.1,876.8 89.6,714.2 89.6,510.7c0,-26.9 2.6,-53.8 9,-79.4 2.6,-9 -6.4,-17.9 -15.4,-15.4 -5.1,1.3 -9,5.1 -10.2,10.2 -9,37.1 -11.5,76.8 -9,116.5C79.4,729.6 234.2,879.4 421.1,890.9c220.2,12.8 401.9,-162.6 401.9,-378.9 0,-87 -29.4,-167.7 -79.4,-231.7l-26.9,5.1z"/>
|
||||
<path android:fillColor="#C3D2D9" android:pathData="M444.2,700.2h2.6c33.3,-7.7 67.8,-11.5 102.4,-11.5 35.8,0 69.1,3.8 102.4,11.5h6.4c16.6,0 19.2,-23 2.6,-26.9 -35.8,-7.7 -71.7,-11.5 -110.1,-11.5 -37.1,0 -74.2,3.8 -110.1,11.5 -14.1,3.8 -11.5,26.9 3.8,26.9z"/>
|
||||
<path android:fillColor="#64D5BD" android:pathData="M610.6,683.5c-19.2,-19.2 -19.2,-49.9 0,-69.1l253.4,-253.4c19.2,-19.2 49.9,-19.2 69.1,0 19.2,19.2 19.2,49.9 0,69.1L679.7,683.5c-19.2,19.2 -49.9,19.2 -69.1,0z"/>
|
||||
</vector>
|
||||
@@ -18,6 +18,43 @@
|
||||
android:textColor="#fff"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0.4"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="食物名"
|
||||
android:textColor="#fff" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_weight="0.01"
|
||||
android:background="#fff"
|
||||
android:gravity="center" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="预估食用量(克)"
|
||||
android:textColor="#fff" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
@@ -74,7 +111,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="7dp"
|
||||
android:layout_toLeftOf="@+id/calorie_tag"
|
||||
android:text="大卡"
|
||||
android:textColor="#fff" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -107,7 +143,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="7dp"
|
||||
android:layout_toLeftOf="@+id/sugar_tag"
|
||||
android:text="大卡"
|
||||
android:textColor="#fff" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -158,7 +193,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="7dp"
|
||||
android:layout_toLeftOf="@+id/fat_tag"
|
||||
android:text="大卡"
|
||||
android:textColor="#fff" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -191,7 +225,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="7dp"
|
||||
android:layout_toLeftOf="@+id/protein_tag"
|
||||
android:text="大卡"
|
||||
android:textColor="#fff" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -194,6 +194,31 @@
|
||||
android:layout_marginTop="15dp"
|
||||
android:src="@drawable/ic_data_add" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/ill_recycler_view"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginRight="25dp">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ill_button"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginRight="35dp"
|
||||
android:alpha="0.3"
|
||||
android:background="@drawable/ic_ill"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
@@ -555,6 +580,13 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/change_information"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center"
|
||||
android:text="修改信息" />
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
|
||||
17
app/src/main/res/layout/activity_material_result.xml
Normal file
17
app/src/main/res/layout/activity_material_result.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="#f4f4f4"
|
||||
tools:context="com.example.ninefourone.nutritionmaster.modules.classifyresult.MaterialResultActivity">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
</LinearLayout>
|
||||
@@ -77,10 +77,10 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/calorie_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="1804"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
@@ -185,10 +185,10 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/weight_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="1804"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
|
||||
44
app/src/main/res/layout/dish_item.xml
Normal file
44
app/src/main/res/layout/dish_item.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="120dp"
|
||||
android:layout_margin="5dp"
|
||||
app:cardCornerRadius="5dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="110dp"
|
||||
android:layout_margin="5dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="16sp"
|
||||
tools:text="红烧肉" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/describle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:text="红烧肉" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
@@ -5,12 +5,13 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_margin="5dp"
|
||||
android:alpha="0.9"
|
||||
app:cardCornerRadius="10dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#fff"
|
||||
android:background="#bde2b7"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
23
app/src/main/res/layout/ill_item.xml
Normal file
23
app/src/main/res/layout/ill_item.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="2dp"
|
||||
android:alpha="0.9"
|
||||
android:background="#f44f2a"
|
||||
android:gravity="center"
|
||||
android:padding="1dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/colorPrimary"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:textSize="8sp"
|
||||
tools:text="感冒" />
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user