示例#1
0
        static async Task <IEnumerable <FileResult> > PlatformPickAsync(PickOptions options, bool allowMultiple = false)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();
            await Permissions.EnsureGrantedAsync <Permissions.StorageRead>();

            var tcs = new TaskCompletionSource <IEnumerable <FileResult> >();

            var appControl = new AppControl();

            appControl.Operation = AppControlOperations.Pick;
            appControl.ExtraData.Add(AppControlData.SectionMode, allowMultiple ? "multiple" : "single");
            appControl.LaunchMode = AppControlLaunchMode.Single;

            var fileType = options?.FileTypes?.Value?.FirstOrDefault();

            appControl.Mime = fileType ?? FileSystem.MimeTypes.All;

            var fileResults = new List <FileResult>();

            AppControl.SendLaunchRequest(appControl, (request, reply, result) =>
            {
                if (result == AppControlReplyResult.Succeeded)
                {
                    if (reply.ExtraData.Count() > 0)
                    {
                        var selectedFiles = reply.ExtraData.Get <IEnumerable <string> >(AppControlData.Selected).ToList();
                        fileResults.AddRange(selectedFiles.Select(f => new FileResult(f)));
                    }
                }

                tcs.TrySetResult(fileResults);
            });

            return(await tcs.Task);
        }
示例#2
0
 static void PlatformShowSettingsUI()
 {
     Permissions.EnsureDeclared <Permissions.LaunchApp>();
     AppControl.SendLaunchRequest(new AppControl()
     {
         Operation = AppControlOperations.Setting
     });
 }
示例#3
0
        static void StartListeners()
        {
            Permissions.EnsureDeclared <Permissions.NetworkState>();

            conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged);

#pragma warning disable CS0618 // Type or member is obsolete
            Platform.AppContext.RegisterReceiver(conectivityReceiver, new IntentFilter(ConnectivityManager.ConnectivityAction));
#pragma warning restore CS0618 // Type or member is obsolete
        }
示例#4
0
        static void PlatformPerform(HapticFeedbackType type)
        {
            Permissions.EnsureDeclared <Permissions.Vibrate>();

            try
            {
                Platform.CurrentActivity?.Window?.DecorView?.PerformHapticFeedback(ConvertType(type));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
            }
        }
示例#5
0
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.Pick,
                Uri       = "geo:",
            };

            appControl.Uri += $"0,0?q={placemark.GetEscapedAddress()}";

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
示例#6
0
        internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapLaunchOptions options)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.View,
                Uri       = "geo:",
            };

            appControl.Uri += $"{latitude.ToString(CultureInfo.InvariantCulture)},{longitude.ToString(CultureInfo.InvariantCulture)}";

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
示例#7
0
        static void PlatformOpen(string number)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.Dial,
                Uri       = "tel:",
            };

            if (!string.IsNullOrEmpty(number))
            {
                appControl.Uri += number;
            }

            AppControl.SendLaunchRequest(appControl);
        }
示例#8
0
 static void PlatformPerform(HapticFeedbackType type)
 {
     Permissions.EnsureDeclared <Permissions.Vibrate>();
     try
     {
         var feedback = new Feedback();
         var pattern  = ConvertType(type);
         if (feedback.IsSupportedPattern(FeedbackType.Vibration, pattern))
         {
             feedback.Play(FeedbackType.Vibration, pattern);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
     }
 }
示例#9
0
        static async Task <IEnumerable <Location> > PlatformGetLocationsAsync(string address)
        {
            Permissions.EnsureDeclared <Permissions.Maps>();
            if (string.IsNullOrWhiteSpace(Platform.MapServiceToken))
            {
                throw new ArgumentNullException(nameof(Platform.MapServiceToken));
            }
            var map = await Platform.GetMapServiceAsync(Platform.MapServiceToken);

            var request = map.CreateGeocodeRequest(address);
            var list    = new List <Location>();

            foreach (var position in await request.GetResponseAsync())
            {
                list.Add(new Location(position.Latitude, position.Longitude));
            }
            return(list);
        }
示例#10
0
        static void PlatformVibrate(TimeSpan duration)
        {
            Permissions.EnsureDeclared <Permissions.Vibrate>();

            var time = (long)duration.TotalMilliseconds;

#if __ANDROID_26__
            if (Platform.HasApiLevelO)
            {
                Platform.Vibrator.Vibrate(VibrationEffect.CreateOneShot(time, VibrationEffect.DefaultAmplitude));
                return;
            }
#endif

#pragma warning disable CS0618 // Type or member is obsolete
            Platform.Vibrator.Vibrate(time);
#pragma warning restore CS0618 // Type or member is obsolete
        }
示例#11
0
        internal static Task SwitchFlashlight(bool switchOn)
        {
            Permissions.EnsureDeclared <Permissions.Flashlight>();
            return(Task.Run(() =>
            {
                if (!IsSupported)
                {
                    throw new FeatureNotSupportedException();
                }

                if (switchOn)
                {
                    Led.Brightness = Led.MaxBrightness;
                }
                else
                {
                    Led.Brightness = 0;
                }
            }));
        }
示例#12
0
        static Task PlatformOpenAsync(OpenFileRequest request)
        {
            if (string.IsNullOrEmpty(request.File.FullPath))
            {
                throw new ArgumentNullException(nameof(request.File.FullPath));
            }

            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.View,
                Mime      = FileSystem.MimeTypes.All,
                Uri       = "file://" + request.File.FullPath,
            };

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
示例#13
0
        static void StartListeners()
        {
            Permissions.EnsureDeclared <Permissions.NetworkState>();

            var filter = new IntentFilter();

            if (Platform.HasApiLevelN)
            {
                RegisterNetworkCallback();
                filter.AddAction(Platform.EssentialsConnectivityChanged);
            }
            else
            {
#pragma warning disable CS0618 // Type or member is obsolete
                filter.AddAction(ConnectivityManager.ConnectivityAction);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged);

            Platform.AppContext.RegisterReceiver(conectivityReceiver, filter);
        }
示例#14
0
        static Task PlatformRequestAsync(ShareMultipleFilesRequest request)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.Share,
            };

            if (!string.IsNullOrEmpty(request.Title))
            {
                appControl.ExtraData.Add(AppControlData.Title, request.Title);
            }

            foreach (var file in request.Files)
            {
                appControl.ExtraData.Add(AppControlData.Path, file.FullPath);
            }

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
示例#15
0
        static Task PlatformComposeAsync(SmsMessage message)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.Compose,
                Uri       = "sms:",
            };

            if (!string.IsNullOrEmpty(message.Body))
            {
                appControl.ExtraData.Add(AppControlData.Text, message.Body);
            }
            if (message.Recipients.Count > 0)
            {
                appControl.Uri += string.Join(" ", message.Recipients);
            }

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
示例#16
0
        static async Task <Contact> PlatformPickContactAsync()
        {
            Permissions.EnsureDeclared <Permissions.ContactsRead>();
            Permissions.EnsureDeclared <Permissions.LaunchApp>();
            await Permissions.EnsureGrantedAsync <Permissions.ContactsRead>();

            var tcs = new TaskCompletionSource <Contact>();

            var appControl = new AppControl();

            appControl.Operation = AppControlOperations.Pick;
            appControl.ExtraData.Add(AppControlData.SectionMode, "single");
            appControl.LaunchMode = AppControlLaunchMode.Single;
            appControl.Mime       = "application/vnd.tizen.contact";

            AppControl.SendLaunchRequest(appControl, (request, reply, result) =>
            {
                Contact contact = null;

                if (result == AppControlReplyResult.Succeeded)
                {
                    var contactId = reply.ExtraData.Get <IEnumerable <string> >(AppControlData.Selected)?.FirstOrDefault();

                    if (int.TryParse(contactId, out var contactInt))
                    {
                        var record = manager.Database.Get(TizenContact.Uri, contactInt);
                        if (record != null)
                        {
                            contact = ToContact(record);
                        }
                    }
                }
                tcs.TrySetResult(contact);
            });

            return(await tcs.Task);
        }
示例#17
0
        static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions launchMode)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.View,
                Uri       = uri.AbsoluteUri
            };

            var hasMatches = AppControl.GetMatchedApplicationIds(appControl).Any();

            if (hasMatches)
            {
                AppControl.SendLaunchRequest(appControl);
            }

            return(Task.FromResult(hasMatches));
        }
示例#18
0
 static void StartListeners()
 {
     Permissions.EnsureDeclared <Permissions.NetworkState>();
     ConnectionManager.ConnectionTypeChanged += OnChanged;
     GetProfileListAsync();
 }
示例#19
0
        static void PlatformCancel()
        {
            Permissions.EnsureDeclared <Permissions.Vibrate>();

            Platform.Vibrator.Cancel();
        }
示例#20
0
 static void PlatformCancel()
 {
     Permissions.EnsureDeclared <Permissions.Vibrate>();
     Vibrator.Vibrators.FirstOrDefault()?.Stop();
 }
示例#21
0
 static void PlatformVibrate(TimeSpan duration)
 {
     Permissions.EnsureDeclared <Permissions.Vibrate>();
     Vibrator.Vibrators.FirstOrDefault()?.Vibrate((int)duration.TotalMilliseconds, 100);
 }