From c7c07eaa32ca7b137b1ac028d17beee0ebcf9a0b Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期二, 26 三月 2024 15:22:15 +0800
Subject: [PATCH] 2024年03月26日15:22:09

---
 app/src/main/java/com/hdl/photovoltaic/utils/AppManagerUtils.java |  113 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 63 insertions(+), 50 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/utils/AppManagerUtils.java b/app/src/main/java/com/hdl/photovoltaic/utils/AppManagerUtils.java
index b85206e..d27b2ed 100644
--- a/app/src/main/java/com/hdl/photovoltaic/utils/AppManagerUtils.java
+++ b/app/src/main/java/com/hdl/photovoltaic/utils/AppManagerUtils.java
@@ -10,6 +10,9 @@
 import android.net.wifi.WifiManager;
 
 import com.hdl.photovoltaic.HDLApp;
+import com.hdl.photovoltaic.R;
+import com.hdl.photovoltaic.other.HdlThreadLogic;
+import com.hdl.photovoltaic.widget.LoadingDialog;
 
 import java.net.Inet4Address;
 import java.net.InetAddress;
@@ -28,6 +31,8 @@
 public class AppManagerUtils {
 
     private static AppManagerUtils appManagerUtils;
+
+    private LoadingDialog loadingDialog;
 
     private AppManagerUtils() {
     }
@@ -165,6 +170,64 @@
         return activityStack.size();
     }
 
+    /**
+     * 鑾峰彇褰撳墠鐨凙ctivity
+     *
+     * @return -
+     */
+    public Activity getLastActivity() {
+        if (activityStack.size() > 0) {
+            return activityStack.get(activityStack.size() - 1);
+        }
+        return null;
+    }
+
+
+    /**
+     * 鑾峰彇LoadingDialog
+     *
+     * @return LoadingDialog
+     */
+    public LoadingDialog getLoadingDialog() {
+        Activity activity = getLastActivity();
+        if (loadingDialog == null && activity != null) {
+            loadingDialog = new LoadingDialog(activity, R.style.Custom_Dialog);
+        }
+        return loadingDialog;
+    }
+
+    /**
+     * 寮�濮婰oading
+     */
+    public void showLoading() {
+        getLoadingDialog().start();
+    }
+
+    /**
+     * 寮�濮婰oading
+     *
+     * @param mes 鑷畾涔夋枃鏈�
+     */
+    public void showLoading(String mes) {
+        getLoadingDialog().start();
+        getLoadingDialog().setText(mes);
+    }
+
+    /**
+     * 鍋滄闅愯棌Loading
+     */
+    public void hideLoading() {
+        HdlThreadLogic.runMainThread(new Runnable() {
+            @Override
+            public void run() {
+                if (loadingDialog != null && loadingDialog.isShowing()) {
+                    loadingDialog.stop();
+                }
+            }
+        }, null, null);
+    }
+
+
 //    /**
 //     * 鍒ゆ柇褰撳墠搴旂敤鏄惁鏄痙ebug鐘舵��
 //     */
@@ -176,56 +239,6 @@
 //            return false;
 //        }
 //    }
-
-    /**
-     * 鑾峰緱IP鍦板潃锛屽垎涓轰袱绉嶆儏鍐�:
-     * 涓�锛氭槸wifi涓嬶紱
-     * 浜岋細鏄Щ鍔ㄧ綉缁滀笅锛�
-     */
-    public String getIPAddress(Context context) {
-        NetworkInfo info = ((ConnectivityManager) context
-                .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
-        if (info != null && info.isConnected()) {
-            if (info.getType() == ConnectivityManager.TYPE_MOBILE) {//褰撳墠浣跨敤2G/3G/4G缃戠粶
-                try {
-                    //Enumeration<NetworkInterface> en=NetworkInterface.getNetworkInterfaces();
-                    for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
-                        NetworkInterface intf = en.nextElement();
-                        for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
-                            InetAddress inetAddress = enumIpAddr.nextElement();
-                            if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
-                                return inetAddress.getHostAddress();
-                            }
-                        }
-                    }
-                } catch (SocketException e) {
-                    e.printStackTrace();
-                }
-            } else if (info.getType() == ConnectivityManager.TYPE_WIFI) {//褰撳墠浣跨敤鏃犵嚎缃戠粶
-                WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
-                WifiInfo wifiInfo = wifiManager.getConnectionInfo();
-                //璋冪敤鏂规硶灏唅nt杞崲涓哄湴鍧�瀛楃涓�
-                String ipAddress = intIP2StringIP(wifiInfo.getIpAddress());//寰楀埌IPV4鍦板潃
-                return ipAddress;
-            }
-        } else {
-            //褰撳墠鏃犵綉缁滆繛鎺�,璇峰湪璁剧疆涓墦寮�缃戠粶
-        }
-        return null;
-    }
-
-    /**
-     * 灏嗗緱鍒扮殑int绫诲瀷鐨処P杞崲涓篠tring绫诲瀷
-     *
-     * @param ip int绫诲瀷
-     * @return -
-     */
-    public static String intIP2StringIP(int ip) {
-        return (ip & 0xFF) + "." +
-                ((ip >> 8) & 0xFF) + "." +
-                ((ip >> 16) & 0xFF) + "." +
-                (ip >> 24 & 0xFF);
-    }
 
 
 }

--
Gitblit v1.8.0