Example #1
0
 protected virtual void LoadImage()
 {
     if (Item != null && _imagePath != null)
     {
         ImageGetter.SetDrawable(_imagePath, (bitmap, url) =>
         {
             if (url == _imagePath)
             {
                 Item.SetIcon(bitmap);
             }
         });
     }
 }
Example #2
0
        public override void OnCreateOptionsMenu(IMenu menu, MenuInflater inflater)
        {
            if (menu == null)
            {
                return;
            }
            menu.Clear();

            if (Menu.ButtonCount > 1 && Build.VERSION.SdkInt <= BuildVersionCodes.JellyBean)
            {
                var itemId = (int)OutputPane * byte.MaxValue;
                var item   = menu.Add((int)OutputPane, itemId, (int)OutputPane, Device.Resources.GetString("Menu"));
                item.SetShowAsAction(ShowAsAction.Always);
                const string source = "ic_menu_dark.png";
                ImageGetter.SetDrawable(source, (bitmap, url) =>
                {
                    if (url == source)
                    {
                        item.SetIcon(bitmap);
                    }
                });
            }
            else if (_buttons != null && _buttons.Length > 0 && _buttons[0]?.Item != null)
            {
                foreach (var button in _buttons)
                {
                    button.Item = menu.Add((int)OutputPane, button.Item.ItemId, (int)OutputPane, button.Title);
                }
            }
            else
            {
                var showIfRoom = true;
                _buttons = Enumerable.Range(0, Menu.ButtonCount).Select(i =>
                {
                    var menuItem = Menu.GetButton(i);
                    if (menuItem is UI.IMenu)
                    {
                        showIfRoom = false;
                    }
                    return(menuItem as MenuButton ?? menuItem?.Pair as MenuButton);
                }).ToArray();
                var subCount = 0;
                for (int i = 0; i < _buttons.Length; i++)
                {
                    var button = _buttons[i];
                    var menuId = button is IMenu ? subCount++ : (int)OutputPane;
                    button.AddToParent(menu, menuId, i, showIfRoom);
                }
            }
            base.OnCreateOptionsMenu(menu, inflater);
        }
Example #3
0
 public void SetBackground(string imagePath, ContentStretch stretch)
 {
     if (DroidFactory.MainActivity.ActionBar == null)
     {
         return;
     }
     ImageGetter.SetDrawable(imagePath, (bitmap, url) =>
     {
         if (url == imagePath)
         {
             DroidFactory.MainActivity.ActionBar.SetBackgroundDrawable(bitmap);
         }
     });
 }
Example #4
0
 public void SetBackground(string imagePath, ContentStretch stretch)
 {
     ImageGetter.SetDrawable(imagePath, (drawable, url) =>
     {
         if (url != imagePath)
         {
             return;
         }
         if (drawable is BitmapDrawable bit)
         {
             SetBackground(bit.Bitmap);
         }
         else
         {
             SetBackground(null);
             _backgroundPath = imagePath;
             Invalidate();
         }
     });
 }