添加ping功能

This commit is contained in:
itgaojian 2024-02-22 10:35:38 +08:00
parent 89357dad64
commit 4475ec660d
15 changed files with 538 additions and 9 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
<bytecodeTargetLevel target="17" />
</component>
</project>

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK" />
</project>

View File

@ -70,6 +70,7 @@ import com.tenlionsoft.baselib.core.widget.marqueen.SimpleMarqueeView;
import com.tenlionsoft.baselib.core.widget.views.BottomSettingPwdView;
import com.tenlionsoft.baselib.core.widget.views.BottomSettingView;
import com.tenlionsoft.baselib.core.widget.views.CenterDialogUpdateView;
import com.tenlionsoft.baselib.core.widget.views.TopPingView;
import com.tenlionsoft.baselib.core.widget.views.TypeFaceTextView;
import com.tenlionsoft.baselib.utils.AppUtils;
import com.tenlionsoft.baselib.utils.ExceptionHandler;
@ -162,6 +163,7 @@ public class MainActivity extends Activity {
intentFilter.addAction(PathConfig.ACTION_SHUT_DOWN);
intentFilter.addAction(PathConfig.ACTION_DO_UPDATE_APP);
intentFilter.addAction(PathConfig.ACTION_APP_INSTALL);
intentFilter.addAction(PathConfig.ACTION_NOTIFY_CLIENT_STATUS);
registerReceiver(this.mBoradCast, intentFilter);
this.mBaseUrl = SPUtils.getInstance().getString("baseUrl");
this.mDeviceCode = SPUtils.getInstance().getString("deviceCode");
@ -849,6 +851,11 @@ public class MainActivity extends Activity {
MainActivity.this.mSettingDialog.dismiss();
}
@Override
public void showPing() {
showPingView();
}
public void shareQQ() {
MainActivity.this.mSettingDialog.dismiss();
Process.killProcess(Process.myPid());
@ -862,6 +869,18 @@ public class MainActivity extends Activity {
this.mSettingDialog.show();
}
/**
* 显示ping
*/
private void showPingView() {
TopPingView pingView = new TopPingView.DialogBuilder(MainActivity.this)
.setIsBackCancelable(false)
.setIscancelable(false)
.build();
pingView.show();
}
/* access modifiers changed from: private */
public void doSubmitDeviceParams(final String str, String str2, final String str3, String str4, String str5,
String str6, String str7) {
@ -1066,6 +1085,12 @@ public class MainActivity extends Activity {
if (!TextUtils.isEmpty(stringExtra)) {
MainActivity.this.installApp(stringExtra);
}
} else if (PathConfig.ACTION_NOTIFY_CLIENT_STATUS.equals(action)) {
boolean isRunning = intent.getBooleanExtra("isRunning", false);
LogUtils.e("是否正在运行"+isRunning);
if (mSettingDialog != null && mSettingDialog.isShowing()) {
mSettingDialog.setStatus(isRunning);
}
}
}
}

View File

@ -4,8 +4,10 @@ import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Build;
import android.os.IBinder;
@ -58,6 +60,7 @@ public class ServerClient extends Service {
FileUploadHolder fileUploadHolder = new FileUploadHolder();
private AsyncServer mAsyncServer = new AsyncServer();
private AsyncHttpServer server = new AsyncHttpServer();
private PushCastReceiver mReceiver;
public static void start(Context context) {
Intent intent = new Intent(context, ServerClient.class);
@ -87,6 +90,10 @@ public class ServerClient extends Service {
stopSelf();
}
}
IntentFilter filter = new IntentFilter();
filter.addAction(PathConfig.ACTION_GET_CLIENT_STATUS);
mReceiver = new PushCastReceiver();
registerReceiver(mReceiver, filter);
return super.onStartCommand(intent, flags, startId);
}
@ -136,6 +143,13 @@ public class ServerClient extends Service {
if (mAsyncServer != null) {
mAsyncServer.stop();
}
if (mReceiver != null) {
unregisterReceiver(mReceiver);
}
Intent intent = new Intent();
intent.setAction(PathConfig.ACTION_NOTIFY_CLIENT_STATUS);
intent.putExtra("isRunning", false);
sendBroadcast(intent);
}
private void startServer() {
@ -161,6 +175,7 @@ public class ServerClient extends Service {
LogUtils.e("开始监听");
}
private void getAppConfigInfo(AsyncHttpServerRequest asyncHttpServerRequest,
AsyncHttpServerResponse asyncHttpServerResponse) {
try {
@ -438,4 +453,23 @@ public class ServerClient extends Service {
this.totalSize += param1ArrayOfbyte.length;
}
}
public class PushCastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (PathConfig.ACTION_GET_CLIENT_STATUS.equals(action)) {
boolean isRunning = false;
if (mAsyncServer != null) {
isRunning = mAsyncServer.isRunning();
}
Intent newIntent = new Intent();
newIntent.setAction(PathConfig.ACTION_NOTIFY_CLIENT_STATUS);
newIntent.putExtra("isRunning", isRunning);
sendBroadcast(newIntent);
}
}
}
}

View File

@ -89,7 +89,7 @@ dependencies {
api "io.github.razerdp:BasePopup:$rootProject.popup_version"
//
api 'io.github.lucksiege:pictureselector:v2.7.3-rc08'
api 'me.rosuh:AndroidFilePicker:0.7.0-x'
api 'me.rosuh:AndroidFilePicker:0.8.3'
//toast
api 'com.github.getActivity:ToastUtils:9.5'

View File

@ -141,5 +141,8 @@ public class PathConfig {
public static final String MODULE = "4";
public static final String ACTION_ASYNC_SERVER_RUNNING = "com.tenlionsoft.xz_touch.service_running";
public static final String ACTION_ASYNC_SERVER_STOP = "com.tenlionsoft.xz_touch.service_stop";
public static final String ACTION_GET_CLIENT_STATUS = "com.tenlionsoft.xz_touch_service_status";
public static final String ACTION_NOTIFY_CLIENT_STATUS = "com.tenlionsoft.xz_touch_service_status";
}

View File

@ -3,6 +3,7 @@ package com.tenlionsoft.baselib.core.widget.views;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
@ -21,6 +22,9 @@ import androidx.appcompat.widget.SwitchCompat;
import androidx.exifinterface.media.ExifInterface;
import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.constant.PathConfig;
import com.tenlionsoft.baselib.utils.AppUtils;
import com.tenlionsoft.baselib.utils.LogUtils;
import com.tenlionsoft.baselib.utils.NetworkUtils;
import com.tenlionsoft.baselib.utils.SPUtils;
import com.tenlionsoft.baselib.utils.UserLgUtils;
@ -43,11 +47,13 @@ public class BottomSettingView extends Dialog {
public EditText mEtUrl;
public EditText mEtWidth;
public ImageView mIvImg;
public ImageView mIvPing;
private OnChoseListener mListener;
private AppCompatSpinner mSpAppType;
private View view;
public int windowHeight;
public int windowWidth;
private ImageView mIvStatus;
public interface OnChoseListener {
void checkUpdate();
@ -57,6 +63,8 @@ public class BottomSettingView extends Dialog {
void shareWeChart();
void shareWeibo();
void showPing();
}
private BottomSettingView(Context context2) {
@ -99,6 +107,9 @@ public class BottomSettingView extends Dialog {
this.mEtWidth = this.view.findViewById(R.id.et_width);
this.mEtHeight = this.view.findViewById(R.id.et_height);
this.mEtResul = this.view.findViewById(R.id.et_resul);
mIvStatus = this.view.findViewById(R.id.iv_status);
mIvPing = this.view.findViewById(R.id.iv_ping);
mIvPing.setOnClickListener(v -> choseType(5));
setCancelable(false);
setCanceledOnTouchOutside(false);
this.mEtDeviceCode = this.view.findViewById(R.id.et_device_code);
@ -123,6 +134,20 @@ public class BottomSettingView extends Dialog {
window.setBackgroundDrawable(new ColorDrawable());
window.setSoftInputMode(4);
getScreenSize();
//获取服务是否在运行
getServiceIsRunning();
}
private void getServiceIsRunning() {
boolean serviceIsRunning = AppUtils.serviceIsRunning();
LogUtils.e("Service is running " + serviceIsRunning);
if (serviceIsRunning) {
Intent intent = new Intent();
intent.setAction(PathConfig.ACTION_GET_CLIENT_STATUS);
context.sendBroadcast(intent);
} else {
setStatus(false);
}
}
public /* synthetic */ void lambda$onCreate$1$BottomSettingView(View view2) {
@ -155,6 +180,14 @@ public class BottomSettingView extends Dialog {
}
}
public void setStatus(boolean isRunning) {
if (isRunning) {
mIvStatus.setBackgroundResource(R.drawable.ic_running_point);
} else {
mIvStatus.setBackgroundResource(R.drawable.ic_stop_point);
}
}
public void addOnChoseListener(OnChoseListener onChoseListener) {
this.mListener = onChoseListener;
}
@ -192,6 +225,8 @@ public class BottomSettingView extends Dialog {
onChoseListener.shareQQ();
} else if (i == 4) {
onChoseListener.checkUpdate();
} else if (i == 5) {
onChoseListener.showPing();
}
}

View File

@ -0,0 +1,4 @@
package com.tenlionsoft.baselib.core.widget.views;
public class PingDialog {
}

View File

@ -0,0 +1,269 @@
package com.tenlionsoft.baselib.core.widget.views;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import androidx.exifinterface.media.ExifInterface;
import com.hjq.toast.ToastUtils;
import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.utils.UIUtil;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
/**
* 作者 : Adam on 2018/7/23.
* 邮箱 : itgaojian@163.com
* 描述 : ping
*/
public class TopPingView extends Dialog {
public String appType;
private Context context;
private OnChoseListener mListener;
private TextView mTvInfo;
private TextView mTvStart;
private TextView mTvCancel;
private EditText mEtUrl;
private ProgressDialog mDialog;
public interface OnChoseListener {
void checkUpdate();
void shareQQ();
void shareWeChart();
void shareWeibo();
void showPing();
}
private TopPingView(Context context2) {
super(context2, R.style.Dialog_ChoseFile);
this.appType = ExifInterface.GPS_MEASUREMENT_2D;
this.context = context2;
}
/* access modifiers changed from: protected */
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
View view = LayoutInflater.from(this.context).inflate(R.layout.dialog_top_ping, null);
setContentView(view);
setCancelable(false);
setCanceledOnTouchOutside(false);
mTvInfo = view.findViewById(R.id.tv_info);
mEtUrl = view.findViewById(R.id.et_ip);
mTvStart = view.findViewById(R.id.tv_confirm);
mTvCancel = view.findViewById(R.id.tv_cancel);
mTvStart.setOnClickListener(v -> {
String url = mEtUrl.getText().toString().trim();
if (!TextUtils.isEmpty(url)) {
ping(url);
} else {
ToastUtils.show("请输入要ping的网络地址");
}
});
mTvCancel.setOnClickListener(v -> {
hideSoftKeyboard(mEtUrl);
this.dismiss();
});
mDialog = UIUtil.initDialog(context, "执行中...");
Window window = getWindow();
window.setGravity(Gravity.TOP);
window.setWindowAnimations(R.style.Dialog_ChoseFile);
WindowManager.LayoutParams attributes = window.getAttributes();
attributes.width = -1;
attributes.height = -2;
window.setAttributes(attributes);
window.setBackgroundDrawable(new ColorDrawable());
window.setSoftInputMode(4);
}
public void hideSoftKeyboard(View view) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (view != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
private void showSoftKeyBoardDialog(EditText editText) {
if (editText != null) {
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
((InputMethodManager) this.context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(editText
, 0);
}
}
public void addOnChoseListener(OnChoseListener onChoseListener) {
this.mListener = onChoseListener;
}
public void show() {
super.show();
getWindow().clearFlags(131080);
}
public void ping(String url) {
Observable.create((ObservableOnSubscribe<String>) emitter -> {
StringBuilder buffer = new StringBuilder();
String result = ""; // 结果集
Process ping;
try {
ping = Runtime.getRuntime().exec(
"ping -c 4 " + url);
int status = ping.waitFor(); // 状态
InputStream input = ping.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(input));
String line = ""; // 长度
while ((line = in.readLine()) != null) {
buffer.append(line).append("\n");
}
if (status == 0) {
result = buffer.toString();
} else {
result = "网络不通";
}
emitter.onNext(result);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
emitter.onError(new Throwable("程序错误"));
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<String>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
mTvStart.setEnabled(false);
mTvStart.setText("执行中...");
mTvInfo.setText("运行中...");
}
@Override
public void onNext(@NonNull String result) {
mTvInfo.setText(result);
mTvStart.setText("执行");
mTvStart.setEnabled(true);
}
@Override
public void onError(@NonNull Throwable e) {
mTvInfo.setText(e.getMessage());
mTvStart.setText("执行");
mTvStart.setEnabled(true);
}
@Override
public void onComplete() {
mTvInfo.setText("");
mTvStart.setText("执行");
mTvStart.setEnabled(true);
}
});
}
private void choseType(int i) {
OnChoseListener onChoseListener = this.mListener;
if (onChoseListener == null) {
return;
}
if (i == 1) {
onChoseListener.shareWeChart();
} else if (i == 2) {
onChoseListener.shareWeibo();
} else if (i == 3) {
onChoseListener.shareQQ();
} else if (i == 4) {
onChoseListener.checkUpdate();
} else if (i == 5) {
onChoseListener.showPing();
}
}
public static class DialogBuilder {
private boolean isCancelable;
private boolean isCommentImg;
private Context mContext;
private int mGravity = 80;
private boolean mIsBackable;
private boolean mIsShow;
private boolean mIsShowOther;
private OnChoseListener mListener;
public DialogBuilder(Context context) {
this.mContext = context;
}
public DialogBuilder setIscancelable(boolean z) {
this.isCancelable = z;
return this;
}
public DialogBuilder setIsBackCancelable(boolean z) {
this.mIsBackable = z;
return this;
}
public DialogBuilder setShowLocation(int i) {
this.mGravity = i;
return this;
}
public DialogBuilder setIsShowFile(boolean z) {
this.mIsShow = z;
return this;
}
public DialogBuilder setIsShowOther(boolean z) {
this.mIsShowOther = z;
return this;
}
public TopPingView build() {
return new TopPingView(this.mContext);
}
public DialogBuilder setIsShowPhoto(String str) {
if ("0".equals(str)) {
this.isCommentImg = false;
} else {
this.isCommentImg = true;
}
return this;
}
}
}

View File

@ -129,7 +129,7 @@ public final class AppUtils {
.getRunningServices(2147483647)
.iterator();
while (iterator.hasNext()) {
if ("com.tenlionsoft.xzdisplay.push.ServerClient".equals(((ActivityManager.RunningServiceInfo) iterator.next()).service.getClassName()))
if ("com.tenlion.xztouch.push.ServerClient".equals(((ActivityManager.RunningServiceInfo) iterator.next()).service.getClassName()))
return true;
}
return false;

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
@ -13,6 +14,7 @@
android:background="@drawable/shape_rectangle_gray_top_5"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -21,6 +23,7 @@
android:paddingLeft="10dp"
android:paddingRight="10dp">
<com.tenlionsoft.baselib.core.widget.views.TypeFaceTextView
android:id="@+id/tv_close"
android:layout_width="wrap_content"
@ -28,6 +31,7 @@
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:clickable="true"
android:focusable="true"
android:text="关闭应用"
@ -35,11 +39,20 @@
android:textSize="18sp"
app:text_type_cus="3" />
<ImageView
android:id="@+id/iv_status"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
tools:src="@drawable/ic_running_point" />
<ImageView
android:id="@+id/iv_update"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@id/iv_status"
android:clickable="true"
android:focusable="true"
android:scaleType="fitXY"
@ -57,6 +70,21 @@
android:focusable="true"
android:scaleType="fitXY"
android:src="@drawable/ic_setting" />
<ImageView
android:id="@+id/iv_ping"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_gravity="right"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/iv_system_setting"
android:clickable="true"
android:focusable="true"
android:scaleType="fitXY"
android:src="@drawable/ic_ping_link" />
</RelativeLayout>
<androidx.core.widget.NestedScrollView

View File

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:background="@color/transparent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_rectangle_white_rim"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="130dp"
android:background="@drawable/shape_rectangle_gray_border">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
android:hint="运行结果"
android:padding="5dp"
android:textColor="@color/text_detail_24"
android:textColorHint="@color/hint_color"
android:textSize="12dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.tenlionsoft.baselib.core.widget.views.TypeFaceTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="网络地址:"
android:textColor="@color/app_title_9f_no"
android:textSize="16sp"
app:text_type_cus="3" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_bottom_line"
android:minHeight="25dp">
<EditText
android:id="@+id/et_ip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_bottom_line"
android:hint="请输入网络地址"
android:padding="5dp"
android:textColor="@color/text_detail_24"
android:textColorHint="@color/hint_color"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@color/gray_line" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.tenlionsoft.baselib.core.widget.views.TypeFaceTextView
android:id="@+id/tv_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:paddingTop="15dp"
android:paddingBottom="20dp"
android:text="结束"
android:textColor="@color/app_title_9f_no"
android:textSize="16sp"
app:text_type_cus="3" />
<com.tenlionsoft.baselib.core.widget.views.TypeFaceTextView
android:id="@+id/tv_confirm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:paddingTop="15dp"
android:paddingBottom="20dp"
android:text="开始"
android:textColor="@color/app_title_9f_no"
android:textSize="16sp"
app:text_type_cus="3" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</LinearLayout>