// do the update coord job private void UpdateCoord(ProgressDialog progressDialog, double dlat, double dlon) { try { // Iterate on selection 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 update :-) // WE NEED TO USE the previous post_response to get valid VIEW_STATES // We build the post string String post_string = GCStuffs.GeneratePostString(post_response, dlat, dlon, gcn.distance, gcn.name, gcn.data, gcn.email, gcn.checknotif); String url = "https://www.geocaching.com/notify/edit.aspx?NID=" + id; // And we post post_response = GCStuffs.GeneratePostRequets(url, post_string, _gcstuffs._cookieJar); } nb++; } // 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()); // Don't go to main activity !!! } else { RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Success), ToastLength.Short).Show()); // Then go back to main activity GoToMainActivity(true); } } 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()); } }
// Define the view private void SetMainView() { // Set our view from the "Configuration" layout resource SetContentView(Resource.Layout.Configuration); // Hide the bloody keyboard by default ? Window.SetSoftInputMode(SoftInput.StateAlwaysHidden); // Retrieve edittext for password & login EditText txtLogin = FindViewById <EditText>(Resource.Id.editLogin); EditText txtPassword = FindViewById <EditText>(Resource.Id.editPassword); // We read configuration from exportdata List <String> conf = GCStuffs.LoadDataString(); if ((conf != null) && (conf.Count >= 2)) { txtLogin.Text = conf[0]; txtPassword.Text = conf[1]; } // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.Save); button.Click += Save_Click; button = FindViewById <Button>(Resource.Id.Cancel); button.Click += Cancel_Click; }
// ************************************************************* // ************************************************************* 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)); } }
public String NiceCoordToString(LatLng location) { String sLat2 = GCStuffs.ConvertDegreesToDDMM(location.Latitude, true); String sLon2 = GCStuffs.ConvertDegreesToDDMM(location.Longitude, false); return /*"DD° MM.MMM: " + */ (sLat2 + " " + sLon2); }
// 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 }
// Creation method protected override void OnCreate(Bundle bundle) { // Base creation base.OnCreate(bundle); // Modify title this.Title = this.Title + " " + PackageManager.GetPackageInfo(PackageName, 0).VersionName + " - "; #if (FULL) this.Title += this.Resources.GetString(Resource.String.Full); #endif #if (LITE) this.Title += this.Resources.GetString(Resource.String.Lite); #endif // Create GCStuffs instance (do nothing except creating object) _gcstuffs = new GCStuffs(); // Get account data GetAccountInformation(); // We retrieved sorting type from preferences ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this); _currentSort = (SortType)(prefs.GetInt("sorttype", (int)(SortType.Age))); _sortDirectionIncrease = prefs.GetBoolean("sortdirection", false); // We display the main view bool accountconfigured = SetMainView(); // Launch configure if no configuration if (!accountconfigured) { Configure(); } }
// Result of an activity, back to work! protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode == Result.Ok) { if (requestCode == 10) // Map { IList <String> p = null; if (data != null) { p = data.Extras.GetStringArrayList("coordinates") ?? new string[0]; } // Check validity of parameter if ((p != null) && (p.Count == 2)) { // List is valid, populate login & password String sLat2 = GCStuffs.ConvertDegreesToDDMM(GCStuffs.ConvertToDouble(p[0]), true); String sLon2 = GCStuffs.ConvertDegreesToDDMM(GCStuffs.ConvertToDouble(p[1]), false); txtCoord.Text = /*"DD° MM.MMM: " + */ sLat2 + " " + sLon2; Toast.MakeText(this, this.Resources.GetString(Resource.String.PickDone), ToastLength.Short).Show(); } } } }
public void OnMapReady(GoogleMap googleMap) { if (googleMap != null) { //Map is ready for use _map = googleMap; if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) == Permission.Granted) { _map.MyLocationEnabled = true; _map.UiSettings.CompassEnabled = true; _map.UiSettings.ZoomControlsEnabled = true; _map.MarkerDragEnd += myMarkerDragEnd; CameraPosition.Builder builder = CameraPosition.InvokeBuilder(); LatLng location = null; if ((lat != "") && (lon != "")) { location = new LatLng(GCStuffs.ConvertToDouble(lat), GCStuffs.ConvertToDouble(lon)); } else { // Don't forget to assign a value to lat and lon // If omeone click on save coord without moving the marker, these values will be used lat = "43.3"; lon = "5.4"; location = new LatLng(43.3, 5.4); } builder.Target(location); builder.Zoom(10);// 13); CameraPosition cameraPosition = builder.Build(); CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition); _map.MoveCamera(cameraUpdate); // Create marker _marker = new MarkerOptions(); _marker.SetPosition(location); TextView lblCoord = FindViewById <TextView>(Resource.Id.lblCoord); lblCoord.Text = /*"DD° MM.MMM: " + */ NiceCoordToString(location); _marker.Draggable(true); _marker.SetTitle(NiceCoordToString(location)); //_marker.SetIcon(BitmapDescriptorFactory.FromResource(geo.GetIconResourceId())); _map.AddMarker(_marker); // Create circle if possible CreateCircle(location); } else { // Show rationale and request permission. Toast.MakeText(this, this.Resources.GetString(Resource.String.ErrorLocation), ToastLength.Short).Show(); } } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "MapLayout" layout resource SetContentView(Resource.Layout.MapLayout); // Get params IList <String> p = null; if (Intent.Extras != null) { p = Intent.Extras.GetStringArrayList("coordinates") ?? new string[0]; } // Check validity of parameter if (p != null) { if (p.Count >= 2) { // List is valid, populate login & password lat = p[0]; lon = p[1]; } if (p.Count >= 3) { if (!Int32.TryParse(p[2], out radius)) { radius = 0; } } } if ((lat != "") && (lon != "")) { // Textview to diplay coordinates TextView lblCoord = FindViewById <TextView>(Resource.Id.lblCoord); String sLat2 = GCStuffs.ConvertDegreesToDDMM(GCStuffs.ConvertToDouble(lat), true); String sLon2 = GCStuffs.ConvertDegreesToDDMM(GCStuffs.ConvertToDouble(lon), false); lblCoord.Text = /*"DD° MM.MMM: " + */ sLat2 + " " + sLon2; } // Create your application here var frag = FragmentManager.FindFragmentById <MapFragment>(Resource.Id.map); frag.GetMapAsync(this); Button button = FindViewById <Button>(Resource.Id.Save); button.Click += Save_Click; button = FindViewById <Button>(Resource.Id.BtnQuit); button.Click += Cancel_Click; }
private void GetAccountInformation() { // we read data from configuration if exists List <String> conf = GCStuffs.LoadDataString(); if ((conf != null) && (conf.Count >= 2)) { // Configuration is valid, populate login & password _login = conf[0]; _password = conf[1]; } }
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); }
// 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()); } }
// The System will call OnLocationChanged when the user's location changes enough to qualify as a location change according to the Criteria we set when requesting location updates. public void OnLocationChanged(Android.Locations.Location location) { //base.OnLocationChanged(location) // STORE VALUES and link it to GPS button !!! String sLat2 = GCStuffs.ConvertDegreesToDDMM(location.Latitude, true); String sLon2 = GCStuffs.ConvertDegreesToDDMM(location.Longitude, false); lastGPSCoords = /*"DD° MM.MMM: " + */ sLat2 + " " + sLon2; Toast.MakeText(this, this.Resources.GetString(Resource.String.GPSFix), ToastLength.Short).Show(); // If no location filled, we put it, better than nothing if (txtCoord.Text == "") { txtCoord.Text = lastGPSCoords; } }
// PickMap_Click button clicked private void PickMap_Click(object sender, EventArgs e) { //#if (FULL) // Create intent to launch configuration activity var intent = new Intent(this, typeof(PickActivity)); // Create coordinates to pass List <string> parameters = new List <string>(); String coord = txtCoord.Text; String sLat = ""; String sLon = ""; if (GCStuffs.TryToConvertCoordinates(coord, ref sLat, ref sLon)) { parameters.Add(sLat); parameters.Add(sLon); } else { parameters.Add(""); parameters.Add(""); } String radius = FindViewById <EditText>(Resource.Id.editRadius).Text; if (!String.IsNullOrEmpty(radius)) { parameters.Add(radius); } intent.PutStringArrayListExtra("coordinates", parameters); // Start the activity waiting for a result StartActivityForResult(intent, 10); // 10 for map return; //#endif /* #if (LITE) * Toast.MakeText(this, this.Resources.GetString(Resource.String.OnlyFullMap), ToastLength.Long).Show(); * return; #endif */ }
// 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)); }
// 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 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()); } }
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()); } }
// 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(); } }
public void AfterTextChanged(IEditable s) { // update all the 3 coords formats et_.Text = GCStuffs.ConvertCoordinates(et_.Text); }
// Define the view private void SetMainView() { // Set our view from the "UpdateCoordLayout" layout resource SetContentView(Resource.Layout.UpdateCoordLayout); // Get params if (Intent.Extras != null) { _ids = Intent.Extras.GetStringArrayList("selectionids") ?? new string[0]; } // Check validity of parameter if ((_ids != null) && (_ids.Count != 0)) { // List is valid, we continue } else { // Nothing to do // Execute cancel operation var intent = new Intent(this, typeof(MainActivity)); SetResult(Result.Canceled, intent); Finish(); } // Hide the bloody keyboard by default ? Window.SetSoftInputMode(SoftInput.StateAlwaysHidden); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.Save); button.Click += Save_Click; button = FindViewById <Button>(Resource.Id.BtnQuit); button.Click += Cancel_Click; button = FindViewById <Button>(Resource.Id.btnCoord); button.Click += btnCoord_Click; button = FindViewById <Button>(Resource.Id.PickMap); button.Click += PickMap_Click; // Store edits for coordinates txtCoord = FindViewById <EditText>(Resource.Id.editCoord); lblCoordAllValues = FindViewById <TextView>(Resource.Id.lblCoordAllValues); txtCoord.TextChanged += (sender, e) => { lblCoordAllValues.Text = GCStuffs.ConvertCoordinates(txtCoord.Text); }; // Now we perform time consumming activities // chec GC account ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner); progressDialog.SetMessage(this.Resources.GetString(Resource.String.LblInitInProgress)); progressDialog.SetTitle(this.Resources.GetString(Resource.String.OperationInProgress)); progressDialog.Indeterminate = true; progressDialog.SetCancelable(false); progressDialog.Show(); ThreadPool.QueueUserWorkItem(o => PerformInit(progressDialog)); }
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(); } }
// do the creation job private void CreateNotificationsImpl(ProgressDialog progressDialog, double dlat, double dlon, int distance, String name, List <Tuple <int, string, List <string>, int> > selectedTypes, String email) { try { // we create notifications // No iterate on selected type and create ! String url = "https://www.geocaching.com/notify/edit.aspx"; String post_response = ""; String post_string = ""; int nb = 1; bool error = false; String warning = ""; foreach (var tpl in selectedTypes) { // Is it canceled ? if (_Canceled) { break; // Yes } // Update progress progressDialog.Progress = nb; // Progress message RunOnUiThread(() => progressDialog.SetMessage(this.Resources.GetString(Resource.String.LblCreateInProgress) + " - " + tpl.Item2)); // On demande la page par défaut pour initialiser une nouvelle demande HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url); objRequest.CookieContainer = _gcstuffs._cookieJar; // surtout récupérer le container de cookie qui est maintenant renseigné avec le cookie d'authentification HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream())) { post_response = responseStream.ReadToEnd(); responseStream.Close(); } // On regarde si on a claqué le nombre max warning = GCStuffs.CheckWarningMessage(post_response); if (warning != "") { error = true; break; } // Une mise à jour pour définir le type de cache post_string = GCStuffs.GeneratePostString(post_response, dlat, dlon, distance, name, tpl, email, true); post_response = GCStuffs.GeneratePostRequets(url, post_string, _gcstuffs._cookieJar); // Une mise à jour pour définir le type de notif post_string = GCStuffs.GeneratePostString(post_response, dlat, dlon, distance, name, tpl, email, true); post_response = GCStuffs.GeneratePostRequets(url, post_string, _gcstuffs._cookieJar); // Vérification de la création correcte ! warning = GCStuffs.CheckValidationMessage(post_response); if (warning != "") { error = true; break; } // On décoche le type que l'on vient de poster foreach (var tc in _typecaches) { if (tc.Type == tpl.Item2) { // Found it ! // On le décoche RunOnUiThread(() => tc.Checked = false); } } nb++; } // Kill progressdialog (we are in UI thread already, good) RunOnUiThread(() => progressDialog.Hide()); // All right! if (error) { RunOnUiThread(() => Toast.MakeText(this, warning, ToastLength.Long).Show()); // Don't go to main activity !!! } else if (_Canceled) { RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Canceled), ToastLength.Short).Show()); // Don't go to main activity !!! } else { RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Success), ToastLength.Short).Show()); // Then go back to main activity GoToMainActivity(true); } } catch (Exception ex) { // Kill progressdialog (we are in UI thread already, good) RunOnUiThread(() => progressDialog.Hide()); // Crap RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Error) + "\n" + ex.Message, ToastLength.Long).Show()); } }
// Define the view private void SetMainView() { // Set our view from the "Creation" layout resource SetContentView(Resource.Layout.Creation); // Hide the bloody keyboard by default ? Window.SetSoftInputMode(SoftInput.StateAlwaysHidden); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.Save); button.Click += Save_Click; button = FindViewById <Button>(Resource.Id.BtnQuit); button.Click += Cancel_Click; button = FindViewById <Button>(Resource.Id.btnCoord); button.Click += btnCoord_Click; button = FindViewById <Button>(Resource.Id.PickMap); button.Click += PickMap_Click; // This button is not used anymore ImageButton btnimg = FindViewById <ImageButton>(Resource.Id.UpdateEmails); btnimg.Visibility = ViewStates.Invisible; // If we have no emails, hide the stuff immediately if ((_emails == null) || (_emails.Count == 0)) { // Hide the spinner and associated label Spinner spinner = FindViewById <Spinner>(Resource.Id.spinnerEmail); spinner.Visibility = ViewStates.Invisible; TextView txt = FindViewById <TextView>(Resource.Id.lblEmail); txt.Visibility = ViewStates.Invisible; ImageView img = FindViewById <ImageView>(Resource.Id.imageEmail); img.Visibility = ViewStates.Invisible; } else { PopulateSpinnerWithEmails(_emails.ToList()); } // Adapter _fa = new TypeCacheAdapter(this, new List <TypeCache>()); var gridview = FindViewById <GridView>(Resource.Id.gridview); gridview.Adapter = _fa; gridview.ItemClick += dataview_ItemClick; // Create initial list of supported caches _allowedtypes = new List <Tuple <int, string, List <string>, int> > { #if (FULL) Tuple.Create(2, "Traditional Cache", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$6" }), Resource.Drawable.Tradi), #endif Tuple.Create(3, "Multi-cache", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$6" }), Resource.Drawable.Multi), Tuple.Create(8, "Unknown Cache", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$6" }), Resource.Drawable.Unknown), Tuple.Create(137, "Earthcache", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$6" }), Resource.Drawable.Earth), Tuple.Create(5, "Letterbox Hybrid", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$6" }), Resource.Drawable.Letterbox), Tuple.Create(1858, "Wherigo Cache", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$6" }), Resource.Drawable.Wherigo), Tuple.Create(4, "Virtual Cache", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$6" }), Resource.Drawable.Virtual), Tuple.Create(13, "Cache In Trash Out Event", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$7" }), Resource.Drawable.CITO), Tuple.Create(6, "Event Cache", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$7" }), Resource.Drawable.Event), Tuple.Create(453, "Mega-Event Cache", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$7" }), Resource.Drawable.Mega), Tuple.Create(7005, "Giga-Event Cache", new List <string>(new string[] { "ctl00$ContentBody$LogNotify$cblLogTypeList$7" }), Resource.Drawable.Giga) }; #if (LITE) Toast.MakeText(this, this.Resources.GetString(Resource.String.OnlyFullTypes), ToastLength.Long).Show(); #endif foreach (var tpl in _allowedtypes) { _typecaches.Add(new TypeCache(tpl.Item2, tpl.Item4)); } // Pass these notifications to the adapter _fa.DisplayedTypeCaches = _typecaches; // Notify adapter that notifications changed to trigger refresh _fa.NotifyDataSetChanged(); // Store edits for coordinates txtCoord = FindViewById <EditText>(Resource.Id.editCoord); lblCoordAllValues = FindViewById <TextView>(Resource.Id.lblCoordAllValues); txtCoord.TextChanged += (sender, e) => { lblCoordAllValues.Text = GCStuffs.ConvertCoordinates(txtCoord.Text); }; // Now we perform time consumming activities // chec GC account // retrieve emails from GC.com ThreadPool.QueueUserWorkItem(o => PerformGCActions(null)); }