清理类库的活动窗口类到测试项目文件夹。
This commit is contained in:
parent
888e2c7a4d
commit
9ef0b0894c
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Tue Mar 25 03:48:39 HKT 2025
|
#Fri Mar 28 10:26:29 GMT 2025
|
||||||
stageCount=18
|
stageCount=18
|
||||||
libraryProject=libapputils
|
libraryProject=libapputils
|
||||||
baseVersion=15.0
|
baseVersion=15.0
|
||||||
publishVersion=15.0.17
|
publishVersion=15.0.17
|
||||||
buildCount=0
|
buildCount=6
|
||||||
baseBetaVersion=15.0.18
|
baseBetaVersion=15.0.18
|
||||||
|
@ -31,6 +31,10 @@
|
|||||||
|
|
||||||
<activity android:name=".TestBBMorseCodeActivity"/>
|
<activity android:name=".TestBBMorseCodeActivity"/>
|
||||||
|
|
||||||
|
<activity android:name=".AssetsHtmlActivity"/>
|
||||||
|
|
||||||
|
<activity android:name=".QRCodeDecodeActivity"/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -13,36 +13,6 @@ public class App extends GlobalApplication {
|
|||||||
|
|
||||||
public static final String TAG = "App";
|
public static final String TAG = "App";
|
||||||
|
|
||||||
public static final String _ACTION_DEBUGVIEW = App.class.getName() + "_ACTION_DEBUGVIEW";
|
|
||||||
|
|
||||||
//static volatile WinBollApplication _WinBollApplication = null;
|
|
||||||
//MyActivityLifecycleCallbacks mMyActivityLifecycleCallbacks;
|
|
||||||
|
|
||||||
// 标记当前应用是否处于调试状态
|
|
||||||
static volatile boolean isDebug = false;
|
|
||||||
|
|
||||||
public synchronized static void setIsDebug(boolean isDebug) {
|
|
||||||
App.isDebug = isDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isDebug() {
|
|
||||||
return isDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
// MyActivityLifecycleCallbacks getMyActivityLifecycleCallbacks() {
|
|
||||||
// return mMyActivityLifecycleCallbacks;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Context getApplicationContext() {
|
|
||||||
return super.getApplicationContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Application getApplication() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package cc.winboll.studio.libapputils.activities;
|
package cc.winboll.studio.apputils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen@QQ.COM
|
* @Author ZhanGSKen@QQ.COM
|
||||||
@ -14,12 +14,24 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toolbar;
|
import android.widget.Toolbar;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libapputils.R;
|
import cc.winboll.studio.libappbase.winboll.IWinBollActivity;
|
||||||
|
import cc.winboll.studio.apputils.R;
|
||||||
import cc.winboll.studio.libapputils.view.SimpleWebView;
|
import cc.winboll.studio.libapputils.view.SimpleWebView;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class AssetsHtmlActivity extends Activity {
|
public class AssetsHtmlActivity extends WinBollActivityBase implements IWinBollActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity getActivity() {
|
||||||
|
return super.getActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final String TAG = "AssetsHtmlActivity";
|
public static final String TAG = "AssetsHtmlActivity";
|
||||||
|
|
||||||
@ -54,7 +66,7 @@ public class AssetsHtmlActivity extends Activity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_assetshtml);
|
setContentView(R.layout.activity_assetshtml);
|
||||||
|
|
||||||
// 初始化工具栏
|
// 初始化工具栏
|
||||||
Toolbar mToolbar = findViewById(R.id.toolbar);
|
Toolbar mToolbar = findViewById(R.id.toolbar);
|
||||||
setActionBar(mToolbar);
|
setActionBar(mToolbar);
|
@ -16,10 +16,6 @@ import cc.winboll.studio.apputils.R;
|
|||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.LogView;
|
import cc.winboll.studio.libappbase.LogView;
|
||||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import cc.winboll.studio.libapputils.activities.AssetsHtmlActivity;
|
|
||||||
import cc.winboll.studio.libapputils.activities.LogActivity;
|
|
||||||
import cc.winboll.studio.libapputils.activities.QRCodeDecodeActivity;
|
|
||||||
import cc.winboll.studio.libapputils.view.YesNoAlertDialog;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -149,10 +145,10 @@ final public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onTestLogActivity(View view) {
|
public void onTestLogActivity(View view) {
|
||||||
Intent intent = new Intent(this, LogActivity.class);
|
// Intent intent = new Intent(this, LogActivity.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
// intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||||
startActivity(intent);
|
// startActivity(intent);
|
||||||
|
|
||||||
//WinBollActivityManager.getInstance().printAvtivityListInfo();
|
//WinBollActivityManager.getInstance().printAvtivityListInfo();
|
||||||
//WinBollActivityManager.getInstance(this).startWinBollActivity(this, LogActivity.class);
|
//WinBollActivityManager.getInstance(this).startWinBollActivity(this, LogActivity.class);
|
||||||
@ -209,7 +205,7 @@ final public class MainActivity extends Activity {
|
|||||||
// //ToastUtils.show("mIWinBoll.isAddWinBollToolBar()");
|
// //ToastUtils.show("mIWinBoll.isAddWinBollToolBar()");
|
||||||
// getMenuInflater().inflate(R.menu.toolbar_winboll_shared_main, menu);
|
// getMenuInflater().inflate(R.menu.toolbar_winboll_shared_main, menu);
|
||||||
// }
|
// }
|
||||||
if (App.isDebug()) {
|
if (App.isDebuging()) {
|
||||||
getMenuInflater().inflate(R.menu.toolbar_studio_debug, menu);
|
getMenuInflater().inflate(R.menu.toolbar_studio_debug, menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +215,7 @@ final public class MainActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.item_exit) {
|
if (item.getItemId() == R.id.item_exit) {
|
||||||
exit();
|
//exit();
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.item_teststringtoqrcodeview) {
|
} else if (item.getItemId() == R.id.item_teststringtoqrcodeview) {
|
||||||
Intent intent = new Intent(this, TestStringToQRCodeViewActivity.class);
|
Intent intent = new Intent(this, TestStringToQRCodeViewActivity.class);
|
||||||
@ -246,21 +242,21 @@ final public class MainActivity extends Activity {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit() {
|
// void exit() {
|
||||||
YesNoAlertDialog.OnDialogResultListener listener = new YesNoAlertDialog.OnDialogResultListener(){
|
// YesNoAlertDialog.OnDialogResultListener listener = new YesNoAlertDialog.OnDialogResultListener(){
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void onYes() {
|
// public void onYes() {
|
||||||
//WinBollActivityManager.getInstance(getApplicationContext()).finishAll();
|
// //WinBollActivityManager.getInstance(getApplicationContext()).finishAll();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void onNo() {
|
// public void onNo() {
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
YesNoAlertDialog.show(this, "[ " + getString(R.string.app_name) + " ]", "Exit(Yes/No).\nIs close all activity?", listener);
|
// YesNoAlertDialog.show(this, "[ " + getString(R.string.app_name) + " ]", "Exit(Yes/No).\nIs close all activity?", listener);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package cc.winboll.studio.libapputils.activities;
|
package cc.winboll.studio.apputils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen@QQ.COM
|
* @Author ZhanGSKen@QQ.COM
|
||||||
@ -11,7 +11,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toolbar;
|
import android.widget.Toolbar;
|
||||||
import cc.winboll.studio.libapputils.R;
|
import cc.winboll.studio.apputils.R;
|
||||||
import com.google.zxing.ResultPoint;
|
import com.google.zxing.ResultPoint;
|
||||||
import com.journeyapps.barcodescanner.BarcodeCallback;
|
import com.journeyapps.barcodescanner.BarcodeCallback;
|
||||||
import com.journeyapps.barcodescanner.BarcodeResult;
|
import com.journeyapps.barcodescanner.BarcodeResult;
|
||||||
@ -41,7 +41,7 @@ public class QRCodeDecodeActivity extends Activity {
|
|||||||
// 初始化工具栏
|
// 初始化工具栏
|
||||||
// Toolbar mToolbar = findViewById(R.id.toolbar);
|
// Toolbar mToolbar = findViewById(R.id.toolbar);
|
||||||
// setActionBar(mToolbar);
|
// setActionBar(mToolbar);
|
||||||
|
|
||||||
//resultTextView = findViewById(R.id.activityqrcodedecodeTextView1);
|
//resultTextView = findViewById(R.id.activityqrcodedecodeTextView1);
|
||||||
barcodeView = findViewById(R.id.activityqrcodedecodeDecoratedBarcodeView1);
|
barcodeView = findViewById(R.id.activityqrcodedecodeDecoratedBarcodeView1);
|
||||||
// 请求相机权限
|
// 请求相机权限
|
@ -0,0 +1,52 @@
|
|||||||
|
package cc.winboll.studio.apputils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/03/28 17:11:37
|
||||||
|
* @Describe 应用活动窗口基类
|
||||||
|
*/
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
|
import cc.winboll.studio.libappbase.winboll.IWinBollActivity;
|
||||||
|
import cc.winboll.studio.libappbase.winboll.WinBollActivityManager;
|
||||||
|
|
||||||
|
public class WinBollActivityBase extends AppCompatActivity implements IWinBollActivity {
|
||||||
|
|
||||||
|
public static final String TAG = "WinBollActivityBase";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity getActivity() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
WinBollActivityManager getWinBollActivityManager() {
|
||||||
|
return WinBollActivityManager.getInstance(GlobalApplication.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
getWinBollActivityManager().add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
|
||||||
|
super.onPostCreate(savedInstanceState, persistentState);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
getWinBollActivityManager().registeRemove(this);
|
||||||
|
}
|
||||||
|
}
|
21
apputils/src/main/res/layout/activity_assetshtml.xml
Normal file
21
apputils/src/main/res/layout/activity_assetshtml.xml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<android.widget.Toolbar
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/toolbar"/>
|
||||||
|
|
||||||
|
<cc.winboll.studio.libapputils.view.SimpleWebView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1.0"
|
||||||
|
android:id="@+id/activityassetshtmlSimpleWebView1"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
20
apputils/src/main/res/layout/activity_qrcodedecode.xml
Normal file
20
apputils/src/main/res/layout/activity_qrcodedecode.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="QRCodeDecodeActivity"/>
|
||||||
|
|
||||||
|
<com.journeyapps.barcodescanner.DecoratedBarcodeView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/activityqrcodedecodeDecoratedBarcodeView1"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -8,7 +8,7 @@ android {
|
|||||||
buildToolsVersion "32.0.0"
|
buildToolsVersion "32.0.0"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 26
|
minSdkVersion 24
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@ -21,6 +21,28 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
// Android 类库
|
||||||
|
//api 'com.android.support:appcompat-v7:28.0.0'
|
||||||
|
api('com.android.support:appcompat-v7:28.0.0'){
|
||||||
|
//exclude group: "com.android.support", module: "support-vector-drawable"
|
||||||
|
exclude group: "com.android.support:animated-vector-drawable:28.0.0"
|
||||||
|
}
|
||||||
|
// https://mvnrepository.com/artifact/com.android.support/support-compat
|
||||||
|
//api 'com.android.support:support-compat:28.0.0' // 保留原有依赖(可选)
|
||||||
|
// https://mvnrepository.com/artifact/com.android.support/support-v4
|
||||||
|
api 'com.android.support:support-v4:28.0.0'
|
||||||
|
// https://mvnrepository.com/artifact/com.android.support/support-media-compat
|
||||||
|
api 'com.android.support:support-media-compat:28.0.0'
|
||||||
|
// https://mvnrepository.com/artifact/com.android.support/support-core-utils
|
||||||
|
api 'com.android.support:support-core-utils:28.0.0'
|
||||||
|
// https://mvnrepository.com/artifact/com.android.support/support-core-ui
|
||||||
|
api 'com.android.support:support-core-ui:28.0.0'
|
||||||
|
// https://mvnrepository.com/artifact/com.android.support/support-fragment
|
||||||
|
api 'com.android.support:support-fragment:28.0.0'
|
||||||
|
// https://mvnrepository.com/artifact/com.android.support/recyclerview-v7
|
||||||
|
api 'com.android.support:recyclerview-v7:28.0.0'
|
||||||
|
|
||||||
|
api 'cc.winboll.studio:libappbase:15.1.3'
|
||||||
|
|
||||||
// 二维码类库
|
// 二维码类库
|
||||||
api 'com.google.zxing:core:3.4.1'
|
api 'com.google.zxing:core:3.4.1'
|
||||||
@ -34,6 +56,4 @@ dependencies {
|
|||||||
|
|
||||||
// SSH
|
// SSH
|
||||||
//api 'com.jcraft:jsch:0.1.55'
|
//api 'com.jcraft:jsch:0.1.55'
|
||||||
|
|
||||||
api 'cc.winboll.studio:libappbase:15.0.10'
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Tue Mar 25 03:48:30 HKT 2025
|
#Fri Mar 28 10:26:29 GMT 2025
|
||||||
stageCount=18
|
stageCount=18
|
||||||
libraryProject=libapputils
|
libraryProject=libapputils
|
||||||
baseVersion=15.0
|
baseVersion=15.0
|
||||||
publishVersion=15.0.17
|
publishVersion=15.0.17
|
||||||
buildCount=0
|
buildCount=6
|
||||||
baseBetaVersion=15.0.18
|
baseBetaVersion=15.0.18
|
||||||
|
@ -24,29 +24,11 @@
|
|||||||
<application
|
<application
|
||||||
android:networkSecurityConfig="@xml/network_security_config">
|
android:networkSecurityConfig="@xml/network_security_config">
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".app.CrashHandler$CrashActiviy"
|
|
||||||
android:label="CrashActiviy"
|
|
||||||
android:launchMode="standard"/>
|
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".activities.LogActivity"
|
|
||||||
android:label="LogActivity"
|
|
||||||
android:launchMode="standard"/>
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.AboutActivity"
|
android:name=".activities.AboutActivity"
|
||||||
android:label="AboutActivity"
|
android:label="AboutActivity"
|
||||||
android:launchMode="standard"/>
|
android:launchMode="standard"/>
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".activities.AssetsHtmlActivity"
|
|
||||||
android:label="AssetsHtmlActivity"/>
|
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".activities.QRCodeDecodeActivity"
|
|
||||||
android:label="QRCodeDecodeActivity"/>
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
package cc.winboll.studio.libapputils.activities;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen@AliYun.Com
|
|
||||||
* @Date 2025/03/08 00:19:39
|
|
||||||
* @Describe LogActivity
|
|
||||||
*/
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
|
||||||
import cc.winboll.studio.libappbase.LogView;
|
|
||||||
import cc.winboll.studio.libapputils.R;
|
|
||||||
|
|
||||||
public class LogActivity extends Activity {
|
|
||||||
|
|
||||||
public static final String TAG = "LogActivity";
|
|
||||||
|
|
||||||
LogView mLogView;
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public Activity getActivity() {
|
|
||||||
// return this;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
LogUtils.d(TAG, "onCreate");
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_log);
|
|
||||||
mLogView = findViewById(R.id.logview);
|
|
||||||
mLogView.start();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
LogUtils.d(TAG, "onResume");
|
|
||||||
super.onResume();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,161 +0,0 @@
|
|||||||
package cc.winboll.studio.libapputils.app;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen@QQ.COM
|
|
||||||
* @Date 2024/08/12 14:45:35
|
|
||||||
* @Describe 应用版本工具集
|
|
||||||
*/
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class AppVersionUtils {
|
|
||||||
|
|
||||||
public static final String TAG = "AppVersionUtils";
|
|
||||||
|
|
||||||
//
|
|
||||||
// 检查新版本是否成立
|
|
||||||
// szCurrentCode : 当前版本应用包名
|
|
||||||
// szNextCode : 新版本应用包名
|
|
||||||
// 返回 :情况1:当前版本是发布版
|
|
||||||
// 返回 true (新版本 > 当前版本)
|
|
||||||
// 情况1:当前版本是Beta版
|
|
||||||
// true 新版本 == 当前版本
|
|
||||||
//
|
|
||||||
public static boolean isHasNewVersion2(String szCurrentName, String szNextName) {
|
|
||||||
LogUtils.d(TAG, String.format("isHasNewVersion2\nszCurrentName : %s\nszNextName : %s", szCurrentName, szNextName));
|
|
||||||
//szCurrentName = "AES_6.2.0-beta0_3234.apk";
|
|
||||||
//szNextName = "AES_6.1.12.apk";
|
|
||||||
//szCurrentName = "AES_6.2.0-beta0_3234.apk";
|
|
||||||
//szNextName = "AES_6.2.0.apk";
|
|
||||||
//szCurrentName = "AES_6.2.0-beta0_3234.apk";
|
|
||||||
//szNextName = "AES_6.2.2.apk";
|
|
||||||
//szCurrentName = "AES_6.2.0-beta0_3234.apk";
|
|
||||||
//szNextName = "AES_6.2.0.apk";
|
|
||||||
//szCurrentName = "AES_6.1.0.apk";
|
|
||||||
//szNextName = "AES_6.2.0.apk";
|
|
||||||
//LogUtils.d(TAG, "szCurrentName : " + szCurrentName);
|
|
||||||
//LogUtils.d(TAG, "szNextName : " + szNextName);
|
|
||||||
|
|
||||||
//boolean isVersionNewer = false;
|
|
||||||
//if(szCurrentName.equals(szNextName)) {
|
|
||||||
// isVersionNewer = false;
|
|
||||||
//} else {
|
|
||||||
//ToastUtils.show("szCurrent : " + szCurrent + "\nszNext : " + szNext);
|
|
||||||
//int nApk = szNextName.lastIndexOf(".apk");
|
|
||||||
//ToastUtils.show("nApk : " + Integer.toString(nApk));
|
|
||||||
//String szNextNoApkName = szNextName.substring(0, nApk);
|
|
||||||
//ToastUtils.show("szNextNoApkName : " + szNextNoApkName);
|
|
||||||
//String szCurrentNoApkName = szCurrentName.substring(0, szNextNoApkName.length());
|
|
||||||
//ToastUtils.show("szCurrentNoApkName : " + szCurrentNoApkName);
|
|
||||||
//String str1 = "3.4.50";
|
|
||||||
//String str2 = "3.3.60";
|
|
||||||
//String str1 = getCodeInPackageName(szCurrentName);
|
|
||||||
//String str2 = getCodeInPackageName(szNextName);
|
|
||||||
//String str1 = getCodeInPackageName(szNextName);
|
|
||||||
//String str2 = getCodeInPackageName(szCurrentName);
|
|
||||||
//Boolean isVersionNewer2 = checkNewVersion(str1,str2);
|
|
||||||
//ToastUtils.show("isVersionNewer2 : " + Boolean.toString(isVersionNewer2));
|
|
||||||
//ToastUtils.show(checkNewVersion(getCodeInPackageName(szCurrentName), getCodeInPackageName(szNextName)));
|
|
||||||
//return checkNewVersion(getCodeInPackageName(szCurrentName), getCodeInPackageName(szNextName));
|
|
||||||
//}
|
|
||||||
//return isVersionNewer;
|
|
||||||
if (checkNewVersion(getCodeInPackageName(szCurrentName), getCodeInPackageName(szNextName))) {
|
|
||||||
// 比 AES_6.2.0.apk 版本大,如 AES_6.2.1.apk。
|
|
||||||
// 比 AES_6.2.0-beta0_3234.apk 大,如 AES_6.2.1.apk。
|
|
||||||
//LogUtils.d(TAG, "App newer stage version is released. Release name : " + szNextName);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (szCurrentName.matches(".*_\\d+\\.\\d+\\.\\d+-beta.*\\.apk")) {
|
|
||||||
String szCurrentReleasePackageName = getReleasePackageName(szCurrentName);
|
|
||||||
//LogUtils.d(TAG, "szCurrentReleasePackageName : " + szCurrentReleasePackageName);
|
|
||||||
if (szCurrentReleasePackageName.equals(szNextName)) {
|
|
||||||
// 与 AES_6.2.0-beta0_3234.apk 版本相同,如 AES_6.2.0.apk。
|
|
||||||
//LogUtils.d(TAG, "App stage version is released. Release name : " + szNextName);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//LogUtils.d(TAG, "App version is the newest. ");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isHasNewStageReleaseVersion(String szCurrentName, String szNextName) {
|
|
||||||
LogUtils.d(TAG, String.format("isHasNewStageReleaseVersion\nszCurrentName : %s\nszNextName : %s", szCurrentName, szNextName));
|
|
||||||
//szCurrentName = "AES_6.2.12.apk";
|
|
||||||
//szNextName = "AES_6.3.12.apk";
|
|
||||||
if (checkNewVersion(getCodeInPackageName(szCurrentName), getCodeInPackageName(szNextName))) {
|
|
||||||
// 比 AES_6.2.0.apk 版本大,如 AES_6.2.1.apk。
|
|
||||||
//LogUtils.d(TAG, "App newer stage version is released. Release name : " + szNextName);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// 检查新版本是否成立
|
|
||||||
// szCurrentCode : 当前版本
|
|
||||||
// szNextCode : 新版本
|
|
||||||
// 返回 :true 新版本 > 当前版本
|
|
||||||
//
|
|
||||||
public static Boolean checkNewVersion(String szCurrentCode, String szNextCode) {
|
|
||||||
if (szCurrentCode == null || szCurrentCode.equals("") || szNextCode == null || szNextCode.equals("")) {
|
|
||||||
LogUtils.d(TAG, String.format("checkNewVersion unexpected parameters:\nszCurrentCode : %s\nszNextCode : %s", szCurrentCode, szNextCode));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
boolean isNew = false;
|
|
||||||
String[] appVersionCurrent = szCurrentCode.split("\\.");
|
|
||||||
String[] appVersionNext = szNextCode.split("\\.");
|
|
||||||
//根据位数最短的判断
|
|
||||||
int lim = appVersionCurrent.length > appVersionNext.length ? appVersionNext.length : appVersionCurrent.length;
|
|
||||||
//根据位数循环判断各个版本
|
|
||||||
for (int i = 0; i < lim; i++) {
|
|
||||||
if (Integer.parseInt(appVersionNext[i]) > Integer.parseInt(appVersionCurrent[i])) {
|
|
||||||
isNew = true;
|
|
||||||
return isNew;
|
|
||||||
} else if (Integer.parseInt(appVersionNext[i]) == Integer.parseInt(appVersionCurrent[i])) {
|
|
||||||
continue ;
|
|
||||||
} else {
|
|
||||||
isNew = false;
|
|
||||||
return isNew;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isNew;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// 截取应用包名称版本号信息
|
|
||||||
// 如 :AppUtils_7.0.4-beta1_0120.apk 版本号为 7.0.4
|
|
||||||
// 如 :AppUtils_7.0.4.apk 版本号为 7.0.4
|
|
||||||
//
|
|
||||||
public static String getCodeInPackageName(String apkName) {
|
|
||||||
LogUtils.d(TAG, String.format("getCodeInPackageName apkName : %s", apkName));
|
|
||||||
//String apkName = "AppUtils_7.0.0.apk";
|
|
||||||
Pattern pattern = Pattern.compile("\\d+\\.\\d+\\.\\d+");
|
|
||||||
Matcher matcher = pattern.matcher(apkName);
|
|
||||||
if (matcher.find()) {
|
|
||||||
String version = matcher.group();
|
|
||||||
LogUtils.d(TAG, String.format("version is %s", version));
|
|
||||||
return version;
|
|
||||||
//System.out.println("Version number: " + version); // 输出:7.0.0
|
|
||||||
}
|
|
||||||
LogUtils.d(TAG, String.format("No result."));
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// 根据Beta版名称生成发布版应用包名称
|
|
||||||
// 如 AppUtils_7.0.4-beta1_0120.apk
|
|
||||||
// 发布版名称就为AppUtils_7.0.4.apk
|
|
||||||
//
|
|
||||||
public static String getReleasePackageName(String szBetaPackageName) {
|
|
||||||
//String szBetaPackageName = "AppUtils_7.0.4-beta1_0120.apk";
|
|
||||||
Pattern pattern = Pattern.compile(".*\\d+\\.\\d+\\.\\d+");
|
|
||||||
Matcher matcher = pattern.matcher(szBetaPackageName);
|
|
||||||
if (matcher.find()) {
|
|
||||||
String szReleasePackageName = matcher.group();
|
|
||||||
return szReleasePackageName + ".apk";
|
|
||||||
//System.out.println("Version number: " + version); // 输出:7.0.0
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,215 +0,0 @@
|
|||||||
package cc.winboll.studio.libapputils.app;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen@QQ.COM
|
|
||||||
* @Date 2024/08/12 13:22:12
|
|
||||||
* @Describe 异常处理类
|
|
||||||
*/
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Application;
|
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.ClipData;
|
|
||||||
import android.content.ClipboardManager;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.HorizontalScrollView;
|
|
||||||
import android.widget.ScrollView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.lang.Thread.UncaughtExceptionHandler;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public final class CrashHandler {
|
|
||||||
|
|
||||||
public static final UncaughtExceptionHandler DEFAULT_UNCAUGHT_EXCEPTION_HANDLER = Thread.getDefaultUncaughtExceptionHandler();
|
|
||||||
|
|
||||||
public static void init(Application app) {
|
|
||||||
init(app, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init(final Application app, final String crashDir) {
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(){
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void uncaughtException(Thread thread, Throwable throwable) {
|
|
||||||
try {
|
|
||||||
tryUncaughtException(thread, throwable);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null)
|
|
||||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tryUncaughtException(Thread thread, Throwable throwable) {
|
|
||||||
final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss", Locale.getDefault()).format(new Date());
|
|
||||||
File crashFile = new File(TextUtils.isEmpty(crashDir) ? new File(app.getExternalFilesDir(null), "crash")
|
|
||||||
: new File(crashDir), "crash_" + time + ".txt");
|
|
||||||
|
|
||||||
String versionName = "unknown";
|
|
||||||
long versionCode = 0;
|
|
||||||
try {
|
|
||||||
PackageInfo packageInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0);
|
|
||||||
versionName = packageInfo.versionName;
|
|
||||||
versionCode = Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode()
|
|
||||||
: packageInfo.versionCode;
|
|
||||||
} catch (PackageManager.NameNotFoundException ignored) {}
|
|
||||||
|
|
||||||
String fullStackTrace; {
|
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
|
||||||
throwable.printStackTrace(pw);
|
|
||||||
fullStackTrace = sw.toString();
|
|
||||||
pw.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("************* Crash Head ****************\n");
|
|
||||||
sb.append("Time Of Crash : ").append(time).append("\n");
|
|
||||||
sb.append("Device Manufacturer: ").append(Build.MANUFACTURER).append("\n");
|
|
||||||
sb.append("Device Model : ").append(Build.MODEL).append("\n");
|
|
||||||
sb.append("Android Version : ").append(Build.VERSION.RELEASE).append("\n");
|
|
||||||
sb.append("Android SDK : ").append(Build.VERSION.SDK_INT).append("\n");
|
|
||||||
sb.append("App VersionName : ").append(versionName).append("\n");
|
|
||||||
sb.append("App VersionCode : ").append(versionCode).append("\n");
|
|
||||||
sb.append("************* Crash Head ****************\n");
|
|
||||||
sb.append("\n").append(fullStackTrace);
|
|
||||||
|
|
||||||
String errorLog = sb.toString();
|
|
||||||
|
|
||||||
try {
|
|
||||||
writeFile(crashFile, errorLog);
|
|
||||||
} catch (IOException ignored) {}
|
|
||||||
|
|
||||||
gotoCrashActiviy: {
|
|
||||||
Intent intent = new Intent(app, CrashActiviy.class);
|
|
||||||
intent.addFlags(
|
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
||||||
);
|
|
||||||
intent.putExtra(CrashActiviy.EXTRA_CRASH_INFO, errorLog);
|
|
||||||
try {
|
|
||||||
app.startActivity(intent);
|
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
|
||||||
System.exit(0);
|
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null)
|
|
||||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeFile(File file, String content) throws IOException {
|
|
||||||
File parentFile = file.getParentFile();
|
|
||||||
if (parentFile != null && !parentFile.exists()) {
|
|
||||||
parentFile.mkdirs();
|
|
||||||
}
|
|
||||||
file.createNewFile();
|
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
|
||||||
fos.write(content.getBytes());
|
|
||||||
try {
|
|
||||||
fos.close();
|
|
||||||
} catch (IOException e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class CrashActiviy extends Activity implements MenuItem.OnMenuItemClickListener {
|
|
||||||
|
|
||||||
private static final String EXTRA_CRASH_INFO = "crashInfo";
|
|
||||||
|
|
||||||
private static final int MENUITEM_COPY = 0;
|
|
||||||
private static final int MENUITEM_RESTART = 1;
|
|
||||||
|
|
||||||
private String mLog;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO);
|
|
||||||
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
|
||||||
setContentView: {
|
|
||||||
ScrollView contentView = new ScrollView(this);
|
|
||||||
contentView.setFillViewport(true);
|
|
||||||
HorizontalScrollView hw = new HorizontalScrollView(this);
|
|
||||||
hw.setBackgroundColor(Color.GRAY);
|
|
||||||
TextView message = new TextView(this); {
|
|
||||||
int padding = dp2px(16);
|
|
||||||
message.setPadding(padding, padding, padding, padding);
|
|
||||||
message.setText(mLog);
|
|
||||||
message.setTextIsSelectable(true);
|
|
||||||
}
|
|
||||||
hw.addView(message);
|
|
||||||
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
||||||
setContentView(contentView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackPressed() {
|
|
||||||
restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void restart() {
|
|
||||||
PackageManager pm = getPackageManager();
|
|
||||||
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
|
|
||||||
if (intent != null) {
|
|
||||||
intent.addFlags(
|
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
||||||
);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
finish();
|
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int dp2px(final float dpValue) {
|
|
||||||
final float scale = Resources.getSystem().getDisplayMetrics().density;
|
|
||||||
return (int) (dpValue * scale + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case MENUITEM_COPY:
|
|
||||||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
|
||||||
break;
|
|
||||||
case MENUITEM_RESTART:
|
|
||||||
restart();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
menu.add(0, MENUITEM_COPY, 0, "Copy").setOnMenuItemClickListener(this)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
|
||||||
menu.add(0, MENUITEM_RESTART, 0, "Restart").setOnMenuItemClickListener(this)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -10,7 +10,6 @@ import android.media.MediaPlayer;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.os.VibratorManager;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -1,346 +0,0 @@
|
|||||||
package cc.winboll.studio.libapputils.view;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen@QQ.COM
|
|
||||||
* @Date 2024/12/07 20:15:47
|
|
||||||
* @Describe WinBoll 服务主机连接状态视图
|
|
||||||
*/
|
|
||||||
import cc.winboll.studio.libapputils.R;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.ServiceConnection;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
|
||||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
|
||||||
import cc.winboll.studio.libapputils.service.IWinBollClientServiceBinder;
|
|
||||||
import cc.winboll.studio.libapputils.service.WinBollClientService;
|
|
||||||
import cc.winboll.studio.libapputils.service.WinBollClientServiceBean;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
//import okhttp3.Authenticator;
|
|
||||||
//import okhttp3.Credentials;
|
|
||||||
//import okhttp3.OkHttpClient;
|
|
||||||
//import okhttp3.Request;
|
|
||||||
//import okhttp3.Response;
|
|
||||||
//import okhttp3.Route;
|
|
||||||
|
|
||||||
public class WinBollServiceStatusView extends LinearLayout {
|
|
||||||
|
|
||||||
public static final String TAG = "WinBollServiceStatusView";
|
|
||||||
|
|
||||||
public static final int MSG_CONNECTION_INFO = 0;
|
|
||||||
public static final int MSG_UPDATE_CONNECTION_STATUS = 1;
|
|
||||||
|
|
||||||
Context mContext;
|
|
||||||
//boolean mIsConnected;
|
|
||||||
ConnectionThread mConnectionThread;
|
|
||||||
|
|
||||||
String mszServerHost;
|
|
||||||
WinBollClientService mWinBollService;
|
|
||||||
ImageView mImageView;
|
|
||||||
TextView mTextView;
|
|
||||||
WinBollServiceViewHandler mWinBollServiceViewHandler;
|
|
||||||
//WebView mWebView;
|
|
||||||
static volatile ConnectionStatus mConnectionStatus;
|
|
||||||
View.OnClickListener mViewOnClickListener;
|
|
||||||
static String _mUserName;
|
|
||||||
static String _mPassword;
|
|
||||||
|
|
||||||
static enum ConnectionStatus {
|
|
||||||
DISCONNECTED,
|
|
||||||
START_CONNECT,
|
|
||||||
CONNECTING,
|
|
||||||
CONNECTED;
|
|
||||||
};
|
|
||||||
|
|
||||||
boolean isBound = false;
|
|
||||||
ServiceConnection connection = new ServiceConnection() {
|
|
||||||
@Override
|
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
||||||
IWinBollClientServiceBinder binder = (IWinBollClientServiceBinder) service;
|
|
||||||
mWinBollService = binder.getService();
|
|
||||||
isBound = true;
|
|
||||||
// 可以在这里调用Service的方法进行通信,比如获取数据
|
|
||||||
mImageView.setBackgroundDrawable(mWinBollService.getCurrentStatusIconDrawable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
|
||||||
isBound = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public WinBollServiceStatusView(Context context) {
|
|
||||||
super(context);
|
|
||||||
mContext = context;
|
|
||||||
initView();
|
|
||||||
}
|
|
||||||
|
|
||||||
public WinBollServiceStatusView(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
mContext = context;
|
|
||||||
initView();
|
|
||||||
}
|
|
||||||
|
|
||||||
public WinBollServiceStatusView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
mContext = context;
|
|
||||||
initView();
|
|
||||||
}
|
|
||||||
|
|
||||||
public WinBollServiceStatusView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
mContext = context;
|
|
||||||
initView();
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectionStatus getConnectionStatus() {
|
|
||||||
return false ?
|
|
||||||
ConnectionStatus.CONNECTED
|
|
||||||
: ConnectionStatus.DISCONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
void initView() {
|
|
||||||
mImageView = new ImageView(mContext);
|
|
||||||
setImageViewByConnection(mImageView, false);
|
|
||||||
mConnectionStatus = getConnectionStatus();
|
|
||||||
//mIsConnected = false;
|
|
||||||
//mWinBollServerHostConnectionStatus = WinBollServerHostConnectionStatus.DISCONNECTED;
|
|
||||||
//ToastUtils.show("initView()");
|
|
||||||
|
|
||||||
mViewOnClickListener = new View.OnClickListener(){
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
//ToastUtils.show("onClick()");
|
|
||||||
//ToastUtils.show("mWinBollServerHostConnectionStatus : " + mWinBollServerHostConnectionStatus);
|
|
||||||
//isConnected = !isConnected;
|
|
||||||
if (mConnectionStatus == ConnectionStatus.CONNECTED) {
|
|
||||||
ToastUtils.show("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);
|
|
||||||
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.");
|
|
||||||
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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*if (isConnected) {
|
|
||||||
mWebView.loadUrl("https://dev.winboll.cc");
|
|
||||||
} else {
|
|
||||||
mWebView.stopLoading();
|
|
||||||
}*/
|
|
||||||
//ToastUtils.show(mDevelopHostConnectionStatus);
|
|
||||||
//LogUtils.d(TAG, "mDevelopHostConnectionStatus : " + mWinBollServerHostConnectionStatus);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
setOnClickListener(mViewOnClickListener);
|
|
||||||
addView(mImageView);
|
|
||||||
mTextView = new TextView(mContext);
|
|
||||||
mWinBollServiceViewHandler = new WinBollServiceViewHandler(this);
|
|
||||||
addView(mTextView);
|
|
||||||
/*mWebView = new WebView(mContext);
|
|
||||||
mWebView.setWebViewClient(new WebViewClient() {
|
|
||||||
@Override
|
|
||||||
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
|
|
||||||
// 弹出系统基本HTTP验证窗口
|
|
||||||
handler.proceed("username", "password");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
addView(mWebView);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkWinBollServerStatusAndUpdateCurrentView() {
|
|
||||||
LogUtils.d(TAG, "checkWinBollServerStatusAndUpdateCurrentView()");
|
|
||||||
/*if (getConnectionStatus() == ConnectionStatus.CONNECTED) {
|
|
||||||
mConnectionStatus = ConnectionStatus.CONNECTED;
|
|
||||||
} else {
|
|
||||||
mConnectionStatus = ConnectionStatus.DISCONNECTED;
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServerHost(String szWinBollServerHost) {
|
|
||||||
mszServerHost = szWinBollServerHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthInfo(String username, String password) {
|
|
||||||
_mUserName = username;
|
|
||||||
_mPassword = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setImageViewByConnection(ImageView imageView, boolean isConnected) {
|
|
||||||
//mIsConnected = isConnected;
|
|
||||||
// 获取vector drawable
|
|
||||||
Drawable drawable = mContext.getDrawable(isConnected ? R.drawable.ic_dev_connected : R.drawable.ic_dev_disconnected);
|
|
||||||
if (drawable != null) {
|
|
||||||
imageView.setImageDrawable(drawable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void requestWithBasicAuth(WinBollServiceViewHandler textViewHandler, String targetUrl, final String username, final String password) {
|
|
||||||
// 用户名和密码,替换为实际的认证信息
|
|
||||||
//String username = "your_username";
|
|
||||||
//String password = "your_password";
|
|
||||||
|
|
||||||
// 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());
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
class WinBollServiceViewHandler extends Handler {
|
|
||||||
WinBollServiceStatusView mDevelopHostConnectionStatusView;
|
|
||||||
|
|
||||||
public WinBollServiceViewHandler(WinBollServiceStatusView view) {
|
|
||||||
mDevelopHostConnectionStatusView = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
if (msg.what == MSG_CONNECTION_INFO) {
|
|
||||||
mDevelopHostConnectionStatusView.mTextView.setText((String)msg.obj);
|
|
||||||
} else if (msg.what == MSG_UPDATE_CONNECTION_STATUS) {
|
|
||||||
mDevelopHostConnectionStatusView.setImageViewByConnection(mImageView, (boolean)msg.obj);
|
|
||||||
mDevelopHostConnectionStatusView.mConnectionStatus = ((boolean)msg.obj) ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED;
|
|
||||||
}
|
|
||||||
super.handleMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void postMessageText(String szMSG) {
|
|
||||||
Message msg = new Message();
|
|
||||||
msg.what = MSG_CONNECTION_INFO;
|
|
||||||
msg.obj = szMSG;
|
|
||||||
sendMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void postMessageConnectionStatus(boolean isConnected) {
|
|
||||||
Message msg = new Message();
|
|
||||||
msg.what = MSG_UPDATE_CONNECTION_STATUS;
|
|
||||||
msg.obj = isConnected;
|
|
||||||
sendMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ConnectionThread extends Thread {
|
|
||||||
|
|
||||||
public volatile boolean mIsExist;
|
|
||||||
|
|
||||||
//DevelopHostConnectionStatusViewHandler mDevelopHostConnectionStatusViewHandler;
|
|
||||||
|
|
||||||
//public ConnectionThread(DevelopHostConnectionStatusViewHandler developHostConnectionStatusViewHandler) {
|
|
||||||
//mDevelopHostConnectionStatusViewHandler = developHostConnectionStatusViewHandler;
|
|
||||||
//}
|
|
||||||
public ConnectionThread() {
|
|
||||||
mIsExist = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
super.run();
|
|
||||||
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);
|
|
||||||
} else if (mConnectionStatus == ConnectionStatus.CONNECTED
|
|
||||||
&& mConnectionStatus == ConnectionStatus.DISCONNECTED) {
|
|
||||||
ToastUtils.show("mWinBollServerHostConnectionStatus " + mConnectionStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(5 * 1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//ToastUtils.show("ConnectionThread exit.");
|
|
||||||
LogUtils.d(TAG, "ConnectionThread exit.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*WinBollService.OnServiceStatusChangeListener mOnServerStatusChangeListener = new WinBollService.OnServiceStatusChangeListener(){
|
|
||||||
@Override
|
|
||||||
public void onServerStatusChange(boolean isServiceAlive) {
|
|
||||||
}
|
|
||||||
};*/
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
package cc.winboll.studio.libapputils.view;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen@QQ.COM
|
|
||||||
* @Date 2024/08/12 14:46:25
|
|
||||||
* @Describe 询问用户确定与否的选择框
|
|
||||||
*/
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
|
|
||||||
public class YesNoAlertDialog {
|
|
||||||
|
|
||||||
public static final String TAG = "YesNoAlertDialog";
|
|
||||||
|
|
||||||
public static void show(Context context, String szTitle, String szMessage, final OnDialogResultListener listener) {
|
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
|
|
||||||
context);
|
|
||||||
|
|
||||||
// set title
|
|
||||||
alertDialogBuilder.setTitle(szTitle);
|
|
||||||
|
|
||||||
// set dialog message
|
|
||||||
alertDialogBuilder
|
|
||||||
.setMessage(szMessage)
|
|
||||||
.setCancelable(true)
|
|
||||||
.setOnCancelListener(new DialogInterface.OnCancelListener(){
|
|
||||||
@Override
|
|
||||||
public void onCancel(DialogInterface dialog) {
|
|
||||||
listener.onNo();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
// if this button is clicked, close
|
|
||||||
// current activity
|
|
||||||
listener.onYes();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
// if this button is clicked, just close
|
|
||||||
// the dialog box and do nothing
|
|
||||||
dialog.cancel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// create alert dialog
|
|
||||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
||||||
|
|
||||||
// show it
|
|
||||||
alertDialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface OnDialogResultListener {
|
|
||||||
abstract void onYes();
|
|
||||||
abstract void onNo();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
<?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">
|
|
||||||
|
|
||||||
<android.widget.Toolbar
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/toolbar"/>
|
|
||||||
|
|
||||||
<cc.winboll.studio.libapputils.view.SimpleWebView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1.0"
|
|
||||||
android:id="@+id/activityassetshtmlSimpleWebView1"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
|||||||
<?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">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="QRCodeDecodeActivity"/>
|
|
||||||
|
|
||||||
<com.journeyapps.barcodescanner.DecoratedBarcodeView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/activityqrcodedecodeDecoratedBarcodeView1"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user