修改了用户热量信息界面

This commit is contained in:
zxj
2025-08-01 18:14:06 +08:00
parent 16554805ad
commit 5ae72cdf04
16 changed files with 147 additions and 84 deletions
@@ -121,7 +121,11 @@ class MainActivity : AppCompatActivity() {
)
binding.recyclerview.adapter = adapter
binding.tvFoodName.setOnClickListener {
presentation.step3()
if (presentation.currentStep == 2) {
presentation.step3()
} else {
presentation.step1()
}
}
registerDataChange()
}
@@ -95,6 +95,11 @@ class SecondaryScreenPresentation(
itemUserNutritionBinding.tvUserName.text = it.userName.maskName()
itemUserNutritionBinding.tvRecommendHeat.text =
"推荐热量:${it.recommendMin}-${it.recommendMax}"
itemUserNutritionBinding.customKcalColumn.setCustomHeight(280, true)
itemUserNutritionBinding.customFoodColumn.setCustomHeightPercent(1f, true)
itemUserNutritionBinding.customVegetableColumn.setCustomHeightPercent(0.5f, true)
itemUserNutritionBinding.customMeatColumn.setCustomHeightPercent(0f, true)
}
}
}
@@ -150,8 +155,8 @@ class SecondaryScreenPresentation(
currentStep = 1
stepChangeCallback(currentStep)
binding.tvFoodInfo.text = "菜品识别中"
binding.ivFaceBg.visibility = View.GONE
binding.flPreview.visibility = View.VISIBLE
// binding.previewView.visibility = View.VISIBLE
binding.ivImg.visibility = View.VISIBLE
binding.flFace.visibility = View.GONE
pauseCamera()
@@ -171,6 +176,7 @@ class SecondaryScreenPresentation(
resumeCamera()
binding.tvFoodInfo.text = foodInfo.foodName
binding.ivFaceBg.visibility = View.VISIBLE
binding.flPreview.visibility = View.GONE
binding.flFace.visibility = View.VISIBLE
@@ -205,9 +211,6 @@ class SecondaryScreenPresentation(
}
binding.tvFoodInfo.text = currentFood!!.foodName
binding.flPreview.visibility = View.VISIBLE
// binding.previewView.visibility = View.GONE
binding.ivImg.visibility = View.VISIBLE
GlideUtils.loadRoundCornerImage(
context,
@@ -215,7 +218,9 @@ class SecondaryScreenPresentation(
imageView = binding.ivImg,
radius = 12
)
binding.flPreview.visibility = View.VISIBLE
// binding.previewView.visibility = View.GONE
binding.ivImg.visibility = View.VISIBLE
binding.flFace.visibility = View.GONE
binding.ivFaceBg.visibility = View.GONE
binding.tvFaceTip.visibility = View.GONE
@@ -317,7 +322,7 @@ class SecondaryScreenPresentation(
recognizeViewModel.recognizeNotice.observe(activity, Observer { notice: String? ->
Timber.i("recognizeNotice observe notice = $notice")
if (currentStep == 3 && notice == "leave") {
step1()
// step1()
}
})
@@ -17,6 +17,10 @@ public class CustomImageView extends androidx.appcompat.widget.AppCompatImageVie
private String textToDraw;
private Paint mPaint;
private int mTextSize = dpToPixels(26);
/**
* 最大高度
*/
private static final int MAX_HEIGHT = 280;
private boolean isDrawText = false;
@@ -65,6 +69,10 @@ public class CustomImageView extends androidx.appcompat.widget.AppCompatImageVie
}
}
public void setCustomHeightPercent(float percent, boolean isAnimation) {
setCustomHeight((int) (percent * MAX_HEIGHT), isAnimation);
}
// 用于设置自定义高度的方法
public void setCustomHeight(int height, boolean isAnimation) {
ViewGroup.LayoutParams layoutParams = getLayoutParams();
Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

+101 -58
View File
@@ -32,7 +32,7 @@
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="40dp"
android:layout_marginTop="26dp"
android:background="#19ECE7D0"
app:layout_constraintTop_toBottomOf="@id/tv_user_name" />
@@ -42,13 +42,17 @@
android:layout_marginTop="20dp"
android:orientation="horizontal">
<RelativeLayout
<!-- 热量 -->
<androidx.constraintlayout.widget.ConstraintLayout
style="@style/takeFoodLayout"
android:layout_weight="2">
android:layout_weight="1.7">
<LinearLayout
android:id="@+id/kcalValueLayout"
style="@style/takeFoodWeightLayout"
android:layout_above="@id/divKcalView">
app:layout_constraintBottom_toTopOf="@id/divKcalView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="@+id/totalKcalTv"
@@ -58,47 +62,57 @@
<TextView
style="@style/takeFoodValueTv"
android:text="千卡"
android:textSize="@dimen/sp16" />
android:textSize="@dimen/sp11" />
</LinearLayout>
<View
android:id="@+id/divKcalView"
android:layout_width="1dp"
android:layout_height="@dimen/dp28"
android:layout_above="@id/customKcalColumn"
android:layout_centerHorizontal="true" />
android:layout_height="@dimen/dp16"
app:layout_constraintBottom_toTopOf="@id/customKcalColumn"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<com.sw.dualscreen.view.CustomImageView
android:id="@+id/customKcalColumn"
android:layout_width="@dimen/dp130"
android:layout_height="100dp"
android:layout_above="@id/imgKcal"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-36dp"
android:layout_width="@dimen/dp87"
android:layout_height="10dp"
android:layout_marginBottom="6dp"
android:scaleType="fitXY"
android:src="@drawable/ic_cylinder_red_big" />
android:src="@drawable/img_big_red_column"
app:layout_constraintBottom_toBottomOf="@id/imgKcal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ImageView
android:id="@+id/imgKcal"
android:layout_width="@dimen/dp160"
android:layout_height="@dimen/dp66"
android:layout_above="@id/kcalTv"
android:layout_centerHorizontal="true"
android:layout_width="@dimen/dp107"
android:layout_height="@dimen/dp44"
android:scaleType="fitXY"
android:src="@drawable/ic_heat" />
android:src="@drawable/ic_heat"
app:layout_constraintBottom_toTopOf="@id/kcalTv"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/kcalTv"
style="@style/takeFoodNameTv"
android:text="热量" />
android:text="热量"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout style="@style/takeFoodLayout">
<!-- 主食 -->
<androidx.constraintlayout.widget.ConstraintLayout style="@style/takeFoodLayout">
<LinearLayout
android:id="@+id/foodValueLayout"
style="@style/takeFoodWeightLayout"
android:layout_above="@id/divTotalFoodView">
app:layout_constraintBottom_toTopOf="@id/divTotalFoodView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="@+id/totalFoodTv"
@@ -108,40 +122,50 @@
<TextView
style="@style/takeFoodValueTv"
android:text="克"
android:textSize="@dimen/sp16" />
android:textSize="@dimen/sp11" />
</LinearLayout>
<View
android:id="@+id/divTotalFoodView"
android:layout_width="1dp"
android:layout_height="@dimen/dp28"
android:layout_above="@id/customFoodColumn"
android:layout_centerHorizontal="true" />
android:layout_height="@dimen/dp16"
app:layout_constraintBottom_toTopOf="@id/customFoodColumn"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<com.sw.dualscreen.view.CustomImageView
android:id="@+id/customFoodColumn"
style="@style/takeFoodCustomColumn"
android:layout_above="@id/imgFood" />
app:layout_constraintBottom_toBottomOf="@id/imgFood"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ImageView
android:id="@+id/imgFood"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:scaleType="fitXY"
android:layout_above="@id/foodTv"
android:src="@drawable/ic_staple_food" />
style="@style/takeFoodImg"
android:src="@drawable/ic_staple_food"
app:layout_constraintBottom_toTopOf="@id/foodTv"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/foodTv"
style="@style/takeFoodNameTv"
android:text="主食" />
</RelativeLayout>
android:text="主食"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout style="@style/takeFoodLayout">
<!-- 果蔬 -->
<androidx.constraintlayout.widget.ConstraintLayout style="@style/takeFoodLayout">
<LinearLayout
android:id="@+id/vegetableValueLayout"
style="@style/takeFoodWeightLayout"
android:layout_above="@id/divVegetableView">
app:layout_constraintBottom_toTopOf="@id/divVegetableView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="@+id/totalVegetableTv"
@@ -151,38 +175,50 @@
<TextView
style="@style/takeFoodValueTv"
android:text="克"
android:textSize="@dimen/sp16" />
android:textSize="@dimen/sp11" />
</LinearLayout>
<View
android:id="@+id/divVegetableView"
android:layout_width="1dp"
android:layout_height="@dimen/dp28"
android:layout_above="@id/customVegetableColumn"
android:layout_centerHorizontal="true" />
android:layout_height="@dimen/dp16"
app:layout_constraintBottom_toTopOf="@id/customVegetableColumn"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<com.sw.dualscreen.view.CustomImageView
android:id="@+id/customVegetableColumn"
style="@style/takeFoodCustomColumn"
android:layout_above="@id/imgVegetable" />
app:layout_constraintBottom_toBottomOf="@id/imgVegetable"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ImageView
android:id="@+id/imgVegetable"
style="@style/takeFoodImg"
android:layout_above="@id/vegetableTv"
android:src="@drawable/ic_fruits_vegetables" />
android:src="@drawable/ic_fruits_vegetables"
app:layout_constraintBottom_toTopOf="@id/vegetableTv"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/vegetableTv"
style="@style/takeFoodNameTv"
android:text="果蔬" />
</RelativeLayout>
android:text="果蔬"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout style="@style/takeFoodLayout">
<!-- 蛋肉 -->
<androidx.constraintlayout.widget.ConstraintLayout style="@style/takeFoodLayout">
<LinearLayout
android:id="@+id/meatValueLayout"
style="@style/takeFoodWeightLayout"
android:layout_above="@id/divMeatView">
app:layout_constraintBottom_toTopOf="@id/divMeatView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="@+id/totalMeatTv"
@@ -192,33 +228,40 @@
<TextView
style="@style/takeFoodValueTv"
android:text="克"
android:textSize="@dimen/sp16" />
android:textSize="@dimen/sp11" />
</LinearLayout>
<View
android:id="@+id/divMeatView"
android:layout_width="1dp"
android:layout_height="@dimen/dp28"
android:layout_above="@id/customMeatColumn"
android:layout_centerHorizontal="true" />
android:layout_height="@dimen/dp16"
app:layout_constraintBottom_toTopOf="@id/customMeatColumn"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<com.sw.dualscreen.view.CustomImageView
android:id="@+id/customMeatColumn"
style="@style/takeFoodCustomColumn"
android:layout_above="@id/imgMeat" />
app:layout_constraintBottom_toBottomOf="@id/imgMeat"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ImageView
android:id="@+id/imgMeat"
style="@style/takeFoodImg"
android:layout_above="@id/meatTv"
android:src="@drawable/ic_meat_eggs" />
android:src="@drawable/ic_meat_eggs"
app:layout_constraintBottom_toTopOf="@id/meatTv"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/meatTv"
style="@style/takeFoodNameTv"
android:text="蛋肉" />
</RelativeLayout>
android:text="蛋肉"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
+1 -1
View File
@@ -49,7 +49,7 @@
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="top|center_horizontal"
android:background="@drawable/ic_cylinder_red_small" />
android:background="@drawable/img_red_column" />
<!-- 底部火焰图片(覆盖圆柱底部) -->
<ImageView
android:id="@+id/bottomImage"
+7 -7
View File
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="bottom_sheet_height">1000dp</dimen>
<dimen name="sp16">16sp</dimen>
<dimen name="sp30">30sp</dimen>
<dimen name="dp28">28dp</dimen>
<dimen name="dp120">120dp</dimen>
<dimen name="dp130">130dp</dimen>
<dimen name="dp160">160dp</dimen>
<dimen name="dp66">66dp</dimen>
<dimen name="sp11">11sp</dimen>
<dimen name="sp20">20sp</dimen>
<dimen name="dp16">16dp</dimen>
<dimen name="dp80">80dp</dimen>
<dimen name="dp87">87dp</dimen>
<dimen name="dp107">107dp</dimen>
<dimen name="dp44">44dp</dimen>
<dimen name="dp53">53dp</dimen>
</resources>
+12 -11
View File
@@ -79,40 +79,41 @@
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:gravity">bottom</item>
<item name="android:layout_marginBottom">20dp</item>
<!-- <item name="android:layout_marginBottom">20dp</item>-->
<item name="android:orientation">horizontal</item>
</style>
<style name="takeFoodValueTv">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">@dimen/sp30</item>
<item name="android:textSize">@dimen/sp20</item>
<item name="android:textColor">#F0E6DC</item>
</style>
<style name="takeFoodCustomColumn">
<item name="android:layout_width">@dimen/dp80</item>
<item name="android:layout_height">100dp</item>
<item name="android:layout_width">@dimen/dp53</item>
<item name="android:layout_height">10dp</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:layout_marginBottom">-36dp</item>
<!-- <item name="android:layout_marginBottom">-36dp</item>-->
<item name="android:scaleType">fitXY</item>
<item name="android:src">@drawable/ic_cylinder_green_big</item>
<item name="android:layout_marginBottom">6dp</item>
<item name="android:src">@drawable/img_green_column</item>
</style>
<style name="takeFoodImg">
<item name="android:layout_width">@dimen/dp120</item>
<item name="android:layout_height">@dimen/dp66</item>
<item name="android:layout_width">@dimen/dp80</item>
<item name="android:layout_height">@dimen/dp44</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:scaleType">fitXY</item>
</style>
<style name="takeFoodNameTv">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_height">36dp</item>
<item name="android:gravity">bottom</item>
<item name="android:textColor">#F0E6DC</item>
<item name="android:textSize">@dimen/sp30</item>
<item name="android:textSize">@dimen/sp20</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_marginTop">50dp</item>
<item name="android:layout_centerHorizontal">true</item>
</style>
</resources>
@@ -13,5 +13,7 @@ public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
int i1 = (int) (0.5f * 280);
System.err.println("");
}
}