feat(winboll): 重构应用主题系统,继承libaes主题元素

主要修改:
- 新增 MyAppTheme 系列主题样式,继承自 AESTheme
  - MyAppTheme (默认)
  - MyDepthAppTheme, MySkyAppTheme, MyGoldenAppTheme
  - MyBearingAppTheme, MyMemorAppTheme, MyTaoAppTheme
- 新增 MyAESAToolbar/MyAESASupportToolbar 样式继承
- 新增 WinBoLLThemeBean/WinBoLLThemeUtil 主题工具类
- MainActivity 使用自定义主题 ID 替换 AES 原始样式
- BaseWinBoLLActivity 主题设置改用 WinBoLLThemeUtil
- 修复 MainActivity Fragment 初始化逻辑
- 集成 AESThemeUtil 主题切换功能

文件变更:
- winboll/src/main/res/values/styles.xml
- winboll/src/main/java/.../winboll/theme/*.java (新增)
- winboll/src/main/java/.../MainActivity.java
- winboll/src/main/java/.../BaseWinBoLLActivity.java

注意:应用正在测试中
This commit is contained in:
2026-05-12 16:08:48 +08:00
parent 6308df8f36
commit 5f2170a7a1
5 changed files with 168 additions and 68 deletions

View File

@@ -11,6 +11,7 @@ import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity; import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
import cc.winboll.studio.libaes.models.DrawerMenuBean; import cc.winboll.studio.libaes.models.DrawerMenuBean;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager; import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.winboll.R; import cc.winboll.studio.winboll.R;
@@ -36,19 +37,17 @@ public class MainActivity extends DrawerFragmentActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
setTheme(cc.winboll.studio.winboll.theme.WinBoLLThemeUtil.getThemeTypeID(this));
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// ------------------- 新增初始化MainActivity的Handler关键 -------------------
initMainHandler(); initMainHandler();
if (mBrowserFragment == null) { if (mBrowserFragment == null) {
LogUtils.d(TAG, "The code in this line is not fix yet."); String externalUrl = extractExternalUrl(getIntent());
// String externalUrl = extractExternalUrl(getIntent()); if (externalUrl != null) {
// if (externalUrl != null) { mBrowserFragment = BrowserFragment.newInstance(externalUrl);
// mBrowserFragment = BrowserFragment.newInstance(externalUrl); } else {
// } else { mBrowserFragment = BrowserFragment.newInstance();
// mBrowserFragment = new BrowserFragment(); }
// } addFragment(mBrowserFragment);
// addFragment(mBrowserFragment);
} }
showFragment(mBrowserFragment); showFragment(mBrowserFragment);
} }
@@ -171,36 +170,35 @@ public class MainActivity extends DrawerFragmentActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int nItemId = item.getItemId(); if (AESThemeUtil.onWinBoLLThemeItemSelected(this, item)) {
if (nItemId == R.id.item_home) { recreate();
// 发送MSG_HOMEPAGE消息给BrowserFragment
if (mBrowserFragment != null && mBrowserFragment.getBrowserHandler() != null) {
Message msg = Message.obtain();
msg.what = BrowserFragment.MSG_HOMEPAGE;
mBrowserFragment.getBrowserHandler().sendMessage(msg);
}
} else if (nItemId == R.id.item_settings) {
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), SettingsActivity.class);
} else if (nItemId == R.id.item_about) {
Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), intent, AboutActivity.class);
} else if (nItemId == R.id.item_mytermux) {
Intent intent = new Intent(getApplicationContext(), MyTermuxActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else if (nItemId == R.id.item_termux_env_test) {
Intent intent = new Intent(getApplicationContext(), TermuxEnvTestActivity.class);
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), intent, AboutActivity.class);
} else if (nItemId == R.id.item_library_activity) {
Intent intent = new Intent(getApplicationContext(), cc.winboll.studio.libwinboll.WinBoLLLibraryActivity.class);
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), intent, AboutActivity.class);
} else { } else {
return super.onOptionsItemSelected(item); int nItemId = item.getItemId();
} if (nItemId == R.id.item_home) {
if (mBrowserFragment != null && mBrowserFragment.getBrowserHandler() != null) {
Message msg = Message.obtain();
msg.what = BrowserFragment.MSG_HOMEPAGE;
mBrowserFragment.getBrowserHandler().sendMessage(msg);
}
} else if (nItemId == R.id.item_settings) {
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), SettingsActivity.class);
} else if (nItemId == R.id.item_about) {
Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), intent, AboutActivity.class);
} else if (nItemId == R.id.item_mytermux) {
Intent intent = new Intent(getApplicationContext(), MyTermuxActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else if (nItemId == R.id.item_termux_env_test) {
Intent intent = new Intent(getApplicationContext(), TermuxEnvTestActivity.class);
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), intent, AboutActivity.class);
} else if (nItemId == R.id.item_library_activity) {
Intent intent = new Intent(getApplicationContext(), cc.winboll.studio.libwinboll.WinBoLLLibraryActivity.class);
WinBoLLActivityManager.getInstance().startWinBoLLActivity(getApplicationContext(), intent, AboutActivity.class);
} else {
return super.onOptionsItemSelected(item);
}
}
return true; return true;
} }

View File

@@ -5,8 +5,8 @@ import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity; import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libaes.models.AESThemeBean; import cc.winboll.studio.libaes.models.AESThemeBean;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager; import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.winboll.theme.WinBoLLThemeUtil;
/** /**
* @Author 豆包&ZhanGSKen<zhangsken@qq.com> * @Author 豆包&ZhanGSKen<zhangsken@qq.com>
@@ -29,16 +29,11 @@ public abstract class BaseWinBoLLActivity extends AppCompatActivity implements I
} }
AESThemeBean.ThemeType getThemeType() { AESThemeBean.ThemeType getThemeType() {
/*SharedPreferences sharedPreferences = getSharedPreferences( return WinBoLLThemeUtil.getThemeStyleType(WinBoLLThemeUtil.getThemeTypeID(getApplicationContext()));
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() { void setThemeStyle() {
//setTheme(AESThemeBean.getThemeStyle(getThemeType())); setTheme(WinBoLLThemeUtil.getThemeTypeID(getApplicationContext()));
setTheme(AESThemeUtil.getThemeTypeID(getApplicationContext()));
} }
@Override @Override

View File

@@ -0,0 +1,49 @@
package cc.winboll.studio.winboll.theme;
import cc.winboll.studio.libaes.models.AESThemeBean;
import cc.winboll.studio.winboll.R;
public class WinBoLLThemeBean {
public static final String TAG = "WinBoLLThemeBean";
public static int getDefaultThemeStyleID() {
return R.style.MyAppTheme;
}
public static int getThemeStyleID(AESThemeBean.ThemeType themeType) {
int themeStyleID = getDefaultThemeStyleID();
if (AESThemeBean.ThemeType.DEPTH == themeType) {
themeStyleID = R.style.MyDepthAppTheme;
} else if (AESThemeBean.ThemeType.SKY == themeType) {
themeStyleID = R.style.MySkyAppTheme;
} else if (AESThemeBean.ThemeType.GOLDEN == themeType) {
themeStyleID = R.style.MyGoldenAppTheme;
} else if (AESThemeBean.ThemeType.BEARING == themeType) {
themeStyleID = R.style.MyBearingAppTheme;
} else if (AESThemeBean.ThemeType.MEMOR == themeType) {
themeStyleID = R.style.MyMemorAppTheme;
} else if (AESThemeBean.ThemeType.TAO == themeType) {
themeStyleID = R.style.MyTaoAppTheme;
}
return themeStyleID;
}
public static AESThemeBean.ThemeType getThemeStyleType(int nThemeStyleID) {
AESThemeBean.ThemeType themeStyle = AESThemeBean.ThemeType.AES;
if (R.style.MyDepthAppTheme == nThemeStyleID) {
themeStyle = AESThemeBean.ThemeType.DEPTH;
} else if (R.style.MySkyAppTheme == nThemeStyleID) {
themeStyle = AESThemeBean.ThemeType.SKY;
} else if (R.style.MyGoldenAppTheme == nThemeStyleID) {
themeStyle = AESThemeBean.ThemeType.GOLDEN;
} else if (R.style.MyBearingAppTheme == nThemeStyleID) {
themeStyle = AESThemeBean.ThemeType.BEARING;
} else if (R.style.MyMemorAppTheme == nThemeStyleID) {
themeStyle = AESThemeBean.ThemeType.MEMOR;
} else if (R.style.MyTaoAppTheme == nThemeStyleID) {
themeStyle = AESThemeBean.ThemeType.TAO;
}
return themeStyle;
}
}

View File

@@ -0,0 +1,36 @@
package cc.winboll.studio.winboll.theme;
import android.content.Context;
import cc.winboll.studio.libaes.models.AESThemeBean;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
public class WinBoLLThemeUtil {
public static final String TAG = "WinBoLLThemeUtil";
public static int getThemeTypeID(Context context) {
AESThemeBean bean = AESThemeBean.loadBean(context, AESThemeBean.class);
int themeTypeID;
if (bean == null) {
themeTypeID = WinBoLLThemeBean.getDefaultThemeStyleID();
} else {
int aesStyleID = bean.getCurrentThemeTypeID();
AESThemeBean.ThemeType themeType = WinBoLLThemeBean.getThemeStyleType(aesStyleID);
themeTypeID = WinBoLLThemeBean.getThemeStyleID(themeType);
}
return themeTypeID;
}
public static void saveThemeStyleID(Context context, int nThemeTypeID) {
AESThemeBean bean = new AESThemeBean(nThemeTypeID);
AESThemeBean.saveBean(context, bean);
}
public static AESThemeBean.ThemeType getThemeStyleType(int nThemeStyleID) {
return WinBoLLThemeBean.getThemeStyleType(nThemeStyleID);
}
public static int getThemeStyleID(AESThemeBean.ThemeType themeType) {
return WinBoLLThemeBean.getThemeStyleID(themeType);
}
}

View File

@@ -1,28 +1,50 @@
<resources> <resources>
<style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <style name="MyAppTheme" parent="AESTheme">
<item name="themeDebug">@style/MyDebugActivityTheme</item> <item name="themeDebug">@style/MyDebugActivityTheme</item>
<item name="aboutViewBackgroundColor">@color/mainWindowBackgroundColor</item> <item name="aToolbar">@style/MyAESAToolbar</item>
<item name="aboutViewTextColor">@color/mainWindowTextColor</item> <item name="aSupportToolbar">@style/MyAESASupportToolbar</item>
<item name="aboutViewTitleColor">@color/mainWindowTextColor</item>
<item name="aboutViewDividerColor">@color/mainWindowTextColor</item>
<item name="dialogBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="dialogTextColor">@color/mainWindowTextColor</item>
<item name="toolbarBackgroundColor">@color/toolbarBackgroundColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
<item name="textViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="textViewTextColor">@color/mainWindowTextColor</item>
<item name="editTextBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="editTextTextColor">@color/mainWindowTextColor</item>
<item name="scrollViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="activityBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="activityTextColor">@color/mainWindowTextColor</item>
<item name="mainWindowBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="mainWindowTextColor">@color/mainWindowTextColor</item>
<item name="mainWindowDarkBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="mainWindowDarkTextColor">@color/mainWindowTextColor</item>
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
</style> </style>
<style name="MyDepthAppTheme" parent="DepthAESTheme">
<item name="themeDebug">@style/MyDebugActivityTheme</item>
<item name="aToolbar">@style/MyAESAToolbar</item>
<item name="aSupportToolbar">@style/MyAESASupportToolbar</item>
</style>
<style name="MySkyAppTheme" parent="SkyAESTheme">
<item name="themeDebug">@style/MyDebugActivityTheme</item>
<item name="aToolbar">@style/MyAESAToolbar</item>
<item name="aSupportToolbar">@style/MyAESASupportToolbar</item>
</style>
<style name="MyGoldenAppTheme" parent="GoldenAESTheme">
<item name="themeDebug">@style/MyDebugActivityTheme</item>
<item name="aToolbar">@style/MyAESAToolbar</item>
<item name="aSupportToolbar">@style/MyAESASupportToolbar</item>
</style>
<style name="MyBearingAppTheme" parent="BearingAESTheme">
<item name="themeDebug">@style/MyDebugActivityTheme</item>
<item name="aToolbar">@style/MyAESAToolbar</item>
<item name="aSupportToolbar">@style/MyAESASupportToolbar</item>
</style>
<style name="MyMemorAppTheme" parent="MemorAESTheme">
<item name="themeDebug">@style/MyDebugActivityTheme</item>
<item name="aToolbar">@style/MyAESAToolbar</item>
<item name="aSupportToolbar">@style/MyAESASupportToolbar</item>
</style>
<style name="MyTaoAppTheme" parent="TaoAESTheme">
<item name="themeDebug">@style/MyDebugActivityTheme</item>
<item name="aToolbar">@style/MyAESAToolbar</item>
<item name="aSupportToolbar">@style/MyAESASupportToolbar</item>
</style>
<style name="MyAESAToolbar" parent="AESAToolbar" />
<style name="MyAESASupportToolbar" parent="AESASupportToolbar" />
<style name="MyDebugActivityTheme" parent="Theme.AppCompat.Light.NoActionBar"> <style name="MyDebugActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item> <item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="colorTittle">@color/mainWindowTextColor</item> <item name="colorTittle">@color/mainWindowTextColor</item>