应用类重构
This commit is contained in:
		| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Thu Jan 23 02:30:25 HKT 2025 | ||||
| #Wed Jan 22 18:42:34 GMT 2025 | ||||
| stageCount=9 | ||||
| libraryProject=libapputils | ||||
| baseVersion=9.2 | ||||
| publishVersion=9.2.8 | ||||
| buildCount=0 | ||||
| buildCount=2 | ||||
| baseBetaVersion=9.2.9 | ||||
|   | ||||
| @@ -5,14 +5,12 @@ 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.GlobalApplication; | ||||
| import cc.winboll.studio.libapputils.app.WinBollGlobalApplication; | ||||
| import com.hjq.toast.ToastUtils; | ||||
| import com.hjq.toast.style.WhiteToastStyle; | ||||
| import cc.winboll.studio.libapputils.app.WinBollUtils; | ||||
|  | ||||
| public class App extends GlobalApplication { | ||||
| public class App extends WinBollGlobalApplication { | ||||
|  | ||||
|     public static final String TAG = "App"; | ||||
|  | ||||
| @@ -21,8 +19,6 @@ public class App extends GlobalApplication { | ||||
|     @Override | ||||
|     public void onCreate() { | ||||
|         super.onCreate(); | ||||
|         // 初始化 WinBoll 框架 | ||||
|         WinBollUtils.init(this); | ||||
|         // 初始化 Toast 框架 | ||||
|         ToastUtils.init(this); | ||||
|         // 设置 Toast 布局样式 | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Thu Jan 23 02:30:17 HKT 2025 | ||||
| #Wed Jan 22 18:42:34 GMT 2025 | ||||
| stageCount=9 | ||||
| libraryProject=libapputils | ||||
| baseVersion=9.2 | ||||
| publishVersion=9.2.8 | ||||
| buildCount=0 | ||||
| buildCount=2 | ||||
| baseBetaVersion=9.2.9 | ||||
|   | ||||
| @@ -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)) { | ||||
|                         WinBollUtils.setIsDebug(true); | ||||
|                         WinBollGlobalApplication.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 (WinBollUtils.isDebug()) { | ||||
|         if (WinBollGlobalApplication.isDebug()) { | ||||
|             getMenuInflater().inflate(R.menu.toolbar_studio_debug, menu); | ||||
|         } | ||||
|         return super.onCreateOptionsMenu(menu); | ||||
|   | ||||
| @@ -171,11 +171,11 @@ public class WinBollActivityManager { | ||||
|                 //ToastUtils.show("finishAll() activity"); | ||||
|                 if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { | ||||
|                     //ToastUtils.show("activity != null ..."); | ||||
|                     if (WinBollUtils.getWinBollUI_TYPE() == WinBollUtils.WinBollUI_TYPE.Service) { | ||||
|                     if (WinBollGlobalApplication.getWinBollUI_TYPE() == WinBollGlobalApplication.WinBollUI_TYPE.Service) { | ||||
|                         // 结束窗口和最近任务栏, 建议前台服务类应用使用,可以方便用户再次调用 UI 操作。 | ||||
|                         activity.finishAndRemoveTask(); | ||||
|                         //ToastUtils.show("finishAll() activity.finishAndRemoveTask();"); | ||||
|                     } else if (WinBollUtils.getWinBollUI_TYPE() == WinBollUtils.WinBollUI_TYPE.Aplication) { | ||||
|                     } else if (WinBollGlobalApplication.getWinBollUI_TYPE() == WinBollGlobalApplication.WinBollUI_TYPE.Aplication) { | ||||
|                         // 结束窗口保留最近任务栏,建议前台服务类应用使用,可以保持应用的系统自觉性。 | ||||
|                         activity.finish(); | ||||
|                         //ToastUtils.show("finishAll() activity.finish();"); | ||||
|   | ||||
| @@ -9,24 +9,9 @@ import com.hjq.toast.ToastUtils; | ||||
| import com.hjq.toast.style.WhiteToastStyle; | ||||
| import cc.winboll.studio.GlobalApplication; | ||||
| 
 | ||||
| public class WinBollUtils { | ||||
| public class WinBollGlobalApplication extends GlobalApplication { | ||||
| 
 | ||||
|     public static final String TAG = "WinBollUtils"; | ||||
| 
 | ||||
|     // | ||||
|     // 单件结构模块 | ||||
|     // | ||||
|     static volatile WinBollUtils _WinBollUtils; | ||||
|     Application mApplication; | ||||
|     WinBollUtils(Application application) { | ||||
|         mApplication = application; | ||||
|     } | ||||
|     static synchronized WinBollUtils getInstance(Application application) { | ||||
|         if (_WinBollUtils == null) { | ||||
|             _WinBollUtils = new WinBollUtils(application); | ||||
|         } | ||||
|         return _WinBollUtils; | ||||
|     } | ||||
|     public static final String TAG = "WinBollGlobalApplication"; | ||||
| 
 | ||||
|     public static enum WinBollUI_TYPE { | ||||
|         Aplication, // 退出应用后,保持最近任务栏任务记录主窗口 | ||||
| @@ -43,7 +28,7 @@ public class WinBollUtils { | ||||
|     static volatile boolean isDebug = false; | ||||
| 
 | ||||
|     public static void setIsDebug(boolean isDebug) { | ||||
|         WinBollUtils.isDebug = isDebug; | ||||
|         WinBollGlobalApplication.isDebug = isDebug; | ||||
|     } | ||||
| 
 | ||||
|     public static boolean isDebug() { | ||||
| @@ -68,14 +53,15 @@ public class WinBollUtils { | ||||
|         return mMyActivityLifecycleCallbacks; | ||||
|     } | ||||
| 
 | ||||
|     public static void init(Application application) { | ||||
|         WinBollUtils winBollUtils = WinBollUtils.getInstance(application); | ||||
|     @Override | ||||
|     public void onCreate() { | ||||
|         super.onCreate(); | ||||
|         // 应用环境初始化, 基本调试环境 | ||||
|         // | ||||
|         // 初始化日志模块 | ||||
|         LogUtils.init(application); | ||||
|         LogUtils.init(this); | ||||
|         // 设置应用调试标志 | ||||
|         DebugBean debugBean = DebugBean.loadBean(application, DebugBean.class); | ||||
|         DebugBean debugBean = DebugBean.loadBean(this, DebugBean.class); | ||||
|         if (debugBean == null) { | ||||
|             //ToastUtils.show("debugBean == null"); | ||||
|             setIsDebug(false); | ||||
| @@ -85,8 +71,8 @@ public class WinBollUtils { | ||||
|         } | ||||
|         // 应用窗口管理模块参数设置 | ||||
|         // | ||||
|         winBollUtils.mMyActivityLifecycleCallbacks = new MyActivityLifecycleCallbacks(application); | ||||
|         application.registerActivityLifecycleCallbacks(winBollUtils.mMyActivityLifecycleCallbacks); | ||||
|         mMyActivityLifecycleCallbacks = new MyActivityLifecycleCallbacks(this); | ||||
|         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.WinBollUtils; | ||||
| import cc.winboll.studio.libapputils.app.WinBollGlobalApplication; | ||||
|  | ||||
| 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 (WinBollUtils.isDebug()) { mLogView.start(); } | ||||
|         if (WinBollGlobalApplication.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.WinBollUtils; | ||||
| import cc.winboll.studio.libapputils.app.WinBollGlobalApplication; | ||||
| 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 (WinBollUtils.isDebug()) { | ||||
|         if (WinBollGlobalApplication.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.WinBollUtils; | ||||
| import cc.winboll.studio.libapputils.app.WinBollGlobalApplication; | ||||
| import cc.winboll.studio.libapputils.bean.APPInfo; | ||||
| import cc.winboll.studio.libapputils.bean.DebugBean; | ||||
| import cc.winboll.studio.libapputils.log.LogUtils; | ||||
| @@ -105,7 +105,7 @@ public class AboutView extends LinearLayout { | ||||
|         mszAppDescription = mAPPInfo.getAppDescription(); | ||||
|         mnAppIcon = mAPPInfo.getAppIcon(); | ||||
|  | ||||
|         mszWinBollServerHost = WinBollUtils.isDebug() ?  "https://dev.winboll.cc": "https://www.winboll.cc"; | ||||
|         mszWinBollServerHost = WinBollGlobalApplication.isDebug() ?  "https://dev.winboll.cc": "https://www.winboll.cc"; | ||||
|  | ||||
|         try { | ||||
|             mszAppVersionName = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName; | ||||
| @@ -116,7 +116,7 @@ public class AboutView extends LinearLayout { | ||||
|         mszHomePage = mszWinBollServerHost + "/studio/details.php?app=" + mszAppAPKFolderName; | ||||
|         mszGitea = "https://gitea.winboll.cc/Studio/" + mszAppGitName + "/src/branch/" + mAPPInfo.getAppGitAPPBranch() + "/" + mAPPInfo.getAppGitAPPSubProjectFolder(); | ||||
|  | ||||
|         if (WinBollUtils.isDebug()) { | ||||
|         if (WinBollGlobalApplication.isDebug()) { | ||||
|             LayoutInflater inflater = LayoutInflater.from(mContext); | ||||
|             View addedView = inflater.inflate(R.layout.view_about_dev, this, false); | ||||
|             LinearLayout llMain = addedView.findViewById(R.id.viewaboutdevLinearLayout1); | ||||
| @@ -207,7 +207,7 @@ public class AboutView extends LinearLayout { | ||||
|         // 定义应用调试按钮 | ||||
|         // | ||||
|         Element elementAppMode; | ||||
|         if (WinBollUtils.isDebug()) { | ||||
|         if (WinBollGlobalApplication.isDebug()) { | ||||
|             elementAppMode = new Element(mContext.getString(R.string.app_normal), R.drawable.ic_winboll); | ||||
|             elementAppMode.setOnClickListener(mAppNormalOnClickListener); | ||||
|         } else { | ||||
| @@ -273,7 +273,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); | ||||
|             WinBollUtils.setIsDebug(true); | ||||
|             WinBollGlobalApplication.setIsDebug(true); | ||||
|             DebugBean.saveBean(context, new DebugBean(true)); | ||||
|  | ||||
|             WinBollActivityManager.getInstance(context).finishAll(); | ||||
| @@ -285,7 +285,7 @@ public class AboutView extends LinearLayout { | ||||
|         Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); | ||||
|         if (intent != null) { | ||||
|             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||||
|             WinBollUtils.setIsDebug(false); | ||||
|             WinBollGlobalApplication.setIsDebug(false); | ||||
|             DebugBean.saveBean(context, new DebugBean(false)); | ||||
|  | ||||
|             WinBollActivityManager.getInstance(context).finishAll(); | ||||
| @@ -311,7 +311,7 @@ public class AboutView extends LinearLayout { | ||||
|                         String szUrl = mszWinBollServerHost + "/studio/details.php?app=" + mszAppAPKFolderName; | ||||
|                         // 构建包含认证信息的请求 | ||||
|                         String credential = ""; | ||||
|                         if (WinBollUtils.isDebug()) { | ||||
|                         if (WinBollGlobalApplication.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