private void UpdateSettings(DataMap dataMap) { if (dataMap != null && !dataMap.IsEmpty) { var API = dataMap.GetString("API", String.Empty); var API_KEY = dataMap.GetString("API_KEY", String.Empty); var KeyVerified = dataMap.GetBoolean("KeyVerified", false); if (!String.IsNullOrWhiteSpace(API)) { Settings.API = API; if (WeatherData.WeatherManager.IsKeyRequired(API)) { Settings.API_KEY = API_KEY; Settings.KeyVerified = KeyVerified; } else { Settings.API_KEY = String.Empty; Settings.KeyVerified = false; } } Settings.FollowGPS = dataMap.GetBoolean("FollowGPS", false); // Send callback to receiver LocalBroadcastManager.GetInstance(this).SendBroadcast( new Intent(WearableHelper.SettingsPath)); } }
public static T Get <T> (this DataMap dataMap, string propertyName, T defaultValue) { var key = propertyName + "Key"; if (!dataMap.ContainsKey(key)) { return(defaultValue); } else { var t = typeof(T); if (t == typeof(bool)) { return((T)(object)dataMap.GetBoolean(key)); } else if (typeof(T) == typeof(string)) { return((T)(object)dataMap.GetString(key)); } else if (t == typeof(Guid)) { var s = dataMap.GetString(key); return((T)(object)Guid.Parse(s)); } else if (t == typeof(DateTime)) { var s = dataMap.GetString(key); DateTime dt = new DateTime(); DateTime.TryParse(s, out dt); return((T)(object)dt); } else { throw new NotSupportedException(typeof(T).Name); } } }
/// <summary> /// Puts a local notification to show calendar card /// </summary> /// <param name="dataItem">Data item.</param> private void UpdateNotificationForDataItem(IDataItem dataItem) { if (Log.IsLoggable(Constants.TAG, LogPriority.Verbose)) { Log.Verbose(Constants.TAG, "Updating notification for IDataItem"); } DataMapItem mapDataItem = DataMapItem.FromDataItem(dataItem); DataMap data = mapDataItem.DataMap; String description = data.GetString(Constants.DESCRIPTION); if (TextUtils.IsEmpty(description)) { description = ""; } else { // Add a space between the description and the time of the event description += " "; } String contentText; if (data.GetBoolean(Constants.ALL_DAY)) { contentText = GetString(Resource.String.desc_all_day, description); } else { String startTime = DateFormat.GetTimeFormat(this).Format(new Date(data.GetLong(Constants.BEGIN))); String endTime = DateFormat.GetTimeFormat(this).Format(new Date(data.GetLong(Constants.END))); contentText = GetString(Resource.String.desc_time_period, description, startTime, endTime); } Intent deleteOperation = new Intent(this, typeof(DeleteService)); // Use a unique identifier for the delete action. String deleteAction = "action_delete" + dataItem.Uri.ToString() + sNotificationId; deleteOperation.SetAction(deleteAction); deleteOperation.SetData(dataItem.Uri); PendingIntent deleteIntent = PendingIntent.GetService(this, 0, deleteOperation, PendingIntentFlags.OneShot); PendingIntent silentDeleteIntent = PendingIntent.GetService(this, 1, deleteOperation.PutExtra(Constants.EXTRA_SILENT, true), PendingIntentFlags.OneShot); Notification.Builder notificationBuilder = new Notification.Builder(this) .SetContentTitle(data.GetString(Constants.TITLE)) .SetContentText(contentText) .SetSmallIcon(Resource.Drawable.ic_launcher) .AddAction(Resource.Drawable.ic_menu_delete, GetText(Resource.String.delete), deleteIntent) .SetDeleteIntent(silentDeleteIntent) .SetLocalOnly(true) .SetPriority((int)NotificationPriority.Min); // Set the event owner's profile picture as the notification background Asset asset = data.GetAsset(Constants.PROFILE_PIC); if (asset != null) { if (mGoogleApiClient.IsConnected) { IDataApiGetFdForAssetResult assetFdResult = WearableClass.DataApi.GetFdForAsset(mGoogleApiClient, asset).Await().JavaCast <IDataApiGetFdForAssetResult>(); if (assetFdResult.Status.IsSuccess) { Bitmap profilePic = BitmapFactory.DecodeStream(assetFdResult.InputStream); notificationBuilder.Extend(new Notification.WearableExtender().SetBackground(profilePic)); } else if (Log.IsLoggable(Constants.TAG, LogPriority.Debug)) { Log.Debug(Constants.TAG, "asset fetch failed with StatusCode: " + assetFdResult.Status.StatusCode); } } else { Log.Error(Constants.TAG, "Failed to set notification background - Client disconnected from Google Play Services"); } Notification card = notificationBuilder.Build(); (GetSystemService(Context.NotificationService).JavaCast <NotificationManager>()).Notify(sNotificationId, card); sNotificationIdByDataItemUri.Add(dataItem.Uri, sNotificationId++); } }