Skip to content

Commit

Permalink
refactor: Adjust Android conditionals
Browse files Browse the repository at this point in the history
We now compile against Android 12 and Android 13 only, so all #if conditionals < 31 are not needed anymore
  • Loading branch information
MartinZikmund committed Jun 7, 2023
1 parent 1f881e8 commit 9f4c56c
Show file tree
Hide file tree
Showing 23 changed files with 10 additions and 77 deletions.
4 changes: 0 additions & 4 deletions src/AddIns/Uno.UI.Lottie/LottieVisualSourceBase.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,8 @@ public void Play(double fromProgress, double toProgress, bool looped)
SetIsPlaying(true);
if (_animation is { } animation)
{
#if __ANDROID_26__
animation.RepeatCount =
looped ? ValueAnimator.Infinite : 0; // Repeat count doesn't include first time.
#else
animation.Loop(looped);
#endif
animation.SetMinProgress((float)fromProgress);
animation.SetMaxProgress((float)toProgress);
animation.PlayAnimation();
Expand Down
2 changes: 0 additions & 2 deletions src/Uno.UI/ActivityHelper.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public static class ActivityHelper
ConfigChanges.ScreenSize |
ConfigChanges.SmallestScreenSize |
ConfigChanges.Touchscreen |
#if __ANDROID_17__
ConfigChanges.LayoutDirection |
#endif
ConfigChanges.UiMode;
}
}
13 changes: 0 additions & 13 deletions src/Uno.UI/Controls/BindableGridView.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,6 @@ public BindableGridView(Android.Content.Context context, IAttributeSet attrs, Bi
SetupItemClickListeners();
}

#if !__ANDROID_16__
public override void SetColumnWidth(int columnWidth)
{
base.SetColumnWidth(columnWidth);
ColumnWidth = columnWidth;
}

public int ColumnWidth
{
get; private set;
}
#endif

public IEnumerable ItemsSource
{
get { return (IEnumerable)this.GetValue(ItemsSourceProperty); }
Expand Down
8 changes: 0 additions & 8 deletions src/Uno.UI/Controls/BindableSwitchCompat.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,9 @@ private void OnThumbTintChanged(Brush newValue)
{
if (newValue is SolidColorBrush asColorBrush)
{
#if __ANDROID_28__
#pragma warning disable 618 // SetColorFilter is deprecated
ThumbDrawable?.SetColorFilter(asColorBrush.ColorWithOpacity, PorterDuff.Mode.SrcIn);
#pragma warning restore 618 // SetColorFilter is deprecated
#else
ThumbDrawable?.SetColorFilter(new BlendModeColorFilter(asColorBrush.ColorWithOpacity, BlendMode.SrcIn));
#endif
}
}

Expand All @@ -106,13 +102,9 @@ private void OnTrackTintChanged(Brush newValue)
{
if (newValue is SolidColorBrush asColorBrush)
{
#if __ANDROID_28__
#pragma warning disable 618 // SetColorFilter is deprecated
TrackDrawable?.SetColorFilter(asColorBrush.ColorWithOpacity, PorterDuff.Mode.SrcIn);
#pragma warning restore 618 // SetColorFilter is deprecated
#else
TrackDrawable?.SetColorFilter(new BlendModeColorFilter(asColorBrush.ColorWithOpacity, BlendMode.SrcIn));
#endif
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/Uno.UI/Extensions/KeycodeExtensions.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ public static VirtualKey ToVirtualKey(this Keycode keycode)
return VirtualKey.Pause;
case Keycode.CapsLock:
return VirtualKey.CapitalLock;
#if __ANDROID_16__
case Keycode.Kana:
return VirtualKey.Kana;
#endif
//case Keycode.Hangul:
// return VirtualKey.Hangul;
//case Keycode.Junja:
Expand Down Expand Up @@ -102,10 +100,8 @@ public static VirtualKey ToVirtualKey(this Keycode keycode)
return VirtualKey.Insert;
case Keycode.Del:
return VirtualKey.Delete;
#if __ANDROID_21__
case Keycode.Help:
return VirtualKey.Help;
#endif
case Keycode.Num0:
return VirtualKey.Number0;
case Keycode.Num1:
Expand Down Expand Up @@ -184,10 +180,8 @@ public static VirtualKey ToVirtualKey(this Keycode keycode)
// return VirtualKey.RightWindows;
case Keycode.AppSwitch:
return VirtualKey.Application;
#if __ANDROID_20__
case Keycode.Sleep:
return VirtualKey.Sleep;
#endif
case Keycode.Numpad0:
return VirtualKey.NumberPad0;
case Keycode.Numpad1:
Expand Down
2 changes: 0 additions & 2 deletions src/Uno.UI/Extensions/ViewHelper.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,11 @@ public static bool IsLoaded(this View view)
}
else
{
#if __ANDROID_18__
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBeanMr2)
{
return view.WindowId != null;
}
else
#endif
{
return view.WindowToken != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,28 +247,24 @@ private static IDisposable InnerCreateLayers(

private static void SetDrawableAlpha(Drawable drawable, int alpha)
{
#if __ANDROID_18__
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
drawable.Alpha = alpha;
}
else
#endif
{
// Do nothing, not supported by this API Level
}
}

private static void SetOverlay(BindableView view, CompositeDisposable disposables, Drawable overlay)
{
#if __ANDROID_18__
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
ExecuteWithNoRelayout(view, v => v.Overlay.Add(overlay));
disposables.Add(() => ExecuteWithNoRelayout(view, v => v.Overlay.Remove(overlay)));
}
else
#endif
{
// Set overlay is not supported by this platform, set the background instead
// and merge with the existing background.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public Color ForegroundColor
}
}

public
#if __ANDROID_23__
new
#endif
Brush Foreground
public new Brush Foreground
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private void OnBackgroundSizingChanged(DependencyPropertyChangedEventArgs e)
#region Foreground Dependency Property

public
#if __ANDROID_23__
#if __ANDROID__
new
#endif
Brush Foreground
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ protected override void OnApplyTemplate()
#region Foreground Dependency Property

public
#if __ANDROID_23__
#if __ANDROID__
new
#endif
Brush Foreground
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Icons/IconElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public IconElement()
/// Gets or sets a brush that describes the foreground color.
/// </summary>
public
#if __ANDROID_23__
#if __ANDROID__
new
#endif
Brush Foreground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ private void ApplyForeground()
//We only support SolidColorBrush for now
if (_native != null && Foreground is SolidColorBrush foregroundColor)
{
#if __ANDROID_28__
#pragma warning disable 618 // SetColorFilter is deprecated
_native.IndeterminateDrawable?.SetColorFilter(foregroundColor.Color, PorterDuff.Mode.SrcIn);
#pragma warning restore 618 // SetColorFilter is deprecated
#else
_native.IndeterminateDrawable?.SetColorFilter(new BlendModeColorFilter(foregroundColor.Color, BlendMode.SrcIn));
#endif
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ private static void InitializeStaticLayoutInterop()

if (_textDirectionHeuristics == null)
{
#if __ANDROID_18__
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
_textDirectionHeuristics = (Java.Lang.Object)TextDirectionHeuristics.FirststrongLtr;
}
else
#endif
{
// This is required because this class was not exposed until API 18 but available before.

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private void OnTextTrimmingChanged()
#region Foreground Dependency Property

public
#if __ANDROID_23__
#if __ANDROID__
new
#endif
Brush Foreground
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static void SetCursorColor(EditText editText, Color color)
var mCursorDrawableRes = _cursorDrawableResField.GetInt(editText);
var editor = _editorField.Get(editText);

#if __ANDROID_28__
#if __ANDROID__
#pragma warning disable 618 // SetColorFilter is deprecated
if ((int)Build.VERSION.SdkInt < 28) // 28 means BuildVersionCodes.P
{
Expand Down Expand Up @@ -292,7 +292,7 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
}

public
#if __ANDROID_23__
#if __ANDROID__
new
#endif
Brush Foreground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,11 @@ public void Start()
/// <inheritdoc />
public void Pause()
{
#if __ANDROID_19__
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
_adaptee.Pause();
}
else
#endif
{
_adaptee.Cancel();
}
Expand All @@ -227,13 +225,11 @@ public void Pause()
/// <inheritdoc />
public void Resume()
{
#if __ANDROID_19__
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
_adaptee.Resume();
}
else
#endif
{
_adaptee.Start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private void InitializeAnimators()

var i = index;

#if __ANDROID_19__
#if __ANDROID__
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
animator.AnimationPause += (a, _) => OnFrame((IValueAnimator)a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private void InitializeAnimators()

var i = index;

#if __ANDROID_19__
#if __ANDROID__
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
animator.AnimationPause += (a, _) => OnFrame((IValueAnimator)a);
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Media/Animation/Timeline.animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void InitializeAnimator()
}
else
{
#if __ANDROID_19__
#if __ANDROID__
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
_animator.AnimationPause += OnAnimatorAnimationPause;
Expand Down
6 changes: 0 additions & 6 deletions src/Uno.UI/UI/Xaml/Window.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,9 @@ private void InternalSetContent(UIElement value)

internal void RaiseNativeSizeChanged()
{
#if __ANDROID_30__
var (windowBounds, visibleBounds, trueVisibleBounds) = Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.R
? GetVisualBounds()
: GetVisualBoundsLegacy();
#else
var (windowBounds, visibleBounds, trueVisibleBounds) = GetVisualBoundsLegacy();
#endif

ApplicationView.GetForCurrentView()?.SetVisibleBounds(visibleBounds);
ApplicationView.GetForCurrentView()?.SetTrueVisibleBounds(trueVisibleBounds);
Expand All @@ -89,7 +85,6 @@ internal void RaiseNativeSizeChanged()
}
}

#if __ANDROID_30__
private (Rect windowBounds, Rect visibleBounds, Rect trueVisibleBounds) GetVisualBounds()
{
var metrics = (ContextHelper.Current as Activity)?.WindowManager?.CurrentWindowMetrics;
Expand Down Expand Up @@ -117,7 +112,6 @@ internal void RaiseNativeSizeChanged()

return (windowBounds.PhysicalToLogicalPixels(), visibleBounds.PhysicalToLogicalPixels(), visibleBounds.PhysicalToLogicalPixels());
}
#endif

private (Rect windowBounds, Rect visibleBounds, Rect trueVisibleBounds) GetVisualBoundsLegacy()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ private static void ShowPhoneCallUIImpl(string phoneNumber, string displayName)
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
{
#if __ANDROID_24__
phoneNumber = PhoneNumberUtils.FormatNumber(phoneNumber, Java.Util.Locale.GetDefault(Java.Util.Locale.Category.Format).Country);
#endif
}
else if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Uno.UWP/ApplicationModel/PackageId.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public PackageVersion Version

private long GetVersionCode()
{
#if __ANDROID_28__
return AndroidX.Core.Content.PM.PackageInfoCompat.GetLongVersionCode(_packageInfo);
#else
return _packageInfo.VersionCode;
#endif
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Uno.UWP/System/Launcher.Android.SpecialUris.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ public static partial class Launcher
};
if (Build.VERSION.SdkInt >= (BuildVersionCodes)28)
{
#if __ANDROID_28__
settings.Add("network-datausage", Settings.ActionDataUsageSettings);
#endif
}
return settings;
});
Expand Down

0 comments on commit 9f4c56c

Please sign in to comment.