private void RegisterPref_PreferenceClick(object sender, Preference.PreferenceClickEventArgs e)
            {
                var intentAndroid = new Intent(e.Preference.Intent)
                                    .AddCategory(Intent.CategoryBrowsable);

                RemoteIntent.StartRemoteActivity(Activity, intentAndroid,
                                                 new ConfirmationResultReceiver(Activity));
            }
            private void ConnStatusPref_PreferenceClick(object sender, Preference.PreferenceClickEventArgs e)
            {
                var intentAndroid = new Intent(Intent.ActionView)
                                    .AddCategory(Intent.CategoryBrowsable)
                                    .SetData(WearableHelper.PlayStoreURI);

                RemoteIntent.StartRemoteActivity(Activity, intentAndroid,
                                                 new ConfirmationResultReceiver(Activity));
            }
예제 #3
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();
            }
        }
            public override bool OnPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
            {
                if (preference != null && preference.Intent != null)
                {
                    RemoteIntent.StartRemoteActivity(Activity, preference.Intent
                                                     .SetAction(Intent.ActionView)
                                                     .AddCategory(Intent.CategoryBrowsable),
                                                     null);

                    // Show open on phone animation
                    new Android.Support.Wearable.Views.ConfirmationOverlay()
                    .SetType(Android.Support.Wearable.Views.ConfirmationOverlay.OpenOnPhoneAnimation)
                    .SetMessage(Activity.GetString(Resource.String.message_openedonphone))
                    .ShowAbove(View);

                    return(true);
                }

                return(base.OnPreferenceTreeClick(preferenceScreen, preference));
            }
        private void BroadcastReceiver_BroadcastReceived(Context context, Intent intent)
        {
            if (WearableDataListenerService.ACTION_UPDATECONNECTIONSTATUS.Equals(intent?.Action))
            {
                var connStatus = (WearConnectionStatus)intent.GetIntExtra(WearableDataListenerService.EXTRA_CONNECTIONSTATUS, 0);
                switch (connStatus)
                {
                case WearConnectionStatus.Disconnected:
                    mTextView.Text = GetString(Resource.String.status_disconnected);
                    ErrorProgress();
                    break;

                case WearConnectionStatus.Connecting:
                    mTextView.Text = GetString(Resource.String.status_connecting);
                    ResetTimer();
                    break;

                case WearConnectionStatus.AppNotInstalled:
                    mTextView.Text = GetString(Resource.String.error_notinstalled);
                    ResetTimer();

                    // Open store on remote device
                    var intentAndroid = new Intent(Intent.ActionView)
                                        .AddCategory(Intent.CategoryBrowsable)
                                        .SetData(WearableHelper.PlayStoreURI);

                    RemoteIntent.StartRemoteActivity(this, intentAndroid,
                                                     new ConfirmationResultReceiver(this));

                    ErrorProgress();
                    break;

                case WearConnectionStatus.Connected:
                    mTextView.Text = GetString(Resource.String.status_connected);
                    ResetTimer();
                    // Continue operation
                    StartService(new Intent(this, typeof(WearableDataListenerService))
                                 .SetAction(WearableDataListenerService.ACTION_REQUESTSETUPSTATUS));
                    break;
                }
            }
            else if (WearableHelper.ErrorPath.Equals(intent?.Action))
            {
                mTextView.Text = GetString(Resource.String.error_syncing);
                ErrorProgress();
            }
            else if (WearableHelper.IsSetupPath.Equals(intent?.Action))
            {
                bool isDeviceSetup = intent.GetBooleanExtra(WearableDataListenerService.EXTRA_DEVICESETUPSTATUS, false);

                Start(isDeviceSetup);
            }
            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);

                if (!success)
                {
                    mTextView.Text = GetString(Resource.String.error_syncing);
                    ErrorProgress();
                }
            }
            else if (WearableHelper.SettingsPath.Equals(intent?.Action))
            {
                mTextView.Text       = GetString(Resource.String.message_settingsretrieved);
                SettingsDataReceived = true;

                if (SettingsDataReceived && LocationDataReceived && WeatherDataReceived)
                {
                    SuccessProgress();
                }
            }
            else if (WearableHelper.LocationPath.Equals(intent?.Action))
            {
                mTextView.Text       = GetString(Resource.String.message_locationretrieved);
                LocationDataReceived = true;

                if (SettingsDataReceived && LocationDataReceived && WeatherDataReceived)
                {
                    SuccessProgress();
                }
            }
            else if (WearableHelper.WeatherPath.Equals(intent?.Action))
            {
                mTextView.Text      = GetString(Resource.String.message_weatherretrieved);
                WeatherDataReceived = true;

                if (SettingsDataReceived && LocationDataReceived && WeatherDataReceived)
                {
                    SuccessProgress();
                }
            }
        }