diff --git a/android/src/main/java/com/leeson/image_pickers/ImagePickersPlugin.java b/android/src/main/java/com/leeson/image_pickers/ImagePickersPlugin.java index af94f30..9af0832 100644 --- a/android/src/main/java/com/leeson/image_pickers/ImagePickersPlugin.java +++ b/android/src/main/java/com/leeson/image_pickers/ImagePickersPlugin.java @@ -118,6 +118,7 @@ public void onMethodCall(MethodCall methodCall, @NonNull MethodChannel.Result re if ("getPickerPaths".equals(methodCall.method)) { String galleryMode = methodCall.argument("galleryMode"); + Number screenOrientation = methodCall.argument("screenOrientation"); Boolean showGif = methodCall.argument("showGif"); Map uiColor = methodCall.argument("uiColor"); Number selectCount = methodCall.argument("selectCount"); @@ -136,6 +137,7 @@ public void onMethodCall(MethodCall methodCall, @NonNull MethodChannel.Result re Intent intent = new Intent(); intent.putExtra(SelectPicsActivity.GALLERY_MODE,galleryMode); + intent.putExtra(SelectPicsActivity.SCREEN_ORIENTATION, screenOrientation); intent.putExtra(SelectPicsActivity.UI_COLOR, (Serializable) uiColor); intent.putExtra(SelectPicsActivity.SELECT_COUNT,selectCount); intent.putExtra(SelectPicsActivity.SHOW_GIF,showGif); diff --git a/android/src/main/java/com/leeson/image_pickers/activitys/SelectPicsActivity.java b/android/src/main/java/com/leeson/image_pickers/activitys/SelectPicsActivity.java index de731ec..3eb969a 100644 --- a/android/src/main/java/com/leeson/image_pickers/activitys/SelectPicsActivity.java +++ b/android/src/main/java/com/leeson/image_pickers/activitys/SelectPicsActivity.java @@ -49,6 +49,7 @@ public class SelectPicsActivity extends BaseActivity { private static final int WRITE_SDCARD = 101; public static final String GALLERY_MODE = "GALLERY_MODE"; + public static final String SCREEN_ORIENTATION = "SCREEN_ORIENTATION"; public static final String UI_COLOR = "UI_COLOR"; public static final String SHOW_GIF = "SHOW_GIF"; public static final String SHOW_CAMERA = "SHOW_CAMERA"; @@ -127,6 +128,7 @@ private int getLang(String language){ private void startSel() { String mode = getIntent().getStringExtra(GALLERY_MODE); + Number screenOrientation = getIntent().getIntExtra(SCREEN_ORIENTATION, 1); Map uiColor = (Map) getIntent().getSerializableExtra(UI_COLOR); Number selectCount = getIntent().getIntExtra(SELECT_COUNT, 9); @@ -145,6 +147,8 @@ private void startSel() { String language = getIntent().getStringExtra(LANGUAGE); + // 屏幕方向 + int requestedOrientation = screenOrientation.intValue() == 0 ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : (screenOrientation.intValue() == 1 ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); PictureStyleUtil pictureStyleUtil = new PictureStyleUtil(this); pictureStyleUtil.setStyle(uiColor); @@ -228,7 +232,7 @@ public void onCancel() { PictureSelector.create(this).openGallery(selectMimeType) .setImageEngine(GlideEngine.createGlideEngine()) .setSelectorUIStyle(pictureStyleUtil.getSelectorStyle()) - .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) + .setRequestedOrientation(requestedOrientation) .setRecordVideoMaxSecond(videoRecordMaxSecond.intValue()) .setRecordVideoMinSecond(videoRecordMinSecond.intValue()) .setLanguage(getLang(language)) diff --git a/lib/image_pickers.dart b/lib/image_pickers.dart index 6cae3db..b4fe03d 100644 --- a/lib/image_pickers.dart +++ b/lib/image_pickers.dart @@ -21,6 +21,16 @@ enum CameraMimeType { video, } +/// 屏幕方向设置,android独有 +enum ScreenOrientation { + // 横屏 + landscape, + // 竖屏 + portrait, + // unspecified + unspecified, +} + class ImagePickers { static const MethodChannel _channel = const MethodChannel('flutter/image_pickers'); @@ -58,7 +68,8 @@ class ImagePickers { Color uiColor = UIConfig.defUiThemeColor; final Map params = { - 'galleryMode': "image", + 'galleryMode': GalleryMode.image.name, + 'screenOrientation': ScreenOrientation.portrait.index, 'showGif': true, 'uiColor': { "a": 255, @@ -124,6 +135,7 @@ class ImagePickers { static Future> pickerPaths({ GalleryMode galleryMode = GalleryMode.image, + ScreenOrientation screenOrientation = ScreenOrientation.portrait, UIConfig? uiConfig, int selectCount = 1, bool showCamera = false, @@ -152,6 +164,7 @@ class ImagePickers { final Map params = { 'galleryMode': galleryMode.name, + 'screenOrientation': screenOrientation.index, 'showGif': showGif, 'uiColor': { "a": 255,