feat: supports changing editor text size
This commit is contained in:
@@ -20,6 +20,7 @@ public class Pref {
|
||||
private static final String KEY_LAST_SHOW_AD_MILLIS = "But... it seems that...you will not come back any more...";
|
||||
private static final String KEY_FLOATING_MENU_SHOWN = "17.10.28 I have idea of what you think...maybe...I'm overthinking...";
|
||||
private static final String KEY_EDITOR_THEME = "editor.theme";
|
||||
private static final String KEY_EDITOR_TEXT_SIZE = "editor.textSize";
|
||||
|
||||
private static SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
@@ -157,4 +158,12 @@ public class Pref {
|
||||
public static void setCurrentTheme(String theme) {
|
||||
def().edit().putString(KEY_EDITOR_THEME, theme).apply();
|
||||
}
|
||||
|
||||
public static void setEditorTextSize(int value) {
|
||||
def().edit().putInt(KEY_EDITOR_TEXT_SIZE, value).apply();
|
||||
}
|
||||
|
||||
public static int getEditorTextSize(int defVlaue) {
|
||||
return def().getInt(KEY_EDITOR_TEXT_SIZE, defVlaue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,9 @@ public class EditorMenu {
|
||||
case R.id.action_console:
|
||||
showConsole();
|
||||
return true;
|
||||
case R.id.action_editor_text_size:
|
||||
mEditorView.selectTextSize();
|
||||
return true;
|
||||
case R.id.action_editor_theme:
|
||||
mEditorView.selectEditorTheme();
|
||||
return true;
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.content.IntentFilter;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
@@ -42,6 +41,8 @@ import com.stardust.scriptdroid.ui.widget.EWebView;
|
||||
import com.stardust.scriptdroid.ui.widget.SimpleTextWatcher;
|
||||
import com.stardust.scriptdroid.ui.widget.ToolbarMenuItem;
|
||||
import com.stardust.util.BackPressedHandler;
|
||||
import com.stardust.util.ViewUtil;
|
||||
import com.stardust.util.ViewUtils;
|
||||
import com.stardust.widget.ViewSwitcher;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
@@ -258,6 +259,7 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
|
||||
setMenuItemStatus(R.id.redo, mEditor.canRedo());
|
||||
}));
|
||||
mEditor.setCursorChangeCallback(this::autoComplete);
|
||||
mEditor.getCodeEditText().setTextSize(Pref.getEditorTextSize((int) ViewUtils.pxToSp(getContext(), mEditor.getCodeEditText().getTextSize())));
|
||||
}
|
||||
|
||||
private void autoComplete(String line, int cursor) {
|
||||
@@ -390,6 +392,18 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
|
||||
});
|
||||
}
|
||||
|
||||
public void selectTextSize() {
|
||||
new TextSizeChangeDialogBuilder(getContext())
|
||||
.initialValue((int) ViewUtils.pxToSp(getContext(), mEditor.getCodeEditText().getTextSize()))
|
||||
.callback(this::setTextSize)
|
||||
.show();
|
||||
}
|
||||
|
||||
public void setTextSize(int value) {
|
||||
Pref.setEditorTextSize(value);
|
||||
mEditor.getCodeEditText().setTextSize(value);
|
||||
}
|
||||
|
||||
private void selectEditorTheme(List<Theme> themes) {
|
||||
int i = themes.indexOf(mEditorTheme);
|
||||
if (i < 0) {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.stardust.scriptdroid.ui.edit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/2/24.
|
||||
*/
|
||||
|
||||
public class TextSizeChangeDialogBuilder extends ThemeColorMaterialDialogBuilder implements SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
|
||||
public interface PositiveCallback {
|
||||
|
||||
void onPositive(int value);
|
||||
}
|
||||
|
||||
private static final int MIN = 8;
|
||||
|
||||
@BindView(R.id.seekbar)
|
||||
SeekBar mSeekBar;
|
||||
|
||||
@BindView(R.id.preview_text)
|
||||
TextView mPreviewText;
|
||||
|
||||
private int mTextSize;
|
||||
private MaterialDialog mMaterialDialog;
|
||||
|
||||
public TextSizeChangeDialogBuilder(@NonNull Context context) {
|
||||
super(context);
|
||||
View view = View.inflate(context, R.layout.dialog_text_size_change, null);
|
||||
customView(view, false);
|
||||
title(R.string.text_text_size);
|
||||
positiveText(R.string.ok);
|
||||
negativeText(R.string.cancel);
|
||||
ButterKnife.bind(this, view);
|
||||
mSeekBar.setOnSeekBarChangeListener(this);
|
||||
}
|
||||
|
||||
private void setTextSize(int textSize) {
|
||||
mTextSize = textSize;
|
||||
String title = getContext().getString(R.string.text_size_current_value, textSize);
|
||||
if (mMaterialDialog != null) {
|
||||
mMaterialDialog.setTitle(title);
|
||||
} else {
|
||||
title(title);
|
||||
}
|
||||
mPreviewText.setTextSize(textSize);
|
||||
}
|
||||
|
||||
public TextSizeChangeDialogBuilder initialValue(int value) {
|
||||
mSeekBar.setProgress(value - MIN);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextSizeChangeDialogBuilder callback(PositiveCallback callback) {
|
||||
onPositive((dialog, which) -> callback.onPositive(mTextSize));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialDialog build() {
|
||||
mMaterialDialog = super.build();
|
||||
return mMaterialDialog;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
setTextSize(progress + MIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,8 @@ import android.view.Gravity;
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.ui.edit.theme.Theme;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/2/11.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user