Skip to content

Commit 93085b2

Browse files
committed
Merge pull request #45 from adjust/bool_fix
Fixing bool handling in JNI and updating example GUI
2 parents 73757c5 + db488bd commit 93085b2

File tree

5 files changed

+85
-52
lines changed

5 files changed

+85
-52
lines changed

Assets/Adjust/Adjust.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace com.adjust.sdk
77
{
88
public class Adjust : MonoBehaviour
99
{
10-
private const string sdkPrefix = "unity4.0.0";
10+
private const string sdkPrefix = "unity4.0.1";
1111
private const string errorMessage = "adjust: SDK not started. Start it manually using the 'appDidLaunch' method.";
1212

1313
private static IAdjust instance = null;

Assets/Adjust/Android/AdjustAndroid.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -116,43 +116,16 @@ public void trackEvent (AdjustEvent adjustEvent)
116116

117117
public bool isEnabled ()
118118
{
119-
var ajo = ajcAdjust.CallStatic<AndroidJavaObject> ("isEnabled");
120-
return ConvertBoolFromJava (ajo) ?? false;
119+
return ajcAdjust.CallStatic<bool> ("isEnabled");
121120
}
122121

123122
public void setEnabled(bool enabled) {
124-
ajcAdjust.CallStatic ("setEnabled", ConvertBoolToJava(enabled));
123+
ajcAdjust.CallStatic ("setEnabled", enabled);
125124
}
126125

127126
public void setOfflineMode(bool enabled)
128127
{
129-
ajcAdjust.CallStatic ("setOfflineMode", ConvertBoolToJava (enabled));
130-
}
131-
132-
#endregion
133-
134-
#region Private & helper methods
135-
136-
private AndroidJavaObject ConvertBoolToJava(bool value)
137-
{
138-
AndroidJavaObject javaBool = new AndroidJavaObject ("java.lang.Boolean", value.ToString ().ToLower ());
139-
140-
return javaBool;
141-
}
142-
143-
private bool? ConvertBoolFromJava (AndroidJavaObject ajo)
144-
{
145-
if (ajo == null) {
146-
return null;
147-
}
148-
149-
var sBool = ajo.Call<string> ("toString");
150-
151-
try {
152-
return Convert.ToBoolean (sBool);
153-
} catch (FormatException) {
154-
return null;
155-
}
128+
ajcAdjust.CallStatic ("setOfflineMode", enabled);
156129
}
157130

158131
#endregion

Assets/Adjust/ExampleGUI/ExampleGUI.cs

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,56 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
23
using System.Runtime.InteropServices;
34

45
using UnityEngine;
6+
using UnityEngine.UI;
57
using com.adjust.sdk;
68

79
public class ExampleGUI : MonoBehaviour
810
{
9-
private int nr_buttons = 5;
10-
private static bool? isEnabled;
11+
private int nr_buttons = 8;
12+
13+
private static bool isEnabled;
14+
private bool showPopUp = false;
15+
16+
private string txtManualLaunch = "Manual Launch";
17+
private string txtSetOfflineMode = "Turn Offline Mode ON";
18+
private string txtSetEnabled = "Disable SDK";
1119

1220
void OnGUI ()
1321
{
14-
if (GUI.Button (new Rect (0, Screen.height * 0 / nr_buttons, Screen.width, Screen.height / nr_buttons), "Manual Launch")) {
15-
AdjustConfig adjustConfig = new AdjustConfig ("{YourAppToken}", AdjustEnvironment.Sandbox);
16-
adjustConfig.setLogLevel (AdjustLogLevel.Verbose);
17-
adjustConfig.setAttributionChangedDelegate (this.attributionChangedDelegate);
18-
19-
Adjust.start (adjustConfig);
20-
isEnabled = true;
22+
if (showPopUp) {
23+
GUI.Window(0, new Rect((Screen.width / 2) - 150, (Screen.height / 2) - 65, 300, 130), showGUI, "Is SDK enabled?");
24+
}
25+
26+
if (GUI.Button (new Rect (0, Screen.height * 0 / nr_buttons, Screen.width, Screen.height / nr_buttons), txtManualLaunch)) {
27+
if (!string.Equals(txtManualLaunch, "SDK Launched", StringComparison.OrdinalIgnoreCase)) {
28+
AdjustConfig adjustConfig = new AdjustConfig ("{YourAppToken}", AdjustEnvironment.Sandbox);
29+
adjustConfig.setLogLevel (AdjustLogLevel.Verbose);
30+
adjustConfig.setAttributionChangedDelegate (this.attributionChangedDelegate);
31+
32+
Adjust.start (adjustConfig);
33+
isEnabled = true;
34+
35+
txtManualLaunch = "SDK Launched";
36+
}
2137
}
2238

2339
if (GUI.Button (new Rect (0, Screen.height * 1 / nr_buttons, Screen.width, Screen.height / nr_buttons), "Track Simple Event")) {
24-
AdjustEvent adjustEvent = new AdjustEvent ("{EventToken}");
40+
AdjustEvent adjustEvent = new AdjustEvent ("{YourEventToken}");
2541

2642
Adjust.trackEvent (adjustEvent);
2743
}
2844

2945
if (GUI.Button (new Rect (0, Screen.height * 2 / nr_buttons, Screen.width, Screen.height / nr_buttons), "Track Revenue Event")) {
30-
AdjustEvent adjustEvent = new AdjustEvent ("{EventToken}");
46+
AdjustEvent adjustEvent = new AdjustEvent ("{YourEventToken}");
3147
adjustEvent.setRevenue (0.25, "EUR");
3248

3349
Adjust.trackEvent (adjustEvent);
3450
}
3551

3652
if (GUI.Button (new Rect (0, Screen.height * 3 / nr_buttons, Screen.width, Screen.height / nr_buttons), "Track Callback Event")) {
37-
AdjustEvent adjustEvent = new AdjustEvent ("{EventToken}");
53+
AdjustEvent adjustEvent = new AdjustEvent ("{YourEventToken}");
3854

3955
adjustEvent.addCallbackParameter ("key", "value");
4056
adjustEvent.addCallbackParameter ("foo", "bar");
@@ -43,14 +59,58 @@ void OnGUI ()
4359
}
4460

4561
if (GUI.Button (new Rect (0, Screen.height * 4 / nr_buttons, Screen.width, Screen.height / nr_buttons), "Track Partner Event")) {
46-
AdjustEvent adjustEvent = new AdjustEvent ("{EventToken}");
62+
AdjustEvent adjustEvent = new AdjustEvent ("{YourEventToken}");
4763

4864
adjustEvent.addPartnerParameter ("key", "value");
4965
adjustEvent.addPartnerParameter ("foo", "bar");
5066

5167
Adjust.trackEvent (adjustEvent);
5268
}
69+
70+
if (GUI.Button (new Rect (0, Screen.height * 5 / nr_buttons, Screen.width, Screen.height / nr_buttons), txtSetOfflineMode)) {
71+
if (string.Equals(txtSetOfflineMode, "Turn Offline Mode ON", StringComparison.OrdinalIgnoreCase)) {
72+
Adjust.setOfflineMode(true);
73+
74+
txtSetOfflineMode = "Turn Offline Mode OFF";
75+
} else {
76+
Adjust.setOfflineMode(false);
77+
78+
txtSetOfflineMode = "Turn Offline Mode ON";
79+
}
80+
}
81+
82+
if (GUI.Button (new Rect (0, Screen.height * 6 / nr_buttons, Screen.width, Screen.height / nr_buttons), txtSetEnabled)) {
83+
if (string.Equals(txtSetEnabled, "Disable SDK", StringComparison.OrdinalIgnoreCase)) {
84+
Adjust.setEnabled(false);
85+
86+
txtSetEnabled = "Enable SDK";
87+
} else {
88+
Adjust.setEnabled(true);
89+
90+
txtSetEnabled = "Disable SDK";
91+
}
92+
}
93+
94+
if (GUI.Button (new Rect (0, Screen.height * 7 / nr_buttons, Screen.width, Screen.height / nr_buttons), "Is SDK Enabled?")) {
95+
isEnabled = Adjust.isEnabled();
96+
97+
showPopUp = true;
98+
}
5399
}
100+
101+
void showGUI(int windowID)
102+
{
103+
104+
if (isEnabled) {
105+
GUI.Label(new Rect(65, 40, 200, 30), "Adjust SDK is ENABLED!");
106+
} else {
107+
GUI.Label(new Rect(65, 40, 200, 30), "Adjust SDK is DISABLED!");
108+
}
109+
110+
if (GUI.Button(new Rect(90, 75, 120, 40), "OK")) {
111+
showPopUp = false;
112+
}
113+
}
54114

55115
public void attributionChangedDelegate (AdjustAttribution attribution)
56116
{

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.0
1+
4.0.1

doc/migrate.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
## Migrate your adjust SDK for Unity3d to 4.0.0 from 3.4.4
1+
## Migrate your adjust SDK for Unity3d to 4.0.1 from 3.4.4
22

3-
N.B. At the moment, SDK 4.0 for Unity supports Android and iOS, but not Windows. If you are planning to release your Unity app on Windows, please migrate to 4.0 only when we add full support for Windows.
3+
N.B. At the moment, SDK 4.0.1 for Unity supports Android and iOS, but not Windows. If you are planning to release your Unity app on Windows, please migrate to 4.0.1 only when we add full support for Windows.
44

55
### Migration procedure
66

7-
Starting from version 4.0.0, the structure of this repository is adjusted to Unity 5. All files which are part of the
7+
Starting from version 4.0.1, the structure of this repository is adjusted to Unity 5. All files which are part of the
88
adjust SDK are now moved to the `Assets/Adjust` folder, since Unity 5 allows that native files can now be placed
99
outside of `Assets/Plugins` folder. This is done so that adjust files are no longer mixed with files you may be
1010
keeping in `Assets/Plugins` folder.
1111

1212
For migration purposes, we have prepared two Unity packages:
1313

14-
* `Adjust_v4.0.0_Unity_4.unitypackage` (for Unity 4 users)
15-
* `Adjust_v4.0.0_Unity_5.unitypackage` (for Unity 5 users)
14+
* `Adjust_v4.0.1_Unity_4.unitypackage` (for Unity 4 users)
15+
* `Adjust_v4.0.1_Unity_5.unitypackage` (for Unity 5 users)
1616

1717
and the adjust SDK uninstall script written in Python (`adjust_uninstall.py`).
1818

19-
Migration to version 4.0.0 of our SDK requires the following steps:
19+
Migration to version 4.0.1 of our SDK requires the following steps:
2020

2121
1. Copy the `adjust_uninstall.py` script to your root Unity project directory and run it. This script should
2222
delete all adjust source files from the previous SDK version you had.

0 commit comments

Comments
 (0)