Ejemplo n.º 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_sync);

            mCircularProgress = FindViewById <CircularProgressLayout>(Resource.Id.circular_progress);
            mCircularProgress.Indeterminate = true;
            mCircularProgress.Click        += (sender, e) =>
            {
                // User canceled, abort the action
                mCircularProgress.StopTimer();
                SetResult(Result.Canceled);
                Finish();
            };
            mCircularProgress.TimerFinished += (sender, e) =>
            {
                // User didn't cancel, perform the action
                // All data received finish activity
                if (SettingsDataReceived && LocationDataReceived && WeatherDataReceived)
                {
                    SetResult(Result.Ok);
                }
                else
                {
                    SetResult(Result.Canceled);
                }
                Finish();
            };
            mTextView          = FindViewById <TextView>(Resource.Id.message);
            mBroadcastReceiver = new LocalBroadcastReceiver();
            mBroadcastReceiver.BroadcastReceived += BroadcastReceiver_BroadcastReceived;

            mTextView.Text = GetString(Resource.String.message_gettingstatus);

            intentFilter = new IntentFilter();
            intentFilter.AddAction(WearableDataListenerService.ACTION_UPDATECONNECTIONSTATUS);
            intentFilter.AddAction(WearableHelper.IsSetupPath);
            intentFilter.AddAction(WearableHelper.LocationPath);
            intentFilter.AddAction(WearableHelper.SettingsPath);
            intentFilter.AddAction(WearableHelper.WeatherPath);
            intentFilter.AddAction(WearableHelper.ErrorPath);

            StartService(new Intent(this, typeof(WearableDataListenerService))
                         .SetAction(WearableDataListenerService.ACTION_UPDATECONNECTIONSTATUS));
        }
Ejemplo n.º 3
0
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your fragment here
            if (Arguments != null)
            {
                using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(
                           new System.IO.StringReader(Arguments.GetString("data", null))))
                {
                    location = LocationData.FromJson(jsonTextReader);
                }

                if (location != null && wLoader == null)
                {
                    wLoader = new WeatherDataLoader(location, this, this);
                }
            }

            if (WearableHelper.IsGooglePlayServicesInstalled && !WearableHelper.HasGPS)
            {
                mFusedLocationClient         = new FusedLocationProviderClient(Activity);
                mLocCallback                 = new LocationCallback();
                mLocCallback.LocationResult += async(sender, e) =>
                {
                    mLocation = e.Result.LastLocation;

                    if (Settings.FollowGPS && await UpdateLocation())
                    {
                        // Setup loader from updated location
                        wLoader = new WeatherDataLoader(this.location, this, this);

                        await RefreshWeather(false);
                    }

                    await mFusedLocationClient.RemoveLocationUpdatesAsync(mLocCallback);
                };
            }
            else
            {
                mLocListnr = new Droid.Helpers.LocationListener();
                mLocListnr.LocationChanged += async(Android.Locations.Location location) =>
                {
                    if (Settings.FollowGPS && await UpdateLocation())
                    {
                        // Setup loader from updated location
                        wLoader = new WeatherDataLoader(this.location, this, this);

                        await RefreshWeather(false);
                    }
                };
            }

            dataReceiver = new LocalBroadcastReceiver();
            dataReceiver.BroadcastReceived += async(context, intent) =>
            {
                if (WearableHelper.LocationPath.Equals(intent?.Action) ||
                    WearableHelper.WeatherPath.Equals(intent?.Action))
                {
                    if (WearableHelper.WeatherPath.Equals(intent.Action) ||
                        (!loaded && location != null))
                    {
                        if (timer.Enabled)
                        {
                            timer.Stop();
                        }

                        // We got all our data; now load the weather
                        wLoader = new WeatherDataLoader(location, this, this);
                        await wLoader.ForceLoadSavedWeatherData();
                    }

                    if (WearableHelper.LocationPath.Equals(intent.Action))
                    {
                        // We got the location data
                        location = Settings.HomeData;
                        loaded   = false;
                    }
                }
                else if (WearableHelper.ErrorPath.Equals(intent?.Action))
                {
                    // An error occurred; cancel the sync operation
                    await CancelDataSync();
                }
                else if (WearableHelper.IsSetupPath.Equals(intent?.Action))
                {
                    if (Settings.DataSync != WearableDataSync.Off)
                    {
                        bool isDeviceSetup = intent.GetBooleanExtra(WearableDataListenerService.EXTRA_DEVICESETUPSTATUS, false);
                        var  connStatus    = (WearConnectionStatus)intent.GetIntExtra(WearableDataListenerService.EXTRA_CONNECTIONSTATUS, 0);

                        if (isDeviceSetup &&
                            connStatus == WearConnectionStatus.Connected)
                        {
                            // Device is setup and connected; proceed with sync
                            Activity?.StartService(new Intent(Activity, typeof(WearableDataListenerService))
                                                   .SetAction(WearableDataListenerService.ACTION_REQUESTLOCATIONUPDATE));
                            Activity?.StartService(new Intent(Activity, typeof(WearableDataListenerService))
                                                   .SetAction(WearableDataListenerService.ACTION_REQUESTWEATHERUPDATE));

                            ResetTimer();
                        }
                        else
                        {
                            // Device is not connected; cancel sync
                            await CancelDataSync();
                        }
                    }
                }
            };

            loaded = true;
        }