Skip to content

Commit

Permalink
add custom font
Browse files Browse the repository at this point in the history
  • Loading branch information
PangBaiWork committed May 1, 2024
1 parent 00adc9e commit 25fe309
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ protected void onCreate(Bundle savedInstanceState) {
void setEditor() {
binding.editor.setCursorAnimationEnabled(false);
binding.editSymbol.init(binding.editor);
String fontPath= PrefManager.getString(PrefManager.Keys.interface_font,null);
binding.editor.setFont(fontPath);

//binding.editor.getProps().disallowSuggestions=true;

binding.editor.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
Expand Down
30 changes: 19 additions & 11 deletions app/src/main/java/com/pangbai/weblog/editor/Editor.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
package com.pangbai.weblog.editor;

import static com.pangbai.weblog.tool.util.runOnUiThread;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.view.inputmethod.ExtractedTextRequest;

import androidx.annotation.Nullable;

import com.google.android.material.snackbar.Snackbar;
import com.pangbai.weblog.tool.IO;
import com.pangbai.weblog.tool.ThreadUtil;

import java.io.FileOutputStream;
import java.io.IOException;

import io.github.rosemoe.sora.text.ContentIO;
import io.github.rosemoe.sora.widget.CodeEditor;

public class Editor extends CodeEditor {
Expand All @@ -35,6 +25,24 @@ public Editor(Context context, AttributeSet attrs, int defStyleAttr) {
public Editor(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public void setFont(@Nullable String path){
Typeface font;
if (path==null) {
font= Typeface.createFromAsset(getContext().getAssets(), "font/JetBrainsMono-Regular.ttf");
setTypefaceText(font);

}else {
try {
font=Typeface.createFromFile(path);
setTypefaceText(font);
}catch (Exception ignored){

}


}

}

// Disable inputMethod suggestion when editor focused
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public enum Keys {
category,
current_project,
current_file,
interface_font,
first_launch_mark,
bl_interface_undo_button_display,
bl_artical_title_to_md5
bl_artical_title_to_md5,

}

static SharedPreferences pref;
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/header_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
app:summaryOn="Always visible"
app:icon="@drawable/ic_file_previous"
app:title="Undo float action button" />
<EditTextPreference
app:key="interface_font"
app:summary="Custom Font"
android:dialogTitle="Please input font Path"
app:title="Set Font"/>

</PreferenceCategory>
<PreferenceCategory app:title="Artical">
Expand Down

0 comments on commit 25fe309

Please sign in to comment.