예제 #1
0
        void UpdateStatusBarColor(ShellAppearance appearance)
        {
            Profile.FrameBegin("UpdtStatBarClr");

            var activity  = AndroidContext.GetActivity();
            var window    = activity?.Window;
            var decorView = window?.DecorView;
            var resources = AndroidContext.Resources;

            int statusBarHeight = 0;
            int resourceId      = resources.GetIdentifier("status_bar_height", "dimen", "android");

            if (resourceId > 0)
            {
                statusBarHeight = resources.GetDimensionPixelSize(resourceId);
            }

            int navigationBarHeight = 0;

            resourceId = resources.GetIdentifier("navigation_bar_height", "dimen", "android");
            if (resourceId > 0)
            {
                navigationBarHeight = resources.GetDimensionPixelSize(resourceId);
            }

            // TODO Previewer Hack
            if (decorView != null)
            {
                // we are using the split drawable here to avoid GPU overdraw.
                // All it really is is a drawable that only draws under the statusbar/bottom bar to make sure
                // we dont draw over areas we dont need to. This has very limited benefits considering its
                // only saving us a flat color fill BUT it helps people not freak out about overdraw.
                AColor color;
                if (appearance != null)
                {
                    color = appearance.BackgroundColor.ToAndroid(Color.FromHex("#03A9F4"));
                }
                else
                {
                    color = Color.FromHex("#03A9F4").ToAndroid();
                }

                if (!(decorView.Background is SplitDrawable splitDrawable) ||
                    splitDrawable.Color != color || splitDrawable.TopSize != statusBarHeight || splitDrawable.BottomSize != navigationBarHeight)
                {
                    Profile.FramePartition("Create SplitDrawable");
                    var split = new SplitDrawable(color, statusBarHeight, navigationBarHeight);
                    Profile.FramePartition("SetBackground");
                    decorView.SetBackground(split);
                }
            }

            Profile.FrameEnd("UpdtStatBarClr");
        }