private void HandleActivityResult(object sender, ActivityResultEventArgs e)
        {
            if (e.RequestCode == VOICE)
            {
                if (e.ResultCode == Result.Ok)
                {
                    var matches = e.Data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
                    if (matches.Count != 0)
                    {
                        string textInput = matches[0];

                        // limit the output to 500 characters
                        if (textInput.Length > 500)
                        {
                            textInput = textInput.Substring(0, 500);
                        }
                        sharedButton.OnTextChanged?.Invoke(textInput);
                        //textBox.Text = textInput;
                    }
                    else
                    {
                        sharedButton.OnTextChanged?.Invoke("No speech was recognised");
                    }
                }
            }
        }
예제 #2
0
        static int PICK_CONTACT_REQUEST = 42; // The request code
        
        protected void OnActivityResult(TaskCompletionSource<ContactInfo> tcs, ActivityResultEventArgs e) //int requestCode, Android.App.Result resultCode, Intent data)
        {
            // Check which request it is that we're responding to
            if (e.requestCode == PICK_CONTACT_REQUEST)
            {
                // Make sure the request was successful
                if (e.resultCode == Android.App.Result.Ok)
                {
                    var loader = new CursorLoader(MainActivity.Instance, e.data.Data, projection, null, null, null);
                    var cursor = (Android.Database.ICursor)loader.LoadInBackground();

                    var contactList = new List<ContactInfo>();
                    if (cursor.MoveToFirst())
                    {
                        do
                        {
                            contactList.Add(GetContactInfoFromCursor(cursor));
                        } while (cursor.MoveToNext());
                    }
                    tcs.SetResult(contactList.FirstOrDefault());
                    return;
                }
            }

            tcs.SetResult(null);
        }
예제 #3
0
        static int PICK_CONTACT_REQUEST = 42; // The request code

        protected void OnActivityResult(TaskCompletionSource <ContactInfo> tcs, ActivityResultEventArgs e)
        {
            // Check which request it is that we're responding to
            if (e.requestCode == PICK_CONTACT_REQUEST)
            {
                // Make sure the request was successful
                if (e.resultCode == Android.App.Result.Ok)
                {
                    var loader = new CursorLoader(MainActivity.Instance, e.data.Data, projection, null, null, null);
                    var cursor = (Android.Database.ICursor)loader.LoadInBackground();

                    var contactList = new List <ContactInfo>();
                    if (cursor.MoveToFirst())
                    {
                        do
                        {
                            contactList.Add(GetContactInfoFromCursor(cursor));
                        } while (cursor.MoveToNext());
                    }
                    tcs.SetResult(contactList.FirstOrDefault());
                    return;
                }
            }

            tcs.SetResult(null);
        }
예제 #4
0
        static int PICK_CONTACT_REQUEST = 42;                                                              // The request code

        protected void OnActivityResult(TaskCompletionSource <ContactInfo> tcs, ActivityResultEventArgs e) //int requestCode, Android.App.Result resultCode, Intent data)
        {
            //TODO: Update to replace no-longer-supported plugin
            //// Check which request it is that we're responding to
            //if (e.requestCode == PICK_CONTACT_REQUEST)
            //{
            //    // Make sure the request was successful
            //    if (e.resultCode == Android.App.Result.Ok)
            //    {
            //        var loader = new CursorLoader(MainActivity.Instance, e.data.Data, projection, null, null, null);
            //        var cursor = (Android.Database.ICursor)loader.LoadInBackground();

            //        var contactList = new List<ContactInfo>();
            //        if (cursor.MoveToFirst())
            //        {
            //            do
            //            {
            //                contactList.Add(GetContactInfoFromCursor(cursor));
            //            } while (cursor.MoveToNext());
            //        }
            //        tcs.SetResult(contactList.FirstOrDefault());
            //        return;
            //    }
            //}

            tcs.SetResult(null);
        }
예제 #5
0
        private void HandleActivityResultDelegate(object sender, ActivityResultEventArgs e)
        {
            if (e.RequestCode != ApiConstants.SpotifyRequestCode)
            {
                return;
            }
            var response = AuthenticationClient.GetResponse((int)e.ResultCode, e.Data);

            if (response?.ResponseType == AuthenticationResponse.Type.Token)
            {
                InitPlayer(response?.AccessToken);
            }
        }
예제 #6
0
        static int PICK_CONTACT_REQUEST = 42;                                                              // The request code

        protected void OnActivityResult(TaskCompletionSource <ContactInfo> tcs, ActivityResultEventArgs e) //int requestCode, Android.App.Result resultCode, Intent data)
        {
            // Check which request it is that we're responding to
            if (e.requestCode == PICK_CONTACT_REQUEST)
            {
                // Make sure the request was successful
                if (e.resultCode == Android.App.Result.Ok)
                {
                    //var uri = ContactsContract.Contacts.ContentUri;
                    string[] projection =
                    {
                        ContactsContract.Contacts.InterfaceConsts.Id,
                        ContactsContract.Contacts.InterfaceConsts.DisplayName,
                        ContactsContract.Contacts.InterfaceConsts.PhotoId,
                    };

                    var loader = new CursorLoader(MainActivity.Instance, e.data.Data, projection, null, null, null);
                    var cursor = (Android.Database.ICursor)loader.LoadInBackground();

                    var contactList = new List <ContactInfo>();
                    if (cursor.MoveToFirst())
                    {
                        do
                        {
                            var displayName = cursor.GetString(cursor.GetColumnIndex(projection[1]));
                            var nameParts   = displayName.Split(' ');
                            var lastName    = nameParts.Length > 1 ? nameParts[1] : null;
                            contactList.Add(new ContactInfo()
                            {
                                Id             = cursor.GetLong(cursor.GetColumnIndex(projection[0])).ToString(),
                                GivenName      = nameParts[0],
                                AdditionalName = null,
                                FamilyName     = lastName
                            });
                        } while (cursor.MoveToNext());
                    }
                    tcs.SetResult(contactList.FirstOrDefault());
                    return;
                }
            }

            tcs.SetResult(null);
        }
예제 #7
0
        static int PICK_CONTACT_REQUEST = 42; // The request code
        
        protected void OnActivityResult(TaskCompletionSource<ContactInfo> tcs, ActivityResultEventArgs e) //int requestCode, Android.App.Result resultCode, Intent data)
        {
            // Check which request it is that we're responding to
            if (e.requestCode == PICK_CONTACT_REQUEST)
            {
                // Make sure the request was successful
                if (e.resultCode == Android.App.Result.Ok)
                {
                    //var uri = ContactsContract.Contacts.ContentUri;
                    string[] projection = {
                       ContactsContract.Contacts.InterfaceConsts.Id,
                       ContactsContract.Contacts.InterfaceConsts.DisplayName,
                       ContactsContract.Contacts.InterfaceConsts.PhotoId,
                    };

                    var loader = new CursorLoader(MainActivity.Instance, e.data.Data, projection, null, null, null);
                    var cursor = (Android.Database.ICursor)loader.LoadInBackground();

                    var contactList = new List<ContactInfo>();
                    if (cursor.MoveToFirst())
                    {
                        do
                        {
                            var displayName = cursor.GetString(cursor.GetColumnIndex(projection[1]));
                            var nameParts = displayName.Split(' ');
                            var lastName = nameParts.Length > 1 ? nameParts[1] : null;
                            contactList.Add(new ContactInfo()
                            {
                                Id = cursor.GetLong(cursor.GetColumnIndex(projection[0])).ToString(),
                                GivenName = nameParts[0],
                                AdditionalName = null,
                                FamilyName = lastName
                            });
                        } while (cursor.MoveToNext());
                    }
                    tcs.SetResult(contactList.FirstOrDefault());
                    return;
                }
            }

            tcs.SetResult(null);
        }
예제 #8
0
        private void HandleActivityResult(object sender, ActivityResultEventArgs e)
        {
            DependencyService.Get <IScreen>().SetFullScreen(App.Config.FullScreen);

            if (e.RequestCode == VOICE && e.ResultCode == Result.Ok)
            {
                var matches = e.Data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
                if (matches.Count != 0)
                {
                    string textInput = matches[0];
                    if (textInput.Length > 500)
                    {
                        textInput = textInput.Substring(0, 500);
                    }
                    sharedButton.OnTextChanged?.Invoke(textInput);
                }
                else
                {
                    sharedButton.OnTextChanged?.Invoke("No speech was recognised");
                }
            }
        }
예제 #9
0
        protected void OnActivityResult(string copyToDirectory, string fileNameWithoutExtension, ActivityResultEventArgs e, TaskCompletionSource <string> tcs)
        {
            if (e.requestCode == PhotoPickerRequestCode)
            {
                if (e.resultCode == Android.App.Result.Ok)
                {
                    var sourceFile = e.data.DataString;
                    var extension  = System.IO.Path.GetExtension(e.data.DataString);
                    if (e.data.Data == null)
                    {
                        tcs.SetResult(null);
                    }
                    else
                    {
                        var fullFileName = fileNameWithoutExtension + extension;
                        var copiedPath   = System.IO.Path.Combine(copyToDirectory, fullFileName);
                        using (var stream = MainActivity.Instance.ContentResolver.OpenInputStream(e.data.Data))
                        {
                            using (var copiedFileStream = new System.IO.FileStream(copiedPath, System.IO.FileMode.OpenOrCreate))
                            {
                                stream.CopyTo(copiedFileStream);
                            }
                        }
                        tcs.SetResult(fullFileName); // we'll reconstruct the path at runtime
                    }
                    return;
                }
            }

            tcs.SetResult(null);
        }