Permalink
Browse files

adjust sizes

  • Loading branch information...
Xlythe committed Feb 5, 2013
1 parent 9f55984 commit 3cf8107f25eff39ba97c3a17a88738d5399dc326
Showing with 14 additions and 10 deletions.
  1. +1 −1 res/values/styles.xml
  2. +13 −9 src/com/android2/calculator3/view/ColorButton.java
View
@@ -20,7 +20,7 @@
<dimen name="btn_clear_text_size">30sp</dimen>
<dimen name="display_text_size">40sp</dimen>
<dimen name="small_display_text_size">20sp</dimen>
- <dimen name="min_display_height">70dp</dimen>
+ <dimen name="min_display_height">100dp</dimen>
<dimen name="barHeight">25dp</dimen>
<integer name="barHeight">25</integer>
@@ -47,7 +47,6 @@
EventListener mListener;
Paint mFeedbackPaint;
Paint mHintPaint;
- Paint mHintExponentPaint;
Rect bounds = new Rect();
public ColorButton(Context context, AttributeSet attrs) {
@@ -70,9 +69,6 @@ private void init(Calculator calc) {
mHintPaint = new Paint();
mHintPaint.setColor(res.getColor(R.color.grey));
mHintPaint.setTextSize(getTextSize() * 0.8f);
- mHintExponentPaint = new Paint();
- mHintExponentPaint.setColor(res.getColor(R.color.grey));
- mHintExponentPaint.setTextSize(getTextSize() * 0.64f);
mAnimStart = -1;
}
@@ -132,16 +128,24 @@ else if(isPressed()) {
String[] exponents = hint.toString().split(Pattern.quote("^"));
int offsetX = LogicalDensity.convertDpToPixel(10, getContext());
int offsetY = (int) ((mTextY + LogicalDensity.convertDpToPixel(20, getContext()) - getTextHeight(mHintPaint, hint.toString())) / 2);
+
+ float textWidth = mHintPaint.measureText(hint.toString());
+ float width = getWidth() - getPaddingLeft() - getPaddingRight() - mTextX - offsetX;
+ float textSize = mHintPaint.getTextSize();
+ if(textWidth > width) {
+ mHintPaint.setTextSize(textSize * width / textWidth);
+ }
+
for(String str : exponents) {
if(str == exponents[0]) {
canvas.drawText(str, 0, str.length(), mTextX + offsetX, mTextY - offsetY, mHintPaint);
- offsetY += LogicalDensity.convertDpToPixel(8, getContext());
+ offsetY += LogicalDensity.convertDpToPixel(10, getContext());
offsetX += mHintPaint.measureText(str);
}
else {
- canvas.drawText(str, 0, str.length(), mTextX + offsetX, mTextY - offsetY, mHintExponentPaint);
- offsetY += LogicalDensity.convertDpToPixel(8, getContext());
- offsetX += mHintExponentPaint.measureText(str);
+ canvas.drawText(str, 0, str.length(), mTextX + offsetX, mTextY - offsetY, mHintPaint);
+ offsetY += LogicalDensity.convertDpToPixel(10, getContext());
+ offsetX += mHintPaint.measureText(str);
}
}
}
@@ -155,7 +159,7 @@ private int getTextHeight(Paint paint, String text) {
int height = bounds.height();
String[] exponents = text.split(Pattern.quote("^"));
for(int i = 1; i < exponents.length; i++) {
- height += LogicalDensity.convertDpToPixel(8, getContext());
+ height += LogicalDensity.convertDpToPixel(10, getContext());
}
return height;
}

0 comments on commit 3cf8107

Please sign in to comment.