Skip to content

Commit

Permalink
优化通知工具类
Browse files Browse the repository at this point in the history
  • Loading branch information
ichtj committed Jun 24, 2024
1 parent 3bfd93e commit 759154a
Show file tree
Hide file tree
Showing 13 changed files with 494 additions and 114 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand Down
42 changes: 38 additions & 4 deletions app/src/main/java/com/ichtj/basetools/MainActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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<Integer, String> getDisplayBtn() {
Map<Integer, String> 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) {
Expand All @@ -107,8 +141,8 @@ public Map<Integer, String> 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());
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/ichtj/basetools/StartPageAty.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
188 changes: 98 additions & 90 deletions app/src/main/java/com/ichtj/basetools/socket/SocketAty.java
Original file line number Diff line number Diff line change
Expand Up @@ -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://关闭连接
Expand Down Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main_aty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:text="dsldlsfs"
android:visibility="gone"
android:layout_height="wrap_content"/>
<com.ichtj.basetools.util.CustomButtonGridView
android:id="@+id/customButtonGridView"
android:layout_width="match_parent"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
<color name="green">#00FF37</color>
<color name="red">#FF0000</color>

<color name="gray_1">#CACDD2</color>
<color name="blue_1">#0144C6</color>

</resources>
Loading

0 comments on commit 759154a

Please sign in to comment.