cpp-143: Calculator text size dynamically in Bug Buttons layout
Fixes #143
This commit is contained in:
parent
496a1e9a79
commit
c56f61a138
@ -34,6 +34,7 @@ import android.util.Log;
|
|||||||
import org.solovyev.android.UiThreadExecutor;
|
import org.solovyev.android.UiThreadExecutor;
|
||||||
import org.solovyev.android.Views;
|
import org.solovyev.android.Views;
|
||||||
import org.solovyev.android.calculator.ga.Ga;
|
import org.solovyev.android.calculator.ga.Ga;
|
||||||
|
import org.solovyev.android.calculator.view.ScreenMetrics;
|
||||||
import org.solovyev.android.checkout.*;
|
import org.solovyev.android.checkout.*;
|
||||||
import org.solovyev.android.view.VibratorContainer;
|
import org.solovyev.android.view.VibratorContainer;
|
||||||
import org.solovyev.common.listeners.JEvent;
|
import org.solovyev.common.listeners.JEvent;
|
||||||
@ -105,6 +106,9 @@ public final class App {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private static volatile Vibrator vibrator;
|
private static volatile Vibrator vibrator;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private static volatile ScreenMetrics screenMetrics;
|
||||||
|
|
||||||
private App() {
|
private App() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@ -161,6 +165,7 @@ public final class App {
|
|||||||
}
|
}
|
||||||
App.broadcaster = new CalculatorBroadcaster(application);
|
App.broadcaster = new CalculatorBroadcaster(application);
|
||||||
App.vibrator = new Vibrator(application, preferences);
|
App.vibrator = new Vibrator(application, preferences);
|
||||||
|
App.screenMetrics = new ScreenMetrics(application);
|
||||||
App.initialized = true;
|
App.initialized = true;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Already initialized!");
|
throw new IllegalStateException("Already initialized!");
|
||||||
@ -261,4 +266,9 @@ public final class App {
|
|||||||
public static Vibrator getVibrator() {
|
public static Vibrator getVibrator() {
|
||||||
return vibrator;
|
return vibrator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static ScreenMetrics getScreenMetrics() {
|
||||||
|
return screenMetrics;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ import org.solovyev.android.calculator.view.NumeralBasesButton;
|
|||||||
import org.solovyev.android.calculator.drag.DragButton;
|
import org.solovyev.android.calculator.drag.DragButton;
|
||||||
import org.solovyev.android.calculator.drag.DragDirection;
|
import org.solovyev.android.calculator.drag.DragDirection;
|
||||||
import org.solovyev.android.calculator.drag.SimpleDragListener;
|
import org.solovyev.android.calculator.drag.SimpleDragListener;
|
||||||
|
import org.solovyev.android.calculator.view.ScreenMetrics;
|
||||||
import org.solovyev.common.math.Point2d;
|
import org.solovyev.common.math.Point2d;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -64,7 +65,12 @@ public final class CalculatorButtons {
|
|||||||
@Nonnull View root) {
|
@Nonnull View root) {
|
||||||
if (!layout.isOptimized()) {
|
if (!layout.isOptimized()) {
|
||||||
|
|
||||||
final float textSize = root.getContext().getResources().getDimensionPixelSize(R.dimen.cpp_keyboard_button_text_size_mobile);
|
final ScreenMetrics metrics = App.getScreenMetrics();
|
||||||
|
final boolean portrait = metrics.isInPortraitMode();
|
||||||
|
final int buttonsCount = portrait ? 5 : 4;
|
||||||
|
final int buttonsWeight = portrait ? (2 + 1 + buttonsCount) : (2 + buttonsCount);
|
||||||
|
final int buttonSize = metrics.getHeightPxs() / buttonsWeight;
|
||||||
|
final int textSize = 5 * buttonSize / 12;
|
||||||
|
|
||||||
Views.processViewsOfType(root, DragButton.class, new Views.ViewProcessor<DragButton>() {
|
Views.processViewsOfType(root, DragButton.class, new Views.ViewProcessor<DragButton>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,120 @@
|
|||||||
|
package org.solovyev.android.calculator.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class ScreenMetrics {
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private final android.view.Display display;
|
||||||
|
@Nonnull
|
||||||
|
private final DisplayMetrics metrics;
|
||||||
|
private float xDpi;
|
||||||
|
private float yDpi;
|
||||||
|
private float diagonalIns;
|
||||||
|
private float widthIns;
|
||||||
|
private float heightIns;
|
||||||
|
private final int layout;
|
||||||
|
|
||||||
|
public ScreenMetrics(@Nonnull Context context) {
|
||||||
|
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||||
|
display = wm.getDefaultDisplay();
|
||||||
|
metrics = new DisplayMetrics();
|
||||||
|
display.getMetrics(metrics);
|
||||||
|
initDpi();
|
||||||
|
initDimensions();
|
||||||
|
layout = context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initDpi() {
|
||||||
|
if ((Build.DEVICE.equals("qsd8250_surf")
|
||||||
|
|| Build.MODEL.equals("Dell Streak"))) {
|
||||||
|
xDpi = 190f;
|
||||||
|
yDpi = 190f;
|
||||||
|
} else if (Build.MODEL.equals("VTAB1008")) {
|
||||||
|
xDpi = 160f;
|
||||||
|
yDpi = 160f;
|
||||||
|
} else if (Build.MODEL.equals("Dell Streak 7")) {
|
||||||
|
xDpi = 150f;
|
||||||
|
yDpi = 150f;
|
||||||
|
} else if (Build.MODEL.equals("A1_07")) {
|
||||||
|
xDpi = 127.5f;
|
||||||
|
yDpi = 100f;
|
||||||
|
} else if (Build.MODEL.equals("N12GPS")
|
||||||
|
|| Build.MODEL.equals("MID_Serials")) {
|
||||||
|
xDpi = 133f;
|
||||||
|
yDpi = 133f;
|
||||||
|
} else if (Build.MODEL.startsWith("GT-N710")
|
||||||
|
|| Build.MODEL.equalsIgnoreCase("SCH-N719")
|
||||||
|
|| Build.MODEL.startsWith("SHV-E250")) {
|
||||||
|
xDpi = 267f;
|
||||||
|
yDpi = 267f;
|
||||||
|
} else if (metrics.densityDpi - metrics.xdpi >= 79.0
|
||||||
|
|| metrics.densityDpi - metrics.ydpi >= 79.0
|
||||||
|
|| Math.abs(metrics.ydpi - metrics.xdpi) > 40.0) {
|
||||||
|
xDpi = yDpi = metrics.densityDpi;
|
||||||
|
} else {
|
||||||
|
xDpi = metrics.xdpi;
|
||||||
|
yDpi = metrics.ydpi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initDimensions() {
|
||||||
|
final float w = getWidthPxs() / xDpi;
|
||||||
|
final float h = getHeightPxs() / yDpi;
|
||||||
|
diagonalIns = (float) Math.sqrt(w * w + h * h);
|
||||||
|
widthIns = w;
|
||||||
|
heightIns = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInPortraitMode() {
|
||||||
|
return getWidthPxs() < getHeightPxs();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public int getWidthPxs() {
|
||||||
|
return display.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public int getHeightPxs() {
|
||||||
|
return display.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getWidthIns() {
|
||||||
|
return widthIns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHeightIns() {
|
||||||
|
return heightIns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDensityDpi() {
|
||||||
|
return metrics.densityDpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getDensity() {
|
||||||
|
return metrics.density;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getXDpi() {
|
||||||
|
return xDpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getYDpi() {
|
||||||
|
return yDpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getDiagonalIns() {
|
||||||
|
return diagonalIns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLayout() {
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
}
|
@ -28,5 +28,4 @@
|
|||||||
<dimen name="cpp_display_text_size_mobile">40sp</dimen>
|
<dimen name="cpp_display_text_size_mobile">40sp</dimen>
|
||||||
|
|
||||||
<dimen name="cpp_keyboard_button_text_size">24dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">24dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">25dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -28,5 +28,4 @@
|
|||||||
<dimen name="cpp_display_text_size_mobile">35sp</dimen>
|
<dimen name="cpp_display_text_size_mobile">35sp</dimen>
|
||||||
|
|
||||||
<dimen name="cpp_keyboard_button_text_size">35dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">35dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">45dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -28,5 +28,4 @@
|
|||||||
<dimen name="cpp_display_text_size_mobile">35sp</dimen>
|
<dimen name="cpp_display_text_size_mobile">35sp</dimen>
|
||||||
|
|
||||||
<dimen name="cpp_keyboard_button_text_size">33dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">33dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">30dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -22,5 +22,4 @@
|
|||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="cpp_keyboard_button_text_size">30dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">30dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">40dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -22,5 +22,4 @@
|
|||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="cpp_keyboard_button_text_size">30dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">30dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">20dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -22,5 +22,4 @@
|
|||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="cpp_keyboard_button_text_size">24dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">24dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">25dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -22,5 +22,4 @@
|
|||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="cpp_keyboard_button_text_size">33dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">33dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">25dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -22,5 +22,4 @@
|
|||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="cpp_keyboard_button_text_size">32dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">32dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">15dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -22,5 +22,4 @@
|
|||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="cpp_keyboard_button_text_size">22dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">22dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">14dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -22,5 +22,4 @@
|
|||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="cpp_keyboard_button_text_size">20dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">20dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">10dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -29,5 +29,4 @@
|
|||||||
<dimen name="cpp_display_text_size">30sp</dimen>
|
<dimen name="cpp_display_text_size">30sp</dimen>
|
||||||
|
|
||||||
<dimen name="cpp_keyboard_button_text_size">40dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">40dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">75dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -29,5 +29,4 @@
|
|||||||
<dimen name="cpp_display_text_size">30sp</dimen>
|
<dimen name="cpp_display_text_size">30sp</dimen>
|
||||||
|
|
||||||
<dimen name="cpp_keyboard_button_text_size">35dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">35dp</dimen>
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">65dp</dimen>
|
|
||||||
</resources>
|
</resources>
|
@ -16,7 +16,6 @@
|
|||||||
<dimen name="cpp_keyboard_button_text_size">30dp</dimen>
|
<dimen name="cpp_keyboard_button_text_size">30dp</dimen>
|
||||||
<dimen name="cpp_button_text_size">20dp</dimen>
|
<dimen name="cpp_button_text_size">20dp</dimen>
|
||||||
|
|
||||||
<dimen name="cpp_keyboard_button_text_size_mobile">20dp</dimen>
|
|
||||||
<dimen name="cpp_display_text_size_mobile">25sp</dimen>
|
<dimen name="cpp_display_text_size_mobile">25sp</dimen>
|
||||||
<dimen name="cpp_editor_text_size_mobile">25sp</dimen>
|
<dimen name="cpp_editor_text_size_mobile">25sp</dimen>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user