Ejemplo n.º 1
0
        void OnCreate(
            Bundle savedInstanceState,
            ActivationFlags flags)
        {
            Profile.FrameBegin();
            _activityCreated = true;
            if (!AllowFragmentRestore)
            {
                // Remove the automatically persisted fragment structure; we don't need them
                // because we're rebuilding everything from scratch. This saves a bit of memory
                // and prevents loading errors from child fragment managers
                savedInstanceState?.Remove("android:support:fragments");
            }

            Profile.FramePartition("Xamarin.Android.OnCreate");
            base.OnCreate(savedInstanceState);

            Profile.FramePartition("SetSupportActionBar");
            AToolbar bar = null;

            if (ToolbarResource == 0)
            {
                ToolbarResource = Resource.Layout.Toolbar;
            }

            if (TabLayoutResource == 0)
            {
                TabLayoutResource = Resource.Layout.Tabbar;
            }

            if (ToolbarResource != 0)
            {
                try
                {
                    bar = LayoutInflater.Inflate(ToolbarResource, null).JavaCast <AToolbar>();
                }
                catch (global::Android.Views.InflateException ie)
                {
                    if ((ie.Cause is Java.Lang.ClassNotFoundException || ie.Cause.Cause is Java.Lang.ClassNotFoundException) &&
                        ie.Message.Contains("Error inflating class android.support.v7.widget.Toolbar"))
                    {
                        Internals.Log.Warning(nameof(FormsAppCompatActivity),
                                              "Toolbar layout needs to be updated from android.support.v7.widget.Toolbar to androidx.appcompat.widget.Toolbar. " +
                                              "Tabbar layout need to be updated from android.support.design.widget.TabLayout to com.google.android.material.tabs.TabLayout. " +
                                              "Or if you haven't made any changes to the default Toolbar and Tabbar layouts they can just be deleted.");

                        ToolbarResource   = Resource.Layout.FallbackToolbarDoNotUse;
                        TabLayoutResource = Resource.Layout.FallbackTabbarDoNotUse;

                        bar = LayoutInflater.Inflate(ToolbarResource, null).JavaCast <AToolbar>();
                    }
                    else
                    {
                        throw;
                    }
                }

                if (bar == null)
                {
                    throw new InvalidOperationException("ToolbarResource must be set to a androidx.appcompat.widget.Toolbar");
                }
            }
            else
            {
                bar = new AToolbar(this);
            }

            SetSupportActionBar(bar);

            Profile.FramePartition("SetContentView");
            _layout = new ARelativeLayout(BaseContext);
            SetContentView(_layout);

            Profile.FramePartition("OnStateChanged");
            Xamarin.Forms.Application.ClearCurrent();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnCreate;

            OnStateChanged();

            Profile.FramePartition("Forms.IsLollipopOrNewer");
            if (Forms.IsLollipopOrNewer)
            {
                // Allow for the status bar color to be changed
                if ((flags & ActivationFlags.DisableSetStatusBarColor) == 0)
                {
                    Profile.FramePartition("Set DrawsSysBarBkgrnds");
                    Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                }
            }
            if (Forms.IsLollipopOrNewer)
            {
                // Listen for the device going into power save mode so we can handle animations being disabled
                Profile.FramePartition("Allocate PowerSaveModeReceiver");
                _powerSaveModeBroadcastReceiver = new PowerSaveModeBroadcastReceiver();
            }

            ContextExtensions.SetDesignerContext(_layout);
            Profile.FrameEnd();
        }
Ejemplo n.º 2
0
        void OnCreate(
            Bundle savedInstanceState,
            ActivationFlags flags)
        {
            Profile.FrameBegin();
            _activityCreated = true;
            if (!AllowFragmentRestore)
            {
                // Remove the automatically persisted fragment structure; we don't need them
                // because we're rebuilding everything from scratch. This saves a bit of memory
                // and prevents loading errors from child fragment managers
                savedInstanceState?.Remove("android:support:fragments");
            }

            Profile.FramePartition("Xamarin.Android.OnCreate");
            base.OnCreate(savedInstanceState);

            Profile.FramePartition("SetSupportActionBar");
            AToolbar bar;

            if (ToolbarResource != 0)
            {
                bar = LayoutInflater.Inflate(ToolbarResource, null).JavaCast <AToolbar>();
                if (bar == null)
                {
                    throw new InvalidOperationException("ToolbarResource must be set to a Android.Support.V7.Widget.Toolbar");
                }
            }
            else
            {
                bar = new AToolbar(this);
            }

            SetSupportActionBar(bar);

            Profile.FramePartition("SetContentView");
            _layout = new ARelativeLayout(BaseContext);
            SetContentView(_layout);

            Profile.FramePartition("OnStateChanged");
            Xamarin.Forms.Application.ClearCurrent();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnCreate;

            OnStateChanged();

            Profile.FramePartition("Forms.IsLollipopOrNewer");
            if (Forms.IsLollipopOrNewer)
            {
                // Allow for the status bar color to be changed
                if ((flags & ActivationFlags.DisableSetStatusBarColor) == 0)
                {
                    Profile.FramePartition("Set DrawsSysBarBkgrnds");
                    Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                }
            }
            if (Forms.IsLollipopOrNewer)
            {
                // Listen for the device going into power save mode so we can handle animations being disabled
                Profile.FramePartition("Allocate PowerSaveModeReceiver");
                _powerSaveModeBroadcastReceiver = new PowerSaveModeBroadcastReceiver();
            }

            ContextExtensions.SetDesignerContext(_layout);
            Profile.FrameEnd();
        }