GetActivity() public static method

public static GetActivity ( ) : AndroidJavaObject
return AndroidJavaObject
Example #1
0
 private void DoGetAnotherServerAuthCode(bool reAuthenticateIfNeeded, Action <string> callback)
 {
     try
     {
         using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
             using (var currentActivity = AndroidHelperFragment.GetActivity())
                 using (var pendingResult = bridgeClass.CallStatic <AndroidJavaObject>(
                            "fetchToken",
                            currentActivity,
                            /* silent= */ reAuthenticateIfNeeded,
                            /* requestAuthCode= */ true,
                            /* requestEmail= */ false,
                            /* requestIdToken= */ false,
                            webClientId,
                            /* forceRefresh= */ false,
                            oauthScopes.ToArray(),
                            /* hidePopups= */ true,
                            /* accountName= */ ""))
                 {
                     pendingResult.Call("setResultCallback", new ResultCallbackProxy(
                                            tokenResult => { callback(tokenResult.Call <string>("getAuthCode")); }));
                 }
     }
     catch (Exception e)
     {
         OurUtils.Logger.e("Exception launching token request: " + e.Message);
         OurUtils.Logger.e(e.ToString());
     }
 }
Example #2
0
 public static void ShowCaptureOverlayUI()
 {
     using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
     {
         helperFragment.CallStatic("showCaptureOverlayUi", AndroidHelperFragment.GetActivity());
     }
 }
Example #3
0
        public static void ShowSelectSnapshotUI(bool showCreateSaveUI, bool showDeleteSaveUI,
                                                int maxDisplayedSavedGames, string uiTitle, Action <SelectUIStatus, ISavedGameMetadata> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (var task = helperFragment.CallStatic <AndroidJavaObject>("showSelectSnapshotUi",
                                                                                AndroidHelperFragment.GetActivity(), uiTitle, showCreateSaveUI, showDeleteSaveUI,
                                                                                maxDisplayedSavedGames))
                {
                    AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(
                        task,
                        result =>
                    {
                        SelectUIStatus status = (SelectUIStatus)result.Get <int>("status");
                        Debug.Log("ShowSelectSnapshotUI result " + status);

                        AndroidJavaObject javaMetadata   = result.Get <AndroidJavaObject>("metadata");
                        AndroidSnapshotMetadata metadata =
                            javaMetadata == null
                                ? null
                                : new AndroidSnapshotMetadata(javaMetadata, /* contents= */ null);

                        cb.Invoke(status, metadata);
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Debug.Log("ShowSelectSnapshotUI failed with exception");
                        cb.Invoke(SelectUIStatus.InternalError, null);
                    });
                }
        }
        public void RequestPermissions(string[] scopes, Action <SignInStatus> callback)
        {
            using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
                using (var currentActivity = AndroidHelperFragment.GetActivity())
                    using (var task =
                               bridgeClass.CallStatic <AndroidJavaObject>("showRequestPermissionsUi", currentActivity,
                                                                          oauthScopes.Union(scopes).ToArray()))
                    {
                        AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(task, /* disposeResult= */ false,
                                                                                  accountWithNewScopes =>
                        {
                            if (accountWithNewScopes == null)
                            {
                                callback(SignInStatus.InternalError);
                                return;
                            }

                            account     = accountWithNewScopes;
                            email       = account.Call <string>("getEmail");
                            idToken     = account.Call <string>("getIdToken");
                            authCode    = account.Call <string>("getServerAuthCode");
                            oauthScopes = oauthScopes.Union(scopes).ToList();
                            callback(SignInStatus.Success);
                        });

                        AndroidTaskUtils.AddOnFailureListener(task, e =>
                        {
                            var failCode = SignInHelper.ToSignInStatus(e.Call <int>("getStatusCode"));
                            OurUtils.Logger.e("Exception requesting new permissions: " + failCode);
                            callback(failCode);
                        });
                    }
        }
Example #5
0
        public static void ShowInvitationInboxUI(Action <UIStatus, Invitation> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (var task = helperFragment.CallStatic <AndroidJavaObject>("showInvitationInboxUI",
                                                                                AndroidHelperFragment.GetActivity()))
                {
                    AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(
                        task,
                        result =>
                    {
                        int status = result.Get <int>("status");
                        if ((UIStatus)status != UIStatus.Valid)
                        {
                            cb.Invoke((UIStatus)status, null);
                            return;
                        }

                        using (var invitation = result.Get <AndroidJavaObject>("invitation"))
                        {
                            cb.Invoke((UIStatus)status, AndroidJavaConverter.ToInvitation(invitation));
                        }
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Debug.Log("ShowInvitationInboxUI failed with exception");
                        cb.Invoke(UIStatus.InternalError, null);
                    });
                }
        }
 public string GetAppBundleId()
 {
     using (var activity = AndroidHelperFragment.GetActivity())
     {
         return(activity.Call <string>("getPackageName"));
     }
 }
Example #7
0
 public static AndroidJavaObject GetDefaultPopupView()
 {
     using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
         using (var activity = AndroidHelperFragment.GetActivity())
         {
             return(helperFragment.CallStatic <AndroidJavaObject>("getDecorView", activity));
         }
 }
Example #8
0
 public AndroidEventsClient(AndroidJavaObject account)
 {
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mEventsClient = gamesClass.CallStatic <AndroidJavaObject>("getEventsClient",
                                                                   AndroidHelperFragment.GetActivity(), account);
     }
 }
Example #9
0
 /// <summary>Returns whether or not user has given permissions for given scopes.</summary>
 /// <param name="scopes">array of scopes</param>
 /// <returns><c>true</c>, if given, <c>false</c> otherwise.</returns>
 public bool HasPermissions(string[] scopes)
 {
     using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
         using (var currentActivity = AndroidHelperFragment.GetActivity())
         {
             return(bridgeClass.CallStatic <bool>("hasPermissions", currentActivity, scopes));
         }
 }
Example #10
0
 public AndroidSavedGameClient(AndroidClient androidClient, AndroidJavaObject account)
 {
     mAndroidClient = androidClient;
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mSnapshotsClient = gamesClass.CallStatic <AndroidJavaObject>("getSnapshotsClient",
                                                                      AndroidHelperFragment.GetActivity(), account);
     }
 }
Example #11
0
 public AndroidVideoClient(bool isCaptureSupported, AndroidJavaObject account)
 {
     mIsCaptureSupported = isCaptureSupported;
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mVideosClient = gamesClass.CallStatic <AndroidJavaObject>("getVideosClient",
                                                                   AndroidHelperFragment.GetActivity(), account);
     }
 }
 public AndroidTurnBasedMultiplayerClient(AndroidClient androidClient, AndroidJavaObject account)
 {
     mAndroidClient = androidClient;
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mClient = gamesClass.CallStatic <AndroidJavaObject>("getTurnBasedMultiplayerClient",
                                                             AndroidHelperFragment.GetActivity(), account);
     }
 }
 public AndroidNearbyConnectionClient()
 {
     PlayGamesHelperObject.CreateObject();
     NearbyHelperObject.CreateObject(this);
     using (var nearbyClass = new AndroidJavaClass("com.google.android.gms.nearby.Nearby"))
     {
         mClient = nearbyClass.CallStatic <AndroidJavaObject>("getConnectionsClient",
                                                              AndroidHelperFragment.GetActivity());
     }
 }
Example #14
0
 public AndroidRealTimeMultiplayerClient(AndroidClient androidClient, AndroidJavaObject account)
 {
     mAndroidClient = androidClient;
     using (var gamesClass = new AndroidJavaClass("com.google.android.gms.games.Games"))
     {
         mRtmpClient = gamesClass.CallStatic <AndroidJavaObject>("getRealTimeMultiplayerClient",
                                                                 AndroidHelperFragment.GetActivity(), account);
         mInvitationsClient = gamesClass.CallStatic <AndroidJavaObject>("getInvitationsClient",
                                                                        AndroidHelperFragment.GetActivity(), account);
     }
 }
Example #15
0
 public void Signout()
 {
     account  = null;
     authCode = null;
     email    = null;
     idToken  = null;
     PlayGamesHelperObject.RunOnGameThread(() =>
     {
         Debug.Log("Calling Signout in token client");
         AndroidJavaClass cls = new AndroidJavaClass(HelperFragmentClass);
         cls.CallStatic("signOut", AndroidHelperFragment.GetActivity());
     });
 }
 private static string ReadServiceId()
 {
     using (var activity = AndroidHelperFragment.GetActivity())
     {
         string packageName = activity.Call <string>("getPackageName");
         using (var pm = activity.Call <AndroidJavaObject>("getPackageManager"))
             using (var appInfo =
                        pm.Call <AndroidJavaObject>("getApplicationInfo", packageName, ApplicationInfoFlags))
                 using (var bundle = appInfo.Get <AndroidJavaObject>("metaData"))
                 {
                     string sysId = bundle.Call <string>("getString",
                                                         "com.google.android.gms.nearby.connection.SERVICE_ID");
                     Debug.Log("SystemId from Manifest: " + sysId);
                     return(sysId);
                 }
     }
 }
Example #17
0
        private static void ShowSelectOpponentsUI(uint minOpponents, uint maxOpponents, bool isRealTime,
                                                  Action <UIStatus, InvitationResultHolder> cb)
        {
            string methodName = isRealTime ? "showRtmpSelectOpponentsUi" : "showTbmpSelectOpponentsUi";

            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (var task = helperFragment.CallStatic <AndroidJavaObject>(methodName,
                                                                                AndroidHelperFragment.GetActivity(), (int)minOpponents, (int)maxOpponents))
                {
                    AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(
                        task,
                        result =>
                    {
                        int status = result.Get <int>("status");
                        if ((UIStatus)status != UIStatus.Valid)
                        {
                            cb.Invoke((UIStatus)status, null);
                            return;
                        }

                        List <string> playerIdsToInvite;
                        using (var ids = result.Get <AndroidJavaObject>("playerIdsToInvite"))
                        {
                            playerIdsToInvite = CreatePlayerIdsToInvite(ids);
                        }

                        InvitationResultHolder resultHolder = new InvitationResultHolder(
                            result.Get <int>("minAutomatchingPlayers"),
                            result.Get <int>("maxAutomatchingPlayers"),
                            playerIdsToInvite
                            );

                        cb.Invoke((UIStatus)status, resultHolder);
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Debug.Log("showSelectOpponentsUi failed with exception");
                        cb.Invoke(UIStatus.InternalError, null);
                    });
                }
        }
Example #18
0
 private void DoGetAnotherServerAuthCode(bool reAuthenticateIfNeeded, Action <string> callback)
 {
     try
     {
         using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
             using (var currentActivity = AndroidHelperFragment.GetActivity())
                 using (var pendingResult = bridgeClass.CallStatic <AndroidJavaObject>(
                            "getAnotherAuthCode", currentActivity, reAuthenticateIfNeeded, webClientId))
                 {
                     pendingResult.Call("setResultCallback", new ResultCallbackProxy(
                                            tokenResult => { callback(tokenResult.Call <string>("getAuthCode")); }));
                 }
     }
     catch (Exception e)
     {
         OurUtils.Logger.e("Exception launching token request: " + e.Message);
         OurUtils.Logger.e(e.ToString());
     }
 }
Example #19
0
        public static void AskForLoadFriendsResolution(
            AndroidJavaObject friendsSharingConsentException, Action <UIStatus> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (
                    var task = helperFragment.CallStatic <AndroidJavaObject>(
                        "askForLoadFriendsResolution", AndroidHelperFragment.GetActivity(),
                        friendsSharingConsentException))
                {
                    AndroidTaskUtils.AddOnSuccessListener <int>(task, uiCode =>
                    {
                        Debug.Log("AskForLoadFriendsResolution result " + uiCode);
                        cb.Invoke((UIStatus)uiCode);
                    });

                    AndroidTaskUtils.AddOnFailureListener(task, exception =>
                    {
                        Debug.Log("AskForLoadFriendsResolution failed with exception");
                        cb.Invoke(UIStatus.InternalError);
                    });
                }
        }
        public static void ShowAchievementsUI(Action<UIStatus> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
            using (var task =
                helperFragment.CallStatic<AndroidJavaObject>("showAchievementUi", AndroidHelperFragment.GetActivity()))
            {
                AndroidTaskUtils.AddOnSuccessListener<int>(
                    task,
                    uiCode =>
                    {
                        OurUtils.Logger.d("ShowAchievementsUI result " + uiCode);
                        cb.Invoke((UIStatus) uiCode);
                    });

                AndroidTaskUtils.AddOnFailureListener(
                    task,
                    exception =>
                    {
                        OurUtils.Logger.e("ShowAchievementsUI failed with exception");
                        cb.Invoke(UIStatus.InternalError);
                    });
            }
        }
Example #21
0
 public static void ShowCompareProfileWithAlternativeNameHintsUI(
     string playerId, string otherPlayerInGameName, string currentPlayerInGameName,
     Action <UIStatus> cb)
 {
     using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
         using (
             var task = helperFragment.CallStatic <AndroidJavaObject>(
                 "showCompareProfileWithAlternativeNameHintsUI",
                 AndroidHelperFragment.GetActivity(), playerId, otherPlayerInGameName,
                 currentPlayerInGameName))
         {
             AndroidTaskUtils.AddOnSuccessListener <int>(task, uiCode =>
             {
                 Debug.Log("ShowCompareProfileWithAlternativeNameHintsUI result " + uiCode);
                 cb.Invoke((UIStatus)uiCode);
             });
             AndroidTaskUtils.AddOnFailureListener(task, exception =>
             {
                 Debug.Log("ShowCompareProfileWithAlternativeNameHintsUI failed with exception");
                 cb.Invoke(UIStatus.InternalError);
             });
         }
 }
Example #22
0
        public static void ShowWaitingRoomUI(AndroidJavaObject room, int minParticipantsToStart,
                                             Action <WaitingRoomUIStatus, AndroidJavaObject> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (var task = helperFragment.CallStatic <AndroidJavaObject>("showWaitingRoomUI",
                                                                                AndroidHelperFragment.GetActivity(), room, minParticipantsToStart))
                {
                    AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(
                        task,
                        result =>
                    {
                        cb.Invoke((WaitingRoomUIStatus)result.Get <int>("status"),
                                  result.Get <AndroidJavaObject>("room"));
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Debug.Log("ShowWaitingRoomUI failed with exception");
                        cb.Invoke(WaitingRoomUIStatus.InternalError, null);
                    });
                }
        }
Example #23
0
        public static void ShowLeaderboardUI(string leaderboardId, LeaderboardTimeSpan timeSpan, Action <UIStatus> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (var task = helperFragment.CallStatic <AndroidJavaObject>("showLeaderboardUi",
                                                                                AndroidHelperFragment.GetActivity(), leaderboardId,
                                                                                AndroidJavaConverter.ToLeaderboardVariantTimeSpan(timeSpan)))
                {
                    AndroidTaskUtils.AddOnSuccessListener <int>(
                        task,
                        uiCode =>
                    {
                        Debug.Log("ShowLeaderboardUI result " + uiCode);
                        cb.Invoke((UIStatus)uiCode);
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Debug.Log("ShowLeaderboardUI failed with exception");
                        cb.Invoke(UIStatus.InternalError);
                    });
                }
        }
Example #24
0
 private void DoFetchToken(bool silent, Action <int> callback)
 {
     try
     {
         using (var bridgeClass = new AndroidJavaClass(HelperFragmentClass))
             using (var currentActivity = AndroidHelperFragment.GetActivity())
                 using (var pendingResult = bridgeClass.CallStatic <AndroidJavaObject>(
                            "fetchToken",
                            currentActivity,
                            silent,
                            requestAuthCode,
                            requestEmail,
                            requestIdToken,
                            webClientId,
                            forceRefresh,
                            oauthScopes.ToArray(),
                            hidePopups,
                            accountName))
                 {
                     pendingResult.Call("setResultCallback", new ResultCallbackProxy(
                                            tokenResult =>
                     {
                         account  = tokenResult.Call <AndroidJavaObject>("getAccount");
                         authCode = tokenResult.Call <string>("getAuthCode");
                         email    = tokenResult.Call <string>("getEmail");
                         idToken  = tokenResult.Call <string>("getIdToken");
                         callback(tokenResult.Call <int>("getStatusCode"));
                     }));
                 }
     }
     catch (Exception e)
     {
         OurUtils.Logger.e("Exception launching token request: " + e.Message);
         OurUtils.Logger.e(e.ToString());
     }
 }
Example #25
0
 private AndroidJavaObject getVideosClient()
 {
     return(mGamesClass.CallStatic <AndroidJavaObject>("getVideosClient", AndroidHelperFragment.GetActivity(),
                                                       mTokenClient.GetAccount()));
 }