Skip to content

Commit

Permalink
增加了图上文下 图下文上的多行文本的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuRi committed Feb 5, 2017
1 parent 2c247d4 commit 1032061
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion LemonBubble/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions LemonBubble/.idea/vcs.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
LemonBubble.getRightBubbleInfo()// 增加无限点语法修改bubbleInfo的特性
.setTitle("这是一个成功的提示")
.setTitle("这是一个成功的提示,这是一个成功的提示")
.setTitleFontSize(12)// 修改字体大小
.setTitleColor(Color.RED)
.setShowStatusBar(false)
.setMaskColor(Color.argb(100, 0, 0, 0))// 修改蒙版颜色
.show(MainActivity.this, 2000);
// LemonBubble.showRight(MainActivity.this, "这是一个成功的提示", 2000);
Expand Down Expand Up @@ -92,7 +91,7 @@ public void onClick(View v) {
myInfo.setLocationStyle(LemonBubbleLocationStyle.BOTTOM);
myInfo.setLayoutStyle(LemonBubbleLayoutStyle.ICON_LEFT_TITLE_RIGHT);
myInfo.setTitle("正在删除");
myInfo.setTitleFontSize(20);
myInfo.setTitleFontSize(14);
myInfo.setBubbleSize(200, 50);
myInfo.setProportionOfDeviation(0.1f);
LemonBubble.showBubbleInfo(MainActivity.this, myInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Fragment;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.widget.RelativeLayout;
Expand Down Expand Up @@ -386,15 +387,22 @@ void calBubbleViewContentPanelFrame(View view) {
_PAT.setSize(view, bubbleWidth, bubbleHeight);
}

int getLineHeight(TextView textView) {
Paint.FontMetrics fontMetrics = textView.getPaint().getFontMetrics();
return _PST.pxToDp((int) (fontMetrics.descent - fontMetrics.top)) + 2;
}

/**
* 获取指定的textV的行高
*
* @param textView 要获取的textView的行高
* @return textView的每行的高度
*/
int getTitleHeight(TextView textView) {
Paint.FontMetrics fontMetrics = textView.getPaint().getFontMetrics();
return _PST.pxToDp((int) (fontMetrics.descent - fontMetrics.top)) + 2;
int getTitleHeight(TextView textView, int viewWidth) {
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(_PST.dpToPx(viewWidth), View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(widthMeasureSpec, heightMeasureSpec);
return _PST.pxToDp(textView.getMeasuredHeight());
}

/**
Expand All @@ -404,7 +412,10 @@ int getTitleHeight(TextView textView) {
* @return 获取到的文字宽度数值
*/
int getTitleWidth(TextView textView) {
return _PST.pxToDp((int) (textView.getPaint().measureText(textView.getText().toString())));
return Math.min(
(int) (bubbleWidth * (1 - proportionOfPaddingX * 2 - proportionOfSpace) - bubbleHeight * proportionOfIcon),
_PST.pxToDp((int) textView.getPaint().measureText(textView.getText().toString()))
);
}

/**
Expand All @@ -424,7 +435,7 @@ void calPaintViewAndTitleViewFrame(LemonBubblePaintView paintView, TextView titl
layoutStyle == LemonBubbleLayoutStyle.TITLE_ONLY) ?
bubbleContentWidth :
bubbleContentWidth * (1 - proportionOfSpace - iconWidth));
int titleHeight = 0;
int titleHeight = getLineHeight(titleView);
int iconX, titleX, iconY, titleY;
iconX = titleX = baseX;
iconY = titleY = baseY;
Expand All @@ -436,7 +447,7 @@ void calPaintViewAndTitleViewFrame(LemonBubblePaintView paintView, TextView titl
titleView.setLayoutParams(new RelativeLayout.LayoutParams(_DP(bubbleContentWidth),
RelativeLayout.LayoutParams.WRAP_CONTENT));
titleView.postInvalidate();// 即时刷新
titleHeight = getTitleHeight(titleView);
titleHeight = getTitleHeight(titleView, titleWidth);
int contentHeight = (int) (iconWidth + bubbleContentHeight * proportionOfSpace + titleHeight);
iconX = baseX + (bubbleContentWidth - iconWidth) / 2;
iconY = baseY + (bubbleContentHeight - contentHeight) / 2;
Expand All @@ -448,7 +459,7 @@ void calPaintViewAndTitleViewFrame(LemonBubblePaintView paintView, TextView titl
titleView.setLayoutParams(new RelativeLayout.LayoutParams(_DP(bubbleContentWidth),
RelativeLayout.LayoutParams.WRAP_CONTENT));
titleView.postInvalidate();// 即时刷新
titleHeight = getTitleHeight(titleView);
titleHeight = getTitleHeight(titleView, titleWidth);
int contentHeight = (int) (iconWidth + bubbleContentHeight * proportionOfSpace + titleHeight);
titleY = (int) (baseY + (bubbleContentHeight - contentHeight) / 2.0);
titleX = (int) (baseX + (bubbleContentWidth - titleWidth) / 2.0);
Expand All @@ -457,10 +468,8 @@ void calPaintViewAndTitleViewFrame(LemonBubblePaintView paintView, TextView titl
break;
}
case ICON_LEFT_TITLE_RIGHT: {// 图左文右
titleView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
titleWidth = getTitleWidth(titleView);
titleView.postInvalidate();// 即时刷新
titleHeight = getTitleHeight(titleView);
int contentWidth = (int) (iconWidth + bubbleContentWidth * proportionOfSpace + getTitleWidth(titleView));
iconX = (int) (baseX + (bubbleContentWidth - contentWidth) / 2.0);
iconY = (int) (baseY + (bubbleContentHeight - iconWidth) / 2.0);
Expand All @@ -469,10 +478,8 @@ void calPaintViewAndTitleViewFrame(LemonBubblePaintView paintView, TextView titl
break;
}
case ICON_RIGHT_TITLE_LEFT: {// 图右文左
titleView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
titleWidth = getTitleWidth(titleView);
titleView.postInvalidate();// 即时刷新
titleHeight = getTitleHeight(titleView);
int contentWidth = (int) (iconWidth + bubbleContentWidth * proportionOfSpace + getTitleWidth(titleView));
titleX = (int) (baseX + (bubbleContentWidth - contentWidth) / 2.0);
titleY = (int) (baseY + (bubbleContentHeight - titleHeight) / 2.0);
Expand All @@ -490,10 +497,10 @@ void calPaintViewAndTitleViewFrame(LemonBubblePaintView paintView, TextView titl
titleView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
titleView.postInvalidate();// 即时刷新
titleHeight = getTitleHeight(titleView);
titleHeight = getTitleHeight(titleView, titleWidth);
iconX = iconY = iconWidth = 0;
titleX = baseX;
titleY = (int) (baseY + (bubbleContentHeight - getTitleHeight(titleView)) / 2.0);
titleY = (int) (baseY + (bubbleContentHeight - getTitleHeight(titleView, titleWidth)) / 2.0);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.view.Gravity;
Expand Down Expand Up @@ -175,6 +176,7 @@ public void onClick(View v) {
_rootLayout.addView(_contentPanel);// 主内容面板
_contentPanel.addView(_paintView);// 动画和帧图标显示控件放置到内容面板上
_contentPanel.addView(_titleView);// 标题显示标签控件放置到内容面板上

}

/**
Expand Down

0 comments on commit 1032061

Please sign in to comment.