wjc
2025-05-07 5d3efa4c93dde0cde474951e5310bb72ebbf4184
app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java
@@ -1,46 +1,32 @@
package com.hdl.photovoltaic.other;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.SystemClock;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.google.gson.JsonObject;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.hdl.linkpm.sdk.user.HDLLinkPMUser;
import com.hdl.photovoltaic.HDLApp;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch;
import com.hdl.photovoltaic.enums.LowerTagType;
import com.hdl.photovoltaic.enums.UnitType;
import com.hdl.photovoltaic.utils.GlideUtils;
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
import com.hdl.sdk.link.core.callback.BaseCallBack;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Hashtable;
/**
@@ -76,14 +62,15 @@
    /**
     * @param value 值
     * @param value    值
     * @param unitType 需要转的单位(kW,kWh)
     * @return 字符串值返回
     */
    public static String convertDoubleValue(String value) {
    public static String convertDoubleValue(String value, String unitType) {
        if (TextUtils.isEmpty(value)) {
            return UnitType.noValue;
        }
        return divideByOneThousandAndFormat(value).toString();
        return divideByOneThousandAndFormat(value,unitType).toString();
    }
    /**
@@ -136,10 +123,10 @@
     * @param value 值
     * @return BigDecimal
     */
    public static BigDecimal divideByOneThousandAndFormat(String value) {
    public static BigDecimal divideByOneThousandAndFormat(String value, String unitType) {
        try {
            double doubleValue = Double.parseDouble(value);
            int mDoubleValue = doubleValue(value);
            long mDoubleValue = doubleValue(value,unitType);
            if (mDoubleValue == 0) {
                return getBigDecimal(value);
            } else {
@@ -157,17 +144,29 @@
     *
     * @param value 值
     */
    public static int doubleValue(String value) {
    public static long doubleValue(String value, String unitType) {
        try {
            double doubleValue = Double.parseDouble(value);
            if (doubleValue > 1000 && doubleValue < 1000 * 1000) {
                return 1000;
            } else if (doubleValue > 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
                return 1000 * 1000;
            } else if (doubleValue > 1000 * 1000 * 1000) {
                return 1000 * 1000 * 1000;
            if (unitType.equals(UnitType.kW)) {
                if (doubleValue > 1000 && doubleValue < 1000 * 1000) {
                    return 1000 ;
                } else if (doubleValue >= 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
                    return 1000 * 1000 ;
                } else if (doubleValue >= 1000 * 1000 * 1000) {
                    return 1000L * 1000 * 1000 ;
                } else {
                    return 1000;
                }
            } else {
                return 0;
                if (doubleValue >= 1000 && doubleValue < 1000 * 1000) {
                    return 1000;
                } else if (doubleValue >= 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
                    return 1000 * 1000;
                } else if (doubleValue >= 1000 * 1000 * 1000) {
                    return 1000 * 1000 * 1000;
                } else {
                    return 0;
                }
            }
        } catch (Exception e) {
            return 0;
@@ -175,43 +174,21 @@
    }
    /**
     * 转换单位
     *
     * @param value    值
     * @param unitType 表示是单位(功率,电量)
     */
    public static String convertUnit(String value, String unitType) {
        try {
            double doubleValue = Double.parseDouble(value);
            if (doubleValue > 1000 && doubleValue < 1000 * 1000) {
                return unitType.equals(UnitType.kW) ? UnitType.mW : UnitType.mWh;
            } else if (doubleValue > 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
                return unitType.equals(UnitType.kW) ? UnitType.gW : UnitType.gWh;
            } else if (doubleValue > 1000 * 1000 * 1000) {
                return unitType.equals(UnitType.kW) ? UnitType.tW : UnitType.tWh;
            } else {
                return unitType.equals(UnitType.kW) ? UnitType.kW : UnitType.kWh;
            }
        } catch (Exception e) {
            return unitType.equals(UnitType.kW) ? UnitType.kW : UnitType.kWh;
        }
    }
    /**
     * 转换(kWh)单位
     * 转换电量(kWh)单位
     *
     * @param value 值
     */
    public static String convertKWUnit(String value) {
    public static String convertKWHUnit(String value) {
        try {
            double doubleValue = Double.parseDouble(value);
            if (doubleValue > 1000 && doubleValue < 1000 * 1000) {
            if (doubleValue >= 1000 && doubleValue < 1000 * 1000) {
                return UnitType.mWh;
            } else if (doubleValue > 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
            } else if (doubleValue >= 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
                return UnitType.gWh;
            } else if (doubleValue > 1000 * 1000 * 1000) {
            } else if (doubleValue >= 1000 * 1000 * 1000) {
                return UnitType.tWh;
            } else {
                return UnitType.kWh;
@@ -223,18 +200,20 @@
    }
    /**
     * 转换(kW)单位
     * 转换功率(kW)单位
     *
     * @param value 值
     */
    public static String convertKWhUnit(String value) {
    public static String convertKWUnit(String value) {
        try {
            double doubleValue = Double.parseDouble(value);
            if (doubleValue > 1000 && doubleValue < 1000 * 1000) {
                return UnitType.kW;
            } else if (doubleValue >= 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
                return UnitType.mW;
            } else if (doubleValue > 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
            } else if (doubleValue >= 1000 * 1000 * 1000&&doubleValue < 1000 * 1000 * 1000*1000L) {
                return UnitType.gW;
            } else if (doubleValue > 1000 * 1000 * 1000) {
            } else if (doubleValue >= 1000 * 1000 * 1000*1000L) {
                return UnitType.tW;
            } else {
                return UnitType.kW;
@@ -246,18 +225,18 @@
    }
    /**
     * 转换(Wp)单位
     * 转换(kWp)单位
     *
     * @param value 值
     */
    public static String convertWPUnit(String value) {
    public static String convertKWPUnit(String value) {
        try {
            double doubleValue = Double.parseDouble(value);
            if (doubleValue > 1000 && doubleValue < 1000 * 1000) {
            if (doubleValue >= 1000 && doubleValue < 1000 * 1000) {
                return UnitType.MWp;
            } else if (doubleValue > 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
            } else if (doubleValue >= 1000 * 1000 && doubleValue < 1000 * 1000 * 1000) {
                return UnitType.GWp;
            } else if (doubleValue > 1000 * 1000 * 1000) {
            } else if (doubleValue >= 1000 * 1000 * 1000) {
                return UnitType.TWp;
            } else {
                return UnitType.kWp;
@@ -379,7 +358,7 @@
                public void updateDrawState(@NonNull TextPaint ds) {
                    super.updateDrawState(ds);
                    //设置字体颜色
                    ds.setColor(HDLApp.getInstance().getResources().getColor(R.color.text_E6FFFFFF, null));
                    ds.setColor(HDLApp.getInstance().getResources().getColor(R.color.text_FFACACAC, null));
                    // 去掉下划线
                    ds.setUnderlineText(isUnderline);
                }