28
28
import android .graphics .drawable .NinePatchDrawable ;
29
29
import androidx .annotation .NonNull ;
30
30
import androidx .annotation .Nullable ;
31
+ import com .blankj .utilcode .util .FileUtils ;
31
32
import com .osfans .trime .core .Rime ;
32
33
import com .osfans .trime .data .AppPrefs ;
33
34
import com .osfans .trime .data .DataManager ;
37
38
import com .osfans .trime .ime .symbol .TabManager ;
38
39
import com .osfans .trime .util .DimensionsKt ;
39
40
import java .io .File ;
40
- import java .io .FileInputStream ;
41
- import java .io .FileOutputStream ;
42
- import java .io .InputStream ;
43
- import java .io .OutputStream ;
44
41
import java .util .ArrayList ;
45
42
import java .util .HashMap ;
46
43
import java .util .List ;
@@ -118,36 +115,20 @@ public void setTheme(String theme) {
118
115
// 设置音效包
119
116
public void setSoundPackage (String name ) {
120
117
soundPackageName = name ;
121
- String path = userDataDir + File .separator + "sound" + File .separator + name + ".sound.yaml" ;
122
- File file = new File (path );
123
- if (file .exists ()) {
124
- applySoundPackage (file , name );
125
- }
118
+ applySoundPackage (name );
126
119
appPrefs .getKeyboard ().setSoundPackage (soundPackageName );
127
120
}
128
121
129
122
// 应用音效包
130
- private void applySoundPackage (File file , String name ) {
131
- // copy soundpackage yaml file from sound folder to build folder
132
- try {
133
- InputStream in = new FileInputStream (file );
134
- OutputStream out =
135
- new FileOutputStream (
136
- userDataDir + File .separator + "build" + File .separator + name + ".sound.yaml" );
137
-
138
- byte [] buffer = new byte [1024 ];
139
- int len ;
140
- while ((len = in .read (buffer )) > 0 ) {
141
- out .write (buffer , 0 , len );
142
- }
143
- in .close ();
144
- out .close ();
145
- Timber .i ("applySoundPackage=%s" , name );
146
- } catch (Exception e ) {
147
- e .printStackTrace ();
123
+ private boolean applySoundPackage (@ NonNull String name ) {
124
+ final String src = userDataDir + "/sound/" + name + ".sound.yaml" ;
125
+ final String dest = userDataDir + "/build/" + name + ".sound.yaml" ;
126
+ boolean result = FileUtils .copy (src , dest );
127
+ if (result ) {
128
+ Sound .get (name );
129
+ currentSound = name ;
148
130
}
149
- Sound .get (name );
150
- currentSound = name ;
131
+ return result ;
151
132
}
152
133
153
134
// 配色指定音效时自动切换音效效果(不会自动修改设置)。
@@ -157,9 +138,7 @@ public void setSoundFromColor() {
157
138
if (m .containsKey ("sound" )) {
158
139
String sound = m .get ("sound" );
159
140
if (!Objects .equals (sound , currentSound )) {
160
- File file = new File (userDataDir + "/sound/" + sound + ".sound.yaml" );
161
- if (file .exists ()) {
162
- applySoundPackage (file , sound );
141
+ if (applySoundPackage (sound )) {
163
142
return ;
164
143
}
165
144
}
0 commit comments