1
This commit is contained in:
@@ -113,6 +113,5 @@ dependencies {
|
||||
implementation files('libs/YoudaoTranslateOffline.jar')
|
||||
implementation files('libs/YoudaoTranslateOnline.jar')
|
||||
|
||||
//图片压缩
|
||||
implementation 'com.github.nanchen2251:CompressHelper:1.0.5'
|
||||
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
|
||||
<application
|
||||
|
||||
android:name=".NutritionMaster"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:hardwareAccelerated="false"
|
||||
android:icon="@mipmap/ic"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:roundIcon="@mipmap/ic"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".modules.MainActivity">
|
||||
|
||||
@@ -35,7 +35,6 @@ 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;
|
||||
@@ -204,11 +203,11 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
|
||||
bos.flush();
|
||||
bos.close();
|
||||
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);
|
||||
// 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(data, Base64.DEFAULT);
|
||||
String imgParam = URLEncoder.encode(imgStr, "UTF-8");
|
||||
final String param = "image=" + imgParam + "&top_num=" + 1;
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@@ -292,28 +291,30 @@ public class ClassifierCamera extends AppCompatActivity {
|
||||
|
||||
|
||||
//把拍照结果的食材名字放到新的List:materials里面
|
||||
List<String> materials = new ArrayList<>();
|
||||
ArrayList<String> materials = new ArrayList<>();
|
||||
for (ClassifyResult classifyResult : resultList) {
|
||||
materials.add(classifyResult.getName());
|
||||
}
|
||||
WebUtil.getInstance().getMenusByMaterials(materials, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, final Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
FoodMenu[] menus = new Gson().fromJson(json, FoodMenu[].class);
|
||||
ArrayList<FoodMenu> menuList = new ArrayList<>();
|
||||
for (FoodMenu foodMenu : menus) {
|
||||
menuList.add(foodMenu);
|
||||
}
|
||||
intent.putExtra("LIST", menuList);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
// WebUtil.getInstance().getMenusByMaterials(materials, new Callback() {
|
||||
// @Override
|
||||
// public void onFailure(Call call, IOException e) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onResponse(Call call, final Response response) throws IOException {
|
||||
// String json = response.body().string();
|
||||
// FoodMenu[] menus = new Gson().fromJson(json, FoodMenu[].class);
|
||||
// ArrayList<FoodMenu> menuList = new ArrayList<>();
|
||||
// for (FoodMenu foodMenu : menus) {
|
||||
// menuList.add(foodMenu);
|
||||
// }
|
||||
// intent.putExtra("LIST", menuList);
|
||||
// startActivity(intent);
|
||||
// }
|
||||
// });
|
||||
intent.putExtra("LIST", materials);
|
||||
startActivity(intent);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -686,7 +686,6 @@ public class MainActivity extends BaseActivity {
|
||||
userIllness.add(flavourString);
|
||||
}
|
||||
NutritionMaster.flavourCount += (options1 + 1);
|
||||
// Logger.d(NutritionMaster.flavourCount);
|
||||
illAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}).build();
|
||||
|
||||
@@ -34,6 +34,7 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
RecyclerView recyclerView;
|
||||
ArrayList<ClassifyResult> classifyResults;
|
||||
ArrayList<FoodMenu> list;
|
||||
private ArrayList<String> nameList;
|
||||
private MaterialResultAdapter adapter;
|
||||
|
||||
@Override
|
||||
@@ -46,13 +47,33 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
Intent intent = getIntent();
|
||||
// classifyResults = (ArrayList<ClassifyResult>) intent.getSerializableExtra("LIST");
|
||||
// list = classifyResults.get(0).getFoodMaterial().getMenus();
|
||||
list= (ArrayList<FoodMenu>) intent.getSerializableExtra("LIST");
|
||||
nameList = (ArrayList<String>) intent.getSerializableExtra("LIST");
|
||||
adapter = new MaterialResultAdapter(list, MaterialResultActivity.this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setNestedScrollingEnabled(false);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(MaterialResultActivity.this));
|
||||
|
||||
WebUtil.getInstance().getMenusByMaterials(nameList, new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, final Response response) throws IOException {
|
||||
String json = response.body().string();
|
||||
FoodMenu[] menus = new Gson().fromJson(json, FoodMenu[].class);
|
||||
for (FoodMenu foodMenu : menus) {
|
||||
list.add(foodMenu);
|
||||
}
|
||||
recyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,6 +93,5 @@ public class MaterialResultActivity extends BaseActivity {
|
||||
ButterKnife.bind(this);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
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.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -17,13 +17,9 @@ 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 com.orhanobut.logger.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -40,6 +36,8 @@ 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<>();
|
||||
@@ -123,6 +121,13 @@ public class RecommendFragment extends BaseFragment {
|
||||
}
|
||||
});
|
||||
recyclerView.setLayoutManager(manager);
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
changeInfor();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,6 +188,9 @@ public class RecommendFragment extends BaseFragment {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter.notifyDataSetChanged();
|
||||
if (swipeRefreshLayout.isRefreshing()){
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -264,4 +272,12 @@ public class RecommendFragment extends BaseFragment {
|
||||
private boolean isDataOverCount() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改信息后修改推荐
|
||||
*/
|
||||
public void changeInfor() {
|
||||
datas.clear();
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
|
||||
BIN
app/src/main/res/drawable/ic.png
Normal file
BIN
app/src/main/res/drawable/ic.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
@@ -4,10 +4,16 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipe_refresh_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#d2e4cb"
|
||||
android:gravity="center" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#d2e4cb"
|
||||
android:gravity="center" />
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
</LinearLayout>
|
||||
BIN
app/src/main/res/mipmap-xxxhdpi/ic.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/ic.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
@@ -3,7 +3,7 @@
|
||||
buildscript {
|
||||
|
||||
|
||||
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
Reference in New Issue
Block a user