mirror of
https://github.com/niushuai233/DevControl.git
synced 2024-10-27 22:43:20 +08:00
feat: 更新工具类
This commit is contained in:
parent
79f922d1df
commit
5b3497ea4f
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -21,14 +22,31 @@ public class UiUtil {
|
|||||||
return ((TextView) activity.findViewById(id)).getText().toString();
|
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) {
|
public static void setTextViewTextById(Activity activity, int id, String text) {
|
||||||
((TextView) activity.findViewById(id)).setText(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) {
|
public static void setImageResource(Activity activity, int id, int resId) {
|
||||||
((ImageView) activity.findViewById(id)).setImageResource(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) {
|
public static void setAppImageCompatResource(Activity activity, int id, int resId) {
|
||||||
((AppCompatImageView) activity.findViewById(id)).setImageResource(resId);
|
((AppCompatImageView) activity.findViewById(id)).setImageResource(resId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public static void setAppImageCompatResource(View view, int id, int resId) {
|
||||||
|
// ((AppCompatImageView) view.findViewById(id)).setImageResource(resId);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user