Ejemplo n.º 1
0
 protected internal override void onPause()
 {
     if (Finishing)
     {
         long id = Intent.getLongExtra(INTENT_EXTRA_CONTENT_ID, -1);
         EngagementReachAgent.getInstance(this).exitLoading(id);
     }
     base.onPause();
 }
Ejemplo n.º 2
0
        protected internal override void onResume()
        {
            long id = Intent.getLongExtra(INTENT_EXTRA_CONTENT_ID, -1);

            if (!EngagementReachAgent.getInstance(this).isLoading(id))
            {
                finish();
            }
            base.onResume();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when download times out. </summary>
        /// <param name="context"> application context. </param>
        /// <param name="intent"> timeout intent containing content identifier. </param>
        private void onDownloadTimeout(Context context, Intent intent)
        {
            /* Delegate to agent */
            EngagementReachAgent reachAgent           = EngagementReachAgent.getInstance(context);
            EngagementReachInteractiveContent content = reachAgent.getContent(intent);

            if (content != null)
            {
                reachAgent.onDownloadTimeout(content);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Called when a notification has been exited (clear button from notification panel). </summary>
        /// <param name="context"> context. </param>
        /// <param name="intent"> intent containing the content identifier to exit. </param>
        private void onNotificationExited(Context context, Intent intent)
        {
            /* Get content */
            EngagementReachAgent reachAgent           = EngagementReachAgent.getInstance(context);
            EngagementReachInteractiveContent content = reachAgent.getContent(intent);

            /* Exit it if found */
            if (content != null)
            {
                content.exitNotification(context);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Report content has been displayed. </summary>
        /// <param name="context"> any application context. </param>
        public virtual void displayContent(Context context)
        {
            /* Notify reach agent */
            EngagementReachAgent.getInstance(context).onContentDisplayed(this);

            /* Guard against multiple calls for feedback */
            if (!mContentDisplayed)
            {
                mCampaignId.sendFeedBack(context, "content-displayed", null);
                mContentDisplayed = true;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Action the notification: this will display the announcement or poll, or will launch the action
        /// URL associated to the notification, depending of the content kind. This will also report the
        /// notification has been actioned. </summary>
        /// <param name="context"> any application context. </param>
        /// <param name="launchIntent"> true to launch intent, false to just report the notification action and
        ///          change internal state. If you call this method passing false, be sure that the content
        ///          is either a notification only announcement or that you properly manage the content
        ///          display and its life cycle (by calling actionContent or exitContent when the user is
        ///          done viewing the content). </param>
        public virtual void actionNotification(Context context, bool launchIntent)
        {
            /* Notify agent if intent must be launched */
            EngagementReachAgent.getInstance(context).onNotificationActioned(this, launchIntent);

            /* Send feedback */
            if (!mNotificationActioned)
            {
                mCampaignId.sendFeedBack(context, NotificationStatusPrefix + "actioned", null);
                mNotificationActioned = true;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called when a push message is received or message download completes. </summary>
        /// <param name="context"> context. </param>
        /// <param name="intent"> intent. </param>
        private void onMessage(Context context, Intent intent)
        {
            string type = intent.getStringExtra(INTENT_EXTRA_TYPE);

            if (INTENT_EXTRA_TYPE_PUSH.Equals(type))
            {
                EngagementReachAgent.getInstance(context).onContentReceived(intent.Extras);
            }
            else if (INTENT_EXTRA_TYPE_DLC.Equals(type))
            {
                EngagementReachAgent.getInstance(context).onMessageDownloaded(intent.Extras);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Called when a system notification for a content has been actioned. </summary>
        /// <param name="context"> context. </param>
        /// <param name="intent"> intent describing the content. </param>
        private void onNotificationActioned(Context context, Intent intent)
        {
            /* Get content */
            EngagementReachAgent reachAgent           = EngagementReachAgent.getInstance(context);
            EngagementReachInteractiveContent content = reachAgent.getContent(intent);

            /* If content retrieved successfully */
            if (content != null)

            /* Tell reach to start the content activity */
            {
                content.actionNotification(context, true);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Report notification has been displayed. </summary>
        /// <param name="context"> any application context. </param>
        public virtual void displayNotification(Context context)
        {
            /* Update last displayed date */
            mNotificationLastDisplayedDate = DateTimeHelperClass.CurrentUnixTimeMillis();

            /* First date and reach feedback the first time */
            if (mNotificationFirstDisplayedDate == null)
            {
                mNotificationFirstDisplayedDate = mNotificationLastDisplayedDate;
                mCampaignId.sendFeedBack(context, NotificationStatusPrefix + "displayed", null);
            }

            /* Notify reach agent */
            EngagementReachAgent.getInstance(context).onNotificationDisplayed(this);
        }
Ejemplo n.º 10
0
        public override void onReceive(Context context, Intent intent)
        {
            /* Big picture downloaded */
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.Equals(intent.Action))
            {
                /* Get content by download id */
                long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                EngagementReachAgent reachAgent           = EngagementReachAgent.getInstance(context);
                EngagementReachInteractiveContent content = reachAgent.getContentByDownloadId(downloadId);

                /* Delegate to agent if content found */
                if (content != null)
                {
                    reachAgent.onDownloadComplete(content);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Dispose of this content so that new content can be notified. Possibly send feedback to the
        /// service that sent it. </summary>
        /// <param name="context"> application context. </param>
        /// <param name="status"> feedback status if any (null not to send anything). </param>
        /// <param name="extras"> extra information like poll answers. </param>
        internal virtual void process(Context context, string status, Bundle extras)
        {
            /* Do it once */
            if (!mProcessed)
            {
                /* Send feedback if any */
                if (status != null)
                {
                    mCampaignId.sendFeedBack(context, status, extras);
                }

                /* Mark this announcement as processed */
                mProcessed = true;

                /* Tell the reach application manager that announcement has been processed */
                EngagementReachAgent.getInstance(context).onContentProcessed(this);
            }
        }
Ejemplo n.º 12
0
        public override void onReceive(Context context, Intent intent)
        {
            /* Boot: restore system notifications */
            string action = intent.Action;

            if (Intent.ACTION_BOOT_COMPLETED.Equals(action))
            {
                EngagementReachAgent.getInstance(context).onDeviceBoot();
            }

            /* Just ensure the reach agent is loaded for checking pending contents in SQLite */
            else if (EngagementAgent.INTENT_ACTION_AGENT_CREATED.Equals(action))
            {
                EngagementReachAgent.getInstance(context);
            }

            /* Notification actioned e.g. clicked (from the system notification) */
            else if (EngagementReachAgent.INTENT_ACTION_ACTION_NOTIFICATION.Equals(action))
            {
                onNotificationActioned(context, intent);
            }

            /* System notification exited (clear button) */
            else if (EngagementReachAgent.INTENT_ACTION_EXIT_NOTIFICATION.Equals(action))
            {
                onNotificationExited(context, intent);
            }

            /* Called when download takes too much time to complete */
            else if (EngagementReachAgent.INTENT_ACTION_DOWNLOAD_TIMEOUT.Equals(action))
            {
                onDownloadTimeout(context, intent);
            }

            /* Called when we receive GCM or ADM push with azme parameters or message download completes. */
            else if (EngagementIntents.INTENT_ACTION_MESSAGE.Equals(action))
            {
                onMessage(context, intent);
            }
        }
Ejemplo n.º 13
0
        protected internal override void onCreate(Bundle savedInstanceState)
        {
            /* No title section on the top */
            base.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);

            /* Get content */
            mContent = EngagementReachAgent.getInstance(this).getContent(Intent);
            if (mContent == null)
            {
                /* If problem with content, exit */
                finish();
                return;
            }

            /* Inflate layout */
            ContentView = getLayoutId(LayoutName);

            /* Set title */
            TextView titleView = getView("title");
            string   title     = mContent.Title;

            if (title != null)
            {
                titleView.Text = title;
            }
            else
            {
                titleView.Visibility = View.GONE;
            }

            /* Set body */
            setBody(mContent.Body, getView("body"));

            /* Action button */
            mActionButton = getView("action");
            string actionLabel = mContent.ActionLabel;

            if (actionLabel != null)
            {
                mActionButton.Text            = actionLabel;
                mActionButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this);
            }

            /* No action label means no action button */
            else
            {
                mActionButton.Visibility = View.GONE;
            }

            /* Exit button */
            Button exitButton = getView("exit");
            string exitLabel  = mContent.ExitLabel;

            if (exitLabel != null)
            {
                exitButton.Text            = exitLabel;
                exitButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper2(this);
            }

            /* No exit label means no exit button */
            else
            {
                exitButton.Visibility = View.GONE;
            }

            /* Hide spacers if only one button is visible (or none) */
            ViewGroup layout     = getView("engagement_button_bar");
            bool      hideSpacer = actionLabel == null || exitLabel == null;

            for (int i = 0; i < layout.ChildCount; i++)
            {
                View view = layout.getChildAt(i);
                if ("spacer".Equals(view.Tag))
                {
                    if (hideSpacer)
                    {
                        view.Visibility = View.VISIBLE;
                    }
                    else
                    {
                        view.Visibility = View.GONE;
                    }
                }
            }

            /* Hide button bar if both action and exit buttons are hidden */
            if (actionLabel == null && exitLabel == null)
            {
                layout.Visibility = View.GONE;
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public Boolean handleNotification(EngagementReachInteractiveContent content) throws RuntimeException
        public virtual bool?handleNotification(EngagementReachInteractiveContent content)
        {
            /* System notification case */
            if (content.SystemNotification)
            {
                /* Big picture handling */
                Bitmap bigPicture    = null;
                string bigPictureURL = content.NotificationBigPicture;
                if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16)
                {
                    /* Schedule picture download if needed, or load picture if download completed. */
                    long?downloadId = content.DownloadId;
                    if (downloadId == null)
                    {
                        EngagementNotificationUtilsV11.downloadBigPicture(mContext, content);
                        return(null);
                    }
                    else
                    {
                        bigPicture = EngagementNotificationUtilsV11.getBigPicture(mContext, downloadId.Value);
                    }
                }

                /* Generate notification identifier */
                int notificationId = getNotificationId(content);

                /* Build notification using support lib to manage compatibility with old Android versions */
                NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

                /* Icon for ticker and content icon */
                builder.SmallIcon = mNotificationIcon;

                /*
                 * Large icon, handled only since API Level 11 (needs down scaling if too large because it's
                 * cropped otherwise by the system).
                 */
                Bitmap notificationImage = content.NotificationImage;
                if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                {
                    builder.LargeIcon = scaleBitmapForLargeIcon(mContext, notificationImage);
                }

                /* Texts */
                string notificationTitle   = content.NotificationTitle;
                string notificationMessage = content.NotificationMessage;
                string notificationBigText = content.NotificationBigText;
                builder.ContentTitle = notificationTitle;
                builder.ContentText  = notificationMessage;

                /*
                 * Replay: display original date and don't replay all the tickers (be as quiet as possible
                 * when replaying).
                 */
                long?notificationFirstDisplayedDate = content.NotificationFirstDisplayedDate;
                if (notificationFirstDisplayedDate != null)
                {
                    builder.When = notificationFirstDisplayedDate;
                }
                else
                {
                    builder.Ticker = notificationTitle;
                }

                /* Big picture */
                if (bigPicture != null)
                {
                    builder.Style = (new NotificationCompat.BigPictureStyle()).bigPicture(bigPicture).setBigContentTitle(notificationTitle).setSummaryText(notificationMessage);
                }

                /* Big text */
                else if (notificationBigText != null)
                {
                    builder.Style = (new NotificationCompat.BigTextStyle()).bigText(notificationBigText);
                }

                /* Vibration/sound if not a replay */
                if (notificationFirstDisplayedDate == null)
                {
                    int defaults = 0;
                    if (content.NotificationSound)
                    {
                        defaults |= Notification.DEFAULT_SOUND;
                    }
                    if (content.NotificationVibrate)
                    {
                        defaults |= Notification.DEFAULT_VIBRATE;
                    }
                    builder.Defaults = defaults;
                }

                /* Launch the receiver on action */
                Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION);
                EngagementReachAgent.setContentIdExtra(actionIntent, content);
                actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId);
                Intent intent = content.Intent;
                if (intent != null)
                {
                    actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.Component);
                }
                actionIntent.Package = mContext.PackageName;
                PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int)content.LocalId, actionIntent, FLAG_CANCEL_CURRENT);
                builder.ContentIntent = contentIntent;

                /* Also launch receiver if the notification is exited (clear button) */
                Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION);
                exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId);
                EngagementReachAgent.setContentIdExtra(exitIntent, content);
                exitIntent.Package = mContext.PackageName;
                PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int)content.LocalId, exitIntent, FLAG_CANCEL_CURRENT);
                builder.DeleteIntent = deleteIntent;

                /* Can be dismissed ? */
                Notification notification = builder.build();
                if (!content.NotificationCloseable)
                {
                    notification.flags |= Notification.FLAG_NO_CLEAR;
                }

                /* Allow overriding */
                if (onNotificationPrepared(notification, content))

                /*
                 * Submit notification, replacing the previous one if any (this should happen only if the
                 * application process is restarted).
                 */
                {
                    mNotificationManager.notify(notificationId, notification);
                }
            }

            /* Activity embedded notification case */
            else
            {
                /* Get activity */
                Activity activity = EngagementActivityManager.Instance.CurrentActivity.get();

                /* Cannot notify in app if no activity provided */
                if (activity == null)
                {
                    return(false);
                }

                /* Get notification area */
                string category             = content.Category;
                int    areaId               = getInAppAreaId(category).Value;
                View   notificationAreaView = activity.findViewById(areaId);

                /* No notification area, check if we can install overlay */
                if (notificationAreaView == null)
                {
                    /* Check overlay is not disabled in this activity */
                    Bundle activityConfig = EngagementUtils.getActivityMetaData(activity);
                    if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true))
                    {
                        return(false);
                    }

                    /* Inflate overlay layout and get reference to notification area */
                    View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null);
                    activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
                    notificationAreaView = activity.findViewById(areaId);
                }

                /* Otherwise check if there is an overlay containing the area to restore visibility */
                else
                {
                    View overlay = activity.findViewById(getOverlayViewId(category));
                    if (overlay != null)
                    {
                        overlay.Visibility = View.VISIBLE;
                    }
                }

                /* Make the notification area visible */
                notificationAreaView.Visibility = View.VISIBLE;

                /* Prepare area */
                prepareInAppArea(content, notificationAreaView);
            }

            /* Success */
            return(true);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Set download identifier for this content. </summary>
 /// <param name="context"> any application context. </param>
 /// <param name="downloadId"> download identifier. </param>
 public virtual void setDownloadId(Context context, long downloadId)
 {
     mDownloadId = downloadId;
     EngagementReachAgent.getInstance(context).onDownloadScheduled(this, downloadId);
 }