feat(ui): 优化通用弹窗样式并修复初始化清零逻辑
- 重构 CommonDialog 弹窗视觉效果:新增带阴影投影的背景、缩放淡入淡出动画、取消/确认按钮主次色区分 - 修复 setCancelable 调用位置错误(原写在 window.run 内不生效) - 新增弹窗按钮圆角 ripple drawable,防止涟漪溢出圆角 - InitActivity 启动时对净材秤和熟食秤执行清零操作 - PrepareCookActivity 弹窗补充内容文案 - 修正 activity_dish_sampling.xml 中 MaterialDivider 颜色属性写法
This commit is contained in:
@@ -66,16 +66,21 @@ open class CommonDialog(
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
binding = DialogCommonBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
// 弹窗不允许点击外部关闭
|
||||
setCancelable(false)
|
||||
window?.run {
|
||||
val screenWidth = context.resources.displayMetrics.widthPixels
|
||||
val isMaster = GlobalData.deviceRole == DeviceRole.MASTER
|
||||
attributes = attributes.apply {
|
||||
width = if (isMaster) (screenWidth * 0.72f).toInt() else (screenWidth * 0.60f).toInt()
|
||||
}
|
||||
// 透明背景,让 shape_dialog_bg 的阴影层正常显示
|
||||
setBackgroundDrawable(ColorDrawable())
|
||||
setCancelable(false)
|
||||
// 应用缩放+淡入淡出动画
|
||||
setWindowAnimations(com.shuwei.dish.match.R.style.CommonDialogAnimation)
|
||||
}
|
||||
val verticalMargin = if (GlobalData.deviceRole == DeviceRole.MASTER) 35.dp else 20.dp
|
||||
// 主/从设备边距微调:主设备内容区域更大,适当增加上下留白
|
||||
val verticalMargin = if (GlobalData.deviceRole == DeviceRole.MASTER) 48.dp else 36.dp
|
||||
binding.tvTitle.updateLayoutParams<LinearLayout.LayoutParams> { topMargin = verticalMargin }
|
||||
binding.tvContent.updateLayoutParams<LinearLayout.LayoutParams> { bottomMargin = verticalMargin }
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.shuwei.dish.match.base.GlobalData
|
||||
import com.shuwei.dish.match.databinding.ActivityInitBinding
|
||||
import com.shuwei.dish.match.objbox.FoodModule
|
||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||
import com.shuwei.dish.match.utils.AddressUtil
|
||||
import com.shuwei.dish.match.utils.AppUtil
|
||||
import com.shuwei.dish.match.utils.NetworkUtils
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
@@ -57,7 +58,9 @@ class InitActivity : BaseActivity() {
|
||||
WeightUtil.init()
|
||||
WeightUtil.getWeight()
|
||||
WeightUtil.startContinuousRead()
|
||||
|
||||
//对净材秤1和熟食秤2称进行清零
|
||||
WeightUtil.tareTwo(AddressUtil.ONE)
|
||||
WeightUtil.tareTwo(AddressUtil.TWO)
|
||||
initViews()
|
||||
}
|
||||
|
||||
|
||||
@@ -265,7 +265,8 @@ class PrepareCookActivity : BaseActivity() {
|
||||
|
||||
private fun showRemindDialog() {
|
||||
CommonDialog(this)
|
||||
.setTitle("温馨提示")
|
||||
.setTitle("制作提示")
|
||||
.setContent(getString(R.string.food_remind_01))
|
||||
.setNegativeButton("返回调整")
|
||||
.setPositiveButton("确认无误") { openSubmitPage() }
|
||||
.setOnDismissCallback { hideStatusBar() }
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 弹窗入场动画:从中心缩放 + 淡入 -->
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:interpolator="@android:anim/decelerate_interpolator">
|
||||
<scale
|
||||
android:fromXScale="0.85"
|
||||
android:toXScale="1.0"
|
||||
android:fromYScale="0.85"
|
||||
android:toYScale="1.0"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:duration="220" />
|
||||
<alpha
|
||||
android:fromAlpha="0.0"
|
||||
android:toAlpha="1.0"
|
||||
android:duration="220" />
|
||||
</set>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 弹窗退场动画:缩小 + 淡出 -->
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:interpolator="@android:anim/accelerate_interpolator">
|
||||
<scale
|
||||
android:fromXScale="1.0"
|
||||
android:toXScale="0.85"
|
||||
android:fromYScale="1.0"
|
||||
android:toYScale="0.85"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:duration="180" />
|
||||
<alpha
|
||||
android:fromAlpha="1.0"
|
||||
android:toAlpha="0.0"
|
||||
android:duration="180" />
|
||||
</set>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 3按钮模式底部确认按钮 ripple:左下+右下圆角裁剪 -->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/ripple_color">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners
|
||||
android:bottomLeftRadius="30dp"
|
||||
android:bottomRightRadius="30dp"
|
||||
android:topLeftRadius="0dp"
|
||||
android:topRightRadius="0dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners
|
||||
android:bottomLeftRadius="30dp"
|
||||
android:bottomRightRadius="30dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 左侧取消按钮 ripple:左下圆角裁剪 -->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/ripple_color">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners
|
||||
android:bottomLeftRadius="30dp"
|
||||
android:bottomRightRadius="0dp"
|
||||
android:topLeftRadius="0dp"
|
||||
android:topRightRadius="0dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners
|
||||
android:bottomLeftRadius="30dp"
|
||||
android:bottomRightRadius="0dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 右侧确认按钮 ripple:右下圆角裁剪 -->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/ripple_color">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners
|
||||
android:bottomLeftRadius="0dp"
|
||||
android:bottomRightRadius="30dp"
|
||||
android:topLeftRadius="0dp"
|
||||
android:topRightRadius="0dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners
|
||||
android:bottomRightRadius="30dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 弹窗背景:白色圆角 + 模拟阴影投影 -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 阴影层:偏移 + 模糊感 -->
|
||||
<item
|
||||
android:left="2dp"
|
||||
android:top="4dp"
|
||||
android:right="2dp"
|
||||
android:bottom="0dp">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#18000000" />
|
||||
<corners android:radius="30dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<!-- 主体白色背景 -->
|
||||
<item
|
||||
android:bottom="4dp">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners android:radius="30dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -117,7 +117,7 @@
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@color/gray_eb" />
|
||||
app:dividerColor="@color/gray_eb" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -184,7 +184,7 @@
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@color/gray_eb" />
|
||||
app:dividerColor="@color/gray_eb" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -1,37 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?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="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:background="@drawable/shape_dialog_bg"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- 标题 -->
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
tools:text="温馨提示"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="40dp"
|
||||
android:layout_marginTop="55dp"
|
||||
android:layout_marginTop="48dp"
|
||||
android:layout_marginEnd="40dp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/black333"
|
||||
android:textSize="36sp"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<!-- 内容 -->
|
||||
<TextView
|
||||
android:id="@+id/tvContent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="40dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginEnd="40dp"
|
||||
android:layout_marginBottom="55dp"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:gravity="center"
|
||||
android:lineSpacingMultiplier="1.4"
|
||||
android:textColor="@color/black999"
|
||||
android:textSize="26sp" />
|
||||
android:textSize="26sp"
|
||||
tools:text="这是弹窗的内容信息,请确认"/>
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
<!-- 分割线 -->
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/gray_eb" />
|
||||
@@ -40,35 +47,38 @@
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutButtonsHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_height="96dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!-- 取消按钮:灰色文字,次要操作 -->
|
||||
<TextView
|
||||
android:id="@+id/btnLeft"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/ripple_btn_left"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/ripple_effect_light2"
|
||||
android:textColor="@color/dish_green"
|
||||
android:textSize="30sp" />
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp"
|
||||
tools:text="取消" />
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/gray_eb" />
|
||||
|
||||
<!-- 确认按钮:绿色加粗,主要操作 -->
|
||||
<TextView
|
||||
android:id="@+id/btnRight"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/ripple_btn_right"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/dish_green"
|
||||
android:background="@drawable/ripple_effect_light2"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold" />
|
||||
android:textSize="28sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="确认"/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 3个按钮时显示(垂直排列,iOS风格) -->
|
||||
@@ -79,42 +89,45 @@
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<!-- 顶部按钮(取消):灰色 -->
|
||||
<TextView
|
||||
android:id="@+id/btnTop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:gravity="center"
|
||||
android:layout_height="90dp"
|
||||
android:background="@drawable/ripple_effect_light2"
|
||||
android:textColor="@color/dish_green"
|
||||
android:textSize="30sp" />
|
||||
android:gravity="center"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/gray_eb" />
|
||||
|
||||
<!-- 中间按钮(中立):绿色 -->
|
||||
<TextView
|
||||
android:id="@+id/btnMiddle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:gravity="center"
|
||||
android:layout_height="90dp"
|
||||
android:background="@drawable/ripple_effect_light2"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/dish_green"
|
||||
android:textSize="30sp" />
|
||||
android:textSize="28sp" />
|
||||
|
||||
<com.google.android.material.divider.MaterialDivider
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/gray_eb" />
|
||||
|
||||
<!-- 底部按钮(确认):绿色加粗 -->
|
||||
<TextView
|
||||
android:id="@+id/btnBottom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_height="90dp"
|
||||
android:background="@drawable/ripple_btn_bottom"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/ripple_effect_light2"
|
||||
android:textColor="@color/dish_green"
|
||||
android:textSize="30sp"
|
||||
android:textSize="28sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -52,4 +52,9 @@
|
||||
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
|
||||
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
|
||||
</style>
|
||||
<!-- 通用弹窗动画:缩放 + 淡入淡出 -->
|
||||
<style name="CommonDialogAnimation">
|
||||
<item name="android:windowEnterAnimation">@anim/dialog_in</item>
|
||||
<item name="android:windowExitAnimation">@anim/dialog_out</item>
|
||||
</style>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user