Editor text size

This commit is contained in:
serso 2016-02-22 13:19:30 +01:00
parent 8658fd9fe5
commit 282d17ad1c
17 changed files with 39 additions and 48 deletions

View File

@ -65,7 +65,10 @@ public class EditorView extends EditTextCompat {
}
private void init() {
Adjuster.adjustText(this, 0.25f);
if (!isFloatingCalculator()) {
Adjuster.adjustText(this, 0.22f,
getResources().getDimensionPixelSize(R.dimen.cpp_min_editor_text_size));
}
addTextChangedListener(new MyTextWatcher());
dontShowSoftInputOnFocusCompat();
// changes should only be reported after the view has been set up completely, i.e. now
@ -86,7 +89,7 @@ public class EditorView extends EditTextCompat {
Check.isMainThread();
// we don't want to be notified about changes we make ourselves
reportChanges = false;
if (App.getTheme().light && getContext() instanceof FloatingCalculatorService) {
if (App.getTheme().light && isFloatingCalculator()) {
// don't need formatting
setText(state.getTextString());
} else {
@ -96,6 +99,10 @@ public class EditorView extends EditTextCompat {
reportChanges = true;
}
private boolean isFloatingCalculator() {
return getContext() instanceof FloatingCalculatorService;
}
@Override
protected void onSelectionChanged(int start, int end) {
Check.isMainThread();

View File

@ -1,5 +1,7 @@
package org.solovyev.android.views;
import static android.graphics.Matrix.MSCALE_Y;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -9,18 +11,20 @@ import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.TextView;
import static android.graphics.Matrix.MSCALE_Y;
public class Adjuster {
private static final float[] MATRIX = new float[9];
public static void adjustText(@NonNull final TextView view, final float percentage) {
adjustText(view, percentage, 0);
}
public static void adjustText(@NonNull final TextView view, final float percentage, final float minTextSizePxs) {
ViewTreeObserver treeObserver = getTreeObserver(view);
if (treeObserver == null) {
return;
}
treeObserver.addOnPreDrawListener(new TextViewAdjuster(view, percentage));
treeObserver.addOnPreDrawListener(new TextViewAdjuster(view, percentage, minTextSizePxs));
}
@Nullable
@ -47,11 +51,13 @@ public class Adjuster {
@NonNull
private final TextView view;
private final float percentage;
private final float minTextSizePxs;
private int lastHeight;
public TextViewAdjuster(@NonNull TextView view, float percentage) {
public TextViewAdjuster(@NonNull TextView view, float percentage, float minTextSizePxs) {
this.view = view;
this.percentage = percentage;
this.minTextSizePxs = minTextSizePxs;
}
@Override
@ -62,7 +68,7 @@ public class Adjuster {
}
lastHeight = height;
final float oldTextSize = Math.round(view.getTextSize());
final float newTextSize = Math.round(height * percentage);
final float newTextSize = Math.max(minTextSizePxs, Math.round(height * percentage));
if (oldTextSize == newTextSize) {
return true;
}

View File

@ -6,17 +6,7 @@
~ or visit http://se.solovyev.org
-->
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout"
style="@style/CppFragment"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:padding="@dimen/cpp_editor_padding">
<org.solovyev.android.calculator.EditorView
a:id="@+id/calculator_editor"
style="@style/CppText.Editor.Onscreen"
a:textIsSelectable="true" />
</LinearLayout>
<org.solovyev.android.calculator.EditorView xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/calculator_editor"
style="@style/CppText.Editor.Onscreen"
a:textIsSelectable="true" />

View File

@ -6,17 +6,7 @@
~ or visit http://se.solovyev.org
-->
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout"
style="@style/CppFragment"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:padding="@dimen/cpp_editor_padding">
<org.solovyev.android.calculator.EditorView
a:id="@+id/calculator_editor"
style="@style/CppText.Editor.Onscreen.Light"
a:textIsSelectable="true" />
</LinearLayout>
<org.solovyev.android.calculator.EditorView xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/calculator_editor"
style="@style/CppText.Editor.Onscreen.Light"
a:textIsSelectable="true" />

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
style="@style/CppMain.Onscreen"
a:orientation="vertical">

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
style="@style/CppMain.Onscreen.Light"
a:orientation="vertical">

View File

@ -21,7 +21,6 @@
-->
<resources>
<dimen name="cpp_editor_text_size">20sp</dimen>
<dimen name="cpp_display_text_size">20sp</dimen>
<dimen name="cpp_keyboard_button_text_size">24dp</dimen>
</resources>

View File

@ -21,7 +21,6 @@
-->
<resources>
<dimen name="cpp_editor_text_size">25sp</dimen>
<dimen name="cpp_display_text_size">20sp</dimen>
<dimen name="cpp_keyboard_button_text_size">35dp</dimen>
</resources>

View File

@ -21,7 +21,6 @@
-->
<resources>
<dimen name="cpp_editor_text_size">30sp</dimen>
<dimen name="cpp_display_text_size">30sp</dimen>
<dimen name="cpp_keyboard_button_text_size">33dp</dimen>
</resources>

View File

@ -21,6 +21,7 @@
-->
<resources>
<dimen name="cpp_min_editor_text_size">28sp</dimen>
<dimen name="cpp_fragment_text_size">17sp</dimen>
<dimen name="cpp_fragment_title_text_size">25sp</dimen>
</resources>

View File

@ -22,6 +22,6 @@
<resources>
<dimen name="cpp_fragment_text_size">15sp</dimen>
<dimen name="cpp_editor_text_size">30sp</dimen>
<dimen name="cpp_min_editor_text_size">24sp</dimen>
<dimen name="cpp_display_text_size">30sp</dimen>
</resources>

View File

@ -22,7 +22,7 @@
<resources>
<dimen name="cpp_fragment_text_size">15sp</dimen>
<dimen name="cpp_editor_text_size">20sp</dimen>
<dimen name="cpp_min_editor_text_size">18sp</dimen>
<dimen name="cpp_display_text_size">20sp</dimen>
<dimen name="cpp_clickable_area_size">40dp</dimen>
</resources>

View File

@ -21,7 +21,6 @@
-->
<resources>
<dimen name="cpp_editor_text_size">30sp</dimen>
<dimen name="cpp_display_text_size">30sp</dimen>
<dimen name="cpp_keyboard_button_text_size">40dp</dimen>
</resources>

View File

@ -21,7 +21,6 @@
-->
<resources>
<dimen name="cpp_editor_text_size">40sp</dimen>
<dimen name="cpp_display_text_size">30sp</dimen>
<dimen name="cpp_keyboard_button_text_size">35dp</dimen>
</resources>

View File

@ -21,6 +21,7 @@
-->
<resources>
<dimen name="cpp_min_editor_text_size">32sp</dimen>
<dimen name="cpp_fragment_text_size">30sp</dimen>
<dimen name="cpp_fragment_title_text_size">40sp</dimen>
</resources>

View File

@ -17,7 +17,7 @@
<dimen name="cpp_keyboard_simple_image_button_padding">12dp</dimen>
<dimen name="cpp_display_text_size">25sp</dimen>
<dimen name="cpp_editor_text_size">25sp</dimen>
<dimen name="cpp_min_editor_text_size">24sp</dimen>
<dimen name="cpp_pane_margin">2dp</dimen>
<dimen name="cpp_li_text_size">16sp</dimen>
<dimen name="cpp_li_secondary_text_size">14sp</dimen>

View File

@ -52,7 +52,10 @@
<item name="android:maxLines">1</item>
<item name="android:minLines">1</item>
<item name="android:lines">1</item>
<item name="android:inputType">text|textNoSuggestions</item>
<item name="android:gravity">center_vertical|left</item>
<item name="android:scrollbars">horizontal</item>
<item name="android:padding">@dimen/cpp_editor_padding</item>
<item name="android:textColor">@color/cpp_text</item>
</style>
@ -61,7 +64,7 @@
<item name="android:gravity">left|top</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:textSize">@dimen/cpp_editor_text_size</item>
<item name="android:textSize">@dimen/cpp_min_editor_text_size</item>
<item name="android:textColor">?attr/cpp_text_color</item>
<item name="android:inputType">textMultiLine|textNoSuggestions</item>
</style>