Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Administrator
AloqaIM-Android
Commits
9f0974fa
Commit
9f0974fa
authored
May 02, 2018
by
Divyanshu Bhargava
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
show drawing view
parent
7c56cc4d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
174 additions
and
1 deletion
+174
-1
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+33
-1
CustomDrawView.kt
...rc/main/java/chat/rocket/android/widget/CustomDrawView.kt
+90
-0
drawing_view.xml
app/src/main/res/layout/drawing_view.xml
+36
-0
fragment_chat_room.xml
app/src/main/res/layout/fragment_chat_room.xml
+10
-0
styles.xml
app/src/main/res/values/styles.xml
+5
-0
No files found.
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
9f0974fa
package
chat.rocket.android.chatroom.ui
import
android.app.Activity
import
android.app.Dialog
import
android.content.ClipData
import
android.content.ClipboardManager
import
android.content.Context
import
android.content.Intent
import
android.graphics.Bitmap
import
android.graphics.BitmapFactory
import
android.net.Uri
import
android.os.Bundle
import
android.os.Handler
import
android.provider.MediaStore
import
android.support.annotation.DrawableRes
import
android.support.v4.app.Fragment
import
android.support.v7.widget.DefaultItemAnimator
import
android.support.v7.widget.LinearLayoutManager
import
android.support.v7.widget.RecyclerView
import
android.view.*
import
android.widget.ImageView
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.adapter.*
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
...
...
@@ -27,6 +32,7 @@ import chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import
chat.rocket.android.helper.KeyboardHelper
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.util.extensions.*
import
chat.rocket.android.widget.CustomDrawView
import
chat.rocket.android.widget.emoji.*
import
chat.rocket.core.internal.realtime.socket.model.State
import
dagger.android.support.AndroidSupportInjection
...
...
@@ -35,7 +41,7 @@ import kotlinx.android.synthetic.main.fragment_chat_room.*
import
kotlinx.android.synthetic.main.message_attachment_options.*
import
kotlinx.android.synthetic.main.message_composer.*
import
kotlinx.android.synthetic.main.message_list.*
import
timber.log.Timber
import
java.io.ByteArrayOutputStream
import
java.util.concurrent.atomic.AtomicInteger
import
javax.inject.Inject
...
...
@@ -620,6 +626,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
button_drawing
.
setOnClickListener
{
showDrawingView
()
handler
.
postDelayed
({
hideAttachmentOptions
()
},
400
)
...
...
@@ -627,6 +634,31 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
private
fun
showDrawingView
()
{
val
drawDialog
=
Dialog
(
activity
,
R
.
style
.
DrawingDialogStyle
)
drawDialog
.
setContentView
(
R
.
layout
.
drawing_view
)
val
customDrawView
:
CustomDrawView
=
drawDialog
.
findViewById
(
R
.
id
.
custom_draw_view
)
val
closeDraw
:
ImageView
=
drawDialog
.
findViewById
(
R
.
id
.
image_close_drawing
)
val
sendDraw
:
ImageView
=
drawDialog
.
findViewById
(
R
.
id
.
image_send_drawing
)
closeDraw
.
setOnClickListener
{
drawDialog
.
dismiss
()
}
sendDraw
.
setOnClickListener
{
val
bitmap
:
Bitmap
=
customDrawView
.
getBitmap
()
uploadFile
(
bitmapToUri
(
bitmap
))
dummy_image
.
setImageBitmap
(
bitmap
)
drawDialog
.
dismiss
()
}
drawDialog
.
show
()
}
fun
bitmapToUri
(
bitmap
:
Bitmap
):
Uri
{
val
bytes
=
ByteArrayOutputStream
()
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
bytes
)
val
path
=
MediaStore
.
Images
.
Media
.
insertImage
(
activity
?.
contentResolver
,
bitmap
,
"title"
,
null
)
return
Uri
.
parse
(
path
)
}
private
fun
setupSuggestionsView
()
{
suggestions_view
.
anchorTo
(
text_message
)
.
setMaximumHeight
(
resources
.
getDimensionPixelSize
(
R
.
dimen
.
suggestions_box_max_height
))
...
...
app/src/main/java/chat/rocket/android/widget/CustomDrawView.kt
0 → 100644
View file @
9f0974fa
package
chat.rocket.android.widget
import
android.content.Context
import
android.graphics.*
import
android.util.AttributeSet
import
android.view.MotionEvent
import
android.view.View
class
CustomDrawView
:
View
{
val
strokeWidth
=
4f
private
var
mX
:
Float
=
0f
private
var
mY
:
Float
=
0f
private
lateinit
var
path
:
Path
private
lateinit
var
paint
:
Paint
private
val
TOLERANCE
=
5f
private
lateinit
var
mBitmap
:
Bitmap
private
lateinit
var
mCanvas
:
Canvas
fun
init
(){
path
=
Path
()
paint
=
Paint
()
paint
.
isAntiAlias
=
true
paint
.
color
=
Color
.
BLACK
paint
.
style
=
Paint
.
Style
.
STROKE
paint
.
strokeJoin
=
Paint
.
Join
.
ROUND
paint
.
strokeWidth
=
strokeWidth
this
.
isDrawingCacheEnabled
=
true
}
constructor
(
context
:
Context
?)
:
super
(
context
){
init
()
}
constructor
(
context
:
Context
?,
attrs
:
AttributeSet
?)
:
super
(
context
,
attrs
){
init
()
}
constructor
(
context
:
Context
?,
attrs
:
AttributeSet
?,
defStyleAttr
:
Int
)
:
super
(
context
,
attrs
,
defStyleAttr
){
init
()
}
override
fun
onDraw
(
canvas
:
Canvas
?)
{
super
.
onDraw
(
canvas
)
canvas
?.
drawPath
(
path
,
paint
)
}
private
fun
startTouch
(
x
:
Float
,
y
:
Float
){
path
.
moveTo
(
x
,
y
)
mX
=
x
mY
=
y
}
private
fun
moveTouch
(
x
:
Float
,
y
:
Float
){
val
dx
:
Float
=
Math
.
abs
(
x
-
mX
)
val
dy
:
Float
=
Math
.
abs
(
y
-
mY
)
if
(
dx
>=
TOLERANCE
||
dy
>=
TOLERANCE
){
path
.
quadTo
(
mX
,
mY
,(
x
+
mX
)/
2
,(
y
+
mY
)/
2
)
mX
=
x
mY
=
y
}
}
private
fun
upTouch
(){
path
.
lineTo
(
mX
,
mY
)
}
override
fun
onSizeChanged
(
w
:
Int
,
h
:
Int
,
oldw
:
Int
,
oldh
:
Int
)
{
super
.
onSizeChanged
(
w
,
h
,
oldw
,
oldh
)
mBitmap
=
Bitmap
.
createBitmap
(
w
,
h
,
Bitmap
.
Config
.
ARGB_8888
)
mCanvas
=
Canvas
(
mBitmap
)
}
override
fun
onTouchEvent
(
event
:
MotionEvent
?):
Boolean
{
val
x
:
Float
=
event
!!
.
x
val
y
:
Float
=
event
.
y
when
(
event
.
action
){
MotionEvent
.
ACTION_DOWN
->
{
startTouch
(
x
,
y
)
invalidate
()
}
MotionEvent
.
ACTION_MOVE
->
{
moveTouch
(
x
,
y
)
invalidate
()
}
MotionEvent
.
ACTION_UP
->
{
upTouch
()
invalidate
()
}
}
return
true
}
fun
getBitmap
():
Bitmap
{
return
this
.
drawingCache
}
}
\ No newline at end of file
app/src/main/res/layout/drawing_view.xml
0 → 100644
View file @
9f0974fa
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/white"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<chat.rocket.android.widget.CustomDrawView
android:id=
"@+id/custom_draw_view"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
<ImageView
android:id=
"@+id/image_close_drawing"
android:layout_width=
"56dp"
android:layout_height=
"56dp"
android:src=
"@drawable/ic_close_white_24dp"
android:tint=
"@color/colorPrimary"
android:padding=
"16dp"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
android:background=
"@color/white"
android:foreground=
"?selectableItemBackground"
/>
<ImageView
android:id=
"@+id/image_send_drawing"
android:layout_width=
"56dp"
android:layout_height=
"56dp"
android:src=
"@drawable/ic_send_24dp"
android:padding=
"16dp"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
android:background=
"@color/white"
android:foreground=
"?selectableItemBackground"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_chat_room.xml
View file @
9f0974fa
...
...
@@ -130,4 +130,14 @@
tools:text=
"connected"
tools:visibility=
"visible"
/>
<ImageView
android:id=
"@+id/dummy_image"
android:layout_width=
"100dp"
android:layout_height=
"100dp"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
android:minHeight=
"100dp"
android:minWidth=
"100dp"
android:background=
"@color/white"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/styles.xml
View file @
9f0974fa
...
...
@@ -109,4 +109,9 @@
<item
name=
"actionModeCloseDrawable"
>
@drawable/ic_close_white_24dp
</item>
</style>
<style
name=
"DrawingDialogStyle"
parent=
"Theme.AppCompat.Light.Dialog.Alert"
>
<item
name=
"android:windowIsFloating"
>
false
</item>
<item
name=
"android:windowBackground"
>
@color/white
</item>
</style>
</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