.idea/deploymentTargetDropDown.xml
New file @@ -0,0 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="deploymentTargetDropDown"> <runningDeviceTargetSelectedWithDropDown> <Target> <type value="RUNNING_DEVICE_TARGET" /> <deviceKey> <Key> <type value="SERIAL_NUMBER" /> <value value="2ffc9a07" /> </Key> </deviceKey> </Target> </runningDeviceTargetSelectedWithDropDown> <timeTargetWasSelectedWithDropDown value="2023-06-26T02:32:08.398530Z" /> </component> </project> .idea/misc.xml
@@ -4,16 +4,21 @@ <option name="filePathToZoomLevelMap"> <map> <entry key="../../../../../layout/custom_preview.xml" value="0.22314814814814815" /> <entry key="app/src/main/res/drawable/progress_small.xml" value="0.1275" /> <entry key="app/src/main/res/layout/activity_home_login.xml" value="0.10030395136778116" /> <entry key="app/src/main/res/layout/activity_my_power_station.xml" value="0.10030395136778116" /> <entry key="app/src/main/res/layout/fragment_house_list.xml" value="0.10030395136778116" /> <entry key="app/src/main/res/layout/fragment_me.xml" value="0.10030395136778116" /> <entry key="app/src/main/res/layout/frgment_house_list_line.xml" value="0.1921875" /> <entry key="app/src/main/res/layout/loading_alert.xml" value="0.1" /> <entry key="app/src/main/res/layout/loading_confirm.xml" value="0.1" /> <entry key="app/src/main/res/layout/loading_confirm_input.xml" value="0.1" /> <entry key="app/src/main/res/layout/loading_exception_log.xml" value="0.1921875" /> <entry key="app/src/main/res/layout/toolbar_top_view_44.xml" value="0.1921875" /> <entry key="app/src/main/res/layout/toolbar_top_view_52.xml" value="0.10030395136778116" /> </map> </option> </component> <component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" /> </project> app/src/main/AndroidManifest.xml
@@ -1,7 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.hdl.photovoltaic" > package="com.hdl.photovoltaic"> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" @@ -12,7 +13,10 @@ <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <application @@ -22,20 +26,19 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.PhotovoltaicDebug" > android:theme="@style/Theme.PhotovoltaicDebug"> <activity android:name=".ui.device.FastScanActivity" android:exported="false" /> <activity android:name=".ui.MyPowerStationActivity" android:exported="false" /> android:exported="false" /> <activity android:name=".ui.HomeLoginActivity" android:exported="false" /> <activity android:name=".ui.StartActivity" android:exported="true" > android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java
@@ -1,19 +1,11 @@ package com.hdl.photovoltaic.base; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.WindowManager; import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import com.hdl.photovoltaic.R; @@ -53,7 +45,7 @@ */ protected LoadingDialog getLoadingDialog() { if (loadingDialog == null && _mActivity != null) { loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_AlertDialog); loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_Dialog); } return loadingDialog; } app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java
@@ -3,11 +3,9 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.FrameLayout; import androidx.annotation.NonNull; @@ -164,7 +162,7 @@ */ protected LoadingDialog getLoadingDialog() { if (loadingDialog == null && _mActivity != null) { loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_AlertDialog); loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_Dialog); } return loadingDialog; } app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java
@@ -4,12 +4,14 @@ import android.content.Context; import android.os.Handler; import android.os.Looper; import android.util.Log; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import com.hdl.photovoltaic.enums.ShowErrorMode; import com.hdl.photovoltaic.widget.ConfirmationDialog; import com.hdl.photovoltaic.widget.ConfirmationExceptionDialog; /** * 线程逻辑 @@ -33,6 +35,7 @@ handler.post(run); } } catch (Exception e) { exception(e, showErrorMode, context); } } @@ -119,8 +122,11 @@ @Override public void Confirm() { confirmationDialog.dismiss(); String s = getStackTrace(ex); ConfirmationExceptionDialog confirmationExceptionDialog = new ConfirmationExceptionDialog(context); // String s = getStackTrace(ex); String s = Log.getStackTraceString(ex); confirmationExceptionDialog.setContent(s); confirmationExceptionDialog.show(); } }); app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -1,6 +1,7 @@ package com.hdl.photovoltaic.other; import com.google.gson.Gson; import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.uni.HDLUniMP; import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; @@ -34,7 +35,7 @@ } /** * 原生接收uni发来的数据 * 原生接收到uni发来的数据 * * @param appId -uni小程序指定的appId * @param event -uni小程序发来数据 @@ -52,9 +53,9 @@ jsonObject = new org.json.JSONObject(data.toString()); } //住宅模块 if (HDLUniMP.UNI_EVENT_HOME_CREATION.equals(event)) { if (HDLUniMP.UNI_EVENT_REPLY_HOME_LIST.equals(event)) { if (callback != null) { callback.invoke(null); uniCallbackData(null, "0", "", callback); } } HdlLogLogic.print("uni===原生接收uni发来的数据", event + "\r\n" + data); @@ -71,7 +72,9 @@ * @param jsonObject 附件数据(没有数据填null) */ public void openUniMP(String path, JSONObject jsonObject) { JSONObject json = this.createdJsonDate(jsonObject); JSONObject json = this.createdJsonDate(jsonObject, true); HdlLogLogic.print("uni===组装uni发送数据格式", json.toString()); HDLUniMPSDKManager.getInstance().openUniMP(HDLUniMP.UNI_APP_ID, path, json, HdlUniLogic.this); } @@ -87,7 +90,7 @@ HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); callBackBaseBean.setTopic(topic); callBackBaseBean.setData(body); HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.UNI_APP_ID, callBackBaseBean.getJSONObject()); HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.UNI_APP_ID, getJSONObject(callBackBaseBean)); } catch (Exception e) { HdlLogLogic.print("uni===原生主动向小程序发送通知事件", e.getMessage()); } @@ -103,22 +106,82 @@ /** * 组装uni发送数据格式 * * @param data -附件数据(没有数据填null) * @param data -附件数据(没有数据填null) * @param isTokenAndRefreshToken (true=底层默认添加token和refreshToken;false=不加) * @return JSONObject */ public JSONObject createdJsonDate(JSONObject data) { private JSONObject createdJsonDate(JSONObject data, boolean isTokenAndRefreshToken) { HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); try { if (data == null) { data = new JSONObject(); } data.put("token", UserConfigManage.getInstance().getToken()); data.put("refreshToken", UserConfigManage.getInstance().getRefreshToken()); if (isTokenAndRefreshToken) { data.put("token", UserConfigManage.getInstance().getToken()); data.put("refreshToken", UserConfigManage.getInstance().getRefreshToken()); } uniCallBackBaseBean.setData(data); return uniCallBackBaseBean.getJSONObject(); return getJSONObject(uniCallBackBaseBean); } catch (Exception e) { HdlLogLogic.print("uni===组装uni发送数据格式", e.getMessage()); } return new JSONObject(); } /** * 组装uni发送数据格式 * 回调数据给uni小程序,统一在这里处理; * * @param obj 附加数据 * @param code 状态码-成功(0)或者失败(-2) * @param msg 结果描述的信息 * @param callback 回调 */ private void uniCallbackData(Object obj, String code, String msg, DCUniMPJSCallback callback) { HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); try { uniCallBackBaseBean.setCode(code); uniCallBackBaseBean.setMes(msg); uniCallBackBaseBean.setData(obj); if (callback != null) { callback.invoke(uniCallBackBaseBean); } } catch (Exception e) { HdlLogLogic.print("uni===组装uni发送数据格式", e.getMessage()); } } /** * 获取uni发送对象 * * @param obj 附加数据 * @param code 状态码 * @param msg 结果描述的信息 */ private HDLUniMP.UniCallBackBaseBean getUniCallBackBaseBean(Object obj, String code, String msg) { HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); uniCallBackBaseBean.setCode(code); uniCallBackBaseBean.setMes(msg); uniCallBackBaseBean.setData(obj); return uniCallBackBaseBean; } /** * 当前对象转 JSONObject * * @return JSONObject */ private JSONObject getJSONObject(Object obj) { try { String json = new Gson().toJson(obj); return new JSONObject(json); } catch (Exception e) { return new JSONObject(); } } } app/src/main/java/com/hdl/photovoltaic/ui/HomeLoginActivity.java
@@ -1,6 +1,8 @@ package com.hdl.photovoltaic.ui; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; import android.text.Editable; import android.text.Spannable; @@ -15,8 +17,10 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.content.res.AppCompatResources; import com.hdl.photovoltaic.HDLApp; import com.hdl.photovoltaic.R; import com.hdl.photovoltaic.base.CustomBaseActivity; import com.hdl.photovoltaic.enums.ShowErrorMode; @@ -28,6 +32,9 @@ import com.hdl.photovoltaic.listener.CloudCallBeak; import com.hdl.photovoltaic.other.HdlAccountLogic; import com.hdl.photovoltaic.other.HdlThreadLogic; import com.hdl.photovoltaic.ui.device.FastScanActivity; import com.hdl.photovoltaic.utils.PermissionUtils; import com.hdl.photovoltaic.utils.WifiUtils; public class HomeLoginActivity extends CustomBaseActivity { @@ -234,13 +241,12 @@ viewBinding.homeLoginExperienceTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // requestPermissions(); // startActivity(MyPowerStationActivity.class); HdlThreadLogic.runMainThread(new Runnable() { @Override public void run() { // int s = 1 / 0; } }, _mActivity, ShowErrorMode.YES); } @@ -312,4 +318,34 @@ view.setText(spannable); } private void requestPermissions() { String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}); if (ary.length > 0) { requestPermissions(ary, PermissionUtils.STATUS_SUCCESS); } else { wifi(); } } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == PermissionUtils.STATUS_SUCCESS) { for (int i = 0; i < permissions.length; i++) { if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { wifi(); } } } } public void wifi() { WifiUtils wifiUtils = new WifiUtils(HDLApp.getInstance()); // wifiUtils.getCurrentConnectWifiInfo(); // wifiUtils.getScanResult(); wifiUtils.connectWiFi("Application", "12345678", 3); } } app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
@@ -28,7 +28,7 @@ @Override public void onBindView(Bundle savedInstanceState) { getWindow().setStatusBarColor(getColor(R.color.text_245EC3)); //初始化 initView(); //初始化界面监听器 app/src/main/java/com/hdl/photovoltaic/ui/StartActivity.java
@@ -12,6 +12,7 @@ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setStatusBarColor(getColor(R.color.text_245EC3)); setContentView(R.layout.activity_start); Intent intent = new Intent(); intent.setClass(this, HomeLoginActivity.class); app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java
@@ -73,7 +73,7 @@ @Override public void onClick(View v) { // 打开小程序页面 HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_HOME_CREATION, null); HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null); } }); //设置下拉箭头颜色 @@ -95,7 +95,7 @@ return; } HouseListBean houseListBean = houseListBeanList.get(position); String path = HDLUniMP.UNI_EVENT_HOME_CREATION + "?homeId=" + houseListBean.getHomeId(); String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseListBean.getHomeId(); HdlUniLogic.getInstance().openUniMP(path, null); } }); app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java
@@ -14,38 +14,41 @@ /*********UniMP wgt id*********/ public final static String UNI_APP_ID = "__UNI__A2E7300";//光伏wgt包小程序id /*********UniMP Event 原生和小程序交互 自定义通知事件*********/ public final static String UNI_EVENT_uniMPOnClose = "uni_MPOnClose";//自定义小程序关闭事件 public final static String UNI_EVENT_GetAppParams = "uni_GetAppParams";//获取APP应用信息 //注意:【小程序】发送到【原生】 加前缀:uni_ /*********住宅【电站】模块*********/ public final static String UNI_EVENT_REPLY_HOME_MODEL = "uni_home_model";//住宅模块 public final static String UNI_EVENT_REPLY_HOME_LIST = "list";//获取住宅【电站】列表 public final static String UNI_EVENT_REPLY_HOME_CREATION = "creation";//住宅【电站】创建 public final static String UNI_EVENT_REPLY_HOME_EDIT = "edit";//住宅【电站】编辑 public final static String UNI_EVENT_REPLY_HOME_DETAILS = "details";//住宅【电站】详情 public final static String UNI_EVENT_REPLY_Home_DEl = "del";//住宅【电站】删除 /*********设备模块*********/ public final static String UNI_EVENT_REPLY_DEVICE_MODEL = "uni_device_model";//设备模块 public final static String UNI_EVENT_REPLY_DEVICE_LIST = "list";//逆变器设备列表 public final static String UNI_EVENT_REPLY_DEVICE_CHILD_LIST = "child_list";//逆变器【下挂】设备列表 public final static String UNI_EVENT_REPLY_DEVICE_ADD = "add";//设备添加 public final static String UNI_EVENT_REPLY_DEVICE_DEL = "del";//设备删除 public final static String UNI_EVENT_REPLY_DEVICE_OID = "oid";//设备【包括下挂设备】oid列表 // //【小程序】发送到【原生】 加前缀:uni_ //public final static String UNI_EVENT_HOME_MODEL = "uni_home_model";//住宅模块 // public final static String UNI_EVENT__DEVICE_MODEL = "uni_device_model";//设备模块 // /*********住宅【电站】模块*********/ // public final static String UNI_EVENT_HOME_LIST = "list";//获取住宅【电站】列表 // public final static String UNI_EVENT_HOME_CREATION = "creation";//住宅【电站】创建 // public final static String UNI_EVENT_HOME_EDIT = "edit";//住宅【电站】编辑 // public final static String UNI_EVENT_HOME_DETAILS = "details";//住宅【电站】详情 // public final static String UNI_EVENT_Home_DEl = "del";//住宅【电站】删除 // /*********设备模块*********/ // public final static String UNI_EVENT_DEVICE_LIST = "list";//逆变器设备列表 // public final static String UNI_EVENT_DEVICE_CHILD_LIST = "child_list";//逆变器【下挂】设备列表 // public final static String UNI_EVENT_DEVICE_ADD = "add";//设备添加 // public final static String UNI_EVENT_DEVICE_DEL = "del";//设备删除 // public final static String UNI_EVENT_DEVICE_OID = "oid";//设备【包括下挂设备】oid列表 /*********Wifi模块*********/ //卫锦定义 public final static String UNI_EVENT_REPLY_WIFI_MODEL = "uni_wifi_model";//wifi模块 public final static String UNI_EVENT_REPLY_WIFI_LIST = "list";//获取wifi列表 public final static String UNI_EVENT_REPLY_WIFI_INFO = "info";//获取当前wifi信息 public final static String UNI_EVENT_REPLY_WIFI_CONNECT = "connect";//连接wifi //注意:【原生】主动发送到【小程序】 加前缀:app_ //【原生】主动发送到【小程序】 加前缀:app_ //【原生】打开【小程序】页面路径(UNI_EVENT_HOME_CREATION+?key=value&key=参数一) //注意:【原生】打开【小程序】页面路径(UNI_EVENT_OPEN_HOME_CREATION+?key=value&key=参数一) /*********住宅模块*********/ public final static String UNI_EVENT_HOME_CREATION = "pages/powerStation/powerStationCreate";//住宅【电站】创建 public final static String UNI_EVENT_HOME_EDIT = "pages/powerStation/powerStationEdit";//住宅【电站】编辑 public final static String UNI_EVENT_HOME_DETAILS = "pages/powerStationDetail/index";//住宅【电站】详情 // public final static String UNI_EVENT_Home_DEl = "del";//住宅【电站】删除 public final static String UNI_EVENT_OPEN_HOME_CREATION = "pages/powerStation/powerStationCreate";//住宅【电站】创建 public final static String UNI_EVENT_OPEN_HOME_EDIT = "pages/powerStation/powerStationEdit";//住宅【电站】编辑 public final static String UNI_EVENT_OPEN_HOME_DETAILS = "pages/powerStationDetail/index";//住宅【电站】详情 public final static String UNI_EVENT_OPEN_HOME_DEl = "del";//住宅【电站】删除 /*********设备模块*********/ //设备模块打开页面全路径 @@ -122,20 +125,6 @@ public void setPath(String path) { this.path = path; } /** * 当前对象转 JSONObject * * @return JSONObject */ public JSONObject getJSONObject() { try { String json = new Gson().toJson(this); return new JSONObject(json); } catch (Exception e) { return new JSONObject(); } } app/src/main/java/com/hdl/photovoltaic/utils/WifiUtils.java
New file @@ -0,0 +1,314 @@ package com.hdl.photovoltaic.utils; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.SystemClock; import android.util.Log; import androidx.core.app.ActivityCompat; import java.util.ArrayList; import java.util.List; public class WifiUtils { public WifiManager mWifiManager; public WifiManager.WifiLock mWifiLock; public Context mContext; public WifiUtils(Context context) { this.mContext = context; mWifiManager = (WifiManager) this.mContext.getSystemService(Context.WIFI_SERVICE); } /** * 获取wifi-ssid名称 * * @return 返回ssid名称 */ public String getCurrentConnectWifiSsid() { WifiInfo wifiInfo = this.getCurrentConnectWifiInfo(); return wifiInfo.getSSID().replace("\"", ""); } /** * 获取当前连接的wifi * * @return wifi信息 */ public WifiInfo getCurrentConnectWifiInfo() { return (mWifiManager == null) ? null : mWifiManager.getConnectionInfo(); } /** * 检测wifi状态 * WIFI_STATE_DISABLED 0 正在关闭 * WIFI_STATE_DISABLED 1 已经关闭 * WIFI_STATE_ENABLING 2 正在打开 * WIFI_STATE_ENABLED 3 已经打开 * WIFI_STATE_UNKNOWN 4 未知 * * @return - */ public int checkWifiState() { return mWifiManager.getWifiState(); } //打开wifi public void openWifiEnabled() { if (mWifiManager != null) { mWifiManager.setWifiEnabled(true); } } //关闭wifi public void colseWifiEnable() { if (mWifiManager != null) { mWifiManager.setWifiEnabled(false); } } //获取一个WIFILock public void crateWifiLock() { if (mWifiManager != null) { mWifiLock = mWifiManager.createWifiLock("Test"); } } //锁定wifi public void lockWifi() { mWifiLock.acquire(); } //释放wifiLock public void releaseWifiLock() { if (mWifiLock.isHeld()) { mWifiLock.release(); } } //获取扫描结果 public List<ScanResult> getScanResult() { List<ScanResult> results = new ArrayList<>(); try { if (mWifiManager != null) { // mWifiManager.startScan(); // SystemClock.sleep(1000); results = mWifiManager.getScanResults(); } } catch (Exception ex) { Log.d("WifiUtils", ex.getMessage()); } return results; } //获取已经配置好的网络连接 public List<WifiConfiguration> getConfigWifiInfo() { List<WifiConfiguration> configInfo = new ArrayList<>(); if (mWifiManager != null) { mWifiManager.startScan(); SystemClock.sleep(1000); if (ActivityCompat.checkSelfPermission(this.mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return configInfo; } configInfo = mWifiManager.getConfiguredNetworks(); } return configInfo; } //断开指定的wifi public void disconnectWifi(int netid) { if (mWifiManager != null) { mWifiManager.disableNetwork(netid); mWifiManager.disconnect(); } } /** * 连接到特定WiFi * * @param SSID SSID * @param password 密码 * @param type 加密类型 1.没有密码 2.用wep加密 3.用wpa加密 */ public boolean connectWiFi(String SSID, String password, int type) { int wcgID = mWifiManager.addNetwork(createConfig(SSID, password, type)); return mWifiManager.enableNetwork(wcgID, true); } //获取一个wifi的配置信息 private WifiConfiguration createConfig(String SSID, String password, int type) { WifiConfiguration config = new WifiConfiguration(); config.allowedAuthAlgorithms.clear(); config.allowedGroupCiphers.clear(); config.allowedKeyManagement.clear(); config.allowedPairwiseCiphers.clear(); config.allowedProtocols.clear(); config.SSID = "\"" + SSID + "\""; // 如果已经连接过WiFi,移除掉 WifiConfiguration tempConfig = isExsits(SSID); if (tempConfig != null) { mWifiManager.removeNetwork(tempConfig.networkId); } if (type == 1) { config.wepKeys[0] = ""; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex = 0; } if (type == 2) { config.hiddenSSID = true; config.wepKeys[0] = "\"" + password + "\""; config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex = 0; } if (type == 3) { config.preSharedKey = "\"" + password + "\""; config.hiddenSSID = true; config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); config.status = WifiConfiguration.Status.ENABLED; } return config; } // 判断当前SSID是否已经连接过 private WifiConfiguration isExsits(String SSID) { List<WifiConfiguration> existingConfigs = mWifiManager.getConfiguredNetworks(); if (existingConfigs == null) return null; for (WifiConfiguration existingConfig : existingConfigs) { if (existingConfig.SSID.equals("\"" + SSID + "\"")) { return existingConfig; } } return null; } /** * 获取附近wifi列表 * 注意:自己定义wifi对象;原生返回wifi调用这个getScanResult()方法 * * @return - */ public List<MyWifiInfo> getCustomWifiDeviceInfo() { List<ScanResult> scanResults = getScanResult();//搜索到的设备列表 List<ScanResult> newScanResultList = new ArrayList<>(); for (ScanResult scanResult : scanResults) { int position = getItemPosition(newScanResultList, scanResult); if (position != -1) { if (newScanResultList.get(position).level < scanResult.level) { newScanResultList.remove(position); newScanResultList.add(position, scanResult); } } else { newScanResultList.add(scanResult); } } List<MyWifiInfo> wifiList = new ArrayList<>(); for (int i = 0; i < newScanResultList.size(); i++) { MyWifiInfo info = new MyWifiInfo(); info.setSSID(newScanResultList.get(i).SSID); info.setLevel(newScanResultList.get(i).level); info.setBSSID(newScanResultList.get(i).BSSID); wifiList.add(info); } return wifiList; /* * wifi RSSI的等级划分如下: * * [-126, -88) 或者 [156, 168) 为 0 格 * [-88, -78) 或者 [168, 178) 为 1 格 * [-78, -67) 或者 [178, 189) 为 2 格 * [-67, -55) 或者 [189, 200) 为 3 格 * [-55, 0] 或者 为 4 格 */ } /** * 返回item在list中的位置 */ private int getItemPosition(List<ScanResult> list, ScanResult item) { for (int i = 0; i < list.size(); i++) { if (item.SSID.equals(list.get(i).SSID)) { return i; } } return -1; } static class MyWifiInfo { /** * Wi-Fi名称 */ private String SSID; /** * 信号强度 */ private int level; private String BSSID; public String getSSID() { return SSID == null ? "" : SSID; } public void setSSID(String SSID) { this.SSID = SSID; } public int getLevel() { return level; } public void setLevel(int level) { this.level = level; } public String getBSSID() { return BSSID == null ? "" : BSSID; } public void setBSSID(String BSSID) { this.BSSID = BSSID; } private int networkId; public int getNetworkId() { return networkId; } public void setNetworkId(int networkId) { this.networkId = networkId; } } } app/src/main/java/com/hdl/photovoltaic/widget/ConfirmationDialog.java
@@ -16,7 +16,7 @@ */ public class ConfirmationDialog extends Dialog { public ConfirmationDialog(@NonNull Context context) { super(context, R.style.Custom_AlertDialog); super(context, R.style.Custom_Dialog); this.mContext = context; } app/src/main/java/com/hdl/photovoltaic/widget/ConfirmationExceptionDialog.java
New file @@ -0,0 +1,85 @@ package com.hdl.photovoltaic.widget; import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.view.Window; import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.appcompat.content.res.AppCompatResources; import com.hdl.photovoltaic.R; import com.hdl.photovoltaic.databinding.LoadingExceptionLogBinding; /** * 异常弹窗 */ public class ConfirmationExceptionDialog extends Dialog { private LoadingExceptionLogBinding viewBinding; private final Context mContext; private String contentStr; public ConfirmationExceptionDialog(@NonNull Context context) { super(context, R.style.Custom_Dialog); mContext = context; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); viewBinding = LoadingExceptionLogBinding.inflate(getLayoutInflater()); setContentView(viewBinding.getRoot()); // Window window = getWindow(); // window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); // setCancelable(true);//系统后退可以取消 //空白处不能取消动画 setCanceledOnTouchOutside(false); //初始化界面控件 initView(); //初始化界面数据 initData(); //初始化界面控件的事件 initEvent(); } /** * 自定义"内容"文本 * * @param content 内容 */ public void setContent(String content) { if (TextUtils.isEmpty(content)) { return; } contentStr = content; if (viewBinding != null) { viewBinding.loadingExceptionTv.setText(content); } } private void initView() { viewBinding.toolbarTopExceptionRl.topLeftIv.setImageDrawable(AppCompatResources.getDrawable(mContext, R.drawable.back)); viewBinding.toolbarTopExceptionRl.topTitleTv.setText("日志详细"); viewBinding.toolbarTopExceptionRl.topBarView.setBackgroundColor(mContext.getColor(R.color.text_245EC3)); viewBinding.loadingExceptionTv.setText(contentStr == null ? "" : contentStr); } private void initEvent() { viewBinding.toolbarTopExceptionRl.topBackBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); } private void initData() { } } app/src/main/java/com/hdl/photovoltaic/widget/ConfirmationInputDialog.java
@@ -23,7 +23,7 @@ public class ConfirmationInputDialog extends Dialog { public ConfirmationInputDialog(@NonNull Context context) { super(context, R.style.Custom_AlertDialog); super(context, R.style.Custom_Dialog); this.mContext = context; } app/src/main/res/layout/loading_exception_log.xml
@@ -1,6 +1,62 @@ <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> android:layout_height="match_parent" android:background="@color/text_FFFFFFFF"> <include android:id="@+id/toolbar_top_exception_rl" layout="@layout/toolbar_top_view_44" /> <!-- <RelativeLayout--> <!-- android:id="@+id/loading_header_el"--> <!-- android:layout_width="match_parent"--> <!-- android:layout_height="@dimen/dp_16"--> <!-- app:layout_constraintEnd_toEndOf="parent"--> <!-- app:layout_constraintStart_toStartOf="parent"--> <!-- app:layout_constraintTop_toBottomOf="@+id/toolbar_top_exception_rl">--> <!-- <TextView--> <!-- android:id="@+id/loading_top_title_tv"--> <!-- android:layout_width="wrap_content"--> <!-- android:layout_height="@dimen/dp_16"--> <!-- android:layout_marginStart="@dimen/dp_5"--> <!-- android:layout_marginBottom="@dimen/dp_5"--> <!-- android:text="截图反馈"--> <!-- android:textAlignment="textStart"--> <!-- android:textColor="@color/text_D34545"--> <!-- android:textIsSelectable="true" />--> <!-- </RelativeLayout>--> <ScrollView android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/toolbar_top_exception_rl"> <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp"> <!--显示异常堆栈信息--> <TextView android:id="@+id/loading_exception_tv" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginStart="@dimen/dp_5" android:layout_marginBottom="@dimen/dp_5" android:gravity="start|center" android:text="显示异常堆栈信息" android:textAlignment="textStart" android:textColor="@color/text_030D1C" android:textIsSelectable="true" /> </RelativeLayout> </ScrollView> </androidx.constraintlayout.widget.ConstraintLayout> app/src/main/res/layout/toolbar_top_view_44.xml
@@ -14,6 +14,7 @@ android:orientation="horizontal"> <ImageView android:id="@+id/top_left_iv" android:layout_width="@dimen/dp_24" android:layout_height="@dimen/dp_24" android:layout_gravity="center" app/src/main/res/values/themes.xml
@@ -29,7 +29,7 @@ <item name="fullscreenTextColor">@color/light_blue_A200</item> </style> <style name="Custom_AlertDialog"> <style name="Custom_Dialog"> <!--背景颜色及和透明程度--> <item name="android:windowBackground">@android:color/transparent</item> <!--是否去除标题 指dialog弹框标题-->