Compare commits

..

20 Commits

Author SHA1 Message Date
ZhanGSKen
de1b3657f8 <aes>APK 15.2.3 release Publish. 2025-03-31 02:04:35 +08:00
ZhanGSKen
6b70019208 服务访问属性调整 2025-03-31 02:03:57 +08:00
ZhanGSKen
641cc0d828 <libaes>Library Release 15.2.2 2025-03-31 00:48:11 +08:00
ZhanGSKen
89ee16a69f <aes>APK 15.2.2 release Publish. 2025-03-31 00:47:52 +08:00
ZhanGSKen
4f44034b72 完成服务器连接与断开逻辑 2025-03-31 00:46:16 +08:00
ZhanGSKen
9d37de4bfc 服务连接函数重构 2025-03-30 14:08:17 +08:00
ZhanGSKen
619fd39a92 调整调试信息 2025-03-30 04:08:09 +08:00
ZhanGSKen
d51ebbd550 调试网站状态图标调试完成 2025-03-30 03:59:55 +08:00
ZhanGSKen
d474eb6158 开发站与公开站API接口调试完成 2025-03-30 01:36:24 +08:00
ZhanGSKen
b1e2a018d8 完善应用介绍页UI风格 2025-03-30 01:01:09 +08:00
ZhanGSKen
81d538589f 初步完成服务访问连接 2025-03-29 17:34:01 +08:00
ZhanGSKen
0735783811 <libaes>Library Release 15.2.1 2025-03-29 12:08:10 +08:00
ZhanGSKen
156329707d <aes>APK 15.2.1 release Publish. 2025-03-29 12:07:46 +08:00
ZhanGSKen
3835800d24 类库引用版本调整测试 2025-03-29 12:06:17 +08:00
ZhanGSKen
5d796c4aba <libaes>Library Release 15.2.0 2025-03-29 08:57:51 +08:00
ZhanGSKen
1891c24d4f <aes>APK 15.2.0 release Publish. 2025-03-29 08:57:30 +08:00
ZhanGSKen
892f9f0d6c 开展新命名空间下的版本调试,更新版本号设置 2025-03-29 08:57:03 +08:00
ZhanGSKen
a374d1aada <aes>APK 15.0.9 release Publish. 2025-03-29 08:53:46 +08:00
ZhanGSKen
b9d2778e11 开展新命名空间下的版本调试 2025-03-29 08:52:57 +08:00
ZhanGSKen
43a91575d5 <libaes>Library Release 15.0.8 2025-03-29 08:38:13 +08:00
17 changed files with 484 additions and 136 deletions

View File

@@ -29,7 +29,7 @@ android {
// versionName 更新后需要手动设置
// 项目模块目录的 build.gradle 文件的 stageCount=0
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
versionName "15.0"
versionName "15.2"
if(true) {
versionName = genVersionName("${versionName}")
}

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Sat Mar 29 08:37:50 HKT 2025
stageCount=9
#Mon Mar 31 02:04:35 HKT 2025
stageCount=4
libraryProject=libaes
baseVersion=15.0
publishVersion=15.0.8
baseVersion=15.2
publishVersion=15.2.3
buildCount=0
baseBetaVersion=15.0.9
baseBetaVersion=15.2.4

View File

@@ -10,7 +10,8 @@
android:label="@string/app_name"
android:theme="@style/MyAESTheme"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true">
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config">
<activity
android:name=".MainActivity"

View File

@@ -5,23 +5,25 @@ package cc.winboll.studio.aes;
* @Date 2025/03/24 23:52:29
* @Describe AES应用介绍窗口
*/
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libaes.winboll.APPInfo;
import cc.winboll.studio.libaes.winboll.AboutView;
import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.winboll.IWinBollActivity;
import android.app.Activity;
public class AboutActivity extends AppCompatActivity implements IWinBollActivity {
public class AboutActivity extends WinBollActivity implements IWinBollActivity {
public static final String TAG = "AboutActivity";
Context mContext;
Toolbar mToolbar;
@Override
public Activity getActivity() {
return this;
@@ -36,17 +38,31 @@ public class AboutActivity extends AppCompatActivity implements IWinBollActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity_about);
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mToolbar.setSubtitle(TAG);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
AboutView aboutView = CreateAboutView();
// 在 Activity 的 onCreate 或其他生命周期方法中调用
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
// LinearLayout layout = new LinearLayout(this);
// layout.setOrientation(LinearLayout.VERTICAL);
// // 创建布局参数(宽度和高度)
// ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT
// );
// addContentView(aboutView, params);
LinearLayout layout = findViewById(R.id.aboutviewroot_ll);
// 创建布局参数(宽度和高度)
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
);
addContentView(aboutView, params);
layout.addView(aboutView, params);
GlobalApplication.getWinBollActivityManager().add(this);
}

View File

@@ -17,7 +17,7 @@ public class App extends GlobalApplication {
public void onCreate() {
super.onCreate();
ToastUtils.init(this);
ToastUtils.show("App onCreate");
//ToastUtils.show("App onCreate");
}
}

View File

@@ -57,7 +57,7 @@ public class MainActivity extends DrawerFragmentActivity implements IWinBollActi
}
showFragment(mTestAButtonFragment);
//setSubtitle(TAG);
ToastUtils.show("onCreate");
//ToastUtils.show("onCreate");
}
@Override

View File

@@ -0,0 +1,50 @@
package cc.winboll.studio.aes;
import android.app.Activity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import cc.winboll.studio.libaes.beans.AESThemeBean;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
import cc.winboll.studio.libappbase.winboll.IWinBollActivity;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/03/30 00:34:02
* @Describe WinBoll 活动窗口通用基类
*/
public class WinBollActivity extends AppCompatActivity implements IWinBollActivity {
public static final String TAG = "WinBollActivity";
protected volatile AESThemeBean.ThemeType mThemeType;
@Override
public Activity getActivity() {
return this;
}
@Override
public String getTag() {
return TAG;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
mThemeType = getThemeType();
setThemeStyle();
super.onCreate(savedInstanceState);
}
AESThemeBean.ThemeType getThemeType() {
/*SharedPreferences sharedPreferences = getSharedPreferences(
SHAREDPREFERENCES_NAME, MODE_PRIVATE);
return AESThemeBean.ThemeType.values()[((sharedPreferences.getInt(DRAWER_THEME_TYPE, AESThemeBean.ThemeType.DEFAULT.ordinal())))];
*/
return AESThemeBean.getThemeStyleType(AESThemeUtil.getThemeTypeID(getApplicationContext()));
}
void setThemeStyle() {
//setTheme(AESThemeBean.getThemeStyle(getThemeType()));
setTheme(AESThemeUtil.getThemeTypeID(getApplicationContext()));
}
}

View File

@@ -0,0 +1,22 @@
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<cc.winboll.studio.libaes.views.ASupportToolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0"
android:id="@+id/aboutviewroot_ll"/>
</LinearLayout>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">winboll.cc</domain>
</domain-config>
</network-security-config>

View File

@@ -51,6 +51,6 @@ dependencies {
//api 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
//api 'androidx.fragment:fragment:1.1.0'
api 'cc.winboll.studio:libappbase:15.1.4'
api 'cc.winboll.studio:libapputils:15.0.19'
api 'cc.winboll.studio:libappbase:15.2.0'
api 'cc.winboll.studio:libapputils:15.2.0'
}

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Sat Mar 29 08:37:50 HKT 2025
stageCount=9
#Mon Mar 31 02:04:35 HKT 2025
stageCount=4
libraryProject=libaes
baseVersion=15.0
publishVersion=15.0.8
baseVersion=15.2
publishVersion=15.2.3
buildCount=0
baseBetaVersion=15.0.9
baseBetaVersion=15.2.4

View File

@@ -5,19 +5,26 @@
<application>
<activity android:name="cc.winboll.studio.libaes.unittests.SecondaryLibraryActivity"/>
<activity android:name="cc.winboll.studio.libaes.unittests.SecondaryLibraryActivity"
android:exported="true"/>
<activity android:name="cc.winboll.studio.libaes.unittests.TestDrawerFragmentActivity"/>
<activity android:name="cc.winboll.studio.libaes.unittests.TestDrawerFragmentActivity"
android:exported="true"/>
<activity android:name="cc.winboll.studio.libaes.unittests.TestAToolbarActivity"/>
<activity android:name="cc.winboll.studio.libaes.unittests.TestAToolbarActivity"
android:exported="true"/>
<activity android:name="cc.winboll.studio.libaes.unittests.TestASupportToolbarActivity"/>
<activity android:name="cc.winboll.studio.libaes.unittests.TestASupportToolbarActivity"
android:exported="true"/>
<service android:name="cc.winboll.studio.libaes.winboll.WinBollClientService"/>
<service android:name="cc.winboll.studio.libaes.winboll.WinBollClientService"
android:exported="true"/>
<service android:name="cc.winboll.studio.libaes.winboll.AssistantService"/>
<service android:name="cc.winboll.studio.libaes.winboll.AssistantService"
android:exported="true"/>
<service android:name="cc.winboll.studio.libaes.winboll.WinBollMail"/>
<service android:name="cc.winboll.studio.libaes.winboll.WinBollMail"
android:exported="true"/>
</application>

View File

@@ -27,6 +27,7 @@ import cc.winboll.studio.libaes.beans.AESThemeBean;
import cc.winboll.studio.libaes.beans.DrawerMenuBean;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
import cc.winboll.studio.libaes.views.ADrawerMenuListView;
import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.winboll.IWinBollActivity;
import com.baoyz.widget.PullRefreshLayout;
@@ -175,6 +176,8 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
getString(i);
}
} else if (R.id.item_log == item.getItemId()) {
GlobalApplication.getWinBollActivityManager().startLogActivity(this);
} else if (R.id.item_about == item.getItemId()) {
LogUtils.d(TAG, "onAbout");
} else if (android.R.id.home == item.getItemId()) {

View File

@@ -13,8 +13,10 @@ import android.content.ServiceConnection;
import android.graphics.drawable.Drawable;
import android.os.IBinder;
import cc.winboll.studio.libaes.winboll.AssistantService;
import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.utils.ServiceUtils;
import cc.winboll.studio.libapputils.utils.PrefUtils;
import com.hjq.toast.ToastUtils;
public class WinBollClientService extends Service implements IWinBollClientServiceBinder {
@@ -25,7 +27,7 @@ public class WinBollClientService extends Service implements IWinBollClientServi
MyServiceConnection mMyServiceConnection;
volatile boolean mIsWinBollClientThreadRunning;
volatile boolean mIsEnableService;
WinBollClientThread mWinBollClientThread;
volatile WinBollClientThread mWinBollClientThread;
public boolean isWinBollClientThreadRunning() {
return mIsWinBollClientThreadRunning;
@@ -50,7 +52,7 @@ public class WinBollClientService extends Service implements IWinBollClientServi
@Override
public void onCreate() {
ToastUtils.show("onCreate");
//ToastUtils.show("onCreate");
super.onCreate();
mWinBollClientThread = null;
mWinBollClientServiceBean = WinBollClientServiceBean.loadWinBollClientServiceBean(this);
@@ -66,7 +68,7 @@ public class WinBollClientService extends Service implements IWinBollClientServi
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
ToastUtils.show("onStartCommand");
//ToastUtils.show("onStartCommand");
// 由应用 Intent 启动时,应用可以通过下面函数实例化实际服务进程。
runMainThread();
@@ -78,9 +80,9 @@ public class WinBollClientService extends Service implements IWinBollClientServi
return mIsEnableService ? Service.START_STICKY: super.onStartCommand(intent, flags, startId);
}
void runMainThread() {
synchronized void runMainThread() {
if (mWinBollClientThread == null) {
ToastUtils.show("runMainThread()");
//ToastUtils.show("runMainThread()");
mWinBollClientThread = new WinBollClientThread();
mWinBollClientThread.start();
}
@@ -89,6 +91,7 @@ public class WinBollClientService extends Service implements IWinBollClientServi
void syncWinBollClientThreadStatus() {
mWinBollClientServiceBean = WinBollClientServiceBean.loadWinBollClientServiceBean(this);
mIsEnableService = mWinBollClientServiceBean.isEnable();
LogUtils.d(TAG, String.format("mIsEnableService %s", mIsEnableService));
}
@@ -123,7 +126,7 @@ public class WinBollClientService extends Service implements IWinBollClientServi
@Override
public void onDestroy() {
super.onDestroy();
ToastUtils.show("onDestroy");
//ToastUtils.show("onDestroy");
}
@Override
@@ -153,34 +156,33 @@ public class WinBollClientService extends Service implements IWinBollClientServi
class WinBollClientThread extends Thread {
@Override
public void run() {
//ToastUtils.show("WinBollClientThread");
super.run();
LogUtils.d(TAG, "run syncWinBollClientThreadStatus");
syncWinBollClientThreadStatus();
if (mIsEnableService) {
if (mIsWinBollClientThreadRunning == false) {
// 设置运行状态
mIsWinBollClientThreadRunning = true;
//ToastUtils.show("run()");
LogUtils.d(TAG, "WinBollClientThread run()");
// 唤醒守护进程
//wakeupAndBindAssistant();
while (mIsEnableService) {
// 显示运行状态
ToastUtils.show(TAG + " is running.");
WinBollServiceStatusView.startConnection();
LogUtils.d(TAG, String.format("while mIsEnableService is %s", mIsEnableService));
try {
Thread.sleep(2 * 1000);
Thread.sleep(10 * 1000);
} catch (InterruptedException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
syncWinBollClientThreadStatus();
//ToastUtils.show("syncServiceThreadStatus OK.");
//ToastUtils.show("mIsExist : " + Boolean.toString(!mIsEnableService));
//break;
}
// 服务进程退出, 重置进程运行状态
WinBollServiceStatusView.stopConnection();
mIsWinBollClientThreadRunning = false;
mWinBollClientThread = null;
}

View File

@@ -0,0 +1,106 @@
package cc.winboll.studio.libaes.winboll;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/03/29 15:57:28
* @Describe WinBoll 服务器服务情况测试访问进程。
*/
import cc.winboll.studio.libappbase.LogUtils;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Credentials;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
// 新增自定义回调接口
interface TextCallback {
void onSuccess(String text);
void onFailure(Exception e);
}
public class WinBollServerConnectionThread extends Thread {
public static final String TAG = "WinBollClientService";
private final String url;
private final String username;
private final String password;
private final int connectTimeout;
private final int readTimeout;
private final int maxRetries;
private final TextCallback callback; // 新增回调成员变量
// 新增带回调的构造函数
public WinBollServerConnectionThread(String url, String username, String password, TextCallback callback) {
this(url, username, password, 10000, 10000, 5, callback);
}
// 修改原有构造函数,添加回调参数
public WinBollServerConnectionThread(String url, String username, String password,
int connectTimeout, int readTimeout, int maxRetries, TextCallback callback) {
this.url = url;
this.username = username;
this.password = password;
this.connectTimeout = connectTimeout;
this.readTimeout = readTimeout;
this.maxRetries = maxRetries;
this.callback = callback;
}
@Override
public void run() {
LogUtils.d(TAG, String.format("run() url %s\nusername %s\npassword %s", url, username, password));
String credential = Credentials.basic(username, password);
LogUtils.d(TAG, String.format("credential %s", credential));
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.header("Accept", "text/plain")
.header("Authorization", credential)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// 优先调用自定义回调
if (callback != null) {
callback.onFailure(e);
} else {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (!response.isSuccessful()) {
if (callback != null) {
callback.onFailure(new Exception("Unexpected code " + response));
} else {
LogUtils.d(TAG, "Unexpected code " + response, Thread.currentThread().getStackTrace());
}
return;
}
try {
String text = response.body().string();
// 优先调用自定义回调
if (callback != null) {
callback.onSuccess(text);
} else {
LogUtils.d(TAG, text);
}
} catch (Exception e) {
if (callback != null) {
callback.onFailure(e);
} else {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
}
});
}
}

View File

@@ -18,9 +18,13 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cc.winboll.studio.libaes.winboll.WinBollClientService;
import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.LogUtils;
import com.hjq.toast.ToastUtils;
import cc.winboll.studio.libapputils.R;
import cc.winboll.studio.libapputils.utils.PrefUtils;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
//import okhttp3.Authenticator;
//import okhttp3.Credentials;
//import okhttp3.OkHttpClient;
@@ -35,9 +39,10 @@ public class WinBollServiceStatusView extends LinearLayout {
public static final int MSG_CONNECTION_INFO = 0;
public static final int MSG_UPDATE_CONNECTION_STATUS = 1;
static WinBollServiceStatusView _WinBollServiceStatusView;
Context mContext;
//boolean mIsConnected;
ConnectionThread mConnectionThread;
volatile ConnectionThread mConnectionThread;
String mszServerHost;
WinBollClientService mWinBollService;
@@ -105,6 +110,8 @@ public class WinBollServiceStatusView extends LinearLayout {
}
void initView() {
_WinBollServiceStatusView = this;
mImageView = new ImageView(mContext);
setImageViewByConnection(mImageView, false);
mConnectionStatus = getConnectionStatus();
@@ -115,56 +122,27 @@ public class WinBollServiceStatusView extends LinearLayout {
mViewOnClickListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
//ToastUtils.show("onClick()");
//ToastUtils.show("mWinBollServerHostConnectionStatus : " + mWinBollServerHostConnectionStatus);
//isConnected = !isConnected;
LogUtils.d(TAG, "onClick()");
if (mConnectionStatus == ConnectionStatus.CONNECTED) {
ToastUtils.show("Click to stop service.");
LogUtils.d(TAG, "Click to stop service.");
WinBollClientServiceBean bean = WinBollClientServiceBean.loadWinBollClientServiceBean(mContext);
bean.setIsEnable(false);
WinBollClientServiceBean.saveBean(mContext, bean);
Intent intent = new Intent(mContext, WinBollClientService.class);
mContext.stopService(intent);
//stopConnectionThread();
mTextView.setText("");
setImageViewByConnection(mImageView, false);
mConnectionStatus = ConnectionStatus.DISCONNECTED;
//
/*//ToastUtils.show("CONNECTED");
setConnectionStatusView(false);
mWinBollServerHostConnectionStatusViewHandler.postMessageText("");
if (mConnectionThread != null) {
mConnectionThread.mIsExist = true;
mConnectionThread = null;
mWinBollServerHostConnectionStatus = WinBollServerHostConnectionStatus.DISCONNECTED;
ToastUtils.show("WinBoll Server Disconnected.");
}*/
} else if (mConnectionStatus == ConnectionStatus.DISCONNECTED) {
ToastUtils.show("Click to start service.");
LogUtils.d(TAG, "Click to start service.");
WinBollClientServiceBean bean = WinBollClientServiceBean.loadWinBollClientServiceBean(mContext);
bean.setIsEnable(true);
WinBollClientServiceBean.saveBean(mContext, bean);
Intent intent = new Intent(mContext, WinBollClientService.class);
mContext.startService(intent);
mConnectionStatus = ConnectionStatus.CONNECTED;
ToastUtils.show("startService");
/*//ToastUtils.show("DISCONNECTED");
setConnectionStatusView(true);
if (mConnectionThread == null) {
ToastUtils.show("mConnectionThread == null");
mConnectionThread = new ConnectionThread();
mWinBollServerHostConnectionStatus = WinBollServerHostConnectionStatus.START_CONNECT;
mConnectionThread.start();
}*/
} else {
ToastUtils.show("Other Click condition.");
//startConnectionThread();
}
/*if (isConnected) {
mWebView.loadUrl("https://dev.winboll.cc");
} else {
mWebView.stopLoading();
}*/
//ToastUtils.show(mDevelopHostConnectionStatus);
//LogUtils.d(TAG, "mDevelopHostConnectionStatus : " + mWinBollServerHostConnectionStatus);
}
};
setOnClickListener(mViewOnClickListener);
@@ -210,56 +188,167 @@ public class WinBollServiceStatusView extends LinearLayout {
}
}
void requestWithBasicAuth(WinBollServiceViewHandler textViewHandler, String targetUrl, final String username, final String password) {
// 用户名和密码,替换为实际的认证信息
//String username = "your_username";
//String password = "your_password";
TextCallback apiTextCallback = new TextCallback() {
@Override
public void onSuccess(String text) {
// 处理成功响应
LogUtils.d(TAG, text);
}
// OkHttpClient client = new OkHttpClient.Builder()
// .authenticator(new Authenticator() {
// @Override
// public Request authenticate(Route route, Response response) throws IOException {
// String credential = Credentials.basic(username, password);
// return response.request().newBuilder()
// .header("Authorization", credential)
// .build();
// }
// })
// .build();
//
// Request request = new Request.Builder()
// .url(targetUrl) // 替换为实际要请求的网页地址
// .build();
//
// try {
// Response response = client.newCall(request).execute();
// if (response.isSuccessful()) {
// //System.out.println(response.body().string());
// //ToastUtils.show("Develop Host Connection IP is : " + response.body().string());
// // 获取当前时间
// LocalDateTime now = LocalDateTime.now();
//
// // 定义时间格式
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
// // 按照指定格式格式化时间并输出
// String formattedDateTime = now.format(formatter);
// //System.out.println(formattedDateTime);
// textViewHandler.postMessageText("ClientIP<" + formattedDateTime + ">: " + response.body().string());
// textViewHandler.postMessageConnectionStatus(true);
// } else {
// String sz = "请求失败,状态码: " + response.code();
// setImageViewByConnection(mImageView, false);
// textViewHandler.postMessageText(sz);
// textViewHandler.postMessageConnectionStatus(false);
// LogUtils.d(TAG, sz);
// }
// } catch (IOException e) {
// textViewHandler.postMessageText(e.getMessage());
// textViewHandler.postMessageConnectionStatus(false);
// LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
// }
@Override
public void onFailure(Exception e) {
// 处理失败情况
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
};
TextCallback cipTextCallback = new TextCallback() {
@Override
public void onSuccess(String text) {
// 处理成功响应
LogUtils.d(TAG, text);
LogUtils.d(TAG, "Develop Host Connection IP is : " + text);
mConnectionStatus = ConnectionStatus.CONNECTED;
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 定义时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
// 按照指定格式格式化时间并输出
String formattedDateTime = now.format(formatter);
String msg = "ClientIP<" + formattedDateTime + ">: " + text;
mWinBollServiceViewHandler.postMessageText(msg);
mWinBollServiceViewHandler.postMessageConnectionStatus(true);
}
@Override
public void onFailure(Exception e) {
// 处理失败情况
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
// 处理网络请求失败
setImageViewByConnection(mImageView, false);
mWinBollServiceViewHandler.postMessageText(e.getMessage());
mWinBollServiceViewHandler.postMessageConnectionStatus(false);
}
};
public void requestAPIWithBasicAuth() {
String targetUrl = "https://" + (GlobalApplication.isDebuging() ?"dev.winboll": "winboll") + ".cc/api/"; // 替换为实际测试的URL
requestWithBasicAuth(targetUrl, apiTextCallback);
}
public void requestCIPWithBasicAuth() {
String targetUrl = mszServerHost + "/cip/?simple=true";
requestWithBasicAuth(targetUrl, cipTextCallback);
}
public void requestWithBasicAuth(String targetUrl, TextCallback callback) {
String username = "";
String password = "";
if (GlobalApplication.isDebuging()) {
username = PrefUtils.getString(mContext, "metDevUserName", "");
password = PrefUtils.getString(mContext, "metDevUserPassword", "");
} else {
username = "WinBoll";
password = "WinBollPowerByZhanGSKen";
}
LogUtils.d(TAG, String.format("Connection Start. targetUrl %s", targetUrl));
WinBollServerConnectionThread thread = new WinBollServerConnectionThread(
targetUrl,
username,
password,
cipTextCallback
);
thread.start();
}
/*void requestWithBasicAuth(final WinBollServiceViewHandler textViewHandler, String targetUrl, final String username, final String password) {
// 用户名和密码,替换为实际的认证信息
//String username = "your_username";
//String password = "your_password";
LogUtils.d(TAG, "requestWithBasicAuth(...)");
LogUtils.d(TAG, String.format("targetUrl %s", targetUrl));
// 构建包含认证信息的请求
String credential = Credentials.basic(username, password);
LogUtils.d(TAG, String.format("credential %s", credential));
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(targetUrl)
.header("Accept", "text/plain") // 设置正确的Content-Type头
.header("Authorization", credential)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// 处理网络请求失败
setImageViewByConnection(mImageView, false);
textViewHandler.postMessageText(e.getMessage());
textViewHandler.postMessageConnectionStatus(false);
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
//String sz = "请求失败,状态码: " + response.code();
//setImageViewByConnection(mImageView, false);
//LogUtils.d(TAG, sz);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (!response.isSuccessful()) {
setImageViewByConnection(mImageView, false);
textViewHandler.postMessageText("Unexpected code " + response);
textViewHandler.postMessageConnectionStatus(false);
LogUtils.d(TAG, "Unexpected code " + response, Thread.currentThread().getStackTrace());
return;
}
try {
// 读取响应体作为字符串,注意这里可能需要解码
String text = response.body().string();
LogUtils.d(TAG, "Develop Host Connection IP is : " + text);
mConnectionStatus = ConnectionStatus.CONNECTED;
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 定义时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
// 按照指定格式格式化时间并输出
String formattedDateTime = now.format(formatter);
textViewHandler.postMessageText("ClientIP<" + formattedDateTime + ">: " + text);
textViewHandler.postMessageConnectionStatus(true);
//org.jsoup.nodes.Document doc = org.jsoup.Jsoup.parse(text);
//LogUtils.d(TAG, doc.text());
// 使用id选择器找到具有特定id的元素
//org.jsoup.nodes.Element elementWithId = doc.select("#LastRelease").first(); // 获取第一个匹配的元素
// 提取并打印元素的文本内容
//mszNewestAppPackageName = elementWithId.text();
//ToastUtils.delayedShow(text + "\n" + mszNewestAppPackageName, 5000);
//mHandler.sendMessage(mHandler.obtainMessage(MSG_APPUPDATE_CHECKED));
//System.out.println(response.body().string());
// mConnectionStatus = ConnectionStatus.CONNECTED;
// // 获取当前时间
// LocalDateTime now = LocalDateTime.now();
//
// // 定义时间格式
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
// // 按照指定格式格式化时间并输出
// String formattedDateTime = now.format(formatter);
// //System.out.println(formattedDateTime);
// textViewHandler.postMessageText("ClientIP<" + formattedDateTime + ">: " + response.body().string());
// textViewHandler.postMessageConnectionStatus(true);
} catch (Exception e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
});
}*/
class WinBollServiceViewHandler extends Handler {
WinBollServiceStatusView mDevelopHostConnectionStatusView;
@@ -293,6 +382,48 @@ public class WinBollServiceStatusView extends LinearLayout {
}
}
public static void startConnection() {
if (_WinBollServiceStatusView != null) {
_WinBollServiceStatusView.startConnectionThread();
}
}
public static void stopConnection() {
if (_WinBollServiceStatusView != null) {
_WinBollServiceStatusView.stopConnectionThread();
}
}
void startConnectionThread() {
if (mConnectionStatus == ConnectionStatus.DISCONNECTED) {
mConnectionStatus = ConnectionStatus.START_CONNECT;
LogUtils.d(TAG, "startConnectionThread");
if (mConnectionThread != null) {
LogUtils.d(TAG, "mConnectionThread != null");
mConnectionThread.mIsExist = true;
}
mConnectionThread = new ConnectionThread();
mConnectionThread.start();
} else if (mConnectionStatus == ConnectionStatus.CONNECTING) {
//LogUtils.d(TAG, "mConnectionStatus == ConnectionStatus.CONNECTING");
} else if (mConnectionStatus == ConnectionStatus.CONNECTED) {
//LogUtils.d(TAG, "mConnectionStatus == ConnectionStatus.CONNECTED");
} else {
LogUtils.d(TAG, String.format("Unknow mConnectionStatus %s, can not start ConnectionThread.", mConnectionStatus));
}
}
void stopConnectionThread() {
LogUtils.d(TAG, "stopConnectionThread");
if (mConnectionThread != null) {
LogUtils.d(TAG, "mConnectionThread != null");
mConnectionThread.mIsExist = true;
mConnectionThread = null;
}
}
class ConnectionThread extends Thread {
public volatile boolean mIsExist;
@@ -312,13 +443,14 @@ public class WinBollServiceStatusView extends LinearLayout {
while (mIsExist == false) {
if (mConnectionStatus == ConnectionStatus.START_CONNECT) {
mConnectionStatus = ConnectionStatus.CONNECTING;
ToastUtils.show("WinBoll Server Connection Start.");
//LogUtils.d(TAG, "Develop Host Connection Start.");
String targetUrl = "https://" + mszServerHost + "/cip/?simple=true"; // 这里替换成你实际要访问的网址
requestWithBasicAuth(mWinBollServiceViewHandler, targetUrl, _mUserName, _mPassword);
//requestAPIWithBasicAuth();
requestCIPWithBasicAuth();
} else if (mConnectionStatus == ConnectionStatus.CONNECTED
&& mConnectionStatus == ConnectionStatus.DISCONNECTED) {
ToastUtils.show("mWinBollServerHostConnectionStatus " + mConnectionStatus);
|| mConnectionStatus == ConnectionStatus.DISCONNECTED) {
//ToastUtils.show("mWinBollServerHostConnectionStatus " + mConnectionStatus);
LogUtils.d(TAG, String.format("mConnectionStatus done %s", mConnectionStatus));
} else {
LogUtils.d(TAG, String.format("mConnectionStatus unknow %s", mConnectionStatus));
}
try {

View File

@@ -9,6 +9,9 @@
android:title="TestAppCrash"/>
</menu>
</item>
<item
android:id="@+id/item_log"
android:title="Log"/>
<item
android:id="@+id/item_about"
android:title="About"/>