1818
1919package com .osfans .trime .data .theme ;
2020
21+ import android .content .res .Resources ;
2122import android .graphics .Bitmap ;
2223import android .graphics .BitmapFactory ;
2324import android .graphics .Color ;
@@ -63,7 +64,7 @@ public static Config get() {
6364
6465 private String soundPackageName , currentSound ;
6566 private static final String defaultThemeName = "trime" ;
66- private String currentSchemaId , currentColorSchemeId ;
67+ private String currentColorSchemeId ;
6768
6869 private Map <String , Object > generalStyle ;
6970 private Map <String , String > fallbackColors ;
@@ -76,10 +77,6 @@ public static Config get() {
7677 public Keyboards keyboards ;
7778
7879 public Config () {
79- this (false );
80- }
81-
82- public Config (boolean skipDeploy ) {
8380 self = this ;
8481 ThemeManager .init ();
8582 soundPackageName = appPrefs .getKeyboard ().getSoundPackage ();
@@ -88,11 +85,7 @@ public Config(boolean skipDeploy) {
8885 DataManager .sync ();
8986 Rime .get (!DataManager .INSTANCE .getSharedDataDir ().exists ());
9087
91- // 正常逻辑不应该部署全部主题,init()方法已经做过当前主题的部署
92- // Timber.d(methodName + "deployTheme");
93- // deployTheme();
94-
95- init (true );
88+ init ();
9689
9790 Timber .d ("Setting sound from color ..." );
9891 setSoundFromColor ();
@@ -141,17 +134,15 @@ public void setSoundFromColor() {
141134 }
142135 }
143136
144- public void init (boolean skipDeployment ) {
145- Timber .d ("Initializing theme ..., skip deployment: %s" , skipDeployment );
146- Timber .d (
147- "Current theme: %s, current schema id: %s" , ThemeManager .getActiveTheme (), currentSchemaId );
137+ public void init () {
138+ Timber .i ("Initializing theme, current theme name: %s ..." , ThemeManager .getActiveTheme ());
148139 try {
149140 final String fullThemeFileName = ThemeManager .getActiveTheme () + ".yaml" ;
150141 final File themeFile = new File (Rime .get_user_data_dir (), "build/" + fullThemeFileName );
151- if (skipDeployment && themeFile .exists ()) {
152- Timber .d ( "Skipped theme file deployment" );
142+ if (themeFile .exists ()) {
143+ Timber .i ( "Deployed file exists, skipping deployment ... " );
153144 } else {
154- Timber .d ("The theme has not been deployed yet, deploying ..." );
145+ Timber .i ("The theme has not been deployed yet, deploying ..." );
155146 Rime .deploy_config_file (fullThemeFileName , "config_version" );
156147 }
157148
@@ -179,7 +170,6 @@ public void init(boolean skipDeployment) {
179170 Timber .d ("Setting up all theme config map takes %s ms" , end - start );
180171 initLiquidKeyboard ();
181172 Timber .d ("init() initLiquidKeyboard done" );
182- reloadSchemaId ();
183173 Timber .d ("init() reset done" );
184174 initCurrentColors ();
185175 initEnterLabels ();
@@ -190,15 +180,11 @@ public void init(boolean skipDeployment) {
190180 Timber .e (e , "Failed to parse the theme!" );
191181 if (!ThemeManager .getActiveTheme ().equals (defaultThemeName )) {
192182 ThemeManager .switchTheme (defaultThemeName );
193- init (false );
183+ init ();
194184 }
195185 }
196186 }
197187
198- public void reloadSchemaId () {
199- currentSchemaId = Rime .getSchemaId ();
200- }
201-
202188 @ Nullable
203189 public static Object obtainValue (Map <String , Object > map , @ NonNull String vararg ) {
204190 if (map == null || map .isEmpty () || vararg .isEmpty ()) return null ;
@@ -665,7 +651,7 @@ private Drawable drawableBitmapObject(Object o) {
665651 final byte [] chunk = bitmap .getNinePatchChunk ();
666652 // 如果 .9.png 没有经过第一步,那么 chunk 就是 null, 只能按照普通方式加载
667653 if (NinePatch .isNinePatchChunk (chunk ))
668- return new NinePatchDrawable (bitmap , chunk , new Rect (), null );
654+ return new NinePatchDrawable (Resources . getSystem (), bitmap , chunk , new Rect (), null );
669655 }
670656 return Drawable .createFromPath (name );
671657 }
@@ -762,7 +748,7 @@ public Drawable getDrawableBitmap_(String key) {
762748 final Bitmap bitmap = BitmapFactory .decodeFile (path );
763749 final byte [] chunk = bitmap .getNinePatchChunk ();
764750 if (NinePatch .isNinePatchChunk (chunk ))
765- return new NinePatchDrawable (bitmap , chunk , new Rect (), null );
751+ return new NinePatchDrawable (Resources . getSystem (), bitmap , chunk , new Rect (), null );
766752 }
767753 return Drawable .createFromPath (path );
768754 }
@@ -777,10 +763,10 @@ public void initCurrentColors() {
777763 currentColors .clear ();
778764 currentColorSchemeId = getColorSchemeName ();
779765 backgroundFolder = style .getString ("background_folder" );
780- Timber .d ("Initializing currentColors ..." );
766+ Timber .d ("Caching color values ..." );
781767 Timber .d (
782- "currentColorSchemeId = %s, currentThemeName = %s, currentSchemaId = %s " ,
783- currentColorSchemeId , ThemeManager .getActiveTheme (), currentSchemaId );
768+ "currentColorSchemeId = %s, currentThemeName = %s" ,
769+ currentColorSchemeId , ThemeManager .getActiveTheme ());
784770 final Map <String , String > colorMap = presetColorSchemes .get (currentColorSchemeId );
785771 if (colorMap == null ) {
786772 Timber .d ("Color scheme id not found: %s" , currentColorSchemeId );
@@ -812,13 +798,12 @@ public void initCurrentColors(boolean darkMode) {
812798 currentColors .clear ();
813799 currentColorSchemeId = getColorSchemeName (darkMode );
814800 backgroundFolder = style .getString ("background_folder" );
815- Timber .d ("Initializing currentColors ..." );
816- Timber .d (
817- "currentColorSchemeId = %s, currentThemeName = %s, currentSchemaId = %s, isDarkMode = %s" ,
818- currentColorSchemeId , ThemeManager .getActiveTheme (), currentSchemaId , darkMode );
801+ Timber .i (
802+ "Caching currentColors (currentColorSchemeId=%s, isDarkMode=%s) ..." ,
803+ currentColorSchemeId , darkMode );
819804 final Map <String , String > colorMap = presetColorSchemes .get (currentColorSchemeId );
820805 if (colorMap == null ) {
821- Timber .i ("Color scheme id not found: %s" , currentColorSchemeId );
806+ Timber .w ("Color scheme id not found: %s" , currentColorSchemeId );
822807 return ;
823808 }
824809 appPrefs .getThemeAndColor ().setSelectedColor (currentColorSchemeId );
0 commit comments