public ConvertButton(Context context, AttributeSet attrs) { super(context, attrs); mArrowText = getResources().getString(R.string.convert_arrow); }
private void layoutTextDivided() { Paint paint = getPaint(); if (mTextSize != 0f) paint.setTextSize(mTextSize); String text = getText().toString(); float maxWidth = Math.max(botTextWidth, topTextWidth); float boxWidth = getWidth() - getPaddingLeft() - getPaddingRight(); float textSize = getTextSize(); if ((arrowWidth + maxWidth) > boxWidth){ paint.setTextSize(textSize * boxWidth / (arrowWidth + maxWidth)); mTopTextX = (getWidth() - topTextWidth + arrowWidth) / 2; mBotTextX = (getWidth() - botTextWidth + arrowWidth) / 2; mTopTextY = (getHeight()) / 2 - paint.descent(); mBotTextY = (getHeight()) / 2 - paint.ascent() * 4 / 5; mArrowTextX = (getWidth() - maxWidth - arrowWidth) / 2; mArrowTextY = (getHeight() - paint.ascent() - paint.descent()) / 2;
/** * Helper method to size text */ protected void layoutText() { String text = getText().toString(); //TODO crude, fix //historical currency (USD [1953]) is too long, put on two lines if (text.contains(" [")){ text = text.replace(" [", "/["); setText(text); mUnderline = false; } if (text.contains("/")){ layoutTextDivided(); } else super.layoutText(); }
/** * Overloaded method, will be called by onDraw in SecondaryTextButton */ @Override protected void drawMainText(Canvas canvas) { String text = getText().toString(); if (text.contains("/")){ getPaint().setColor(getCurrentTextColor()); if (mUnderline) getPaint().setUnderlineText(true); canvas.drawText(mTopText, 0, mTopText.length(), mTopTextX, mTopTextY, getPaint()); getPaint().setUnderlineText(false); canvas.drawText(mBotText, 0, mBotText.length(), mBotTextX, mBotTextY, getPaint()); if (text.contains(mArrowText)){ canvas.drawText(mArrowText, 0, mArrowText.length(), mArrowTextX, mArrowTextY, getPaint()); } } else super.drawMainText(canvas); }