コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_place_suggestion_search);

            ApiKey        = Intent.Extras.GetString("apiKey");
            SearchService = SearchServiceFactory.Create(this, Uri.Encode(ApiKey));

            ResultTextView   = FindViewById <TextView>(Resource.Id.textview_pss_results);
            QueryInput       = FindViewById <EditText>(Resource.Id.edittext_search_query_pss);
            LatitudeInput    = FindViewById <EditText>(Resource.Id.edittext_lat_pss);
            LongitudeInput   = FindViewById <EditText>(Resource.Id.edittext_lon_pss);
            RadiusInput      = FindViewById <EditText>(Resource.Id.edittext_radius_pss);
            LanguageInput    = FindViewById <EditText>(Resource.Id.edittext_language_pss);
            CountryCodeInput = FindViewById <EditText>(Resource.Id.edittext_country_code_pss);

            NortheastLatInput = FindViewById <EditText>(Resource.Id.query_suggestion_bounds_northeast_lat_input);
            NortheastLngInput = FindViewById <EditText>(Resource.Id.query_suggestion_bounds_northeast_lng_input);
            SouthwestLatInput = FindViewById <EditText>(Resource.Id.query_suggestion_bounds_southwest_lat_input);
            SouthwestLngInput = FindViewById <EditText>(Resource.Id.query_suggestion_bounds_southwest_lng_input);

            Childern    = FindViewById <Switch>(Resource.Id.switch_query_suggestion_children);
            BoundStrict = FindViewById <Switch>(Resource.Id.switch_query_suggestion_strict_bounds);

            SearchPlaceSuggestionButton        = FindViewById <Button>(Resource.Id.btn_search_place_suggestion);
            SearchPlaceSuggestionButton.Click += delegate { ExecPlaceSuggestionSearch(); };
        }
コード例 #2
0
        ///<Summary>
        /// Load wav or mp3 audio file as a stream
        ///</Summary>
        public bool Load(Stream audioStream)
        {
            player.Reset();

            DeleteFile(path);

            //cache to the file system
            path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), $"cache{index++}.wav");
            var fileStream = File.Create(path);

            audioStream.CopyTo(fileStream);
            fileStream.Close();

            try
            {
                player.SetDataSource(path);
            }
            catch
            {
                try
                {
                    var context = Android.App.Application.Context;
                    player?.SetDataSource(context, Uri.Parse(Uri.Encode(path)));
                }
                catch
                {
                    return(false);
                }
            }

            return(PreparePlayer());
        }
コード例 #3
0
        internal string GetMapsUri(Placemark placemark, MapLaunchOptions options)
        {
            if (placemark == null)
            {
                throw new ArgumentNullException(nameof(placemark));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var uri = string.Empty;

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"geo:0,0?q={placemark.GetEscapedAddress()}";
                if (!string.IsNullOrWhiteSpace(options.Name))
                {
                    uri += $"({AndroidUri.Encode(options.Name)})";
                }
            }
            else
            {
                uri = $"google.navigation:q={placemark.GetEscapedAddress()}{GetMode(options.NavigationMode)}";
            }

            return(uri);
        }
コード例 #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_place_search);

            ApiKey        = Intent.Extras.GetString("apiKey");
            SearchService = SearchServiceFactory.Create(this, Uri.Encode(ApiKey));

            ResultTextView         = FindViewById <TextView>(Resource.Id.textview_text_search_results);
            QueryInput             = FindViewById <EditText>(Resource.Id.edittext_text_search_query);
            LatitudeInput          = FindViewById <EditText>(Resource.Id.edittext_lat);
            LongitudeInput         = FindViewById <EditText>(Resource.Id.edittext_lon);
            RadiusInput            = FindViewById <EditText>(Resource.Id.edittext_radius);
            LanguageInput          = FindViewById <EditText>(Resource.Id.edittext_language);
            PageIndexInput         = FindViewById <EditText>(Resource.Id.edittext_page_index);
            PageSizeInput          = FindViewById <EditText>(Resource.Id.edittext_page_size);
            PoiTypeSpinner         = FindViewById <Spinner>(Resource.Id.spinner_nearby_search_poitype);
            PoiTypeSpinner.Adapter = new ArrayAdapter <LocationType>(this, Android.Resource.Layout.SimpleSpinnerItem, LocationType.Values().ToList());
            BoundStrict            = FindViewById <Switch>(Resource.Id.switch_nearby_search_strict_bounds);
            Switch UsePOITypeSwitch = FindViewById <Switch>(Resource.Id.switch_nearby_search_poitype);

            UsePOITypeSwitch.CheckedChange += delegate(object sender, CompoundButton.CheckedChangeEventArgs e)
            {
                PoiTypeSpinner.Enabled = e.IsChecked;
            };

            SearchNearbyPlaceButton        = FindViewById <Button>(Resource.Id.btn_search_nearby_place);
            SearchNearbyPlaceButton.Click += delegate { ExecPlaceSearch(); };

            PoiTypeSpinner.Enabled = false;
        }
コード例 #5
0
        bool Load(string path)
        {
            var context = Android.App.Application.Context;

            //load the cached audio into MediaPlayer
            player?.Dispose();
            player = new Android.Media.MediaPlayer();

            try
            {
                player.SetDataSource(path);
            }
            catch
            {
                try
                {
                    player?.SetDataSource(context, Uri.Parse(Uri.Encode(path)));
                }
                catch
                {
                    return(false);
                }
            }

            player.Prepare();

            player.Completion += OnPlaybackEnded;

            return(true);
        }
コード例 #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_keyword);
            // Instantiate the SearchService object.
            ApiKey        = Intent.Extras.GetString("apiKey");
            SearchService = SearchServiceFactory.Create(this, Uri.Encode(ApiKey));

            QueryInput             = FindViewById <EditText>(Resource.Id.edit_text_text_search_query);
            LatInput               = FindViewById <EditText>(Resource.Id.edit_text_text_search_location_lat);
            LngInput               = FindViewById <EditText>(Resource.Id.edit_text_text_search_location_lng);
            RadiusInput            = FindViewById <EditText>(Resource.Id.edit_text_text_search_radius);
            PoiTypeSpinner         = FindViewById <Spinner>(Resource.Id.spinner_text_search_poitype);
            PoiTypeSpinner.Adapter = new ArrayAdapter <LocationType>(this, Android.Resource.Layout.SimpleSpinnerItem, LocationType.Values().ToList());

            Switch UsePOITypeSwitch = FindViewById <Switch>(Resource.Id.switch_text_search_poitype);

            UsePOITypeSwitch.CheckedChange += delegate(object sender, CompoundButton.CheckedChangeEventArgs e)
            {
                PoiTypeSpinner.Enabled = e.IsChecked;
            };
            CountryInput   = FindViewById <EditText>(Resource.Id.edit_text_text_search_country);
            LanguageInput  = FindViewById <EditText>(Resource.Id.edit_text_text_search_language);
            PageIndexInput = FindViewById <EditText>(Resource.Id.edit_text_text_search_pageindex);
            PageSizeInput  = FindViewById <EditText>(Resource.Id.edit_text_text_search_pagesize);
            ResultTextView = FindViewById <TextView>(Resource.Id.response_text_search);

            Childern = FindViewById <Switch>(Resource.Id.switch_text_search_children);

            Search = FindViewById <Button>(Resource.Id.button_text_search);

            Search.Click += delegate { ExecTextSearch(); };

            PoiTypeSpinner.Enabled = false;
        }
コード例 #7
0
        public Task OpenAsync(Placemark placemark, MapLaunchOptions options)
        {
            if (placemark == null)
            {
                throw new ArgumentNullException(nameof(placemark));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var uri = string.Empty;

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"geo:0,0?q={placemark.GetEscapedAddress()}";
                if (!string.IsNullOrWhiteSpace(options.Name))
                {
                    uri += $"({AndroidUri.Encode(options.Name)})";
                }
            }
            else
            {
                uri = $"google.navigation:q={placemark.GetEscapedAddress()}{GetMode(options.NavigationMode)}";
            }

            StartIntent(uri);
            return(Task.CompletedTask);
        }
コード例 #8
0
        public Task OpenAsync(double latitude, double longitude, MapLaunchOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var uri = string.Empty;
            var lat = latitude.ToString(CultureInfo.InvariantCulture);
            var lng = longitude.ToString(CultureInfo.InvariantCulture);

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"geo:{lat},{lng}?q={lat},{lng}";

                if (!string.IsNullOrWhiteSpace(options.Name))
                {
                    uri += $"({AndroidUri.Encode(options.Name)})";
                }
            }
            else
            {
                uri = $"google.navigation:q={lat},{lng}{GetMode(options.NavigationMode)}";
            }

            StartIntent(uri);
            return(Task.CompletedTask);
        }
コード例 #9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_auto_complete);
            // Instantiate the SearchService object.
            ApiKey        = Intent.Extras.GetString("apiKey");
            SearchService = SearchServiceFactory.Create(this, Uri.Encode(ApiKey));

            QueryInput         = FindViewById <EditText>(Resource.Id.query_suggestion_query_input);
            LatInput           = FindViewById <EditText>(Resource.Id.query_suggestion_location_lat_input);
            LngInput           = FindViewById <EditText>(Resource.Id.query_suggestion_location_lng_input);
            RadiusInput        = FindViewById <EditText>(Resource.Id.query_suggestion_radius_input);
            LanguageInput      = FindViewById <EditText>(Resource.Id.query_suggestion_language_input);
            Childern           = FindViewById <Switch>(Resource.Id.switch_query_auto_complete_children);
            AutoCompleteSearch = FindViewById <Button>(Resource.Id.search_query_auto_complete_button);
            ResultTextView     = FindViewById <TextView>(Resource.Id.response_text_search);

            AutoCompleteSearch.Click += delegate { QueryAutoComplete(); };
        }
コード例 #10
0
        private string GetContactInfoFromAddress(long address)
        {
            var uri = Uri.WithAppendedPath(
                ContactsContract.PhoneLookup.ContentFilterUri,
                Uri.Encode(address.ToString()));

            string[] projection =
            {
                ContactsContract.Contacts.InterfaceConsts.Id,
                ContactsContract.Contacts.InterfaceConsts.DisplayName
            };

            var contactCursor = FetchCursor(uri, projection, null);

            if (contactCursor.MoveToFirst())
            {
                string name;

                do
                {
                    var contactId = contactCursor.GetString(
                        contactCursor.GetColumnIndex(projection[0]));

                    var emailAddress = GetEmailFromContactId(contactId);

                    name = contactCursor.GetString(
                        contactCursor.GetColumnIndex(
                            projection[1]));

                    if (!string.IsNullOrEmpty(emailAddress))
                    {
                        return($"{name} <{emailAddress}>");
                    }
                } while (contactCursor.MoveToNext());

                return(name);
            }
            else
            {
                return(address.ToString());
            }
        }
コード例 #11
0
 /// <summary>
 /// Navigate to a particular Coordinate
 /// </summary>
 /// <param name="name">Label to display</param>
 /// <param name="latitude">Latitude</param>
 /// <param name="longitude">Longitude</param>
 /// <param name="zoomLevel">Zoom Level</param>
 public Task <bool> PinTo(string name, double latitude, double longitude, int zoomLevel)
 {
     try
     {
         string uriBegin     = "geo:" + latitude + "," + longitude;
         string query        = latitude + "," + longitude + "(" + name + ")";
         string encodedQuery = Uri.Encode(query);
         string uriString    = uriBegin + "?q=" + encodedQuery + "&z=" + zoomLevel;
         Uri    uri          = Uri.Parse(uriString);
         Intent intent       = new Intent(Intent.ActionView, uri);
         if (TryIntent(intent))
         {
             return(Task.FromResult(true));
         }
     }
     catch (Exception e)
     {
     }
     return(Task.FromResult(false));
 }
コード例 #12
0
ファイル: Map.android.cs プロジェクト: zhamppx97/maui
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            var uri = string.Empty;

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"geo:0,0?q={placemark.GetEscapedAddress()}";
                if (!string.IsNullOrWhiteSpace(options.Name))
                {
                    uri += $"({AndroidUri.Encode(options.Name)})";
                }
            }
            else
            {
                uri = $"google.navigation:q={placemark.GetEscapedAddress()}{GetMode(options.NavigationMode)}";
            }

            StartIntent(uri);
            return(Task.CompletedTask);
        }
コード例 #13
0
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapsLaunchOptions options)
        {
            placemark = placemark.Escape();
            var uri = string.Empty;

            if (options.MapDirectionsMode == MapDirectionsMode.None)
            {
                uri = $"geo:0,0?q={placemark.Thoroughfare} {placemark.Locality} {placemark.AdminArea} {placemark.PostalCode} {placemark.CountryName}";
                if (!string.IsNullOrWhiteSpace(options.Name))
                {
                    uri += $"({AndroidUri.Encode(options.Name)})";
                }
            }
            else
            {
                uri = $"google.navigation:q={placemark.Thoroughfare} {placemark.Locality} {placemark.AdminArea} {placemark.PostalCode} {placemark.CountryName}{GetMode(options.MapDirectionsMode)}";
            }

            StartIntent(uri);
            return(Task.CompletedTask);
        }
コード例 #14
0
ファイル: Contact.cs プロジェクト: dustincjensen/Poke
        /// <summary>
        /// Returns ContactInfo for the phone number.
        /// This may return more than 1 record if they have multiple
        /// contacts in their contact database that have the same number.
        /// </summary>
        /// <param name="phoneNumber">The phone number to look for.</param>
        /// <param name="context">The context to run the method under.</param>
        /// <returns>A list of possible contacts.</returns>
        public static List <ContactInfo> FindContact(string phoneNumber, Context context)
        {
            var contactInfo = new List <ContactInfo>();

            var uri = Uri.WithAppendedPath(
                ContactsContract.CommonDataKinds.Phone.ContentFilterUri, Uri.Encode(phoneNumber));

            var projection = new[]
            {
                ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Id,
                ContactsContract.CommonDataKinds.Phone.InterfaceConsts.DisplayName
            };

            var cursor = context.ContentResolver.Query(uri, projection, null, null, null, null);

            try
            {
                if (cursor.MoveToFirst())
                {
                    do
                    {
                        contactInfo.Add(new ContactInfo
                        {
                            ID          = cursor.GetString(cursor.GetColumnIndexOrThrow(projection[0])),
                            Name        = cursor.GetString(cursor.GetColumnIndexOrThrow(projection[1])),
                            PhoneNumber = phoneNumber
                        });
                    } while (cursor.MoveToNext());
                }
            }
            finally
            {
                cursor.Close();
            }

            // Return the contact info that we found.
            return(contactInfo);
        }
コード例 #15
0
        internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapsLaunchOptions options)
        {
            var uri = string.Empty;
            var lat = latitude.ToString(CultureInfo.InvariantCulture);
            var lng = longitude.ToString(CultureInfo.InvariantCulture);

            if (options.MapDirectionsMode == MapDirectionsMode.None)
            {
                uri = $"geo:{lat},{lng}?q={lat},{lng}";

                if (!string.IsNullOrWhiteSpace(options.Name))
                {
                    uri += $"({AndroidUri.Encode(options.Name)})";
                }
            }
            else
            {
                uri = $"google.navigation:q={lat},{lng}{GetMode(options.MapDirectionsMode)}";
            }

            StartIntent(uri);
            return(Task.CompletedTask);
        }
コード例 #16
0
        static Intent CreateIntent(string recipient, string body = null)
        {
            Intent intent = null;

            body      = body ?? string.Empty;
            recipient = recipient ?? string.Empty;

            if (string.IsNullOrWhiteSpace(recipient) && Platform.HasApiLevel(BuildVersionCodes.Kitkat))
            {
                var packageName = Telephony.Sms.GetDefaultSmsPackage(Platform.CurrentContext);
                if (!string.IsNullOrWhiteSpace(packageName))
                {
                    intent = new Intent(Intent.ActionSend);
                    intent.SetType("text/plain");
                    intent.PutExtra(Intent.ExtraText, body);
                    intent.SetPackage(packageName);

                    return(intent);
                }
            }

            // Fall back to normal send
            intent = new Intent(Intent.ActionView);

            if (!string.IsNullOrWhiteSpace(body))
            {
                intent.PutExtra("sms_body", body);
            }

            intent.PutExtra("address", recipient);

            var uri = AndroidUri.Parse("smsto:" + AndroidUri.Encode(recipient));

            intent.SetData(uri);

            return(intent);
        }
コード例 #17
0
        /// <summary>
        /// Opens the Maps app on Android device.
        /// </summary>
        /// <param name="address">String representing the address.</param>
        /// <param name="coordinate">Coordinate object representing the location.</param>
        /// <returns>Task object that represents this action.</returns>
        public override async Task OpenMapAsync(string address, Coordinate coordinate)
        {
            Intent intent = new Intent(Intent.ActionView);

            if (address != null && coordinate != null)
            {
                intent.SetData(Uri.Parse(string.Format("geo:{0},{1}?q={2}", coordinate.Latitude, coordinate.Longitude, Uri.Encode(address))));
            }
            else if (address != null && coordinate == null)
            {
                intent.SetData(Uri.Parse(string.Format("geo:0,0?q={0}", Uri.Encode(address))));
            }
            else
            {
                intent.SetData(Uri.Parse(string.Format("geo:0,0")));
            }

            if (intent.ResolveActivity(context.PackageManager) != null)
            {
                context.StartActivity(intent);
            }

            await Task.FromResult(true);
        }
コード例 #18
0
ファイル: Sms.android.cs プロジェクト: inthehand/Essentials
        static Intent CreateIntent(string body, List <string> recipients)
        {
            Intent intent = null;

            body = body ?? string.Empty;

            if (Platform.HasApiLevel(BuildVersionCodes.Kitkat) && recipients.All(x => string.IsNullOrWhiteSpace(x)))
            {
                var packageName = Telephony.Sms.GetDefaultSmsPackage(Platform.AppContext);
                if (!string.IsNullOrWhiteSpace(packageName))
                {
                    intent = new Intent(Intent.ActionSend);
                    intent.SetType(FileSystem.MimeTypes.TextPlain);
                    intent.PutExtra(Intent.ExtraText, body);
                    intent.SetPackage(packageName);

                    return(intent);
                }
            }

            // Fall back to normal send
            intent = new Intent(Intent.ActionView);

            if (!string.IsNullOrWhiteSpace(body))
            {
                intent.PutExtra("sms_body", body);
            }

            var recipienturi = string.Join(smsRecipientSeparator, recipients.Select(r => AndroidUri.Encode(r)));

            var uri = AndroidUri.Parse($"smsto:{recipienturi}");

            intent.SetData(uri);

            return(intent);
        }