Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.6+1

* Refactors code in preparation for adopting Pigeon.

## 0.8.6

* Adds `usePhotoPickerAndroid` options.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.flutter.plugins.imagepicker;

import androidx.annotation.Nullable;

/** Stores settings for image output options. */
public class ImageOutputOptions {
/** The maximum width of the image, if the width should be constrained. */
@Nullable public final Double maxWidth;
/** The maximum height of the image, if the width should be constrained. */
@Nullable public final Double maxHeight;
/**
* The output quality of the image, as a number from 0 to 100.
*
* <p>Defaults to 100.
*/
final int quality;

public ImageOutputOptions(
@Nullable Double maxWidth, @Nullable Double maxHeight, @Nullable Integer quality) {
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
// Treat any invalid value as full quality.
this.quality = quality == null || quality < 0 || quality > 100 ? 100 : quality;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code treated quality at a nullable value until the very bottom layer where it was used, at which point null and 100 were actually handled the same, so I moved that logic into this layer to simplify things.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import android.net.Uri;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import io.flutter.plugin.common.MethodCall;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

class ImagePickerCache {
public enum CacheType {
IMAGE,
VIDEO
}

static final String MAP_KEY_PATH = "path";
static final String MAP_KEY_PATH_LIST = "pathList";
Expand Down Expand Up @@ -53,44 +56,31 @@ class ImagePickerCache {
prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}

void saveTypeWithMethodCallName(String methodCallName) {
if (methodCallName.equals(ImagePickerPlugin.METHOD_CALL_IMAGE)
| methodCallName.equals(ImagePickerPlugin.METHOD_CALL_MULTI_IMAGE)) {
setType("image");
} else if (methodCallName.equals(ImagePickerPlugin.METHOD_CALL_VIDEO)) {
setType("video");
void saveType(CacheType type) {
switch (type) {
case IMAGE:
setType("image");
break;
case VIDEO:
setType("video");
break;
}
}

private void setType(String type) {

prefs.edit().putString(SHARED_PREFERENCE_TYPE_KEY, type).apply();
}

void saveDimensionWithMethodCall(MethodCall methodCall) {
Double maxWidth = methodCall.argument(MAP_KEY_MAX_WIDTH);
Double maxHeight = methodCall.argument(MAP_KEY_MAX_HEIGHT);
int imageQuality =
methodCall.argument(MAP_KEY_IMAGE_QUALITY) == null
? 100
: (int) methodCall.argument(MAP_KEY_IMAGE_QUALITY);

setMaxDimension(maxWidth, maxHeight, imageQuality);
}

private void setMaxDimension(Double maxWidth, Double maxHeight, int imageQuality) {
void saveDimensionWithOutputOptions(ImageOutputOptions options) {
SharedPreferences.Editor editor = prefs.edit();
if (maxWidth != null) {
editor.putLong(SHARED_PREFERENCE_MAX_WIDTH_KEY, Double.doubleToRawLongBits(maxWidth));
}
if (maxHeight != null) {
editor.putLong(SHARED_PREFERENCE_MAX_HEIGHT_KEY, Double.doubleToRawLongBits(maxHeight));
if (options.maxWidth != null) {
editor.putLong(SHARED_PREFERENCE_MAX_WIDTH_KEY, Double.doubleToRawLongBits(options.maxWidth));
}
if (imageQuality > -1 && imageQuality < 101) {
editor.putInt(SHARED_PREFERENCE_IMAGE_QUALITY_KEY, imageQuality);
} else {
editor.putInt(SHARED_PREFERENCE_IMAGE_QUALITY_KEY, 100);
if (options.maxHeight != null) {
editor.putLong(
SHARED_PREFERENCE_MAX_HEIGHT_KEY, Double.doubleToRawLongBits(options.maxHeight));
}
editor.putInt(SHARED_PREFERENCE_IMAGE_QUALITY_KEY, options.quality);
editor.apply();
}

Expand Down
Loading