Exemple #1
0
        protected override void OnPause()
        {
            _layout.HideKeyboard(true);

            // Stop animations or other ongoing actions that could consume CPU
            // Commit unsaved changes, build only if users expect such changes to be permanently saved when thy leave such as a draft email
            // Release system resources, such as broadcast receivers, handles to sensors (like GPS), or any resources that may affect battery life when your activity is paused.
            // Avoid writing to permanent storage and CPU intensive tasks
            base.OnPause();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnPause;

            OnStateChanged();
        }
        // Scenarios that stop and restart your app
        // -- Switches from your app to another app, activity restarts when clicking on the app again.
        // -- Action in your app that starts a new Activity, the current activity is stopped and the second is created, pressing back restarts the activity
        // -- The user receives a phone call while using your app on his or her phone
        protected override void OnStop()
        {
            // writing to storage happens here!
            // full UI obstruction
            // users focus in another activity
            // perform heavy load shutdown operations
            // clean up resources
            // clean up everything that may leak memory
            base.OnStop();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnStop;

            OnStateChanged();
        }
Exemple #3
0
        protected override void OnStart()
        {
            Profile.FrameBegin();

            Profile.FramePartition("Android OnStart");
            base.OnStart();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnStart;

            Profile.FramePartition("OnStateChanged");
            OnStateChanged();

            Profile.FrameEnd();
        }
Exemple #4
0
        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;

            OnStateChanged();
        }
Exemple #5
0
		protected override void OnCreate(Bundle savedInstanceState)
		{
			_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
				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();
			}
		}
Exemple #6
0
        protected override void OnResume()
        {
            // counterpart to OnPause
            base.OnResume();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnResume;

            if (Forms.IsLollipopOrNewer)
            {
                // Start listening for power save mode changes
                RegisterReceiver(_powerSaveModeBroadcastReceiver, new IntentFilter(
                                     PowerManager.ActionPowerSaveModeChanged));
            }

            OnStateChanged();
        }
        protected override void OnResume()
        {
            // counterpart to OnPause
            base.OnResume();

            if (_application != null && _application.OnThisPlatform().GetShouldPreserveKeyboardOnResume())
            {
                if (CurrentFocus != null && (CurrentFocus is EditText || CurrentFocus is TextView || CurrentFocus is SearchView))
                {
                    CurrentFocus.ShowKeyboard();
                }
            }

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnResume;

            OnStateChanged();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            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);

            SetSoftInputMode();

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

            Xamarin.Forms.Application.ClearCurrent();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnCreate;

            OnStateChanged();

            AddStatusBarUnderlay();
        }
Exemple #9
0
        protected override void OnPause()
        {
            _layout.HideKeyboard(true);

            if (_powerSaveReceiverRegistered && Forms.IsLollipopOrNewer)
            {
                // Don't listen for power save mode changes while we're paused
                UnregisterReceiver(_powerSaveModeBroadcastReceiver);
                _powerSaveReceiverRegistered = false;
            }

            // Stop animations or other ongoing actions that could consume CPU
            // Commit unsaved changes, build only if users expect such changes to be permanently saved when thy leave such as a draft email
            // Release system resources, such as broadcast receivers, handles to sensors (like GPS), or any resources that may affect battery life when your activity is paused.
            // Avoid writing to permanent storage and CPU intensive tasks
            base.OnPause();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnPause;

            OnStateChanged();
        }
        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 #11
0
		protected override void OnResume()
		{
			// counterpart to OnPause
			base.OnResume();

			if (_application != null && CurrentFocus != null && _application.OnThisPlatform().GetShouldPreserveKeyboardOnResume())
			{
				CurrentFocus.ShowKeyboard();
			}

			_previousState = _currentState;
			_currentState = AndroidApplicationLifecycleState.OnResume;

			if (Forms.IsLollipopOrNewer)
			{
				// Start listening for power save mode changes
				RegisterReceiver(_powerSaveModeBroadcastReceiver, new IntentFilter(
					PowerManager.ActionPowerSaveModeChanged
				));
			}

			OnStateChanged();
		}
Exemple #12
0
        protected override void OnResume()
        {
            Profile.FrameBegin();

            // counterpart to OnPause
            base.OnResume();

            if (_application != null && CurrentFocus != null && _application.OnThisPlatform().GetShouldPreserveKeyboardOnResume())
            {
                CurrentFocus.ShowKeyboard();
            }

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnResume;

            if (_needMainPageAssign)
            {
                _needMainPageAssign = false;
                SettingMainPage();
                SetMainPage();
            }

            if (!_powerSaveReceiverRegistered && Forms.IsLollipopOrNewer)
            {
                // Start listening for power save mode changes
                RegisterReceiver(_powerSaveModeBroadcastReceiver, new IntentFilter(
                                     PowerManager.ActionPowerSaveModeChanged
                                     ));

                _powerSaveReceiverRegistered = true;
            }

            OnStateChanged();

            Profile.FrameEnd();
        }
Exemple #13
0
 protected FormsAppCompatActivity()
 {
     _previousState = AndroidApplicationLifecycleState.Uninitialized;
     _currentState  = AndroidApplicationLifecycleState.Uninitialized;
     PopupManager.Subscribe(this);
 }
Exemple #14
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();
        }
Exemple #15
0
 protected FormsApplicationActivity()
 {
     _previousState = AndroidApplicationLifecycleState.Uninitialized;
     _currentState  = AndroidApplicationLifecycleState.Uninitialized;
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            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);

            Window.SetSoftInputMode(SoftInput.AdjustPan);

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

            Xamarin.Forms.Application.ClearCurrent();

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnCreate;

            OnStateChanged();

            _statusBarUnderlay = new global::Android.Views.View(this);
            var layoutParameters = new ARelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, GetStatusBarHeight())
            {
                AlignWithParent = true
            };

            layoutParameters.AddRule(LayoutRules.AlignTop);
            _statusBarUnderlay.LayoutParameters = layoutParameters;
            _layout.AddView(_statusBarUnderlay);

            if (Forms.IsLollipopOrNewer)
            {
                Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(SystemUiFlags.LayoutFullscreen | SystemUiFlags.LayoutStable);
                Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                Window.SetStatusBarColor(AColor.Transparent);

                int primaryColorDark = GetColorPrimaryDark();

                if (primaryColorDark != 0)
                {
                    int r = AColor.GetRedComponent(primaryColorDark);
                    int g = AColor.GetGreenComponent(primaryColorDark);
                    int b = AColor.GetBlueComponent(primaryColorDark);
                    int a = AColor.GetAlphaComponent(primaryColorDark);
                    SetStatusBarColor(AColor.Argb(a, r, g, b));
                }
            }
        }
		protected override void OnPause()
		{
			_layout.HideKeyboard(true);

			// Stop animations or other ongoing actions that could consume CPU
			// Commit unsaved changes, build only if users expect such changes to be permanently saved when thy leave such as a draft email
			// Release system resources, such as broadcast receivers, handles to sensors (like GPS), or any resources that may affect battery life when your activity is paused.
			// Avoid writing to permanent storage and CPU intensive tasks
			base.OnPause();

			_previousState = _currentState;
			_currentState = AndroidApplicationLifecycleState.OnPause;

			OnStateChanged();
		}
		protected override void OnResume()
		{
			// counterpart to OnPause
			base.OnResume();

			_previousState = _currentState;
			_currentState = AndroidApplicationLifecycleState.OnResume;

			OnStateChanged();
		}
		protected override void OnStart()
		{
			base.OnStart();

			_previousState = _currentState;
			_currentState = AndroidApplicationLifecycleState.OnStart;

			OnStateChanged();
		}
		// Scenarios that stop and restart you app
		// -- Switches from your app to another app, activity restarts when clicking on the app again.
		// -- Action in your app that starts a new Activity, the current activity is stopped and the second is created, pressing back restarts the activity
		// -- The user recieves a phone call while using your app on his or her phone
		protected override void OnStop()
		{
			// writing to storage happens here!
			// full UI obstruction
			// users focus in another activity
			// perform heavy load shutdown operations
			// clean up resources
			// clean up everything that may leak memory
			base.OnStop();

			_previousState = _currentState;
			_currentState = AndroidApplicationLifecycleState.OnStop;

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

			OnStateChanged();
		}
Exemple #22
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)
                {
                    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");
            Microsoft.Maui.Controls.Application.Current = null;

            _previousState = _currentState;
            _currentState  = AndroidApplicationLifecycleState.OnCreate;

            OnStateChanged();

            // Allow for the status bar color to be changed
            if ((flags & ActivationFlags.DisableSetStatusBarColor) == 0)
            {
                Profile.FramePartition("Set DrawsSysBarBkgrnds");
                Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            }

            Profile.FrameEnd();
        }
		protected FormsApplicationActivity()
		{
			_previousState = AndroidApplicationLifecycleState.Uninitialized;
			_currentState = AndroidApplicationLifecycleState.Uninitialized;
		}