Permalink
Browse files

reset paint when button layout changes

  • Loading branch information...
1 parent 8c8dca3 commit 6ce04bf06fcd4014d4b33a5eb0e4537a67bd50c1 @Xlythe committed Feb 10, 2013
Showing with 13 additions and 19 deletions.
  1. +0 −9 res/values-sw600dp/styles.xml
  2. +1 −1 res/values/colors.xml
  3. +12 −9 src/com/android2/calculator3/view/ColorButton.java
View
9 res/values-sw600dp/styles.xml
@@ -25,13 +25,4 @@
<dimen name="left_right_padding">16sp</dimen>
<dimen name="top_bottom_padding">16sp</dimen>
<dimen name="group_padding">16sp</dimen>
-
- <style name="button_hint_style">
- <item name="android:textSize">17sp</item>
- <item name="android:layout_width">wrap_content</item>
- <item name="android:layout_height">wrap_content</item>
- <item name="android:paddingRight">4dp</item>
- <item name="android:paddingTop">5dp</item>
- <item name="android:textColor">@color/grey</item>
- </style>
</resources>
View
2 res/values/colors.xml
@@ -17,10 +17,10 @@
<resources>
<color name="magic_flame">#00FFFFFF</color>
<color name="button_text">#FFFFFFFF</color>
+ <color name="button_hint_text">#474747</color>
<color name="pressed_color">#07547B</color>
<color name="history_input">#E6E6E6</color>
<color name="history_result">#999999</color>
<color name="background">#FF000000</color>
- <color name="grey">#474747</color>
<color name="graph_color">#31B6E7</color>
</resources>
View
21 src/com/android2/calculator3/view/ColorButton.java
@@ -45,8 +45,9 @@
long mAnimStart;
EventListener mListener;
Paint mFeedbackPaint;
- Paint mHintPaint;
+ Paint mHintPaint = new Paint();
Rect bounds = new Rect();
+ float mTextSize = 0f;
public ColorButton(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -65,38 +66,40 @@ private void init(Calculator calc) {
mFeedbackPaint.setStyle(Style.STROKE);
mFeedbackPaint.setStrokeWidth(2);
getPaint().setColor(res.getColor(R.color.button_text));
- mHintPaint = new Paint();
- mHintPaint.setColor(res.getColor(R.color.grey));
- mHintPaint.setTextSize(getTextSize() * 0.8f);
+ mHintPaint.setColor(res.getColor(R.color.button_hint_text));
mAnimStart = -1;
}
- @Override
- public void onSizeChanged(int w, int h, int oldW, int oldH) {
- layoutText();
- }
-
private void layoutText() {
Paint paint = getPaint();
+ if(mTextSize != 0f) paint.setTextSize(mTextSize);
float textWidth = paint.measureText(getText().toString());
float width = getWidth() - getPaddingLeft() - getPaddingRight();
float textSize = getTextSize();
if(textWidth > width) {
paint.setTextSize(textSize * width / textWidth);
mTextX = getPaddingLeft();
+ mTextSize = textSize;
}
else {
mTextX = (getWidth() - textWidth) / 2;
}
mTextY = (getHeight() - paint.ascent() - paint.descent()) / 2;
+ if(mHintPaint != null) mHintPaint.setTextSize(paint.getTextSize() * 0.8f);
}
@Override
protected void onTextChanged(CharSequence text, int start, int before, int after) {
layoutText();
}
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+ if(changed) layoutText();
+ }
+
private void drawMagicFlame(int duration, Canvas canvas) {
int alpha = 255 - 255 * duration / CLICK_FEEDBACK_DURATION;
int color = CLICK_FEEDBACK_COLOR | (alpha << 24);

0 comments on commit 6ce04bf

Please sign in to comment.