Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #320 from gini/develop
Browse files Browse the repository at this point in the history
Release version 4.1.1
  • Loading branch information
a-szotyori authored Jul 1, 2021
2 parents bea5520 + d6cb806 commit 5185a6a
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ app/build.gradle:

```
dependencies {
implementation 'net.gini:gini-vision-lib:4.1.0'
implementation 'net.gini:gini-vision-lib:4.1.1'
}
```

Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.4.10"
classpath "org.jetbrains.dokka:kotlin-as-java-plugin:1.4.10"
classpath 'com.google.gms:google-services:4.3.8'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -32,6 +33,9 @@ allprojects {
// For Commons Imaging
url 'https://repo.gini.net/nexus/content/repositories/open'
}
maven {
url 'https://repo.gini.net/nexus/content/repositories/snapshots'
}
mavenCentral()
}
}
Expand Down
4 changes: 2 additions & 2 deletions ginivision-accounting-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ app/build.gradle:

```
dependencies {
implementation 'net.gini:gini-vision-lib:4.1.0'
implementation 'net.gini:gini-vision-accounting-network-lib:4.1.0'
implementation 'net.gini:gini-vision-lib:4.1.1'
implementation 'net.gini:gini-vision-accounting-network-lib:4.1.1'
}
```

Expand Down
4 changes: 2 additions & 2 deletions ginivision-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ app/build.gradle:

```
dependencies {
implementation 'net.gini:gini-vision-lib:4.1.0'
implementation 'net.gini:gini-vision-network-lib:4.1.0'
implementation 'net.gini:gini-vision-lib:4.1.1'
implementation 'net.gini:gini-vision-network-lib:4.1.1'
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package net.gini.android.vision.internal.camera.photo;

import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.NOPLogger;
Expand All @@ -14,12 +20,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* Internal use only.
*
* <p>
* This singleton cache keeps references to byte arrays and Bitmaps to be preserved between
* parceling and unparceling.
*
Expand All @@ -34,6 +37,7 @@ public enum ParcelableMemoryCache {

private static final boolean DEBUG = false;
private static final Logger LOG;

static {
if (DEBUG) {
LOG = LoggerFactory.getLogger(ParcelableMemoryCache.class);
Expand All @@ -42,6 +46,60 @@ public enum ParcelableMemoryCache {
}
}

private static final long REMOVE_DELAY_MS = 1000;

private static final int STORE_BYTE_ARRAY = 1;
private static final int REMOVE_BYTE_ARRAY = 2;
private static final int STORE_BITMAP = 3;
private static final int REMOVE_BITMAP = 4;
private static final int REMOVE_ENTRIES_WITH_TAG = 5;

private static final Handler mHandler = new Handler(Looper.getMainLooper(), new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
switch (msg.what) {
case STORE_BYTE_ARRAY:
INSTANCE.doStoreByteArray((TokenWithPayload<byte[]>) msg.obj);
return true;
case REMOVE_BYTE_ARRAY:
INSTANCE.doRemoveByteArray((Token) msg.obj);
return true;
case STORE_BITMAP:
INSTANCE.doStoreBitmap((TokenWithPayload<Bitmap>) msg.obj);
return true;
case REMOVE_BITMAP:
INSTANCE.doRemoveBitmap((Token) msg.obj);
return true;
case REMOVE_ENTRIES_WITH_TAG:
INSTANCE.doRemoveEntriesWithTag((String) msg.obj);
return true;
default:
return false;
}
}
});

private static class TokenWithPayload<P> {
private final Token token;
private final P payload;
private final String tag;

private TokenWithPayload(@NonNull final Token token,
@NonNull final P payload,
@NonNull final String tag) {
this.token = token;
this.payload = payload;
this.tag = tag;
}

private TokenWithPayload(@NonNull final Token token,
@NonNull final P payload) {
this.token = token;
this.payload = payload;
this.tag = null;
}
}

/**
* Opaque tokenId type to identify a document.
*/
Expand Down Expand Up @@ -143,29 +201,51 @@ private void logCacheSizes() {
mBitmapCache.size());
}

@NonNull
public Token storeByteArray(@NonNull final byte[] documentJpeg) {
final Token token = Token.next();
mByteArrayCache.put(token, documentJpeg);
LOG.debug("Store byte array for token {}", token);
logCacheSizes();
final Message msg = mHandler.obtainMessage(STORE_BYTE_ARRAY,
new TokenWithPayload<>(token, documentJpeg));
mHandler.sendMessage(msg);
return token;
}

@NonNull
public Token storeByteArray(@NonNull final byte[] documentJpeg, @NonNull final String tag) {
final Token token = Token.next(tag);
mByteArrayCache.put(token, documentJpeg);
LOG.debug("Store byte array for token {} with tag {}", token, tag);
logCacheSizes();
final Message msg = mHandler.obtainMessage(STORE_BYTE_ARRAY,
new TokenWithPayload<>(token, documentJpeg, tag));
mHandler.sendMessage(msg);
return token;
}

private void doStoreByteArray(@NonNull final TokenWithPayload<byte[]> tokenWithPayload) {
mByteArrayCache.put(tokenWithPayload.token, tokenWithPayload.payload);
if (tokenWithPayload.tag != null) {
LOG.debug("Store byte array for token {} with tag {}", tokenWithPayload.token,
tokenWithPayload.tag);
} else {
LOG.debug("Store byte array for token {}", tokenWithPayload.token);
}
logCacheSizes();
}

public void removeByteArray(@NonNull final Token token) {
mHandler.sendMessageDelayed(mHandler.obtainMessage(REMOVE_BYTE_ARRAY, token),
REMOVE_DELAY_MS);
}

private void doRemoveByteArray(@NonNull final Token token) {
mByteArrayCache.remove(token);
LOG.debug("Remove byte array for token {}", token);
logCacheSizes();
}

public void removeEntriesWithTag(@NonNull final String tag) {
mHandler.sendMessage(mHandler.obtainMessage(REMOVE_ENTRIES_WITH_TAG, tag));
}

private void doRemoveEntriesWithTag(@NonNull final String tag) {
removeByteArraysWithTag(tag);
removeBitmapsWithTag(tag);
LOG.debug("Remove entries for tag {}", tag);
Expand All @@ -181,7 +261,7 @@ private void removeBitmapsWithTag(@NonNull final String tag) {
}

private void removeTokensWithTag(final Set<Token> tokens,
@NonNull final String tag) {
@NonNull final String tag) {
final Iterator<Token> iterator = tokens.iterator();
while (iterator.hasNext()) {
final Token token = iterator.next();
Expand All @@ -202,25 +282,41 @@ public Bitmap getBitmap(@NonNull final Token token) {
public Token storeBitmap(@Nullable final Bitmap documentBitmap) {
final Token token = Token.next();
if (documentBitmap != null) {
mBitmapCache.put(token, documentBitmap);
final Message msg = mHandler.obtainMessage(STORE_BITMAP,
new TokenWithPayload<>(token, documentBitmap));
mHandler.sendMessage(msg);
}
LOG.debug("Store bitmap for token {}", token);
logCacheSizes();
return token;
}

@NonNull
public Token storeBitmap(@Nullable final Bitmap documentBitmap, @NonNull final String tag) {
final Token token = Token.next(tag);
if (documentBitmap != null) {
mBitmapCache.put(token, documentBitmap);
final Message msg = mHandler.obtainMessage(STORE_BITMAP,
new TokenWithPayload<>(token, documentBitmap, tag));
mHandler.sendMessage(msg);
}
LOG.debug("Store bitmap for token {} with tag {}", token, tag);
logCacheSizes();
return token;
}

private void doStoreBitmap(@NonNull final TokenWithPayload<Bitmap> tokenWithPayload) {
mBitmapCache.put(tokenWithPayload.token, tokenWithPayload.payload);
if (tokenWithPayload.tag != null) {
LOG.debug("Store bitmap for token {} with tag {}", tokenWithPayload.token,
tokenWithPayload.tag);
} else {
LOG.debug("Store bitmap for token {}", tokenWithPayload.token);
}
logCacheSizes();
}

public void removeBitmap(@NonNull final Token token) {
mHandler.sendMessageDelayed(mHandler.obtainMessage(REMOVE_BITMAP, token),
REMOVE_DELAY_MS);
}

private void doRemoveBitmap(@NonNull final Token token) {
mBitmapCache.remove(token);
LOG.debug("Remove bitmap for token {}", token);
logCacheSizes();
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m
# mavenReleasesRepoUrl=https://repo.i.gini.net/nexus/content/repositories/releases
# mavenOpenRepoUrl=https://repo.i.gini.net/nexus/content/repositories/open
groupId=net.gini
version=4.1.0
version=4.1.1
24 changes: 18 additions & 6 deletions screenapiexample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,30 @@ dependencies {

// For testing the local version
implementation project(path: ':ginivision-network')
// For testing a released version
//implementation 'net.gini:gini-vision-network-lib:2.5.0'
// For testing a released version or a snapshot
// implementation ('net.gini:gini-vision-network-lib') {
// version {
// strictly '4.1.0-20210701.150110-2'
// }
// }

// For testing the local version
implementation project(path: ':ginivision-accounting-network')
// For testing a released version
//implementation 'net.gini:gini-vision-accounting-network-lib:2.5.0'
// For testing a released version or a snapshot
// implementation ('net.gini:gini-vision-accounting-network-lib') {
// version {
// strictly '4.1.0-20210701.150114-2'
// }
// }

// For testing the local version
implementation project(path: ':ginivision')
// For testing a released version
//implementation 'net.gini:gini-vision-lib:2.0.0-alpha.1'
// For testing a released version or a snapshot
// implementation ('net.gini:gini-vision-lib') {
// version {
// strictly '4.1.0-20210701.150106-2'
// }
// }

testImplementation deps.junit

Expand Down

0 comments on commit 5185a6a

Please sign in to comment.