示例#1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            mWearableActionDrawer = FindViewById <WearableActionDrawerView>(Resource.Id.bottom_action_drawer);
            mWearableActionDrawer.SetOnMenuItemClickListener(this);
            mWearableActionDrawer.PeekOnScrollDownEnabled = true;

            mWearableNavigationDrawer = FindViewById <WearableNavigationDrawerView>(Resource.Id.top_nav_drawer);
            mWearableNavigationDrawer.AddOnItemSelectedListener(this);
            mWearableNavigationDrawer.PeekOnScrollDownEnabled = true;
            mNavDrawerAdapter = new NavDrawerAdapter(this);
            mWearableNavigationDrawer.SetAdapter(mNavDrawerAdapter);

            mBroadcastReceiver = new LocalBroadcastReceiver();
            mBroadcastReceiver.BroadcastReceived += (context, intent) =>
            {
                if (WearableDataListenerService.ACTION_SHOWSTORELISTING.Equals(intent?.Action))
                {
                    var intentAndroid = new Intent(Intent.ActionView)
                                        .AddCategory(Intent.CategoryBrowsable)
                                        .SetData(WearableHelper.PlayStoreURI);

                    RemoteIntent.StartRemoteActivity(this, intentAndroid,
                                                     new ConfirmationResultReceiver(this));
                }
                else if (WearableDataListenerService.ACTION_OPENONPHONE.Equals(intent?.Action))
                {
                    bool success = (bool)intent?.GetBooleanExtra(WearableDataListenerService.EXTRA_SUCCESS, false);

                    new ConfirmationOverlay()
                    .SetType(success ? ConfirmationOverlay.OpenOnPhoneAnimation : ConfirmationOverlay.FailureAnimation)
                    .ShowOn(this);
                }
            };
            var filter = new IntentFilter();

            filter.AddAction(WearableDataListenerService.ACTION_SHOWSTORELISTING);
            filter.AddAction(WearableDataListenerService.ACTION_OPENONPHONE);
            LocalBroadcastManager.GetInstance(this).RegisterReceiver(mBroadcastReceiver, filter);

            // Create your application here
            Fragment fragment = FragmentManager.FindFragmentById(Resource.Id.fragment_container);

            // Check if fragment exists
            if (fragment == null)
            {
                fragment = new WeatherNowFragment();

                // Navigate to WeatherNowFragment
                FragmentManager.BeginTransaction()
                .Replace(Resource.Id.fragment_container, fragment, "home")
                .Commit();
            }
        }
        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();
                };
            }
        }