Skip to content

Commit

Permalink
fixed : 解决item message 布局
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobuxie committed Dec 21, 2020
1 parent ab1971e commit abeb052
Show file tree
Hide file tree
Showing 19 changed files with 503 additions and 56 deletions.
461 changes: 461 additions & 0 deletions Client/.idea/dbnavigator.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public LocalDatabase getLocalDataBase() {
return localDatabase;
}


public void logout() {
localDatabase = null;
SharedPreferences.Editor editor = getSharedPreferences("login_account", Context.MODE_PRIVATE).edit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import androidx.lifecycle.ViewModel;

import com.chrisjaunes.communication.client.Config;
import com.chrisjaunes.communication.client.myView.ChatTextStyleRaw;
import com.chrisjaunes.communication.client.myView.ChatTextStyleView;
import com.chrisjaunes.communication.client.my_view.ChatTextStyleRaw;
import com.chrisjaunes.communication.client.my_view.ChatTextStyleView;
import com.chrisjaunes.communication.client.utils.BitmapHelper;
import com.chrisjaunes.communication.client.utils.HttpHelper;
import com.chrisjaunes.communication.client.utils.UniApiResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.chrisjaunes.communication.client.Config;
import com.chrisjaunes.communication.client.R;
import com.chrisjaunes.communication.client.account.model.AccountRaw;
import com.chrisjaunes.communication.client.myView.ChatTextStyleHelper;
import com.chrisjaunes.communication.client.my_view.ChatTextStyleHelper;
import com.chrisjaunes.communication.client.utils.BitmapHelper;
import com.chrisjaunes.communication.client.utils.UniApiResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import androidx.annotation.NonNull;

import com.chrisjaunes.communication.client.myView.ChatTextStyleRaw;
import com.chrisjaunes.communication.client.my_view.ChatTextStyleRaw;

/**
* 采用了建造者模式
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import androidx.annotation.NonNull;

import com.chrisjaunes.communication.client.account.model.AccountRaw;
import com.chrisjaunes.communication.client.myView.ChatTextStyleView;
import com.chrisjaunes.communication.client.my_view.ChatTextStyleView;
import com.chrisjaunes.communication.client.utils.BitmapHelper;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import androidx.annotation.NonNull;

import com.chrisjaunes.communication.client.myView.ChatTextStyleView;
import com.chrisjaunes.communication.client.my_view.ChatTextStyleView;
import com.chrisjaunes.communication.client.utils.BitmapHelper;
/**
* 设计模式:适配器模式(对象适配器)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.chrisjaunes.communication.client.Config;
import com.chrisjaunes.communication.client.R;
import com.chrisjaunes.communication.client.account.model.AccountView;
import com.chrisjaunes.communication.client.account.AccountViewManage;
import com.chrisjaunes.communication.client.contacts.model.ContactsView;
import com.chrisjaunes.communication.client.contacts.ContactsViewManage;
import com.chrisjaunes.communication.client.group.model.GMessage;
import com.chrisjaunes.communication.client.myView.ChatTextView;
import com.chrisjaunes.communication.client.my_view.ChatTextView;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chrisjaunes.communication.client.myView;
package com.chrisjaunes.communication.client.my_view;

import android.content.Context;
import android.graphics.Bitmap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chrisjaunes.communication.client.myView;
package com.chrisjaunes.communication.client.my_view;

import android.content.Context;
import android.content.res.TypedArray;
Expand All @@ -7,7 +7,6 @@
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.text.Layout;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chrisjaunes.communication.client.myView;
package com.chrisjaunes.communication.client.my_view;

import android.graphics.drawable.ColorDrawable;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chrisjaunes.communication.client.myView;
package com.chrisjaunes.communication.client.my_view;

import androidx.annotation.NonNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chrisjaunes.communication.client.myView;
package com.chrisjaunes.communication.client.my_view;

import android.graphics.Color;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chrisjaunes.communication.client.myView;
package com.chrisjaunes.communication.client.my_view;

import android.content.Context;
import android.content.res.TypedArray;
Expand All @@ -10,11 +10,15 @@
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chrisjaunes.communication.client.R;

import java.util.HashMap;

public class ChatTextView extends View {
// textwidth
public final static int textWidth = 600;
Expand All @@ -32,7 +36,7 @@ public class ChatTextView extends View {
//左边
private Boolean is_left;
// 内容
private String text;
private String text = "";
//字体大小
private int text_size;
// 外面边框画笔
Expand All @@ -47,9 +51,15 @@ public class ChatTextView extends View {
int text_color;

int signleLineHeight;
// test
HashMap<String,Integer> testWidth;

public ChatTextView(Context context, @Nullable AttributeSet attrs) {

super(context, attrs);
// test
testWidth = new HashMap<>();

Log.d("ChatTextView","create view");
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ChatTextView);
radius = typedArray.getFloat(R.styleable.ChatTextView_border_radius,0);
Expand Down Expand Up @@ -88,35 +98,24 @@ public ChatTextView(Context context, @Nullable AttributeSet attrs) {

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if( text == null ){
setMeasuredDimension(0,0);
return;
}
Log.d("ChatTextView","now text: " + text);
//获得当前view的宽高限制的类型
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
width = calcWidth();
height = calcHeight();
Log.d("ChatTextView","measure: width" + width + " height: " + height);
requestLayout();
setMeasuredDimension(width,height);
}

@Override
protected void onDraw(Canvas canvas){
Log.d("ChatTextView",String.format("onDraw : time: %d width : %d height: %d text: %s, C_width %d, C_Hight %d",
System.currentTimeMillis(),width,height,text, getWidth(), getHeight()));

paintIn.setColor(bubble_color);
paintText.setColor(text_color);
paintOut.setColor(border_color);
if( text == null ) {
super.onDraw(canvas);
return;
}
Log.d("ChatTextView","onDraw");
Log.d("ChatTextView","text: " + text);
Log.d("ChatTextView","draw: width" + width + " height: " + height);
RectF rectF = new RectF(0,0,width,height);
if( is_left){
// 画外矩形
Expand Down Expand Up @@ -148,6 +147,7 @@ protected void onDraw(Canvas canvas){
//画内矩形
rectF = new RectF(borderWidth,borderWidth,width-triangleWidth-borderWidth,height-borderWidth);
}

canvas.drawRect(rectF,paintIn);
// canvas.drawRoundRect(rectF,radius,radius,paintIn);
drawText(canvas);
Expand Down Expand Up @@ -216,26 +216,11 @@ private int calcHeight(){
}

// 给外面接口,更改text
public void setMyText(String text){
public void setMyText(@NonNull final String text){
this.text = text;
invalidate();
}

// 更改颜色
public void setMyColor(int text_color,int border_color,int background_color){
this.text_color = text_color;
this.border_color = border_color;
this.bubble_color = background_color;
invalidate();
}
// 更改颜色
public void setMyColor(ChatTextStyleRaw chatTextStyle){
this.text_color = Color.parseColor(chatTextStyle.font_color);
this.border_color = Color.parseColor(chatTextStyle.border_color);
this.bubble_color = Color.parseColor(chatTextStyle.bubble_color);
Log.d("TalkAdapterX", "" + this.text_color);
invalidate();
}
// 更改颜色
public void setMyColor(ChatTextStyleView chatTextStyleView){
this.text_color = chatTextStyleView.text_color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import com.chrisjaunes.communication.client.account.model.AccountView;
import com.chrisjaunes.communication.client.account.AccountViewManage;
import com.chrisjaunes.communication.client.contacts.model.ContactsView;
import com.chrisjaunes.communication.client.group.model.GMessage;
import com.chrisjaunes.communication.client.myView.ChatTextView;
import com.chrisjaunes.communication.client.my_view.ChatTextView;

import java.util.List;

Expand Down Expand Up @@ -69,6 +68,7 @@ public void addMessageList(@NonNull List<TMessage> newMessageList) {
messageList.clear();
messageList.addAll(newMessageList);
notifyDataSetChanged();

}
@Override
public int getItemCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import androidx.annotation.NonNull;

import com.chrisjaunes.communication.client.R;
import com.chrisjaunes.communication.client.myView.ChatTextStyleRaw;
import com.chrisjaunes.communication.client.my_view.ChatTextStyleRaw;

/**
* @author Chris
Expand Down
2 changes: 1 addition & 1 deletion Client/app/src/main/res/layout/drawer_head.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:theme="@style/ThemeOverlay.AppCompat.Dark">


<com.chrisjaunes.communication.client.myView.AvatarCircleView
<com.chrisjaunes.communication.client.my_view.AvatarCircleView
android:id="@+id/iv_avatar"
android:layout_width="150dp"
android:layout_height="150dp"
Expand Down
11 changes: 7 additions & 4 deletions Client/app/src/main/res/layout/item_message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="nick name"
android:textSize="10sp"
tools:ignore="RtlHardcoded,SmallSp" />
<com.chrisjaunes.communication.client.myView.ChatTextView
<com.chrisjaunes.communication.client.my_view.ChatTextView
android:id="@+id/left_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -53,6 +54,7 @@
app:mborder_color="@color/colorPrimaryDark"
app:mtext_color="#050010"
app:mtextSize="20sp"
android:layout_margin="5dp"
app:border_radius="25"
app:is_left="true" />
</LinearLayout>
Expand All @@ -62,21 +64,22 @@
android:orientation="horizontal"
android:id="@+id/layout_right"
android:layout_width="match_parent"
android:layout_gravity="right"
android:layout_gravity="end"
android:layout_height="0dp"
android:layout_weight="2">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="10"
android:layout_height="wrap_content"
android:gravity="right">
android:gravity="end">
<TextView
android:id="@+id/right_nickname"
android:layout_width="wrap_content"
android:text="nick name"
android:layout_height="wrap_content"
android:textSize="10sp"/>
<com.chrisjaunes.communication.client.myView.ChatTextView
<com.chrisjaunes.communication.client.my_view.ChatTextView
android:id="@+id/message_right_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit abeb052

Please sign in to comment.