Exemple #1
0
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            if (_backgroundPath != null && _backgroundImage == null)
            {
                SetBackground(ImageGetter.LoadFromStorage(_backgroundPath, canvas.Width, canvas.Height));
            }

            if (_foregroundPath != null)
            {
                SetForeground(ImageGetter.LoadFromStorage(_foregroundPath, canvas.Width, canvas.Height));
                _foregroundPath = null;
            }
            else if (_mutableForeground == null)
            {
                SetForeground(null);
            }

            DrawBackground(canvas);

            if (_mutableForeground == null || _mutableForeground.IsRecycled)
            {
                return;
            }
            var left = (_canvasSize.Width - _mutableForeground.Width) / 2;
            var top  = (_canvasSize.Height - _mutableForeground.Height) / 2;

            canvas.DrawBitmap(_mutableForeground, (float)left, (float)top, _bitmapPaint);
            canvas.DrawPath(_currentStroke, _strokeBrush);
        }
Exemple #2
0
 protected virtual void LoadImage()
 {
     if (Item != null && _imagePath != null)
     {
         ImageGetter.SetDrawable(_imagePath, (bitmap, url) =>
         {
             if (url == _imagePath)
             {
                 Item.SetIcon(bitmap);
             }
         });
     }
 }
Exemple #3
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);
        }
Exemple #4
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);
         }
     });
 }
Exemple #5
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();
         }
     });
 }
Exemple #6
0
        public void Render()
        {
            this.RaiseEvent(nameof(Rendering), EventArgs.Empty);
            if (!TabItems.Any())
            {
                return;
            }
            DroidFactory.Tabs = this;
            _inFlight         = true;
            var actionBar = DroidFactory.MainActivity.ActionBar;

            actionBar.RemoveAllTabs();

            var ig = new ImageGetter();

            foreach (var tab in TabItems)
            {
                var abTab = actionBar.NewTab();
                abTab.SetTabListener(this);
                abTab.SetText(tab.Title);
                abTab.SetIcon(ig.GetDrawable(tab.ImagePath));
                actionBar.AddTab(abTab);
            }
            _inFlight = false;

            HeaderColor = iApp.Instance.Style.HeaderColor;

            actionBar.Title    = null;
            actionBar.Subtitle = null;
            if (SelectedIndex > -1)
            {
                iApp.SetNavigationContext(new iLayer.NavigationContext
                {
                    OutputOnPane       = iApp.CurrentNavContext.ActivePane,
                    NavigatedActiveTab = SelectedIndex,
                });
                actionBar.SelectTab(actionBar.GetTabAt(SelectedIndex));
            }
            actionBar.NavigationMode = ActionBarNavigationMode.Tabs;
        }
Exemple #7
0
        protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
        {
            base.OnSizeChanged(w, h, oldw, oldh);
            _canvasSize = new Size(w, h);

            Bitmap foreground = null;

            try
            {
                var view = DroidFactory.MainActivity.FindViewById <ImageView>(((FragmentHistoryStack)((BaseFragment)Parent).Stack).BackgroundId);
                if (view == null)
                {
                    return;
                }
                if (_backgroundPath != null && _backgroundImage == null)
                {
                    SetBackground(ImageGetter.LoadFromStorage(_backgroundPath, view.MeasuredWidth, view.MeasuredHeight));
                }

                if (_foregroundPath != null)
                {
                    foreground = ImageGetter.LoadFromStorage(_foregroundPath, view.MeasuredWidth, view.MeasuredHeight);
                    SetForeground(null);
                    _foregroundPath = null;
                }
                else
                {
                    foreground = _mutableForeground;
                    SetForeground(Bitmap.CreateBitmap((int)_canvasSize.Width, (int)_canvasSize.Height, Bitmap.Config.Argb8888));
                    this.OnPropertyChanged("MutableForeground");
                }
            }
            catch (Exception ex)
            {
                iApp.Log.Error(ex);
            }

            if (foreground == null)
            {
                return;
            }

            var foregroundWidth  = foreground.Width;
            var foregroundHeight = foreground.Height;

            var scaled = false;

            if (foregroundWidth > _canvasSize.Width)
            {
                foregroundHeight = (int)(foregroundHeight * (_canvasSize.Width / foregroundWidth));
                foregroundWidth  = (int)_canvasSize.Width;
                scaled           = true;
            }

            if (foregroundHeight > _canvasSize.Height)
            {
                foregroundWidth  = (int)(foregroundWidth * (_canvasSize.Height / foregroundHeight));
                foregroundHeight = (int)_canvasSize.Height;
                scaled           = true;
            }

            if (scaled)
            {
                var fore = foreground;
                foreground = Bitmap.CreateScaledBitmap(foreground, foregroundWidth, foregroundHeight, false);
                fore.Recycle();
            }

            var left = foregroundWidth > _canvasSize.Width ? 0 : ((float)_canvasSize.Width - foregroundWidth) / 2;
            var top  = foregroundHeight > _canvasSize.Height ? 0 : ((float)_canvasSize.Height - foregroundHeight) / 2;

            ForegroundMutator.DrawBitmap(foreground, left, top, _bitmapPaint);
            Recycle(foreground);
        }