Skip to content

Commit

Permalink
增强EasyPhoto的文件选择能力
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicent9920 committed Mar 1, 2020
1 parent 8a2aaf2 commit d09eca7
Show file tree
Hide file tree
Showing 6 changed files with 494 additions and 131 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/Theme.AppCompat.Light">
<activity android:name=".DemosActivity">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.haoge.sample.easyandroid.activities

import android.Manifest
import android.content.Intent
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.EasyPhoto
import com.haoge.easyandroid.easy.EasyToast
Expand Down Expand Up @@ -39,6 +41,7 @@ class EasyPhotoActivity : BaseActivity() {
if(!grant){
finish()
} }.request(this)

}

@OnClick(R.id.indicate_img_path)
Expand All @@ -51,7 +54,7 @@ class EasyPhotoActivity : BaseActivity() {
null
}

photo.setImgPath(indicatePath)
photo.setFilePath(indicatePath)
}

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




@OnClick(R.id.takePhoto_zoom)
fun takePhotoZoom() {
photo.setCrop(true).takePhoto(this)
Expand All @@ -73,6 +79,44 @@ class EasyPhotoActivity : BaseActivity() {
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)
}

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

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
EasyLog.DEFAULT.e("onActivityResult $requestCode $resultCode $data" )
this.fragmentManager.findFragmentByTag(EasyPhoto.PhotoFragment.TAG).onActivityResult(requestCode, resultCode, data)
}

}
122 changes: 89 additions & 33 deletions app/src/main/res/layout/activity_easy_photo.xml
Original file line number Diff line number Diff line change
@@ -1,47 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.EasyPhotoActivity">

<Button
android:id="@+id/takePhoto"
android:text="拍照"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:orientation="vertical">

<Button
android:id="@+id/selectPhoto"
android:text="选择图片"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/takePhoto"
android:text="拍照"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/takePhoto_zoom"
android:text="拍照——图片裁剪"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/selectPhoto"
android:text="选择图片"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/selectPhoto_zoom"
android:text="选择图片-图片裁剪"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/getPhoto"
android:text="拍照/选择图片"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/takePhoto_zoom"
android:text="拍照——图片裁剪"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/selectPhoto_zoom"
android:text="选择图片-图片裁剪"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/indicate_img_path"
android:text="使用默认缓存地址"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/takeVideo"
android:text="视频录制"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/selectVideo"
android:text="选择视频"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/getVideo"
android:text="录制视频/选择视频"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ImageView
android:id="@+id/showImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_gravity="center_horizontal"/>

<Button
android:id="@+id/takeAudio"
android:text="音频录制"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/selectAudio"
android:text="选择音频"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/getAudio"
android:text="录制音频/选择音频"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/selectNormalFile"
android:text="选择文件"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

<Button
android:id="@+id/indicate_img_path"
android:text="使用默认缓存地址"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<ImageView
android:id="@+id/showImg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_gravity="center_horizontal"/>

</LinearLayout>
</ScrollView>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.30'
ext.kotlin_version = '1.3.10'
repositories {
mavenCentral()
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat May 05 23:18:41 CST 2018
#Wed Jul 03 21:23:06 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Loading

0 comments on commit d09eca7

Please sign in to comment.