From 5b3497ea4f05adcc6fd89f1e4b02142f1c53c97d Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Tue, 25 Oct 2022 14:55:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devcontrol/base/util/CommonUiUtil.java | 84 +++++++++++++++++++ .../devcontrol/base/util/DateFormatUtil.java | 29 +++++++ .../project/devcontrol/base/util/UiUtil.java | 18 ++++ 3 files changed, 131 insertions(+) create mode 100644 app/src/main/java/cc/niushuai/project/devcontrol/base/util/CommonUiUtil.java create mode 100644 app/src/main/java/cc/niushuai/project/devcontrol/base/util/DateFormatUtil.java diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/CommonUiUtil.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/CommonUiUtil.java new file mode 100644 index 0000000..7a13396 --- /dev/null +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/CommonUiUtil.java @@ -0,0 +1,84 @@ +package cc.niushuai.project.devcontrol.base.util; + +import android.app.Activity; + +import cc.niushuai.project.devcontrol.R; +import cc.niushuai.project.devcontrol.db.entity.Device; +import cc.niushuai.project.devcontrol.vo.DeviceInfo; + +/** + * 公共ui统一处理工具 + * + * @author niushuai233 + * @date 2022/10/25 13:57 + */ +public class CommonUiUtil { + + + /** + * 得到页面数据值并赋值为对象返回 + * + * @param activity + * @param deviceId + * @author niushuai + * @date: 2022/10/25 14:01 + * @return: {@link DeviceInfo} + */ + public static DeviceInfo getDeviceInfo(Activity activity, String deviceId) { + + DeviceInfo deviceInfo = new DeviceInfo(); + deviceInfo.setId(deviceId); + + deviceInfo.setDeviceName(UiUtil.getTextViewTextById(activity, R.id.device_add_name)); + deviceInfo.setCommandPath(UiUtil.getTextViewTextById(activity, R.id.device_add_param_program)); + deviceInfo.setCommandStatus(UiUtil.getTextViewTextById(activity, R.id.device_add_param_status)); + deviceInfo.setCommandOpen(UiUtil.getTextViewTextById(activity, R.id.device_add_param_open)); + deviceInfo.setCommandClose(UiUtil.getTextViewTextById(activity, R.id.device_add_param_close)); + deviceInfo.setRemark(UiUtil.getTextViewTextById(activity, R.id.device_add_param_remark)); + + return deviceInfo; + } + + /** + * 得到页面数据值并赋值为对象返回 + * + * @param activity + * @param deviceId + * @author niushuai + * @date: 2022/10/25 14:01 + * @return: {@link Device} + */ + public static Device getDeviceInfo(Activity activity, Long deviceId) { + + Device device = new Device(); + device.setId(deviceId); + + device.setDeviceName(UiUtil.getTextViewTextById(activity, R.id.device_add_name)); + device.setCommandPath(UiUtil.getTextViewTextById(activity, R.id.device_add_param_program)); + device.setCommandStatus(UiUtil.getTextViewTextById(activity, R.id.device_add_param_status)); + device.setCommandOpen(UiUtil.getTextViewTextById(activity, R.id.device_add_param_open)); + device.setCommandClose(UiUtil.getTextViewTextById(activity, R.id.device_add_param_close)); + device.setRemark(UiUtil.getTextViewTextById(activity, R.id.device_add_param_remark)); + + return device; + } + + /** + * 回显设备数据 + * + * @param activity 页面 + * @param device 设备信息 + * @author niushuai + * @date: 2022/10/25 14:07 + */ + public static void echoDeviceInfo(Activity activity, DeviceInfo device) { + UiUtil.setTextViewTextById(activity, R.id.device_add_name, device.getDeviceName()); + UiUtil.setTextViewTextById(activity, R.id.device_add_param_program, device.getCommandPath()); + UiUtil.setTextViewTextById(activity, R.id.device_add_param_status, device.getCommandStatus()); + UiUtil.setTextViewTextById(activity, R.id.device_add_param_open, device.getCommandOpen()); + UiUtil.setTextViewTextById(activity, R.id.device_add_param_close, device.getCommandClose()); + UiUtil.setTextViewTextById(activity, R.id.device_add_param_remark, device.getRemark()); + + UiUtil.setAppImageCompatResource(activity, R.id.device_add_select_icon, device.getIconId()); + } +} diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/DateFormatUtil.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/DateFormatUtil.java new file mode 100644 index 0000000..fc030e3 --- /dev/null +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/DateFormatUtil.java @@ -0,0 +1,29 @@ +package cc.niushuai.project.devcontrol.base.util; + +import java.util.Date; + +import cn.hutool.core.date.DateUtil; + +/** + * 对hutool的包装 + * + * @author niushuai233 + * @date 2022/10/25 14:33 + */ +public class DateFormatUtil { + + public static Date parseDateTime(CharSequence dateStr) { + if (null == dateStr) { + return null; + } + return DateUtil.parseDateTime(dateStr); + } + + public static String formatDateTime(Date date) { + if (null == date) { + return null; + } + return DateUtil.formatDateTime(date); + } + +} diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/UiUtil.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/UiUtil.java index bff2e9e..9d7d264 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/UiUtil.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/UiUtil.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Context; import android.content.res.Resources; import android.util.TypedValue; +import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -21,14 +22,31 @@ public class UiUtil { return ((TextView) activity.findViewById(id)).getText().toString(); } +// public static String getTextViewTextById(View view, int id) { +// return ((TextView) view.findViewById(id)).getText().toString(); +// } + public static void setTextViewTextById(Activity activity, int id, String text) { ((TextView) activity.findViewById(id)).setText(text); } +// public static void setTextViewTextById(View view, int id, String text) { +// ((TextView) view.findViewById(id)).setText(text); +// } + public static void setImageResource(Activity activity, int id, int resId) { ((ImageView) activity.findViewById(id)).setImageResource(resId); } + +// public static void setImageResource(View view, int id, int resId) { +// ((ImageView) view.findViewById(id)).setImageResource(resId); +// } + public static void setAppImageCompatResource(Activity activity, int id, int resId) { ((AppCompatImageView) activity.findViewById(id)).setImageResource(resId); } + +// public static void setAppImageCompatResource(View view, int id, int resId) { +// ((AppCompatImageView) view.findViewById(id)).setImageResource(resId); +// } }