Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve java api #2

Merged
merged 4 commits into from Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,10 @@
Version 0.0.2
----------------------------

Improve Java api


Version 0.0.1
----------------------------

Initial release.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -27,10 +27,10 @@ android {
}

dependencies {
implementation 'com.github.the-super-toys.glimpse-android:glimpse-core:0.0.1'
implementation 'com.github.the-super-toys.glimpse-android:glimpse-core:0.0.2'

//only required for glide extensions
implementation 'com.github.the-super-toys.glimpse-android:glimpse-glide:0.0.1'
implementation 'com.github.the-super-toys.glimpse-android:glimpse-glide:0.0.2'

implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
}
Expand Down Expand Up @@ -84,6 +84,8 @@ We tried to ship Glimpse with both Picasso and Fresco extensions but we were not

We opened an [issue on Picasso repository](https://github.com/square/picasso/issues/2067) and a [labeled Fresco question on Stack Overflow](https://stackoverflow.com/questions/54773198/fresco-how-to-use-scaletypes-focuscrop-based-on-bitmap-content) asking for guidance, but sadly we did not find much support. If you know how to assemble Glimpse cropping functionality to either lib without disrupting their original pipeline, please open an issue to review together the proposal. We really want to offer support for all the popular loading image libraries!

### Java callers
If you're using Java you can take a look at this [file](https://github.com/the-super-toys/glimpse-android/blob/master/sample-app/src/main/java/glimpse/sample/TestingApiFromJava.java) to see how Glimpse api looks for Java callers.

## Sample app
`:sample-app` module showcase Glimpse usage by making use of Glide extensions. The application is also published on [Google Play](https://play.google.com/store/apps/details?id=glimpse.sample).
Expand Down
6 changes: 6 additions & 0 deletions glimpse-core/src/main/java/glimpse/core/BitmapExtensions.kt
@@ -1,3 +1,5 @@
@file:JvmName("BitmapUtils")

package glimpse.core

import android.graphics.*
Expand All @@ -6,6 +8,8 @@ import org.tensorflow.lite.Interpreter
import kotlin.math.max
import kotlin.math.min


@JvmOverloads
fun Bitmap.crop(
centerX: Float,
centerY: Float,
Expand Down Expand Up @@ -41,6 +45,7 @@ fun Bitmap.crop(
return target
}

@JvmOverloads
fun Bitmap.debugHeatMap(
temperature: Float = 0.2f,
lowerBound: Float = 0.25f
Expand Down Expand Up @@ -103,6 +108,7 @@ fun Bitmap.debugHeatMap(
}
}

@JvmOverloads
fun Bitmap.findCenter(
temperature: Float = 0.2f,
lowerBound: Float = 0.25f
Expand Down
1 change: 1 addition & 0 deletions glimpse-core/src/main/java/glimpse/core/Glimpse.kt
Expand Up @@ -5,6 +5,7 @@ import android.app.Application
object Glimpse {
internal lateinit var client: Application

@JvmStatic
fun init(app: Application) {
client = app
}
Expand Down
30 changes: 30 additions & 0 deletions sample-app/src/main/java/glimpse/sample/TestingApiFromJava.java
@@ -0,0 +1,30 @@
package glimpse.sample;

import android.app.Application;
import android.graphics.Bitmap;
import glimpse.core.BitmapUtils;
import glimpse.core.Glimpse;
import glimpse.glide.GlimpseTransformation;
import kotlin.Pair;

public class TestingApiFromJava {

private static void howDoesItFeel() {
Application app = null;
Bitmap bitmap = null;

Glimpse.init(app);

Bitmap croppedBitmap = BitmapUtils.crop(bitmap, 0, 0, 0, 0, bitmap);
croppedBitmap = BitmapUtils.crop(bitmap, 0, 0, 0, 0);

Pair<Float, Float> focalPoints = BitmapUtils.findCenter(bitmap, 0, 0);
focalPoints = BitmapUtils.findCenter(bitmap);

Bitmap heatMap = BitmapUtils.debugHeatMap(bitmap, 0, 0);
heatMap = BitmapUtils.debugHeatMap(bitmap);

new GlimpseTransformation();
}

}