Skip to content

Commit

Permalink
feat: Use Ace Editor instead of Sora editor for target old android de…
Browse files Browse the repository at this point in the history
…vices
  • Loading branch information
SyntaxGalaxy committed Nov 22, 2023
1 parent f618e00 commit 323707d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
12 changes: 2 additions & 10 deletions app/src/main/java/com/dragon/ide/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
import android.content.Intent;
import android.os.Process;
import android.util.Log;
import android.widget.Toast;
import com.dragon.ide.ui.activities.DebugActivity;
import com.dragon.ide.utils.Environments;
import com.google.android.material.color.DynamicColors;
import editor.tsd.editors.sora.lang.textmate.provider.TextMateProvider;
import io.github.rosemoe.sora.langs.textmate.registry.FileProviderRegistry;
import io.github.rosemoe.sora.langs.textmate.registry.provider.AssetsFileResolver;
import editor.tsd.editors.AceEditor;

public class MyApplication extends Application {
private Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
Expand Down Expand Up @@ -54,11 +51,6 @@ public void uncaughtException(Thread thread, Throwable throwable) {
}
});

FileProviderRegistry.getInstance().addFileProvider(new AssetsFileResolver(getAssets()));
try {
TextMateProvider.loadGrammars();
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
AceEditor.install(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import android.graphics.Color;
import com.dragon.ide.R;
import com.dragon.ide.databinding.LayoutSouceCodeDialogBinding;
import com.dragon.ide.utils.ColorUtils;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import editor.tsd.editors.ace.AceEditorColors;
import editor.tsd.tools.Themes;
import editor.tsd.widget.CodeEditorLayout;
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme;
Expand All @@ -15,16 +17,22 @@ public ShowSourceCodeDialog(Activity activity, String code, String language) {
LayoutSouceCodeDialogBinding binding =
LayoutSouceCodeDialogBinding.inflate(activity.getLayoutInflater());
setTitle(R.string.source_code);
binding.editor.setEditor(CodeEditorLayout.SoraCodeEditor);
binding.editor.setCode(code);
binding.editor.setTheme(Themes.SoraEditorTheme.Light.Quietlight);
AceEditorColors aceEditorColors = new AceEditorColors();
aceEditorColors.setEditorBackground("#00000000");
aceEditorColors.setActiveLineColor("#0000002d");
aceEditorColors.setGutterActiveLineColor("#0000002d");
aceEditorColors.setGutterBackground("#00000000");
aceEditorColors.setGutterTextColor(
String.format(
"#%06X",
(0xFFFFFF
& ColorUtils.getColor(
activity, com.google.android.material.R.attr.colorOnSurfaceVariant))));
aceEditorColors.apply(activity);
binding.editor.setEditor(CodeEditorLayout.AceCodeEditor);
binding.editor.setTheme(Themes.AceEditorTheme.Light.Chrome);
binding.editor.setLanguageMode(language);
binding.editor.getSoraCodeEditor().setEditable(false);
binding
.editor
.getSoraCodeEditor()
.getColorScheme()
.setColor(EditorColorScheme.CURRENT_LINE, Color.parseColor("#11000000"));
binding.editor.setCode(code);
setView(binding.getRoot());
setPositiveButton(R.string.cancel, (param1, param2) -> {});
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/layout_souce_code_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

<editor.tsd.widget.CodeEditorLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/editor" />
android:layout_width="match_parent"
android:id="@+id/editor"
android:minHeight="300dp"
app:codeEditor="SoraCodeEditor" />

</LinearLayout>

0 comments on commit 323707d

Please sign in to comment.