Beispiel #1
0
        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);
        }
Beispiel #2
0
        private void Init()
        {
            UAirship.Shared().Channel.AddChannelListener(this);

            //Adding Inbox updated listener
            MessageCenterClass.Shared().Inbox.AddListener(this);
        }
Beispiel #3
0
        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);
        }
        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();
        }
        public override void OnCreate()
        {
            var options = AirshipConfigOptions.LoadDefaultOptions(this);

            // Optionally, customize your config
            options.InProduction         = false;
            options.DevelopmentAppKey    = "";
            options.DevelopmentAppSecret = "";

            UAirship.TakeOff(this, options);

            //use CustomPushNotificationBuilder to specify a custom layout
            CustomPushNotificationBuilder nb = new CustomPushNotificationBuilder();

            nb.StatusBarIconDrawableId = Resource.Id.icon;            //custom status bar icon

            nb.Layout = Resource.Layout.notification;
            nb.LayoutIconDrawableId = Resource.Id.icon;            //custom layout icon
            nb.LayoutIconId         = Resource.Id.icon;
            nb.LayoutSubjectId      = Resource.Id.subject;
            nb.LayoutMessageId      = Resource.Id.message;

            PushManager.Shared().NotificationBuilder  = nb;
            PushManager.Shared().IntentReceiver       = Class.FromType(typeof(IntentReceiver));
            UALocationManager.Shared().IntentReceiver = Class.FromType(typeof(IntentReceiver));
        }
Beispiel #7
0
        /**
         * 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);
        }
        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();
        }
Beispiel #9
0
 public Channel.TagGroupsEditor EditChannelTagGroups()
 {
     return(new Channel.TagGroupsEditor((List <Channel.TagGroupsEditor.TagOperation> payload) =>
     {
         var editor = UAirship.Shared().Channel.EditTagGroups();
         TagGroupHelper(payload, editor);
         editor.Apply();
     }));
 }
Beispiel #10
0
 public Push.TagGroupsEditor EditChannelTagGroups()
 {
     return(new Push.TagGroupsEditor((List <Push.TagGroupsEditor.TagOperation> payload) =>
     {
         var editor = UAirship.Shared().PushManager.EditTagGroups();
         TagGroupHelper(payload, editor);
         editor.Apply();
     }));
 }
Beispiel #11
0
 public AttributeEditor EditNamedUserAttributes()
 {
     return(new AttributeEditor((List <AttributeEditor.IAttributeOperation> operations) =>
     {
         var editor = UAirship.Shared().NamedUser.EditAttributes();
         ApplyAttributesOperations(editor, operations);
         editor.Apply();
     }));
 }
Beispiel #12
0
        public override void OnCreate()
        {
            base.OnCreate();

            UAirship.TakeOff(this, (UAirship airship) => {
                airship.PushManager.UserNotificationsEnabled = true;
                airship.PushManager.Tags = new String[] { "android-xamarin" };
            });
        }
Beispiel #13
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Bootstrap the Urban Airship SDK
            UAirship.TakeOff();

            // Enable visible push notifications
            UAirship.Push.UserPushNotificationsEnabled = true;

            return(true);
        }
        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();
        }
        public override void OnAirshipReady(UAirship airship)
        {
            ISharedPreferences sharedPreferences = UAirship.ApplicationContext.GetSharedPreferences(NoBackupPreferences, FileCreationMode.Private);
            bool isFirstRun = sharedPreferences.GetBoolean(FirstRunKey, true);

            if (isFirstRun)
            {
                sharedPreferences.Edit().PutBoolean(FirstRunKey, false).Apply();
                airship.PushManager.UserNotificationsEnabled = true;
            }
        }
Beispiel #16
0
        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();
        }
Beispiel #17
0
    void Start()
    {
        UAirship.AddListener(gameObject);

        if (!string.IsNullOrEmpty(addTagOnStart))
        {
            UAirship.AddTag(addTagOnStart);
        }

        CheckDeepLink();
    }
Beispiel #18
0
 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();
     }
 }
        public override void OnCreate()
        {
            UAirship.TakeOff(this);
            PushManager.Shared().IntentReceiver = Class.FromType(typeof(PushReceiver));
            RichPushManager.SetJavascriptInterface(Class.FromType(typeof(RichPushMessageJavaScript)), "urbanairship");

            // If running on Jelly Bean or higher, then use the inbox style notification builder
            if ((int)Build.VERSION.SdkInt >= (int)BuildVersionCodes.JellyBean)
            {
                PushManager.Shared().NotificationBuilder = new RichNotificationBuilder();
            }
        }
Beispiel #20
0
        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();
            }
        }
Beispiel #21
0
        public override void OnCreate()
        {
            UAirship.TakeOff(this);
            //PushManager.Shared ().IntentReceiver = Java.Lang.Class.FromType (typeof(IntentReceiver));
            RichPushManager.SetJavascriptInterface(Java.Lang.Class.FromType(typeof(RichPushMessageJavaScript)), "urbanairship");

            /*
             * // If running on Jelly Bean or higher, then use the inbox style notification builder
             * if (Build.VERSION.SdkInt >= 16) {
             *      PushManager.Shared().NotificationBuilder = new RichNotificationBuilder ();
             * }
             */
        }
Beispiel #22
0
    void CheckDeepLink()
    {
        Debug.Log("Checking for deeplink.");

        string deepLink = UAirship.GetDeepLink();

        if (!string.IsNullOrEmpty(deepLink))
        {
            Debug.Log("Launched with deeplink! " + deepLink);

            // Handle any deep links here
        }
    }
Beispiel #23
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // Set log level for debugging config loading (optional)
            // It will be set to the value in the loaded config upon takeOff
            UAirship.LogLevel = UALogLevel.Trace;

            // Populate AirshipConfig.plist with your app's info from https://go.urbanairship.com
            // or set runtime properties here.
            UAConfig config = UAConfig.DefaultConfig();

            if (!config.Validate())
            {
                throw new RuntimeException("The AirshipConfig.plist must be a part of the app bundle and " +
                                           "include a valid appkey and secret for the selected production level.");
            }

            WarnIfSimulator();

            // Bootstrap the Airship SDK
            UAirship.TakeOff(config, options);

            Console.WriteLine("Config:{0}", config);

            UAirship.Push.ResetBadge();

            pushHandler = new PushHandler();
            UAirship.Push.PushNotificationDelegate = pushHandler;

            UNNotificationAction sampleAction = UNNotificationAction.FromIdentifier("sampleAction", title: "Sample Action Title", options: UNNotificationActionOptions.Destructive);

            var sampleActions     = new UNNotificationAction[] { sampleAction };
            var intentIdentifiers = new string[] { };

            // Create category for sample content extension
            UNNotificationCategory[]       SampleCategoryArray = { UNNotificationCategory.FromIdentifier("sample-extension-category", actions: sampleActions, intentIdentifiers: intentIdentifiers, options: UNNotificationCategoryOptions.None) };
            NSSet <UNNotificationCategory> categories          = new NSSet <UNNotificationCategory>(SampleCategoryArray);

            // Add sample content extension category to Airship custom categories
            UAirship.Push.CustomCategories = categories;

            UAirship.Push.WeakRegistrationDelegate = this;

            NSNotificationCenter.DefaultCenter.AddObserver(new NSString("channelIDUpdated"), (notification) =>
            {
                //FIXME: Find a way to call the refreshView from the HomeViewController
            });

            InitFormsApp();

            return(base.FinishedLaunching(app, options));
        }
Beispiel #24
0
        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;
            }
        }
        public override void OnAirshipReady(UAirship airship)
        {
            ISharedPreferences sharedPreferences = UAirship.ApplicationContext.GetSharedPreferences(NoBackupPreferences, FileCreationMode.Private);
            bool isFirstRun = sharedPreferences.GetBoolean(FirstRunKey, true);

            if (isFirstRun)
            {
                sharedPreferences.Edit().PutBoolean(FirstRunKey, false).Apply();
            }

            UrbanAirshipListener airshipListener = new UrbanAirshipListener();

            airship.PushManager.NotificationListener = airshipListener;
            airship.PushManager.AddPushListener(airshipListener);
            airship.PushManager.AddPushTokenListener(airshipListener);
            airship.Channel.AddChannelListener(airshipListener);
        }
        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();
            }
        }
Beispiel #28
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            viewController            = new UrbanAirshipPushNotificationsViewController();
            window.RootViewController = viewController;
            window.MakeKeyAndVisible();

            options = new NSDictionary();
            var takeOffOptions = new NSMutableDictionary();

            takeOffOptions.SetValueForKey(options, new NSString("UAirshipTakeOffOptionsLaunchOptionsKey"));

            UAPush.Shared.ResetBadge();
            UAirship.TakeOff(takeOffOptions);

            return(true);
        }
Beispiel #29
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            this.FailIfSimulator();

            Xamarin.Forms.Forms.Init();

            // Set log level for debugging config loading (optional)
            // It will be set to the value in the loaded config upon takeOff
            UAirship.SetLogLevel(UALogLevel.Trace);

            // Populate AirshipConfig.plist with your app's info from https://go.urbanairship.com
            // or set runtime properties here.
            UAConfig config = UAConfig.DefaultConfig();

            if (!config.Validate())
            {
                this.ShowInvalidConfigAlert();
                return(true);
            }

            config.MessageCenterStyleConfig = "UAMessageCenterDefaultStyle";

            // Bootstrap the Urban Airship SDK
            UAirship.TakeOff(config);

            Console.WriteLine("Config:{0}", config);

            UAirship.Push.ResetBadge();

            pushHandler = new PushHandler();
            UAirship.Push.PushNotificationDelegate = pushHandler;

            inboxDelegate           = new InboxDelegate(Window.RootViewController);
            UAirship.Inbox.Delegate = inboxDelegate;

            NSString messageListUpdated = new NSString("com.urbanairship.notification.message_list_updated");

            NSNotificationCenter.DefaultCenter.AddObserver(messageListUpdated, (notification) =>
            {
                refreshMessageCenterBadge();
            });

            return(true);
        }
Beispiel #30
0
        /**
         * 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());
        }