Skip to content

Commit d09eca7

Browse files
committed
增强EasyPhoto的文件选择能力
1 parent 8a2aaf2 commit d09eca7

File tree

6 files changed

+494
-131
lines changed

6 files changed

+494
-131
lines changed

app/src/main/AndroidManifest.xml

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

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

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.haoge.sample.easyandroid.activities
22

33
import android.Manifest
4+
import android.content.Intent
45
import android.os.Bundle
56
import android.os.Environment
67
import android.widget.ImageView
78
import android.widget.TextView
89
import butterknife.OnClick
910
import com.bumptech.glide.Glide
11+
import com.haoge.easyandroid.easy.EasyLog
1012
import com.haoge.easyandroid.easy.EasyPermissions
1113
import com.haoge.easyandroid.easy.EasyPhoto
1214
import com.haoge.easyandroid.easy.EasyToast
@@ -39,6 +41,7 @@ class EasyPhotoActivity : BaseActivity() {
3941
if(!grant){
4042
finish()
4143
} }.request(this)
44+
4245
}
4346

4447
@OnClick(R.id.indicate_img_path)
@@ -51,7 +54,7 @@ class EasyPhotoActivity : BaseActivity() {
5154
null
5255
}
5356

54-
photo.setImgPath(indicatePath)
57+
photo.setFilePath(indicatePath)
5558
}
5659

5760
@OnClick(R.id.takePhoto)
@@ -64,6 +67,9 @@ class EasyPhotoActivity : BaseActivity() {
6467
photo.setCrop(false).selectPhoto(this)
6568
}
6669

70+
71+
72+
6773
@OnClick(R.id.takePhoto_zoom)
6874
fun takePhotoZoom() {
6975
photo.setCrop(true).takePhoto(this)
@@ -73,6 +79,44 @@ class EasyPhotoActivity : BaseActivity() {
7379
fun selectPhotoZoom() {
7480
photo.setCrop(true).selectPhoto(this)
7581
}
82+
@OnClick(R.id.getPhoto)
83+
fun getPhoto(){
84+
photo.getImage(this)
85+
}
86+
87+
@OnClick(R.id.takeAudio)
88+
fun takeAudio(){
89+
photo.takeAudio(this)
90+
}
91+
92+
@OnClick(R.id.selectAudio)
93+
fun selectAudio() {
94+
photo.selectAudio(this)
95+
}
96+
97+
@OnClick(R.id.getAudio)
98+
fun getAudio(){
99+
photo.getAudio(this)
100+
}
101+
@OnClick(R.id.takeVideo)
102+
fun takeVideo(){
103+
photo.takeVideo(this)
104+
}
105+
106+
@OnClick(R.id.selectVideo)
107+
fun selectVideo() {
108+
photo.selectVideo(this)
109+
}
110+
111+
@OnClick(R.id.getVideo)
112+
fun getVideo(){
113+
photo.getVideo(this)
114+
}
115+
116+
@OnClick(R.id.selectNormalFile)
117+
fun selectNormalFile() {
118+
photo.selectFile(this)
119+
}
76120

77121
/**
78122
* 加载图片
@@ -84,4 +128,10 @@ class EasyPhotoActivity : BaseActivity() {
84128
Glide.with(showImg).load(outputFile).into(showImg)
85129
}
86130

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+
}
136+
87137
}
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,103 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:orientation="vertical"
87
tools:context=".activities.EasyPhotoActivity">
98

10-
<Button
11-
android:id="@+id/takePhoto"
12-
android:text="拍照"
9+
<LinearLayout
1310
android:layout_width="match_parent"
14-
android:layout_height="wrap_content" />
11+
android:layout_height="wrap_content"
12+
android:orientation="vertical">
1513

16-
<Button
17-
android:id="@+id/selectPhoto"
18-
android:text="选择图片"
19-
android:layout_width="match_parent"
20-
android:layout_height="wrap_content" />
14+
<Button
15+
android:id="@+id/takePhoto"
16+
android:text="拍照"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content" />
2119

22-
<Button
23-
android:id="@+id/takePhoto_zoom"
24-
android:text="拍照——图片裁剪"
25-
android:layout_width="match_parent"
26-
android:layout_height="wrap_content" />
20+
<Button
21+
android:id="@+id/selectPhoto"
22+
android:text="选择图片"
23+
android:layout_width="match_parent"
24+
android:layout_height="wrap_content" />
2725

28-
<Button
29-
android:id="@+id/selectPhoto_zoom"
30-
android:text="选择图片-图片裁剪"
31-
android:layout_width="match_parent"
32-
android:layout_height="wrap_content" />
26+
<Button
27+
android:id="@+id/getPhoto"
28+
android:text="拍照/选择图片"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content" />
31+
32+
<Button
33+
android:id="@+id/takePhoto_zoom"
34+
android:text="拍照——图片裁剪"
35+
android:layout_width="match_parent"
36+
android:layout_height="wrap_content" />
37+
38+
<Button
39+
android:id="@+id/selectPhoto_zoom"
40+
android:text="选择图片-图片裁剪"
41+
android:layout_width="match_parent"
42+
android:layout_height="wrap_content" />
43+
44+
<Button
45+
android:id="@+id/indicate_img_path"
46+
android:text="使用默认缓存地址"
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content" />
49+
50+
<Button
51+
android:id="@+id/takeVideo"
52+
android:text="视频录制"
53+
android:layout_width="match_parent"
54+
android:layout_height="wrap_content" />
55+
56+
<Button
57+
android:id="@+id/selectVideo"
58+
android:text="选择视频"
59+
android:layout_width="match_parent"
60+
android:layout_height="wrap_content" />
61+
62+
<Button
63+
android:id="@+id/getVideo"
64+
android:text="录制视频/选择视频"
65+
android:layout_width="match_parent"
66+
android:layout_height="wrap_content" />
67+
68+
<ImageView
69+
android:id="@+id/showImg"
70+
android:layout_width="wrap_content"
71+
android:layout_height="wrap_content"
72+
android:src="@mipmap/ic_launcher"
73+
android:layout_gravity="center_horizontal"/>
74+
75+
<Button
76+
android:id="@+id/takeAudio"
77+
android:text="音频录制"
78+
android:layout_width="match_parent"
79+
android:layout_height="wrap_content" />
80+
81+
<Button
82+
android:id="@+id/selectAudio"
83+
android:text="选择音频"
84+
android:layout_width="match_parent"
85+
android:layout_height="wrap_content" />
86+
87+
<Button
88+
android:id="@+id/getAudio"
89+
android:text="录制音频/选择音频"
90+
android:layout_width="match_parent"
91+
android:layout_height="wrap_content" />
92+
93+
<Button
94+
android:id="@+id/selectNormalFile"
95+
android:text="选择文件"
96+
android:layout_width="match_parent"
97+
android:layout_height="wrap_content" />
98+
99+
</LinearLayout>
33100

34-
<Button
35-
android:id="@+id/indicate_img_path"
36-
android:text="使用默认缓存地址"
37-
android:layout_width="match_parent"
38-
android:layout_height="wrap_content" />
39101

40-
<ImageView
41-
android:id="@+id/showImg"
42-
android:layout_width="match_parent"
43-
android:layout_height="match_parent"
44-
android:src="@mipmap/ic_launcher"
45-
android:layout_gravity="center_horizontal"/>
46102

47-
</LinearLayout>
103+
</ScrollView>

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.2.30'
4+
ext.kotlin_version = '1.3.10'
55
repositories {
66
mavenCentral()
77
google()
88
jcenter()
99

1010
}
1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:3.1.2'
12+
classpath 'com.android.tools.build:gradle:3.4.1'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414

1515
// NOTE: Do not place your application dependencies here; they belong
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat May 05 23:18:41 CST 2018
1+
#Wed Jul 03 21:23:06 CST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 commit comments

Comments
 (0)