Skip to content

Commit

Permalink
import dependency and custom class
Browse files Browse the repository at this point in the history
  • Loading branch information
dinitri committed Apr 26, 2024
1 parent 09e99d1 commit fb35179
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</config-file>
<source-file src="src/android/SpectrumManager.java" target-dir="src/com/spoon/spectrum" />
<source-file src="src/android/SpoonCameraExif.java" target-dir="src/com/spoon/spectrum" />
<framework src="com.google.code.findbugs:jsr305:3.0.2"></framework>
</platform>

<!-- ios -->
Expand Down
1 change: 1 addition & 0 deletions src/android/SpectrumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,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
Expand Down
23 changes: 23 additions & 0 deletions src/android/utils/DoNotStrip.java
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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 {}
63 changes: 63 additions & 0 deletions src/android/utils/ImageSize.java
Original file line number Diff line number Diff line change
@@ -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 + '}';
}
}
54 changes: 54 additions & 0 deletions src/android/utils/Preconditions.java
Original file line number Diff line number Diff line change
@@ -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 <code>null</code>
* @throws NullPointerException if the given reference is <code>null</code>
*/
public static <T> 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 <code>false</code>
*/
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 <code>false</code>
*/
public static void checkState(final boolean assertion) {
if (!assertion) {
throw new IllegalStateException();
}
}
}

0 comments on commit fb35179

Please sign in to comment.