コード例 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            listView   = FindViewById <ListView> (Resource.Id.listView);
            textSearch = FindViewById <AutoCompleteTextView> (Resource.Id.textSearch);

            googleApiClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(this)
                              .EnableAutoManage(this, 0, this)
                              .AddApi(Android.Gms.Location.Places.PlacesClass.GEO_DATA_API)
                              .Build();

            adapter            = new PlacesAutocompleteAdapter(this, googleApiClient, BOUNDS_GREATER_SYDNEY, null);
            textSearch.Adapter = adapter;


            textSearch.ItemClick += (sender, e) => {
                var item = adapter [e.Position];

                // Go to details of place:
                var intent = new Intent(this, typeof(PlaceDetailsActivity));
                intent.PutExtra("PLACE_ID", item.PlaceId);
                StartActivity(intent);
            };
        }
コード例 #2
0
 bool resolveConnectionFailure(Activity activity, Android.Gms.Common.Apis.GoogleApiClient client, ConnectionResult result, int requestCode, string fallbackErrorMessage)
 {
     if (result.HasResolution)
     {
         try {
             result.StartResolutionForResult(activity, requestCode);
             return(true);
         } catch (IntentSender.SendIntentException e) {
             // The intent was canceled before it was sent.  Return to the default
             // state and attempt to connect to get an updated ConnectionResult.
             client.Connect();
             return(false);
         }
     }
     else
     {
         // not resolvable... so show an error message
         int errorCode = result.ErrorCode;
         var dialog    = GooglePlayServicesUtil.GetErrorDialog(errorCode, activity, requestCode);
         if (dialog != null)
         {
             dialog.Show();
         }
         else
         {
             // no built-in dialog: show the fallback error message
             //ShowAlert (activity, fallbackErrorMessage);
             (new AlertDialog.Builder(activity)).SetMessage(fallbackErrorMessage)
             .SetNeutralButton(Android.Resource.String.Ok, delegate { }).Create().Show();
         }
         return(false);
     }
 }
コード例 #3
0
        public override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            if (savedInstanceState != null)
            {
                mSignInButtonClicked = savedInstanceState.GetBoolean(KEY_SIGNIN_BUTTON_CLICKED);
            }

            var args = Arguments;

            if (args != null)
            {
                mLoginAction = args.GetInt(LoginActivity.EXTRA_ACTION);
            }

            var options = new Android.Gms.Plus.PlusClass.PlusOptions.Builder().Build();

            mGoogleApiClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(Activity)
                               .AddApi(Android.Gms.Plus.PlusClass.API, options)
                               .AddConnectionCallbacks(this)
                               .AddOnConnectionFailedListener(this)
                               .AddScope(Android.Gms.Plus.PlusClass.ScopePlusProfile)
                               .AddScope(new Android.Gms.Common.Apis.Scope(WALLET_SCOPE))
                               .Build();
        }
コード例 #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            // Button listeners
            FindViewById <Button> (Resource.Id.button_advertise).Click += delegate {
                StartAdvertising();
            };
            FindViewById <Button> (Resource.Id.button_discover).Click += delegate {
                StartDiscovery();
            };
            FindViewById <Button> (Resource.Id.button_send).Click += delegate {
                SendMessage();
            };

            // EditText
            mMessageText = FindViewById <EditText> (Resource.Id.edittext_message);

            // Debug text view
            mDebugInfo = FindViewById <TextView> (Resource.Id.debug_text);
            mDebugInfo.MovementMethod = new Android.Text.Method.ScrollingMovementMethod();

            // Initialize Google API Client for Nearby Connections. Note: if you are using Google+
            // sign-in with your project or any other API that requires Authentication you may want
            // to use a separate Google API Client for Nearby Connections.  This API does not
            // require the user to authenticate so it can be used even when the user does not want to
            // sign in or sign-in has failed.
            mGoogleApiClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(this)
                               .AddConnectionCallbacks(this)
                               .AddOnConnectionFailedListener(this)
                               .AddApi(Android.Gms.Nearby.NearbyClass.CONNECTIONS_API)
                               .Build();
        }
コード例 #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            client = new Android.Gms.Common.Apis.GoogleApiClient.Builder(this, this, this)
                     .AddApi(Android.Gms.Panorama.PanoramaClass.API)
                     .Build();
        }
コード例 #6
0
 public PlacesAutocompleteAdapter(Context context, Android.Gms.Common.Apis.GoogleApiClient googleApiClient,
                                  Android.Gms.Maps.Model.LatLngBounds bounds, Android.Gms.Location.Places.AutocompleteFilter filter)
 {
     this.context            = context;
     this.googleApiClient    = googleApiClient;
     this.bounds             = bounds;
     this.autoCompleteFilter = filter;
 }
コード例 #7
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            Log("onCreate()");

            // Create the Google Api Client with access to Plus and Games
            mGoogleApiClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(this)
                               .AddConnectionCallbacks(this)
                               .AddOnConnectionFailedListener(this)
                               .AddApi(Android.Gms.Plus.PlusClass.API).AddScope(Android.Gms.Plus.PlusClass.ScopePlusLogin)
                               .AddApi(Android.Gms.Games.GamesClass.API).AddScope(Android.Gms.Games.GamesClass.ScopeGames)
                               .Build();

            // Set up click listeners
            FindViewById <ImageButton> (Resource.Id.button_open_inbox).Click += delegate {
                // show inbox!
                if (mGoogleApiClient != null && mGoogleApiClient.IsConnected)
                {
                    StartActivityForResult(Android.Gms.Games.GamesClass.Requests.GetInboxIntent(mGoogleApiClient), SHOW_INBOX);
                }
            };
            FindViewById <ImageButton> (Resource.Id.button_send_gift).Click += delegate {
                // send gift!
                showSendIntent(GameRequest.TypeGift);
            };
            FindViewById <ImageButton> (Resource.Id.button_send_request).Click += delegate {
                // request gift!
                showSendIntent(GameRequest.TypeWish);
            };
            FindViewById <SignInButton> (Resource.Id.button_sign_in).Click += delegate {
                // Check to see the developer who's running this sample code read the instructions :-)
                // NOTE: this check is here only because this is a sample! Don't include this
                // check in your actual production app.
                //if (!BaseGameUtils.VerifySampleSetup (this, Resource.String.app_id))
                //    Log ("*** Warning: setup problems detected. Sign in may not work!");

                // start the sign-in flow
                Log("Sign-in button clicked");
                mSignInClicked = true;
                mGoogleApiClient.Connect();
            };
            FindViewById <Button> (Resource.Id.button_sign_out).Click += delegate {
                // sign out.
                Log("Sign-out button clicked");
                mSignInClicked = false;
                Android.Gms.Games.GamesClass.SignOut(mGoogleApiClient);
                mGoogleApiClient.Disconnect();
                showSignInBar();
            };

            mGiftIcon = BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_send_gift);
        }
コード例 #8
0
        // [END auth_oncreate_setup_ending]

        // [START auth_build_googleapiclient_beginning]

        /**
         *  Build a {@link GoogleApiClient} that will authenticate the user and allow the application
         *  to connect to Fitness APIs. The scopes included should match the scopes your app needs
         *  (see documentation for details). Authentication will occasionally fail intentionally,
         *  and in those cases, there will be a known resolution, which the OnConnectionFailedListener()
         *  can address. Examples of this include the user never having signed in before, or having
         *  multiple accounts on the device and needing to specify which account to use, etc.
         */
        void buildFitnessClient()
        {
            // Create the Google API Client
            mClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(this)
                      .AddApi(Android.Gms.Fitness.FitnessClass.SENSORS_API)
                      .AddScope(new Android.Gms.Common.Apis.Scope(Android.Gms.Common.Scopes.FitnessLocationRead))
                      .AddConnectionCallbacks(
                bundle => {
                Log(TAG, "Connected!!!");
                // Now you can make calls to the Fitness APIs.
                // Put application specific code here.
                // [END auth_build_googleapiclient_beginning]
                //  What to do? Find some data sources!
                findFitnessDataSources();

                // [START auth_build_googleapiclient_ending]
            },
                i => {
                // If your connection to the sensor gets lost at some point,
                // you'll be able to determine the reason and react to it here.
                if (i == Android.Gms.Common.Apis.GoogleApiClient.ConnectionCallbacks.CauseNetworkLost)
                {
                    Log(TAG, "Connection lost.  Cause: Network Lost.");
                }
                else if (i == Android.Gms.Common.Apis.GoogleApiClient.ConnectionCallbacks.CauseServiceDisconnected)
                {
                    Log(TAG, "Connection lost.  Reason: Service Disconnected");
                }
            })
                      .AddOnConnectionFailedListener(
                result => {
                Log(TAG, "Connection failed. Cause: " + result);
                if (!result.HasResolution)
                {
                    // Show the localized error dialog
                    Android.Gms.Common.GooglePlayServicesUtil.GetErrorDialog(result.ErrorCode, this, 0).Show();
                    return;
                }
                // The failure has a resolution. Resolve it.
                // Called typically when the app is not yet authorized, and an
                // authorization dialog is displayed to the user.
                if (!authInProgress)
                {
                    try {
                        Log(TAG, "Attempting to resolve failed connection");
                        authInProgress = true;
                        result.StartResolutionForResult(this, REQUEST_OAUTH);
                    } catch (IntentSender.SendIntentException e) {
                        Log(TAG, "Exception while starting resolution activity: " + e);
                    }
                }
            })
                      .Build();
        }
コード例 #9
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var button = FindViewById <Button> (Resource.Id.buttonInvite);

            button.Click += delegate {
                SendAppInvite();
            };

            googleApiClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(this)
                              .AddApi(Android.Gms.AppInvite.AppInviteClass.API)
                              .AddConnectionCallbacks(async info => {
                if (Android.Gms.AppInvite.AppInviteReferral.HasReferral(Intent))
                {
                    await UpdateInvitationStatus(Intent);
                }
            }, cause => Console.WriteLine("Connection Suspended: {0}", cause))
                              .AddOnConnectionFailedListener(result => {
                if (!result.IsSuccess)
                {
                    if (result.HasResolution)
                    {
                        result.StartResolutionForResult(this, RESOLUTION_CODE);
                    }
                    else
                    {
                        Toast.MakeText(this, "Failed to Connect: " + result.ErrorCode, ToastLength.Long).Show();
                    }
                }
            })
                              .Build();

            // If the app was already installed and the appinvite was opened
            // we may have information passed in about it here
            if (bundle == null)
            {
                // No savedInstanceState, so it is the first launch of this activity

                if (Android.Gms.AppInvite.AppInviteReferral.HasReferral(Intent))
                {
                    // In this case the referral data is in the intent launching the MainActivity,
                    // which means this user already had the app installed. We do not have to
                    // register the Broadcast Receiver to listen for Play Store Install information
                    LaunchDeepLinkActivity(Intent);
                }
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            textLastLocation    = FindViewById <TextView>(Resource.Id.textLastLocation);
            textLocationUpdates = FindViewById <TextView>(Resource.Id.textLocationUpdates);

            googleApiClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(this)
                              .AddApi(Android.Gms.Location.LocationServices.API)
                              .AddConnectionCallbacks(this)
                              .AddOnConnectionFailedListener(this)
                              .Build();
            googleApiClient.Connect();
        }
コード例 #11
0
        protected override void OnCreate(Android.OS.Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.PlaceDetails);

            textTitle   = FindViewById <TextView> (Resource.Id.textTitle);
            textDetails = FindViewById <TextView> (Resource.Id.textDetails);
            textInfo    = FindViewById <TextView> (Resource.Id.textInfo);

            googleApiClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(this)
                              .AddConnectionCallbacks(this)
                              .AddOnConnectionFailedListener(this)
                              .AddApi(Android.Gms.Location.Places.PlacesClass.GEO_DATA_API)
                              .Build();
        }
        public override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            if (savedInstanceState != null)
            {
                mPromoWasSelected = savedInstanceState.GetBoolean(KEY_PROMO_CLICKED);
            }

            var accountName = ((BikestoreApplication)Activity.Application).AccountName;
            var options     = new Android.Gms.Identity.Intents.Address.AddressOptions(Android.Gms.Wallet.WalletConstants.ThemeLight);

            mGoogleApiClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(Activity)
                               .AddApi(Android.Gms.Identity.Intents.Address.Api, options)
                               .SetAccountName(accountName)
                               .AddConnectionCallbacks(this)
                               .AddOnConnectionFailedListener(this)
                               .Build();
        }
コード例 #13
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // If you want to understand the life cycle more, you can use below command to turn on
            // verbose logging for this Activity on your testing device:
            // adb shell setprop log.tag.SignInActivity VERBOSE
            mIsLogVerbose = Android.Util.Log.IsLoggable(TAG, Android.Util.LogPriority.Verbose);

            SetContentView(Resource.Layout.sign_in_activity);

            restoreState(savedInstanceState);

            logVerbose("Activity onCreate, creating new GoogleApiClient");

            mGoogleApiClient = buildGoogleApiClient(false);

            mSignInStatus        = FindViewById <TextView> (Resource.Id.sign_in_status);
            mSignInButton        = FindViewById <SignInButton> (Resource.Id.sign_in_button);
            mSignInButton.Click += (sender, e) => {
                if (!mGoogleApiClient.IsConnecting)
                {
                    int available = GooglePlayServicesUtil.IsGooglePlayServicesAvailable(this);
                    if (available != ConnectionResult.Success)
                    {
                        ShowDialog(DIALOG_GET_GOOGLE_PLAY_SERVICES);
                        return;
                    }

                    mSignInClicked     = true;
                    mSignInStatus.Text = GetString(Resource.String.signing_in_status);
                    resolveSignInError();
                }
            };

            mServerAuthCodeDisabledLabel      = FindViewById <TextView> (Resource.Id.server_auth_code_disabled);
            mServerAuthCodeResetButton        = FindViewById <View> (Resource.Id.server_auth_code_reset_button);
            mServerAuthCodeResetButton.Click += (sender, e) => {
                mServerAuthCodeRequired.Set(true);
            };
            if (!isUsingOfflineAccess())
            {
                mServerAuthCodeDisabledLabel.Visibility = ViewStates.Visible;
                mServerAuthCodeResetButton.Visibility   = ViewStates.Gone;
            }
            else
            {
                mServerAuthCodeDisabledLabel.Visibility = ViewStates.Gone;
                mServerAuthCodeResetButton.Visibility   = ViewStates.Visible;
            }

            mSignOutButton        = FindViewById <View> (Resource.Id.sign_out_button);
            mSignOutButton.Click += (sender, e) => {
                if (mGoogleApiClient.IsConnected)
                {
                    mGoogleApiClient.ClearDefaultAccountAndReconnect();
                }
            };
            mRevokeAccessButton        = FindViewById(Resource.Id.revoke_access_button);
            mRevokeAccessButton.Click += async delegate {
                mServerAuthCodeRequired.Set(true);
                if (mGoogleApiClient.IsConnected)
                {
                    // TODO: asyncify
                    var result =
                        //await
                        Android.Gms.Plus.PlusClass.AccountApi
                        //.RevokeAccessAndDisconnectAsync (mGoogleApiClient);
                        .RevokeAccessAndDisconnect(mGoogleApiClient);

                    /*
                     * if (result.IsSuccess) {
                     *  mSignInStatus.SetText (Resource.String.revoke_access_status);
                     * } else {
                     *  mSignInStatus.SetText (Resource.String.revoke_access_error_status);
                     * }
                     * mGoogleApiClient.Reconnect ();
                     */

                    updateButtons(false /* isSignedIn */);
                }
            };

            mScopeSelector = FindViewById <ToggleButton> (Resource.Id.scope_selection_toggle);
            mScopeSelector.CheckedChange += (sender, e) => {
                mGoogleApiClient.Disconnect();
                // Since we changed the configuration, the cached connection result is no longer
                // valid.
                mConnectionResult = null;
                mGoogleApiClient  = buildGoogleApiClient(e.IsChecked);
                mGoogleApiClient.Connect();
            };


            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                ActionBar.SetDisplayHomeAsUpEnabled(true);
            }
        }
コード例 #14
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            buttonCheck          = FindViewById <Button> (Resource.Id.buttonCheck);
            buttonVerify         = FindViewById <Button> (Resource.Id.buttonVerify);
            buttonVerify.Enabled = false;

            googleApiClient = new Android.Gms.Common.Apis.GoogleApiClient.Builder(this)
                              .EnableAutoManage(this, this)
                              .AddApi(Android.Gms.SafetyNet.SafetyNetClass.API)
                              .Build();

            buttonCheck.Click += async delegate {
                var api   = Android.Gms.SafetyNet.SafetyNetClass.GetClient(this);
                var nonce = Android.Gms.SafetyNet.Nonce.Generate();  // Should be at least 16 bytes in length.
                var r     = await api.AttestAsync(nonce, DEVELOPERS_CONSOLE_API_KEY);

                if (r != null && !string.IsNullOrEmpty(r.JwsResult))
                {
                    // Store for future verification with google servers
                    attestationResponse = r;

                    // Get the JSON from the JWS result by decoding
                    var decodedResult = r.DecodeJwsResult(nonce);

                    string error = null;

                    // Try and verify the body of the response
                    if (VerifyAttestResponse(decodedResult, nonce, out error))
                    {
                        Toast.MakeText(this, "Compatibility Passed!", ToastLength.Long).Show();
                        buttonVerify.Enabled = true;
                    }
                    else
                    {
                        Toast.MakeText(this, "Compatibility Failed: " + error, ToastLength.Long).Show();
                    }
                }
                else
                {
                    // Error
                    Toast.MakeText(this, "Failed to Check Compatibility", ToastLength.Long).Show();
                }
            };


            buttonVerify.Click += async delegate {
                // Validate the JWS response with Google to ensure it came from them
                var valid = await attestationResponse.ValidateWithGoogle(DEVELOPERS_CONSOLE_API_KEY);

                if (valid)
                {
                    Toast.MakeText(this, "Successfully validated response with Google!", ToastLength.Short).Show();
                }
                else
                {
                    Toast.MakeText(this, "Failed response validation with Google!", ToastLength.Short).Show();
                }
            };
        }