Skip to content

Commit

Permalink
优化工具:objutils
Browse files Browse the repository at this point in the history
  • Loading branch information
ctj committed Jun 12, 2023
1 parent 80c258a commit 35ef031
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
import androidx.annotation.Nullable;

import com.chtj.base_framework.network.FLteTools;
import com.chtj.base_framework.network.NetDbmListener;
import com.face_chtj.base_iotutils.FileUtils;
import com.face_chtj.base_iotutils.KLog;
import com.face_chtj.base_iotutils.SPUtils;
import com.face_chtj.base_iotutils.ShellUtils;
import com.face_chtj.base_iotutils.TimeUtils;
import com.face_chtj.base_iotutils.TypeDataUtils;
import com.face_chtj.base_iotutils.ObjectUtils;
import com.face_chtj.base_iotutils.NetUtils;
import com.wave_chtj.example.R;
import com.wave_chtj.example.callback.INetMonitor;
Expand Down Expand Up @@ -101,7 +100,7 @@ public void getDataCallBack() {
if (nCallback == null) {
return;
}
String[] pingList = TypeDataUtils.getRandomList(NetUtils.DNS_LIST,3);
String[] pingList = ObjectUtils.getRandomList(NetUtils.DNS_LIST,3);
boolean isNetPing = NetUtils.checkNetWork(pingList, 1, 1);
nCallback.getNetType(NetUtils.getNetWorkTypeName(), isNetPing);
nCallback.getPingList(pingList);
Expand Down Expand Up @@ -264,7 +263,7 @@ public void accept(Long aLong) throws Exception {

}
}
String[] pingList = TypeDataUtils.getRandomList(NetUtils.DNS_LIST,3);
String[] pingList = ObjectUtils.getRandomList(NetUtils.DNS_LIST,3);
boolean isNetPing = NetUtils.checkNetWork(pingList, 1, 1);
//判断模块重置的下一次执行之前 判断网络是否成功
long converNum = nowCount + 1;
Expand Down Expand Up @@ -362,7 +361,7 @@ public void onReceive(Context context, Intent intent) {
if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) {//网络变化
if (nCallback != null) {
String netType = NetUtils.getNetWorkTypeName();
String[] pingList = TypeDataUtils.getRandomList(NetUtils.DNS_LIST,3);
String[] pingList = ObjectUtils.getRandomList(NetUtils.DNS_LIST,3);
boolean isNetPing = NetUtils.checkNetWork(pingList, 1, 1);
KLog.d(TAG, "action==> " + action + ", netType==> " + netType + ",isNetPing==> " + isNetPing);
nCallback.getNetType(netType, isNetPing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static List<AppEntity> getNormalAppList() {
* @return 是否存在
*/
public static boolean existLocal(String packageName) {
if (TypeDataUtils.isEmpty(packageName)) {
if (ObjectUtils.isEmpty(packageName)) {
return false;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class DialogUtils {
private AlertDialog mDialog;
private TextView tvTitle;
private EditText etContent;
private boolean isShowlBottomView;
private boolean isShowBoard;
private IDialogCallback iCallback;
private boolean isClickBtn;
Expand All @@ -47,11 +46,6 @@ public static DialogUtils setDialogCallback(IDialogCallback iCallback) {
return instance();
}

public static DialogUtils setBottomVisible(boolean isShow) {
instance().isShowlBottomView=isShow;
return instance();
}

public static EditText getEditeContent() {
return instance().etContent;
}
Expand Down Expand Up @@ -118,7 +112,6 @@ public void onDismiss(DialogInterface dialog) {
instance().etContent = view.findViewById(R.id.etContent);
instance().etContent.setBackground(needEnter?ContextCompat.getDrawable(context,R.drawable.ic_dialogalert_bg):null);
instance().tvTitle = view.findViewById(R.id.tvTitle);
view.findViewById(R.id.lBottomView).setVisibility(instance().isShowlBottomView?View.VISIBLE:View.GONE);
if(!needEnter){
instance().tvTitle.setFocusable(true);
instance().etContent.setLongClickable(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
import android.os.Build;
import android.telephony.TelephonyManager;

import androidx.annotation.IntDef;
import androidx.annotation.RequiresPermission;

import com.face_chtj.base_iotutils.entity.DnsBean;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
Expand Down Expand Up @@ -267,7 +265,7 @@ public static boolean reloadDnsPing() {
return tryRefreshDns();
} else {
//未达到指定刷新dns的时间 那么使用前一次获取的列表
return checkNetWork(TypeDataUtils.getRandomList(getConvertDns(), 3), 1, 1);
return checkNetWork(ObjectUtils.getRandomList(getConvertDns(), 3), 1, 1);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public static NotifyUtils setAppAbout(String appAbout) {

private static NotifyUtils setView(int viewId,String content) {
String appendStr = "";
if (!TypeDataUtils.isEmpty(content)) {
if (!ObjectUtils.isEmpty(content)) {
appendStr = content;
} else {
appendStr = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* {@link #isEmpty(String)} 判断字符是否为空
* {@link #getRandomList(String[], int)} 两重循环去重,随机指定范围内N个不重复的数
*/
public class TypeDataUtils {
public class ObjectUtils {
/**
* 是否为空
* @param str 字符串
Expand All @@ -25,6 +25,16 @@ public static Boolean isEmpty(String str) {
return false;
}

/**
* 判断obj是否为空
*/
public static boolean isEmpty(Object obj) {
if (obj == null || obj.toString().length() == 0|| "null".equals(obj.toString())) {
return true;
}
return false;
}

/**
* 数组中的字符串是否为空
* @param array 字符串
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static boolean zipFiles(Collection<File> resFiles, String zipFilePath, St
* @return 文件
*/
private static File getFileByPath(String filePath) {
return TypeDataUtils.isEmpty(filePath) ? null : new File(filePath);
return ObjectUtils.isEmpty(filePath) ? null : new File(filePath);
}
/**
* 批量压缩文件
Expand Down Expand Up @@ -191,13 +191,13 @@ public static boolean zipFile(File resFile, File zipFile, String comment)
*/
private static boolean zipFile(File resFile, String rootPath, ZipOutputStream zos, String comment)
throws IOException {
rootPath = rootPath + (TypeDataUtils.isEmpty(rootPath) ? "" : File.separator) + resFile.getName();
rootPath = rootPath + (ObjectUtils.isEmpty(rootPath) ? "" : File.separator) + resFile.getName();
if (resFile.isDirectory()) {
File[] fileList = resFile.listFiles();
// 如果是空文件夹那么创建它,我把'/'换为File.separator测试就不成功,eggPain
if (fileList.length <= 0) {
ZipEntry entry = new ZipEntry(rootPath + '/');
if (!TypeDataUtils.isEmpty(comment)) {
if (!ObjectUtils.isEmpty(comment)) {
entry.setComment(comment);
}
zos.putNextEntry(entry);
Expand All @@ -215,7 +215,7 @@ private static boolean zipFile(File resFile, String rootPath, ZipOutputStream zo
try {
is = new BufferedInputStream(new FileInputStream(resFile));
ZipEntry entry = new ZipEntry(rootPath);
if (!TypeDataUtils.isEmpty(comment)) {
if (!ObjectUtils.isEmpty(comment)) {
entry.setComment(comment);
}
zos.putNextEntry(entry);
Expand Down Expand Up @@ -544,7 +544,7 @@ public static String zipEncrypt(String src, String dest, boolean isCreateDir, St
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
// 压缩级别
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
if (!TypeDataUtils.isEmpty(passwd)) {
if (!ObjectUtils.isEmpty(passwd)) {
parameters.setEncryptFiles(true);
// 加密方式
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
Expand Down Expand Up @@ -581,7 +581,7 @@ public static String zipEncrypt(String src, String dest, boolean isCreateDir, St
* @return 正确的压缩文件存放路径
*/
private static String buildDestinationZipFilePath(File srcFile, String destParam) {
if (TypeDataUtils.isEmpty(destParam)) {
if (ObjectUtils.isEmpty(destParam)) {
if (srcFile.isDirectory()) {
destParam = srcFile.getParent() + File.separator + srcFile.getName() + ".zip";
} else {
Expand Down Expand Up @@ -628,7 +628,7 @@ public static String zipEncryptRargo(String src, String dest, boolean isCreateDi
// 默认COMP_DEFLATE
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
if (!TypeDataUtils.isEmpty(passwd)) {
if (!ObjectUtils.isEmpty(passwd)) {
parameters.setEncryptFiles(true);
parameters.setEncryptionMethod(0);
parameters.setPassword(passwd.toCharArray());
Expand Down
1 change: 1 addition & 0 deletions base_iotutils/src/main/res/layout/dialog_edite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
android:gravity="center_vertical"
android:orientation="vertical"
android:textColor="@color/black"
android:singleLine="true"
android:textColorHint="@color/gray"
android:textSize="20sp" />

Expand Down

0 comments on commit 35ef031

Please sign in to comment.