Exemple #1
0
        void OnCreate(
            Bundle savedInstanceState,
            ActivationFlags flags)
        {
            _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");
            }

            base.OnCreate(savedInstanceState);

            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);

            _layout = new ARelativeLayout(BaseContext);
            SetContentView(_layout);

            Xamarin.Forms.Application.ClearCurrent();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnCreate;

            OnStateChanged();

            if (Forms.IsLollipopOrNewer)
            {
                // Allow for the status bar color to be changed
                if ((flags & ActivationFlags.DisableSetStatusBarColor) == 0)
                {
                    Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                }
            }
            if (Forms.IsLollipopOrNewer)
            {
                // Listen for the device going into power save mode so we can handle animations being disabled
                _powerSaveModeBroadcastReceiver = new PowerSaveModeBroadcastReceiver();
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            Window.RequestFeature(WindowFeatures.IndeterminateProgress);

            base.OnCreate(savedInstanceState);

            _layout = new LinearLayout(BaseContext);
            SetContentView(_layout);

            Xamarin.Forms.Application.ClearCurrent();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnCreate;

            if (Forms.IsLollipopOrNewer)
            {
                // Listen for the device going into power save mode so we can handle animations being disabled
                _powerSaveModeBroadcastReceiver = new PowerSaveModeBroadcastReceiver();
            }

            OnStateChanged();
        }
Exemple #3
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 __ANDROID_29__
            if (ToolbarResource == 0)
            {
                ToolbarResource = Resource.Layout.Toolbar;
            }

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

            if (ToolbarResource != 0)
            {
                try
                {
                    bar = LayoutInflater.Inflate(ToolbarResource, null).JavaCast <AToolbar>();
                }
#if __ANDROID_29__
                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") &&
                        this.TargetSdkVersion() >= 29)
                    {
                        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;
                    }
#else
                catch
                {
                    throw;
#endif
                }

                if (bar == null)
#if __ANDROID_29__
                { throw new InvalidOperationException("ToolbarResource must be set to a Android.Support.V7.Widget.Toolbar"); }
#else
                { throw new InvalidOperationException("ToolbarResource must be set to a androidx.appcompat.widget.Toolbar"); }
#endif
            }
            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();
        }
        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)
                {
                    throw new InvalidOperationException("ToolbarResource must be set to a androidx.appcompat.widget.Toolbar", ie);
                }

                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();
        }