Пример #1
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);
        }
Пример #2
0
        // Perform HMI stuff : check GC account
        private void PerformInit(ProgressDialog progressDialog)
        {
            // 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());
                return;
            }

            // Kill progressdialog (we are in UI thread already, good)
            if (progressDialog != null)
            {
                RunOnUiThread(() => progressDialog.Hide());
            }
        }
Пример #3
0
        // Perform authentication and quit to mainactivity if ok
        private void PerformAuthentication(ProgressDialog progressDialog)
        {
            // Check that filled values are valid
            GCStuffs gc = new GCStuffs();

            // Retrieve edittext for password & login
            EditText txtLogin    = FindViewById <EditText>(Resource.Id.editLogin);
            EditText txtPassword = FindViewById <EditText>(Resource.Id.editPassword);

            if (gc.CheckGCAccount(txtLogin.Text, txtPassword.Text, true, this))
            {
                Thread.Sleep(1000);

                // We have valid information
                // We save the configuration
                GCStuffs.ExportData(txtLogin.Text, txtPassword.Text);

                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // All right!
                RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.AccountGood) + " " + txtLogin.Text, ToastLength.Short).Show());

                // Go back in MainActivity and pass the valid login & password
                var intent = new Intent(this, typeof(MainActivity));
                SetResult(Result.Ok, intent);
                Finish();
            }
            else
            {
                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // Invalid account information, throw a message
                RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.AccountError), ToastLength.Short).Show());
            }
        }
Пример #4
0
        private void ShowOnMap(ProgressDialog progressDialog)
        {
            try
            {
                // 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)
                {
                    // Need to configure :-(
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.AccountConfigure), ToastLength.Short).Show());
                    GoodBye();
                }

                // we get information
                // Now iterate
                // dictionary with data
                Dictionary <String, List <GCNotification> > diconotifs = new Dictionary <string, List <GCNotification> >();
                int nb = 1;
                foreach (String id in _ids)
                {
                    // Is it canceled ?
                    if (_Canceled)
                    {
                        break; // Yes
                    }
                    // Update progress
                    progressDialog.Progress = nb;

                    // Get info
                    String         post_response = ""; // Not used here
                    GCNotification gcn           = _gcstuffs.GetNotificationData(id, ref post_response);
                    if (gcn != null)
                    {
                        // We stacks notifs with same coordinates
                        // key is lat+lon
                        String key = gcn.dlat.ToString() + gcn.dlon.ToString() + gcn.distance.ToString();
                        if (diconotifs.ContainsKey(key))
                        {
                            // update existing
                            diconotifs[key].Add(gcn);
                        }
                        else
                        {
                            // new one
                            diconotifs.Add(key, new List <GCNotification>(new GCNotification[] { gcn }));
                        }
                    }

                    nb++;
                }

                // Store all marker locations
                List <LatLng> markerslocations = new List <LatLng>();

                // iterate on notifications
                foreach (KeyValuePair <String, List <GCNotification> > pair in diconotifs)
                {
                    // We create the marker
                    // Get color
                    Color                 c    = Color.Pink;
                    float                 b    = BitmapDescriptorFactory.HueRose;
                    GCNotification        gcn  = pair.Value[0];
                    List <GCNotification> gcns = pair.Value;
                    if (pair.Value.Count == 1)
                    {
                        // get color of this single notif
                        gcn.GetIcon(ref b, ref c);
                    }

                    // Create marker
                    LatLng location = new LatLng(gcn.dlat, gcn.dlon);
                    // Not necessary since we do it for the circles right below
                    //markerslocations.Add(location);

                    // Create markeroptions
                    MarkerOptions mk = new MarkerOptions();
                    mk.SetPosition(location);

                    // And the icon color
                    mk.SetIcon(BitmapDescriptorFactory.DefaultMarker(b));

                    // And a title and snippet
                    String title   = "";
                    String snippet = "";

                    // Title and snippet depending on number of gnc
                    if (gcns.Count == 1)
                    {
                        // Single notification
                        title   = gcn.name + " (" + gcn.distance.ToString() + " Km)";
                        snippet = gcn.GetTypeKeyInEnglish();
                    }
                    else
                    {
                        // Merged markers
                        // Create tooltip (may be to long, anyway...)
                        // Everyone is colocated
                        // Try to regroup by gcn names
                        Dictionary <String, List <GCNotification> > dicoNameGCN = new Dictionary <String, List <GCNotification> >();
                        foreach (GCNotification gn in gcns)
                        {
                            // Regroup by name
                            if (dicoNameGCN.ContainsKey(gn.name))
                            {
                                dicoNameGCN[gn.name].Add(gn);
                            }
                            else
                            {
                                dicoNameGCN.Add(gn.name, new List <GCNotification>(new GCNotification[] { gn }));
                            }
                        }

                        // Now create the tip
                        String tip = "";
                        foreach (KeyValuePair <String, List <GCNotification> > pair2 in dicoNameGCN)
                        {
                            // this is the gcn name
                            tip += pair2.Key + "\n";

                            // Now list all type / kind of notification
                            foreach (GCNotification g in pair2.Value)
                            {
                                // Type (tradi, etc...)
                                tip += "    " + g.GetTypeKeyInEnglish();// + ": ";

                                // And now the kind of notif (publish, etc...)
                                // NO! THIS IS THE POST VALUE NOT READABLE

                                /*
                                 * foreach(String kn in g.data.Item3)
                                 * {
                                 *  tip += kn + " ";
                                 * }
                                 */
                                // new line
                                tip += "\n";
                            }
                        }

                        // Assign values
                        title   = Resources.GetString(Resource.String.MergedMarkers) + " (" + gcns[0].distance.ToString() + " Km)";
                        snippet = tip;
                    }

                    // Assign real values
                    mk.SetTitle(title);
                    mk.SetSnippet(snippet);

                    // Add marker
                    RunOnUiThread(() => _map.AddMarker(mk));

                    // We create the circle marker
                    CircleOptions circleOptions = new CircleOptions();
                    circleOptions.InvokeCenter(location);
                    circleOptions.InvokeRadius(gcn.distance * 1000);
                    circleOptions.InvokeFillColor(Color.Argb(60, c.R, c.G, c.B));
                    //circleOptions.InvokeStrokeColor(Color.Argb(60, c.R, c.G, c.B));
                    circleOptions.InvokeStrokeWidth(2.0f);

                    // And we update the markerslocations with the bounding box of the circle
                    BoundingBox bb = GCStuffs.GetBoundingBox(new MapPoint {
                        Latitude = location.Latitude, Longitude = location.Longitude
                    }, gcn.distance);
                    markerslocations.Add(new LatLng(bb.MinPoint.Latitude, bb.MinPoint.Longitude));
                    markerslocations.Add(new LatLng(bb.MaxPoint.Latitude, bb.MaxPoint.Longitude));

                    // Create on map
                    RunOnUiThread(() => _map.AddCircle(circleOptions).Visible = true);
                }

                // Zoom map to fit
                if (markerslocations.Count != 0)
                {
                    RunOnUiThread(() => FitAllMarkers(markerslocations));
                }

                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // All right!
                if (_Canceled)
                {
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Canceled), ToastLength.Short).Show());
                }
                else
                {
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Success), ToastLength.Short).Show());
                }
            }
            catch (Exception)
            {
                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // Crap
                RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Error), ToastLength.Short).Show());
            }
        }