Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
杨凯
YDL-Component-Medical
Commits
b7ee0d16
Commit
b7ee0d16
authored
May 11, 2022
by
范玉宾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save share meditation to local commit patch
parent
6b6331d1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
142 additions
and
7 deletions
+142
-7
PlayMeditationActivity.kt
m-muse/src/main/java/com/yidianling/muse/activity/PlayMeditationActivity.kt
+1
-1
ShareMeditationUtil.kt
m-muse/src/main/java/com/yidianling/muse/utils/ShareMeditationUtil.kt
+78
-1
ShareMeditationDialog.kt
m-muse/src/main/java/com/yidianling/muse/widget/ShareMeditationDialog.kt
+62
-5
layout_share_play_meditation.xml
m-muse/src/main/res/layout/layout_share_play_meditation.xml
+1
-0
No files found.
m-muse/src/main/java/com/yidianling/muse/activity/PlayMeditationActivity.kt
View file @
b7ee0d16
...
...
@@ -19,7 +19,7 @@ import com.yidianling.muse.utils.MediaPlayerTimeUtil
import
com.yidianling.muse.widget.QuitMeditationDialog
import
com.yidianling.muse.widget.ShareMeditationDialog
import
kotlinx.android.synthetic.main.activity_play_meditation.*
import
kotlinx.android.synthetic.main.
exo_
player_control_view.*
import
kotlinx.android.synthetic.main.player_control_view.*
import
java.util.*
...
...
m-muse/src/main/java/com/yidianling/muse/utils/ShareMeditationUtil.kt
View file @
b7ee0d16
package
com.yidianling.muse.utils
class
Image
{
import
android.content.Context
import
android.content.Intent
import
android.graphics.Bitmap
import
android.net.Uri
import
android.os.Environment
import
android.provider.MediaStore
import
android.view.View
import
com.yidianling.common.tools.ToastUtil
import
java.io.File
import
java.io.FileOutputStream
import
java.io.IOException
import
java.lang.Exception
import
java.text.SimpleDateFormat
import
java.util.*
import
kotlin.properties.Delegates
class
ShareMeditationUtil
{
companion
object
{
fun
saveImageToLocal
(
view
:
View
){
val
timeStamp
=
SimpleDateFormat
(
"yyyyMMdd_HHmmss"
,
Locale
.
CHINA
).
format
(
Date
())
val
fileName
=
"IMG_$timeStamp"
val
bitmap
=
saveViewBitmapToAlbum
(
view
,
fileName
,
true
)
}
private
fun
saveViewBitmapToAlbum
(
view
:
View
,
name
:
String
,
isPrompt
:
Boolean
):
Bitmap
?{
view
.
isDrawingCacheEnabled
=
false
view
.
isDrawingCacheEnabled
=
true
view
.
measure
(
view
.
measuredWidth
,
view
.
measuredHeight
)
try
{
val
bitmap
=
view
.
drawingCache
return
saveBitmapToAlbum
(
view
.
context
,
bitmap
,
name
,
isPrompt
)
}
catch
(
e
:
Exception
){
}
return
null
}
private
fun
saveBitmapToAlbum
(
context
:
Context
,
bitmap
:
Bitmap
,
name
:
String
,
isPrompt
:
Boolean
):
Bitmap
?{
var
fileName
by
Delegates
.
notNull
<
String
>()
val
galleryPath
=
Environment
.
getExternalStorageDirectory
().
toString
()+
File
.
separator
+
Environment
.
DIRECTORY_DCIM
+
File
.
separator
+
"Camera"
+
File
.
separator
var
file
:
File
?=
null
var
outStream
:
FileOutputStream
?=
null
try
{
file
=
File
(
galleryPath
,
"$name.png"
)
fileName
=
file
.
toString
()
outStream
=
FileOutputStream
(
fileName
)
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
90
,
outStream
)
}
catch
(
e
:
Exception
){
}
finally
{
try
{
outStream
?.
close
()
}
catch
(
e
:
IOException
){
}
}
MediaStore
.
Images
.
Media
.
insertImage
(
context
.
contentResolver
,
bitmap
,
fileName
,
null
)
val
intent
=
Intent
(
Intent
.
ACTION_MEDIA_SCANNER_SCAN_FILE
)
val
uri
=
Uri
.
fromFile
(
file
)
intent
.
data
=
uri
context
.
sendBroadcast
(
intent
)
if
(
isPrompt
){
ToastUtil
.
toastShort
(
if
(
bitmap
!=
null
)
"已保存"
else
"保存失败"
)
}
return
bitmap
}
}
}
\ No newline at end of file
m-muse/src/main/java/com/yidianling/muse/widget/ShareMeditationDialog.kt
View file @
b7ee0d16
package
com.yidianling.muse.widget
import
android.app.Activity
import
android.graphics.Bitmap
import
android.graphics.Canvas
import
android.graphics.Color
import
android.os.Bundle
import
android.util.DisplayMetrics
import
android.view.LayoutInflater
...
...
@@ -12,8 +16,16 @@ import android.widget.LinearLayout
import
android.widget.TextView
import
androidx.fragment.app.DialogFragment
import
com.bumptech.glide.Glide
import
com.umeng.socialize.bean.SHARE_MEDIA
import
com.ydl.ydlcommon.actions.share.ShareUtils
import
com.ydl.ydlcommon.utils.remind.ToastHelper
import
com.yidianling.muse.R
import
com.yidianling.muse.utils.ShareMeditationUtil
import
kotlinx.android.synthetic.main.layout_share_play_meditation.*
import
java.io.File
import
java.io.FileNotFoundException
import
java.io.FileOutputStream
import
java.io.IOException
class
ShareMeditationDialog
:
DialogFragment
()
{
...
...
@@ -56,6 +68,8 @@ class ShareMeditationDialog:DialogFragment() {
private
fun
initView
(
view
:
View
?)
{
val
imageUrl
=
"http://static.ydlcdn.com/v1/images/logo320.png"
val
shareImageUrl
=
arguments
?.
getString
(
KEY_SHARE_IMAGE_URL
)
val
shareContent
=
arguments
?.
getString
(
KEY_SHARE_CONTENT
)
...
...
@@ -77,23 +91,31 @@ class ShareMeditationDialog:DialogFragment() {
llQQFriend
=
view
?.
findViewById
(
R
.
id
.
ll_qq_friend
)
llWeChat
?.
setOnClickListener
{
ToastHelper
.
show
(
"分享给微信好友!"
)
ShareUtils
.
shareTo
(
SHARE_MEDIA
.
WEIXIN
,
activity
as
Activity
,
"share_title"
,
"http://www.baidu.com"
,
"share_context"
,
imageUrl
)
dismiss
()
}
llCircleOfFriends
?.
setOnClickListener
{
ToastHelper
.
show
(
"分享到朋友圈!"
)
ShareUtils
.
shareTo
(
SHARE_MEDIA
.
WEIXIN_CIRCLE
,
activity
as
Activity
,
"share_title"
,
"https://www.baidu.com"
,
"share_context"
,
imageUrl
)
dismiss
()
}
llSave
?.
setOnClickListener
{
ToastHelper
.
show
(
"保存图片!"
)
ShareMeditationUtil
.
saveImageToLocal
(
csl_layout_top
)
}
llQQZone
?.
setOnClickListener
{
ToastHelper
.
show
(
"分享到QQ空间!"
)
ShareUtils
.
shareTo
(
SHARE_MEDIA
.
QZONE
,
activity
as
Activity
,
"share_title"
,
"http://www.baidu.com"
,
"share_context"
,
imageUrl
)
dismiss
()
}
llQQFriend
?.
setOnClickListener
{
ToastHelper
.
show
(
"分享给QQ好友!"
)
ShareUtils
.
shareTo
(
SHARE_MEDIA
.
QQ
,
activity
as
Activity
,
"share_title"
,
"http://www.baidu.com"
,
"share_context"
,
imageUrl
)
dismiss
()
}
view
?.
findViewById
<
TextView
>(
R
.
id
.
tv_cancel_share
)
?.
setOnClickListener
{
...
...
@@ -102,6 +124,41 @@ class ShareMeditationDialog:DialogFragment() {
}
private
fun
getBitmapFromView
(
view
:
View
):
Bitmap
?{
val
w
=
view
.
width
val
h
=
view
.
height
val
bitmap
=
Bitmap
.
createBitmap
(
w
,
h
,
Bitmap
.
Config
.
ARGB_8888
)
val
c
=
Canvas
(
bitmap
)
view
.
layout
(
0
,
0
,
w
,
h
)
view
.
draw
(
c
)
// var bitmap = Bitmap.createBitmap(view.width,view.height,Bitmap.Config.ARGB_8888)
// var canvas = Canvas(bitmap)
// canvas.drawColor(Color.WHITE)
// view.draw(canvas)
return
bitmap
}
private
fun
savePNG
(
bitmap
:
Bitmap
,
name
:
String
){
val
file
=
File
(
name
)
try
{
val
out
=
FileOutputStream
(
file
)
if
(
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
out
)){
out
.
flush
()
out
.
close
()
}
}
catch
(
e
:
FileNotFoundException
){
}
catch
(
e
:
IOException
){
}
}
fun
getScreenWidth
()
=
context
?.
resources
?.
displayMetrics
?.
widthPixels
fun
getScreenHeight
()
=
context
?.
resources
?.
displayMetrics
?.
heightPixels
companion
object
{
const
val
TAG
=
"ShareMeditationDialog"
...
...
m-muse/src/main/res/layout/layout_share_play_meditation.xml
View file @
b7ee0d16
...
...
@@ -164,6 +164,7 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/csl_layout_top"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginHorizontal=
"20dp"
...
...
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