Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RvApp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lify
RvApp
Commits
b2a44106
Commit
b2a44106
authored
Sep 21, 2019
by
jianglx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加图片上传进度
parent
fc9d4725
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
266 additions
and
14 deletions
+266
-14
ChatContentAdapter.java
...m/src/main/java/com/rv/im/adapter/ChatContentAdapter.java
+11
-4
ServiceUtils.java
plugin_im/src/main/java/com/rv/im/util/ServiceUtils.java
+28
-0
UploadEngine.java
plugin_im/src/main/java/com/rv/im/util/UploadEngine.java
+4
-2
CycleProgress.java
plugin_im/src/main/java/com/rv/im/view/CycleProgress.java
+168
-0
shape_from_chat_msg.xml
plugin_im/src/main/res/drawable/shape_from_chat_msg.xml
+9
-0
shape_to_chat_msg.xml
plugin_im/src/main/res/drawable/shape_to_chat_msg.xml
+9
-0
chat_to_item_pic.xml
plugin_im/src/main/res/layout/chat_to_item_pic.xml
+21
-8
attrs.xml
plugin_im/src/main/res/values/attrs.xml
+16
-0
No files found.
plugin_im/src/main/java/com/rv/im/adapter/ChatContentAdapter.java
View file @
b2a44106
...
@@ -24,6 +24,7 @@ import com.rv.im.glide.GlideOptions;
...
@@ -24,6 +24,7 @@ import com.rv.im.glide.GlideOptions;
import
com.rv.im.glide.TransformationUtils
;
import
com.rv.im.glide.TransformationUtils
;
import
com.rv.im.util.DateUtils
;
import
com.rv.im.util.DateUtils
;
import
com.rv.im.util.SmileyParser
;
import
com.rv.im.util.SmileyParser
;
import
com.rv.im.view.CycleProgress
;
import
com.rv.im.view.RoundImageView
;
import
com.rv.im.view.RoundImageView
;
import
java.util.Date
;
import
java.util.Date
;
...
@@ -289,11 +290,15 @@ public class ChatContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
...
@@ -289,11 +290,15 @@ public class ChatContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
holder
.
chatPic
.
setOnClickListener
(
v
->
listener
.
onClick
(
v
.
getId
(),
bean
));
holder
.
chatPic
.
setOnClickListener
(
v
->
listener
.
onClick
(
v
.
getId
(),
bean
));
holder
.
ivFailed
.
setOnClickListener
(
v
->
listener
.
reSend
(
bean
));
holder
.
ivFailed
.
setOnClickListener
(
v
->
listener
.
reSend
(
bean
));
if
(
bean
.
getMessageStatus
()
==
0
)
{
holder
.
progressBar
.
setVisibility
(
View
.
VISIBLE
);
if
(
bean
.
getUpLoadStatus
()
==
1
){
holder
.
progressBar
.
setVisibility
(
View
.
GONE
);
holder
.
ivFailed
.
setVisibility
(
View
.
GONE
);
holder
.
ivFailed
.
setVisibility
(
View
.
GONE
);
holder
.
tvRead
.
setVisibility
(
View
.
GONE
);
holder
.
tvRead
.
setVisibility
(
View
.
GONE
);
}
else
if
(
bean
.
getUpLoadStatus
()
==
2
)
{
// 上传 成功
holder
.
cycleProgress
.
setVisibility
(
View
.
VISIBLE
);
holder
.
cycleProgress
.
setmProgress
(
bean
.
getUploadSchedule
());
}
else
if
(
bean
.
getUpLoadStatus
()
==
2
)
{
// 上传 成功
holder
.
cycleProgress
.
setVisibility
(
View
.
GONE
);
if
(
bean
.
getMessageStatus
()
==
0
)
{
if
(
bean
.
getMessageStatus
()
==
0
)
{
holder
.
progressBar
.
setVisibility
(
View
.
VISIBLE
);
holder
.
progressBar
.
setVisibility
(
View
.
VISIBLE
);
holder
.
ivFailed
.
setVisibility
(
View
.
GONE
);
holder
.
ivFailed
.
setVisibility
(
View
.
GONE
);
...
@@ -307,11 +312,11 @@ public class ChatContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
...
@@ -307,11 +312,11 @@ public class ChatContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
holder
.
ivFailed
.
setVisibility
(
View
.
VISIBLE
);
holder
.
ivFailed
.
setVisibility
(
View
.
VISIBLE
);
holder
.
tvRead
.
setVisibility
(
View
.
GONE
);
holder
.
tvRead
.
setVisibility
(
View
.
GONE
);
}
}
}
else
if
(
bean
.
getUpLoadStatus
()
==
3
)
{
// 上传失败
}
else
if
(
bean
.
getUpLoadStatus
()
==
3
)
{
// 上传失败
holder
.
progressBar
.
setVisibility
(
View
.
GONE
);
holder
.
progressBar
.
setVisibility
(
View
.
GONE
);
holder
.
ivFailed
.
setVisibility
(
View
.
VISIBLE
);
holder
.
ivFailed
.
setVisibility
(
View
.
VISIBLE
);
holder
.
tvRead
.
setVisibility
(
View
.
GONE
);
holder
.
tvRead
.
setVisibility
(
View
.
GONE
);
holder
.
cycleProgress
.
setVisibility
(
View
.
GONE
);
}
}
}
}
...
@@ -451,6 +456,7 @@ public class ChatContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
...
@@ -451,6 +456,7 @@ public class ChatContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
ImageView
chatPic
;
ImageView
chatPic
;
ImageView
ivFailed
;
ImageView
ivFailed
;
TextView
tvRead
;
TextView
tvRead
;
CycleProgress
cycleProgress
;
public
MsgToPicHolder
(
@NonNull
View
itemView
)
{
public
MsgToPicHolder
(
@NonNull
View
itemView
)
{
super
(
itemView
);
super
(
itemView
);
...
@@ -460,6 +466,7 @@ public class ChatContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
...
@@ -460,6 +466,7 @@ public class ChatContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
progressBar
=
itemView
.
findViewById
(
R
.
id
.
progress
);
progressBar
=
itemView
.
findViewById
(
R
.
id
.
progress
);
ivFailed
=
itemView
.
findViewById
(
R
.
id
.
iv_failed
);
ivFailed
=
itemView
.
findViewById
(
R
.
id
.
iv_failed
);
tvRead
=
itemView
.
findViewById
(
R
.
id
.
tv_read
);
tvRead
=
itemView
.
findViewById
(
R
.
id
.
tv_read
);
cycleProgress
=
itemView
.
findViewById
(
R
.
id
.
cycle_progress
);
}
}
}
}
...
...
plugin_im/src/main/java/com/rv/im/util/ServiceUtils.java
0 → 100644
View file @
b2a44106
package
com
.
rv
.
im
.
util
;
import
android.app.ActivityManager
;
import
android.content.Context
;
import
java.util.ArrayList
;
public
class
ServiceUtils
{
/**
* 判断服务是否开启
*
* @return
*/
public
static
boolean
isServiceRunning
(
Context
context
)
{
ActivityManager
myManager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
ArrayList
<
ActivityManager
.
RunningServiceInfo
>
runningService
=
(
ArrayList
<
ActivityManager
.
RunningServiceInfo
>)
myManager
.
getRunningServices
(
30
);
for
(
int
i
=
0
;
i
<
runningService
.
size
();
i
++)
{
if
(
runningService
.
get
(
i
).
service
.
getClassName
()
.
equals
(
"com.rv.im.ImService"
))
{
return
true
;
}
}
return
false
;
}
}
plugin_im/src/main/java/com/rv/im/util/UploadEngine.java
View file @
b2a44106
...
@@ -48,10 +48,9 @@ public class UploadEngine {
...
@@ -48,10 +48,9 @@ public class UploadEngine {
message
.
setUploadSchedule
(
100
);
message
.
setUploadSchedule
(
100
);
response
.
onUpProgress
(
toUserId
,
message
);
response
.
onUpProgress
(
toUserId
,
message
);
}
else
{
}
else
{
if
(
totalSize
!=
0
)
{
if
(
totalSize
!=
0
)
{
message
.
setUpLoadStatus
(
1
);
message
.
setUpLoadStatus
(
1
);
int
progress
=
bytesWritten
/
totalSize
*
100
;
int
progress
=
bytesWritten
*
100
/
totalSize
;
message
.
setUploadSchedule
(
progress
);
message
.
setUploadSchedule
(
progress
);
response
.
onUpProgress
(
toUserId
,
message
);
response
.
onUpProgress
(
toUserId
,
message
);
}
}
...
@@ -73,6 +72,7 @@ public class UploadEngine {
...
@@ -73,6 +72,7 @@ public class UploadEngine {
}
}
if
(
result
.
getFailure
()
==
1
)
{
//上传失败
if
(
result
.
getFailure
()
==
1
)
{
//上传失败
if
(
response
!=
null
)
{
if
(
response
!=
null
)
{
message
.
setUpLoadStatus
(
3
);
response
.
onFailure
(
toUserId
,
message
);
response
.
onFailure
(
toUserId
,
message
);
}
}
LogUtil
.
d
(
"上传文件失败,"
);
LogUtil
.
d
(
"上传文件失败,"
);
...
@@ -100,6 +100,7 @@ public class UploadEngine {
...
@@ -100,6 +100,7 @@ public class UploadEngine {
if
(
TextUtils
.
isEmpty
(
url
))
{
//返回成功,但是却获取不到对应的URL,服务器返回值异常<概率极小>
if
(
TextUtils
.
isEmpty
(
url
))
{
//返回成功,但是却获取不到对应的URL,服务器返回值异常<概率极小>
if
(
response
!=
null
)
{
if
(
response
!=
null
)
{
message
.
setUpLoadStatus
(
3
);
response
.
onFailure
(
toUserId
,
message
);
response
.
onFailure
(
toUserId
,
message
);
}
}
}
else
{
}
else
{
...
@@ -116,6 +117,7 @@ public class UploadEngine {
...
@@ -116,6 +117,7 @@ public class UploadEngine {
public
void
onFailure
(
int
arg0
,
Header
[]
arg1
,
byte
[]
arg2
,
Throwable
arg3
)
{
public
void
onFailure
(
int
arg0
,
Header
[]
arg1
,
byte
[]
arg2
,
Throwable
arg3
)
{
requestHandleMap
.
remove
(
message
.
getPackId
());
requestHandleMap
.
remove
(
message
.
getPackId
());
LogUtil
.
i
(
"上传文件<"
+
message
.
getFilePath
()
+
">失败,"
+
arg3
);
LogUtil
.
i
(
"上传文件<"
+
message
.
getFilePath
()
+
">失败,"
+
arg3
);
message
.
setUpLoadStatus
(
3
);
if
(
response
!=
null
)
{
if
(
response
!=
null
)
{
response
.
onFailure
(
toUserId
,
message
);
response
.
onFailure
(
toUserId
,
message
);
}
}
...
...
plugin_im/src/main/java/com/rv/im/view/CycleProgress.java
0 → 100644
View file @
b2a44106
package
com
.
rv
.
im
.
view
;
;
import
android.content.Context
;
import
android.content.res.TypedArray
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.Paint
;
import
android.graphics.RectF
;
import
android.support.annotation.Nullable
;
import
android.util.AttributeSet
;
import
android.view.View
;
import
com.rv.im.R
;
/**
* Created by root on 2018/9/12.
*/
public
class
CycleProgress
extends
View
{
private
Context
mContext
;
private
int
cycleBgStrokeWidth
;
private
int
progressStrokeWidth
;
private
boolean
isProgressText
;
private
int
centerTextColor
;
private
int
centerTextSize
;
private
int
cycleBgColor
;
private
int
progressColor
;
private
Paint
progressPaint
;
private
Paint
cycleBgPaint
;
private
Paint
centerTextPaint
;
/**
* 圆心x坐标
*/
private
float
centerX
;
/**
* 圆心y坐标
*/
private
float
centerY
;
/**
* 圆的半径
*/
private
float
radius
;
/**
* 进度
*/
private
float
mProgress
=
0
;
/**
* 扇形所在矩形
*/
private
RectF
rectF
=
new
RectF
();
public
CycleProgress
(
Context
context
)
{
super
(
context
);
init
(
context
,
null
);
}
public
CycleProgress
(
Context
context
,
@Nullable
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
init
(
context
,
attrs
);
}
public
CycleProgress
(
Context
context
,
@Nullable
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
init
(
context
,
attrs
);
}
private
void
init
(
Context
context
,
AttributeSet
attrs
)
{
this
.
mContext
=
context
;
getAttr
(
attrs
);
// 获取控件属性,
initPaint
();
// 初始化圆圈画笔
initTextPaint
();
// 初始化文字画笔
}
/**
* 获取控件属性(命名空间)
*/
private
void
getAttr
(
AttributeSet
attrs
)
{
TypedArray
typedArray
=
mContext
.
obtainStyledAttributes
(
attrs
,
R
.
styleable
.
CycleProgress
);
cycleBgStrokeWidth
=
10
;
progressStrokeWidth
=
10
;
isProgressText
=
true
;
centerTextColor
=
Color
.
parseColor
(
"#999999"
);
centerTextSize
=
30
;
cycleBgColor
=
Color
.
parseColor
(
"#ffffff"
);
progressColor
=
Color
.
parseColor
(
"#66999999"
);
typedArray
.
recycle
();
}
/**
* 初始化圆圈画笔
*/
private
void
initPaint
()
{
progressPaint
=
getPaint
(
progressStrokeWidth
,
progressColor
);
cycleBgPaint
=
getPaint
(
cycleBgStrokeWidth
,
cycleBgColor
);
}
private
Paint
getPaint
(
int
width
,
int
color
)
{
Paint
paint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
paint
.
setStrokeWidth
(
width
);
// Paint.Style.FILL:填充内部 Paint.Style.FILL_AND_STROKE:填充内部和描边Paint.Style.STROKE :描边
paint
.
setStyle
(
Paint
.
Style
.
STROKE
);
paint
.
setColor
(
color
);
paint
.
setAntiAlias
(
true
);
// 扛锯齿
paint
.
setStrokeCap
(
Paint
.
Cap
.
ROUND
);
// 两端是圆角
return
paint
;
}
/**
* 初始化文字画笔
*/
private
void
initTextPaint
()
{
centerTextPaint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
centerTextPaint
.
setColor
(
centerTextColor
);
centerTextPaint
.
setTextAlign
(
Paint
.
Align
.
CENTER
);
// 设置文字位置在中间
centerTextPaint
.
setTextSize
(
centerTextSize
);
// 设置文字大小
centerTextPaint
.
setAntiAlias
(
true
);
}
/**
* view发生改变的时候调用
*
* @param w
* @param h
* @param oldw
* @param oldh
*/
@Override
protected
void
onSizeChanged
(
int
w
,
int
h
,
int
oldw
,
int
oldh
)
{
super
.
onSizeChanged
(
w
,
h
,
oldw
,
oldh
);
centerX
=
w
/
2
;
centerY
=
h
/
2
;
radius
=
Math
.
min
(
w
,
h
)
/
2
-
Math
.
max
(
cycleBgStrokeWidth
,
progressStrokeWidth
);
// 两数中的最小值 / 2 - 两数中的最大值
rectF
.
set
(
centerX
-
radius
,
centerY
-
radius
,
centerX
+
radius
,
centerY
+
radius
);
}
/**
* 画
*
* @param canvas
*/
@Override
protected
void
onDraw
(
Canvas
canvas
)
{
super
.
onDraw
(
canvas
);
canvas
.
drawCircle
(
centerX
,
centerY
,
radius
,
cycleBgPaint
);
canvas
.
drawArc
(
rectF
,
270
,
mProgress
*
3.6f
,
false
,
progressPaint
);
if
(
isProgressText
)
{
Paint
.
FontMetrics
fontMetrics
=
centerTextPaint
.
getFontMetrics
();
int
baseline
=
(
int
)
((
rectF
.
bottom
+
rectF
.
top
-
fontMetrics
.
bottom
-
fontMetrics
.
top
)
/
2
);
canvas
.
drawText
((
int
)
mProgress
+
"%"
,
rectF
.
centerX
(),
baseline
,
centerTextPaint
);
}
}
public
void
setmProgress
(
int
progress
)
{
this
.
mProgress
=
progress
;
invalidate
();
}
}
plugin_im/src/main/res/drawable/shape_from_chat_msg.xml
0 → 100644
View file @
b2a44106
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<corners
android:bottomLeftRadius=
"@dimen/size_100"
android:bottomRightRadius=
"@dimen/size_100"
android:topLeftRadius=
"0dp"
android:topRightRadius=
"@dimen/size_100"
/>
<solid
android:color=
"@android:color/white"
/>
</shape>
\ No newline at end of file
plugin_im/src/main/res/drawable/shape_to_chat_msg.xml
0 → 100644
View file @
b2a44106
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<corners
android:bottomLeftRadius=
"@dimen/size_100"
android:bottomRightRadius=
"@dimen/size_100"
android:topLeftRadius=
"@dimen/size_100"
android:topRightRadius=
"0dp"
/>
<solid
android:color=
"#FFB74B"
/>
</shape>
\ No newline at end of file
plugin_im/src/main/res/layout/chat_to_item_pic.xml
View file @
b2a44106
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:cyclepb=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
...
@@ -65,15 +66,27 @@
...
@@ -65,15 +66,27 @@
</RelativeLayout>
</RelativeLayout>
<ImageView
<FrameLayout
android:id=
"@+id/chat_pic"
android:layout_width=
"120dp"
android:layout_width=
"120dp"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
>
android:layout_centerInParent=
"true"
android:layout_marginLeft=
"@dimen/dp5"
<ImageView
android:layout_marginTop=
"@dimen/chat_head_top"
android:id=
"@+id/chat_pic"
android:layout_marginRight=
"5dp"
android:layout_width=
"120dp"
android:maxWidth=
"210dp"
/>
android:layout_height=
"wrap_content"
android:layout_centerInParent=
"true"
android:layout_marginLeft=
"@dimen/dp5"
android:layout_marginTop=
"@dimen/chat_head_top"
android:layout_marginRight=
"5dp"
android:maxHeight=
"210dp"
/>
<com.rv.im.view.CycleProgress
android:id=
"@+id/cycle_progress"
android:layout_width=
"@dimen/dp40"
android:layout_height=
"@dimen/dp40"
android:layout_gravity=
"center"
/>
</FrameLayout>
<com.rv.im.view.RoundImageView
<com.rv.im.view.RoundImageView
android:id=
"@+id/iv_header"
android:id=
"@+id/iv_header"
...
...
plugin_im/src/main/res/values/attrs.xml
View file @
b2a44106
...
@@ -136,4 +136,20 @@
...
@@ -136,4 +136,20 @@
<attr
name=
"view_color"
format=
"color"
/>
<attr
name=
"view_color"
format=
"color"
/>
</declare-styleable>
</declare-styleable>
<declare-styleable
name=
"CycleProgress"
>
<attr
name=
"circleBgStrokeWidth"
format=
"dimension"
/>
<!--圈的宽度 -->
<attr
name=
"progressStrokeWidth"
format=
"dimension"
/>
<!--进度条的宽度 -->
<attr
name=
"circleBgColor"
format=
"color"
/>
<!--圈的颜色 -->
<attr
name=
"progressColor"
format=
"color"
/>
<!--进度条的颜色 -->
<attr
name=
"circleAnimationDuration"
format=
"integer"
/>
<!--进度条时长 -->
<attr
name=
"isDrawCenterProgressText"
format=
"boolean"
/>
<!--是否显示圈内文字 -->
<attr
name=
"centerProgressTextColor"
format=
"color"
/>
<!--圈内文字的颜色 -->
<attr
name=
"centerProgressTextSize"
format=
"dimension"
/>
<!--圈内文字的大小 -->
</declare-styleable>
</resources>
</resources>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment