panlili2024
2024-09-19 071a8328823a2861f93ce556a4da3e4119cab1a3
app/src/main/java/com/hdl/sdk/ttl_sdk/activity/MainActivity.java
@@ -1,13 +1,14 @@
package com.hdl.sdk.ttl_sdk.activity;
import static com.hdl.sdk.ttl_sdk.HDLApplication.HDL_BAUDRATE;
import static com.hdl.sdk.ttl_sdk.HDLApplication.HDL_UART_PATH;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
@@ -15,25 +16,22 @@
import android.widget.TextView;
import android.widget.Toast;
import com.hdl.sdk.ttl.Config.Configuration;
import com.hdl.sdk.ttl.HDLAppliances.Config.HDLApConfig;
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.DevicesData;
import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLCommand;
import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLDeviceManager;
import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLSerialPortCore;
import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLTtlSdk;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.BgmInfoEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.DevicesInfoEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.DiscoverNewDevicesEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.UpdateRemarkFeedBackEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.ThirdPartyBgmInfoEvent;
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.WarningInfoEvent;
import com.hdl.sdk.ttl.Utils.HDLUtlis.HDLStringUtils;
import com.hdl.sdk.ttl_sdk.R;
import com.hdl.sdk.ttl_sdk.adapter.HDLMainListAdapter;
import com.hdl.sdk.ttl_sdk.base.BaseActivity;
//import com.hdl.sdk.ttl_sdk.bean.ZigbeeActivity2;
import com.hdl.sdk.ttl_sdk.utlis.HDLLog;
import com.hdl.sdk.ttl_sdk.utlis.HDLWarningType;
@@ -44,9 +42,6 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import static com.hdl.sdk.ttl_sdk.HDLApplication.HDL_BAUDRATE;
import static com.hdl.sdk.ttl_sdk.HDLApplication.HDL_UART_PATH;
/**
 * Modify by JLChen on 2019/6/27
@@ -72,7 +67,10 @@
//    private RelativeLayout topBarBack;
    private TextView topBarTitle;
    private TextView tvVersion;
    private EditText etGatewaySubID;
    private EditText etGatewaydeviceID;
    private Button btnSearch;
    private Button btnSearchScene;
    private Button btnGetLocal;
    private Button btnClose;
    private Button btnOpen;
@@ -88,7 +86,7 @@
    private List<String> mAllDevicesList = new ArrayList<>();//搜索到的设备的备注名
    private ProgressDialog mProgressDialog;
//    private static String HDL_PATH_NAME = "/dev/ttyS2"; //串口设备路径名
    //    private static String HDL_PATH_NAME = "/dev/ttyS2"; //串口设备路径名
//    private static int HDL_BAUDRATE = 115200;  //波特率
    private Boolean bOpen = false;
    private int remarkId = 0;
@@ -123,7 +121,10 @@
    private void initView() {
        topBarTitle = findViewById(R.id.tv_top_b_header_title);
        tvVersion = findViewById(R.id.tv_version);
        etGatewaySubID = findViewById(R.id.et_gateway_subID);
        etGatewaydeviceID = findViewById(R.id.et_gateway_deviceID);
        btnSearch = findViewById(R.id.btn_search);
        btnSearchScene = findViewById(R.id.btn_searchScene);
        btnGetLocal = findViewById(R.id.btn_getlocal);
        btnClose = findViewById(R.id.btn_close);
        btnOpen = findViewById(R.id.btn_open);
@@ -186,10 +187,22 @@
        btnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(etGatewaySubID.getText().toString()) || TextUtils.isEmpty(etGatewaydeviceID.getText().toString())) {
                    Toast.makeText(MainActivity.this, "请输入网关的子网号设备号!", Toast.LENGTH_SHORT).show();
                    return;
                }
                /**全部重新搜索,清空原设备列表数据*/
                clearListView();
                HDLCommand.getHomeDevices();
                HDLDeviceManager.clearAllDeviceList();
                HDLCommand.getHomeDevices(Integer.parseInt(etGatewaySubID.getText().toString()), Integer.parseInt(etGatewaydeviceID.getText().toString()));
                mProgressDialog.show();
            }
        });
        btnSearchScene.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CtrlSceneActivity.open(MainActivity.this, etGatewaySubID.getText().toString(), etGatewaydeviceID.getText().toString());
            }
        });
@@ -339,9 +352,9 @@
        for (int i = 0; i < mDevicesDataList.size(); i++) {
            if (TextUtils.isEmpty(mDevicesDataList.get(i).getRemark())) {
                mAllDevicesList.add("暂无备注");
                mAllDevicesList.add("模块子网设备号" + ":" + mDevicesDataList.get(i).getDeviceSubnetID() + "-" + mDevicesDataList.get(i).getDeviceDeviceID());
            } else {
                mAllDevicesList.add(mDevicesDataList.get(i).getRemark());
                mAllDevicesList.add(mDevicesDataList.get(i).getRemark() + ":" + mDevicesDataList.get(i).getDeviceSubnetID() + "-" + mDevicesDataList.get(i).getDeviceDeviceID());
            }
        }
        mHDLMainListAdapter.notifyDataSetChanged();
@@ -437,12 +450,10 @@
    }
    @SuppressWarnings("unused")
    private void closePhone(Context context, String[] shutdown){
    private void closePhone(Context context, String[] shutdown) {
        try {
            Process    process = Runtime.getRuntime().exec(shutdown);
            Process process = Runtime.getRuntime().exec(shutdown);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();