-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathEasyPhotoActivity.kt
More file actions
135 lines (109 loc) · 3.32 KB
/
Copy pathEasyPhotoActivity.kt
File metadata and controls
135 lines (109 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.haoge.sample.easyandroid.activities
import android.Manifest
import android.os.Bundle
import android.os.Environment
import android.widget.ImageView
import android.widget.TextView
import butterknife.OnClick
import com.bumptech.glide.Glide
import com.haoge.easyandroid.easy.EasyLog
import com.haoge.easyandroid.easy.EasyPermissions
import com.haoge.easyandroid.easy.EasyMediaFile
import com.haoge.easyandroid.easy.EasyToast
import com.haoge.sample.easyandroid.BaseActivity
import com.haoge.sample.easyandroid.R
import java.io.File
/**
* 创建日期:2018/8/22 上午 10:42
* @author:Vincent
* 备注:
*/
class EasyPhotoActivity : BaseActivity() {
private val switcher by lazy { findViewById<TextView>(R.id.indicate_img_path) }
private var indicatePath:String? = null
private val photo = EasyMediaFile().setError {
EasyLog.DEFAULT.e(it.message)
}.setCallback {
showImg(it)
}
override fun getLayoutId(): Int {
return R.layout.activity_easy_photo
}
override fun initPage(savedInstanceState: Bundle?) {
//拒绝权限将无法使用
EasyPermissions.create(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.CAMERA).callback { grant ->
//拒绝直接关闭
if(!grant){
finish()
} }.request(this)
}
@OnClick(R.id.indicate_img_path)
fun indicateImgPath() {
indicatePath = if (indicatePath == null) {
switcher.text = "指定图片缓存地址"
File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "EasyPhotoTest.jpg").absolutePath
} else {
switcher.text = "使用默认缓存地址"
null
}
photo.setFilePath(indicatePath)
}
@OnClick(R.id.takePhoto)
fun takePhoto() {
photo.setCrop(false).takePhoto(this)
}
@OnClick(R.id.selectPhoto)
fun selectPhoto() {
photo.setCrop(false).selectPhoto(this)
}
@OnClick(R.id.takePhoto_zoom)
fun takePhotoZoom() {
photo.setCrop(true).takePhoto(this)
}
@OnClick(R.id.selectPhoto_zoom)
fun selectPhotoZoom() {
photo.setCrop(true).selectPhoto(this)
}
@OnClick(R.id.getPhoto)
fun getPhoto(){
photo.getImage(this)
}
@OnClick(R.id.takeAudio)
fun takeAudio(){
photo.takeAudio(this)
}
@OnClick(R.id.selectAudio)
fun selectAudio() {
photo.selectAudio(this)
}
@OnClick(R.id.getAudio)
fun getAudio(){
photo.getAudio(this)
}
@OnClick(R.id.takeVideo)
fun takeVideo(){
photo.takeVideo(this)
}
@OnClick(R.id.selectVideo)
fun selectVideo() {
photo.selectVideo(this)
}
@OnClick(R.id.getVideo)
fun getVideo(){
photo.getVideo(this)
}
@OnClick(R.id.selectNormalFile)
fun selectNormalFile() {
// photo.selectFile(this)
}
/**
* 加载图片
*/
private fun showImg(outputFile: File) {
val showImg:ImageView = findViewById(R.id.showImg)
EasyToast.DEFAULT.show("得到的文件名为:${outputFile.absolutePath}")
EasyLog.DEFAULT.e("得到的文件名为:${outputFile.absolutePath}")
//加载图片
Glide.with(showImg).load(outputFile).into(showImg)
}
}