Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
flutter_plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林生雨
flutter_plugin
Commits
592bc5ed
Commit
592bc5ed
authored
Oct 28, 2019
by
林生雨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
3636de24
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
350 additions
and
76 deletions
+350
-76
workspace.xml
.idea/workspace.xml
+0
-0
GengmeiFlutterPlugin.kt
...om/example/gengmei_flutter_plugin/GengmeiFlutterPlugin.kt
+17
-4
ImageRespository.kt
...flutter_plugin/ImagePlugin/repository/ImageRespository.kt
+0
-0
MediaFile.kt
...i_flutter_plugin/ImagePlugin/repository/bean/MediaFile.kt
+4
-1
ImageScanner.kt
...utter_plugin/ImagePlugin/repository/local/ImageScanner.kt
+42
-30
Thumb.kt
...gmei_flutter_plugin/ImagePlugin/repository/local/Thumb.kt
+13
-0
ThumbUtil.java
...lutter_plugin/ImagePlugin/repository/local/ThumbUtil.java
+165
-0
VideoScanner.kt
...utter_plugin/ImagePlugin/repository/local/VideoScanner.kt
+45
-28
FileUtil.java
...va/com/example/gengmei_flutter_plugin/utils/FileUtil.java
+7
-4
MyUtil.kt
...n/java/com/example/gengmei_flutter_plugin/utils/MyUtil.kt
+50
-0
AlbumModel.dart
example/lib/AlbumModel/page/album/AlbumModel.dart
+2
-6
AlbumPage.dart
example/lib/AlbumModel/page/album/AlbumPage.dart
+4
-3
gengmei_flutter_plugin.iml
gengmei_flutter_plugin.iml
+1
-0
No files found.
.idea/workspace.xml
View file @
592bc5ed
This diff is collapsed.
Click to expand it.
android/src/main/java/com/example/gengmei_flutter_plugin/GengmeiFlutterPlugin.kt
View file @
592bc5ed
...
...
@@ -227,6 +227,7 @@ class GengmeiFlutterPlugin : MethodCallHandler {
}).
addTo
(
disposable
)
}
QUIT_PAGE
->
{
disposable
.
clear
()
disposable
.
dispose
()
disposable
=
CompositeDisposable
()
quit_page
=
true
;
...
...
@@ -297,10 +298,22 @@ class GengmeiFlutterPlugin : MethodCallHandler {
}
resign
.
addRequestPermissionsResultListener
{
id
,
permissions
,
grantResults
->
if
(
grantResults
.
size
>
0
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
&&
grantResults
[
1
]
==
PackageManager
.
PERMISSION_GRANTED
&&
grantResults
[
2
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
listener
.
OK
();
if
(
grantResults
.
size
>
0
)
{
var
givePremission
=
true
;
grantResults
.
forEach
{
if
(
it
!=
PackageManager
.
PERMISSION_GRANTED
)
{
givePremission
=
false
;
}
}
if
(
givePremission
)
{
listener
.
OK
()
}
else
{
Toast
.
makeText
(
activity
.
applicationContext
,
"请同意权限"
,
Toast
.
LENGTH_SHORT
).
show
()
result
?.
run
{
this
.
error
(
"没有权限!!"
,
"no premission"
,
"没有权限!!"
);
}
}
}
else
{
Toast
.
makeText
(
activity
.
applicationContext
,
"请同意权限"
,
Toast
.
LENGTH_SHORT
).
show
()
result
?.
run
{
...
...
android/src/main/java/com/example/gengmei_flutter_plugin/ImagePlugin/repository/ImageRespository.kt
View file @
592bc5ed
This diff is collapsed.
Click to expand it.
android/src/main/java/com/example/gengmei_flutter_plugin/ImagePlugin/repository/bean/MediaFile.kt
View file @
592bc5ed
...
...
@@ -6,6 +6,7 @@ package com.example.myimagepicker.bean
*/
data class
MediaFile
(
var
id
:
Int
?
=
0
,
var
path
:
String
?
=
null
,
var
mime
:
String
?
=
null
,
var
folderId
:
Int
?
=
null
,
...
...
@@ -16,5 +17,7 @@ data class MediaFile(
var
isBigIm
:
Boolean
=
false
,
var
bigScare
:
Float
=
0f
,
var
realPath
:
String
?
=
null
,
var
isVideo
:
Boolean
?
=
null
var
isVideo
:
Boolean
?
=
null
,
var
width
:
Int
?
=
0
,
var
height
:
Int
?
=
0
)
android/src/main/java/com/example/gengmei_flutter_plugin/ImagePlugin/repository/local/ImageScanner.kt
View file @
592bc5ed
...
...
@@ -24,7 +24,13 @@ class ImageScanner(var context: Context) : AbsMediaScanner<MediaFile>(context) {
override
val
projection
:
Array
<
String
>
get
()
=
arrayOf
(
MediaStore
.
Images
.
Media
.
DATA
,
MediaStore
.
Images
.
Media
.
MIME_TYPE
,
MediaStore
.
Images
.
Media
.
BUCKET_ID
,
MediaStore
.
Images
.
Media
.
BUCKET_DISPLAY_NAME
,
MediaStore
.
Images
.
Media
.
DATE_TAKEN
,
MediaStore
.
Images
.
Media
.
SIZE
)
arrayOf
(
MediaStore
.
Images
.
Media
.
DATA
,
// MediaStore.Images.Media.MIME_TYPE,
// MediaStore.Images.Media.BUCKET_ID,
MediaStore
.
Images
.
Media
.
BUCKET_DISPLAY_NAME
,
MediaStore
.
Images
.
Media
.
DATE_TAKEN
,
MediaStore
.
Images
.
Media
.
SIZE
,
MediaStore
.
Audio
.
Media
.
_ID
)
override
val
selection
:
String
get
()
=
...
...
@@ -46,41 +52,47 @@ class ImageScanner(var context: Context) : AbsMediaScanner<MediaFile>(context) {
* @return
*/
override
fun
parse
(
cursor
:
Cursor
):
MediaFile
{
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Images
.
Media
.
DATA
))
val
mime
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Images
.
Media
.
MIME_TYPE
))
val
folderId
=
cursor
.
getInt
(
cursor
.
getColumnIndex
(
MediaStore
.
Images
.
Media
.
BUCKET_ID
))
val
folderName
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Images
.
Media
.
BUCKET_DISPLAY_NAME
))
val
dateToken
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
MediaStore
.
Images
.
Media
.
DATE_TAKEN
))
val
size
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
MediaStore
.
Images
.
Media
.
SIZE
))
val
mediaFile
=
MediaFile
()
// val path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA))
// val mime = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE))
// val folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID))
// val folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME))
// val dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN))
// val size = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.SIZE))
mediaFile
.
mime
=
mime
mediaFile
.
folderId
=
folderId
val
path
=
cursor
.
getString
(
0
)
val
folderName
=
cursor
.
getString
(
1
)
val
dateToken
=
cursor
.
getLong
(
2
)
val
size
=
cursor
.
getLong
(
3
)
val
id
=
cursor
.
getInt
(
4
);
val
mediaFile
=
MediaFile
()
mediaFile
.
id
=
id
// mediaFile.mime = mime
// mediaFile.folderId = folderId
mediaFile
.
folderName
=
folderName
mediaFile
.
dateToken
=
dateToken
mediaFile
.
size
=
size
mediaFile
.
realPath
=
path
mediaFile
.
isVideo
=
false
val
dir
=
Environment
.
getExternalStorageDirectory
().
absolutePath
+
"/GMAlbum/.album"
;
// val dir = getImageCacheDir(context, Luban.DEFAULT_DISK_CACHE_DIR)!!.absolutePath;
val
tempFilePngString
=
dir
+
"/"
+
getFileName
(
path
)
!!
+
".png"
;
val
tempFilePngExists
=
File
(
tempFilePngString
).
exists
()
if
(
tempFilePngExists
)
{
mediaFile
.
path
=
tempFilePngString
;
}
val
tempFileJpgString
=
dir
+
"/"
+
getFileName
(
path
)
!!
+
".jpg"
;
val
tempFileJpgExists
=
File
(
tempFileJpgString
).
exists
()
if
(
tempFileJpgExists
)
{
mediaFile
.
path
=
tempFileJpgString
;
}
val
tempFileJpegString
=
dir
+
"/"
+
getFileName
(
path
)
!!
+
".jpeg"
val
tempFileJpegExists
=
File
(
tempFileJpegString
).
exists
()
if
(
tempFileJpegExists
)
{
mediaFile
.
path
=
tempFileJpegString
;
}
if
(
size
<
1024
*
160
)
{
mediaFile
.
path
=
path
}
//
val dir = Environment.getExternalStorageDirectory().absolutePath + "/GMAlbum/.album";
//
//
val dir = getImageCacheDir(context, Luban.DEFAULT_DISK_CACHE_DIR)!!.absolutePath;
//
val tempFilePngString = dir + "/" + getFileName(path)!! + ".png";
//
val tempFilePngExists = File(tempFilePngString).exists()
//
if (tempFilePngExists) {
//
mediaFile.path = tempFilePngString;
//
}
//
val tempFileJpgString = dir + "/" + getFileName(path)!! + ".jpg";
//
val tempFileJpgExists = File(tempFileJpgString).exists()
//
if (tempFileJpgExists) {
//
mediaFile.path = tempFileJpgString;
//
}
//
val tempFileJpegString = dir + "/" + getFileName(path)!! + ".jpeg"
//
val tempFileJpegExists = File(tempFileJpegString).exists()
//
if (tempFileJpegExists) {
//
mediaFile.path = tempFileJpegString;
//
}
//
if (size < 1024 * 160) {
//
mediaFile.path = path
//
}
//
// if (it.size > 1024 * 1024 && !tempFilePngExists
// && !tempFileJpgExists && !tempFileJpegExists) {
...
...
android/src/main/java/com/example/gengmei_flutter_plugin/ImagePlugin/repository/local/Thumb.kt
0 → 100644
View file @
592bc5ed
package
com.example.gengmei_flutter_plugin.ImagePlugin.repository.local
/**
* @author lsy
* @date 2019-10-27
*/
class
Thumb
{
companion
object
{
}
}
\ No newline at end of file
android/src/main/java/com/example/gengmei_flutter_plugin/ImagePlugin/repository/local/ThumbUtil.java
0 → 100644
View file @
592bc5ed
package
com
.
example
.
gengmei_flutter_plugin
.
ImagePlugin
.
repository
.
local
;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.provider.MediaStore
;
import
android.util.Log
;
import
com.example.myimagepicker.bean.MediaFile
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
/**
* @author lsy
* @date 2019-10-27
*/
public
class
ThumbUtil
{
public
static
ArrayList
<
MediaFile
>
getAllPictures
(
Context
context
)
{
long
st
=
System
.
currentTimeMillis
();
ArrayList
<
MediaFile
>
scanList
=
new
ArrayList
<>();
ContentResolver
cr
=
context
.
getContentResolver
();
Cursor
cursor
=
cr
.
query
(
MediaStore
.
Images
.
Thumbnails
.
EXTERNAL_CONTENT_URI
,
new
String
[]{
MediaStore
.
Images
.
Thumbnails
.
IMAGE_ID
,
MediaStore
.
Images
.
Thumbnails
.
DATA
,
MediaStore
.
Images
.
Thumbnails
.
WIDTH
,
MediaStore
.
Images
.
Thumbnails
.
HEIGHT
,
},
null
,
null
,
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
do
{
MediaFile
mediaFile
=
new
MediaFile
();
mediaFile
.
setId
(
cursor
.
getInt
(
0
));
mediaFile
.
setPath
(
cursor
.
getString
(
1
));
mediaFile
.
setWidth
(
cursor
.
getInt
(
2
));
mediaFile
.
setHeight
(
cursor
.
getInt
(
3
));
mediaFile
.
setVideo
(
false
);
scanList
.
add
(
mediaFile
);
}
while
(
cursor
.
moveToNext
());
cursor
.
close
();
}
Log
.
e
(
"lsy"
,
" T1122 !! "
+
(
System
.
currentTimeMillis
()
-
st
));
return
scanList
;
}
// public static ArrayList<MediaFile> getAllRealImages(Context context){
// ArrayList<MediaFile> scanList = new ArrayList<>();
// ContentResolver cr = context.getContentResolver();
// Cursor cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
// new String[]{
// MediaStore.Images.Media.DATA,
// MediaStore.Images.Media.MIME_TYPE,
// MediaStore.Images.Media.BUCKET_ID,
// MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
// MediaStore.Images.Media.DATE_TAKEN,
// MediaStore.Images.Media.SIZE,
// MediaStore.Audio.Media._ID
//
// },
// MediaStore.Audio.Media._ID + "=" + file.getId(),
// null,
// MediaStore.Images.Media.DATE_TAKEN +
// " DESC"
// );
//
//
// for (int i = 0; i < scanList.size(); i++) {
// MediaFile file = scanList.get(i);
//
// if (cursor.moveToFirst()) {
// do {
// String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
// String mime = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE));
// int folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID));
// String folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME));
// long dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN));
// long size = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.SIZE));
// long aLong = cursor.getLong(6);
// Log.e("lsy", " LONGGG " + aLong);
// file.setRealPath(path);
// file.setMime(mime);
// file.setFolderId(folderId);
// file.setFolderName(folderName);
// file.setDateToken(dateToken);
// file.setSize(size);
// scanList.set(i, file);
// } while (cursor.moveToNext());
// cursor.close();
// }
// }
// return scanList;
// }
public
static
ArrayList
<
MediaFile
>
getAllVideos
(
Context
context
)
{
ArrayList
<
MediaFile
>
scanList
=
new
ArrayList
<>();
ContentResolver
cr
=
context
.
getContentResolver
();
Cursor
cursor
=
cr
.
query
(
MediaStore
.
Video
.
Thumbnails
.
EXTERNAL_CONTENT_URI
,
new
String
[]{
MediaStore
.
Video
.
Thumbnails
.
VIDEO_ID
,
MediaStore
.
Video
.
Thumbnails
.
DATA
,
MediaStore
.
Video
.
Thumbnails
.
WIDTH
,
MediaStore
.
Video
.
Thumbnails
.
HEIGHT
,
},
null
,
null
,
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
do
{
MediaFile
mediaFile
=
new
MediaFile
();
mediaFile
.
setId
(
cursor
.
getInt
(
0
));
mediaFile
.
setPath
(
cursor
.
getString
(
1
));
mediaFile
.
setWidth
(
cursor
.
getInt
(
2
));
mediaFile
.
setHeight
(
cursor
.
getInt
(
3
));
scanList
.
add
(
mediaFile
);
}
while
(
cursor
.
moveToNext
());
cursor
.
close
();
}
// for (int i = 0; i < scanList.size(); i++) {
// MediaFile file = scanList.get(i);
// cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
// new String[]{
// MediaStore.Video.Media.DATA,
// MediaStore.Video.Media.MIME_TYPE,
// MediaStore.Video.Media.BUCKET_ID,
// MediaStore.Video.Media.BUCKET_DISPLAY_NAME,
// MediaStore.Video.Media.DURATION,
// MediaStore.Video.Media.DATE_TAKEN,
// MediaStore.Images.Media.SIZE
// },
// MediaStore.Audio.Media._ID + "=" + file.getId(),
// null,
// MediaStore.Images.Media.DATE_TAKEN +
// " DESC"
// );
// if (cursor.moveToFirst()) {
// do {
// String path = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA));
// String mime = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE));
// int folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_ID));
// String folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME));
// long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DURATION));
// long dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN));
// file.setRealPath(path);
// file.setMime(mime);
// file.setFolderId(folderId);
// file.setFolderName(folderName);
// file.setDateToken(dateToken);
// file.setDuration(duration);
// scanList.set(i, file);
// } while (cursor.moveToNext());
// cursor.close();
// }
// }
return
scanList
;
}
}
android/src/main/java/com/example/gengmei_flutter_plugin/ImagePlugin/repository/local/VideoScanner.kt
View file @
592bc5ed
...
...
@@ -5,6 +5,7 @@ import android.database.Cursor
import
android.net.Uri
import
android.os.Environment
import
android.provider.MediaStore
import
android.util.Log
import
com.example.gengmei_flutter_plugin.utils.MyUtil
import
com.example.myimagepicker.bean.MediaFile
import
java.io.File
...
...
@@ -22,14 +23,21 @@ class VideoScanner(private val mContext: Context) : AbsMediaScanner<MediaFile>(m
override
val
projection
:
Array
<
String
>
get
()
=
arrayOf
(
MediaStore
.
Video
.
Media
.
DATA
,
MediaStore
.
Video
.
Media
.
MIME_TYPE
,
MediaStore
.
Video
.
Media
.
BUCKET_ID
,
MediaStore
.
Video
.
Media
.
BUCKET_DISPLAY_NAME
,
MediaStore
.
Video
.
Media
.
DURATION
,
MediaStore
.
Video
.
Media
.
DATE_TAKEN
,
MediaStore
.
Images
.
Media
.
SIZE
arrayOf
(
MediaStore
.
Video
.
Media
.
DATA
,
// MediaStore.Video.Media.MIME_TYPE,
// MediaStore.Video.Media.BUCKET_ID,
MediaStore
.
Video
.
Media
.
BUCKET_DISPLAY_NAME
,
MediaStore
.
Video
.
Media
.
DURATION
,
MediaStore
.
Video
.
Media
.
DATE_TAKEN
,
MediaStore
.
Images
.
Media
.
SIZE
,
MediaStore
.
Audio
.
Media
.
_ID
)
override
val
order
:
String
get
()
=
MediaStore
.
Video
.
Media
.
DATE_TAKEN
+
" desc"
override
val
selectionArgs
:
Array
<
String
>?
// get() = null
// get() = null
get
()
=
arrayOf
(
"video/mp4"
,
"video/avi"
)
override
val
selection
:
String
...
...
@@ -45,38 +53,47 @@ class VideoScanner(private val mContext: Context) : AbsMediaScanner<MediaFile>(m
*/
protected
override
fun
parse
(
cursor
:
Cursor
):
MediaFile
{
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Video
.
Media
.
DATA
))
val
mime
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Video
.
Media
.
MIME_TYPE
))
val
folderId
=
cursor
.
getInt
(
cursor
.
getColumnIndex
(
MediaStore
.
Video
.
Media
.
BUCKET_ID
))
val
folderName
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
Video
.
Media
.
BUCKET_DISPLAY_NAME
))
val
duration
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
MediaStore
.
Video
.
Media
.
DURATION
))
val
dateToken
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
MediaStore
.
Video
.
Media
.
DATE_TAKEN
))
// val path = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA))
// val mime = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE))
// val folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_ID))
// val folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME))
// val duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DURATION))
// val dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN))
val
path
=
cursor
.
getString
(
0
)
val
folderName
=
cursor
.
getString
(
1
)
val
duration
=
cursor
.
getLong
(
2
)
val
dateToken
=
cursor
.
getLong
(
3
)
val
size
=
cursor
.
getLong
(
4
)
val
id
=
cursor
.
getInt
(
5
);
val
mediaFile
=
MediaFile
()
mediaFile
.
realPath
=
path
mediaFile
.
mime
=
mime
mediaFile
.
folderId
=
folderId
//
mediaFile.mime = mime
//
mediaFile.folderId = folderId
mediaFile
.
folderName
=
folderName
mediaFile
.
duration
=
duration
mediaFile
.
dateToken
=
dateToken
mediaFile
.
isVideo
=
true
val
dir
=
Environment
.
getExternalStorageDirectory
().
absolutePath
+
"/GMAlbum/.album"
// val dir = getImageCacheDir(context, Luban.DEFAULT_DISK_CACHE_DIR)!!.absolutePath;
val
tempFilePngString
=
dir
+
"/"
+
MyUtil
.
getFileName
(
path
)
!!
+
".png"
;
val
tempFilePngExists
=
File
(
tempFilePngString
).
exists
()
if
(
tempFilePngExists
)
{
mediaFile
.
path
=
tempFilePngString
;
}
val
tempFileJpgString
=
dir
+
"/"
+
MyUtil
.
getFileName
(
path
)
!!
+
".jpg"
;
val
tempFileJpgExists
=
File
(
tempFileJpgString
).
exists
()
if
(
tempFileJpgExists
)
{
mediaFile
.
path
=
tempFileJpgString
;
}
val
tempFileJpegString
=
dir
+
"/"
+
MyUtil
.
getFileName
(
path
)
!!
+
".jpeg"
val
tempFileJpegExists
=
File
(
tempFileJpegString
).
exists
()
if
(
tempFileJpegExists
)
{
mediaFile
.
path
=
tempFileJpegString
;
}
mediaFile
.
isVideo
=
true
mediaFile
.
size
=
size
mediaFile
.
id
=
id
// val dir = Environment.getExternalStorageDirectory().absolutePath + "/GMAlbum/.album"
//// val dir = getImageCacheDir(context, Luban.DEFAULT_DISK_CACHE_DIR)!!.absolutePath;
// val tempFilePngString = dir + "/" + MyUtil.getFileName(path)!! + ".png";
// val tempFilePngExists = File(tempFilePngString).exists()
// if (tempFilePngExists) {
// mediaFile.path = tempFilePngString;
// }
// val tempFileJpgString = dir + "/" + MyUtil.getFileName(path)!! + ".jpg";
// val tempFileJpgExists = File(tempFileJpgString).exists()
// if (tempFileJpgExists) {
// mediaFile.path = tempFileJpgString;
// }
// val tempFileJpegString = dir + "/" + MyUtil.getFileName(path)!! + ".jpeg"
// val tempFileJpegExists = File(tempFileJpegString).exists()
// if (tempFileJpegExists) {
// mediaFile.path = tempFileJpegString;
// }
return
mediaFile
}
...
...
android/src/main/java/com/example/gengmei_flutter_plugin/utils/FileUtil.java
View file @
592bc5ed
package
com
.
example
.
gengmei_flutter_plugin
.
utils
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.util.Log
;
import
java.io.File
;
...
...
@@ -18,9 +20,8 @@ public class FileUtil {
if
(
fileNames
.
length
>
0
)
{
// directory
File
file
=
new
File
(
newPath
);
if
(!
file
.
mkdirs
())
{
Log
.
d
(
"mkdir"
,
"can't make folder"
);
if
(!
file
.
mkdirs
())
{
Log
.
d
(
"mkdir"
,
"can't make folder"
);
}
...
...
@@ -47,7 +48,9 @@ public class FileUtil {
}
}
public
static
void
copyAssetsFileToSD
(
Context
context
,
String
name
,
String
predictorPath
)
{
public
static
void
copyAssetsFileToSD
(
Context
context
,
String
name
,
String
predictorPath
)
{
// File file = new File(predictorPath);
// if (file.exists()) {
// return;
...
...
android/src/main/java/com/example/gengmei_flutter_plugin/utils/MyUtil.kt
View file @
592bc5ed
...
...
@@ -6,8 +6,11 @@ import com.example.myimagepicker.luban.Luban
import
java.io.File
import
android.media.ThumbnailUtils
import
android.graphics.Bitmap
import
android.graphics.BitmapFactory
import
android.util.DebugUtils
import
java.io.FileNotFoundException
import
java.io.FileOutputStream
import
java.io.IOException
import
java.lang.Exception
...
...
@@ -77,6 +80,53 @@ class MyUtil {
return
filePath
}
fun
scareImg
(
imgPath
:
String
,
scareSize
:
Float
,
filePath
:
String
,
quality
:
Int
):
String
{
val
newOpts
=
BitmapFactory
.
Options
()
// 开始读入图片,此时把options.inJustDecodeBounds 设回true,即只读边不读内容
newOpts
.
inJustDecodeBounds
=
true
newOpts
.
inPreferredConfig
=
Bitmap
.
Config
.
RGB_565
// 获取位图信息,但请注意位图现在为空
var
bitmap
=
BitmapFactory
.
decodeFile
(
imgPath
,
newOpts
)
newOpts
.
inJustDecodeBounds
=
false
val
w
=
newOpts
.
outWidth
val
h
=
newOpts
.
outHeight
val
max
=
Math
.
max
(
w
,
h
)
var
scare
=
1f
if
(
max
>
scareSize
)
{
scare
=
max
/
scareSize
}
// 想要缩放的目标尺寸,现在大部分手机都是1080*1920,参考值可以让宽高都缩小一倍
// float hh = w * scare;// 设置高度为960f时,可以明显看到图片缩小了
// float ww = h * scare;// 设置宽度为540f,可以明显看到图片缩小了
// // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
// int be = 1;// be=1表示不缩放
// if (w > h && w > ww) {// 如果宽度大的话根据宽度固定大小缩放
// be = (int) (newOpts.outWidth / ww);
// } else if (w < h && h > hh) {// 如果高度高的话根据宽度固定大小缩放
// be = (int) (newOpts.outHeight / hh);
// }
// if (be <= 0)
// be = 1;
newOpts
.
inSampleSize
=
scare
.
toInt
()
// 设置缩放比例
// 开始压缩图片,注意此时已经把options.inJustDecodeBounds 设回false了
bitmap
=
BitmapFactory
.
decodeFile
(
imgPath
,
newOpts
)
val
file
=
File
(
filePath
)
try
{
val
out
=
FileOutputStream
(
file
)
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
quality
,
out
)
out
.
flush
()
out
.
close
()
bitmap
.
recycle
()
}
catch
(
e
:
FileNotFoundException
)
{
e
.
printStackTrace
()
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
}
return
filePath
}
}
}
example/lib/AlbumModel/page/album/AlbumModel.dart
View file @
592bc5ed
...
...
@@ -64,12 +64,8 @@ class AlbumModel {
if
(
key
[
i
]
==
null
)
{
continue
;
}
if
(
itemList
[
i
].
path
==
null
)
{
itemList
[
i
].
path
=
key
[
i
][
"path"
];
}
if
(
itemList
[
i
].
realPath
==
null
)
{
itemList
[
i
].
realPath
=
key
[
i
][
"realPath"
];
}
itemList
[
i
].
path
=
key
[
i
][
"path"
];
itemList
[
i
].
realPath
=
key
[
i
][
"realPath"
];
}
}
});
...
...
example/lib/AlbumModel/page/album/AlbumPage.dart
View file @
592bc5ed
...
...
@@ -127,9 +127,9 @@ class AlbumState extends State<AlbumPage> {
}
return
GridView
.
builder
(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount
(
crossAxisCount:
3
,
crossAxisSpacing:
5
,
mainAxisSpacing:
5
,
crossAxisCount:
4
,
crossAxisSpacing:
1
,
mainAxisSpacing:
1
,
childAspectRatio:
1
),
itemCount:
imgList
.
data
.
length
+
2
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
...
...
@@ -204,6 +204,7 @@ class AlbumState extends State<AlbumPage> {
color:
Colors
.
grey
,
size:
25
,
),
imgList
.
data
[
newIndex
].
isVideo
?
Icon
(
Icons
.
cancel
,
color:
Colors
.
yellow
,):
Container
(),
_model
.
isFullSelect
()
&&
!
_model
.
isSelect
(
newIndex
)
?
Container
(
width:
double
.
maxFinite
,
...
...
gengmei_flutter_plugin.iml
View file @
592bc5ed
...
...
@@ -17,6 +17,7 @@
<excludeFolder
url=
"file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/.dart_tool"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/.pub"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/build"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/ios/Flutter/App.framework/flutter_assets/packages"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages"
/>
</content>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment