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_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_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_THEME = "editor.theme";
|
||||||
|
private static final String KEY_EDITOR_TEXT_SIZE = "editor.textSize";
|
||||||
|
|
||||||
private static SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
private static SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -157,4 +158,12 @@ public class Pref {
|
|||||||
public static void setCurrentTheme(String theme) {
|
public static void setCurrentTheme(String theme) {
|
||||||
def().edit().putString(KEY_EDITOR_THEME, theme).apply();
|
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:
|
case R.id.action_console:
|
||||||
showConsole();
|
showConsole();
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.action_editor_text_size:
|
||||||
|
mEditorView.selectTextSize();
|
||||||
|
return true;
|
||||||
case R.id.action_editor_theme:
|
case R.id.action_editor_theme:
|
||||||
mEditorView.selectEditorTheme();
|
mEditorView.selectEditorTheme();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import android.content.IntentFilter;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Gravity;
|
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.SimpleTextWatcher;
|
||||||
import com.stardust.scriptdroid.ui.widget.ToolbarMenuItem;
|
import com.stardust.scriptdroid.ui.widget.ToolbarMenuItem;
|
||||||
import com.stardust.util.BackPressedHandler;
|
import com.stardust.util.BackPressedHandler;
|
||||||
|
import com.stardust.util.ViewUtil;
|
||||||
|
import com.stardust.util.ViewUtils;
|
||||||
import com.stardust.widget.ViewSwitcher;
|
import com.stardust.widget.ViewSwitcher;
|
||||||
|
|
||||||
import org.androidannotations.annotations.AfterViews;
|
import org.androidannotations.annotations.AfterViews;
|
||||||
@@ -258,6 +259,7 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
|
|||||||
setMenuItemStatus(R.id.redo, mEditor.canRedo());
|
setMenuItemStatus(R.id.redo, mEditor.canRedo());
|
||||||
}));
|
}));
|
||||||
mEditor.setCursorChangeCallback(this::autoComplete);
|
mEditor.setCursorChangeCallback(this::autoComplete);
|
||||||
|
mEditor.getCodeEditText().setTextSize(Pref.getEditorTextSize((int) ViewUtils.pxToSp(getContext(), mEditor.getCodeEditText().getTextSize())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void autoComplete(String line, int cursor) {
|
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) {
|
private void selectEditorTheme(List<Theme> themes) {
|
||||||
int i = themes.indexOf(mEditorTheme);
|
int i = themes.indexOf(mEditorTheme);
|
||||||
if (i < 0) {
|
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.BuildConfig;
|
||||||
import com.stardust.scriptdroid.ui.edit.theme.Theme;
|
import com.stardust.scriptdroid.ui.edit.theme.Theme;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Administrator on 2018/2/11.
|
* Created by Administrator on 2018/2/11.
|
||||||
*/
|
*/
|
||||||
|
|||||||
57
app/src/main/res/layout/dialog_text_size_change.xml
Normal file
57
app/src/main/res/layout/dialog_text_size_change.xml
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:paddingTop="8dp">
|
||||||
|
|
||||||
|
<android.support.v7.widget.AppCompatSeekBar
|
||||||
|
android:id="@+id/seekbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:max="40"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<com.stardust.theme.widget.ThemeColorTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:text="@string/text_size_min_value"
|
||||||
|
android:textSize="16sp"/>
|
||||||
|
|
||||||
|
<com.stardust.theme.widget.ThemeColorTextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="@string/text_size_max_value"
|
||||||
|
android:textSize="16sp"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.stardust.theme.widget.ThemeColorTextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="@string/text_preview"
|
||||||
|
android:textColor="@android:color/primary_text_light"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/preview_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:minHeight="60dp"
|
||||||
|
android:text="@string/_app_name"
|
||||||
|
android:textColor="@android:color/primary_text_light"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -51,11 +51,6 @@
|
|||||||
|
|
||||||
<menu>
|
<menu>
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_jump_to_def"
|
|
||||||
android:title="@string/text_jump_to_def"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_jump_to_line"
|
android:id="@+id/action_jump_to_line"
|
||||||
android:title="@string/text_jump_to_line"
|
android:title="@string/text_jump_to_line"
|
||||||
@@ -106,6 +101,11 @@
|
|||||||
android:title="@string/text_info"
|
android:title="@string/text_info"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_editor_text_size"
|
||||||
|
android:title="@string/text_text_size"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_editor_theme"
|
android:id="@+id/action_editor_theme"
|
||||||
android:title="@string/text_editor_theme"
|
android:title="@string/text_editor_theme"
|
||||||
|
|||||||
@@ -343,4 +343,9 @@
|
|||||||
<string name="text_request_permission">重新授予</string>
|
<string name="text_request_permission">重新授予</string>
|
||||||
<string name="info_no_phone_state_permission">软件需要显示启动页广告来维持服务器和软件的开发和维护,因此需要\"读取手机状态\"的权限。\n如果您不喜欢广告,可以在设置中设定广告每天只显示一次。</string>
|
<string name="info_no_phone_state_permission">软件需要显示启动页广告来维持服务器和软件的开发和维护,因此需要\"读取手机状态\"的权限。\n如果您不喜欢广告,可以在设置中设定广告每天只显示一次。</string>
|
||||||
<string name="dex_crcs">1805165984\n1603032210\no7Za8UoEvAoTVZPxJAqmQA==V8tiED7XGmzTkAGKbFPjLw==</string>
|
<string name="dex_crcs">1805165984\n1603032210\no7Za8UoEvAoTVZPxJAqmQA==V8tiED7XGmzTkAGKbFPjLw==</string>
|
||||||
|
<string name="text_size_min_value">8</string>
|
||||||
|
<string name="text_size_max_value">56</string>
|
||||||
|
<string name="text_text_size">字体大小</string>
|
||||||
|
<string name="text_preview">预览</string>
|
||||||
|
<string name="text_size_current_value" formatted="true">字体大小: %d</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.stardust.util;
|
package com.stardust.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewParent;
|
import android.view.ViewParent;
|
||||||
|
|
||||||
@@ -20,4 +22,8 @@ public class ViewUtils {
|
|||||||
return findParentById(viewParent, id);
|
return findParentById(viewParent, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float pxToSp(Context context, float px) {
|
||||||
|
float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
|
||||||
|
return px / scaledDensity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user