Skip to content

Commit

Permalink
Merge pull request #213 from CaiJingLong/add-orientation
Browse files Browse the repository at this point in the history
Add orientation.
  • Loading branch information
CaiJingLong authored Mar 19, 2020
2 parents 3d2589a + 11299ba commit eabb469
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 0.5.0-dev.1

Feature:

- Add `orientation` for `AssetEntity`.

Update

- **Breaking change**, Split video filter and image filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ data class AssetEntity(
val height: Int,
val type: Int,
val displayName: String,
val modifiedDate: Long
val modifiedDate: Long,
val orientation:Int
) {
var lat: Double? = null
var lng: Double? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ object AndroidQDBUtils : IDBUtils {
val height = cursor.getInt(MediaStore.MediaColumns.HEIGHT)
val displayName = cursor.getString(MediaStore.Images.Media.DISPLAY_NAME)
val modifiedDate = cursor.getLong(MediaStore.MediaColumns.DATE_MODIFIED)

val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate)
val orientation: Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION)
val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation)
list.add(asset)
cache.putAsset(asset)
}
Expand Down Expand Up @@ -176,8 +176,9 @@ object AndroidQDBUtils : IDBUtils {
val height = cursor.getInt(MediaStore.MediaColumns.HEIGHT)
val displayName = cursor.getString(MediaStore.Images.Media.DISPLAY_NAME)
val modifiedDate = cursor.getLong(MediaStore.MediaColumns.DATE_MODIFIED)

val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate)
val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION)

val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation)
list.add(asset)
cache.putAsset(asset)
}
Expand Down Expand Up @@ -212,8 +213,9 @@ object AndroidQDBUtils : IDBUtils {
val height = cursor.getInt(MediaStore.MediaColumns.HEIGHT)
val displayName = cursor.getString(MediaStore.MediaColumns.DISPLAY_NAME)
val modifiedDate = cursor.getLong(MediaStore.MediaColumns.DATE_MODIFIED)

val dbAsset = AssetEntity(databaseId, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate)
val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION)

val dbAsset = AssetEntity(databaseId, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation)
cacheContainer.putAsset(dbAsset)

cursor.close()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package top.kikt.imagescanner.core.utils

import top.kikt.imagescanner.AssetType
import top.kikt.imagescanner.core.entity.*
import top.kikt.imagescanner.core.entity.AssetEntity
import top.kikt.imagescanner.core.entity.FilterCond
import top.kikt.imagescanner.core.entity.FilterOption
import top.kikt.imagescanner.core.entity.GalleryEntity

/// create 2019-09-05 by cai
Expand Down Expand Up @@ -39,6 +42,7 @@ object ConvertUtils {
"createDt" to entity.createDt / 1000,
"width" to entity.width,
"height" to entity.height,
"orientation" to entity.orientation,
"modifiedDt" to entity.modifiedDate,
"lat" to entity.lat,
"lng" to entity.lng,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ object DBUtils : IDBUtils {

val lat = cursor.getDouble(MediaStore.Images.ImageColumns.LATITUDE)
val lng = cursor.getDouble(MediaStore.Images.ImageColumns.LONGITUDE)
val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION)

val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate)
val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate,orientation)

if (lat != 0.0) {
asset.lat = lat
Expand Down Expand Up @@ -232,8 +233,9 @@ object DBUtils : IDBUtils {

val lat = cursor.getDouble(MediaStore.Images.ImageColumns.LATITUDE)
val lng = cursor.getDouble(MediaStore.Images.ImageColumns.LONGITUDE)
val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION)

val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate)
val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation)

if (lat != 0.0) {
asset.lat = lat
Expand Down Expand Up @@ -279,8 +281,9 @@ object DBUtils : IDBUtils {
val modifiedDate = cursor.getLong(MediaStore.MediaColumns.DATE_MODIFIED)
val lat = cursor.getDouble(MediaStore.Images.ImageColumns.LATITUDE)
val lng = cursor.getDouble(MediaStore.Images.ImageColumns.LONGITUDE)
val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION)

val dbAsset = AssetEntity(databaseId, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate)
val dbAsset = AssetEntity(databaseId, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation)

if (lat != 0.0) {
dbAsset.lat = lat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface IDBUtils {
MediaStore.MediaColumns.BUCKET_DISPLAY_NAME, // dir name 目录名字
MediaStore.MediaColumns.WIDTH, // 宽
MediaStore.MediaColumns.HEIGHT, // 高
MediaStore.MediaColumns.ORIENTATION, // 角度
MediaStore.MediaColumns.DATE_MODIFIED, // 修改时间
MediaStore.MediaColumns.MIME_TYPE, // 高
MediaStore.MediaColumns.DATE_TAKEN //日期
Expand All @@ -48,6 +49,7 @@ interface IDBUtils {
MediaStore.MediaColumns.DATE_TAKEN, //日期
MediaStore.MediaColumns.WIDTH, // 宽
MediaStore.MediaColumns.HEIGHT, // 高
MediaStore.MediaColumns.ORIENTATION, // 角度
MediaStore.MediaColumns.DATE_MODIFIED, // 修改时间
MediaStore.MediaColumns.MIME_TYPE, // 高
MediaStore.MediaColumns.DURATION //时长
Expand Down
10 changes: 8 additions & 2 deletions example/lib/page/detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import 'package:photo_manager/photo_manager.dart';
class DetailPage extends StatefulWidget {
final File file;
final AssetEntity entity;
final String mediaUrl;
const DetailPage({Key key, this.file, this.entity,this.mediaUrl, }) : super(key: key);
final String mediaUrl;
const DetailPage({
Key key,
this.file,
this.entity,
this.mediaUrl,
}) : super(key: key);

@override
_DetailPageState createState() => _DetailPageState();
Expand Down Expand Up @@ -78,6 +83,7 @@ class _DetailPageState extends State<DetailPage> {
buildInfoItem("create", entity.createDateTime.toString()),
buildInfoItem("modified", entity.modifiedDateTime.toString()),
buildInfoItem("size", entity.size.toString()),
buildInfoItem("orientation", entity.orientation.toString()),
buildInfoItem("duration", entity.videoDuration.toString()),
buildInfoItemAsync("title", entity.titleAsync),
buildInfoItem("lat", lat?.toString() ?? "null"),
Expand Down
23 changes: 11 additions & 12 deletions example/lib/widget/image_item_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ class _ImageItemWidgetState extends State<ImageItemWidget> {
Widget image;

if (u8List != null) {
return Image.memory(
u8List,
width: size.toDouble(),
height: size.toDouble(),
fit: BoxFit.cover,
);
return _buildImageWidget(item, u8List, size);
} else {
image = FutureBuilder<Uint8List>(
future: item.thumbDataWithSize(size, size),
Expand All @@ -44,12 +39,7 @@ class _ImageItemWidgetState extends State<ImageItemWidget> {
}
if (snapshot.hasData) {
ImageLruCache.setData(item, size, snapshot.data);
w = FittedBox(
fit: BoxFit.cover,
child: Image.memory(
snapshot.data,
),
);
w = _buildImageWidget(item, snapshot.data, size);
} else {
w = Center(
child: loadWidget,
Expand All @@ -64,6 +54,15 @@ class _ImageItemWidgetState extends State<ImageItemWidget> {
return image;
}

Widget _buildImageWidget(AssetEntity entity, Uint8List uint8list, num size) {
return Image.memory(
uint8list,
width: size.toDouble(),
height: size.toDouble(),
fit: BoxFit.cover,
);
}

@override
void didUpdateWidget(ImageItemWidget oldWidget) {
super.didUpdateWidget(oldWidget);
Expand Down
4 changes: 4 additions & 0 deletions ios/Classes/PHAsset+PHAsset_checkType.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ -(bool)isVideo{
return [self mediaType] == PHAssetMediaTypeVideo;
}

-(bool)isAudio{
return [self mediaType] == PHAssetMediaTypeAudio;
}

-(bool)isImageOrVideo{
return [self isVideo] || [self isImage];
}
Expand Down
12 changes: 9 additions & 3 deletions lib/src/entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ class AssetEntity {
Future<bool> get exists => PhotoManager._assetExistsWithId(id);

/// The url is provided to some video player. Such as [flutter_ijkplayer](https://pub.dev/packages/flutter_ijkplayer)
///
///
/// It is such as `file:///var/mobile/Media/DCIM/118APPLE/IMG_8371.MOV` in iOS.
///
///
/// Android28 or lower: `file:///storage/emulated/0/DCIM/Camera/20201020_202020.MP4`
///
///
/// AndroidQ or higher: `content://media/external/video/media/894857`
Future<String> getMediaUrl() {
if (type == AssetType.video) {
Expand All @@ -276,6 +276,12 @@ class AssetEntity {
return null;
}

/// Orientation of android MediaStore. See [ORIENTATION](https://developer.android.com/reference/android/provider/MediaStore.MediaColumns#ORIENTATION)
/// Example values for android: 0 90 180 270
///
/// The value always 0 in iOS.
int orientation;

@override
int get hashCode {
return id.hashCode;
Expand Down
1 change: 1 addition & 0 deletions lib/src/utils/convert_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ConvertUtils {
..createDtSecond = item["createDt"]
..width = item["width"]
..height = item["height"]
..orientation = (item["orientation"] ?? 0)
..duration = item["duration"]
..modifiedDateSecond = item["modifiedDt"]
..typeInt = item["type"]
Expand Down

0 comments on commit eabb469

Please sign in to comment.