Beispiel #1
0
        /// <summary>
        /// The on create method.
        /// </summary>
        /// <param name="savedInstanceState">The saved instance state.</param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            //Start by calling the base create method.
            base.OnCreate(savedInstanceState);

            //Initialize the essentials with Androids activity and bundle.
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            //Create the dialog handler.
            this.dialogHandler = new DialogHandler(this);

            //Set the context view to the main view.
            this.SetContentView(Resource.Layout.activity_main);

            //Set the tool bar.
            this.SetSupportActionBar(FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar));

            //From here on in we need permissions so we need to check and see if we have them.
            //If we do we'll continue, if not we'll wait until the permissions have been resolved.
            if (this.CheckPermissions())
            {
                //Create the location database handler.
                this.locationDatabaseHandler = new LocationDatabaseHandler();

                //Setup the location manager.
                this.SetupLocationManager();

                //Setup the list view.
                this.SetupListView();
            }
        }
Beispiel #2
0
        /// <summary>
        /// The on create method.
        /// </summary>
        /// <param name="savedInstanceState">The saved instance state.</param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            //Start by calling the base create method.
            base.OnCreate(savedInstanceState);

            //Initialize the essentials with Androids activity and bundle.
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            //Create the dialog handler.
            this.dialogHandler = new DialogHandler(this);

            //Set the context view to location item view.
            SetContentView(Resource.Layout.activity_item);

            //Set the tool bar.
            this.SetSupportActionBar(FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar));

            //Get the intents and extras.
            Bundle extras = this.Intent.Extras;

            //If no extras are present.
            if (extras == null)
            {
                //Finish the activity.
                this.FinishActivity(0);
            }

            //Get the id from the extras.
            int id = extras.GetInt("ID");

            //Create the location database handler.
            this.locationDatabaseHandler = new LocationDatabaseHandler();

            //Retrieve the location model from the database.
            this.locationModel = this.locationDatabaseHandler.GetByID(id);

            //Get the textboxes.
            this.locationTitleText = this.FindViewById <EditText>(Resource.Id.locationTitleText);
            this.noteText          = this.FindViewById <EditText>(Resource.Id.noteText);

            //Set the values for the textboxes.
            this.locationTitleText.Text = locationModel.Title;
            this.noteText.Text          = locationModel.Note;

            //Show the longitude, latitude and alitude values.
            this.FindViewById <TextView>(Resource.Id.longitudeTextView).Text = string.Format(Resources.GetString(Resource.String.longitude_format), locationModel.Longitude);
            this.FindViewById <TextView>(Resource.Id.latitudeTextView).Text  = string.Format(Resources.GetString(Resource.String.latitude_format), locationModel.Latitude);
            this.FindViewById <TextView>(Resource.Id.altitudeTextView).Text  = string.Format(Resources.GetString(Resource.String.altitude_format), locationModel.Altitude);
        }
Beispiel #3
0
        /// <summary>
        /// After the permissions result has been determined.
        /// </summary>
        /// <param name="requestCode">Request code.</param>
        /// <param name="permissions">Permissions requested.</param>
        /// <param name="grantResults">Grant results.</param>
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            //Create a new list for unaccepted permissions.
            var unacceptedPermissions = new List <string>();

            //Loop through the permissions.
            for (int i = 0; i < permissions.Length; i++)
            {
                //If a permission has been denied.
                if (grantResults[i] == Permission.Denied)
                {
                    //We'll add it to the unaccepted list so we can ask again.
                    unacceptedPermissions.Add(permissions[i]);
                }
            }

            //If we've no permissions left to request
            if (unacceptedPermissions.Count <= 0)
            {
                //Create the location database handler.
                this.locationDatabaseHandler = new LocationDatabaseHandler();

                //Setup the location manager.
                this.SetupLocationManager();

                //Setup the list view.
                this.SetupListView();

                //Return and do nothing.
                return;
            }

            //Format a display string to show the user.
            var message = Resources.GetString(Resource.String.android_permissions_denied)
                          + string.Format(Resources.GetString(Resource.String.android_permissions_request),
                                          string.Join("\n", unacceptedPermissions.Select(x => x.Split(".")[2])));

            //Display a dialog notifying the user we'll be asking for permissions. And then request them.
            this.dialogHandler.ShowInertAlert(Resources.GetString(Resource.String.missing_permissions_title), message,
                                              (s, e) => this.RequestPermissions(unacceptedPermissions.ToArray(), 0),
                                              new DialogButton(Resources.GetString(Resource.String.exit_button_title), CloseApp));
        }