重构 WinBoll 框架应用类
This commit is contained in:
		| @@ -50,6 +50,8 @@ android { | ||||
|  | ||||
| dependencies { | ||||
| 	api project(':libapputils') | ||||
|     api 'cc.winboll.studio:libappbase:1.0.3' | ||||
|      | ||||
|     api 'cc.winboll.studio:libappbase:1.1.0' | ||||
|      | ||||
|     api fileTree(dir: 'libs', include: ['*.jar']) | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Wed Jan 22 17:19:54 HKT 2025 | ||||
| #Wed Jan 22 11:33:02 GMT 2025 | ||||
| stageCount=3 | ||||
| libraryProject=libapputils | ||||
| baseVersion=9.2 | ||||
| publishVersion=9.2.2 | ||||
| buildCount=0 | ||||
| buildCount=8 | ||||
| baseBetaVersion=9.2.3 | ||||
|   | ||||
| @@ -5,27 +5,25 @@ package cc.winboll.studio.apputils; | ||||
|  * @Date 2024/12/08 15:10:51 | ||||
|  * @Describe 全局应用类 | ||||
|  */ | ||||
| import android.app.Application; | ||||
| import android.view.Gravity; | ||||
| import cc.winboll.studio.libapputils.app.WinBollApplication; | ||||
| import cc.winboll.studio.GlobalApplication; | ||||
| import com.hjq.toast.ToastUtils; | ||||
| import com.hjq.toast.style.WhiteToastStyle; | ||||
| import cc.winboll.studio.libapputils.app.WinBollUtils; | ||||
|  | ||||
| public class App extends WinBollApplication { | ||||
| public class App extends GlobalApplication { | ||||
|  | ||||
|     public static final String TAG = "App"; | ||||
|  | ||||
|     public static final String _ACTION_DEBUGVIEW = WinBollApplication.class.getName() + "_ACTION_DEBUGVIEW"; | ||||
|     public static final String _ACTION_DEBUGVIEW = App.class.getName() + "_ACTION_DEBUGVIEW"; | ||||
|  | ||||
|     @Override | ||||
|     public void onCreate() { | ||||
|         super.onCreate(); | ||||
|         // 初始化 Toast 框架 | ||||
|         // | ||||
|         ToastUtils.init(this); | ||||
|         // 设置 Toast 布局样式 | ||||
|         //ToastUtils.setView(R.layout.view_toast); | ||||
|         ToastUtils.setStyle(new WhiteToastStyle()); | ||||
|         ToastUtils.setGravity(Gravity.BOTTOM, 0, 200); | ||||
|         // 初始化 WinBoll 框架 | ||||
|         WinBollUtils.getInstance(this).init(this); | ||||
|          | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -38,7 +38,7 @@ dependencies { | ||||
|     api 'androidx.fragment:fragment:1.0.0' | ||||
|     api 'com.google.android.material:material:1.0.0' | ||||
|      | ||||
|     api 'cc.winboll.studio:libappbase:1.0.3' | ||||
|     api 'cc.winboll.studio:libappbase:1.1.0' | ||||
|      | ||||
|     api fileTree(dir: 'libs', include: ['*.jar']) | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Wed Jan 22 17:19:38 HKT 2025 | ||||
| #Wed Jan 22 11:33:02 GMT 2025 | ||||
| stageCount=3 | ||||
| libraryProject=libapputils | ||||
| baseVersion=9.2 | ||||
| publishVersion=9.2.2 | ||||
| buildCount=0 | ||||
| buildCount=8 | ||||
| baseBetaVersion=9.2.3 | ||||
|   | ||||
| @@ -6,22 +6,23 @@ package cc.winboll.studio.libapputils.app; | ||||
|  */ | ||||
| import android.app.Activity; | ||||
| import android.app.Application; | ||||
| import android.content.ComponentName; | ||||
| import android.content.Intent; | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import cc.winboll.studio.GlobalApplication; | ||||
| import cc.winboll.studio.libapputils.log.LogUtils; | ||||
| import com.hjq.toast.ToastUtils; | ||||
| import java.util.Set;  | ||||
| import android.content.Context;  | ||||
|  | ||||
| public class MyActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {  | ||||
|  | ||||
|     public static final String TAG = "MyActivityLifecycleCallbacks"; | ||||
|  | ||||
|     Application mApplication; | ||||
|      | ||||
|     public String mInfo = ""; | ||||
|      | ||||
|     public MyActivityLifecycleCallbacks(WinBollApplication application) { | ||||
|          | ||||
|     public MyActivityLifecycleCallbacks(Application application) { | ||||
|         mApplication = application; | ||||
|     } | ||||
|  | ||||
|     void createActivityeInfo(Activity activity) { | ||||
|   | ||||
| @@ -64,7 +64,7 @@ abstract public class WinBollActivity extends AppCompatActivity { | ||||
|                 // 传入的Intent action在Activity清单的intent-filter的action节点里有定义 | ||||
|                 if (intent.getAction() != null) { | ||||
|                     if (intent.getAction().equals(cc.winboll.studio.libapputils.intent.action.DEBUGVIEW)) { | ||||
|                         WinBollApplication.setIsDebug(true); | ||||
|                         WinBollUtils.setIsDebug(true); | ||||
|                         //ToastUtils.show!("WinBollApplication.setIsDebug(true) by action : " + intent.getAction()); | ||||
|  | ||||
|                     } | ||||
| @@ -356,7 +356,7 @@ abstract public class WinBollActivity extends AppCompatActivity { | ||||
|         if (isAddWinBollToolBar()) { | ||||
|             getMenuInflater().inflate(R.menu.toolbar_winboll_shared_main, menu); | ||||
|         } | ||||
|         if (WinBollApplication.isDebug()) { | ||||
|         if (WinBollUtils.isDebug()) { | ||||
|             getMenuInflater().inflate(R.menu.toolbar_studio_debug, menu); | ||||
|         } | ||||
|         return super.onCreateOptionsMenu(menu); | ||||
| @@ -378,8 +378,9 @@ abstract public class WinBollActivity extends AppCompatActivity { | ||||
|             //ToastUtils.show("item_exit"); | ||||
|             WinBollActivityManager.getInstance(this).finishAll(); | ||||
|         } else if (item.getItemId() == R.id.item_info) { | ||||
|             WinBollApplication application = (WinBollApplication) getApplication(); | ||||
|             application.getMyActivityLifecycleCallbacks().showActivityeInfo(); | ||||
|             LogUtils.d(TAG, "item_info not yet."); | ||||
|             //WinBollApplication application = (WinBollApplication) getApplication(); | ||||
|             //application.getMyActivityLifecycleCallbacks().showActivityeInfo(); | ||||
|         } else if (item.getItemId() == R.id.item_exitdebug) { | ||||
|             AboutView.setApp2NormalMode(getApplicationContext()); | ||||
|         } else if (item.getItemId() == R.id.item_about) { | ||||
|   | ||||
| @@ -171,11 +171,11 @@ public class WinBollActivityManager { | ||||
|                 //ToastUtils.show("finishAll() activity"); | ||||
|                 if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { | ||||
|                     //ToastUtils.show("activity != null ..."); | ||||
|                     if (WinBollApplication.getWinBollUI_TYPE() == WinBollApplication.WinBollUI_TYPE.Service) { | ||||
|                     if (WinBollUtils.getInstance(mContext).getWinBollUI_TYPE() == WinBollUtils.WinBollUI_TYPE.Service) { | ||||
|                         // 结束窗口和最近任务栏, 建议前台服务类应用使用,可以方便用户再次调用 UI 操作。 | ||||
|                         activity.finishAndRemoveTask(); | ||||
|                         //ToastUtils.show("finishAll() activity.finishAndRemoveTask();"); | ||||
|                     } else if (WinBollApplication.getWinBollUI_TYPE() == WinBollApplication.WinBollUI_TYPE.Aplication) { | ||||
|                     } else if (WinBollUtils.getInstance(mContext).getWinBollUI_TYPE() == WinBollUtils.WinBollUI_TYPE.Aplication) { | ||||
|                         // 结束窗口保留最近任务栏,建议前台服务类应用使用,可以保持应用的系统自觉性。 | ||||
|                         activity.finish(); | ||||
|                         //ToastUtils.show("finishAll() activity.finish();"); | ||||
|   | ||||
| @@ -1,11 +1,31 @@ | ||||
| package cc.winboll.studio.libapputils.app; | ||||
| 
 | ||||
| import android.app.Application; | ||||
| import android.content.Context; | ||||
| import android.view.Gravity; | ||||
| import cc.winboll.studio.libapputils.bean.DebugBean; | ||||
| import cc.winboll.studio.libapputils.log.LogUtils; | ||||
| import com.hjq.toast.ToastUtils; | ||||
| import com.hjq.toast.style.WhiteToastStyle; | ||||
| 
 | ||||
| public class WinBollApplication extends cc.winboll.studio.libappbase.GlobalApplication { | ||||
| public class WinBollUtils { | ||||
| 
 | ||||
|     public static final String TAG = "WinBollApplication"; | ||||
|     public static final String TAG = "WinBollUtils"; | ||||
| 
 | ||||
|     // | ||||
|     // 单件结构模块 | ||||
|     // | ||||
|     static volatile WinBollUtils _WinBollUtils; | ||||
|     Context mContext; | ||||
|     WinBollUtils(Context context) { | ||||
|         mContext = context; | ||||
|     } | ||||
|     public static synchronized WinBollUtils getInstance(Context context) { | ||||
|         if (_WinBollUtils == null) { | ||||
|             _WinBollUtils = new WinBollUtils(context); | ||||
|         } | ||||
|         return _WinBollUtils; | ||||
|     } | ||||
| 
 | ||||
|     public static enum WinBollUI_TYPE { | ||||
|         Aplication, // 退出应用后,保持最近任务栏任务记录主窗口 | ||||
| @@ -15,14 +35,14 @@ public class WinBollApplication extends cc.winboll.studio.libappbase.GlobalAppli | ||||
|     // 应用类型标志 | ||||
|     volatile static WinBollUI_TYPE _mWinBollUI_TYPE = WinBollUI_TYPE.Service; | ||||
| 
 | ||||
|     static volatile WinBollApplication _WinBollApplication = null; | ||||
|     //static volatile WinBollApplication _WinBollApplication = null; | ||||
|     MyActivityLifecycleCallbacks mMyActivityLifecycleCallbacks; | ||||
| 
 | ||||
|     // 标记当前应用是否处于调试状态 | ||||
|     static volatile boolean isDebug = false; | ||||
| 
 | ||||
|     public static void setIsDebug(boolean isDebug) { | ||||
|         WinBollApplication.isDebug = isDebug; | ||||
|         WinBollUtils.isDebug = isDebug; | ||||
|     } | ||||
| 
 | ||||
|     public static boolean isDebug() { | ||||
| @@ -47,16 +67,19 @@ public class WinBollApplication extends cc.winboll.studio.libappbase.GlobalAppli | ||||
|         return mMyActivityLifecycleCallbacks; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onCreate() { | ||||
|         super.onCreate(); | ||||
|         _WinBollApplication = this; | ||||
|     public void init(Application application) { | ||||
|         // 应用环境初始化, 基本调试环境 | ||||
|         // | ||||
|         CrashHandler.init(this); | ||||
|         LogUtils.init(this); | ||||
| 
 | ||||
|         DebugBean debugBean = DebugBean.loadBean(this, DebugBean.class); | ||||
|         // 初始化日志模块 | ||||
|         LogUtils.init(mContext); | ||||
|         // 初始化 Toast 框架 | ||||
|         ToastUtils.init(application); | ||||
|         // 设置 Toast 布局样式 | ||||
|         //ToastUtils.setView(R.layout.view_toast); | ||||
|         ToastUtils.setStyle(new WhiteToastStyle()); | ||||
|         ToastUtils.setGravity(Gravity.BOTTOM, 0, 200); | ||||
|         // 设置应用调试标志 | ||||
|         DebugBean debugBean = DebugBean.loadBean(mContext, DebugBean.class); | ||||
|         if (debugBean == null) { | ||||
|             //ToastUtils.show("debugBean == null"); | ||||
|             setIsDebug(false); | ||||
| @@ -64,11 +87,10 @@ public class WinBollApplication extends cc.winboll.studio.libappbase.GlobalAppli | ||||
|             //ToastUtils.show("saveDebugStatus(" + String.valueOf(debugBean.isDebuging()) + ")"); | ||||
|             setIsDebug(debugBean.isDebuging()); | ||||
|         } | ||||
| 
 | ||||
|         // 应用运行状态环境设置 | ||||
|         // 应用窗口管理模块参数设置 | ||||
|         // | ||||
|         mMyActivityLifecycleCallbacks = new MyActivityLifecycleCallbacks(this); | ||||
|         registerActivityLifecycleCallbacks(mMyActivityLifecycleCallbacks); | ||||
|         mMyActivityLifecycleCallbacks = new MyActivityLifecycleCallbacks(application); | ||||
|         application.registerActivityLifecycleCallbacks(mMyActivityLifecycleCallbacks); | ||||
|         // 设置默认 WinBoll 应用 UI 类型 | ||||
|         setWinBollUI_TYPE(WinBollUI_TYPE.Service); | ||||
|         //ToastUtils.show("WinBollUI_TYPE " + getWinBollUI_TYPE()); | ||||
| @@ -9,7 +9,7 @@ import android.os.Bundle; | ||||
| import androidx.appcompat.widget.Toolbar; | ||||
| import cc.winboll.studio.libapputils.R; | ||||
| import cc.winboll.studio.libapputils.app.WinBollActivity; | ||||
| import cc.winboll.studio.libapputils.app.WinBollApplication; | ||||
| import cc.winboll.studio.libapputils.app.WinBollUtils; | ||||
|  | ||||
| public class LogActivity extends WinBollActivity { | ||||
|  | ||||
| @@ -44,7 +44,7 @@ public class LogActivity extends WinBollActivity { | ||||
|         setContentView(R.layout.activity_log); | ||||
|         mLogView = findViewById(R.id.logview); | ||||
|  | ||||
|         if (WinBollApplication.isDebug()) { mLogView.start(); } | ||||
|         if (WinBollUtils.isDebug()) { mLogView.start(); } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -7,7 +7,7 @@ package cc.winboll.studio.libapputils.log; | ||||
|  * @Describe 应用日志类 | ||||
|  */ | ||||
| import android.content.Context; | ||||
| import cc.winboll.studio.libapputils.app.WinBollApplication; | ||||
| import cc.winboll.studio.libapputils.app.WinBollUtils; | ||||
| import cc.winboll.studio.libapputils.util.FileUtils; | ||||
| import dalvik.system.DexFile; | ||||
| import java.io.BufferedReader; | ||||
| @@ -61,7 +61,7 @@ public class LogUtils { | ||||
|     // 初始化函数 | ||||
|     // | ||||
|     public static void init(Context context, LOG_LEVEL logLevel) { | ||||
|         if (WinBollApplication.isDebug()) { | ||||
|         if (WinBollUtils.isDebug()) { | ||||
|             // 初始化日志缓存文件路径 | ||||
|             _mfLogCacheDir = new File(context.getApplicationContext().getExternalCacheDir(), TAG); | ||||
|             if (!_mfLogCacheDir.exists()) { | ||||
|   | ||||
| @@ -19,7 +19,7 @@ import android.widget.LinearLayout; | ||||
| import cc.winboll.studio.libapputils.R; | ||||
| import cc.winboll.studio.libapputils.app.AppVersionUtils; | ||||
| import cc.winboll.studio.libapputils.app.WinBollActivityManager; | ||||
| import cc.winboll.studio.libapputils.app.WinBollApplication; | ||||
| import cc.winboll.studio.libapputils.app.WinBollUtils; | ||||
| import cc.winboll.studio.libapputils.bean.APPInfo; | ||||
| import cc.winboll.studio.libapputils.bean.DebugBean; | ||||
| import cc.winboll.studio.libapputils.log.LogUtils; | ||||
| @@ -101,7 +101,7 @@ public class AboutView extends LinearLayout { | ||||
|         mszAppDescription = mAPPInfo.getAppDescription(); | ||||
|         mnAppIcon = mAPPInfo.getAppIcon(); | ||||
|  | ||||
|         mszWinBollServerHost = WinBollApplication.isDebug() ?  "http://10.8.0.13": "https://www.winboll.cc"; | ||||
|         mszWinBollServerHost = WinBollUtils.isDebug() ?  "http://10.8.0.13": "https://www.winboll.cc"; | ||||
|  | ||||
|         try { | ||||
|             mszAppVersionName = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName; | ||||
| @@ -112,7 +112,7 @@ public class AboutView extends LinearLayout { | ||||
|         mszHomePage = mszWinBollServerHost + "/studio/details.php?app=" + mszAppAPKFolderName; | ||||
|         mszGitea = "https://gitea.winboll.cc/Studio/" + mszAppGitName + ".git"; | ||||
|  | ||||
|         if (WinBollApplication.isDebug()) { | ||||
|         if (WinBollUtils.isDebug()) { | ||||
|             LayoutInflater inflater = LayoutInflater.from(mContext); | ||||
|             View addedView = inflater.inflate(R.layout.view_about_dev, this, false); | ||||
|             LinearLayout llMain = addedView.findViewById(R.id.viewaboutdevLinearLayout1); | ||||
| @@ -199,7 +199,7 @@ public class AboutView extends LinearLayout { | ||||
|         // 定义应用调试按钮 | ||||
|         // | ||||
|         Element elementAppMode; | ||||
|         if (WinBollApplication.isDebug()) { | ||||
|         if (WinBollUtils.isDebug()) { | ||||
|             elementAppMode = new Element(mContext.getString(R.string.app_normal), R.drawable.ic_winboll); | ||||
|             elementAppMode.setOnClickListener(mAppNormalOnClickListener); | ||||
|         } else { | ||||
| @@ -265,7 +265,7 @@ public class AboutView extends LinearLayout { | ||||
|         if (intent != null) { | ||||
|             intent.setAction(cc.winboll.studio.libapputils.intent.action.DEBUGVIEW); | ||||
|             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||||
|             WinBollApplication.setIsDebug(true); | ||||
|             WinBollUtils.setIsDebug(true); | ||||
|             DebugBean.saveBean(context, new DebugBean(true)); | ||||
|  | ||||
|             WinBollActivityManager.getInstance(context).finishAll(); | ||||
| @@ -277,7 +277,7 @@ public class AboutView extends LinearLayout { | ||||
|         Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); | ||||
|         if (intent != null) { | ||||
|             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||||
|             WinBollApplication.setIsDebug(false); | ||||
|             WinBollUtils.setIsDebug(false); | ||||
|             DebugBean.saveBean(context, new DebugBean(false)); | ||||
|  | ||||
|             WinBollActivityManager.getInstance(context).finishAll(); | ||||
| @@ -303,7 +303,7 @@ public class AboutView extends LinearLayout { | ||||
|                         String szUrl = mszWinBollServerHost + "/studio/details.php?app=" + mszAppAPKFolderName; | ||||
|                         // 构建包含认证信息的请求 | ||||
|                         String credential = ""; | ||||
|                         if (WinBollApplication.isDebug()) { | ||||
|                         if (WinBollUtils.isDebug()) { | ||||
|                             credential = Credentials.basic(metDevUserName.getText().toString(), metDevUserPassword.getText().toString()); | ||||
|                             PrefUtils.saveString(mContext, "metDevUserName", metDevUserName.getText().toString()); | ||||
|                             PrefUtils.saveString(mContext, "metDevUserPassword", metDevUserPassword.getText().toString()); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 ZhanGSKen
					ZhanGSKen