Skip to content

Commit a04b924

Browse files
authored
fix: correct font path for SoraEditor
fix: Type: RuntimeException Message: Font asset not found /fonts/SourceCodePro-Regular.ttf StackTrace: at android.graphics.Typeface.createFromFile(Typeface.java:1094) at org.xedox.webaide.sora.SoraEditor.init(SoraEditor.java:41) at org.xedox.webaide.sora.SoraEditor.<init>(SoraEditor.java:35) at org.xedox.webaide.sora.SoraEditor.<init>(SoraEditor.java:30) at org.xedox.webaide.sora.SoraEditor.<init>(SoraEditor.java:26) at org.xedox.webaide.editor.FileFragment.onCreateView(FileFragment.java:61) at androidx.fragment.app.Fragment.performCreateView(Fragment.java:3104) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:524) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1899) at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1817) at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1729) at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:317) at androidx.viewpager2.adapter.FragmentStateAdapter.placeFragmentInViewHolder(FragmentStateAdapter.java:343) at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:274) at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:74) at androidx.recyclerview.widget.RecyclerView.dispatchChildAttached(RecyclerView.java:8377) at androidx.recyclerview.widget.RecyclerView$5.addView(RecyclerView.java:954) at androidx.recyclerview.widget.ChildHelper.addView(ChildHelper.java:131) at androidx.recyclerview.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:9430) at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:9388) at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:9375) at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1676) at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1622) at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:687) at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4645) at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4348) at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4919) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at androidx.viewpager2.widget.ViewPager2.onLayout(ViewPager2.java:535) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1103) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1103) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1263) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673) at android.widget.LinearLayout.onLayout(LinearLayout.java:1582) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673) at android.widget.LinearLayout.onLayout(LinearLayout.java:1582) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at com.android.internal.policy.DecorView.onLayout(DecorView.java:798) at android.view.View.layout(View.java:23322) at android.view.ViewGroup.layout(ViewGroup.java:6541) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3874) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3330) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2306) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8904) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1038) at android.view.Choreographer.doCallbacks(Choreographer.java:846) at android.view.Choreographer.doFrame(Choreographer.java:781) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1023) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7996) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:553) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
1 parent 5457c51 commit a04b924

1 file changed

Lines changed: 228 additions & 0 deletions

File tree

main/src/main/java/org/xedox/webaide/SettingsActivity.java

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,234 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
148148
}
149149
}
150150

151+
public static class EditorFragment extends PreferenceFragmentCompat
152+
implements Preference.OnPreferenceChangeListener {
153+
154+
public EditorFragment() {}
155+
156+
@Override
157+
public void onCreatePreferences(Bundle extraArgs, String root) {
158+
setPreferencesFromResource(R.xml.settings_editor, root);
159+
160+
Preference useTabPref = findPreference("editor_use_tab");
161+
Preference indentSizePref = findPreference("editor_indent_size");
162+
163+
if (useTabPref != null) {
164+
useTabPref.setOnPreferenceChangeListener(this);
165+
}
166+
if (indentSizePref != null) {
167+
indentSizePref.setOnPreferenceChangeListener(this);
168+
}
169+
170+
MaterialListPreference fontsPref = findPreference("editor_font");
171+
try {
172+
List<File> fontSources = Arrays.asList(AppCore.fontList());
173+
String[] entries = new String[fontSources.size()];
174+
String[] values = new String[fontSources.size()];
175+
176+
for (int i = 0; i < fontSources.size(); i++) {
177+
File fontFile = fontSources.get(i);
178+
entries[i] = fontFile.getName();
179+
values[i] = fontFile.getAbsolutePath();
180+
}
181+
182+
fontsPref.setEntries(entries);
183+
fontsPref.setEntryValues(values);
184+
185+
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireContext());
186+
String currentFont = sp.getString("editor_font", null);
187+
if (currentFont == null) {
188+
String defaultFont = AppCore.dir("fonts") + "SourceCodePro-Regular.ttf";
189+
fontsPref.setValue(defaultFont);
190+
sp.edit().putString("editor_font", defaultFont).apply();
191+
} else {
192+
fontsPref.setValue(currentFont);
193+
}
194+
195+
} catch (Exception err) {
196+
ErrorDialog.show(requireActivity(), err);
197+
}
198+
199+
MaterialListPreference themesPref = findPreference("editor_theme");
200+
try {
201+
SoraEditorManager.Theme[] themes = SoraEditorManager.getThemesList();
202+
String[] names = new String[themes.length];
203+
for (int i = 0; i < themes.length; i++) {
204+
names[i] = themes[i].name;
205+
}
206+
themesPref.setEntries(names);
207+
themesPref.setEntryValues(names);
208+
209+
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireContext());
210+
String currentTheme = sp.getString("editor_theme", null);
211+
if (currentTheme == null) {
212+
String defaultTheme = "Darcula";
213+
themesPref.setValue(defaultTheme);
214+
sp.edit().putString("editor_theme", defaultTheme).apply();
215+
} else {
216+
themesPref.setValue(currentTheme);
217+
}
218+
219+
} catch (Exception err) {
220+
ErrorDialog.show(requireActivity(), err);
221+
}
222+
223+
if (themesPref != null) {
224+
themesPref.setOnPreferenceChangeListener(this);
225+
}
226+
if (fontsPref != null) {
227+
fontsPref.setOnPreferenceChangeListener(this);
228+
}
229+
}
230+
231+
@Override
232+
public boolean onPreferenceChange(Preference preference, Object newValue) {
233+
String key = preference.getKey();
234+
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireContext());
235+
SharedPreferences.Editor editor = sp.edit();
236+
String value = newValue.toString();
237+
238+
if (key.equals("editor_use_tab")) {
239+
boolean useTab = (Boolean) newValue;
240+
editor.putBoolean(key, useTab).apply();
241+
FormatConfig.getInstance().setUseTab(useTab);
242+
return true;
243+
} else if (key.equals("editor_font")) {
244+
editor.putString(key, value).apply();
245+
SoraEditorManager.updateFont(value);
246+
return true;
247+
} else if (key.equals("editor_theme")) {
248+
editor.putString(key, value).apply();
249+
SoraEditorManager.updateTheme(value);
250+
return true;
251+
} else if (key.equals("editor_indent_size")) {
252+
try {
253+
int indentSize = Integer.parseInt(value);
254+
editor.putString(key, value).apply();
255+
FormatConfig.getInstance().setIndentSize(indentSize);
256+
} catch (Exception e) {
257+
ErrorDialog.show(requireActivity(), e);
258+
}
259+
return true;
260+
}
261+
262+
return false;
263+
}
264+
}
265+
} getSupportActionBar().setDisplayShowHomeEnabled(true);
266+
267+
if (savedInstanceState == null) {
268+
getSupportFragmentManager()
269+
.beginTransaction()
270+
.replace(R.id.content, new SettingsFragment())
271+
.commit();
272+
}
273+
} catch (Exception err) {
274+
ErrorDialog.show(this, err);
275+
}
276+
}
277+
278+
@Override
279+
public boolean onOptionsItemSelected(MenuItem item) {
280+
int id = item.getItemId();
281+
if (id == android.R.id.home) {
282+
handleBackPressed();
283+
return true;
284+
}
285+
return super.onOptionsItemSelected(item);
286+
}
287+
288+
@Override
289+
public void handleBackPressed() {
290+
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
291+
getSupportFragmentManager().popBackStack();
292+
} else {
293+
finish();
294+
}
295+
}
296+
297+
public static class SettingsFragment extends PreferenceFragmentCompat
298+
implements Preference.OnPreferenceClickListener {
299+
300+
public SettingsFragment() {}
301+
302+
@Override
303+
public void onCreatePreferences(Bundle extraArgs, String root) {
304+
setPreferencesFromResource(R.xml.settings_preferences, root);
305+
306+
Preference generalPref = findPreference("general_settings");
307+
Preference editorPref = findPreference("editor_settings");
308+
309+
if (generalPref != null) {
310+
generalPref.setOnPreferenceClickListener(this);
311+
}
312+
if (editorPref != null) {
313+
editorPref.setOnPreferenceClickListener(this);
314+
}
315+
}
316+
317+
@Override
318+
public boolean onPreferenceClick(Preference preference) {
319+
String key = preference.getKey();
320+
321+
if (key.equals("general_settings")) {
322+
navigateToFragment(new GeneralFragment());
323+
return true;
324+
} else if (key.equals("editor_settings")) {
325+
navigateToFragment(new EditorFragment());
326+
return true;
327+
}
328+
329+
return false;
330+
}
331+
332+
private void navigateToFragment(PreferenceFragmentCompat fragment) {
333+
requireActivity()
334+
.getSupportFragmentManager()
335+
.beginTransaction()
336+
.replace(R.id.content, fragment)
337+
.addToBackStack(null)
338+
.commit();
339+
}
340+
}
341+
342+
public static class GeneralFragment extends PreferenceFragmentCompat
343+
implements Preference.OnPreferenceChangeListener {
344+
345+
public GeneralFragment() {}
346+
347+
@Override
348+
public void onCreatePreferences(Bundle extraArgs, String root) {
349+
setPreferencesFromResource(R.xml.settings_general, root);
350+
351+
Preference appDialogTypePref = findPreference("app_dialog_type");
352+
Preference recopyAssetsPref = findPreference("recopy_assets");
353+
recopyAssetsPref.setOnPreferenceClickListener(
354+
(v) -> {
355+
CopyAssetsDialog.show(requireActivity());
356+
return true;
357+
});
358+
if (appDialogTypePref != null) {
359+
appDialogTypePref.setOnPreferenceChangeListener(this);
360+
}
361+
}
362+
363+
@Override
364+
public boolean onPreferenceChange(Preference preference, Object newValue) {
365+
String key = preference.getKey();
366+
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireContext());
367+
SharedPreferences.Editor editor = sp.edit();
368+
369+
if (key.equals("app_dialog_type")) {
370+
editor.putString(key, newValue.toString()).apply();
371+
AppCore.setDialogType(newValue.toString());
372+
return true;
373+
}
374+
375+
return false;
376+
}
377+
}
378+
151379
public static class EditorFragment extends PreferenceFragmentCompat
152380
implements Preference.OnPreferenceChangeListener {
153381

0 commit comments

Comments
 (0)