diff --git a/plugin.xml b/plugin.xml index 6e135ba..8f0eceb 100755 --- a/plugin.xml +++ b/plugin.xml @@ -17,17 +17,20 @@ - - - - + + + + + + + @@ -37,16 +40,6 @@ - - - - - - - - - - diff --git a/src/android/SpectrumManager.java b/src/android/SpectrumManager.java index c062e07..3daff12 100644 --- a/src/android/SpectrumManager.java +++ b/src/android/SpectrumManager.java @@ -5,8 +5,6 @@ import android.net.Uri; import android.os.Build; import android.util.Log; -import com.facebook.spectrum.Spectrum; -import com.facebook.spectrum.image.ImageSize; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; @@ -19,6 +17,7 @@ import java.io.IOException; import java.util.UUID; import androidx.exifinterface.media.ExifInterface; +import com.spoon.spectrum.utils.ImageSize; public class SpectrumManager extends CordovaPlugin { @Override diff --git a/src/android/utils/DoNotStrip.java b/src/android/utils/DoNotStrip.java new file mode 100644 index 0000000..6821004 --- /dev/null +++ b/src/android/utils/DoNotStrip.java @@ -0,0 +1,23 @@ +package com.spoon.spectrum.utils; +/* + * Copyright (c) 2004-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + * + */ + +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Add this annotation to a class, method, or field to instruct Proguard to not strip it out. + * + *

This is useful for methods called via reflection that could appear as unused to Proguard. + */ +@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@Retention(CLASS) +public @interface DoNotStrip {} \ No newline at end of file diff --git a/src/android/utils/ImageSize.java b/src/android/utils/ImageSize.java new file mode 100644 index 0000000..5d29d93 --- /dev/null +++ b/src/android/utils/ImageSize.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.spoon.spectrum.utils; + +import javax.annotation.concurrent.Immutable; + +/** Represents a rectangular area defined by its width and height. */ +@DoNotStrip +@Immutable +public class ImageSize { + + /** + * Setting to 2**16 as this is the smallest common denominator for all common image libraries that + * we are interested in. + */ + @DoNotStrip static final int MAX_IMAGE_SIDE_DIMENSION = 65536; + + /** The size's width. */ + @DoNotStrip public final int width; + + /** The size's height. */ + @DoNotStrip public final int height; + + /** + * Creates a new {@link ImageSize} + * + * @param width Must be within [0, {@link #MAX_IMAGE_SIDE_DIMENSION}] + * @param height Must be within [0, {@link #MAX_IMAGE_SIDE_DIMENSION}] + */ + @DoNotStrip + public ImageSize(final int width, final int height) { + Preconditions.checkArgument(width >= 0 && width <= MAX_IMAGE_SIDE_DIMENSION); + Preconditions.checkArgument(height >= 0 && height <= MAX_IMAGE_SIDE_DIMENSION); + this.width = width; + this.height = height; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + final ImageSize that = (ImageSize) o; + return width == that.width && height == that.height; + } + + @Override + public int hashCode() { + int result = width; + result = 31 * result + height; + return result; + } + + @Override + public String toString() { + return "ImageSize{" + "width=" + width + ", height=" + height + '}'; + } +} diff --git a/src/android/utils/Preconditions.java b/src/android/utils/Preconditions.java new file mode 100644 index 0000000..b418a09 --- /dev/null +++ b/src/android/utils/Preconditions.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.spoon.spectrum.utils; + +import androidx.annotation.Nullable; + +/** Light-weight implementation for Precondition checks. */ +public final class Preconditions { + + private Preconditions() {} + + /** + * Asserts that the given reference is not null. + * + * @param reference A reference that might be null + * @return reference if reference is not null + * @throws NullPointerException if the given reference is null + */ + public static T checkNotNull(@Nullable final T reference) { + if (reference == null) { + throw new NullPointerException(); + } + return reference; + } + + /** + * Asserts that the given assertion about an argument is true. + * + * @param assertion The assertion to check + * @throws IllegalArgumentException if the given assertion is false + */ + public static void checkArgument(final boolean assertion) { + if (!assertion) { + throw new IllegalArgumentException(); + } + } + + /** + * Asserts that the given assertion about a state is true. + * + * @param assertion The assertion to check + * @throws IllegalStateException if the given assertion is false + */ + public static void checkState(final boolean assertion) { + if (!assertion) { + throw new IllegalStateException(); + } + } +} diff --git a/src/ios/SpectrumManager.h b/src/ios/SpectrumManager.h index 75b9122..5596ba4 100644 --- a/src/ios/SpectrumManager.h +++ b/src/ios/SpectrumManager.h @@ -7,13 +7,9 @@ #import #import -#import -#import -#import NS_ASSUME_NONNULL_BEGIN @interface SpectrumManager : CDVPlugin{ - FSPSpectrum *spectrum; } -(void)compressImage:(CDVInvokedUrlCommand*)command; @end