diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index ce1fc4f..ce889bd 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -1,22 +1,6 @@
-
-
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 61a9130..fb7f4a8 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 57e10d2..a4d8df1 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -7,6 +7,7 @@
+
-
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index eb2873e..1e2d92c 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -26,5 +26,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d5d35ec..ef61796 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/app/build.gradle b/app/build.gradle
index b66086b..d8f1b33 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,15 +1,13 @@
apply plugin: 'com.android.application'
-
apply plugin: 'kotlin-android'
-
apply plugin: 'kotlin-android-extensions'
android {
- compileSdkVersion 30
+ compileSdkVersion 33
defaultConfig {
applicationId "com.app.hapimediapic"
minSdkVersion 15
- targetSdkVersion 30
+ targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
@@ -24,9 +22,9 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
- implementation 'androidx.appcompat:appcompat:1.3.0'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+
+ implementation 'androidx.appcompat:appcompat:1.5.1'
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
implementation project(":hapimediapicker")
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 08e5831..171e8f7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -12,7 +12,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
-
+
diff --git a/build.gradle b/build.gradle
index 8d4c1cc..c1432b4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,33 +1,31 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
-
buildscript {
- ext.kotlin_version = '1.3.21'
repositories {
- google()
- jcenter()
maven { url 'https://jitpack.io' }
+ google()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
+ mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.4.2'
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
+ classpath 'com.android.tools.build:gradle:7.1.2'
+ classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
- classpath 'com.github.MJLblabla:HapiDepend:1.0.2'
-
}
}
allprojects {
- apply plugin: 'hapidepend'
-
repositories {
+ maven { url 'https://jitpack.io' }
google()
jcenter()
- maven { url 'https://jitpack.io' }
+ mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
+
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index f07c9b0..a5dd264 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
diff --git a/hapimediapicker/build.gradle b/hapimediapicker/build.gradle
index dd10b1b..cbff677 100644
--- a/hapimediapicker/build.gradle
+++ b/hapimediapicker/build.gradle
@@ -1,17 +1,12 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
-apply plugin: 'hapidepend'
-
-apply plugin: 'com.github.dcendents.android-maven'
-group='com.github.MJLblabla'
-
android {
- compileSdkVersion depend.compileSdkVersion
+ compileSdkVersion 33
defaultConfig {
minSdkVersion 15
- targetSdkVersion depend.targetSdkVersion
+ targetSdkVersion 33
versionCode 1
versionName "1.0"
@@ -27,18 +22,13 @@ android {
}
}
-
-
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
- implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
implementation 'com.github.MJLblabla:android_dev_utils:1.0.2'
- implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
- implementation depend.appcompat_v7()
+ implementation 'androidx.appcompat:appcompat:1.5.1'
+
testImplementation 'junit:junit:4.12'
- implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
diff --git a/hapimediapicker/src/main/java/com/hapi/mediapicker/ContentUriUtil.kt b/hapimediapicker/src/main/java/com/hapi/mediapicker/ContentUriUtil.kt
index 9ca35c9..1e2f4a3 100644
--- a/hapimediapicker/src/main/java/com/hapi/mediapicker/ContentUriUtil.kt
+++ b/hapimediapicker/src/main/java/com/hapi/mediapicker/ContentUriUtil.kt
@@ -44,7 +44,7 @@ object ContentUriUtil {
}
@SuppressLint("NewApi")
- fun getDataFromUri(context: Context, uri: Uri, contentType: ContentType?): String? {
+ fun getDataFromUri(context: Context, uri: Uri, contentType: ContentType): String? {
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) { // DocumentProvider
if (isExternalStorageDocument(uri)) { // ExternalStorageProvider
val docId = DocumentsContract.getDocumentId(uri)
@@ -75,7 +75,7 @@ object ContentUriUtil {
}
val selection = "_id=?"
val selectionArgs = arrayOf(split[1])
- return getDataColumn(context, type, contentUri, selection, selectionArgs)
+ return getDataColumn(context, type, contentUri!!, selection, selectionArgs)
}
} else if (ContentResolver.SCHEME_CONTENT.equals(uri.scheme!!, ignoreCase = true)) { // DownloadsProvider
return getDataColumn(context, contentType, uri, null, null)
@@ -104,7 +104,7 @@ object ContentUriUtil {
* @param selectionArgs (Optional) Selection arguments used in the query.
* @return The value of the _data column, which is typically a file path.
*/
- fun getDataColumn(context: Context, type: ContentType?, contentUri: Uri?, selection: String?, selectionArgs: Array?): String? {
+ fun getDataColumn(context: Context, type: ContentType, contentUri: Uri, selection: String?, selectionArgs: Array?): String? {
var contentResolver = context.contentResolver
val mediaIdColumn = MediaStore.MediaColumns._ID
val mimeTypeColumn = MediaStore.MediaColumns.MIME_TYPE
diff --git a/hapimediapicker/src/main/java/com/hapi/mediapicker/ImageCompression.kt b/hapimediapicker/src/main/java/com/hapi/mediapicker/ImageCompression.kt
index 6692abe..e7d0e1e 100644
--- a/hapimediapicker/src/main/java/com/hapi/mediapicker/ImageCompression.kt
+++ b/hapimediapicker/src/main/java/com/hapi/mediapicker/ImageCompression.kt
@@ -63,7 +63,6 @@ class ImageCompression(context: Context) : AsyncTask() {
}
}
-
private fun compressImage(imagePath: String): String {
var scaledBitmap: Bitmap? = null
@@ -122,7 +121,7 @@ class ImageCompression(context: Context) : AsyncTask() {
scaleMatrix.setScale(ratioX, ratioY, middleX, middleY)
val canvas = Canvas(scaledBitmap!!)
- canvas.matrix = scaleMatrix
+ canvas.setMatrix(scaleMatrix)
canvas.drawBitmap(bmp, middleX - bmp.width / 2, middleY - bmp.height / 2, Paint(Paint.FILTER_BITMAP_FLAG))
bmp.recycle()
diff --git a/hapimediapicker/src/main/java/com/hapi/mediapicker/PhotoRequestFragment.kt b/hapimediapicker/src/main/java/com/hapi/mediapicker/PhotoRequestFragment.kt
index f0b3b37..22f415a 100644
--- a/hapimediapicker/src/main/java/com/hapi/mediapicker/PhotoRequestFragment.kt
+++ b/hapimediapicker/src/main/java/com/hapi/mediapicker/PhotoRequestFragment.kt
@@ -39,14 +39,14 @@ final class PhotoRequestFragment : androidx.fragment.app.Fragment() {
if (!checkSizeCrop()) {
val originFileData =
ContentUriUtil.getDataFromUri(
- context!!,
- data.data,
+ requireContext(),
+ data.data!!,
ContentUriUtil.ContentType.image
)
if(originFileData==null){
callback?.onSuccess("", data.data)
}else{
- ImageCompression(context!!)
+ ImageCompression(requireContext())
.setOutputFilePath(ImageChooseHelper.compressFilePath)
.setCompressCallback(object : ImagePickCallback {
@@ -58,17 +58,17 @@ final class PhotoRequestFragment : androidx.fragment.app.Fragment() {
} else {
mTempFilePath = ImageChooseHelper.cropFilePath
val filePath = ContentUriUtil.getDataFromUri(
- context!!,
- data.data,
+ requireContext(),
+ data.data!!,
ContentUriUtil.ContentType.image
)
val imageUri = FileProvider.getUriForFile(
- context!!,
+ requireContext(),
ImageChooseHelper.PROVIDER_KEY,
File(filePath!!)
)
val intent = ImageChooseHelper.cropImageIntent(
- activity!!,
+ requireActivity(),
imageUri!!,
size!!,
mTempFilePath!!
@@ -81,7 +81,7 @@ final class PhotoRequestFragment : androidx.fragment.app.Fragment() {
}
PicPickHelper.REQUEST_CODE_CAMERA -> {
if (!checkSizeCrop()) {
- ImageCompression(context!!)
+ ImageCompression(requireContext())
.setOutputFilePath(ImageChooseHelper.compressFilePath)
.setCompressCallback(object : ImagePickCallback {
override fun onSuccess(result: String?, uri: Uri?) {
@@ -91,13 +91,13 @@ final class PhotoRequestFragment : androidx.fragment.app.Fragment() {
} else {
val imageUri =
FileProvider.getUriForFile(
- context!!,
+ requireContext(),
ImageChooseHelper.PROVIDER_KEY,
File(mCameraFilePath!!)
)
mTempFilePath = ImageChooseHelper.cropFilePath
val intent = ImageChooseHelper.cropImageIntent(
- activity!!,
+ requireActivity(),
imageUri,
size!!,
mTempFilePath!!
@@ -106,7 +106,7 @@ final class PhotoRequestFragment : androidx.fragment.app.Fragment() {
}
}
PicPickHelper.REQUEST_CODE_CROP -> {// 所有图片选取都得走得这一步
- ImageCompression(context!!)
+ ImageCompression(requireContext())
.setOutputFilePath(ImageChooseHelper.compressFilePath)
.setCompressCallback(object : ImagePickCallback {
override fun onSuccess(result: String?, uri: Uri?) {
@@ -116,7 +116,6 @@ final class PhotoRequestFragment : androidx.fragment.app.Fragment() {
}
else -> {
}
-
}
}
diff --git a/hapimediapicker/src/main/java/com/hapi/mediapicker/PicPickHelper.kt b/hapimediapicker/src/main/java/com/hapi/mediapicker/PicPickHelper.kt
index 7c75c12..5880435 100644
--- a/hapimediapicker/src/main/java/com/hapi/mediapicker/PicPickHelper.kt
+++ b/hapimediapicker/src/main/java/com/hapi/mediapicker/PicPickHelper.kt
@@ -2,26 +2,19 @@ package com.hapi.mediapicker
import android.Manifest
import android.app.Dialog
-import android.content.Context
-import androidx.fragment.app.FragmentActivity
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.TextView
-import com.tbruyelle.rxpermissions2.RxPermissions
+import androidx.appcompat.app.AppCompatActivity
+import com.hapi.permission.HapiPermission
import java.lang.ref.WeakReference
-
-/**
- * Created by caizhaowei on 2017/10/5.
- */
-
-class PicPickHelper(activity: androidx.fragment.app.FragmentActivity) {
+class PicPickHelper(activity: AppCompatActivity) {
private var activityWeakReference = WeakReference(activity)
private val photoRequestFragment by lazy { getPhotoRequstFragment(activity) }
- private val rxPermissions by lazy { RxPermissions(activity) }
/**
* 使用默认选择弹窗
@@ -29,15 +22,17 @@ class PicPickHelper(activity: androidx.fragment.app.FragmentActivity) {
fun show(size: Size?, callback: ImagePickCallback) {
photoRequestFragment.callback = callback
photoRequestFragment.size = size
- val bottomDialog = Dialog(activityWeakReference.get(), R.style.BottomViewWhiteMask)
- val contentView = LayoutInflater.from(activityWeakReference.get()).inflate(R.layout.dialog_choose_pic, null)
- bottomDialog.setCancelable(true)
- bottomDialog.setCanceledOnTouchOutside(true)
- bottomDialog.setContentView(contentView)
- bottomDialog.show()
+ val bottomDialog = activityWeakReference.get()
+ ?.let { Dialog(it, R.style.BottomViewWhiteMask) }
+ val contentView = LayoutInflater.from(activityWeakReference.get())
+ .inflate(R.layout.dialog_choose_pic, null)
+ bottomDialog?.setCancelable(true)
+ bottomDialog?.setCanceledOnTouchOutside(true)
+ bottomDialog?.setContentView(contentView)
+ bottomDialog?.show()
val imageChooseListener = View.OnClickListener { v ->
- bottomDialog.dismiss()
+ bottomDialog?.dismiss()
when (v.id) {
R.id.view1 -> {
fromCamera()
@@ -47,19 +42,17 @@ class PicPickHelper(activity: androidx.fragment.app.FragmentActivity) {
}
}
}
-
contentView.findViewById(R.id.view1).setOnClickListener(imageChooseListener)
contentView.findViewById(R.id.view2).setOnClickListener(imageChooseListener)
contentView.findViewById(R.id.view3).setOnClickListener(imageChooseListener)
- val attributes = bottomDialog.window.attributes
- attributes.width = WindowManager.LayoutParams.MATCH_PARENT
- attributes.height = WindowManager.LayoutParams.WRAP_CONTENT
- attributes.gravity = Gravity.BOTTOM
- bottomDialog.window.attributes = attributes
+ val attributes = bottomDialog?.window?.attributes
+ attributes?.width = WindowManager.LayoutParams.MATCH_PARENT
+ attributes?.height = WindowManager.LayoutParams.WRAP_CONTENT
+ attributes?.gravity = Gravity.BOTTOM
+ bottomDialog?.window?.attributes = attributes
}
-
/**
* 打开相机选择
*/
@@ -72,14 +65,12 @@ class PicPickHelper(activity: androidx.fragment.app.FragmentActivity) {
/**
* 打开相册
*/
-
fun fromLocal(size: Size?, callback: ImagePickCallback) {
photoRequestFragment.callback = callback
photoRequestFragment.size = size
fromLocal()
}
-
// 获取Fragment的方法
private fun getPhotoRequstFragment(activity: androidx.fragment.app.FragmentActivity): PhotoRequestFragment {
// 查询是否已经存在了该Fragment,这样是为了让该Fragment只有一个实例
@@ -105,59 +96,48 @@ class PicPickHelper(activity: androidx.fragment.app.FragmentActivity) {
return activity.fragmentManager.findFragmentByTag(TAG) as PhotoRequestFragment?
}
-
private fun fromCamera() {
activityWeakReference.get()?.let {
- rxPermissions.requestEachCombined(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.CAMERA)
- .subscribe{permission->
- if (permission.granted) {//全部同意后调用
- val mCameraFilePath = ImageChooseHelper.cameraFilePath
- photoRequestFragment.mCameraFilePath = mCameraFilePath
- photoRequestFragment.startActivityForResult(
- ImageChooseHelper.takePhotoIntent(
- it,
- mCameraFilePath!!
- ), REQUEST_CODE_CAMERA
- )
-
- } else if (permission.shouldShowRequestPermissionRationale) {//只要有一个选择:禁止,但没有选择“以后不再询问”,以后申请权限,会继续弹出提示
- photoRequestFragment.callback?.onPermissionNotGet(permission.name)
- } else {//只要有一个选择:禁止,但选择“以后不再询问”,以后申请权限,不会继续弹出提示
- photoRequestFragment.callback?.onPermissionNotGet(permission.name)
- }
+ HapiPermission.requestPermission(
+ it, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
+ ) { grantedPermissions, deniedPermissions, alwaysDeniedPermissions ->
+ if (grantedPermissions.size == 2) {
+ val mCameraFilePath = ImageChooseHelper.cameraFilePath
+ photoRequestFragment.mCameraFilePath = mCameraFilePath
+ photoRequestFragment.startActivityForResult(
+ ImageChooseHelper.takePhotoIntent(
+ it,
+ mCameraFilePath
+ ), REQUEST_CODE_CAMERA
+ )
+ } else {
+ photoRequestFragment.callback?.onPermissionNotGet(deniedPermissions.toString() + alwaysDeniedPermissions.toString())
}
+ }
}
}
-
private fun fromLocal() {
activityWeakReference.get()?.let {
- rxPermissions.requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE)
- .subscribe{
- permission->
- if (permission.granted) {//全部同意后调用
- photoRequestFragment.startActivityForResult(
- ImageChooseHelper.pickImageIntent(),
- REQUEST_CODE_CHOOSE_LOCAL
- )
-
- } else if (permission.shouldShowRequestPermissionRationale) {//只要有一个选择:禁止,但没有选择“以后不再询问”,以后申请权限,会继续弹出提示
- photoRequestFragment.callback?.onPermissionNotGet(permission.name)
- } else {//只要有一个选择:禁止,但选择“以后不再询问”,以后申请权限,不会继续弹出提示
- photoRequestFragment.callback?.onPermissionNotGet(permission.name)
- }
+ HapiPermission.requestPermission(
+ it, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ ) { grantedPermissions, deniedPermissions, alwaysDeniedPermissions ->
+ if (grantedPermissions.size == 1) {
+ photoRequestFragment.startActivityForResult(
+ ImageChooseHelper.pickImageIntent(),
+ REQUEST_CODE_CHOOSE_LOCAL
+ )
+ } else {
+ photoRequestFragment.callback?.onPermissionNotGet(deniedPermissions.toString() + alwaysDeniedPermissions.toString())
}
+ }
}
}
-
companion object {
val REQUEST_CODE_CHOOSE_LOCAL = RequestCodeCreator.generate()
val REQUEST_CODE_CAMERA = RequestCodeCreator.generate()
val REQUEST_CODE_CROP = RequestCodeCreator.generate()
-
-
-
val TAG = "PhotoRequestFragment"
}
}
diff --git a/hapimediapicker/src/main/java/com/hapi/mediapicker/VideoPickHelper.kt b/hapimediapicker/src/main/java/com/hapi/mediapicker/VideoPickHelper.kt
index 557ea6c..796e645 100644
--- a/hapimediapicker/src/main/java/com/hapi/mediapicker/VideoPickHelper.kt
+++ b/hapimediapicker/src/main/java/com/hapi/mediapicker/VideoPickHelper.kt
@@ -3,31 +3,25 @@ package com.hapi.mediapicker
import android.Manifest
import android.app.Dialog
import android.content.Intent
-import android.provider.MediaStore
-import androidx.fragment.app.FragmentActivity
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.TextView
-import com.hapi.ut.OsInfoUtil
-import com.tbruyelle.rxpermissions2.RxPermissions
+import androidx.appcompat.app.AppCompatActivity
+import com.hapi.permission.HapiPermission
import java.lang.ref.WeakReference
-/**
- *
- * @date 2018/12/14
- */
-class VideoPickHelper constructor(activity: androidx.fragment.app.FragmentActivity) {
+class VideoPickHelper constructor(activity: AppCompatActivity) {
+
+ private var host = WeakReference(activity)
- private var host = WeakReference(activity)
- private val rxPermissions by lazy { RxPermissions(activity) }
private val videoRequestFragment by lazy { getPhotoRequstFragment(activity) }
fun show(callback: VideoPickCallBack) {
videoRequestFragment.callback = callback
- val bottomDialog = Dialog(host.get(), R.style.BottomViewWhiteMask)
+ val bottomDialog = Dialog(host.get()!!, R.style.BottomViewWhiteMask)
val contentView = LayoutInflater.from(host.get()).inflate(R.layout.dialog_choose_pic, null)
bottomDialog.setCancelable(true)
bottomDialog.setCanceledOnTouchOutside(true)
@@ -50,11 +44,11 @@ class VideoPickHelper constructor(activity: androidx.fragment.app.FragmentActivi
contentView.findViewById(R.id.view2).setOnClickListener(imageChooseListener)
contentView.findViewById(R.id.view3).setOnClickListener(imageChooseListener)
- val attributes = bottomDialog.window.attributes
- attributes.width = WindowManager.LayoutParams.MATCH_PARENT
- attributes.height = WindowManager.LayoutParams.WRAP_CONTENT
- attributes.gravity = Gravity.BOTTOM
- bottomDialog.window.attributes = attributes
+ val attributes = bottomDialog.window?.attributes
+ attributes?.width = WindowManager.LayoutParams.MATCH_PARENT
+ attributes?.height = WindowManager.LayoutParams.WRAP_CONTENT
+ attributes?.gravity = Gravity.BOTTOM
+ bottomDialog.window?.attributes = attributes
}
@@ -90,17 +84,15 @@ class VideoPickHelper constructor(activity: androidx.fragment.app.FragmentActivi
}
private fun fromCamera() {
host.get()?.let {
- rxPermissions.requestEachCombined(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.CAMERA)
- .subscribe{permission->
- if (permission.granted) {//全部同意后调用
- val intent = ImageChooseHelper.videoIntent(it)
- videoRequestFragment.startActivityForResult(intent, REQUEST_CODE_CAMERA)
- } else if (permission.shouldShowRequestPermissionRationale) {//只要有一个选择:禁止,但没有选择“以后不再询问”,以后申请权限,会继续弹出提示
- videoRequestFragment.callback?.onPermissionNotGet(permission.name)
- } else {//只要有一个选择:禁止,但选择“以后不再询问”,以后申请权限,不会继续弹出提示
- videoRequestFragment.callback?.onPermissionNotGet(permission.name)
- }
+ HapiPermission.requestPermission(it,arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)){
+ grantedPermissions, deniedPermissions, alwaysDeniedPermissions ->
+ if (grantedPermissions.size == 2) {
+ val intent = ImageChooseHelper.videoIntent(it)
+ videoRequestFragment.startActivityForResult(intent, REQUEST_CODE_CAMERA)
+ } else {
+ videoRequestFragment.callback?.onPermissionNotGet(deniedPermissions.toString() + alwaysDeniedPermissions.toString())
}
+ }
}
}
@@ -111,30 +103,23 @@ class VideoPickHelper constructor(activity: androidx.fragment.app.FragmentActivi
private fun fromLocal() {
host.get()?.let {
- rxPermissions.requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE)
- .subscribe{
- permission->
- if (permission.granted) {//全部同意后调用
- val intent =
- Intent(Intent.ACTION_GET_CONTENT)
- intent.type = "video/*" //String VIDEO_UNSPECIFIED = "video/*";
-
- val wrapperIntent =
- Intent.createChooser(intent, null)
-
- videoRequestFragment.startActivityForResult(wrapperIntent, REQUEST_CODE_PICK)
-
- } else if (permission.shouldShowRequestPermissionRationale) {//只要有一个选择:禁止,但没有选择“以后不再询问”,以后申请权限,会继续弹出提示
- videoRequestFragment.callback?.onPermissionNotGet(permission.name)
- } else {//只要有一个选择:禁止,但选择“以后不再询问”,以后申请权限,不会继续弹出提示
- videoRequestFragment.callback?.onPermissionNotGet(permission.name)
- }
+ HapiPermission.requestPermission(it,arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)){
+ grantedPermissions, deniedPermissions, alwaysDeniedPermissions ->
+ if (grantedPermissions.size == 1) {
+ val intent =
+ Intent(Intent.ACTION_GET_CONTENT)
+ intent.type = "video/*" //String VIDEO_UNSPECIFIED = "video/*";
+ val wrapperIntent =
+ Intent.createChooser(intent, null)
+ videoRequestFragment.startActivityForResult(wrapperIntent, REQUEST_CODE_PICK)
+
+ } else {
+ videoRequestFragment.callback?.onPermissionNotGet(deniedPermissions.toString() + alwaysDeniedPermissions.toString())
}
+ }
}
}
-
-
companion object {
private val TAG = "VideoPickHelper"
val REQUEST_CODE_PICK = RequestCodeCreator.generate()
diff --git a/hapimediapicker/src/main/java/com/hapi/mediapicker/VideoRequestFragment.kt b/hapimediapicker/src/main/java/com/hapi/mediapicker/VideoRequestFragment.kt
index 9baaa2f..6eb481f 100644
--- a/hapimediapicker/src/main/java/com/hapi/mediapicker/VideoRequestFragment.kt
+++ b/hapimediapicker/src/main/java/com/hapi/mediapicker/VideoRequestFragment.kt
@@ -11,87 +11,75 @@ import android.text.TextUtils
import com.hapi.ut.BitmapUtils
import com.hapi.ut.FileUtil
import com.hapi.ut.constans.FileConstants
-
-import io.reactivex.Observable
-import io.reactivex.android.schedulers.AndroidSchedulers
-import io.reactivex.functions.Function
-import io.reactivex.schedulers.Schedulers
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.async
+import kotlinx.coroutines.launch
import java.io.File
class VideoRequestFragment : androidx.fragment.app.Fragment() {
-
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.retainInstance = true
}
-
- var callback : VideoPickCallBack?=null
-
+ var callback: VideoPickCallBack? = null
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK && data != null) {//从相册选取视频
- activity?.let {
- Observable.just(data.data)
- .map(object : Function {
- override fun apply(t: Uri): MediaParams {
- var path = ContentUriUtil.getDataFromUri(it, t, ContentUriUtil.ContentType.video)
- var params = getVideoParams(path)
- if (params != null) {
- return params
- }
- throw Exception("获取视频资源失败")
- }
- })
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe({
- callback?.onSuccess(it)
- }, {
-
- })
+ activity?.let {
+ GlobalScope.launch(Dispatchers.Main) {
+ val ret = async(Dispatchers.IO) {
+ val path = ContentUriUtil.getDataFromUri(
+ it,
+ data.data!!,
+ ContentUriUtil.ContentType.video
+ )
+ getVideoParams(path)
+ }
+ val p = ret.await()
+ callback?.onSuccess(p ?: MediaParams())
+ }
}
}
}
@WorkerThread
fun getVideoParams(videoPath: String?): MediaParams? {
- if(FileConstants.CACHE_VIDEO_DIR ==null){
+ if (FileConstants.CACHE_VIDEO_DIR == null) {
activity?.application?.let { FileConstants.initFileConfig(it) }
}
if (TextUtils.isEmpty(videoPath)) {
return null
}
- var media = MediaMetadataRetriever()
+ val media = MediaMetadataRetriever()
try {
var path = videoPath
- val file = File(path)
+ val file = path?.let { File(it) }
media.setDataSource(path)
//取得指定时间(第6us)的Bitmap,即可以实现抓图(缩略图)功能
val thumb = media.getFrameAtTime(3)
val thumPath = FileConstants.CACHE_VIDEO_DIR + System.currentTimeMillis() + ".jpeg"
BitmapUtils.saveBitmap2JPG(thumb, thumPath)
- val video_length = media.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION).toLong()
+ val video_length =
+ media.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)?.toLong()?:0L
val size = FileUtil.getFileSize(file)
val mimeType = media.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE)
//如果不包含文件后缀就复制一份有后缀的文件
- if (!file.name.contains(".")) {
- var suffix = mimeType.substring(mimeType.lastIndexOf("/") + 1)
- path = FileConstants.CACHE_VIDEO_DIR + file.name + "." + suffix
- var newFile = FileUtil.createFile(path)
+ if ((file?.name?.contains(".")) != true) {
+ val suffix = mimeType?.substring(mimeType?.lastIndexOf("/") + 1)
+ path = FileConstants.CACHE_VIDEO_DIR + file?.name + "." + suffix
+ val newFile = FileUtil.createFile(path)
newFile?.let {
- file.copyTo(it, true)
+ file?.copyTo(it, true)
}
}
return MediaParams(path, thumPath, size, video_length, mimeType)
} catch (e: Exception) {
e.printStackTrace()
} finally {
- media?.let {
- it.release()
- }
+ media.release()
}
return null
}
diff --git a/hapimediapicker/src/main/java/com/hapi/permission/FragmentAttachCallback.java b/hapimediapicker/src/main/java/com/hapi/permission/FragmentAttachCallback.java
new file mode 100644
index 0000000..96d9d1e
--- /dev/null
+++ b/hapimediapicker/src/main/java/com/hapi/permission/FragmentAttachCallback.java
@@ -0,0 +1,6 @@
+package com.hapi.permission;
+
+
+public interface FragmentAttachCallback {
+ void onAttach();
+}
diff --git a/hapimediapicker/src/main/java/com/hapi/permission/HapiPermission.kt b/hapimediapicker/src/main/java/com/hapi/permission/HapiPermission.kt
new file mode 100644
index 0000000..196fb7a
--- /dev/null
+++ b/hapimediapicker/src/main/java/com/hapi/permission/HapiPermission.kt
@@ -0,0 +1,44 @@
+package com.hapi.permission;
+
+import android.content.pm.PackageManager
+import android.os.Build
+import androidx.appcompat.app.AppCompatActivity
+
+object HapiPermission {
+ @JvmField
+ var permissionFragment: PermissionFragment? = null
+ fun requestPermission(
+ context: AppCompatActivity,
+ permissions: Array,
+ permissionCallback: PermissionCallback?
+ ) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ var isAllGet = true
+ for (p in permissions) {
+ if (PackageManager.PERMISSION_GRANTED != context.checkSelfPermission(
+ p
+ )
+ ) {
+ isAllGet = false
+ }
+ }
+ if (isAllGet) {
+ permissionCallback?.onComplete(permissions.toList(), ArrayList(), ArrayList());
+ return
+ }
+ if (permissionFragment == null) {
+ permissionFragment = PermissionFragment()
+ }
+ permissionFragment!!.setOnAttachCallback {
+ permissionFragment!!.requestPermission(
+ permissions
+ )
+ }
+ permissionFragment!!.setOnPermissionCallback(permissionCallback)
+ val fragmentTransaction = context.supportFragmentManager.beginTransaction()
+ fragmentTransaction.add(permissionFragment!!, "permissionFragment@777").commit()
+ } else {
+ permissionCallback?.onComplete(permissions.toList(), ArrayList(), ArrayList());
+ }
+ }
+}
\ No newline at end of file
diff --git a/hapimediapicker/src/main/java/com/hapi/permission/PermissionCallback.java b/hapimediapicker/src/main/java/com/hapi/permission/PermissionCallback.java
new file mode 100644
index 0000000..0f4dddb
--- /dev/null
+++ b/hapimediapicker/src/main/java/com/hapi/permission/PermissionCallback.java
@@ -0,0 +1,8 @@
+package com.hapi.permission;
+
+import java.util.List;
+
+
+public interface PermissionCallback {
+ void onComplete(List grantedPermissions, List deniedPermissions, List alwaysDeniedPermissions);
+}
diff --git a/hapimediapicker/src/main/java/com/hapi/permission/PermissionFragment.java b/hapimediapicker/src/main/java/com/hapi/permission/PermissionFragment.java
new file mode 100644
index 0000000..3db58d8
--- /dev/null
+++ b/hapimediapicker/src/main/java/com/hapi/permission/PermissionFragment.java
@@ -0,0 +1,89 @@
+package com.hapi.permission;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.core.app.ActivityCompat;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+import java.util.ArrayList;
+
+public class PermissionFragment extends Fragment {
+
+ private static final int PERMISSION_REQUEST_CODE = 777;
+
+ private FragmentAttachCallback fragmentAttachCallback;
+ private PermissionCallback permissionCallback;
+
+ @Nullable
+ @Override
+ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ if (this.getActivity() == null) {
+ return;
+ }
+ ArrayList grantList = new ArrayList<>();
+ ArrayList deniedList = new ArrayList<>();
+ ArrayList alwaysDeniedList = new ArrayList<>();
+ if (requestCode == PERMISSION_REQUEST_CODE) {
+ for (int i = 0; i < permissions.length; i++) {
+ if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
+ //获得权限
+ grantList.add(permissions[i]);
+ } else {
+ //点了'不再询问'的权限
+ boolean alwaysDenied = !ActivityCompat.shouldShowRequestPermissionRationale(this.getActivity(), permissions[i]);
+ if (alwaysDenied) {
+ alwaysDeniedList.add(permissions[i]);
+ } else {
+ //拒绝的权限
+ deniedList.add(permissions[i]);
+ }
+ }
+ }
+ permissionCallback.onComplete(grantList, deniedList, alwaysDeniedList);
+ removeFragment();
+ }
+ }
+
+ private void removeFragment() {
+ FragmentManager fragmentManager = getFragmentManager();
+ if (fragmentManager != null) {
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+ fragmentTransaction.remove(this).commit();
+ }
+ permissionCallback = null;
+ HapiPermission.permissionFragment = null;
+ }
+
+ void requestPermission(String[] permissions) {
+ requestPermissions(permissions, PERMISSION_REQUEST_CODE);
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ if (fragmentAttachCallback != null) {
+ fragmentAttachCallback.onAttach();
+ }
+ }
+
+ void setOnAttachCallback(FragmentAttachCallback fragmentAttachCallback) {
+ this.fragmentAttachCallback = fragmentAttachCallback;
+ }
+
+ void setOnPermissionCallback(PermissionCallback permissionCallback) {
+ this.permissionCallback = permissionCallback;
+ }
+}
diff --git a/lib_sreenshot/build.gradle b/lib_sreenshot/build.gradle
index 1d37387..f5ddcfe 100644
--- a/lib_sreenshot/build.gradle
+++ b/lib_sreenshot/build.gradle
@@ -1,17 +1,11 @@
apply plugin: 'com.android.library'
-apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
-apply plugin: 'hapidepend'
-
-apply plugin: 'com.github.dcendents.android-maven'
-group='com.github.MJLblabla'
-
android {
- compileSdkVersion depend.compileSdkVersion
+ compileSdkVersion 33
defaultConfig {
minSdkVersion 15
- targetSdkVersion depend.targetSdkVersion
+ targetSdkVersion 33
versionCode 1
versionName "1.0"
@@ -29,8 +23,7 @@ android {
dependencies {
- implementation 'androidx.appcompat:appcompat:1.3.1'
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+ implementation 'androidx.appcompat:appcompat:1.5.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
diff --git a/lib_sreenshot/src/main/res/drawable-v24/ic_launcher_foreground.xml b/lib_sreenshot/src/main/res/drawable-v24/ic_launcher_foreground.xml
deleted file mode 100644
index 2b068d1..0000000
--- a/lib_sreenshot/src/main/res/drawable-v24/ic_launcher_foreground.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib_sreenshot/src/main/res/drawable/ic_launcher_background.xml b/lib_sreenshot/src/main/res/drawable/ic_launcher_background.xml
deleted file mode 100644
index 07d5da9..0000000
--- a/lib_sreenshot/src/main/res/drawable/ic_launcher_background.xml
+++ /dev/null
@@ -1,170 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lib_sreenshot/src/main/res/layout/activity_main.xml b/lib_sreenshot/src/main/res/layout/activity_main.xml
deleted file mode 100644
index 4fc2444..0000000
--- a/lib_sreenshot/src/main/res/layout/activity_main.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib_sreenshot/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/lib_sreenshot/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
deleted file mode 100644
index eca70cf..0000000
--- a/lib_sreenshot/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/lib_sreenshot/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/lib_sreenshot/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
deleted file mode 100644
index eca70cf..0000000
--- a/lib_sreenshot/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/lib_sreenshot/src/main/res/mipmap-hdpi/ic_launcher.webp b/lib_sreenshot/src/main/res/mipmap-hdpi/ic_launcher.webp
deleted file mode 100644
index c209e78..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-hdpi/ic_launcher.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/lib_sreenshot/src/main/res/mipmap-hdpi/ic_launcher_round.webp
deleted file mode 100644
index b2dfe3d..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-hdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/mipmap-mdpi/ic_launcher.webp b/lib_sreenshot/src/main/res/mipmap-mdpi/ic_launcher.webp
deleted file mode 100644
index 4f0f1d6..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-mdpi/ic_launcher.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/lib_sreenshot/src/main/res/mipmap-mdpi/ic_launcher_round.webp
deleted file mode 100644
index 62b611d..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-mdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/mipmap-xhdpi/ic_launcher.webp b/lib_sreenshot/src/main/res/mipmap-xhdpi/ic_launcher.webp
deleted file mode 100644
index 948a307..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-xhdpi/ic_launcher.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/lib_sreenshot/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
deleted file mode 100644
index 1b9a695..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-xhdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/lib_sreenshot/src/main/res/mipmap-xxhdpi/ic_launcher.webp
deleted file mode 100644
index 28d4b77..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-xxhdpi/ic_launcher.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/lib_sreenshot/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
deleted file mode 100644
index 9287f50..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/lib_sreenshot/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
deleted file mode 100644
index aa7d642..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-xxxhdpi/ic_launcher.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/lib_sreenshot/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
deleted file mode 100644
index 9126ae3..0000000
Binary files a/lib_sreenshot/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/lib_sreenshot/src/main/res/values-night/themes.xml b/lib_sreenshot/src/main/res/values-night/themes.xml
deleted file mode 100644
index 5eb5fed..0000000
--- a/lib_sreenshot/src/main/res/values-night/themes.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/lib_sreenshot/src/main/res/values/colors.xml b/lib_sreenshot/src/main/res/values/colors.xml
deleted file mode 100644
index f8c6127..0000000
--- a/lib_sreenshot/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- #FFBB86FC
- #FF6200EE
- #FF3700B3
- #FF03DAC5
- #FF018786
- #FF000000
- #FFFFFFFF
-
\ No newline at end of file
diff --git a/lib_sreenshot/src/main/res/values/strings.xml b/lib_sreenshot/src/main/res/values/strings.xml
deleted file mode 100644
index bd83525..0000000
--- a/lib_sreenshot/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
- lib_sreenshot
-
\ No newline at end of file
diff --git a/lib_sreenshot/src/main/res/values/themes.xml b/lib_sreenshot/src/main/res/values/themes.xml
deleted file mode 100644
index 43c2c91..0000000
--- a/lib_sreenshot/src/main/res/values/themes.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
\ No newline at end of file