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

Commit

Permalink
Merge pull request #97 from natsuite/android-23
Browse files Browse the repository at this point in the history
Upgrade to Android 23
  • Loading branch information
olokobayusuf authored Nov 25, 2020
2 parents 3b916fd + dc413b4 commit 36ab100
Show file tree
Hide file tree
Showing 79 changed files with 1,668 additions and 654 deletions.
11 changes: 9 additions & 2 deletions Android/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
build/
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions Android/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Android/.idea/caches/build_file_checksums.ser
Binary file not shown.
6 changes: 6 additions & 0 deletions Android/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Android/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Android/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Android/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1600100630597</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions Android/NatShare/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1600100630616</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
12 changes: 6 additions & 6 deletions Android/NatShare/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: "com.android.library"

android {
compileSdkVersion 'android-R'
buildToolsVersion "30.0.0rc1"
compileSdkVersion "android-R"
ndkVersion "21.1.6352462"

defaultConfig {
minSdkVersion 22
minSdkVersion 24
versionCode 1
versionName "1.0"
externalNativeBuild {
Expand Down Expand Up @@ -39,13 +39,13 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation "androidx.appcompat:appcompat:1.0.0"
implementation project(":Unity")
}

task copyToUnity(type: Copy) {
from 'build/outputs/aar/NatShare-release.aar'
into '../../Assets/NatSuite/Plugins/Android'
from "build/outputs/aar/NatShare-release.aar"
into "../../Assets/NatSuite/NatShare/Plugins/Android"
rename '(.+)-release(.+)', '$1$2'
}

Expand Down
41 changes: 17 additions & 24 deletions Android/NatShare/src/main/cpp/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,56 @@ static JNIEnv* GetEnv ();
static jobject CreateCallback (JNIEnv* env, NSShareHandler completionHandler, void* context);


#pragma region --NatCorder--
#pragma region --NatShare--

void* NSCreateSharePayload (NSShareHandler completionHandler, void* context) {
void* NSCreateSharePayload () {
// Get Java environment
JNIEnv* env = GetEnv();
if (!env)
return nullptr;
// Create callback
jobject callback = completionHandler ? CreateCallback(env, completionHandler, context) : nullptr;
jclass clazz = env->FindClass("api/natsuite/natshare/SharePayload");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Lapi/natsuite/natshare/Payload$Callback;)V");
// Create payload
jobject object = env->NewObject(clazz, constructor, callback);
jclass clazz = env->FindClass("api/natsuite/natshare/SharePayload");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "()V");
jobject object = env->NewObject(clazz, constructor);
jobject payload = env->NewGlobalRef(object);
// Release locals
if (callback)
env->DeleteLocalRef(callback);
env->DeleteLocalRef(clazz);
env->DeleteLocalRef(object);
return static_cast<void*>(payload);
}

void* NSCreateSavePayload (const char* album, NSShareHandler completionHandler, void* context) {
void* NSCreateSavePayload (const char* album) {
// Get Java environment
JNIEnv* env = GetEnv();
if (!env)
return nullptr;
// Create callback
jstring albumStr = album ? env->NewStringUTF(album) : nullptr;
jobject callback = completionHandler ? CreateCallback(env, completionHandler, context) : nullptr;
jclass clazz = env->FindClass("api/natsuite/natshare/SavePayload");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Ljava/lang/String;Lapi/natsuite/natshare/Payload$Callback;)V");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(Ljava/lang/String;)V");
// Create payload
jobject object = env->NewObject(clazz, constructor, albumStr, callback);
jobject object = env->NewObject(clazz, constructor, albumStr);
jobject payload = env->NewGlobalRef(object);
// Release locals
if (albumStr)
env->DeleteLocalRef(albumStr);
if (callback)
env->DeleteLocalRef(callback);
env->DeleteLocalRef(clazz);
env->DeleteLocalRef(object);
return static_cast<void*>(payload);
}

void* NSCreatePrintPayload (bool color, bool landscape, NSShareHandler completionHandler, void* context) {
void* NSCreatePrintPayload (bool color, bool landscape) {
// Get Java environment
JNIEnv* env = GetEnv();
if (!env)
return nullptr;
// Create callback
jobject callback = completionHandler ? CreateCallback(env, completionHandler, context) : nullptr;
jclass clazz = env->FindClass("api/natsuite/natshare/PrintPayload");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(ZZLapi/natsuite/natshare/Payload$Callback;)V");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "(ZZ)V");
// Create payload
jobject object = env->NewObject(clazz, constructor, color, landscape, callback);
jobject object = env->NewObject(clazz, constructor, color, landscape);
jobject payload = env->NewGlobalRef(object);
// Release locals
if (callback)
env->DeleteLocalRef(callback);
env->DeleteLocalRef(clazz);
env->DeleteLocalRef(object);
return static_cast<void*>(payload);
Expand Down Expand Up @@ -127,18 +117,21 @@ void NSAddMedia (void* payloadPtr, const char* pathPtr) {
env->DeleteLocalRef(clazz);
}

void NSCommit (void* payloadPtr) {
void NSCommit (void* payloadPtr, NSShareHandler completionHandler, void* context) {
// Get Java environment
JNIEnv* env = GetEnv();
if (!env)
return;
// Invoke method
jobject callback = completionHandler ? CreateCallback(env, completionHandler, context) : nullptr;
jobject payload = static_cast<jobject>(payloadPtr);
jclass clazz = env->GetObjectClass(payload);
jmethodID method = env->GetMethodID(clazz, "commit", "()V");
env->CallVoidMethod(payload, method);
jmethodID method = env->GetMethodID(clazz, "commit", "(Lapi/natsuite/natshare/Payload$Callback;)V");
env->CallVoidMethod(payload, method, callback);
// Release locals
env->DeleteLocalRef(clazz);
if (callback)
env->DeleteLocalRef(callback);
}
#pragma endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ interface Callback {

void addMedia (String uri);

void commit ();
void commit (Callback completionHandler);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

import androidx.print.PrintHelper;
import com.unity3d.player.UnityPlayer;

import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand All @@ -18,15 +16,13 @@
public final class PrintPayload implements Payload {

private final PrintHelper printHelper;
private final Callback completionHandler;
private final ArrayList<Bitmap> images;
private final ArrayList<Uri> files;
private int remaining;

public PrintPayload (boolean color, boolean landscape, Callback completionHandler) {
public PrintPayload (boolean color, boolean landscape) {
// Init state
this.printHelper = new PrintHelper(UnityPlayer.currentActivity);
this.completionHandler = completionHandler;
this.images = new ArrayList<>();
this.files = new ArrayList<>();
// Configure printing
Expand All @@ -35,10 +31,10 @@ public PrintPayload (boolean color, boolean landscape, Callback completionHandle
}

@Override
public void addText (String text) { } // Not implemented
public void addText (final String text) { } // Not implemented

@Override
public void addImage (ByteBuffer jpegData) {
public void addImage (final ByteBuffer jpegData) {
// Read into managed memory
final byte[] buffer = new byte[jpegData.capacity()];
jpegData.clear();
Expand All @@ -49,12 +45,14 @@ public void addImage (ByteBuffer jpegData) {
}

@Override
public void addMedia (String uri) {
files.add(Uri.fromFile(new File(uri)));
public void addMedia (final String path) {
File file = new File(path);
if (file.exists())
files.add(Uri.fromFile(file));
}

@Override
public void commit () {
public void commit (final Callback completionHandler) {
// Check if supported
if (!printHelper.systemSupportsPrint()) {
completionHandler.onCompletion(false);
Expand Down
Loading

0 comments on commit 36ab100

Please sign in to comment.