private Drawable GetImage(string vehicleTypeLogoName, bool etaBadge = false) { return(DrawableHelper.GetDrawableFromString(Resources, string.Format(Selected ? "{0}_" + (etaBadge ? "no_" : "") + "badge_selected" : "{0}_" + (etaBadge ? "no_" : "") + "badge", vehicleTypeLogoName.ToLower()))); }
public Noun(int id, string lemma, string dependency, IEdgeFactory factory, ElementFactory elementFactory, IImageManager manager, int width, int height) : base(id, lemma, dependency) { this.Extensions = new List <IProcessable>(); this.Suffixes = new List <Element>(); this.Actions = new List <Verb>(); this.Adpositions = new List <Adposition>(); this.EdgeFactory = factory; this.ElementFactory = elementFactory; this.Manager = manager; this.Width = width; this.Height = height; this.DrawableHelper = new DrawableHelper(); }
protected override void Render() { var native = Native; var element = Element; // Visibility if (element.Visibility == Visibility.Visible) { // Icon var iconUri = (element.Icon as BitmapIcon)?.UriSource; if (iconUri != null) { native.NavigationIcon = DrawableHelper.FromUri(iconUri); } // Foreground var foreground = (element.Foreground as SolidColorBrush); var foregroundOpacity = foreground?.Opacity ?? 0; if (FeatureConfiguration.AppBarButton.EnableBitmapIconTint) { var foregroundColor = foreground?.Color; if (native.NavigationIcon != null) { if (foreground != null) { DrawableCompat.SetTint(native.NavigationIcon, (Android.Graphics.Color)foregroundColor); } else { DrawableCompat.SetTintList(native.NavigationIcon, null); } } } // Label native.NavigationContentDescription = element.Label; // Opacity var opacity = element.Opacity; var finalOpacity = foregroundOpacity * opacity; var alpha = (int)(finalOpacity * 255); native.NavigationIcon?.SetAlpha(alpha); } else { native.NavigationIcon = null; native.NavigationContentDescription = null; } }
private void ShowAvailableVehicles(AvailableVehicle[] vehicles) { // remove currently displayed pushpins foreach (var marker in _availableVehiclePushPins) { marker.Remove(); marker.Dispose(); } _availableVehiclePushPins.Clear(); if (vehicles == null) { return; } const string defaultLogoName = "taxi"; foreach (var v in vehicles) { var isCluster = v is AvailableVehicleCluster; var logoKey = isCluster ? string.Format("cluster_{0}", v.LogoName ?? defaultLogoName) : string.Format("nearby_{0}", v.LogoName ?? defaultLogoName); var resId = DrawableHelper.GetIdFromString(Resources, logoKey); if (!resId.HasValue) { // Resource not found, skip to next continue; } var pushPin = Map.AddMarker(new MarkerOptions() .Anchor(.5f, 1f) .SetPosition(new LatLng(v.Latitude, v.Longitude)) .InvokeIcon(BitmapDescriptorFactory.FromResource(resId.Value)) .Visible(true)); _availableVehiclePushPins.Add(pushPin); } PostInvalidate(); }
protected override void Render() { // Visibility if (Element.Visibility == Visibility.Visible) { // Icon var iconUri = (Element.Icon as BitmapIcon)?.UriSource; Native.NavigationIcon = DrawableHelper.FromUri(iconUri); // Foreground var foreground = (Element.Foreground as SolidColorBrush); var foregroundColor = foreground?.Color; var foregroundOpacity = foreground?.Opacity ?? 0; if (Native.NavigationIcon != null) { if (foreground != null) { DrawableCompat.SetTint(Native.NavigationIcon, (Android.Graphics.Color)foregroundColor); } else { DrawableCompat.SetTintList(Native.NavigationIcon, null); } } // Label Native.NavigationContentDescription = Element.Label; // Opacity var opacity = Element.Opacity; var finalOpacity = foregroundOpacity * opacity; var alpha = (int)(finalOpacity * 255); Native.NavigationIcon?.SetAlpha(alpha); } else { Native.NavigationIcon = null; Native.NavigationContentDescription = null; } }
private static async Task <StorageFile> GetFileFromApplicationUri(CancellationToken ct, Uri uri) { if (uri.Scheme != "ms-appx") { throw new InvalidOperationException("Uri is not using the ms-appx scheme"); } var path = AndroidResourceNameEncoder.EncodeResourcePath(Uri.UnescapeDataString(uri.PathAndQuery).TrimStart(new char[] { '/' })); // Read the contents of our asset var outputCachePath = global::System.IO.Path.Combine(Android.App.Application.Context.CacheDir.AbsolutePath, path); if (typeof(StorageFile).Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug)) { typeof(StorageFile).Log().Debug($"GetFileFromApplicationUriAsyncTask path:{path} outputCachePath:{outputCachePath}"); } // Ensure only one generation of the cached file can occur at a time. // The copy of tha android asset should not be necessary, but requires a significant // refactoring of the StorageFile class to make non-local provides opaque. // This will need to be revisited once we add support for other providers. using var gate = await _assetGate.LockForAsset(ct, path); if (!File.Exists(outputCachePath)) { Directory.CreateDirectory(global::System.IO.Path.GetDirectoryName(outputCachePath)); Stream GetAsset() { if (DrawableHelper.FindResourceIdFromPath(path) is { } resourceId) { return(ContextHelper.Current.Resources.OpenRawResource(resourceId)); } else { var assets = global::Android.App.Application.Context.Assets; return(assets.Open(path)); } }
internal static async Task <ShortcutInfo> ToShortcutInfoAsync(this JumpListItem jumpListItem) { var builder = new ShortcutInfo.Builder(Application.Context, jumpListItem.Arguments); var pm = Application.Context.PackageManager; var intent = pm.GetLaunchIntentForPackage(Application.Context.PackageName); intent.PutExtra(JumpListItem.ArgumentsExtraKey, jumpListItem.Arguments); builder.SetIntent(intent); builder.SetShortLabel( !string.IsNullOrEmpty(jumpListItem.DisplayName) ? jumpListItem.DisplayName : " "); //Android requires non-empty DisplayName if (!string.IsNullOrEmpty(jumpListItem.Description)) { builder.SetLongLabel(jumpListItem.Description); } var persistableBundle = new PersistableBundle(); persistableBundle.PutString(JumpListItem.UnoShortcutKey, "true"); if (jumpListItem.Logo != null) { persistableBundle.PutString(JumpListItem.ImagePathKey, jumpListItem.Logo.ToString()); var imageResourceId = DrawableHelper.FindResourceId(jumpListItem.Logo.LocalPath); if (imageResourceId != null) { var bitmap = await BitmapFactory.DecodeResourceAsync( ContextHelper.Current.Resources, imageResourceId.Value, new BitmapFactory.Options()); builder.SetIcon(Icon.CreateWithBitmap(bitmap)); } } builder.SetExtras(persistableBundle); return(builder.Build()); }
public Root(string text, IImageManager manager) : base(0, text, "root") { this.Position = new Vector2(0, 0); this.Manager = manager; this.DrawableHelper = new DrawableHelper(); }
protected override void Render() { // Content Native.Title = Element.Content as string; _contentContainer.Child = Element.Content as View; _contentContainer.Visibility = Element.Content is View ? Visibility.Visible : Visibility.Collapsed; // CommandBarExtensions.Subtitle Native.Subtitle = Element.GetValue(SubtitleProperty) as string; // Background var backgroundColor = (Element.Background as SolidColorBrush)?.ColorWithOpacity; if (backgroundColor != null) { Native.SetBackgroundColor((Android.Graphics.Color)backgroundColor); } else { Native.Background = _originalBackground ?? new ColorDrawable(Color.FromArgb(255, 250, 250, 250)); } // Foreground var foregroundColor = (Element.Foreground as SolidColorBrush)?.ColorWithOpacity; if (foregroundColor != null) { Native.SetTitleTextColor((Android.Graphics.Color)foregroundColor); } else { Native.SetTitleTextColor(_originalTitleTextColor.Value); } // PrimaryCommands & SecondaryCommands var currentMenuItemIds = GetMenuItems(Native.Menu).Select(i => i.ItemId); var intendedMenuItemIds = Element.PrimaryCommands .Concat(Element.SecondaryCommands) .OfType <AppBarButton>() .Select(i => i.GetHashCode()); if (!currentMenuItemIds.SequenceEqual(intendedMenuItemIds)) { Native.Menu.Clear(); foreach (var command in Element.PrimaryCommands.Concat(Element.SecondaryCommands).OfType <AppBarButton>()) { var menuItem = Native.Menu.Add(0, command.GetHashCode(), Menu.None, null); var renderer = command.GetRenderer(() => new AppBarButtonRenderer(command)); renderer.Native = menuItem; // This ensures that Behaviors expecting this button to be in the logical tree work. command.SetParent(Element); } } // CommandBarExtensions.NavigationCommand var navigationCommand = Element.GetValue(NavigationCommandProperty) as AppBarButton; if (navigationCommand != null) { var renderer = navigationCommand.GetRenderer(() => new NavigationAppBarButtonRenderer(navigationCommand)); renderer.Native = Native; // This ensures that Behaviors expecting this button to be in the logical tree work. navigationCommand.SetParent(Element); } // CommandBarExtensions.BackButtonVisibility else if ((Visibility)Element.GetValue(BackButtonVisibilityProperty) == Visibility.Visible) { // CommandBarExtensions.BackButtonIcon if (Element.GetValue(BackButtonIconProperty) is BitmapIcon bitmapIcon) { Native.NavigationIcon = DrawableHelper.FromUri(bitmapIcon.UriSource); } else { Native.NavigationIcon = new Android.Support.V7.Graphics.Drawable.DrawerArrowDrawable(ContextHelper.Current) { // 0 = menu icon // 1 = back icon Progress = 1, }; } // CommandBarExtensions.BackButtonForeground var backButtonForeground = (Element.GetValue(BackButtonForegroundProperty) as SolidColorBrush)?.ColorWithOpacity; if (backButtonForeground != null) { switch (Native.NavigationIcon) { case Android.Support.V7.Graphics.Drawable.DrawerArrowDrawable drawerArrowDrawable: drawerArrowDrawable.Color = (Android.Graphics.Color)backButtonForeground; break; case Drawable drawable: DrawableCompat.SetTint(drawable, (Android.Graphics.Color)backButtonForeground); break; } } } else { Native.NavigationIcon = null; Native.NavigationContentDescription = null; } // Padding var physicalPadding = Element.Padding.LogicalToPhysicalPixels(); Native.SetPadding( (int)physicalPadding.Left, (int)physicalPadding.Top, (int)physicalPadding.Right, (int)physicalPadding.Bottom ); // Opacity Native.Alpha = (float)Element.Opacity; }
protected override void Render() { // CommandBar::PrimaryCommands -> !IsInOverflow -> AsAction.Never -> displayed directly on command bar // CommandBar::SecondaryCommands -> IsInOverflow -> AsAction.Awalys -> (displayed as flyout menu items under [...]) var native = Native; var element = Element; // IsInOverflow var showAsAction = element.IsInOverflow ? ShowAsAction.Never : ShowAsAction.Always; native.SetShowAsAction(showAsAction); // (Icon ?? Content) and Label if (element.IsInOverflow) { native.SetActionView(null); native.SetIcon(null); native.SetTitle(element.Label); } else if (element.Icon != null) { switch (element.Icon) { case BitmapIcon bitmap: var drawable = DrawableHelper.FromUri(bitmap.UriSource); native.SetIcon(drawable); break; case FontIcon font: // not supported case PathIcon path: // not supported case SymbolIcon symbol: // not supported default: this.Log().WarnIfEnabled(() => $"{GetType().Name ?? "FontIcon, PathIcon and SymbolIcon"} are not supported. Use BitmapIcon instead with UriSource."); native.SetIcon(null); break; } native.SetActionView(null); native.SetTitle(null); } else { switch (element.Content) { case string text: native.SetIcon(null); native.SetActionView(null); native.SetTitle(text); break; case FrameworkElement fe: var currentParent = element.GetParent(); _appBarButtonWrapper.Child = element; //Restore the original parent if any, as we // want the DataContext to flow properly from the // CommandBar. element.SetParent(currentParent); native.SetIcon(null); native.SetActionView(fe.Visibility == Visibility.Visible ? _appBarButtonWrapper : null); native.SetTitle(null); break; default: native.SetIcon(null); native.SetActionView(null); native.SetTitle(null); break; } } // IsEnabled native.SetEnabled(element.IsEnabled); // According to the Material Design guidelines, the opacity inactive icons should be: // - Light background: 38% // - Dark background: 50% // Source: https://material.io/guidelines/style/icons.html // For lack of a reliable way to identify whether the background is light or dark, // we'll go with 50% opacity until this no longer satisfies projects requirements. var isEnabledOpacity = (element.IsEnabled ? 1.0 : 0.5); // Visibility native.SetVisible(element.Visibility == Visibility.Visible); // Foreground var foreground = element.Foreground as SolidColorBrush; var foregroundColor = foreground?.Color; var foregroundOpacity = foreground?.Opacity ?? 0; if (native.Icon != null) { if (foreground != null) { DrawableCompat.SetTint(native.Icon, (Android.Graphics.Color)foregroundColor); } else { DrawableCompat.SetTintList(native.Icon, null); } } // Background var backgroundColor = (element.Background as SolidColorBrush)?.ColorWithOpacity; if (backgroundColor != null) { _appBarButtonWrapper.SetBackgroundColor((Android.Graphics.Color)backgroundColor); } // Opacity var opacity = element.Opacity; var finalOpacity = isEnabledOpacity * foregroundOpacity * opacity; var alpha = (int)(finalOpacity * 255); native.Icon?.SetAlpha(alpha); }
protected override void Render() { // IsInOverflow var showAsAction = Element.IsInOverflow ? ShowAsAction.Never : ShowAsAction.Always; Native.SetShowAsAction(showAsAction); // Label / String Content Native.SetTitle(Element.Label ?? (Element.Content is string contentLabel ? contentLabel : string.Empty)); // Content & Icon if (!Element.IsInOverflow) // We don't want to consider Icon or Content in overflow { // Icon switch (Element.Icon) { case BitmapIcon bitmap: var drawable = DrawableHelper.FromUri(bitmap.UriSource); Native.SetIcon(drawable); break; default: // Custom Content switch (Element.Content) { case FrameworkElement content: var currentParent = Element.GetParent(); _appBarButtonWrapper.Child = Element; // Restore the original parent if any, as we // want the DataContext to flow properly from the // CommandBar. Element.SetParent(currentParent); if (content.Visibility == Visibility.Visible) { Native.SetActionView(_appBarButtonWrapper); } break; } break; } } // IsEnabled Native.SetEnabled(Element.IsEnabled); // According to the Material Design guidelines, the opacity inactive icons should be: // - Light background: 38% // - Dark background: 50% // Source: https://material.io/guidelines/style/icons.html // For lack of a reliable way to identify whether the background is light or dark, // we'll go with 50% opacity until this no longer satisfies projects requirements. var isEnabledOpacity = (Element.IsEnabled ? 1.0 : 0.5); // Visibility Native.SetVisible(Element.Visibility == Visibility.Visible); // Foreground var foreground = Element.Foreground as SolidColorBrush; var foregroundColor = foreground?.Color; var foregroundOpacity = foreground?.Opacity ?? 0; if (Native.Icon != null) { if (foreground != null) { DrawableCompat.SetTint(Native.Icon, (Android.Graphics.Color)foregroundColor); } else { DrawableCompat.SetTintList(Native.Icon, null); } } // Background var backgroundColor = (Element.Background as SolidColorBrush)?.ColorWithOpacity; if (backgroundColor != null) { _appBarButtonWrapper.SetBackgroundColor((Android.Graphics.Color)backgroundColor); } // Opacity var opacity = Element.Opacity; var finalOpacity = isEnabledOpacity * foregroundOpacity * opacity; var alpha = (int)(finalOpacity * 255); Native.Icon?.SetAlpha(alpha); }