summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJustin Klaassen <justinklaassen@google.com>2015-06-30 19:02:25 -0700
committerJustin Klaassen <justinklaassen@google.com>2015-07-01 13:56:57 -0700
commitb2c3e4406043da5ae2b90feccec824c38b0d8d3b (patch)
tree9e19bb138f8a58f1e4525287862521f0791f6f63 /src
parent6a83e391768d2343dc34341ebbf85008fef68544 (diff)
downloadandroid_packages_apps_ExactCalculator-b2c3e4406043da5ae2b90feccec824c38b0d8d3b.tar.gz
android_packages_apps_ExactCalculator-b2c3e4406043da5ae2b90feccec824c38b0d8d3b.tar.bz2
android_packages_apps_ExactCalculator-b2c3e4406043da5ae2b90feccec824c38b0d8d3b.zip
Always use "H" for formula text alignment
Bug: 22208425 Most of the mathematical operators/symbols (e.g. "π") cannot be encoded using "ISO-8859-1" however they still should be aligned using the default capital letter height ("H"). Change-Id: I4ca6674de6e6a96b0ce513ecd8acea775f2e7081
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calculator2/AlignedTextView.java24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/com/android/calculator2/AlignedTextView.java b/src/com/android/calculator2/AlignedTextView.java
index 1c4b78f..91ad0dd 100644
--- a/src/com/android/calculator2/AlignedTextView.java
+++ b/src/com/android/calculator2/AlignedTextView.java
@@ -19,21 +19,15 @@ package com.android.calculator2;
import android.content.Context;
import android.graphics.Paint;
import android.graphics.Rect;
-import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-
/**
* Extended {@link TextView} that supports ascent/baseline alignment.
*/
public class AlignedTextView extends TextView {
private static final String LATIN_CAPITAL_LETTER = "H";
- private static final CharsetEncoder LATIN_CHARSET_ENCODER =
- Charset.forName("ISO-8859-1").newEncoder();
// temporary rect for use during layout
private final Rect mTempRect = new Rect();
@@ -58,18 +52,14 @@ public class AlignedTextView extends TextView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- CharSequence text = getText();
- if (TextUtils.isEmpty(text) || LATIN_CHARSET_ENCODER.canEncode(text)) {
- // For latin text align to the default capital letter height.
- text = LATIN_CAPITAL_LETTER;
- }
- getPaint().getTextBounds(text.toString(), 0, text.length(), mTempRect);
-
- final Paint textPaint = getPaint();
+ final Paint paint = getPaint();
+
+ // Always align text to the default capital letter height.
+ paint.getTextBounds(LATIN_CAPITAL_LETTER, 0, 1, mTempRect);
+
mTopPaddingOffset = Math.min(getPaddingTop(),
- (int) Math.floor(mTempRect.top - textPaint.ascent()));
- mBottomPaddingOffset = Math.min(getPaddingBottom(),
- (int) Math.floor(textPaint.descent()));
+ (int) Math.ceil(mTempRect.top - paint.ascent()));
+ mBottomPaddingOffset = Math.min(getPaddingBottom(), (int) Math.ceil(paint.descent()));
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}