Beispiel #1
0
        // Show on map button clicked
        private void ShowOnMapSelection()
        {
#if (LITE)
            Toast.MakeText(this, this.Resources.GetString(Resource.String.OnlyFullShowOnMap), ToastLength.Long).Show();
            return;
#endif
#if (FULL)
            // Check if something is selected
            if (!DoWeHaveSelection())
            {
                return;
            }

            // Check if internet access is available
            if (!GCStuffs.CheckNetworkAccess(this))
            {
                Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Short).Show();
                return;
            }

            // List of notifications ids
            // All that is selected
            List <String> ids = GetSelectedIds();

            // Create intent to launch show on map activity
            var intent = new Intent(this, typeof(ShowOnMapActivity));

            // Call activity
            intent.PutStringArrayListExtra("selectionids", ids);

            // Start the activity waiting for a result
            StartActivityForResult(intent, 4);              // 4 for show on map
#endif
        }
        // *************************************************************
        // *************************************************************

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            DateTime timeLimit = DateTime.Now;
            bool     bExpired  = false;

            // Is expiration mechanism active?
            if (GetExpirationDate(ref timeLimit))
            {
                // are we to late to use EzFTF?
                bExpired = (DateTime.Now > timeLimit);
            }

            if (bExpired)
            {
                // Message to inform that it is expired
                Toast.MakeText(this, this.Resources.GetString(Resource.String.ExpiredVersion), ToastLength.Long).Show();
                ThreadPool.QueueUserWorkItem(o => DoFinish());
            }
            else if (!GCStuffs.CheckNetworkAccess(this))
            {
                Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Long).Show();
                ThreadPool.QueueUserWorkItem(o => DoFinish());
            }
            else
            {
                //Start MainActivity Activity
                StartActivity(typeof(MainActivity));
            }
        }
Beispiel #3
0
        private bool SetMainView()
        {
            // Check if internet access is available
            if (!GCStuffs.CheckNetworkAccess(this))
            {
                Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Short).Show();
            }

            // Right before displaying the view, check GC account stuff (time consuming)
            // And force cookiejar generation, and store cookiejar inside _gcstuffs
            bool accountconfigured = _gcstuffs.CheckGCAccount(_login, _password, true, this);

            // Set our view from the "Main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            ImageButton button1 = FindViewById <ImageButton>(Resource.Id.Update);

            button1.Click += Update_Click;
            ImageButton button2 = FindViewById <ImageButton>(Resource.Id.Add);

            button2.Click += Add_Click;
            ImageButton button3 = FindViewById <ImageButton>(Resource.Id.Configure);

            button3.Click += Configure_Click;
            ImageButton button4 = FindViewById <ImageButton>(Resource.Id.MenuSel);

            button4.Click += MenuSel_Click;
            ImageButton button5 = FindViewById <ImageButton>(Resource.Id.Quit);

            button5.Click += Quit_Click;
            ImageButton button6 = FindViewById <ImageButton>(Resource.Id.About);

            button6.Click += About_Click;


            // Create adapter to display listview items (notifications)
            ListView lvItems = FindViewById <ListView>(Resource.Id.lvItems);

            _fa                = new NotifAdapter(this, new List <Notif>());
            lvItems.Adapter    = _fa;
            lvItems.ItemClick += LvItems_ItemClick;

            // Update hmi and populate list
            UpdateHMIAndPopulate(accountconfigured);

            return(accountconfigured);
        }
Beispiel #4
0
        // Perform selected notifications toggle
        private void Toggle()
        {
            // Check if internet access is available
            if (!GCStuffs.CheckNetworkAccess(this))
            {
                Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Short).Show();
                return;
            }

            // List of notifications ids to toggle
            // All that is selected will have its toggle activation status toggled
            List <String> ids = GetSelectedIds();

            // At last one selection ?
            if (ids.Count == 0)
            {
                // Cancel deletion since no type
                Toast.MakeText(this, this.Resources.GetString(Resource.String.NoNotif), ToastLength.Short).Show();
                return;
            }

            // Launch application inside a progress bar
            ProgressDialog progressDialog = new ProgressDialog(this);

            progressDialog.SetProgressStyle(ProgressDialogStyle.Horizontal);
            progressDialog.SetMessage(this.Resources.GetString(Resource.String.LblToggleInProgress));
            progressDialog.SetTitle(this.Resources.GetString(Resource.String.OperationInProgress));
            progressDialog.Progress = 0;
            progressDialog.Max      = ids.Count;
            progressDialog.SetCancelable(false);
            _Canceled = false;
            progressDialog.SetButton((int)(DialogButtonType.Negative),
                                     this.Resources.GetString(Resource.String.Cancel),
                                     (st, evt) =>
            {
                // Tell the system about cancellation
                _Canceled = true;
            });
            progressDialog.Show();

            ThreadPool.QueueUserWorkItem(o => ToggleNotificationImpl(progressDialog, ids));
        }
Beispiel #5
0
        // Save button clicked
        private void Save_Click(object sender, EventArgs e)
        {
            // Check if internet access is available
            if (!GCStuffs.CheckNetworkAccess(this))
            {
                Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Short).Show();
                return;
            }

            ProgressDialog progressDialog = new ProgressDialog(this);

            progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);
            progressDialog.SetMessage(this.Resources.GetString(Resource.String.LblAccountVerif));
            progressDialog.SetTitle(this.Resources.GetString(Resource.String.OperationInProgress));
            progressDialog.Indeterminate = true;
            progressDialog.SetCancelable(false);
            progressDialog.Show();

            ThreadPool.QueueUserWorkItem(o => PerformAuthentication(progressDialog));
        }
        // Perform HMI stuff : check GC account and populate emails
        private void PerformGCActions(ProgressDialog progressDialog)
        {
            if (_CheckingEmails)
            {
                return;
            }
            _CheckingEmails = true;

            if (!GCStuffs.CheckNetworkAccess(this))
            {
                if (progressDialog != null)
                {
                    RunOnUiThread(() => progressDialog.Hide());
                }

                // Need to connect to internet :-(
                RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Short).Show());
                _CheckingEmails = false;
                return;
            }

            // Create a new _gcstuffs
            _gcstuffs = new GCStuffs();

            // We read configuration from exportdata
            bool          needtoconf = false;
            List <String> conf       = GCStuffs.LoadDataString();

            if ((conf != null) && (conf.Count >= 2))
            {
                // We have a configuration on exportdata
                // check if account is valid and populate cookiejar
                if (_gcstuffs.CheckGCAccount(conf[0], conf[1], true, this))
                {
                    // All right !
                }
                else
                {
                    needtoconf = true;
                }
            }
            else
            {
                needtoconf = true;
            }

            // Do we need to configure ? no reason to be there in that case
            if (needtoconf)
            {
                // Kill progressdialog (we are in UI thread already, good)
                if (progressDialog != null)
                {
                    RunOnUiThread(() => progressDialog.Hide());
                }

                // Need to configure :-(
                RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.AccountConfigure), ToastLength.Short).Show());
                _CheckingEmails = false;
                return;
            }

            // Kill progressdialog (we are in UI thread already, good)
            if (progressDialog != null)
            {
                RunOnUiThread(() => progressDialog.Hide());
            }
            _CheckingEmails = false;
        }
        private void CreateNotifications()
        {
            // Check if internet access is available
            if (!GCStuffs.CheckNetworkAccess(this))
            {
                Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Short).Show();
                return;
            }

            try
            {
                // Get all the nested values
                // Get coordinates
                String coord = txtCoord.Text;
                String sLat  = "";
                String sLon  = "";
                if (!GCStuffs.TryToConvertCoordinates(coord, ref sLat, ref sLon))
                {
                    // Cancel creation wrong coordinates
                    Toast.MakeText(this, this.Resources.GetString(Resource.String.BadCoordinates), ToastLength.Short).Show();
                    return;
                }
                // convert to double
                double dlat = GCStuffs.ConvertToDouble(sLat);
                double dlon = GCStuffs.ConvertToDouble(sLon);

                // Get radius
                String radius   = FindViewById <EditText>(Resource.Id.editRadius).Text;
                int    distance = 0;
                if (!Int32.TryParse(radius, out distance) || (distance == 0))
                {
                    // Cancel creation wrong radius
                    Toast.MakeText(this, this.Resources.GetString(Resource.String.BadDistance), ToastLength.Short).Show();
                    return;
                }

                // Get Name
                String name = FindViewById <EditText>(Resource.Id.editName).Text;
                if (name == "")
                {
                    // Cancel creation since empty name
                    Toast.MakeText(this, this.Resources.GetString(Resource.String.BadName), ToastLength.Short).Show();
                    return;
                }

                // Email
                Spinner mySpinner = FindViewById <Spinner>(Resource.Id.spinnerEmail);
                String  email     = "";
                if (mySpinner.Visibility != ViewStates.Invisible)
                {
                    if (mySpinner.SelectedItem != null)
                    {
                        email = mySpinner.SelectedItem.ToString();
                    }

                    /*
                     * if (email == "")
                     * {
                     *  // Cancel creation since empty name
                     *  Toast.MakeText(this, this.Resources.GetString(Resource.String.BadEmail), ToastLength.Short).Show();
                     *  return;
                     * }*/
                }
                // Types : check that at least one type is checked
                List <Tuple <int, string, List <string>, int> > selectedTypes = new List <Tuple <int, string, List <string>, int> >();
                foreach (var tc in _typecaches)
                {
                    // Is it checked ?
                    if (tc.Checked)
                    {
                        // Yes, so we find the correspoding tuple
                        foreach (var tpl in _allowedtypes)
                        {
                            if (tpl.Item2 == tc.Type)
                            {
                                // Found it !
                                selectedTypes.Add(tpl);
                            }
                        }
                    }
                }

                // At least one type selected ?
                int nbsel = selectedTypes.Count;
                if (nbsel == 0)
                {
                    // Cancel creation since no type
                    Toast.MakeText(this, this.Resources.GetString(Resource.String.NoType), ToastLength.Short).Show();
                    return;
                }
                else
                {
                    // Check if we go higher that 40 notifications
                    if ((nbNotifs + nbsel) > 40)
                    {
                        int    maxnb = 40 - nbNotifs;
                        String msg   = String.Format(this.Resources.GetString(Resource.String.MaxNotifWillReached), nbNotifs, maxnb);
                        Toast.MakeText(this, msg, ToastLength.Long).Show();
                        return;
                    }
                }

                // Ask if we are ready
                var builder = new AlertDialog.Builder(this);
                builder.SetMessage(this.Resources.GetString(Resource.String.ConfirmCreate));
                builder.SetPositiveButton(this.Resources.GetString(Resource.String.BtnYes), (s, ev) =>
                {
                    // Launch application inside a progress bar
                    ProgressDialog progressDialog = new ProgressDialog(this);
                    progressDialog.SetProgressStyle(ProgressDialogStyle.Horizontal);
                    progressDialog.SetMessage(this.Resources.GetString(Resource.String.LblCreateInProgress));
                    progressDialog.SetTitle(this.Resources.GetString(Resource.String.OperationInProgress));
                    progressDialog.Progress = 0;
                    progressDialog.Max      = selectedTypes.Count;
                    progressDialog.SetCancelable(false);
                    _Canceled = false;
                    progressDialog.SetButton((int)(DialogButtonType.Negative),
                                             this.Resources.GetString(Resource.String.Cancel),
                                             (st, evt) =>
                    {
                        // Tell the system about cancellation
                        _Canceled = true;
                    });

                    progressDialog.Show();

                    ThreadPool.QueueUserWorkItem(o => CreateNotificationsImpl(progressDialog, dlat, dlon, distance, name, selectedTypes, email));
                });
                builder.SetNegativeButton(this.Resources.GetString(Resource.String.BtnNo), (s, ev) =>
                {
                    // do something on Cancel click
                });
                builder.Create().Show();
            }
            catch (Exception)
            {
                Toast.MakeText(this, this.Resources.GetString(Resource.String.Error), ToastLength.Short).Show();
            }
        }
Beispiel #8
0
        // Save button clicked
        private void Save_Click(object sender, EventArgs e)
        {
            // Check if internet access is available
            if (!GCStuffs.CheckNetworkAccess(this))
            {
                Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Short).Show();
                return;
            }

            try
            {
                // Get all the nested values
                // Get coordinates
                String coord = txtCoord.Text;
                String sLat  = "";
                String sLon  = "";
                if (!GCStuffs.TryToConvertCoordinates(coord, ref sLat, ref sLon))
                {
                    // Cancel creation wrong coordinates
                    Toast.MakeText(this, this.Resources.GetString(Resource.String.BadCoordinates), ToastLength.Short).Show();
                    return;
                }
                // convert to double
                double dlat = GCStuffs.ConvertToDouble(sLat);
                double dlon = GCStuffs.ConvertToDouble(sLon);

                // Ask if we are ready
                var builder = new AlertDialog.Builder(this);
                builder.SetMessage(this.Resources.GetString(Resource.String.ConfirmUpdateCoord));
                builder.SetPositiveButton(this.Resources.GetString(Resource.String.BtnYes), (s, ev) =>
                {
                    // Launch application inside a progress bar
                    ProgressDialog progressDialog = new ProgressDialog(this);
                    progressDialog.SetProgressStyle(ProgressDialogStyle.Horizontal);
                    progressDialog.SetMessage(this.Resources.GetString(Resource.String.LblUpdateInProgress));
                    progressDialog.SetTitle(this.Resources.GetString(Resource.String.OperationInProgress));
                    progressDialog.Progress = 0;
                    progressDialog.Max      = _ids.Count;
                    progressDialog.SetCancelable(false);
                    _Canceled = false;
                    progressDialog.SetButton((int)(DialogButtonType.Negative),
                                             this.Resources.GetString(Resource.String.Cancel),
                                             (st, evt) =>
                    {
                        // Tell the system about cancellation
                        _Canceled = true;
                    });
                    progressDialog.Show();

                    ThreadPool.QueueUserWorkItem(o => UpdateCoord(progressDialog, dlat, dlon));
                });
                builder.SetNegativeButton(this.Resources.GetString(Resource.String.BtnNo), (s, ev) =>
                {
                    // do something on Cancel click
                });
                builder.Create().Show();
            }
            catch (Exception)
            {
                Toast.MakeText(this, this.Resources.GetString(Resource.String.Error), ToastLength.Short).Show();
            }
        }