public static void UpdateBarTextColor(this AToolbar nativeToolbar, Toolbar toolbar) { var textColor = toolbar.BarTextColor; // Because we use the same toolbar across multiple navigation pages (think tabbed page with nested NavigationPage) // We need to reset the toolbar text color to the default color when it's unset if (_defaultTitleTextColor == null) { var context = nativeToolbar.Context?.GetThemedContext(); _defaultTitleTextColor = PlatformInterop.GetColorStateListForToolbarStyleableAttribute(context, Resource.Attribute.toolbarStyle, Resource.Styleable.Toolbar_titleTextColor); } if (textColor != null) { nativeToolbar.SetTitleTextColor(textColor.ToPlatform().ToArgb()); } else if (_defaultTitleTextColor != null) { nativeToolbar.SetTitleTextColor(_defaultTitleTextColor); } if (nativeToolbar.NavigationIcon is DrawerArrowDrawable icon) { if (textColor != null) { _defaultNavigationIconColor = icon.Color; icon.Color = textColor.ToPlatform().ToArgb(); } else if (_defaultNavigationIconColor != null) { icon.Color = _defaultNavigationIconColor.Value; } } }
public override Task <IImageSourceServiceResult <Drawable>?> GetDrawableAsync(IImageSource imageSource, Context context, CancellationToken cancellationToken = default) { var fileImageSource = (IFileImageSource)imageSource; if (!fileImageSource.IsEmpty) { try { var id = context?.GetDrawableId(fileImageSource.File) ?? -1; if (id > 0) { var d = context?.GetDrawable(id); if (d is not null) { return(Task.FromResult <IImageSourceServiceResult <Drawable>?>(new ImageSourceServiceResult(d))); } } var drawableCallback = new ImageLoaderResultCallback(); PlatformInterop.LoadImageFromFile(context, fileImageSource.File, drawableCallback); return(drawableCallback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image file '{File}'.", fileImageSource.File); throw; } } return(Task.FromResult <IImageSourceServiceResult <Drawable>?>(null)); }
public override Task <IImageSourceServiceResult <Drawable>?> GetDrawableAsync(IImageSource imageSource, Context context, CancellationToken cancellationToken = default) { var fontImageSource = (IFontImageSource)imageSource; if (!fontImageSource.IsEmpty) { var size = FontManager.GetFontSize(fontImageSource.Font); var unit = fontImageSource.Font.AutoScalingEnabled ? ComplexUnitType.Sp : ComplexUnitType.Dip; var textSize = TypedValue.ApplyDimension(unit, size.Value, context?.Resources?.DisplayMetrics); var typeface = FontManager.GetTypeface(fontImageSource.Font); var color = (fontImageSource.Color ?? Graphics.Colors.White).ToPlatform(); try { var drawableCallback = new ImageLoaderResultCallback(); PlatformInterop.LoadImageFromFont( context, color, fontImageSource.Glyph, typeface, textSize, drawableCallback); return(drawableCallback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to generate font image '{Glyph}'.", fontImageSource.Glyph); throw; } } return(Task.FromResult <IImageSourceServiceResult <Drawable>?>(null)); }
public static void Initialize(this AView platformView, IView view) { var pivotX = (float)(view.AnchorX * platformView.ToPixels(view.Frame.Width)); var pivotY = (float)(view.AnchorY * platformView.ToPixels(view.Frame.Height)); int visibility; if (view is IActivityIndicator a) { visibility = (int)a.GetActivityIndicatorVisibility(); } else { visibility = (int)view.Visibility.ToPlatformVisibility(); } // NOTE: use named arguments for clarity PlatformInterop.Set(platformView, visibility: visibility, layoutDirection: (int)GetLayoutDirection(view), minimumHeight: (int)platformView.ToPixels(view.MinimumHeight), minimumWidth: (int)platformView.ToPixels(view.MinimumWidth), enabled: view.IsEnabled, alpha: (float)view.Opacity, translationX: platformView.ToPixels(view.TranslationX), translationY: platformView.ToPixels(view.TranslationY), scaleX: (float)(view.Scale * view.ScaleX), scaleY: (float)(view.Scale * view.ScaleY), rotation: (float)view.Rotation, rotationX: (float)view.RotationX, rotationY: (float)view.RotationY, pivotX: pivotX, pivotY: pivotY ); }
public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { base.OnCreateView(inflater, container, savedInstanceState); var context = MauiContext.Context; _outerLayout = PlatformInterop.CreateNavigationBarOuterLayout(context); _navigationArea = PlatformInterop.CreateNavigationBarArea(context, _outerLayout); _bottomView = PlatformInterop.CreateNavigationBar(context, Resource.Attribute.bottomNavigationViewStyle, _outerLayout, this); if (ShellItem == null) { throw new InvalidOperationException("Active Shell Item not set. Have you added any Shell Items to your Shell?"); } if (ShellItem.CurrentItem == null) { throw new InvalidOperationException($"Content not found for active {ShellItem}. Title: {ShellItem.Title}. Route: {ShellItem.Route}."); } HookEvents(ShellItem); SetupMenu(); _appearanceTracker = ShellContext.CreateBottomNavViewAppearanceTracker(ShellItem); _bottomNavigationTracker = new BottomNavigationViewTracker(); ((IShellController)ShellContext.Shell).AddAppearanceObserver(this, ShellItem); return(_outerLayout); }
public override Task <IImageSourceServiceResult?> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var fileImageSource = (IFileImageSource)imageSource; if (!fileImageSource.IsEmpty) { var callback = new ImageLoaderCallback(); try { var id = imageView.Context?.GetDrawableId(fileImageSource.File) ?? -1; if (id > 0) { imageView.SetImageResource(id); return(Task.FromResult <IImageSourceServiceResult?>(new ImageSourceServiceLoadResult())); } else { PlatformInterop.LoadImageFromFile(imageView, fileImageSource.File, callback); } return(callback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image file '{File}'.", fileImageSource.File); throw; } } return(Task.FromResult <IImageSourceServiceResult?>(null)); }
public static void UpdateTextColor(this EditText editText, Graphics.Color textColor) { if (textColor != null) { if (PlatformInterop.CreateEditTextColorStateList(editText.TextColors, textColor.ToPlatform()) is ColorStateList c) { editText.SetTextColor(c); } } }
public static void UpdatePlaceholderColor(this EditText editText, Graphics.Color placeholderTextColor) { if (placeholderTextColor != null) { if (PlatformInterop.CreateEditTextColorStateList(editText.HintTextColors, placeholderTextColor.ToPlatform()) is ColorStateList c) { editText.SetHintTextColor(c); } } }
public static void UpdateAnchorY(this AView platformView, IView view) { if (platformView.Context == null) { return; } var pivotY = (float)(view.AnchorY * platformView.Context.ToPixels(view.Frame.Height)); PlatformInterop.SetPivotYIfNeeded(platformView, pivotY); }
public static void UpdateAnchorX(this AView platformView, IView view) { if (platformView.Context == null) { return; } var pivotX = (float)(view.AnchorX * platformView.Context.ToPixels(view.Frame.Width)); PlatformInterop.SetPivotXIfNeeded(platformView, pivotX); }
public static void UpdateTitleColor(this MauiPicker platformPicker, IPicker picker) { var titleColor = picker.TitleColor; if (titleColor != null) { if (PlatformInterop.CreateEditTextColorStateList(platformPicker.TextColors, titleColor.ToPlatform()) is ColorStateList c) { platformPicker.SetHintTextColor(c); } } }
public static void UpdateTextColor(this MauiDatePicker platformDatePicker, IDatePicker datePicker) { var textColor = datePicker.TextColor; if (textColor != null) { if (PlatformInterop.CreateEditTextColorStateList(platformDatePicker.TextColors, textColor.ToPlatform()) is ColorStateList c) { platformDatePicker.SetTextColor(c); } } }
public static void UpdateTextColor(this MauiPicker platformPicker, IPicker picker, ColorStateList?defaultColor) { var textColor = picker.TextColor; if (textColor == null) { platformPicker.SetTextColor(defaultColor); } else { if (PlatformInterop.CreateEditTextColorStateList(platformPicker.TextColors, textColor.ToPlatform()) is ColorStateList c) { platformPicker.SetTextColor(c); } } }
internal static Size GetDesiredSizeFromHandler(this IViewHandler viewHandler, double widthConstraint, double heightConstraint) { var Context = viewHandler.MauiContext?.Context; var platformView = viewHandler.ToPlatform(); var virtualView = viewHandler.VirtualView; if (platformView == null || virtualView == null || Context == null) { return(Size.Zero); } // Create a spec to handle the native measure var widthSpec = Context.CreateMeasureSpec(widthConstraint, virtualView.Width, virtualView.MaximumWidth); var heightSpec = Context.CreateMeasureSpec(heightConstraint, virtualView.Height, virtualView.MaximumHeight); var packed = PlatformInterop.MeasureAndGetWidthAndHeight(platformView, widthSpec, heightSpec); var measuredWidth = (int)(packed >> 32); var measuredHeight = (int)(packed & 0xffffffffL); // Convert back to xplat sizes for the return value return(Context.FromPixels(measuredWidth, measuredHeight)); }
public override async Task <IImageSourceServiceResult <Drawable>?> GetDrawableAsync(IImageSource imageSource, Context context, CancellationToken cancellationToken = default) { var streamImageSource = (IStreamImageSource)imageSource; if (!streamImageSource.IsEmpty) { Stream?stream = null; try { stream = await streamImageSource.GetStreamAsync(cancellationToken).ConfigureAwait(false); var drawableCallback = new ImageLoaderResultCallback(); PlatformInterop.LoadImageFromStream(context, stream, drawableCallback); var result = await drawableCallback.Result.ConfigureAwait(false); stream?.Dispose(); return(result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image stream."); throw; } finally { if (stream != null) { GC.KeepAlive(stream); } } } return(null); }
public override Task <IImageSourceServiceResult <Drawable>?> GetDrawableAsync(IImageSource imageSource, Context context, CancellationToken cancellationToken = default) { var uriImageSource = (IUriImageSource)imageSource; if (!uriImageSource.IsEmpty) { try { var drawableCallback = new ImageLoaderResultCallback(); PlatformInterop.LoadImageFromUri(context, uriImageSource.Uri.OriginalString, new Java.Lang.Boolean(uriImageSource.CachingEnabled), drawableCallback); return(drawableCallback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image uri '{Uri}'.", uriImageSource.Uri.OriginalString); throw; } } return(Task.FromResult <IImageSourceServiceResult <Drawable>?>(null)); }
public static void UpdatePlaceholderColor(this SearchView searchView, ISearchBar searchBar, ColorStateList?defaultPlaceholderColor, EditText?editText = null) { editText ??= searchView.GetFirstChildOfType <EditText>(); if (editText == null) { return; } var placeholderTextColor = searchBar.PlaceholderColor; if (placeholderTextColor == null) { editText.SetHintTextColor(defaultPlaceholderColor); } else { if (PlatformInterop.CreateEditTextColorStateList(editText.HintTextColors, placeholderTextColor.ToPlatform()) is ColorStateList c) { editText.SetHintTextColor(c); } } }
public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var shellSection = ShellSection; if (shellSection == null) { return(null); } if (shellSection.CurrentItem == null) { throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}."); } var context = Context; var root = PlatformInterop.CreateShellCoordinatorLayout(context); var appbar = PlatformInterop.CreateShellAppBar(context, Resource.Attribute.appBarLayoutStyle, root); int actionBarHeight = context.GetActionBarHeight(); _toolbar = PlatformInterop.CreateShellToolbar(context, appbar, actionBarHeight, Resource.Style.ThemeOverlay_AppCompat_Light); _tablayout = PlatformInterop.CreateShellTabLayout(context, appbar, actionBarHeight); var pagerContext = MauiContext.MakeScoped(layoutInflater: inflater, fragmentManager: ChildFragmentManager); var adapter = new ShellFragmentStateAdapter(shellSection, ChildFragmentManager, pagerContext); var pageChangedCallback = new ViewPagerPageChanged(this); _viewPager = PlatformInterop.CreateShellViewPager(context, root, _tablayout, this, adapter, pageChangedCallback); Page currentPage = null; int currentIndex = -1; var currentItem = shellSection.CurrentItem; var items = SectionController.GetItems(); while (currentIndex < 0 && items.Count > 0 && shellSection.CurrentItem != null) { currentItem = shellSection.CurrentItem; currentPage = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent(); // current item hasn't changed if (currentItem == shellSection.CurrentItem) { currentIndex = items.IndexOf(currentItem); } } _toolbarTracker = _shellContext.CreateTrackerForToolbar(_toolbar); _toolbarTracker.Page = currentPage; _viewPager.CurrentItem = currentIndex; if (items.Count == 1) { UpdateTablayoutVisibility(); } _tablayout.LayoutChange += OnTabLayoutChange; _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection); _toolbarAppearanceTracker = _shellContext.CreateToolbarAppearanceTracker(); HookEvents(); return(_rootView = root); }
internal static View GetSemanticPlatformElement(this View platformView) { return(PlatformInterop.GetSemanticPlatformElement(platformView) !); }
public static ColorStateList CreateDefault(int color) => PlatformInterop.GetDefaultColorStateList(color);
public static ColorStateList CreateButton(int enabled, int disabled, int off, int pressed) => PlatformInterop.GetButtonColorStateList(enabled, disabled, off, pressed);
public static ColorStateList CreateSwitch(int disabled, int on, int normal) => PlatformInterop.GetSwitchColorStateList(disabled, on, normal);
public static ColorStateList CreateCheckBox(int enabledChecked, int enabledUnchecked, int disabledChecked, int disabledUnchecked) => PlatformInterop.GetCheckBoxColorStateList(enabledChecked, enabledUnchecked, disabledChecked, disabledUnchecked);
public static ColorStateList CreateEditText(int enabled, int disabled) => PlatformInterop.GetEditTextColorStateList(enabled, disabled);