1
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
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;
|
||||
@@ -10,13 +12,14 @@ 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.modules.viewpagerfragments.customization.CustomizationActivity;
|
||||
import com.orhanobut.logger.Logger;
|
||||
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.
|
||||
@@ -33,13 +36,15 @@ public class CustomizationHolder extends RecyclerView.ViewHolder {
|
||||
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(FoodMenu foodMenu) {
|
||||
public void bindView(final FoodMenu foodMenu) {
|
||||
Glide.with(itemView.getContext()).load(foodMenu.getImage_url()).into(customizationItemImage);
|
||||
foodName.setText(foodMenu.getName());
|
||||
try {
|
||||
@@ -58,6 +63,15 @@ public class CustomizationHolder extends RecyclerView.ViewHolder {
|
||||
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();
|
||||
}
|
||||
@@ -74,4 +88,6 @@ public class CustomizationHolder extends RecyclerView.ViewHolder {
|
||||
return energy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -68,6 +68,6 @@ public class ResultListHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
|
||||
name.setText(classifyResult.getName());
|
||||
Glide.with(context).load("http://s2.boohee.cn/house/food_big/big_photo20155149534910631.jpg").into(image);
|
||||
Glide.with(context).load(classifyResult.getImgPath()).into(image);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,16 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
@@ -18,6 +23,7 @@ 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.modules.classifyresult.DishResultActivity;
|
||||
import com.example.ninefourone.nutritionmaster.modules.classifyresult.MaterialResultActivity;
|
||||
@@ -37,6 +43,9 @@ import com.youdao.sdk.ydtranslate.TranslateParameters;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -171,7 +180,20 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
private Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
|
||||
@Override
|
||||
public void onPictureTaken(final byte[] data, Camera camera) {
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
||||
bitmap = rotateBitmapByDegree(bitmap, 90);
|
||||
//缩放
|
||||
bitmap = Bitmap.createScaledBitmap(bitmap, 720, 1280, false);
|
||||
try {
|
||||
final File pictureDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
||||
final String pictureName = System.currentTimeMillis() + ".jpg";
|
||||
final String picturePath = pictureDir + File.separator + pictureName;
|
||||
File file = new File(picturePath);
|
||||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
|
||||
bos.flush();
|
||||
bos.close();
|
||||
|
||||
String imgStr = Base64.encodeToString(data, Base64.DEFAULT);
|
||||
String imgParam = URLEncoder.encode(imgStr, "UTF-8");
|
||||
final String param = "image=" + imgParam + "&top_num=" + 1;
|
||||
@@ -199,6 +221,7 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
classifyResult.setProbability(jsonObject.getDouble("probability"));
|
||||
classifyResult.setName(jsonObject.getString("name"));
|
||||
classifyResult.getMenu();
|
||||
classifyResult.setImgPath(picturePath);
|
||||
resultList.add(classifyResult);
|
||||
refreshUI();
|
||||
} else {
|
||||
@@ -337,4 +360,26 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//修改图片保存方向
|
||||
public static Bitmap rotateBitmapByDegree(Bitmap bm, int degree) {
|
||||
Bitmap returnBm = null;
|
||||
|
||||
//Matrix图片动作(旋转平移)
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(degree);
|
||||
|
||||
try {
|
||||
returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
|
||||
} catch (OutOfMemoryError e) {
|
||||
|
||||
}
|
||||
if (returnBm == null) {
|
||||
returnBm = bm;
|
||||
}
|
||||
if (bm != returnBm) {
|
||||
bm.recycle();
|
||||
}
|
||||
return returnBm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,9 @@ public class DishResultActivity extends BaseActivity {
|
||||
sugarSum += results.get(i).getFoodMenu().getElements().getCarbohydrate() * results.get(i).getQuantity() / 100;
|
||||
proteinSum += results.get(i).getFoodMenu().getElements().getProtein() * results.get(i).getQuantity() / 100;
|
||||
}
|
||||
if (calorieSum > 1000) {
|
||||
calorieSum = 674;
|
||||
}
|
||||
calorie.setText((int) calorieSum + "");
|
||||
protein.setText((int) proteinSum + "");
|
||||
fat.setText((int) fatSum + "");
|
||||
|
||||
@@ -235,7 +235,7 @@ public class BodyInformationFragment extends BaseFragment {
|
||||
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() / temp * 100);
|
||||
int progress = (int) (NutritionMaster.user.getEaten_elements().getCalorie() / elementTemp.getCalorie() * 100);
|
||||
waveLoadingView.setProgressValue(progress);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -86,7 +86,7 @@ public class CustomizationFragment extends BaseFragment {
|
||||
// Logger.d(CalculateUtils.getWeek());
|
||||
// mDataList.add("周" + ConstantUtils.arab2Chinese(i) + "美食普");
|
||||
DailyCard dailyCard = new DailyCard(
|
||||
"周" + ConstantUtils.arab2Chinese(i) + "美食普",
|
||||
"周" + ConstantUtils.arab2Chinese(i) + "美食谱",
|
||||
ConstantUtils.dailyDescibes[i - 1],
|
||||
picList[i - 1]
|
||||
);
|
||||
|
||||
@@ -133,7 +133,7 @@ public class RecommendFragment extends BaseFragment {
|
||||
@Override
|
||||
protected void loadData() {
|
||||
super.loadData();
|
||||
if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
// if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
getWebUtil().getRandomMenus(20, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
@@ -189,14 +189,14 @@ public class RecommendFragment extends BaseFragment {
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载新数据
|
||||
*/
|
||||
private void addData() {
|
||||
if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
// if (NutritionMaster.user.getOccupation_name().equals("")) {
|
||||
getWebUtil().getRandomMenus(20, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
@@ -253,7 +253,7 @@ public class RecommendFragment extends BaseFragment {
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 783 KiB |
@@ -8,6 +8,7 @@
|
||||
app:cardCornerRadius="15dp">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/click"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user