Skip to content

Commit

Permalink
2.8 Notifications/ads/purchase NAPTWOEIGHT-50 - Set a flag to local …
Browse files Browse the repository at this point in the history
…and push notifications to display status bar notifications only when in background.
  • Loading branch information
emmaTresanszki committed Dec 12, 2011
1 parent 56e3141 commit 293987f
Show file tree
Hide file tree
Showing 32 changed files with 839 additions and 179 deletions.
22 changes: 21 additions & 1 deletion libs/Notification/LocalNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,31 @@ namespace Notification
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
int LocalNotification::setFlag(const int flag)
int LocalNotification::setFlag(const NotificationFlag flag)
{
return this->setPropertyInt(MA_NOTIFICATION_LOCAL_FLAG, flag);
}

/**
* Set the display flags applied to the local notification.
* Note that regardless of this setting, the didReceiveLocalNotification
* callback will be made for each incoming notification.
* #NOTIFICATION_DISPLAY_ONLY_IF_IN_BACKGROUND is enabled by default.
* Platform: Android.
* @param displayFlag is the required state of the application for
* a notification to be displayed. One of the constants:
* - #NOTIFICATION_DISPLAY_ONLY_IF_IN_BACKGROUND
* - #NOTIFICATION_DISPLAY_ANYTIME.
* @return Any of the following result codes:
* - #MA_NOTIFICATION_RES_OK if the property could be set.
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
int LocalNotification::setDisplayFlag(const NotificationDisplayFlag displayFlag)
{
return this->setPropertyInt(MA_NOTIFICATION_LOCAL_DISPLAY_FLAG, displayFlag);
}

/**
* Enable/disable the sound played when an alert is displayed.
* @param playSound If true the notification will play a sound when
Expand Down
45 changes: 42 additions & 3 deletions libs/Notification/LocalNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ namespace Notification
{

/**
* Constants indicating the flags
* Constants indicating the notification flags.
* Platform: Android only.
*/
enum NotificationFlags
enum NotificationFlag
{
// Indicates that the audio will be repeated until the notification is
// canceled or the notification window is opened.
Expand All @@ -58,6 +58,28 @@ namespace Notification
NOTIFICATION_FLAG_AUTO_CANCEL = 16
};

/**
* Constants used for setting the required state of the application
* for a notification to be displayed.
* Note that regardless of this setting, the didReceiveLocalNotification
* callback will be made for each incoming notification.
* Platform: Android only.
*/
enum NotificationDisplayFlag
{
// For local notifications:by setting this, the incoming notifications
// will be displayed to the user only if the application is in background.
// For push notifications: by setting this, the incoming notifications
// will be displayed to the user only if the application is not in use.
// This setting is enabled by default.
NOTIFICATION_DISPLAY_DEFAULT = 0,
// By setting this, the incoming notifications will be displayed to
// the user regardless of the application's focus state.
// So, even when in foreground, the notifications will be shown to
// the user.
NOTIFICATION_DISPLAY_ANYTIME = 1
};

/**
* Flashing LED lights.
* Define color and pattern.
Expand Down Expand Up @@ -280,7 +302,24 @@ namespace Notification
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
int setFlag(const int flag);
int setFlag(const NotificationFlag flag);

/**
* Set the display flags applied to the local notification.
* Note that regardless of this setting, the didReceiveLocalNotification
* callback will be made for each incoming notification.
* #NOTIFICATION_DISPLAY_ONLY_IF_IN_BACKGROUND is enabled by default.
* Platform: Android.
* @param displayFlag is the required state of the application for
* a notification to be displayed. One of the constants:
* - #NOTIFICATION_DISPLAY_DEFAULT
* - #NOTIFICATION_DISPLAY_ANYTIME.
* @return Any of the following result codes:
* - #MA_NOTIFICATION_RES_OK if the property could be set.
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
int setDisplayFlag(const NotificationDisplayFlag displayFlag);

/**
* Set the title of the action button or slider.
Expand Down
47 changes: 40 additions & 7 deletions libs/Notification/NotificationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ MA 02110-1301, USA.
#include <conprint.h>

#include "NotificationManager.h"
#include "LocalNotification.h"
#include "LocalNotificationListener.h"
#include "PushNotification.h"
#include "PushNotificationListener.h"
Expand Down Expand Up @@ -187,6 +186,9 @@ namespace Notification
/**
* Schedules a local notification for delivery at its encapsulated
* date and time.
* By default, the notifications are displayed to the user only if the application
* is in background. But on Android you can configure this via the
* #MA_NOTIFICATION_LOCAL_DISPLAY_FLAG property by calling setDisplayFlag().
* @param localNotification Handle to a local notification object.
* @return One of the constants:
* - #MA_NOTIFICATION_RES_OK if no error occurred.
Expand Down Expand Up @@ -235,9 +237,11 @@ namespace Notification
* PUSH_NOTIFICATION_TYPE_BADGE | PUSH_NOTIFICATION_TYPE_ALERT, "");
*
* @return One of the next result codes:
* - MA_NOTIFICATION_RES_OK if no error occurred.
* - MA_NOTIFICATION_RES_ALREADY_REGISTERED if the application is already
* - #MA_NOTIFICATION_RES_OK if no error occurred.
* - #MA_NOTIFICATION_RES_ALREADY_REGISTERED if the application is already
* registered for receiving push notifications.
* - #MA_NOTIFICATION_RES_UNSUPPORTED if notifications are not supported
* on current platform.
*/
int NotificationManager::registerPushNotification(
const int types,
Expand Down Expand Up @@ -315,18 +319,43 @@ namespace Notification
return maNotificationGetIconBadge();
}

/**
* Set the display flags applied to the incoming push notifications.
* Note that regardless of this setting, the didReceivePushNotification
* callback will be made for each incoming notification.
* #NOTIFICATION_DISPLAY_DEFAULT is enabled by default.
* Platform: Android only.
* @param displayFlag is the required state of the application for
* a notification to be displayed. One of the constants:
* - #NOTIFICATION_DISPLAY_DEFAULT
* - #NOTIFICATION_DISPLAY_ANYTIME.
* @return Any of the following result codes:
* - #MA_NOTIFICATION_RES_OK if the property could be set.
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
int NotificationManager::setPushNotificationsDisplayFlag(
const NotificationDisplayFlag displayFlag)
{
return maNotificationPushSetDisplayFlag(displayFlag);
}

/**
* Set the message title in the notification area for incoming push
* notifications.
* This call does not alter already received notifications.
* Platform: Android only.
* @param title The title that goes in the expanded entry of the
* notification.
* @return Any of the following result codes:
* - #MA_NOTIFICATION_RES_OK if the property could be set.
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
void NotificationManager::setPushNotificationsTitle(
int NotificationManager::setPushNotificationsTitle(
const MAUtil::String& title)
{
maNotificationPushSetMessageTitle(title.c_str());
return maNotificationPushSetMessageTitle(title.c_str());
}

/**
Expand All @@ -336,11 +365,15 @@ namespace Notification
* Platform: Android only.
* @param ticker The text that flows by in the status bar when the
* notification first activates.
* @return Any of the following result codes:
* - #MA_NOTIFICATION_RES_OK if the property could be set.
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
void NotificationManager::setPushNotificationsTickerText(
int NotificationManager::setPushNotificationsTickerText(
const MAUtil::String& ticker)
{
maNotificationPushSetTickerText(ticker.c_str());
return maNotificationPushSetTickerText(ticker.c_str());
}

/**
Expand Down
40 changes: 36 additions & 4 deletions libs/Notification/NotificationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ MA 02110-1301, USA.
#include <MAUtil/Map.h>
#include <MAUtil/Environment.h>

#include "LocalNotification.h"

namespace Notification
{

Expand Down Expand Up @@ -156,6 +158,9 @@ namespace Notification
/**
* Schedules a local notification for delivery at its encapsulated
* date and time.
* By default, the notifications are displayed to the user only if the application
* is in background. But on Android you can configure this via the
* #MA_NOTIFICATION_LOCAL_DISPLAY_FLAG property by calling setDisplayFlag().
* @param localNotification Handle to a local notification object.
* @return One of the constants:
* - #MA_NOTIFICATION_RES_OK if no error occurred.
Expand Down Expand Up @@ -198,9 +203,11 @@ namespace Notification
* PUSH_NOTIFICATION_TYPE_BADGE | PUSH_NOTIFICATION_TYPE_ALERT, "");
*
* @return One of the next result codes:
* - MA_NOTIFICATION_RES_OK if no error occurred.
* - MA_NOTIFICATION_RES_ALREADY_REGISTERED if the application is already
* - #MA_NOTIFICATION_RES_OK if no error occurred.
* - #MA_NOTIFICATION_RES_ALREADY_REGISTERED if the application is already
* registered for receiving push notifications.
* - #MA_NOTIFICATION_RES_UNSUPPORTED if notifications are not supported
* on current platform.
*/
int registerPushNotification(
const int types,
Expand Down Expand Up @@ -244,15 +251,36 @@ namespace Notification
*/
int getApplicationIconBadgeNumber();

/**
* Set the display flags applied to the incoming push notifications.
* Note that regardless of this setting, the didReceivePushNotification
* callback will be made for each incoming notification.
* #NOTIFICATION_DISPLAY_DEFAULT is enabled by default.
* Platform: Android only.
* @param displayFlag is the required state of the application for
* a notification to be displayed. One of the constants:
* - #NOTIFICATION_DISPLAY_DEFAULT
* - #NOTIFICATION_DISPLAY_ANYTIME.
* @return Any of the following result codes:
* - #MA_NOTIFICATION_RES_OK if the property could be set.
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
int setPushNotificationsDisplayFlag(const NotificationDisplayFlag displayFlag);

/**
* Set the message title in the notification area for incoming push
* notifications.
* This call does not alter already received notifications.
* Platform: Android only.
* @param title The title that goes in the expanded entry of the
* notification.
* @return Any of the following result codes:
* - #MA_NOTIFICATION_RES_OK if the property could be set.
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
void setPushNotificationsTitle(const MAUtil::String& title);
int setPushNotificationsTitle(const MAUtil::String& title);

/**
* Set the ticker text in the notification status bar for incoming push
Expand All @@ -261,8 +289,12 @@ namespace Notification
* Platform: Android only.
* @param ticker The text that flows by in the status bar when the
* notification first activates.
* @return Any of the following result codes:
* - #MA_NOTIFICATION_RES_OK if the property could be set.
* - #MA_NOTIFICATION_RES_INVALID_PROPERTY_NAME if the property name
* was invalid for the target platform.
*/
void setPushNotificationsTickerText(const MAUtil::String& ticker);
int setPushNotificationsTickerText(const MAUtil::String& ticker);

/**
* Get the message title of the incoming notifications.
Expand Down
16 changes: 16 additions & 0 deletions runtimes/cpp/platforms/android/IOCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3194,6 +3194,22 @@ namespace Base
return result;
}

int _maNotificationPushSetDisplayFlag(int flag, JNIEnv* jNIEnv, jobject jThis)
{
jclass cls = jNIEnv->GetObjectClass(jThis);
jmethodID methodID = jNIEnv->GetMethodID(cls, "maNotificationPushSetDisplayFlag", "(I)I");
if (methodID == 0)
{
return 0;
}

int result = jNIEnv->CallIntMethod(jThis, methodID, flag);

jNIEnv->DeleteLocalRef(cls);

return result;
}

int _maSyscallPanicsEnable(JNIEnv* jNIEnv, jobject jThis)
{
jclass cls = jNIEnv->GetObjectClass(jThis);
Expand Down
2 changes: 2 additions & 0 deletions runtimes/cpp/platforms/android/IOCtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,8 @@ namespace Base

int _maNotificationPushSetMessageTitle(const char* text, JNIEnv* jNIEnv, jobject jThis);

int _maNotificationPushSetDisplayFlag(int flag, JNIEnv* jNIEnv, jobject jThis);

int _maSyscallPanicsEnable(JNIEnv* jNIEnv, jobject jThis);

int _maSyscallPanicsDisable(JNIEnv* jNIEnv, jobject jThis);
Expand Down
3 changes: 3 additions & 0 deletions runtimes/cpp/platforms/android/SyscallImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2706,6 +2706,9 @@ return 0; \
mJThis);
}

case maIOCtl_maNotificationPushSetDisplayFlag:
return _maNotificationPushSetDisplayFlag(a, mJNIEnv, mJThis);

case maIOCtl_maSyscallPanicsEnable:
SYSLOG("maIOCtl_maSyscallPanicsEnable");
return _maSyscallPanicsEnable(
Expand Down
Loading

0 comments on commit 293987f

Please sign in to comment.