// *********************************************************************** // Assembly : XLabs.Forms.Droid // Author : XLabs Team // Created : 12-27-2015 // // Last Modified By : XLabs Team // Last Modified On : 01-04-2016 // *********************************************************************** // // Copyright (c) XLabs Team. All rights reserved. // // // This project is licensed under the Apache 2.0 license // https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/LICENSE // // XLabs is a open source project that aims to provide a powerfull and cross // platform set of controls tailored to work with Xamarin Forms. // // *********************************************************************** // using System; using Xamarin.Forms; using Xamarin.Forms.Platform.Android; using XLabs.Platform.Device; using XLabs.Platform.Mvvm; using XLabs.Platform.Services; using XLabs.Platform.Services.Email; using XLabs.Platform.Services.Geolocation; using XLabs.Platform.Services.IO; using XLabs.Platform.Services.Media; using Environment = Android.OS.Environment; namespace XLabs.Forms { /// /// Class XFormsApplicationDroid. /// public class XFormsCompatApplicationDroid : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { /// /// Gets or sets the destroy. /// /// The destroy. public EventHandler Destroy { get; set; } /// /// Gets or sets the pause. /// /// The pause. public EventHandler Pause { get; set; } /// /// Gets or sets the restart. /// /// The restart. public EventHandler Restart { get; set; } /// /// Gets or sets the resume. /// /// The resume. public EventHandler Resume { get; set; } /// /// Gets or sets the start. /// /// The start. public EventHandler Start { get; set; } /// /// Gets or sets the stop. /// /// The stop event handler. public EventHandler Stop { get; set; } /// /// Called when [destroy]. /// protected override void OnDestroy() { var handler = this.Destroy; if (handler != null) { handler(this, new EventArgs()); } base.OnDestroy(); } /// /// Called as part of the activity lifecycle when an activity is going into /// the background, but has not (yet) been killed. /// /// /// /// /// /// Called as part of the activity lifecycle when an activity is going into /// the background, but has not (yet) been killed. The counterpart to /// . /// /// When activity B is launched in front of activity A, this callback will /// be invoked on A. B will not be created until A's returns, /// so be sure to not do anything lengthy here. /// /// This callback is mostly used for saving any persistent state the /// activity is editing, to present a "edit in place" model to the user and /// making sure nothing is lost if there are not enough resources to start /// the new activity without first killing this one. This is also a good /// place to do things like stop animations and other things that consume a /// noticeable amount of CPU in order to make the switch to the next activity /// as fast as possible, or to close resources that are exclusive access /// such as the camera. /// /// In situations where the system needs more memory it may kill paused /// processes to reclaim resources. Because of this, you should be sure /// that all of your state is saved by the time you return from /// this function. In general is used to save /// per-instance state in the activity and this method is used to store /// global persistent data (in content providers, files, etc.) /// /// After receiving this call you will usually receive a following call /// to (after the next activity has been resumed and /// displayed), however in some cases there will be a direct call back to /// without going through the stopped state. /// /// /// Derived classes must call through to the super class's /// implementation of this method. If they do not, an exception will be /// thrown. /// /// /// /// [Android Documentation] /// /// protected override void OnPause() { var handler = this.Pause; if (handler != null) { handler(this, new EventArgs()); } base.OnPause(); } /// /// Called after when the current activity is being /// re-displayed to the user (the user has navigated back to it). /// /// /// /// /// /// Called after when the current activity is being /// re-displayed to the user (the user has navigated back to it). It will /// be followed by and then . /// /// For activities that are using raw objects (instead of /// creating them through /// , /// this is usually the place /// where the cursor should be required (because you had deactivated it in /// . /// /// /// Derived classes must call through to the super class's /// implementation of this method. If they do not, an exception will be /// thrown. /// /// /// /// [Android Documentation] /// /// protected override void OnRestart() { var handler = this.Restart; if (handler != null) { handler(this, new EventArgs()); } base.OnRestart(); } /// /// Called after , , or /// , for your activity to start interacting with the user. /// /// /// /// /// /// /// Called after , , or /// , for your activity to start interacting with the user. /// This is a good place to begin animations, open exclusive-access devices /// (such as the camera), etc. /// /// Keep in mind that onResume is not the best indicator that your activity /// is visible to the user; a system window such as the key guard may be in /// front. Use to know for certain that your /// activity is visible to the user (for example, to resume a game). /// /// /// Derived classes must call through to the super class's /// implementation of this method. If they do not, an exception will be /// thrown. /// /// /// /// [Android Documentation] /// /// protected override void OnResume() { var handler = this.Resume; if (handler != null) { handler(this, new EventArgs()); } base.OnResume(); } /// /// Called after or after when /// the activity had been stopped, but is now again being displayed to the /// user. /// /// /// /// /// /// Called after or after when /// the activity had been stopped, but is now again being displayed to the /// user. It will be followed by . /// /// /// Derived classes must call through to the super class's /// implementation of this method. If they do not, an exception will be /// thrown. /// /// /// /// [Android Documentation] /// /// protected override void OnStart() { var handler = this.Start; if (handler != null) { handler(this, new EventArgs()); } base.OnStart(); } /// /// Called when you are no longer visible to the user. /// /// /// /// /// /// /// Called when you are no longer visible to the user. You will next /// receive either , , or nothing, /// depending on later user activity. /// /// Note that this method may never be called, in low memory situations /// where the system does not have enough memory to keep your activity's /// process running after its method is called. /// /// /// Derived classes must call through to the super class's /// implementation of this method. If they do not, an exception will be /// thrown. /// /// /// /// [Android Documentation] /// /// protected override void OnStop() { var handler = this.Stop; if (handler != null) { handler(this, new EventArgs()); } base.OnStop(); } } /// /// Class XFormsAppDroid. /// public class XFormsCompatAppDroid : XFormsApp { /// /// Initializes a new instance of the class. /// public XFormsCompatAppDroid() { } /// /// Initializes a new instance of the class. /// /// The application. public XFormsCompatAppDroid(XFormsCompatApplicationDroid app) : base(app) { } /// /// Raises the back press. /// public void RaiseBackPress() { this.OnBackPress(); } /// /// Called when [initialize]. /// /// The application. /// Should initialize services. protected override void OnInit(XFormsCompatApplicationDroid app, bool initServices = true) { this.AppContext.Start += (o, e) => this.OnStartup(); this.AppContext.Stop += (o, e) => this.OnClosing(); this.AppContext.Pause += (o, e) => this.OnSuspended(); this.AppContext.Resume += (o, e) => this.OnResumed(); this.AppDataDirectory = Environment.ExternalStorageDirectory.AbsolutePath; this.Orientation = AppContext.RequestedOrientation == Android.Content.PM.ScreenOrientation.Portrait ? Enums.Orientation.Portrait : Enums.Orientation.None; if (initServices) { DependencyService.Register(); DependencyService.Register(); DependencyService.Register(); DependencyService.Register(); DependencyService.Register(); DependencyService.Register(); DependencyService.Register(); } base.OnInit(app); } } }