2020-07-21 20:26:52 +02:00
|
|
|
using System;
|
2020-06-14 01:18:12 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Android.App;
|
2020-06-30 19:06:35 +02:00
|
|
|
using Android.Content;
|
2020-06-14 01:18:12 +02:00
|
|
|
using Android.Gms.Ads;
|
2020-07-21 20:26:52 +02:00
|
|
|
using Android.Gms.Common;
|
|
|
|
using Android.Gms.Common.Apis;
|
|
|
|
using Android.Gms.Extensions;
|
|
|
|
using Android.Gms.Games;
|
2020-07-21 21:51:30 +02:00
|
|
|
using Android.Gms.Games.Achievement;
|
2020-07-08 18:23:57 +02:00
|
|
|
using Android.Runtime;
|
2020-06-29 13:47:45 +02:00
|
|
|
using Android.Views;
|
2020-06-14 01:18:12 +02:00
|
|
|
using Android.Widget;
|
2020-07-21 20:26:52 +02:00
|
|
|
using Coroutine;
|
2020-06-14 01:18:12 +02:00
|
|
|
using GameAnalyticsSDK;
|
|
|
|
using GameAnalyticsSDK.Utilities;
|
|
|
|
using TouchyTickets;
|
2020-07-21 21:51:30 +02:00
|
|
|
using Achievement = TouchyTickets.Achievement;
|
2020-07-21 20:26:52 +02:00
|
|
|
using Uri = Android.Net.Uri;
|
2020-06-14 01:18:12 +02:00
|
|
|
|
|
|
|
namespace Android {
|
|
|
|
public class AndroidPlatform : Platform {
|
|
|
|
|
2020-07-21 20:26:52 +02:00
|
|
|
public const int GooglePlayLoginRequest = 9001;
|
2020-07-21 21:51:30 +02:00
|
|
|
public const int ShowAchievementsRequest = 9002;
|
|
|
|
|
|
|
|
private static readonly Dictionary<string, string> AchievementIds = new Dictionary<string, string> {
|
|
|
|
{"1Stars", "CgkI_Lyp7PcEEAIQAw"},
|
|
|
|
{"10Stars", "CgkI_Lyp7PcEEAIQBA"},
|
|
|
|
{"100Stars", "CgkI_Lyp7PcEEAIQBQ"},
|
|
|
|
{"FullMap", "CgkI_Lyp7PcEEAIQBg"},
|
|
|
|
{"OnlySmallRides", "CgkI_Lyp7PcEEAIQBw"},
|
|
|
|
{"OnlyRelaxedRides", "CgkI_Lyp7PcEEAIQCA"},
|
|
|
|
{"OnlyWalkingRides", "CgkI_Lyp7PcEEAIQCQ"},
|
|
|
|
{"OnlyNonTechnologyRides", "CgkI_Lyp7PcEEAIQCg"},
|
|
|
|
{"100Modifiers", "CgkI_Lyp7PcEEAIQCw"},
|
|
|
|
{"500Modifiers", "CgkI_Lyp7PcEEAIQDA"},
|
|
|
|
{"1000Modifiers", "CgkI_Lyp7PcEEAIQDQ"},
|
|
|
|
{"5000Modifiers", "CgkI_Lyp7PcEEAIQDg"},
|
|
|
|
{"1.00MTickets", "CgkI_Lyp7PcEEAIQDw"},
|
|
|
|
{"1.00BTickets", "CgkI_Lyp7PcEEAIQEA"},
|
|
|
|
{"1.00TTickets", "CgkI_Lyp7PcEEAIQEQ"},
|
|
|
|
{"1.00QTickets", "CgkI_Lyp7PcEEAIQEg"},
|
|
|
|
{"1.00QiTickets", "CgkI_Lyp7PcEEAIQEw"},
|
|
|
|
{"1.00STickets", "CgkI_Lyp7PcEEAIQFA"},
|
|
|
|
{"1.00SpTickets", "CgkI_Lyp7PcEEAIQFQ"},
|
|
|
|
{"1.00OTickets", "CgkI_Lyp7PcEEAIQFg"},
|
|
|
|
{"1.00NTickets", "CgkI_Lyp7PcEEAIQFw"},
|
|
|
|
{"1.00DTickets", "CgkI_Lyp7PcEEAIQGA"}
|
|
|
|
};
|
|
|
|
|
2020-06-14 01:18:12 +02:00
|
|
|
private readonly Activity activity;
|
|
|
|
private readonly LinearLayout adLayout;
|
2020-07-21 20:26:52 +02:00
|
|
|
public GoogleApiClient GoogleApi { get; private set; }
|
2020-06-14 01:18:12 +02:00
|
|
|
|
|
|
|
public AndroidPlatform(Activity activity, LinearLayout adLayout) {
|
|
|
|
this.activity = activity;
|
|
|
|
this.adLayout = adLayout;
|
|
|
|
}
|
|
|
|
|
2020-07-21 20:26:52 +02:00
|
|
|
public override void SetupOnlineInteractions(Dictionary<string, object> analyticsJson) {
|
|
|
|
// Analytics
|
|
|
|
GameAnalytics.SetAutoDetectAppVersion(true);
|
|
|
|
GameAnalytics.Initialize(this.activity, GA_MiniJSON.JsonEncode(new Hashtable(analyticsJson)));
|
|
|
|
AndroidEnvironment.UnhandledExceptionRaiser += (o, args) => GameAnalytics.NewErrorEvent(GAErrorSeverity.Critical, args.Exception.ToString());
|
|
|
|
|
|
|
|
// Ads
|
2020-06-14 01:18:12 +02:00
|
|
|
var ad = new AdView(this.activity) {
|
|
|
|
AdUnitId = "ca-app-pub-5754829579653773/7841535920",
|
|
|
|
AdSize = AdSize.SmartBanner
|
|
|
|
};
|
|
|
|
ad.LoadAd(new AdRequest.Builder()
|
|
|
|
.AddTestDevice("14B965C6457E17D2808061ADF7E34923")
|
|
|
|
.Build());
|
|
|
|
this.adLayout.AddView(ad);
|
|
|
|
|
2020-07-21 20:26:52 +02:00
|
|
|
// Google Play game services
|
|
|
|
this.GoogleApi = new GoogleApiClient.Builder(this.activity)
|
|
|
|
.AddApi(GamesClass.API)
|
|
|
|
.AddScope(GamesClass.ScopeGames)
|
|
|
|
.AddOnConnectionFailedListener(res => {
|
|
|
|
if (res.HasResolution) {
|
|
|
|
res.StartResolutionForResult(this.activity, GooglePlayLoginRequest);
|
|
|
|
} else {
|
|
|
|
throw new GoogleApiClientConnectionException(res);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.Build();
|
|
|
|
this.GoogleApi.Connect();
|
2020-07-21 21:51:30 +02:00
|
|
|
|
|
|
|
// Sanity check to ensure that all achievements are mapped
|
|
|
|
foreach (var achievement in Achievement.Achievements.Values) {
|
|
|
|
var _ = AchievementIds[achievement.Name];
|
|
|
|
}
|
2020-06-14 01:18:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId) {
|
|
|
|
GameAnalytics.NewResourceEvent(sink ? GAResourceFlowType.Sink : GAResourceFlowType.Source, currency, amount, itemType, itemId);
|
|
|
|
}
|
|
|
|
|
2020-06-29 13:47:45 +02:00
|
|
|
public override void SetKeepScreenOn(bool keep) {
|
|
|
|
if (keep) {
|
|
|
|
this.activity.Window.AddFlags(WindowManagerFlags.KeepScreenOn);
|
|
|
|
} else {
|
|
|
|
this.activity.Window.ClearFlags(WindowManagerFlags.KeepScreenOn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-30 19:06:35 +02:00
|
|
|
public override void OpenRateLink() {
|
|
|
|
this.activity.StartActivity(new Intent(Intent.ActionView, Uri.Parse("https://play.google.com/store/apps/details?id=de.ellpeck.touchytickets")));
|
|
|
|
}
|
|
|
|
|
2020-07-21 21:51:30 +02:00
|
|
|
public override void GainAchievement(Achievement achievement) {
|
|
|
|
if (this.GoogleApi != null)
|
|
|
|
GamesClass.Achievements.Unlock(this.GoogleApi, AchievementIds[achievement.Name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void ShowAchievements() {
|
|
|
|
if (this.GoogleApi == null)
|
|
|
|
return;
|
|
|
|
var intent = GamesClass.Achievements.GetAchievementsIntent(this.GoogleApi);
|
|
|
|
this.activity.StartActivityForResult(intent, ShowAchievementsRequest);
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:18:12 +02:00
|
|
|
}
|
|
|
|
}
|