Skip to content
This repository has been archived by the owner on May 30, 2020. It is now read-only.

Commit

Permalink
draw bubbles in MessageItemView
Browse files Browse the repository at this point in the history
  • Loading branch information
gerc99 committed Jun 3, 2014
1 parent 6a1a826 commit e14ddcc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/ru/sawim/models/MessagesAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ public View getView(int index, View convView, ViewGroup viewGroup) {
item.setTextColor(Scheme.getColor(Scheme.THEME_CHAT_INMSG));
}
} else {
item.setBackgroundResource(incoming ?
(Scheme.isBlack() ? R.drawable.msg_in_dark : R.drawable.msg_in)
: (Scheme.isBlack() ? R.drawable.msg_out_dark : R.drawable.msg_out));
item.setIncoming(incoming);
if (incoming) {
item.setPadding(Util.dipToPixels(item.getContext(), 19),
Util.dipToPixels(item.getContext(), 7), Util.dipToPixels(item.getContext(), 9), Util.dipToPixels(item.getContext(), 9));
Expand Down
25 changes: 25 additions & 0 deletions src/ru/sawim/widget/chat/MessageItemView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.Layout;
import android.text.Spannable;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import ru.sawim.R;
import ru.sawim.Scheme;
import ru.sawim.text.InternalURLSpan;
import ru.sawim.text.TextLinkClickListener;
Expand All @@ -29,6 +31,7 @@
public class MessageItemView extends View {

private static final TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private boolean isIncoming;
private String msgTimeText;
private String nickText;
private int nickColor;
Expand All @@ -52,10 +55,17 @@ public class MessageItemView extends View {
private boolean isShowDivider = false;
private int titleHeight;

private static Drawable backgroundDrawableIn;
private static Drawable backgroundDrawableOut;

private static final HashMap<String, Layout> layoutHolder = new HashMap<String, Layout>();

public MessageItemView(Context context) {
super(context);
if (backgroundDrawableIn == null) {
backgroundDrawableIn = context.getResources().getDrawable(Scheme.isBlack() ? R.drawable.msg_in_dark : R.drawable.msg_in);
backgroundDrawableOut = context.getResources().getDrawable(Scheme.isBlack() ? R.drawable.msg_out_dark : R.drawable.msg_out);
}
textPaint.setAntiAlias(true);
}

Expand Down Expand Up @@ -125,6 +135,10 @@ private void computeCoordinates(int viewWidth, int viewHeight) {
textY = getPaddingTop() - (int) textPaint.ascent();
}

public void setIncoming(boolean incoming) {
this.isIncoming = incoming;
}

public void setNick(int nickColor, int nickSize, Typeface nickTypeface, String nickText) {
this.nickColor = nickColor;
this.nickSize = nickSize;
Expand Down Expand Up @@ -180,6 +194,13 @@ protected void onDraw(Canvas canvas) {
textPaint.setColor(Scheme.getColor(Scheme.THEME_TEXT));
canvas.drawLine(getPaddingLeft(), getScrollY() - 2, stopX, getScrollY() - 2, textPaint);
}
if (isIncoming) {
setDrawableBounds(backgroundDrawableIn, 0, 0, getWidth(), getHeight());
backgroundDrawableIn.draw(canvas);
} else {
setDrawableBounds(backgroundDrawableOut, 0, 0, getWidth(), getHeight());
backgroundDrawableOut.draw(canvas);
}

if (nickText != null) {
textPaint.setColor(nickColor);
Expand Down Expand Up @@ -218,6 +239,10 @@ public void setShowDivider(boolean showDivider) {
textPaint.setStrokeWidth((int) (4 * getResources().getDisplayMetrics().density + 0.5f));
}

private void setDrawableBounds(Drawable drawable, int x, int y, int w, int h) {
drawable.setBounds(x, y, x + w, y + h);
}

@Override
public boolean hasFocusable() {
return false;
Expand Down

0 comments on commit e14ddcc

Please sign in to comment.