-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added query methods to support Android SDK 1.3.x
- Loading branch information
1 parent
40436fd
commit 01b306a
Showing
36 changed files
with
2,721 additions
and
908 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
125 changes: 125 additions & 0 deletions
125
Assets/Zapic/Android/ZapicAndroidAuthenticationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#if !UNITY_EDITOR && UNITY_ANDROID | ||
|
||
using System; | ||
using UnityEngine; | ||
|
||
namespace ZapicSDK | ||
{ | ||
internal sealed class ZapicAndroidAuthenticationHandler : AndroidJavaProxy | ||
{ | ||
/// <summary>The <see cref="IZapicInterface"/> that communicates with the Zapic Android SDK.</summary> | ||
private readonly ZapicAndroidInterface platform; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ZapicAndroidAuthenticationHandler"/> class. | ||
/// </summary> | ||
/// <param name="platform"> | ||
/// The <see cref="IZapicInterface"/> that communicates with the Zapic Android SDK. | ||
/// </param> | ||
internal ZapicAndroidAuthenticationHandler(ZapicAndroidInterface platform) | ||
: base("com/zapic/sdk/android/ZapicPlayerAuthenticationHandler") | ||
{ | ||
this.platform = platform; | ||
} | ||
|
||
public void onLogin(AndroidJavaObject playerObject) | ||
{ | ||
try | ||
{ | ||
var handler = platform.OnLogin; | ||
if (handler == null) | ||
{ | ||
return; | ||
} | ||
|
||
ZapicPlayer player; | ||
try | ||
{ | ||
player = ZapicAndroidUtilities.ConvertPlayer(playerObject); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError("Zapic: An error occurred converting the Java object to ZapicPlayer"); | ||
Debug.LogException(e); | ||
return; | ||
} | ||
finally | ||
{ | ||
if (playerObject != null) | ||
{ | ||
playerObject.Dispose(); | ||
playerObject = null; | ||
} | ||
} | ||
|
||
try | ||
{ | ||
handler(player); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError("Zapic: An error occurred invoking the application callback"); | ||
Debug.LogException(e); | ||
} | ||
} | ||
finally | ||
{ | ||
if (playerObject != null) | ||
{ | ||
playerObject.Dispose(); | ||
} | ||
} | ||
} | ||
|
||
public void onLogout(AndroidJavaObject playerObject) | ||
{ | ||
try | ||
{ | ||
var handler = platform.OnLogout; | ||
if (handler == null) | ||
{ | ||
return; | ||
} | ||
|
||
ZapicPlayer player; | ||
try | ||
{ | ||
player = ZapicAndroidUtilities.ConvertPlayer(playerObject); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError("Zapic: An error occurred converting the Java object to ZapicPlayer"); | ||
Debug.LogException(e); | ||
return; | ||
} | ||
finally | ||
{ | ||
if (playerObject != null) | ||
{ | ||
playerObject.Dispose(); | ||
playerObject = null; | ||
} | ||
} | ||
|
||
try | ||
{ | ||
handler(player); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError("Zapic: An error occurred invoking the application callback"); | ||
Debug.LogException(e); | ||
} | ||
} | ||
finally | ||
{ | ||
if (playerObject != null) | ||
{ | ||
playerObject.Dispose(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
2 changes: 1 addition & 1 deletion
2
Assets/Zapic/ZapicPlayType.cs.meta → ...ZapicAndroidAuthenticationHandler.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
149 changes: 149 additions & 0 deletions
149
Assets/Zapic/Android/ZapicAndroidFunctionCallback{T}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#if !UNITY_EDITOR && UNITY_ANDROID | ||
|
||
using System; | ||
using UnityEngine; | ||
|
||
namespace ZapicSDK | ||
{ | ||
internal sealed class ZapicAndroidFunctionCallback<T> : AndroidJavaProxy | ||
where T : class | ||
{ | ||
/// <summary>The callback invoked with the result of the asynchronous query.</summary> | ||
private readonly Action<T, ZapicException> callback; | ||
|
||
/// <summary>The callback invoked to convert the result of the asynchronous query.</summary> | ||
private readonly Func<AndroidJavaObject, T> convertResult; | ||
|
||
/// <summary>Initializes a new instance of the <see cref="ZapicAndroidFunctionCallback{T}"/> class.</summary> | ||
/// <param name="callback">The callback invoked with the result of the asynchronous query.</param> | ||
/// <param name="convertResult">The callback invoked to convert the result of the asynchronous query.</param> | ||
/// <exception cref="ArgumentNullException"> | ||
/// If <paramref name="callback"/> or <paramref name="convertResult"/> are <c>null</c>. | ||
/// </exception> | ||
internal ZapicAndroidFunctionCallback( | ||
Action<T, ZapicException> callback, | ||
Func<AndroidJavaObject, T> convertResult) | ||
: base("com/zapic/sdk/android/ZapicCallback") | ||
{ | ||
if (callback == null) | ||
{ | ||
throw new ArgumentNullException("callback"); | ||
} | ||
|
||
if (convertResult == null) | ||
{ | ||
throw new ArgumentNullException("convertResult"); | ||
} | ||
|
||
this.callback = callback; | ||
this.convertResult = convertResult; | ||
} | ||
|
||
public void onComplete(AndroidJavaObject resultObject, AndroidJavaObject errorObject) | ||
{ | ||
try | ||
{ | ||
ZapicException error; | ||
try | ||
{ | ||
error = ZapicAndroidUtilities.ConvertError(errorObject); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError("Zapic: An error occurred converting the Java object to ZapicException"); | ||
Debug.LogException(e); | ||
|
||
error = new ZapicException( | ||
ZapicErrorCode.INVALID_RESPONSE, | ||
"An error occurred converting the Java object to ZapicException", | ||
e); | ||
} | ||
finally | ||
{ | ||
if (errorObject != null) | ||
{ | ||
errorObject.Dispose(); | ||
errorObject = null; | ||
} | ||
} | ||
|
||
if (error != null) | ||
{ | ||
if (resultObject != null) | ||
{ | ||
resultObject.Dispose(); | ||
resultObject = null; | ||
} | ||
|
||
try | ||
{ | ||
callback(null, error); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError("Zapic: An error occurred invoking the application callback"); | ||
Debug.LogException(e); | ||
} | ||
|
||
return; | ||
} | ||
|
||
T result; | ||
try | ||
{ | ||
result = convertResult(resultObject); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError("Zapic: An error occurred converting the Java object to " + typeof(T).Name); | ||
Debug.LogException(e); | ||
|
||
error = new ZapicException( | ||
ZapicErrorCode.INVALID_RESPONSE, | ||
"An error occurred converting the Java object to " + typeof(T).Name, | ||
e); | ||
result = null; | ||
} | ||
finally | ||
{ | ||
if (resultObject != null) | ||
{ | ||
resultObject.Dispose(); | ||
resultObject = null; | ||
} | ||
} | ||
|
||
try | ||
{ | ||
if (error != null) | ||
{ | ||
callback(null, error); | ||
} | ||
else | ||
{ | ||
callback(result, null); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError("Zapic: An error occurred invoking the application callback"); | ||
Debug.LogException(e); | ||
} | ||
} | ||
finally | ||
{ | ||
if (errorObject != null) | ||
{ | ||
errorObject.Dispose(); | ||
} | ||
|
||
if (resultObject != null) | ||
{ | ||
resultObject.Dispose(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
11 changes: 11 additions & 0 deletions
11
Assets/Zapic/Android/ZapicAndroidFunctionCallback{T}.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.