public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.fragment_home, container, false); channelIdUpdateReceiver = new ChannelIdBroadcastReceiver((Intent) => { RefreshChannelId(); }); channelId = (TextView)view.FindViewById(Resource.Id.channel_id); shareButton = (Button)view.FindViewById(Resource.Id.share_button); copyButton = (Button)view.FindViewById(Resource.Id.copy_button); copyButton.Click += (sender, e) => { if (!string.IsNullOrEmpty(channelId.Text)) { ActionRunRequest.CreateRequest(ClipboardAction.DefaultRegistryName) .SetValue(UAirship.Shared().PushManager.ChannelId) .Run((args, result) => { Toast.MakeText(Context, GetString(Resource.String.toast_channel_clipboard), ToastLength.Short).Show(); }); } }; shareButton.Click += (sender, e) => { if (!string.IsNullOrEmpty(channelId.Text)) { ActionRunRequest.CreateRequest(ShareAction.DefaultRegistryName) .SetValue(UAirship.Shared().PushManager.ChannelId) .Run(); } }; return(view); }
private void Init() { UAirship.Shared().Channel.AddChannelListener(this); //Adding Inbox updated listener MessageCenterClass.Shared().Inbox.AddListener(this); }
protected override void OnResume() { base.OnResume(); if (PlayServicesUtils.IsGooglePlayStoreAvailable(this)) { PlayServicesUtils.HandleAnyPlayServicesError(this); } if (RichPushInbox.ViewInboxIntentAction == Intent.Action) { v4.App.Fragment fragment = Navigate(Resource.Id.nav_message_center); if (Intent.Data != null && Intent.Data.Scheme.ToLower() == RichPushInbox.MessageDataScheme) { string messageId = Intent.Data.SchemeSpecificPart; if (fragment != null && fragment is MessageCenterFragment) { ((MessageCenterFragment)fragment).SetMessageID(messageId); } } Intent.SetAction(null); } UAirship.Shared().Inbox.AddListener(inboxListener); ShowMessageCenterIndicator(); UpdateUnreadCount(); }
private void SetTags(List <string> addTags) { currentTags.Clear(); currentTags.UnionWith(addTags); UAirship.Shared().PushManager.Tags = currentTags; }
protected void OnStart() { base.OnStart(); // Activity instrumentation for analytic tracking UAirship.Shared().Analytics.ActivityStarted(this); }
private void ShowMessageCenterIndicator() { IList <RichPushMessage> unreadMessages = UAirship.Shared().Inbox.UnreadMessages; if (unreadMessages.Count == 0 || messageCenterLastSentDate >= unreadMessages[0].SentDateMS) { return; } messageCenterLastSentDate = unreadMessages[0].SentDateMS; if (messageCenterSnackbar != null && messageCenterSnackbar.IsShownOrQueued) { return; } if (currentNavPosition == Resource.Id.nav_message_center) { return; } String text = Resources.GetQuantityString(Resource.Plurals.mc_indicator_text, unreadMessages.Count, unreadMessages.Count); messageCenterSnackbar = Snackbar.Make(FindViewById(Resource.Id.coordinatorLayout), text, MessageCenterIndicatorDurationMs) .SetActionTextColor(ContextCompat.GetColor(this, Resource.Color.color_accent)) .SetAction(Resource.String.view, (View v) => { messageCenterSnackbar.Dismiss(); UAirship.Shared().Inbox.StartInboxActivity(); }); messageCenterSnackbar.Show(); }
/** * Dismisses the inbox style notification if it exists */ public static void DismissInboxNotification() { NotificationManager manager = (NotificationManager)UAirship.Shared(). ApplicationContext.GetSystemService(Context.NotificationService); manager.Cancel(INBOX_NOTIFICATION_ID); }
public Push.TagGroupsEditor EditChannelTagGroups() { return(new Push.TagGroupsEditor((List <Push.TagGroupsEditor.TagOperation> payload) => { var editor = UAirship.Shared().PushManager.EditTagGroups(); TagGroupHelper(payload, editor); editor.Apply(); })); }
public Channel.TagGroupsEditor EditChannelTagGroups() { return(new Channel.TagGroupsEditor((List <Channel.TagGroupsEditor.TagOperation> payload) => { var editor = UAirship.Shared().Channel.EditTagGroups(); TagGroupHelper(payload, editor); editor.Apply(); })); }
public AttributeEditor EditNamedUserAttributes() { return(new AttributeEditor((List <AttributeEditor.IAttributeOperation> operations) => { var editor = UAirship.Shared().NamedUser.EditAttributes(); ApplyAttributesOperations(editor, operations); editor.Apply(); })); }
protected void OnStop() { base.OnStop(); // Activity instrumentation for analytic tracking UAirship.Shared().Analytics.ActivityStopped(this); // Apply any changed UA preferences from the preference screen preferenceAdapter.ApplyUrbanAirshipPreferences(); }
private void DeviceTagHelper(bool clear, string[] addTags, string[] removeTags) { var editor = UAirship.Shared().PushManager.EditTags(); if (clear) { editor = editor.Clear(); } editor.AddTags(addTags).RemoveTags(removeTags).Apply(); }
public void AssociateIdentifier(string key, string identifier) { if (identifier == null) { UAirship.Shared().Analytics.EditAssociatedIdentifiers().RemoveIdentifier(key).Apply(); } else { UAirship.Shared().Analytics.EditAssociatedIdentifiers().AddIdentifier(key, identifier).Apply(); } }
void LocationUpdateReceiver_OnReceive(Context context, Intent intent) { if (UALocationManager.ActionLocationUpdate == intent.Action) { Location newLocation = (Location)intent.Extras.Get(UALocationManager.LocationKey); String text = string.Format("lat: {0}, lon: {1}", newLocation.Latitude, newLocation.Longitude); Toast.MakeText(UAirship.Shared().ApplicationContext, text, ToastLength.Long).Show(); } }
private void SetAlias(string alias) { alias = UAStringUtil.IsEmpty(alias) ? null : alias; PushManager.Shared().Alias = (alias); if (UAirship.Shared().AirshipConfigOptions.RichPushEnabled) { RichPushManager.Shared().RichPushUser.Alias = (alias); RichPushManager.Shared().UpdateUser(); } currentAlias = alias; }
private void UpdateUnreadCount() { int unreadCount = UAirship.Shared().Inbox.UnreadCount; TextView view = (TextView)navigation.Menu.FindItem(Resource.Id.nav_message_center).ActionView; if (unreadCount > 0) { view.Visibility = ViewStates.Visible; view.Text = unreadCount.ToString(); } else { view.Visibility = ViewStates.Gone; } }
private void SetTags(IList <String> tags) { currentTags.Clear(); foreach (var tag in tags) { currentTags.Add(tag); } PushManager.Shared().Tags = currentTags; if (UAirship.Shared().AirshipConfigOptions.RichPushEnabled) { // FIXME: not sure if this use of ToArray() is safe... RichPushManager.Shared().RichPushUser.Tags = new Java.Util.HashSet(currentTags.ToArray()); RichPushManager.Shared().UpdateUser(); } }
/** * Creates an inbox style notification summarizing the unread messages * in the inbox * * @param incomingAlert The alert message from an Urban Airship push * @return An inbox style notification */ private Android.App.Notification CreateInboxNotification(string incomingAlert) { Context context = UAirship.Shared().ApplicationContext; IList <RichPushMessage> unreadMessages = RichPushInbox.Shared().UnreadMessages; int inboxUnreadCount = unreadMessages.Count; // The incoming message is not immediately made available to the inbox because it needs // to first fetch its contents. int totalUnreadCount = inboxUnreadCount + 1; Resources res = UAirship.Shared().ApplicationContext.Resources; string title = res.GetQuantityString(Resource.Plurals.inbox_notification_title, totalUnreadCount, totalUnreadCount); Bitmap largeIcon = BitmapFactory.DecodeResource(res, Resource.Drawable.ua_launcher); var style = new Notification.InboxStyle( new Notification.Builder(context) .SetContentTitle(title) .SetContentText(incomingAlert) .SetLargeIcon(largeIcon) .SetSmallIcon(Resource.Drawable.ua_notification_icon) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .SetNumber(totalUnreadCount)); // Add the incoming alert as the first line in bold style.AddLine(Html.FromHtml("<b>" + incomingAlert + "</b>")); // Add any extra messages to the notification style int extraMessages = Math.Min(EXTRA_MESSAGES_TO_SHOW, inboxUnreadCount); for (int i = 0; i < extraMessages; i++) { style.AddLine(unreadMessages [i].Title); } // If we have more messages to show then the EXTRA_MESSAGES_TO_SHOW, add a summary if (inboxUnreadCount > EXTRA_MESSAGES_TO_SHOW) { style.SetSummaryText(context.GetString(Resource.String.inbox_summary, inboxUnreadCount - EXTRA_MESSAGES_TO_SHOW)); } return(style.Build()); }
// When the activity starts, we need to fetch and display the user's current // Push preferences in the view, if applicable. public override void OnStart() { base.OnStart(); bool isPushEnabled = pushPrefs.IsPushEnabled; pushEnabled.Checked = isPushEnabled; soundEnabled.Checked = pushPrefs.SoundEnabled; vibrateEnabled.Checked = pushPrefs.VibrateEnabled; PushSettingsActive(isPushEnabled); bool isQuietTimeEnabled = pushPrefs.QuietTimeEnabled; quietTimeEnabled.Checked = isQuietTimeEnabled; QuietTimeSettingsActive(isQuietTimeEnabled); if (!UAirship.Shared().AirshipConfigOptions.LocationOptions.LocationServiceEnabled) { locationEnabled.Visibility = ViewStates.Gone; backgroundLocationEnabled.Visibility = ViewStates.Gone; foregroundLocationEnabled.Visibility = ViewStates.Gone; locationEnabledLabel.Visibility = ViewStates.Gone; backgroundLocationEnabledLabel.Visibility = ViewStates.Gone; foregroundLocationEnabledLabel.Visibility = ViewStates.Gone; } else { locationEnabled.Checked = locPrefs.IsLocationEnabled; backgroundLocationEnabled.Checked = locPrefs.IsBackgroundLocationEnabled; foregroundLocationEnabled.Checked = locPrefs.IsForegroundLocationEnabled; } //this will be null if a quiet time interval hasn't been set Date[] interval = pushPrefs.GetQuietTimeInterval(); if (interval != null) { startTime.CurrentHour = new Java.Lang.Integer(interval[0].Hours); startTime.CurrentMinute = new Java.Lang.Integer(interval[0].Minutes); endTime.CurrentHour = new Java.Lang.Integer(interval[1].Hours); endTime.CurrentMinute = new Java.Lang.Integer(interval[1].Minutes); } }
void RefreshChannelId() { string channelIdString = UAirship.Shared().PushManager.ChannelId; if (!(channelIdString == channelId.Text)) { channelId.Text = channelIdString; } if (String.IsNullOrEmpty(channelIdString)) { copyButton.Enabled = false; shareButton.Enabled = false; } else { copyButton.Enabled = true; shareButton.Enabled = true; } }
public override void OnReceive(Context context, Intent intent) { Log.Info(logTag, "Received intent: " + intent); String action = intent.Action; if (action == PushManager.ActionPushReceived) { int id = intent.GetIntExtra(PushManager.ExtraNotificationId, 0); Log.Info(logTag, "Received push notification. Alert: " + intent.GetStringExtra(PushManager.ExtraAlert) + " [NotificationID=" + id + "]"); LogPushExtras(intent); } else if (action == PushManager.ActionNotificationOpened) { Log.Info(logTag, "User clicked notification. Message: " + intent.GetStringExtra(PushManager.ExtraAlert)); LogPushExtras(intent); Intent launch = new Intent(Intent.ActionMain); launch.SetClass(UAirship.Shared().ApplicationContext, typeof(MainActivity)); launch.SetFlags(ActivityFlags.NewTask); UAirship.Shared().ApplicationContext.StartActivity(launch); } else if (action == PushManager.ActionRegistrationFinished) { Log.Info(logTag, "Registration complete. APID:" + intent.GetStringExtra(PushManager.ExtraApid) + ". Valid: " + intent.GetBooleanExtra(PushManager.ExtraRegistrationValid, false)); // Notify any app-specific listeners Intent launch = new Intent(UAirship.PackageName + APID_UPDATED_ACTION_SUFFIX); UAirship.Shared().ApplicationContext.SendBroadcast(launch); } else if (action == GCMMessageHandler.ActionGcmDeletedMessages) { Log.Info(logTag, "The GCM service deleted " + intent.GetStringExtra(GCMMessageHandler.ExtraGcmTotalDeleted) + " messages."); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (DeepLink == null) { StartActivity(new Intent(this, typeof(MainActivity))); Finish(); return; } switch (DeepLink) { case "/preferences": StartActivity(new Intent(this, typeof(SettingsActivity))); break; case "/home": StartActivity(new Intent(this, typeof(MainActivity))); break; case "/inbox": string messageId = GetDeepLinkQueryParameter("message_id"); if (messageId != null && messageId.Length > 0) { UAirship.Shared().Inbox.StartMessageActivity(messageId); } else { UAirship.Shared().Inbox.StartInboxActivity(); } break; default: Log.Error(TAG, "Unknown deep link: " + DeepLink + ". Falling back to main activity."); StartActivity(new Intent(this, typeof(MainActivity))); break; } Finish(); }
public void AddCustomEvent(Portable.Analytics.CustomEvent customEvent) { if (customEvent == null || customEvent.EventName == null) { return; } string eventName = customEvent.EventName; double eventValue = customEvent.EventValue; string transactionId = customEvent.TransactionId; string interactionType = customEvent.InteractionType; string interactionId = customEvent.InteractionId; var builder = new UrbanAirship.Analytics.CustomEvent.Builder(eventName) .SetEventValue(eventValue); if (!string.IsNullOrEmpty(transactionId)) { builder.SetTransactionId(transactionId); } if (!string.IsNullOrEmpty(interactionType) && !string.IsNullOrEmpty(interactionId)) { builder.SetInteraction(interactionType, interactionId); } if (customEvent.PropertyList != null) { foreach (dynamic property in customEvent.PropertyList) { if (string.IsNullOrEmpty(property.name)) { continue; } builder.AddProperty(property.name, property.value); } } UAirship.Shared().Analytics.AddEvent(builder.Create()); }
private void RequestLocation() { if (Build.VERSION.SdkInt >= BuildVersionCodes.M && ContextCompat.CheckSelfPermission(Context, Android.Manifest.Permission.AccessFineLocation) != Permission.Granted) { RequestPermissions(new string[] { Android.Manifest.Permission.AccessFineLocation }, PERMISSIONS_REQUEST_LOCATION); return; } if (pendingRequest != null) { pendingRequest.Cancel(); } progress.Visibility = ViewStates.Visible; LocationRequestOptions options = new LocationRequestOptions.Builder() .SetPriority(Priority) .Create(); pendingRequest = UAirship.Shared().LocationManager.RequestSingleLocation(new LocManagerCallback(Context, progress), options); }
private void HandleLocation() { if (!UAirship.Shared().AirshipConfigOptions.LocationOptions.LocationServiceEnabled) { return; } bool isLocationEnabledInActivity = locationEnabled.Checked; bool isBackgroundLocationEnabledInActivity = backgroundLocationEnabled.Checked; bool isForegroundLocationEnabledInActivity = foregroundLocationEnabled.Checked; // Set the location enable preference first because it will be used // in the logic to enable/disable background and foreground locations. if (isLocationEnabledInActivity) { UALocationManager.EnableLocation(); } else { UALocationManager.DisableLocation(); } HandleBackgroundLocationPreference(isBackgroundLocationEnabledInActivity); HandleForegroundLocationPreference(isForegroundLocationEnabledInActivity); }
protected void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set the actionBar to have up navigation ABSActionBar actionBar = SupportActionBar; if (actionBar != null) { actionBar.SetDisplayOptions( ABSActionBar.DisplayHomeAsUp, ABSActionBar.DisplayHomeAsUp); } AirshipConfigOptions options = UAirship.Shared().AirshipConfigOptions; // Only add the push preferences if the pushServiceEnabled is true if (options.PushServiceEnabled) { this.AddPreferencesFromResource(Resource.Xml.push_preferences); } // Only add the location preferences if the locationServiceEnabled is true if (options.LocationOptions.LocationServiceEnabled) { this.AddPreferencesFromResource(Resource.Xml.location_preferences); } // Display the advanced settings if (options.PushServiceEnabled) { this.AddPreferencesFromResource(Resource.Xml.advanced_preferences); } // Creates the UAPreferenceAdapter with the entire preference screen preferenceAdapter = new UAPreferenceAdapter(PreferenceScreen); }
protected void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AirshipConfigOptions options = UAirship.Shared().AirshipConfigOptions; // Only add the push preferences if the pushServiceEnabled is true if (options.PushServiceEnabled) { this.AddPreferencesFromResource(Resource.Xml.push_preferences); } // Only add the location preferences if the locationServiceEnabled is true if (options.LocationOptions.LocationServiceEnabled) { this.AddPreferencesFromResource(Resource.Xml.location_preferences); } // Display the advanced settings if (options.PushServiceEnabled) { this.AddPreferencesFromResource(Resource.Xml.advanced_preferences); } }
public AddTagsPreference(Context context, IAttributeSet attrs) : base(context, attrs) { currentTags = new HashSet <string>(UAirship.Shared().PushManager.Tags); }
public void DisplayMessageCenter() { UAirship.Shared().Inbox.StartInboxActivity(); }
protected override void OnPause() { base.OnPause(); UAirship.Shared().Inbox.RemoveListener(inboxListener); }