diff --git a/README.md b/README.md index a6dcec8..2c1df23 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ allprojects { ```groovy dependencies { //多个物联网相关基础工具类 - implementation 'com.github.wave-chtj:BaseIotUtils:2.4.3' + implementation 'com.github.wave-chtj:BaseIotUtils:2.6.0' } ``` diff --git a/app/src/main/java/com/ichtj/basetools/MainActivity.java b/app/src/main/java/com/ichtj/basetools/MainActivity.java index 6454b8d..ddc5116 100644 --- a/app/src/main/java/com/ichtj/basetools/MainActivity.java +++ b/app/src/main/java/com/ichtj/basetools/MainActivity.java @@ -1,11 +1,20 @@ package com.ichtj.basetools; +import android.content.ComponentName; +import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.net.wifi.ScanResult; +import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.Environment; import android.os.Handler; +import android.util.Log; +import android.widget.Button; +import android.widget.Toast; + import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import com.alibaba.android.arouter.facade.annotation.Route; import com.chtj.base_framework.FScreentTools; @@ -29,6 +38,9 @@ import com.face_chtj.base_iotutils.ToastUtils; import com.face_chtj.base_iotutils.UriPathUtils; import com.face_chtj.base_iotutils.callback.INotifyStateCallback; +import com.face_chtj.base_iotutils.download.DownloadCallback; +import com.face_chtj.base_iotutils.download.DownloadManager; +import com.face_chtj.base_iotutils.download.DownloadStatus; import com.ichtj.basetools.allapp.AllAppAty; import com.ichtj.basetools.audio.AudioAty; import com.ichtj.basetools.base.BaseActivity; @@ -66,9 +78,12 @@ import com.ichtj.basetools.video.VideoPlayAty; import java.io.InputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; @Route(path = PACKAGES.BASE + "basetools") public class MainActivity extends BaseActivity implements CustomButtonGridView.OnButtonClickListener { @@ -79,21 +94,40 @@ public class MainActivity extends BaseActivity implements CustomButtonGridView.O protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_aty); + Button button = findViewById(R.id.btnNext); + button.setTextColor(ContextCompat.getColor(this, R.color.red)); customButtonGridView = findViewById(R.id.customButtonGridView); customButtonGridView.setButtonMap(getDisplayBtn()); customButtonGridView.setNumColumns(2); // 设置每列显示2个按钮 customButtonGridView.setOnButtonClickListener(this); +// DownloadManager downloadManager =new DownloadManager(this, new DownloadCallback() { +// @Override +// public void onDownloadStatusChanged(DownloadStatus status) { +// Log.d(TAG, "onDownloadStatusChanged: "+status.toString()); +// } +// +// @Override +// public void onDownloadProgress(String url, int progress) { +// Log.d(TAG, "onDownloadProgress: url>>"+url+",progress>>"+progress); +// } +// }); +// downloadManager.downloadFile("https://fireware-1257276602.cos.ap-guangzhou.myqcloud.com/test_file/ichtj_test/update.zip","/sdcard/testdownload/update.zip"); +// downloadManager.downloadFile("https://fireware-1257276602.cos.ap-guangzhou.myqcloud.com/test_file/ichtj_test/sabresd_6dq-ota-20211029155349.zip","/sdcard/testdownload/20211029155349.zip"); + Intent intent = new Intent(); + intent.setComponent(new ComponentName("com.zto.ztoexpresscabinet", "com.zto.ztoexpresscabinet.business.view.MainActivity")); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); } public Map getDisplayBtn() { Map btnList = new HashMap<>(); - Space ramSpace = new Space(0, 0, 0); + Space ramSpace = null; try { ramSpace = FStorageTools.getRamSpace(FStorageTools.TYPE_MB); } catch (Throwable throwable) { throwable.printStackTrace(); } - Space sdSpace = new Space(0, 0, 0); + Space sdSpace = null; try { sdSpace = FStorageTools.getSdcardSpace(FStorageTools.TYPE_MB); } catch (Throwable throwable) { @@ -107,8 +141,8 @@ public Map getDisplayBtn() { btnList.put(FKey.KEY_IS_ROOT, "是否ROOT:" + AppsUtils.isRoot()); btnList.put(FKey.KEY_LOCAL_IP, "本地IP:" + NetUtils.getLocalIp()); btnList.put(FKey.KEY_FW_VERSION, "固件版本:" + DeviceUtils.getFwVersion()); - btnList.put(FKey.KEY_RAM, "运存:" + ramSpace.getTotalSize() + "M/" + ramSpace.getUseSize() + "M/" + ramSpace.getAvailableSize() + "M"); - btnList.put(FKey.KEY_SD_SPACE, "SD:" + sdSpace.getTotalSize() + "M/" + sdSpace.getUseSize() + "M/" + sdSpace.getAvailableSize() + "M"); + btnList.put(FKey.KEY_RAM, "运存:" + ramSpace.getTotalSize() + "MB/" + ramSpace.getUseSize() + "MB/" + ramSpace.getAvailableSize() + "MB"); + btnList.put(FKey.KEY_SD_SPACE, "SD:" + sdSpace.getTotalSize() + "MB/" + sdSpace.getUseSize() + "MB/" + sdSpace.getAvailableSize() + "MB"); btnList.put(FKey.KEY_ETH_MODE, "ETH模式:" + FEthTools.getIpMode(BaseIotUtils.getContext())); try { btnList.put(FKey.KEY_DBM, "4G信号值:" + FLteTools.getDbm()); diff --git a/app/src/main/java/com/ichtj/basetools/StartPageAty.java b/app/src/main/java/com/ichtj/basetools/StartPageAty.java index 1e64284..ace726d 100644 --- a/app/src/main/java/com/ichtj/basetools/StartPageAty.java +++ b/app/src/main/java/com/ichtj/basetools/StartPageAty.java @@ -7,11 +7,6 @@ import com.ichtj.basetools.base.BaseActivity; import com.ichtj.basetools.util.PACKAGES; -/** - * Create on 2019/10/16 - * author chtj - * desc $ 启动页 - */ public class StartPageAty extends BaseActivity { @Override diff --git a/app/src/main/java/com/ichtj/basetools/socket/SocketAty.java b/app/src/main/java/com/ichtj/basetools/socket/SocketAty.java index 3d4b126..b1f2761 100644 --- a/app/src/main/java/com/ichtj/basetools/socket/SocketAty.java +++ b/app/src/main/java/com/ichtj/basetools/socket/SocketAty.java @@ -111,97 +111,9 @@ public void onViewClicked(View view) { switch (view.getId()) { case R.id.btnConnect://开启连接 if(selectOpiton==TCP_OPTION){ - //设置参数 地址+端口 - baseTcpSocket = new BaseTcpSocket(etIp.getText().toString(), Integer.parseInt(etPort.getText().toString()), 5000); - //设置监听回调 - baseTcpSocket.setSocketListener(new ISocketListener() { - @Override - public void recv(byte[] data, int offset, int size) { - KLog.d(TAG,"recv:>="+Arrays.toString(data)); - Message message = handler.obtainMessage(); - try { - message.obj = "\n\r读到数据:" + /*Arrays.toString(data);*/new String(data, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - handler.sendMessage(message); - } - - @Override - public void writeSuccess(byte[] data) { - Message message = handler.obtainMessage(); - message.obj = "\n\r写入数据:" + Arrays.toString(data); - handler.sendMessage(message); - } - - @Override - public void connSuccess() { - Message message = handler.obtainMessage(); - message.obj = "\n\r连接成功"; - handler.sendMessage(message); - } - - @Override - public void connFaild(Throwable t) { - Message message = handler.obtainMessage(); - message.obj = "\n\r连接异常"; - handler.sendMessage(message); - } - - @Override - public void connClose() { - KLog.d(TAG, "The connection is disconnect"); - Message message = handler.obtainMessage(); - message.obj = "\n\r关闭连接"; - handler.sendMessage(message); - } - }); - //开启连接 - baseTcpSocket.connect(this); + startTcpConnect(); }else if(selectOpiton==UDP_OPTION){ - //设置参数 地址+端口 - baseUdpSocket=new BaseUdpSocket(etIp.getText().toString(), Integer.parseInt(etPort.getText().toString()),0); - //设置监听回调 - baseUdpSocket.setSocketListener(new ISocketListener() { - @Override - public void recv(byte[] data, int offset, int size) { - Message message = handler.obtainMessage(); - message.obj = "\n\r读到数据:" + Arrays.toString(data); - handler.sendMessage(message); - } - - @Override - public void writeSuccess(byte[] data) { - Message message = handler.obtainMessage(); - message.obj = "\n\r写入数据:" + Arrays.toString(data); - handler.sendMessage(message); - } - - @Override - public void connSuccess() { - Message message = handler.obtainMessage(); - message.obj = "\n\r连接成功"; - handler.sendMessage(message); - } - - @Override - public void connFaild(Throwable t) { - KLog.d(TAG, "errMeg: "+t.getMessage()); - Message message = handler.obtainMessage(); - message.obj = "\n\r连接异常"; - handler.sendMessage(message); - } - - @Override - public void connClose() { - KLog.d(TAG, "The connection is disconnect"); - Message message = handler.obtainMessage(); - message.obj = "\n\r关闭连接"; - handler.sendMessage(message); - } - }); - //开启连接 - baseUdpSocket.connect(this); + startUdpConnect(); } break; case R.id.btnDisConnect://关闭连接 @@ -232,4 +144,100 @@ public void connClose() { break; } } + + private void startUdpConnect() { + //设置参数 地址+端口 + baseUdpSocket=new BaseUdpSocket(etIp.getText().toString(), Integer.parseInt(etPort.getText().toString()),0); + //设置监听回调 + baseUdpSocket.setSocketListener(new ISocketListener() { + @Override + public void recv(byte[] data, int offset, int size) { + Message message = handler.obtainMessage(); + message.obj = "\n\r读到数据:" + Arrays.toString(data); + handler.sendMessage(message); + } + + @Override + public void writeSuccess(byte[] data) { + Message message = handler.obtainMessage(); + message.obj = "\n\r写入数据:" + Arrays.toString(data); + handler.sendMessage(message); + } + + @Override + public void connSuccess() { + Message message = handler.obtainMessage(); + message.obj = "\n\r连接成功"; + handler.sendMessage(message); + } + + @Override + public void connFaild(Throwable t) { + KLog.d(TAG, "errMeg: "+t.getMessage()); + Message message = handler.obtainMessage(); + message.obj = "\n\r连接异常"; + handler.sendMessage(message); + } + + @Override + public void connClose() { + KLog.d(TAG, "The connection is disconnect"); + Message message = handler.obtainMessage(); + message.obj = "\n\r关闭连接"; + handler.sendMessage(message); + } + }); + //开启连接 + baseUdpSocket.connect(this); + } + + private void startTcpConnect() { + //设置参数 地址+端口 + baseTcpSocket = new BaseTcpSocket(etIp.getText().toString(), Integer.parseInt(etPort.getText().toString()), 5000); + //设置监听回调 + baseTcpSocket.setSocketListener(new ISocketListener() { + @Override + public void recv(byte[] data, int offset, int size) { + KLog.d(TAG,"recv:>="+Arrays.toString(data)); + Message message = handler.obtainMessage(); + try { + message.obj = "\n\r读到数据:" + /*Arrays.toString(data);*/new String(data, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + handler.sendMessage(message); + } + + @Override + public void writeSuccess(byte[] data) { + Message message = handler.obtainMessage(); + message.obj = "\n\r写入数据:" + Arrays.toString(data); + handler.sendMessage(message); + } + + @Override + public void connSuccess() { + Message message = handler.obtainMessage(); + message.obj = "\n\r连接成功"; + handler.sendMessage(message); + } + + @Override + public void connFaild(Throwable t) { + Message message = handler.obtainMessage(); + message.obj = "\n\r连接异常"; + handler.sendMessage(message); + } + + @Override + public void connClose() { + KLog.d(TAG, "The connection is disconnect"); + Message message = handler.obtainMessage(); + message.obj = "\n\r关闭连接"; + handler.sendMessage(message); + } + }); + //开启连接 + baseTcpSocket.connect(this); + } } diff --git a/app/src/main/res/layout/activity_main_aty.xml b/app/src/main/res/layout/activity_main_aty.xml index 9bb2108..f18dda9 100644 --- a/app/src/main/res/layout/activity_main_aty.xml +++ b/app/src/main/res/layout/activity_main_aty.xml @@ -3,6 +3,12 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> +