public LocationSearchFragment() { // Required empty public constructor ClickListener = LocationSearchFragment_clickListener; cts = new CancellationTokenSource(); wm = WeatherData.WeatherManager.GetInstance(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.activity_setup); cts = new CancellationTokenSource(); wm = WeatherData.WeatherManager.GetInstance(); // Set default API to HERE // if a valid API key hasn't been entered yet if (wm.KeyRequired && !Settings.KeyVerified) { Settings.API = WeatherData.WeatherAPI.Here; wm.UpdateAPI(); if (String.IsNullOrWhiteSpace(wm.GetAPIKey())) { // If (internal) key doesn't exist, fallback to Yahoo Settings.API = WeatherData.WeatherAPI.Yahoo; wm.UpdateAPI(); Settings.UsePersonalKey = true; Settings.KeyVerified = false; } else { // If key exists, go ahead Settings.UsePersonalKey = false; Settings.KeyVerified = true; } } // Controls searchButton = FindViewById <FloatingActionButton>(Resource.Id.search_button); searchButton.Click += (sender, e) => { FragmentManager.BeginTransaction() .Replace(Resource.Id.search_fragment_container, new LocationSearchFragment()) .Commit(); mWearableActionDrawer.Controller.CloseDrawer(); }; locationButton = FindViewById <FloatingActionButton>(Resource.Id.location_button); locationButton.Click += async(sender, e) => { await FetchGeoLocation(); }; mWearableActionDrawer = FindViewById <WearableActionDrawerView>(Resource.Id.bottom_action_drawer); mWearableActionDrawer.SetOnMenuItemClickListener(this); mWearableActionDrawer.LockedWhenClosed = true; mWearableActionDrawer.Controller.PeekDrawer(); progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar); progressBar.Visibility = ViewStates.Gone; // Location client if (WearableHelper.IsGooglePlayServicesInstalled && !WearableHelper.HasGPS) { mFusedLocationClient = new FusedLocationProviderClient(this); mLocCallback = new LocationCallback(); mLocCallback.LocationResult += async(sender, e) => { if (e.Result == null) { mLocation = null; } else { mLocation = e.Result.LastLocation; } if (mLocation == null) { EnableControls(true); Toast.MakeText(this, Resource.String.error_retrieve_location, ToastLength.Short).Show(); } else { await FetchGeoLocation(); } await mFusedLocationClient.RemoveLocationUpdatesAsync(mLocCallback); }; mLocCallback.LocationAvailability += async(sender, e) => { await mFusedLocationClient.FlushLocationsAsync(); if (!e.Availability.IsLocationAvailable) { EnableControls(true); Toast.MakeText(this, Resource.String.error_retrieve_location, ToastLength.Short).Show(); } }; } else { mLocListnr = new Droid.Helpers.LocationListener(); mLocListnr.LocationChanged += async(Location location) => { mLocation = location; await FetchGeoLocation(); }; } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Check if this activity was started from adding a new widget if (Intent != null && AppWidgetManager.ActionAppwidgetConfigure.Equals(Intent.Action)) { mAppWidgetId = Intent.GetIntExtra(AppWidgetManager.ExtraAppwidgetId, AppWidgetManager.InvalidAppwidgetId); if (Settings.WeatherLoaded || mAppWidgetId == AppWidgetManager.InvalidAppwidgetId) { // This shouldn't happen, but just in case SetResult(Android.App.Result.Ok); Finish(); // Return if we're finished return; } if (mAppWidgetId != AppWidgetManager.InvalidAppwidgetId) { // Set the result to CANCELED. This will cause the widget host to cancel // out of the widget placement if they press the back button. SetResult(Android.App.Result.Canceled, new Intent().PutExtra(AppWidgetManager.ExtraAppwidgetId, mAppWidgetId)); } } SetContentView(Resource.Layout.activity_setup); mActionModeCallback.CreateActionMode += OnCreateActionMode; mActionModeCallback.DestroyActionMode += OnDestroyActionMode; // Get ActionMode state if (savedInstanceState != null && savedInstanceState.GetBoolean("SearchUI", false)) { inSearchUI = true; // Restart ActionMode mActionMode = StartSupportActionMode(mActionModeCallback); } wm = WeatherData.WeatherManager.GetInstance(); searchViewContainer = FindViewById(Resource.Id.search_bar); gpsFollowButton = FindViewById <Button>(Resource.Id.gps_follow); progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar); progressBar.Visibility = ViewStates.Gone; // NOTE: Bug: Explicitly set tintmode on Lollipop devices if (Build.VERSION.SdkInt == BuildVersionCodes.Lollipop) { progressBar.IndeterminateTintMode = PorterDuff.Mode.SrcIn; } /* Event Listeners */ searchViewContainer.Click += delegate { mActionMode = StartSupportActionMode(mActionModeCallback); }; FindViewById(Resource.Id.search_fragment_container).Click += delegate { ExitSearchUi(); }; gpsFollowButton.Click += async delegate { await FetchGeoLocation(); }; // Location Listener mLocListnr = new LocationListener(); mLocListnr.LocationChanged += async(Location location) => { mLocation = location; await FetchGeoLocation(); }; // Reset focus FindViewById(Resource.Id.activity_setup).RequestFocus(); // Set default API to HERE Settings.API = WeatherData.WeatherAPI.Here; wm.UpdateAPI(); if (String.IsNullOrWhiteSpace(wm.GetAPIKey())) { // If (internal) key doesn't exist, fallback to Yahoo Settings.API = WeatherData.WeatherAPI.Yahoo; wm.UpdateAPI(); Settings.UsePersonalKey = true; Settings.KeyVerified = false; } else { // If key exists, go ahead Settings.UsePersonalKey = false; Settings.KeyVerified = true; } }