Exemplo n.º 1
0
        static Task PlatformComposeAsync(EmailMessage message)
        {
            Permissions.EnsureDeclared(PermissionType.LaunchApp);

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

            if (message.Bcc.Count > 0)
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/bcc", message.Bcc);
            }
            if (!string.IsNullOrEmpty(message.Body))
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/text", message.Body);
            }
            if (message.Cc.Count > 0)
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/cc", message.Cc);
            }
            if (!string.IsNullOrEmpty(message.Subject))
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/subject", message.Subject);
            }
            if (message.To.Count > 0)
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/to", message.To);
            }

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        static Task PlatformRequestAsync(ShareTextRequest request)
        {
            if (string.IsNullOrEmpty(request.Text) && string.IsNullOrEmpty(request.Uri))
            {
                throw new ArgumentNullException(nameof(request.Text));
            }

            Permissions.EnsureDeclared(PermissionType.LaunchApp);

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

            if (!string.IsNullOrEmpty(request.Text))
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/text", request.Text);
            }
            if (!string.IsNullOrEmpty(request.Uri))
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/url", request.Uri);
            }
            if (!string.IsNullOrEmpty(request.Subject))
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/subject", request.Subject);
            }
            if (!string.IsNullOrEmpty(request.Title))
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/title", request.Title);
            }

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Exemplo n.º 3
0
        static async Task <IEnumerable <Placemark> > PlatformGetPlacemarksAsync(double latitude, double longitude)
        {
            Permissions.EnsureDeclared(PermissionType.Maps);
            if (string.IsNullOrWhiteSpace(Platform.MapServiceToken))
            {
                throw new ArgumentNullException(nameof(Platform.MapServiceToken));
            }
            var map = await Platform.GetMapServiceAsync(Platform.MapServiceToken);

            var request = map.CreateReverseGeocodeRequest(latitude, longitude);

            var list = new List <Placemark>();

            foreach (var address in await request.GetResponseAsync())
            {
                list.Add(new Placemark
                {
                    CountryCode     = address.CountryCode,
                    CountryName     = address.Country,
                    AdminArea       = address.State,
                    SubAdminArea    = address.County,
                    Locality        = address.City,
                    SubLocality     = address.District,
                    Thoroughfare    = address.Street,
                    SubThoroughfare = address.Building,
                    FeatureName     = address.Street,
                    Location        = new Location(latitude, longitude),
                    PostalCode      = address.PostalCode,
                });
            }
            return(list);
        }
        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 ?? "*/*";

            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);
        }
Exemplo n.º 5
0
        static Task PlatformComposeAsync(EmailMessage message)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

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

            if (message.Bcc.Count > 0)
            {
                appControl.ExtraData.Add(AppControlData.Bcc, message.Bcc);
            }
            if (!string.IsNullOrEmpty(message.Body))
            {
                appControl.ExtraData.Add(AppControlData.Text, message.Body);
            }
            if (message.Cc.Count > 0)
            {
                appControl.ExtraData.Add(AppControlData.Cc, message.Cc);
            }
            if (!string.IsNullOrEmpty(message.Subject))
            {
                appControl.ExtraData.Add(AppControlData.Subject, message.Subject);
            }
            if (message.To.Count > 0)
            {
                appControl.ExtraData.Add(AppControlData.To, message.To);
            }

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Exemplo n.º 6
0
        static void StartBatteryListeners()
        {
            Permissions.EnsureDeclared(PermissionType.Battery);

            batteryReceiver = new BatteryBroadcastReceiver(OnBatteryChanged);
            Platform.AppContext.RegisterReceiver(batteryReceiver, new IntentFilter(Intent.ActionBatteryChanged));
        }
Exemplo n.º 7
0
 static void PlatformShowSettingsUI()
 {
     Permissions.EnsureDeclared <Permissions.LaunchApp>();
     AppControl.SendLaunchRequest(new AppControl()
     {
         Operation = AppControlOperations.Setting
     });
 }
Exemplo n.º 8
0
        static void StartListeners()
        {
            Permissions.EnsureDeclared(PermissionType.NetworkState);

            conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged);

            Platform.AppContext.RegisterReceiver(conectivityReceiver, new IntentFilter(ConnectivityManager.ConnectivityAction));
        }
Exemplo n.º 9
0
        static void StartListeners()
        {
            Permissions.EnsureDeclared(PermissionType.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
        }
Exemplo n.º 10
0
        static void ValidateBatteryStatsPermission()
        {
            if (hasBatteryStatsPermission)
            {
                return;
            }

            Permissions.EnsureDeclared(PermissionType.Battery);

            hasBatteryStatsPermission = true;
        }
Exemplo n.º 11
0
        static void ValidatePermission()
        {
            if (hasPermission)
            {
                return;
            }

            // Make sure the manifest has declared this permission
            Permissions.EnsureDeclared(PermissionType.NetworkState);

            hasPermission = true;
        }
Exemplo n.º 12
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}");
            }
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        static void PlatformOpen(string number)
        {
            Permissions.EnsureDeclared(PermissionType.LaunchApp);

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

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

            AppControl.SendLaunchRequest(appControl);
        }
Exemplo n.º 16
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}");
     }
 }
Exemplo n.º 17
0
        static void PlatformVibrate(TimeSpan duration)
        {
            Permissions.EnsureDeclared(PermissionType.Vibrate);

            var time = (long)duration.TotalMilliseconds;

            if (Platform.HasApiLevel(BuildVersionCodes.O))
            {
                Platform.Vibrator.Vibrate(VibrationEffect.CreateOneShot(time, VibrationEffect.DefaultAmplitude));
            }
            else
            {
#pragma warning disable CS0618 // Type or member is obsolete
                Platform.Vibrator.Vibrate(time);
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Exemplo n.º 18
0
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

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

            placemark       = placemark.Escape();
            appControl.Uri += $"0,0?q={placemark.Thoroughfare} {placemark.Locality} {placemark.AdminArea} {placemark.PostalCode} {placemark.CountryName}";

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        static void PlatformVibrate(TimeSpan duration)
        {
            Permissions.EnsureDeclared(PermissionType.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
        }
Exemplo n.º 21
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;
		}
        internal static Java.IO.File GetTemporaryRootDirectory()
        {
            // If we specifically want the internal storage, no extra checks are needed, we have permission
            if (TemporaryLocation == FileProviderLocation.Internal)
            {
                return(Platform.AppContext.CacheDir);
            }

            // If we explicitly want only external locations we need to do some permissions checking
            var externalOnly = TemporaryLocation == FileProviderLocation.External;

            // Check to see if we are >= API Level 19 (KitKat) since we don't need to declare the permission on these API levels to save to the external cache/storage
            // If we're not on 19 or higher we do need to check for permissions, but if we aren't limiting to external only, don't throw an exception if the
            // permission wasn't declared because we can always fall back to internal cache
            var hasPermission = Platform.HasApiLevel(BuildVersionCodes.Kitkat) || Permissions.EnsureDeclared(PermissionType.WriteExternalStorage, externalOnly);

            // make sure the external storage is available
            var hasExternalMedia = Platform.HasApiLevel(BuildVersionCodes.Lollipop)
                ? AndroidEnvironment.GetExternalStorageState(Platform.AppContext.ExternalCacheDir) == AndroidEnvironment.MediaMounted
#pragma warning disable CS0618 // Type or member is obsolete
                : AndroidEnvironment.GetStorageState(Platform.AppContext.ExternalCacheDir) == AndroidEnvironment.MediaMounted;

#pragma warning restore CS0618 // Type or member is obsolete

            // undo all the work if we have requested a fail (mainly for testing)
            if (AlwaysFailExternalMediaAccess)
            {
                hasExternalMedia = false;
            }

            // fail if we need the external storage, but there is none
            if (externalOnly && !hasExternalMedia)
            {
                throw new InvalidOperationException("Unable to access the external storage, the media is not mounted.");
            }

            // based on permssions, return the correct directory
            // if permission were required, then it would have already thrown
            return(hasPermission && hasExternalMedia
                ? Platform.AppContext.ExternalCacheDir
                : Platform.AppContext.CacheDir);
        }
Exemplo n.º 23
0
        internal static Task SwitchFlashlight(bool switchOn)
        {
            Permissions.EnsureDeclared(PermissionType.Flashlight);
            return(Task.Run(() =>
            {
                if (!IsSupported)
                {
                    throw new FeatureNotSupportedException();
                }

                if (switchOn)
                {
                    Led.Brightness = Led.MaxBrightness;
                }
                else
                {
                    Led.Brightness = 0;
                }
            }));
        }
Exemplo n.º 24
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      = "*/*",
                Uri       = "file://" + request.File.FullPath,
            };

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Exemplo n.º 25
0
        static Task PlatformRequestAsync(ShareFileRequest request)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

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

            if (!string.IsNullOrEmpty(request.File.FullPath))
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/path", request.File.FullPath);
            }
            if (!string.IsNullOrEmpty(request.Title))
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/title", request.Title);
            }

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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,
            };

            if (!string.IsNullOrEmpty(request.File.FullPath))
            {
                appControl.ExtraData.Add("http://tizen.org/appcontrol/data/path", request.File.FullPath);
            }

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Exemplo n.º 28
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("http://tizen.org/appcontrol/data/text", message.Body);
            }
            if (message.Recipients.Count > 0)
            {
                appControl.Uri += string.Join(" ", message.Recipients);
            }

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
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);
        }