summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-08-10 18:08:18 (GMT)
committerRui Marinho <me@ruimarinho.net>2017-08-10 18:08:18 (GMT)
commit0ff50e2418c1620a86c01004f35dd2855bfe4c0f (patch)
treed7bb35796300b51daea67ad3a37080104aa38dae /Xamarin.Forms.Platform.Android
parent1aab6ff4893935fb3bb91187d2d3fa796576198a (diff)
downloadxamarin-forms-0ff50e2418c1620a86c01004f35dd2855bfe4c0f.zip
xamarin-forms-0ff50e2418c1620a86c01004f35dd2855bfe4c0f.tar.gz
xamarin-forms-0ff50e2418c1620a86c01004f35dd2855bfe4c0f.tar.bz2
Add support for backcompat hint flags (#1074)
* Add support for backcompat hint flags * Making fast renderers internal and sealed while experimental
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs17
-rw-r--r--Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs16
-rw-r--r--Xamarin.Forms.Platform.Android/FastRenderers/GestureManager.cs2
-rw-r--r--Xamarin.Forms.Platform.Android/FastRenderers/ImageRenderer.cs14
-rw-r--r--Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs8
-rw-r--r--Xamarin.Forms.Platform.Android/FastRenderers/VisualElementRenderer.cs4
-rw-r--r--Xamarin.Forms.Platform.Android/Flags.cs7
-rw-r--r--Xamarin.Forms.Platform.Android/Forms.cs13
-rw-r--r--Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj1
9 files changed, 56 insertions, 26 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
index 106080c..b1050d0 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
@@ -116,13 +116,22 @@ namespace Xamarin.Forms.Platform.Android
RegisterHandlerForDefaultRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer), typeof(NavigationRenderer));
RegisterHandlerForDefaultRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer), typeof(TabbedRenderer));
RegisterHandlerForDefaultRenderer(typeof(MasterDetailPage), typeof(MasterDetailPageRenderer), typeof(MasterDetailRenderer));
- RegisterHandlerForDefaultRenderer(typeof(Button), typeof(FastRenderers.ButtonRenderer), typeof(ButtonRenderer));
RegisterHandlerForDefaultRenderer(typeof(Switch), typeof(AppCompat.SwitchRenderer), typeof(SwitchRenderer));
RegisterHandlerForDefaultRenderer(typeof(Picker), typeof(AppCompat.PickerRenderer), typeof(PickerRenderer));
- RegisterHandlerForDefaultRenderer(typeof(Frame), typeof(FastRenderers.FrameRenderer), typeof(FrameRenderer));
RegisterHandlerForDefaultRenderer(typeof(CarouselPage), typeof(AppCompat.CarouselPageRenderer), typeof(CarouselPageRenderer));
- RegisterHandlerForDefaultRenderer(typeof(Label), typeof(FastRenderers.LabelRenderer), typeof(LabelRenderer));
- RegisterHandlerForDefaultRenderer(typeof(Image), typeof(FastRenderers.ImageRenderer), typeof(ImageRenderer));
+
+ if (Forms.Flags.Contains(Flags.FastRenderersExperimental))
+ {
+ RegisterHandlerForDefaultRenderer(typeof(Button), typeof(FastRenderers.ButtonRenderer), typeof(ButtonRenderer));
+ RegisterHandlerForDefaultRenderer(typeof(Label), typeof(FastRenderers.LabelRenderer), typeof(LabelRenderer));
+ RegisterHandlerForDefaultRenderer(typeof(Image), typeof(FastRenderers.ImageRenderer), typeof(ImageRenderer));
+ RegisterHandlerForDefaultRenderer(typeof(Frame), typeof(FastRenderers.FrameRenderer), typeof(FrameRenderer));
+ }
+ else
+ {
+ RegisterHandlerForDefaultRenderer(typeof(Button), typeof(AppCompat.ButtonRenderer), typeof(ButtonRenderer));
+ RegisterHandlerForDefaultRenderer(typeof(Frame), typeof(AppCompat.FrameRenderer), typeof(FrameRenderer));
+ }
_renderersAdded = true;
}
diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs
index 9280098..61fb62c 100644
--- a/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs
@@ -13,7 +13,7 @@ using static System.String;
namespace Xamarin.Forms.Platform.Android.FastRenderers
{
- public class ButtonRenderer : AppCompatButton, IVisualElementRenderer, AView.IOnAttachStateChangeListener,
+ internal sealed class ButtonRenderer : AppCompatButton, IVisualElementRenderer, AView.IOnAttachStateChangeListener,
AView.IOnFocusChangeListener, IEffectControlProvider, AView.IOnClickListener, AView.IOnTouchListener
{
float _defaultFontSize;
@@ -206,12 +206,12 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
return base.OnTouchEvent(e);
}
- protected virtual Size MinimumSize()
+ Size MinimumSize()
{
return new Size();
}
- protected virtual void OnElementChanged(ElementChangedEventArgs<Button> e)
+ void OnElementChanged(ElementChangedEventArgs<Button> e)
{
if (e.OldElement != null)
{
@@ -234,7 +234,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(e.OldElement, e.NewElement));
}
- protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Button.TextProperty.PropertyName)
{
@@ -287,21 +287,21 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
base.OnLayout(changed, l, t, r, b);
}
- protected void SetTracker(VisualElementTracker tracker)
+ void SetTracker(VisualElementTracker tracker)
{
_tracker = tracker;
}
- protected void UpdateBackgroundColor()
+ void UpdateBackgroundColor()
{
_backgroundTracker.UpdateBackgroundColor();
}
- internal virtual void OnNativeFocusChanged(bool hasFocus)
+ internal void OnNativeFocusChanged(bool hasFocus)
{
}
- internal virtual void SendVisualElementInitialized(VisualElement element, AView nativeView)
+ internal void SendVisualElementInitialized(VisualElement element, AView nativeView)
{
element.SendViewInitialized(nativeView);
}
diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/GestureManager.cs b/Xamarin.Forms.Platform.Android/FastRenderers/GestureManager.cs
index 5830899..ec10138 100644
--- a/Xamarin.Forms.Platform.Android/FastRenderers/GestureManager.cs
+++ b/Xamarin.Forms.Platform.Android/FastRenderers/GestureManager.cs
@@ -8,7 +8,7 @@ using Object = Java.Lang.Object;
namespace Xamarin.Forms.Platform.Android.FastRenderers
{
- public class GestureManager : Object, global::Android.Views.View.IOnClickListener, global::Android.Views.View.IOnTouchListener
+ internal class GestureManager : Object, global::Android.Views.View.IOnClickListener, global::Android.Views.View.IOnTouchListener
{
IVisualElementRenderer _renderer;
readonly Lazy<GestureDetector> _gestureDetector;
diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/ImageRenderer.cs b/Xamarin.Forms.Platform.Android/FastRenderers/ImageRenderer.cs
index a230cf5..24623b2 100644
--- a/Xamarin.Forms.Platform.Android/FastRenderers/ImageRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/FastRenderers/ImageRenderer.cs
@@ -8,7 +8,7 @@ using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Platform.Android.FastRenderers
{
- public class ImageRenderer : AImageView, IVisualElementRenderer, IImageRendererController
+ internal sealed class ImageRenderer : AImageView, IVisualElementRenderer, IImageRendererController
{
bool _disposed;
Image _element;
@@ -61,7 +61,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
base.Invalidate();
}
- protected virtual async void OnElementChanged(ElementChangedEventArgs<Image> e)
+ async void OnElementChanged(ElementChangedEventArgs<Image> e)
{
await TryUpdateBitmap(e.OldElement);
UpdateAspect();
@@ -78,7 +78,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
return handled ? result : base.OnTouchEvent(e);
}
- protected virtual Size MinimumSize()
+ Size MinimumSize()
{
return new Size();
}
@@ -148,7 +148,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
void IImageRendererController.SkipInvalidate() => _skipInvalidate = true;
- protected AImageView Control => this;
+ AImageView Control => this;
public event EventHandler<VisualElementChangedEventArgs> ElementChanged;
public event EventHandler<PropertyChangedEventArgs> ElementPropertyChanged;
@@ -157,7 +157,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
{
}
- protected virtual async void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ async void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Image.SourceProperty.PropertyName)
await TryUpdateBitmap();
@@ -167,7 +167,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
ElementPropertyChanged?.Invoke(this, e);
}
- protected virtual async Task TryUpdateBitmap(Image previous = null)
+ async Task TryUpdateBitmap(Image previous = null)
{
// By default we'll just catch and log any exceptions thrown by UpdateBitmap so they don't bring down
// the application; a custom renderer can override this method and handle exceptions from
@@ -187,7 +187,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
}
}
- protected async Task UpdateBitmap(Image previous = null)
+ async Task UpdateBitmap(Image previous = null)
{
if (_element == null || _disposed)
{
diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs b/Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs
index 8c88f0d..f92873b 100644
--- a/Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs
@@ -9,7 +9,7 @@ using AView = Android.Views.View;
namespace Xamarin.Forms.Platform.Android.FastRenderers
{
- public class LabelRenderer : FormsTextView, IVisualElementRenderer
+ internal sealed class LabelRenderer : FormsTextView, IVisualElementRenderer
{
int? _defaultLabelFor;
bool _disposed;
@@ -43,7 +43,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
ViewGroup IVisualElementRenderer.ViewGroup => null;
- protected Label Element
+ Label Element
{
get { return _element; }
set
@@ -169,7 +169,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
return handled ? result : base.OnTouchEvent(e);
}
- protected virtual void OnElementChanged(ElementChangedEventArgs<Label> e)
+ void OnElementChanged(ElementChangedEventArgs<Label> e)
{
ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(e.OldElement, e.NewElement));
@@ -199,7 +199,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
}
}
- protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
ElementPropertyChanged?.Invoke(this, e);
diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Android/FastRenderers/VisualElementRenderer.cs
index 51ad714..91943fb 100644
--- a/Xamarin.Forms.Platform.Android/FastRenderers/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/FastRenderers/VisualElementRenderer.cs
@@ -8,7 +8,7 @@ using Object = Java.Lang.Object;
namespace Xamarin.Forms.Platform.Android.FastRenderers
{
// TODO hartez 2017/03/03 14:11:17 It's weird that this class is called VisualElementRenderer but it doesn't implement that interface. The name should probably be different.
- public class VisualElementRenderer : IDisposable, IEffectControlProvider
+ internal sealed class VisualElementRenderer : IDisposable, IEffectControlProvider
{
bool _disposed;
@@ -56,7 +56,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
GC.SuppressFinalize(this);
}
- protected void Dispose(bool disposing)
+ void Dispose(bool disposing)
{
if (_disposed)
return;
diff --git a/Xamarin.Forms.Platform.Android/Flags.cs b/Xamarin.Forms.Platform.Android/Flags.cs
new file mode 100644
index 0000000..887b538
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/Flags.cs
@@ -0,0 +1,7 @@
+namespace Xamarin.Forms
+{
+ internal static class Flags
+ {
+ internal const string FastRenderersExperimental = "FastRenderers_Experimental";
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/Forms.cs b/Xamarin.Forms.Platform.Android/Forms.cs
index e674563..b568dee 100644
--- a/Xamarin.Forms.Platform.Android/Forms.cs
+++ b/Xamarin.Forms.Platform.Android/Forms.cs
@@ -151,6 +151,19 @@ namespace Xamarin.Forms
IsInitialized = true;
}
+ static IReadOnlyList<string> s_flags;
+ public static IReadOnlyList<string> Flags => s_flags ?? (s_flags = new List<string>().AsReadOnly());
+
+ public static void SetFlags(params string[] flags)
+ {
+ if (IsInitialized)
+ {
+ throw new InvalidOperationException($"{nameof(SetFlags)} must be called before {nameof(Init)}");
+ }
+
+ s_flags = flags.ToList().AsReadOnly();
+ }
+
static Color GetAccentColor()
{
Color rc;
diff --git a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
index 4ebc2c4..91f5db7 100644
--- a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
+++ b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
@@ -128,6 +128,7 @@
<Compile Include="FastRenderers\GestureManager.cs" />
<Compile Include="FastRenderers\LabelRenderer.cs" />
<Compile Include="FastRenderers\VisualElementRenderer.cs" />
+ <Compile Include="Flags.cs" />
<Compile Include="FormsApplicationActivity.cs" />
<Compile Include="AndroidActivity.cs" />
<Compile Include="AndroidTicker.cs" />