Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell Android Handler #979

Merged
merged 2 commits into from Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -59,20 +59,20 @@

namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.Android
{
public class ShellWithCustomRendererDisabledAnimationsRenderer : ShellRenderer
public class ShellWithCustomRendererDisabledAnimationsRenderer : ShellView
{
public ShellWithCustomRendererDisabledAnimationsRenderer(Context context) : base(context)
{
}

protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
protected override IShellItemView CreateShellItemView(ShellItem shellItem)
{
return new ShellWithCustomRendererDisabledAnimationsShellItemRenderer(this);
}

public class ShellWithCustomRendererDisabledAnimationsShellItemRenderer : ShellItemRenderer
public class ShellWithCustomRendererDisabledAnimationsShellItemRenderer : ShellItemView
{
public ShellWithCustomRendererDisabledAnimationsShellItemRenderer(IShellContext shellContext) : base(shellContext)
public ShellWithCustomRendererDisabledAnimationsShellItemRenderer(Controls.Platform.IShellContext shellContext) : base(shellContext)
{
}

Expand Down
Expand Up @@ -216,20 +216,20 @@ void SetupAutomationDefaults()
if (!_defaultAutomationSet)
{
_defaultAutomationSet = true;
AutomationPropertiesProvider.SetupDefaults(this, ref _defaultContentDescription);
Controls.Platform.AutomationPropertiesProvider.SetupDefaults(this, ref _defaultContentDescription);
}
}

protected virtual void SetAutomationId(string id)
{
SetupAutomationDefaults();
AutomationPropertiesProvider.SetAutomationId(this, Element, id);
Controls.Platform.AutomationPropertiesProvider.SetAutomationId(this, Element, id);
}

protected virtual void SetContentDescription()
{
SetupAutomationDefaults();
AutomationPropertiesProvider.SetContentDescription(this, Element, _defaultContentDescription, null);
Controls.Platform.AutomationPropertiesProvider.SetContentDescription(this, Element, _defaultContentDescription, null);
}

protected override void Dispose(bool disposing)
Expand Down
Expand Up @@ -11,6 +11,7 @@
using AndroidX.AppCompat.App;
using Microsoft.Maui.Controls.Compatibility.Platform.Android.AppCompat;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific.AppCompat;
using AColor = Android.Graphics.Color;
Expand Down
Expand Up @@ -5,6 +5,7 @@
using AndroidX.Fragment.App;
using Java.Lang;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Platform;
using FragmentTransit = Android.App.FragmentTransit;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android.AppCompat
Expand Down
18 changes: 2 additions & 16 deletions src/Compatibility/Core/src/Android/AppCompat/FormsViewPager.cs
Expand Up @@ -4,10 +4,11 @@
using Android.Util;
using Android.Views;
using AndroidX.ViewPager.Widget;
using Microsoft.Maui.Controls.Platform;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android.AppCompat
{
internal class FormsViewPager : ViewPager
internal class FormsViewPager : MauiViewPager
{
public FormsViewPager(Context context) : base(context)
{
Expand All @@ -20,20 +21,5 @@ public FormsViewPager(Context context, IAttributeSet attrs) : base(context, attr
protected FormsViewPager(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}

public bool EnableGesture { get; set; } = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all inside MauiViewPager now


public override bool OnInterceptTouchEvent(MotionEvent ev)
{
// Same as:
// if (!EnableGesture) return false;
// However this is, at least in theory a tidge faster which in this particular area is good
return EnableGesture && base.OnInterceptTouchEvent(ev);
}

public override bool OnTouchEvent(MotionEvent e)
{
return EnableGesture && base.OnTouchEvent(e);
}
}
}
Expand Up @@ -655,7 +655,7 @@ void RegisterToolbar()

_drawerLayout = renderer;

FastRenderers.AutomationPropertiesProvider.GetDrawerAccessibilityResources(context, _flyoutPage, out int resourceIdOpen, out int resourceIdClose);
Controls.Platform.AutomationPropertiesProvider.GetDrawerAccessibilityResources(context, _flyoutPage, out int resourceIdOpen, out int resourceIdClose);

if (_drawerToggle != null)
{
Expand Down Expand Up @@ -910,18 +910,18 @@ void UpdateMenu()

_currentMenuItems.Clear();
_currentMenuItems = new List<IMenuItem>();
_toolbar.UpdateMenuItems(_toolbarTracker?.ToolbarItems, Context, null, OnToolbarItemPropertyChanged, _currentMenuItems, _currentToolbarItems, UpdateMenuItemIcon);
_toolbar.UpdateMenuItems(_toolbarTracker?.ToolbarItems, Element.FindMauiContext(), null, OnToolbarItemPropertyChanged, _currentMenuItems, _currentToolbarItems, UpdateMenuItemIcon);
}

protected virtual void OnToolbarItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
var items = _toolbarTracker?.ToolbarItems?.ToList();
_toolbar.OnToolbarItemPropertyChanged(e, (ToolbarItem)sender, items, Context, null, OnToolbarItemPropertyChanged, _currentMenuItems, _currentToolbarItems, UpdateMenuItemIcon);
_toolbar.OnToolbarItemPropertyChanged(e, (ToolbarItem)sender, items, Element.FindMauiContext(), null, OnToolbarItemPropertyChanged, _currentMenuItems, _currentToolbarItems, UpdateMenuItemIcon);
}

protected virtual void UpdateMenuItemIcon(Context context, IMenuItem menuItem, ToolbarItem toolBarItem)
{
ToolbarExtensions.UpdateMenuItemIcon(context, menuItem, toolBarItem, null);
ToolbarExtensions.UpdateMenuItemIcon(Element.FindMauiContext(), menuItem, toolBarItem, null);
}

void UpdateToolbar()
Expand Down Expand Up @@ -1055,7 +1055,7 @@ void UpdateTitleIcon()
_ = this.ApplyDrawableAsync(currentPage, NavigationPage.TitleIconImageSourceProperty, Context, drawable =>
{
_titleIconView.SetImageDrawable(drawable);
FastRenderers.AutomationPropertiesProvider.AccessibilitySettingsChanged(_titleIconView, source);
AutomationPropertiesProvider.AccessibilitySettingsChanged(_titleIconView, source);
});
}
}
Expand Down
Expand Up @@ -28,7 +28,7 @@ public class RadioButtonRenderer : AppCompatRadioButton,
bool _isDisposed;
bool _inputTransparent;
Lazy<TextColorSwitcher> _textColorSwitcher;
AutomationPropertiesProvider _automationPropertiesProvider;
FastRenderers.AutomationPropertiesProvider _automationPropertiesProvider;
VisualElementTracker _tracker;
VisualElementRenderer _visualElementRenderer;
BorderBackgroundManager _backgroundTracker;
Expand Down Expand Up @@ -235,7 +235,7 @@ internal void SendVisualElementInitialized(VisualElement element, AView nativeVi

void Initialize()
{
_automationPropertiesProvider = new AutomationPropertiesProvider(this);
_automationPropertiesProvider = new FastRenderers.AutomationPropertiesProvider(this);
_backgroundTracker = new BorderBackgroundManager(this);

SoundEffectsEnabled = false;
Expand Down
Expand Up @@ -658,7 +658,7 @@ void SetupBottomNavigationView(NotifyCollectionChangedEventArgs e)
items,
currentIndex,
_bottomNavigationView,
Context);
Element.FindMauiContext());

if (Element.CurrentPage == null && Element.Children.Count > 0)
Element.CurrentPage = Element.Children[0];
Expand Down Expand Up @@ -863,7 +863,7 @@ public bool OnNavigationItemSelected(IMenuItem item)
if (id == BottomNavigationViewUtils.MoreTabId)
{
var items = CreateTabList();
var bottomSheetDialog = BottomNavigationViewUtils.CreateMoreBottomSheet(OnMoreItemSelected, Context, items, _bottomNavigationView.MaxItemCount);
var bottomSheetDialog = BottomNavigationViewUtils.CreateMoreBottomSheet(OnMoreItemSelected, Element.FindMauiContext(), items, _bottomNavigationView.MaxItemCount);
bottomSheetDialog.DismissEvent += OnMoreSheetDismissed;
bottomSheetDialog.Show();
}
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/Android/CellAdapter.cs
Expand Up @@ -9,6 +9,7 @@
using AActionMode = global::AndroidX.AppCompat.View.ActionMode;
using AListView = Android.Widget.ListView;
using AView = Android.Views.View;
using Microsoft.Maui.Controls.Platform;
#if NET6_0
using AMenu = Android.Views.IMenu;
#else
Expand Down
Expand Up @@ -6,6 +6,7 @@
using Android.Widget;
using AndroidX.Core.Widget;
using Java.Lang;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
Expand Down
Expand Up @@ -18,7 +18,7 @@ public abstract class ItemsViewRenderer<TItemsView, TAdapter, TItemsViewSource>
where TAdapter : ItemsViewAdapter<TItemsView, TItemsViewSource>
where TItemsViewSource : IItemsViewSource
{
readonly AutomationPropertiesProvider _automationPropertiesProvider;
readonly FastRenderers.AutomationPropertiesProvider _automationPropertiesProvider;
readonly EffectControlProvider _effectControlProvider;

protected TAdapter ItemsViewAdapter;
Expand Down Expand Up @@ -46,7 +46,7 @@ public abstract class ItemsViewRenderer<TItemsView, TAdapter, TItemsViewSource>
new ContextThemeWrapper(context, Microsoft.Maui.Controls.Compatibility.Resource.Style.collectionViewTheme), null,
Microsoft.Maui.Controls.Compatibility.Resource.Attribute.collectionViewStyle)
{
_automationPropertiesProvider = new AutomationPropertiesProvider(this);
_automationPropertiesProvider = new FastRenderers.AutomationPropertiesProvider(this);
_effectControlProvider = new EffectControlProvider(this);

_emptyCollectionObserver = new DataChangeObserver(UpdateEmptyViewVisibility);
Expand Down
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using Android.Content;
using Android.Views;
using Microsoft.Maui.Controls.Platform;
using ADragFlags = Android.Views.DragFlags;
using AUri = Android.Net.Uri;
using AView = Android.Views.View;
Expand Down Expand Up @@ -265,7 +266,7 @@ public void OnLongPress(MotionEvent e)
customLocalStateData.DataPackage = args.Data;

//_dragSource[element] = args.Data;
string clipDescription = FastRenderers.AutomationPropertiesProvider.ConcatenateNameAndHelpText(element) ?? String.Empty;
string clipDescription = AutomationPropertiesProvider.ConcatenateNameAndHelpText(element) ?? String.Empty;
ClipData.Item item = null;
List<string> mimeTypes = new List<string>();

Expand Down
Expand Up @@ -29,7 +29,7 @@ public override void OnInitializeAccessibilityNodeInfo(global::Android.Views.Vie
if (_element != null)
{
var value = string.IsNullOrWhiteSpace(ValueText) ? string.Empty : $"{ValueText}. ";
host.ContentDescription = $"{value}{AutomationPropertiesProvider.ConcatenateNameAndHelpText(_element)}";
host.ContentDescription = $"{value}{Controls.Platform.AutomationPropertiesProvider.ConcatenateNameAndHelpText(_element)}";
}
}
}
Expand Down
Expand Up @@ -115,28 +115,6 @@ public static string SetNavigationContentDescription(this AToolbar Control, Elem
return _defaultNavigationContentDescription;
}

public static void SetTitleOrContentDescription(this IMenuItem Control, ToolbarItem Element)
{
SetTitleOrContentDescription(Control, (MenuItem)Element);
}

public static void SetTitleOrContentDescription(this IMenuItem Control, MenuItem Element)
{
if (Element == null)
return;

var elemValue = ConcatenateNameAndHint(Element);

if (string.IsNullOrWhiteSpace(elemValue))
elemValue = Element.AutomationId;
else if (!String.IsNullOrEmpty(Element.Text))
elemValue = String.Join(". ", Element.Text, elemValue);

if (!string.IsNullOrWhiteSpace(elemValue))
AMenuItemCompat.SetContentDescription(Control, elemValue);

}

static string ConcatenateNameAndHint(Element Element)
{
string separator;
Expand Down