diff --git a/.gitignore b/.gitignore
index 43bb6ec3..e9e26752 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,18 +28,6 @@ proguard/
captures/
# IntelliJ
*.iml
-.idea/
-# .idea/workspace.xml
-# .idea/tasks.xml
-# .idea/gradle.xml
-# .idea/assetWizardSettings.xml
-# .idea/dictionaries
-.idea/libraries
-# Android Studio 3 in .gitignore file.
-.idea/caches
-.idea/modules.xml
-# Comment next line if keeping position of elements in Navigation Editor is relevant for you
-.idea/navEditor.xml
# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
*.jks
@@ -68,7 +56,4 @@ lint/outputs/
lint/tmp/
# lint/reports/
# MacOS
-.DS_Store
-# App Specific cases
-app/release/output.json
-.idea/codeStyles/
\ No newline at end of file
+.DS_Store
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..9698cfc1
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,9 @@
+/codeStyles
+/inspectionProfiles
+/libraries
+# Android Studio 3 in .gitignore file.
+/caches
+modules.xml
+# Comment next line if keeping position of elements in Navigation Editor is relevant for you
+navEditor.xml
+jarRepositories.xml
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100644
index ae78c113..00000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,113 +0,0 @@
-
-
-
-
-
-
-
-
-
- xmlns:android
-
- ^$
-
-
-
-
-
-
-
-
- xmlns:.*
-
- ^$
-
-
- BY_NAME
-
-
-
-
-
-
- .*:id
-
- http://schemas.android.com/apk/res/android
-
-
-
-
-
-
-
-
- .*:name
-
- http://schemas.android.com/apk/res/android
-
-
-
-
-
-
-
-
- name
-
- ^$
-
-
-
-
-
-
-
-
- style
-
- ^$
-
-
-
-
-
-
-
-
- .*
-
- ^$
-
-
- BY_NAME
-
-
-
-
-
-
- .*
-
- http://schemas.android.com/apk/res/android
-
-
- ANDROID_ATTRIBUTE_ORDER
-
-
-
-
-
-
- .*
-
- .*
-
-
- BY_NAME
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
deleted file mode 100644
index a55e7a17..00000000
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
deleted file mode 100644
index 73ab2c85..00000000
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
deleted file mode 100644
index 11ec93cf..00000000
--- a/.idea/jarRepositories.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 223caa4b..72cf020c 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,41 +1,10 @@
-
-
-
-
-
-
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1ddf..00000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 4f184b51..f5cb1397 100644
--- a/README.md
+++ b/README.md
@@ -86,6 +86,8 @@ val config = ImagePickerConfig(
launcher.launch(config)
```
+Java example: [MainActivity.java](example/src/main/java/com/imagepicker/example/java/MainActivity.java)
+
## Configuration options
| Option | Description | Default value
diff --git a/example/.gitignore b/example/.gitignore
index 43bb6ec3..9c4e755b 100644
--- a/example/.gitignore
+++ b/example/.gitignore
@@ -28,18 +28,6 @@ proguard/
captures/
# IntelliJ
*.iml
-.idea/
-# .idea/workspace.xml
-# .idea/tasks.xml
-# .idea/gradle.xml
-# .idea/assetWizardSettings.xml
-# .idea/dictionaries
-.idea/libraries
-# Android Studio 3 in .gitignore file.
-.idea/caches
-.idea/modules.xml
-# Comment next line if keeping position of elements in Navigation Editor is relevant for you
-.idea/navEditor.xml
# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
*.jks
@@ -70,5 +58,4 @@ lint/tmp/
# MacOS
.DS_Store
# App Specific cases
-app/release/output.json
-.idea/codeStyles/
\ No newline at end of file
+release/output.json
\ No newline at end of file
diff --git a/example/release/output.json b/example/release/output.json
deleted file mode 100644
index 6331a354..00000000
--- a/example/release/output.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "version": 1,
- "artifactType": {
- "type": "APK",
- "kind": "Directory"
- },
- "applicationId": "com.imagepicker.example",
- "variantName": "release",
- "elements": [
- {
- "type": "SINGLE",
- "filters": [],
- "properties": [],
- "versionCode": 1,
- "versionName": "1",
- "enabled": true,
- "outputFile": "example-release.apk"
- }
- ]
-}
\ No newline at end of file
diff --git a/example/src/main/java/com/imagepicker/example/java/JvmContextProvider.java b/example/src/main/java/com/imagepicker/example/java/JvmContextProvider.java
new file mode 100644
index 00000000..5fde3c71
--- /dev/null
+++ b/example/src/main/java/com/imagepicker/example/java/JvmContextProvider.java
@@ -0,0 +1,37 @@
+package com.imagepicker.example.java;
+
+import android.app.Activity;
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
+import kotlin.jvm.functions.Function0;
+
+public class JvmContextProvider implements Function0 {
+
+ @Nullable
+ private Activity hostAct;
+ @Nullable
+ private Fragment hostFrag;
+
+ public JvmContextProvider(@NonNull Activity host) {
+ this.hostAct = host;
+ }
+
+ public JvmContextProvider(@NonNull Fragment host) {
+ this.hostFrag = host;
+ }
+
+ @Override
+ public Context invoke() {
+ if (hostAct != null) {
+ return hostAct;
+ } else if (hostFrag != null) {
+ return hostFrag.requireContext();
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/example/src/main/java/com/imagepicker/example/java/JvmImagePickerCallback.java b/example/src/main/java/com/imagepicker/example/java/JvmImagePickerCallback.java
new file mode 100644
index 00000000..0b0c02f9
--- /dev/null
+++ b/example/src/main/java/com/imagepicker/example/java/JvmImagePickerCallback.java
@@ -0,0 +1,19 @@
+package com.imagepicker.example.java;
+
+import com.nguyenhoanglam.imagepicker.model.Image;
+
+import java.util.ArrayList;
+
+import kotlin.Unit;
+import kotlin.jvm.functions.Function1;
+
+public interface JvmImagePickerCallback extends Function1, Unit> {
+
+ void onImagePickerResult(ArrayList images);
+
+ @Override
+ default Unit invoke(ArrayList images) {
+ this.onImagePickerResult(images);
+ return null;
+ }
+}
diff --git a/example/src/main/java/com/imagepicker/example/java/MainActivity.java b/example/src/main/java/com/imagepicker/example/java/MainActivity.java
new file mode 100644
index 00000000..71ae8141
--- /dev/null
+++ b/example/src/main/java/com/imagepicker/example/java/MainActivity.java
@@ -0,0 +1,44 @@
+package com.imagepicker.example.java;
+
+import android.os.Bundle;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+
+import com.nguyenhoanglam.imagepicker.model.Image;
+import com.nguyenhoanglam.imagepicker.model.ImagePickerConfig;
+import com.nguyenhoanglam.imagepicker.ui.imagepicker.ImagePicker;
+import com.nguyenhoanglam.imagepicker.ui.imagepicker.ImagePickerLauncher;
+
+import java.util.ArrayList;
+
+public class MainActivity extends AppCompatActivity {
+
+ private final ImagePickerLauncher launcher = ImagePicker.registerImagePicker(
+ this,
+ new JvmContextProvider(this),
+ new JvmImagePickerCallback() {
+ @Override
+ public void onImagePickerResult(ArrayList images) {
+ // TODO handle image result
+ }
+ }
+ );
+
+ private final ImagePickerLauncher launcherLambda = ImagePicker.registerImagePicker(
+ this,
+ () -> this,
+ (ArrayList images) -> {
+ // TODO handle image result
+ return null;
+ }
+ );
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ ImagePickerConfig config = new ImagePickerConfig();
+ // TODO config.setSomething();
+ launcher.launch(config);
+ }
+}
diff --git a/imagepicker/src/main/java/com/nguyenhoanglam/imagepicker/ui/imagepicker/ImagePicker.kt b/imagepicker/src/main/java/com/nguyenhoanglam/imagepicker/ui/imagepicker/ImagePicker.kt
index d347a039..e2b38086 100644
--- a/imagepicker/src/main/java/com/nguyenhoanglam/imagepicker/ui/imagepicker/ImagePicker.kt
+++ b/imagepicker/src/main/java/com/nguyenhoanglam/imagepicker/ui/imagepicker/ImagePicker.kt
@@ -3,6 +3,8 @@
* Author: Nguyen Hoang Lam
*/
+@file:JvmName("ImagePicker")
+
package com.nguyenhoanglam.imagepicker.ui.imagepicker
import android.content.Context
@@ -55,6 +57,7 @@ fun getImages(data: Intent?): ArrayList {
else arrayListOf()
}
+@JvmOverloads
fun ComponentActivity.registerImagePicker(
context: () -> Context = { this },
callback: ImagePickerCallback
@@ -62,6 +65,7 @@ fun ComponentActivity.registerImagePicker(
return ImagePickerLauncher(context, createLauncher(callback))
}
+@JvmOverloads
fun Fragment.registerImagePicker(
context: () -> Context = { requireContext() },
callback: ImagePickerCallback