-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3836 from kartikaysharma01/mlkit-scanner
feat: Choice between classic and MLkit scanner with a system of dimensions to disable binary blobs for F-Droid
- Loading branch information
Showing
28 changed files
with
2,993 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
app/src/playstore/java/openfoodfacts/github/scrachx/openfood/camera/CameraReticleAnimator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package openfoodfacts.github.scrachx.openfood.camera | ||
|
||
import android.animation.AnimatorSet | ||
import android.animation.ValueAnimator | ||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator | ||
|
||
/** | ||
* Custom animator for the object or barcode reticle in live camera. | ||
*/ | ||
class CameraReticleAnimator(graphicOverlay: GraphicOverlay) { | ||
|
||
/** Returns the scale value of ripple alpha ranges in [0, 1]. */ | ||
var rippleAlphaScale = 0f | ||
private set | ||
|
||
/** Returns the scale value of ripple size ranges in [0, 1]. */ | ||
var rippleSizeScale = 0f | ||
private set | ||
|
||
/** Returns the scale value of ripple stroke width ranges in [0, 1]. */ | ||
var rippleStrokeWidthScale = 1f | ||
private set | ||
|
||
private val animatorSet: AnimatorSet | ||
|
||
init { | ||
val rippleFadeInAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(DURATION_RIPPLE_FADE_IN_MS).apply { | ||
addUpdateListener { animation -> | ||
rippleAlphaScale = animation.animatedValue as Float | ||
graphicOverlay.postInvalidate() | ||
} | ||
} | ||
|
||
val rippleFadeOutAnimator = ValueAnimator.ofFloat(1f, 0f).setDuration(DURATION_RIPPLE_FADE_OUT_MS).apply { | ||
startDelay = START_DELAY_RIPPLE_FADE_OUT_MS | ||
addUpdateListener { animation -> | ||
rippleAlphaScale = animation.animatedValue as Float | ||
graphicOverlay.postInvalidate() | ||
} | ||
} | ||
|
||
val rippleExpandAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(DURATION_RIPPLE_EXPAND_MS).apply { | ||
startDelay = START_DELAY_RIPPLE_EXPAND_MS | ||
interpolator = FastOutSlowInInterpolator() | ||
addUpdateListener { animation -> | ||
rippleSizeScale = animation.animatedValue as Float | ||
graphicOverlay.postInvalidate() | ||
} | ||
} | ||
|
||
val rippleStrokeWidthShrinkAnimator = ValueAnimator.ofFloat(1f, 0.5f).setDuration(DURATION_RIPPLE_STROKE_WIDTH_SHRINK_MS).apply { | ||
startDelay = START_DELAY_RIPPLE_STROKE_WIDTH_SHRINK_MS | ||
interpolator = FastOutSlowInInterpolator() | ||
addUpdateListener { animation -> | ||
rippleStrokeWidthScale = animation.animatedValue as Float | ||
graphicOverlay.postInvalidate() | ||
} | ||
} | ||
|
||
val fakeAnimatorForRestartDelay = ValueAnimator.ofInt(0, 0).setDuration(DURATION_RESTART_DORMANCY_MS).apply { | ||
startDelay = START_DELAY_RESTART_DORMANCY_MS | ||
} | ||
|
||
animatorSet = AnimatorSet().apply { | ||
playTogether( | ||
rippleFadeInAnimator, | ||
rippleFadeOutAnimator, | ||
rippleExpandAnimator, | ||
rippleStrokeWidthShrinkAnimator, | ||
fakeAnimatorForRestartDelay | ||
) | ||
} | ||
|
||
} | ||
|
||
fun start() { | ||
if (!animatorSet.isRunning) animatorSet.start() | ||
} | ||
|
||
fun cancel() { | ||
animatorSet.cancel() | ||
rippleAlphaScale = 0f | ||
rippleSizeScale = 0f | ||
rippleStrokeWidthScale = 1f | ||
} | ||
|
||
companion object { | ||
|
||
private const val DURATION_RIPPLE_FADE_IN_MS: Long = 333 | ||
private const val DURATION_RIPPLE_FADE_OUT_MS: Long = 500 | ||
private const val DURATION_RIPPLE_EXPAND_MS: Long = 833 | ||
private const val DURATION_RIPPLE_STROKE_WIDTH_SHRINK_MS: Long = 833 | ||
private const val DURATION_RESTART_DORMANCY_MS: Long = 1333 | ||
private const val START_DELAY_RIPPLE_FADE_OUT_MS: Long = 667 | ||
private const val START_DELAY_RIPPLE_EXPAND_MS: Long = 333 | ||
private const val START_DELAY_RIPPLE_STROKE_WIDTH_SHRINK_MS: Long = 333 | ||
private const val START_DELAY_RESTART_DORMANCY_MS: Long = 1167 | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/playstore/java/openfoodfacts/github/scrachx/openfood/camera/CameraSizePair.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@file:Suppress("DEPRECATION") | ||
|
||
package openfoodfacts.github.scrachx.openfood.camera | ||
|
||
import android.hardware.Camera | ||
import com.google.android.gms.common.images.Size | ||
|
||
/** | ||
* Stores a preview size and a corresponding same-aspect-ratio picture size. To avoid distorted | ||
* preview images on some devices, the picture size must be set to a size that is the same aspect | ||
* ratio as the preview size or the preview may end up being distorted. If the picture size is null, | ||
* then there is no picture size with the same aspect ratio as the preview size. | ||
*/ | ||
|
||
data class CameraSizePair(val previewSize: Camera.Size, val pictureSize: Camera.Size?) { | ||
|
||
val preview: Size = Size(previewSize.width, previewSize.height) | ||
val picture: Size? = pictureSize?.let { Size(it.width, it.height) } | ||
|
||
} |
Oops, something went wrong.