| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package com.naz.sdkdemo.weight;
- import android.text.TextUtils;
- import android.util.Log;
- import com.google.gson.Gson;
- import com.naz.sdkdemo.bean.UserDetail;
- import com.naz.sdkdemo.comm.Constants;
- import com.naz.sdkdemo.utils.SPUtils;
- import android_serialport_api.SerialPortFinder;
- /**
- * Description:
- * Author: ydd
- * Date:2020/12/7
- */
- public class UserCache extends SPUtils {
- /**
- * 保存用户详情信息
- */
- public static void saveUserInfoDetail(UserDetail userInfo) {
- setString(Constants.USERCACHEKEY, new Gson().toJson(userInfo));
- }
- /**
- * 获取用户详情信息
- */
- public static UserDetail getUserInfoDetail() {
- String str = getString(Constants.USERCACHEKEY);
- if (!TextUtils.isEmpty(str)) {
- return new Gson().fromJson(str, UserDetail.class);
- } else {
- return null;
- }
- }
- /**
- * 清除用户详情数据
- *
- * @return true is success
- */
- public static void clearUserInfoDetail() {
- remove(Constants.USERCACHEKEY);
- }
- public static void saveDeviceId(String code) {
- setString(Constants.DEVICE_CODE, code);
- }
- public static String getDeviceId() {
- String str = getString(Constants.DEVICE_CODE);
- if (!TextUtils.isEmpty(str)) {
- return str;
- } else {
- return "DV00001";
- }
- }
- public static void saveSerialInfo(String ip, int port, String name, int rate) {
- setString(Constants.IP, ip);
- setInt(Constants.PORT, port);
- setString(Constants.SERIAL_NAME, name);
- setInt(Constants.SERIAL_RATE, rate);
- }
- public static String getIP() {
- String str = getString(Constants.IP);
- if (!TextUtils.isEmpty(str)) {
- return str;
- } else {
- return "192.168.1.253";
- }
- }
- public static int getPort() {
- int value = getInt(Constants.PORT);
- if (value == -1){
- value = 1030;
- }
- return value;
- }
- public static int getSerialRate() {
- int value = getInt(Constants.SERIAL_RATE);
- if (value == -1){
- value = 19200;
- }
- return value;
- }
- public static String getSerialName() {
- SerialPortFinder finder = new SerialPortFinder();
- if (finder.getAllDevicesPath().length>0){
- for (int i = 0; i < finder.getAllDevicesPath().length; i++) {
- Log.e("------------>","---------->finder.getAllDevicesPath("+i+")="+finder.getAllDevicesPath()[i]);
- }
- Log.e("------------>","---------->finder.getAllDevicesPath()="+finder.getAllDevicesPath());
- String sName = finder.getAllDevicesPath()[0];
- return sName;
- }
- return "";
- }
- }
|