Procházet zdrojové kódy

Added Live Geolocation to Android Platform
Tweaked some UI resources

Frank van den Bos před 1 měsícem
rodič
revize
38a62f2220

+ 22 - 0
InABox.Avalonia.Platform.Android/Geolocation.Android.cs

@@ -0,0 +1,22 @@
+using InABox.Core;
+using Microsoft.Maui.Devices.Sensors;
+
+namespace InABox.Avalonia.Platform.Android;
+
+public class Android_Geolocation : DefaultGeolocation
+{
+    public Logger? Logger { get; set; }
+    
+    public override async Task<GeoPoint?> GetLocationAsync(CancellationTokenSource cancel)
+    {
+        GeolocationRequest request =
+            new GeolocationRequest(GeolocationAccuracy.Medium, TimeSpan.FromSeconds(10));
+        
+        var location =
+            await Geolocation.Default.GetLocationAsync(request, cancel.Token);
+        
+        return location != null 
+            ? new GeoPoint((float)location.Latitude, (float)location.Longitude) 
+            : null;
+    }
+}

+ 74 - 2
InABox.Avalonia/Converters/BooleanToColorConverter.cs

@@ -1,5 +1,6 @@
 using System;
 using Avalonia.Media;
+using Avalonia.Media.Immutable;
 
 namespace InABox.Avalonia.Converters
 {
@@ -9,13 +10,84 @@ namespace InABox.Avalonia.Converters
         public IBrush False{ get; set; }
         
         public IBrush True { get; set; }
+
+        public double Opacity { get; set; } = 1.0;
         
         protected override IBrush Convert(bool value, object parameter = null)
         {
             return value
-                ? True
-                : False;
+                ? CloneBrushWithOpacity(True,Opacity)
+                : CloneBrushWithOpacity(False,Opacity);
+        }
+        
+        private IBrush CloneBrushWithOpacity(IBrush value, double opacity)
+        {
+            opacity = Math.Clamp(opacity, 0.0, 1.0);
+    
+            switch (value)
+            {
+                
+                case ImmutableSolidColorBrush scb:
+                    return new ImmutableSolidColorBrush(scb.Color, scb.Opacity * opacity);
+                case SolidColorBrush scb:
+                    return new SolidColorBrush(scb.Color, scb.Opacity * opacity);
+    
+                case LinearGradientBrush lgb:
+                    var linear = new LinearGradientBrush
+                    {
+                        StartPoint = lgb.StartPoint,
+                        EndPoint = lgb.EndPoint,
+                        SpreadMethod = lgb.SpreadMethod,
+                        GradientStops = CloneGradientStops(lgb.GradientStops, opacity)
+                    };
+                    linear.Transform = lgb.Transform;
+                    return linear;
+    
+                case RadialGradientBrush rgb:
+                    var radial = new RadialGradientBrush
+                    {
+                        Center = rgb.Center,
+                        GradientOrigin = rgb.GradientOrigin,
+                        Radius = rgb.Radius,
+                        SpreadMethod = rgb.SpreadMethod,
+                        GradientStops = CloneGradientStops(rgb.GradientStops, opacity)
+                    };
+                    radial.Transform = rgb.Transform;
+                    return radial;
+    
+                case ImageBrush ib:
+                    return new ImageBrush
+                    {
+                        Source = ib.Source,
+                        AlignmentX = ib.AlignmentX,
+                        AlignmentY = ib.AlignmentY,
+                        Stretch = ib.Stretch,
+                        TileMode = ib.TileMode,
+                        DestinationRect = ib.DestinationRect,
+                        SourceRect = ib.SourceRect,
+                        Opacity = ib.Opacity * opacity
+                    };
+    
+                default:
+                    return value;
+            }
+        }
+        
+        private GradientStops CloneGradientStops(GradientStops stops, double opacity)
+        {
+            var gs = new GradientStops();
+
+            foreach (var stop in stops)
+            {
+                gs.Add(new GradientStop(
+                    stop.Color,
+                    stop.Offset)
+                );
+            }
+
+            return gs;
         }
 
     }
+
 }

+ 14 - 0
InABox.Avalonia/Converters/MultiConverters/ByteArrayToBooleanConverter.cs

@@ -0,0 +1,14 @@
+namespace InABox.Avalonia.Converters;
+
+public class ByteArrayToBooleanConverter : AbstractConverter<byte[]?, bool>
+{
+
+    public bool Inverted { get; set; } = false;
+    
+    protected override bool Convert(byte[]? value, object? parameter = null)
+    {
+        return value?.Any() == true
+            ? !Inverted
+            : Inverted;
+    }
+}

+ 2 - 0
InABox.Avalonia/Theme/Fonts.axaml

@@ -2,6 +2,8 @@
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:system="clr-namespace:System;assembly=System.Runtime">
 
+    <system:Double x:Key="PrsFontSizeSuperLarge">28</system:Double>
+    
     <system:Double x:Key="PrsFontSizeExtraLarge">20</system:Double>
 
     <system:Double x:Key="PrsFontSizeLarge">16</system:Double>