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:
@@ -11,6 +11,7 @@ import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
||||
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.libappbase.LogUtils;
|
||||
import cc.winboll.studio.winboll.R;
|
||||
@@ -36,19 +37,17 @@ public class MainActivity extends DrawerFragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(cc.winboll.studio.winboll.theme.WinBoLLThemeUtil.getThemeTypeID(this));
|
||||
super.onCreate(savedInstanceState);
|
||||
// ------------------- 新增:初始化MainActivity的Handler(关键) -------------------
|
||||
initMainHandler();
|
||||
|
||||
if (mBrowserFragment == null) {
|
||||
LogUtils.d(TAG, "The code in this line is not fix yet.");
|
||||
// String externalUrl = extractExternalUrl(getIntent());
|
||||
// if (externalUrl != null) {
|
||||
// mBrowserFragment = BrowserFragment.newInstance(externalUrl);
|
||||
// } else {
|
||||
// mBrowserFragment = new BrowserFragment();
|
||||
// }
|
||||
// addFragment(mBrowserFragment);
|
||||
String externalUrl = extractExternalUrl(getIntent());
|
||||
if (externalUrl != null) {
|
||||
mBrowserFragment = BrowserFragment.newInstance(externalUrl);
|
||||
} else {
|
||||
mBrowserFragment = BrowserFragment.newInstance();
|
||||
}
|
||||
addFragment(mBrowserFragment);
|
||||
}
|
||||
showFragment(mBrowserFragment);
|
||||
}
|
||||
@@ -171,36 +170,35 @@ public class MainActivity extends DrawerFragmentActivity {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int nItemId = item.getItemId();
|
||||
if (nItemId == R.id.item_home) {
|
||||
// 发送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);
|
||||
if (AESThemeUtil.onWinBoLLThemeItemSelected(this, item)) {
|
||||
recreate();
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
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.winboll.theme.WinBoLLThemeUtil;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
@@ -29,16 +29,11 @@ public abstract class BaseWinBoLLActivity extends AppCompatActivity implements I
|
||||
}
|
||||
|
||||
AESThemeBean.ThemeType getThemeType() {
|
||||
/*SharedPreferences sharedPreferences = getSharedPreferences(
|
||||
SHAREDPREFERENCES_NAME, MODE_PRIVATE);
|
||||
return AESThemeBean.ThemeType.values()[((sharedPreferences.getInt(DRAWER_THEME_TYPE, AESThemeBean.ThemeType.DEFAULT.ordinal())))];
|
||||
*/
|
||||
return AESThemeBean.getThemeStyleType(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
return WinBoLLThemeUtil.getThemeStyleType(WinBoLLThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
}
|
||||
|
||||
void setThemeStyle() {
|
||||
//setTheme(AESThemeBean.getThemeStyle(getThemeType()));
|
||||
setTheme(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
setTheme(WinBoLLThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,50 @@
|
||||
<resources>
|
||||
<style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<style name="MyAppTheme" parent="AESTheme">
|
||||
<item name="themeDebug">@style/MyDebugActivityTheme</item>
|
||||
<item name="aboutViewBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="aboutViewTextColor">@color/mainWindowTextColor</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>
|
||||
<item name="aToolbar">@style/MyAESAToolbar</item>
|
||||
<item name="aSupportToolbar">@style/MyAESASupportToolbar</item>
|
||||
</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">
|
||||
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
|
||||
<item name="colorTittle">@color/mainWindowTextColor</item>
|
||||
|
||||
Reference in New Issue
Block a user