public override async void OnMessageReceived(IMessageEvent messageEvent) { await _initTask.Value; switch (messageEvent.Path) { case ListCapability: await ListAuthenticators(messageEvent.SourceNodeId); break; case GetCodeCapability: { var position = Int32.Parse(Encoding.UTF8.GetString(messageEvent.GetData())); await GetCode(position, messageEvent.SourceNodeId); break; } case ListCustomIconsCapability: await ListCustomIcons(messageEvent.SourceNodeId); break; case GetCustomIconCapability: { var id = Encoding.UTF8.GetString(messageEvent.GetData()); await GetCustomIcon(id, messageEvent.SourceNodeId); break; } } }
public async void OnMessageReceived(IMessageEvent messageEvent) { switch (messageEvent.Path) { case ListCapability: OnAuthenticatorListReceived(messageEvent.GetData()); break; case ListCustomIconsCapability: await OnCustomIconListReceived(messageEvent.GetData()); break; case GetCustomIconCapability: await OnCustomIconReceived(messageEvent.GetData()); break; case RefreshCapability: await Refresh(); break; } Interlocked.Add(ref _responsesReceived, 1); if (_responsesReceived == _responsesRequired) { OnReady(); } }
public void OnMessageReceived(IMessageEvent messageEvent) { switch (messageEvent.Path) { case WearGetCodeCapability: { // Invalid position, return to list if (messageEvent.GetData().Length == 0) { Finish(); return; } var json = Encoding.UTF8.GetString(messageEvent.GetData()); var update = JsonConvert.DeserializeObject <WearAuthenticatorCodeResponse>(json); _timeRenew = update.TimeRenew; _codeTextView.Text = FormatCode(update.Code, _digits); UpdateProgressBar(); break; } case RefreshCapability: Finish(); // We don't know what changed, just go back break; } }
public async void OnMessageReceived(IMessageEvent messageEvent) { await _requestLock.WaitAsync(); _requestLock.Release(); switch (messageEvent.Path) { case ListAuthenticatorsCapability: await OnAuthenticatorListReceived(messageEvent.GetData()); break; case ListCategoriesCapability: await OnCategoriesListReceived(messageEvent.GetData()); break; case ListCustomIconsCapability: await OnCustomIconListReceived(messageEvent.GetData()); break; case GetCustomIconCapability: await OnCustomIconReceived(messageEvent.GetData()); break; case GetPreferencesCapability: OnPreferencesReceived(messageEvent.GetData()); break; case RefreshCapability: await OnRefreshRecieved(); break; } Interlocked.Increment(ref _responsesReceived); var received = Interlocked.CompareExchange(ref _responsesReceived, 0, 0); var required = Interlocked.CompareExchange(ref _responsesRequired, 0, 0); if (received == required) { _responseLock.Release(); } }
public override void OnMessageReceived(IMessageEvent messageEvent) { if (!messageEvent.Path.Equals (DigitalWatchFaceUtil.PathWithFeature)) { return; } var rawData = messageEvent.GetData (); // It's allowed that the message carries only some of the keys used in the config DataItem // and skips the ones that we don't want to change. var configKeysToOverwrite = DataMap.FromByteArray (rawData); if (Log.IsLoggable (Tag, LogPriority.Debug)) { Log.Debug (Tag, "Received watch face config message: " + configKeysToOverwrite); } if (googleApiClient == null) { googleApiClient = new GoogleApiClientBuilder (this) .AddConnectionCallbacks (this) .AddOnConnectionFailedListener (this) .AddApi (WearableClass.Api) .Build (); } if (!googleApiClient.IsConnected) { var connectionResult = googleApiClient.BlockingConnect (30, TimeUnit.Seconds); if (!connectionResult.IsSuccess) { Log.Error (Tag, "Failed to connect to GoogleApiClient."); return; } } DigitalWatchFaceUtil.OverwriteKeysInConfigDataMap (googleApiClient, configKeysToOverwrite); }
// Implementing IMessageApiMessageListener interface // On message received we want invoke event public void OnMessageReceived(IMessageEvent messageEvent) { var message = Encoding.Default.GetString(messageEvent.GetData()); Log.Info("Spidey", "Communicator: Message received \"" + message + "\""); MessageReceived(message); }
public void OnMessageReceived(IMessageEvent message) { if (!message.Path.EndsWith("/Answer")) { return; } IList <Station> stations = null; GeoPoint currentLocation; using (var content = new System.IO.MemoryStream(message.GetData())) { currentLocation = GeoUtils.ParseFromStream(content); stations = StationUtils.ParseStations(content); } if (stations != null) { handler.Post(() => { var adapter = new StationGridAdapter(FragmentManager, stations, currentLocation, ActionStatus); pager.Adapter = adapter; pager.OffscreenPageCount = 2; label.Visibility = ViewStates.Gone; pager.Visibility = ViewStates.Visible; }); } }
public override async void OnMessageReceived(IMessageEvent messageEvent) { if (_connection == null || _source == null) { await Init(); } await _source.Update(); switch (messageEvent.Path) { case ListCapability: await ListAuthenticators(messageEvent.SourceNodeId); break; case GetCodeCapability: { var position = Int32.Parse(Encoding.UTF8.GetString(messageEvent.GetData())); await GetCode(position, messageEvent.SourceNodeId); break; } } }
public void OnMessageReceived(IMessageEvent messageEvent) { var message = Encoding.Default.GetString(messageEvent.GetData()); Console.WriteLine(string.Format("Communicator: Message received \"{0}\"", message)); MessageReceived(message); }
public void OnMessageReceived(IMessageEvent messageEvent) { switch (messageEvent.Path) { case WearGetCodeCapability: { // Invalid position, return to list if (messageEvent.GetData().Length == 0) { Finish(); return; } var json = Encoding.UTF8.GetString(messageEvent.GetData()); var update = JsonConvert.DeserializeObject <WearAuthenticatorCodeResponse>(json); _timeRenew = update.TimeRenew; var code = update.Code; if (code == null) { code = "".PadRight(_digits, '-'); } var spacesInserted = 0; var groupSize = Math.Min(MaxCodeGroupSize, _digits / 2); for (var i = 0; i < _digits; ++i) { if (i % groupSize == 0 && i > 0) { code = code.Insert(i + spacesInserted, " "); spacesInserted++; } } _codeTextView.Text = code; UpdateProgressBar(); break; } case RefreshCapability: Finish(); // We don't know what changed, just go back break; } }
public override void OnMessageReceived(IMessageEvent messageEvent) { if (Log.IsLoggable(Constants.TAG, LogPriority.Debug)) { Log.Debug(Constants.TAG, "OnMessageReceived: " + messageEvent.Path + " " + messageEvent.GetData() + " for " + PackageName); } }
public void OnMessageReceived(IMessageEvent e) { if (MessageTag.Equals(e.Path)) { var month = System.Text.Encoding.UTF8.GetString(e.GetData()); Log.Debug(Tag, month); SendResponseAsync(int.Parse(month)); } }
public async void OnMessageReceived(IMessageEvent messageEvent) { switch (messageEvent.Path) { case ListAuthenticatorsCapability: await OnAuthenticatorListReceived(messageEvent.GetData()); break; case ListCategoriesCapability: await OnCategoriesListReceived(messageEvent.GetData()); break; case ListCustomIconsCapability: await OnCustomIconListReceived(messageEvent.GetData()); break; case GetCustomIconCapability: await OnCustomIconReceived(messageEvent.GetData()); break; case RefreshCapability: await Refresh(); break; } Interlocked.Add(ref _responsesReceived, 1); var received = Interlocked.CompareExchange(ref _responsesReceived, 0, 0); var required = Interlocked.CompareExchange(ref _responsesRequired, 0, 0); if (received == required) { RunOnUiThread(UpdateViewState); } }
private async Task HandleMessage(IMessageEvent message) { try { Log.Info("WearIntegration", "Received Message"); googleApiClient.Connect(); if (!googleApiClient.IsConnected) { Log.Info("WearIntegration", "Connecting"); } var authManager = ServiceContainer.Resolve <AuthManager> (); if (!authManager.IsAuthenticated) { Log.Info("WearIntegration", "Is not authenticated"); NotifyNotLoggedIn(); return; } var path = message.Path; try { if (path == Common.StartStopTimeEntryPath) { await WearDataProvider.StartStopTimeEntry(BaseContext); await UpdateSharedTimeEntryList(); } else if (path == Common.ContinueTimeEntryPath) { var guid = Guid.Parse(Common.GetString(message.GetData())); await StartEntry(guid); await UpdateSharedTimeEntryList(); } else if (path == Common.RequestSyncPath) { Log.Info("WearIntegration", "Sending sync data!"); await UpdateSharedTimeEntryList(); } else if (path == Common.OpenHandheldPath) { StartMainActivity(); } } catch (Exception e) { Log.Error("WearIntegration", e.ToString()); } } catch (Exception e) { Log.Error("WearIntegration", e.ToString()); } }
public override void OnMessageReceived(IMessageEvent messageEvent) { if (messageEvent.Path.Equals(START_ACTIVITY_PATH)) { string message = messageEvent.GetData().GetString(); if (string.IsNullOrWhiteSpace(message)) { var launchPage = new Intent(this, typeof(LaunchedFromHandheldActivity)); launchPage.AddFlags(ActivityFlags.NewTask); StartActivity(launchPage); } else { // Start a new activity var launchPage = new Intent(this, typeof(LaunchedFromHandheldWithDataActivity)); launchPage.PutExtra("WearMessage", message); launchPage.AddFlags(ActivityFlags.NewTask); StartActivity(launchPage); } } else if (messageEvent.Path.Equals(START_ACTIVITY_PATH_IN_MAIN_ACTIVITY)) { string message = messageEvent.GetData().GetString(); // Broadcast message to wearable activity for display var messageIntent = new Intent(); messageIntent.SetAction(Intent.ActionSend); messageIntent.PutExtra("message", message); LocalBroadcastManager.GetInstance(this).SendBroadcast(messageIntent); } else { base.OnMessageReceived(messageEvent); } }
public async void OnMessageReceived(IMessageEvent messageEvent) { switch (messageEvent.Path) { case ListCapability: { var json = Encoding.UTF8.GetString(messageEvent.GetData()); _authenticatorListAdapter.Items = JsonConvert.DeserializeObject <List <WearAuthenticatorResponse> >(json); if (_authenticatorListAdapter.Items.Count == 0) { AnimUtil.FadeInView(_emptyLayout, 200); } else { AnimUtil.FadeOutView(_emptyLayout, 200); } _authenticatorListAdapter.NotifyDataSetChanged(); var anim = new AlphaAnimation(0f, 1f) { Duration = 200 }; anim.AnimationEnd += (sender, e) => { _authList.Visibility = ViewStates.Visible; _authList.RequestFocus(); }; _authList.StartAnimation(anim); _loadingLayout.Visibility = ViewStates.Invisible; break; } case RefreshCapability: await Refresh(); break; } }
public override void OnMessageReceived(IMessageEvent messageEvent) { // base.OnMessageReceived(p0); if (messageEvent.Path == MessageValue.PathStart) { var bcore = Encoding.UTF8.GetString(messageEvent.GetData()); Android.Util.Log.Debug("MsgListenerService", "Recv MsgAPI:" + bcore); var intent = new Intent(this, typeof(ControllerService)); intent.PutExtra(ControllerService.ExtraKeyBcore, bcore); StartService(intent); } else if (messageEvent.Path == MessageValue.PathStop) { var intent = new Intent(ControllerService.ActionKeyStop); SendBroadcast(intent); } }
public override void OnMessageReceived(IMessageEvent messageEvent) { base.OnMessageReceived(messageEvent); if (messageEvent.Path.Equals(WearableHelper.ErrorPath)) { LocalBroadcastManager.GetInstance(this) .SendBroadcast(new Intent(WearableHelper.ErrorPath)); } else if (messageEvent.Path.Equals(WearableHelper.IsSetupPath)) { var data = messageEvent.GetData(); bool isDeviceSetup = BitConverter.ToBoolean(data, 0); LocalBroadcastManager.GetInstance(this) .SendBroadcast(new Intent(WearableHelper.IsSetupPath) .PutExtra(EXTRA_DEVICESETUPSTATUS, isDeviceSetup) .PutExtra(EXTRA_CONNECTIONSTATUS, (int)mConnectionStatus)); } }
public override async void OnMessageReceived(IMessageEvent messageEvent) { await _initTask.Value; switch (messageEvent.Path) { case GetSyncBundleCapability: await GetSyncBundle(messageEvent.SourceNodeId); break; case GetCustomIconCapability: { var id = Encoding.UTF8.GetString(messageEvent.GetData()); await GetCustomIcon(id, messageEvent.SourceNodeId); break; } } }
public override void OnMessageReceived(IMessageEvent messageEvent) { if (messageEvent.Path.Equals(WearableHelper.StartActivityPath)) { Intent startIntent = new Intent(this, typeof(LaunchActivity)) .SetFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask | ActivityFlags.ClearTask); StartActivity(startIntent); } else if (messageEvent.Path.Equals(WearableHelper.SettingsPath)) { Task.Run(async() => await CreateSettingsDataRequest(true)); } else if (messageEvent.Path.Equals(WearableHelper.LocationPath)) { Task.Run(async() => await CreateLocationDataRequest(true)); } else if (messageEvent.Path.Equals(WearableHelper.WeatherPath)) { var data = messageEvent.GetData(); bool force = false; if (data != null && data.Length > 0) { force = BitConverter.ToBoolean(data, 0); } if (!force) { Task.Run(async() => await CreateWeatherDataRequest(true)); } else { // Refresh weather data WeatherWidgetService.EnqueueWork(this, new Intent(this, typeof(WeatherWidgetService)) .SetAction(WeatherWidgetService.ACTION_UPDATEWEATHER)); } } else if (messageEvent.Path.Equals(WearableHelper.IsSetupPath)) { SendSetupStatus(messageEvent.SourceNodeId); } }
public void OnMessageReceived (IMessageEvent message) { if (!message.Path.EndsWith ("/Answer")) return; IList<Station> stations = null; GeoPoint currentLocation; using (var content = new System.IO.MemoryStream (message.GetData ())) { currentLocation = GeoUtils.ParseFromStream (content); stations = StationUtils.ParseStations (content); } if (stations != null) { handler.Post (() => { var adapter = new StationGridAdapter (FragmentManager, stations, currentLocation, ActionStatus); pager.Adapter = adapter; pager.OffscreenPageCount = 2; label.Visibility = ViewStates.Gone; pager.Visibility = ViewStates.Visible; }); } }
// Implementing IMessageApiMessageListener interface // On message received we want invoke event public void OnMessageReceived(IMessageEvent messageEvent) { var message = System.Text.Encoding.Default.GetString(messageEvent.GetData()); Log.Info("my_log", "Communicator: Message received \"" + message + "\""); EventViewModel eventModel = new EventViewModel(); if (message.Contains("option") && message.ToString().ToCharArray().Length > ("option").Length) { Device.BeginInvokeOnMainThread(async() => { await eventModel.setOption(message); }); } if (message.Contains("option")) { Device.BeginInvokeOnMainThread(async() => { await eventModel.TriggerFeatureAsync(); }); } MessageReceived(message); }
public void OnMessageReceived(IMessageEvent e) { if (MessageTag.Equals(e.Path)) { var msg = System.Text.Encoding.UTF8.GetString(e.GetData()); Log.Debug(Tag, msg); var ringo = msg.Split(':'); var colorName = System.Drawing.Color.FromName(ringo[2]); var colorRgb = Android.Graphics.Color.Rgb(colorName.R, colorName.G, colorName.B); this.RunOnUiThread(() => { var layout = FindViewById <LinearLayout>(Resource.Id.linear); layout.SetBackgroundColor(colorRgb); var status = FindViewById <TextView>(Resource.Id.status); status.Text = string.Format("{0}月 - {1}", ringo[0], ringo[1]); status.SetBackgroundColor(colorRgb); status.SetTextColor(Color.Black); }); } }
public override void OnMessageReceived(IMessageEvent messageEvent) { if (!messageEvent.Path.Equals(DigitalWatchFaceUtil.PathWithFeature)) { return; } var rawData = messageEvent.GetData(); // It's allowed that the message carries only some of the keys used in the config DataItem // and skips the ones that we don't want to change. var configKeysToOverwrite = DataMap.FromByteArray(rawData); if (Log.IsLoggable(Tag, LogPriority.Debug)) { Log.Debug(Tag, "Received watch face config message: " + configKeysToOverwrite); } if (googleApiClient == null) { googleApiClient = new GoogleApiClientBuilder(this) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .AddApi(WearableClass.Api) .Build(); } if (!googleApiClient.IsConnected) { var connectionResult = googleApiClient.BlockingConnect(30, TimeUnit.Seconds); if (!connectionResult.IsSuccess) { Log.Error(Tag, "Failed to connect to GoogleApiClient."); return; } } DigitalWatchFaceUtil.OverwriteKeysInConfigDataMap(googleApiClient, configKeysToOverwrite); }
public override void OnMessageReceived(IMessageEvent messageEvent) { string path = messageEvent.Path; if (path.Equals(Constants.QUIZ_EXITED_PATH)) { ((NotificationManager)GetSystemService(NotificationService)).CancelAll(); } if (path.Equals(Constants.QUIZ_ENDED_PATH) || path.Equals(Constants.QUIZ_EXITED_PATH)) { var dataMap = DataMap.FromByteArray(messageEvent.GetData()); int numCorrect = dataMap.GetInt(Constants.NUM_CORRECT); int numIncorrect = dataMap.GetInt(Constants.NUM_INCORRECT); int numSkipped = dataMap.GetInt(Constants.NUM_SKIPPED); var builder = new Notification.Builder(this) .SetContentTitle(GetString(Resource.String.quiz_report)) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetLocalOnly(true); var quizReportText = new SpannableStringBuilder(); AppendColored(quizReportText, numCorrect.ToString(), Resource.Color.dark_green); quizReportText.Append(" " + GetString(Resource.String.correct) + "\n"); AppendColored(quizReportText, numIncorrect.ToString(), Resource.Color.dark_red); quizReportText.Append(" " + GetString(Resource.String.incorrect) + "\n"); AppendColored(quizReportText, numSkipped.ToString(), Resource.Color.dark_yellow); quizReportText.Append(" " + GetString(Resource.String.skipped) + "\n"); builder.SetContentText(quizReportText); if (!path.Equals(Constants.QUIZ_EXITED_PATH)) { builder.AddAction(Resource.Drawable.ic_launcher, GetString(Resource.String.reset_quiz), GetResetQuizPendingIntent()); } ((NotificationManager)GetSystemService(NotificationService)) .Notify(QUIZ_REPORT_NOTIF_ID, builder.Build()); } }
public override void OnMessageReceived (IMessageEvent messageEvent) { string path = messageEvent.Path; if (path.Equals (Constants.QUIZ_EXITED_PATH)) { ((NotificationManager)GetSystemService (NotificationService)).CancelAll (); } if (path.Equals (Constants.QUIZ_ENDED_PATH) || path.Equals (Constants.QUIZ_EXITED_PATH)) { var dataMap = DataMap.FromByteArray (messageEvent.GetData ()); int numCorrect = dataMap.GetInt (Constants.NUM_CORRECT); int numIncorrect = dataMap.GetInt (Constants.NUM_INCORRECT); int numSkipped = dataMap.GetInt (Constants.NUM_SKIPPED); var builder = new Notification.Builder (this) .SetContentTitle (GetString (Resource.String.quiz_report)) .SetSmallIcon (Resource.Drawable.ic_launcher) .SetLocalOnly (true); var quizReportText = new SpannableStringBuilder (); AppendColored (quizReportText, numCorrect.ToString (), Resource.Color.dark_green); quizReportText.Append (" " + GetString (Resource.String.correct) + "\n"); AppendColored (quizReportText, numIncorrect.ToString (), Resource.Color.dark_red); quizReportText.Append (" " + GetString (Resource.String.incorrect) + "\n"); AppendColored (quizReportText, numSkipped.ToString (), Resource.Color.dark_yellow); quizReportText.Append (" " + GetString (Resource.String.skipped) + "\n"); builder.SetContentText (quizReportText); if (!path.Equals (Constants.QUIZ_EXITED_PATH)) { builder.AddAction (Resource.Drawable.ic_launcher, GetString (Resource.String.reset_quiz), GetResetQuizPendingIntent ()); } ((NotificationManager)GetSystemService (NotificationService)) .Notify (QUIZ_REPORT_NOTIF_ID, builder.Build ()); } }
private async Task HandleMessage (IMessageEvent message) { try { Log.Info ("WearIntegration", "Received Message"); googleApiClient.Connect(); if (!googleApiClient.IsConnected) { Log.Info ("WearIntegration", "Connecting"); } var authManager = ServiceContainer.Resolve<AuthManager> (); if (!authManager.IsAuthenticated) { Log.Info ("WearIntegration", "Is not authenticated"); NotifyNotLoggedIn(); return; } var path = message.Path; try { if (path == Common.StartStopTimeEntryPath) { await WearDataProvider.StartStopTimeEntry (BaseContext); await UpdateSharedTimeEntryList (); } else if (path == Common.ContinueTimeEntryPath) { var guid = Guid.Parse (Common.GetString (message.GetData())); await StartEntry (guid); await UpdateSharedTimeEntryList (); } else if (path == Common.RequestSyncPath) { Log.Info ("WearIntegration", "Sending sync data!"); await UpdateSharedTimeEntryList (); } else if (path == Common.OpenHandheldPath) { StartMainActivity (); } } catch (Exception e) { Log.Error ("WearIntegration", e.ToString ()); } } catch (Exception e) { Log.Error ("WearIntegration", e.ToString ()); } }
public override void OnMessageReceived (IMessageEvent messageEvent) { if (Log.IsLoggable (Constants.TAG, LogPriority.Debug)) { Log.Debug (Constants.TAG, "OnMessageReceived: " + messageEvent.Path + " " + messageEvent.GetData () + " for " + PackageName); } }