From 30859ca8f2175475d2c666353bc27f3b2ceede53 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 22 八月 2024 13:43:47 +0800
Subject: [PATCH] 2024年08月22日13:43:45

---
 app/src/main/java/com/hdl/photovoltaic/utils/AppManagerUtils.java |  140 ++++++++++++++++++++++++++--------------------
 1 files changed, 80 insertions(+), 60 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..e579bc9 100644
--- a/app/src/main/java/com/hdl/photovoltaic/utils/AppManagerUtils.java
+++ b/app/src/main/java/com/hdl/photovoltaic/utils/AppManagerUtils.java
@@ -4,18 +4,11 @@
 import android.content.Context;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.net.wifi.WifiInfo;
-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;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.Stack;
 
@@ -28,6 +21,8 @@
 public class AppManagerUtils {
 
     private static AppManagerUtils appManagerUtils;
+
+    private LoadingDialog loadingDialog;
 
     private AppManagerUtils() {
     }
@@ -104,6 +99,20 @@
     }
 
     /**
+     * 鏄惁瀛樺湪绫诲悕鐨凙ctivity
+     */
+    public boolean existsActivity(Class<?>... args) {
+        for (Activity activity : activityStack) {
+            for (Class<?> cls : args) {
+                if (activity.getClass().equals(cls)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
      * 鎸囧畾涓�涓被鍚�,浠庢寚瀹氱被鍚嶅紑濮嬬Щ闄ゅ悗闈㈡墍鏈堿ctivity
      *
      * @param className   Activity-绫诲悕(activity.getClass().getName())
@@ -146,6 +155,9 @@
      * 缁撴潫鎵�鏈堿ctivity
      */
     public void finishAllActivity() {
+        if (activityStack == null) {
+            return;
+        }
         for (int i = 0, size = activityStack.size(); i < size; i++) {
             if (null != activityStack.get(i)) {
                 Activity activity = activityStack.get(i);
@@ -165,6 +177,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 +246,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