Skip to content

Commit ed8a1c4

Browse files
committed
update EasyPhoto
1 parent d09eca7 commit ed8a1c4

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

app/src/main/AndroidManifest.xml

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
android:label="@string/app_name"
1717
android:roundIcon="@mipmap/ic_launcher_round"
1818
android:supportsRtl="true"
19-
android:requestLegacyExternalStorage="true"
2019
android:theme="@style/Theme.AppCompat.Light">
2120
<activity android:name=".DemosActivity">
2221
<intent-filter>

app/src/main/java/com/haoge/sample/easyandroid/activities/EasyPhotoActivity.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,11 @@ class EasyPhotoActivity : BaseActivity() {
124124
private fun showImg(outputFile: File) {
125125
val showImg:ImageView = findViewById(R.id.showImg)
126126
EasyToast.DEFAULT.show("得到的文件名为:${outputFile.absolutePath}")
127+
EasyLog.DEFAULT.e("得到的文件名为:${outputFile.absolutePath}")
127128
//加载图片
128129
Glide.with(showImg).load(outputFile).into(showImg)
129130
}
130131

131-
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
132-
super.onActivityResult(requestCode, resultCode, data)
133-
EasyLog.DEFAULT.e("onActivityResult $requestCode $resultCode $data" )
134-
this.fragmentManager.findFragmentByTag(EasyPhoto.PhotoFragment.TAG).onActivityResult(requestCode, resultCode, data)
135-
}
132+
136133

137134
}

utils/src/main/java/com/haoge/easyandroid/easy/EasyPhoto.kt

+16-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class EasyPhoto {
7979
}
8080

8181

82-
8382
/**
8483
* 选择文件
8584
* 支持图片、音频、视频、联系人以及其它类型文件
@@ -188,7 +187,7 @@ class EasyPhoto {
188187
buff.append("(").append(MediaStore.Images.ImageColumns.DATA).append("=").append("'$path'").append(")")
189188
cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, arrayOf(MediaStore.Images.ImageColumns._ID,
190189
MediaStore.Images.ImageColumns.DATA), buff.toString(), null, null).apply {
191-
this?: throw RuntimeException("cursor is null")
190+
this ?: throw RuntimeException("cursor is null")
192191
var dataIdx: Int
193192
while (!this.isAfterLast) {
194193
dataIdx = this.getColumnIndex(MediaStore.Images.ImageColumns.DATA)
@@ -203,7 +202,7 @@ class EasyPhoto {
203202
"content" -> {
204203

205204
context.contentResolver.query(uri, arrayOf(MediaStore.Images.Media.DATA), null, null, null).apply {
206-
this?: throw RuntimeException("cursor is null")
205+
this ?: throw RuntimeException("cursor is null")
207206
if (this.moveToFirst()) {
208207
val columnIndex = this.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
209208
path = this.getString(columnIndex)
@@ -431,8 +430,19 @@ class EasyPhoto {
431430
*/
432431
private fun takeFileInternal(takePhotoPath: File, intent: Intent, activity: Activity) {
433432
val fragment = PhotoFragment.findOrCreate(activity)
434-
fragment.start(intent, PhotoFragment.REQ_TAKE_FILE) { requestCode: Int, _: Intent? ->
433+
fragment.start(intent, PhotoFragment.REQ_TAKE_FILE) { requestCode: Int, data: Intent? ->
435434
if (requestCode == PhotoFragment.REQ_TAKE_FILE) {
435+
if(data?.data != null){
436+
mFilePath = uriToFile(activity,data.data)
437+
if(isCrop){
438+
zoomPhoto(takePhotoPath, mFilePath
439+
?: File(generateFilePath(activity)), activity)
440+
}else{
441+
callback?.invoke(mFilePath!!)
442+
mFilePath = null
443+
}
444+
return@start
445+
}
436446
if (isCrop) {
437447
zoomPhoto(takePhotoPath, mFilePath
438448
?: File(generateFilePath(activity)), activity)
@@ -554,7 +564,7 @@ class EasyPhoto {
554564
/**
555565
* 用于获取图片的Fragment
556566
*/
557-
class PhotoFragment : Fragment() {
567+
class PhotoFragment : Fragment() {
558568
/**
559569
* Fragment处理照片后返回接口
560570
*/
@@ -585,7 +595,7 @@ class EasyPhoto {
585595
const val REQ_TAKE_FILE = 10001
586596
const val REQ_SELECT_FILE = 10002
587597
const val REQ_ZOOM_PHOTO = 10003
588-
const val TAG = "EasyPhoto:PhotoFragment"
598+
private const val TAG = "EasyPhoto:PhotoFragment"
589599
590600
@JvmStatic
591601
fun findOrCreate(activity: Activity): PhotoFragment {

0 commit comments

Comments
 (0)