📄 sms.c
字号:
/*===========================================================================
FILE: sms.c
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEStdlib.h"
#include "AEEText.h"
#include "AEESound.h" // Sound Interface definitions
#include "AEETapi.h" // TAPI Interface definitions
#include "SMS.BID"
#include "sms_res.h"
#define PHONE_NUM 12
#define MESSAGE_LENGTH 141
#define SOFT_CTL_NUM 10
#define CONTROL_SPACE 5
#define SMS_PREFS_VERSION 1
#define GROUP_SMS_COUNT 20
typedef enum {
PHONE_NUMBER_TEXT_CTL,
MESSAGE_TEXT_CTL,
SOFTKEY_OK_CTL,
SEND_RESULT_CTL
}CTRL_FOCUS;
typedef struct
{
char phoneNum[PHONE_NUM];
} CSmsPrefs;
typedef struct _CSmsApp
{
AEEApplet a; // Mandatory AEEApplet data member appears first
ITextCtl * m_pText;
IMenuCtl * m_pSoftKey;
ITextCtl * m_pMessageText;
IMenuCtl * m_pMessageSoftKey;
ITAPI * m_pITAPI;
IStatic * m_pStatic;
IMenuCtl * m_pResultSoftKey;
AEERect m_rc; //Device Screen Rect
int m_fontHeight;
uint16 m_focus; //control focus
AECHAR wStrNum[15];
char strNum[15];
AECHAR wStrMessage[MESSAGE_LENGTH];
CSmsPrefs m_Prefs;
uint16 SentStatus;
} CSmsApp;
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean sms_HandleEvent(CSmsApp * pApp, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static void sms_FreeAppData(CSmsApp * pApp);
static boolean sms_InitAppData(CSmsApp * pApp);
static void TextMesage_init(CSmsApp * pApp);
static void sms_init(CSmsApp * pApp);
static void sms_release(CSmsApp * pApp);
static void sms_Send(CSmsApp * pApp);
static void MySmsNotify(CSmsApp * pApp, int16 status);
/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
that has been provided in AEEAppGen.c.
After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to IDisplay_InitAppData().
This is done as follows: InitAppData() is called to initialize AppletData
instance. It is app developers responsibility to fill-in app data initialization
code of InitAppData(). App developer is also responsible to release memory
allocated for data contained in AppletData -- this can be done in
IDisplay_FreeAppData().
PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded
pIShell: [in]: Contains pointer to the IShell object.
pIModule: pin]: Contains pointer to the IModule object to the current module to which
this app belongs
ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().
DEPENDENCIES
none
RETURN VALUE
AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
successful
EFAILED: If the app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, the app will not be loaded.
SIDE EFFECTS
none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
*ppObj = NULL;
if(ClsId == AEECLSID_SMS)
{
if(AEEApplet_New(sizeof(CSmsApp), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)sms_HandleEvent,(PFNFREEAPPDATA)sms_FreeAppData)
== TRUE)
{
// Add your code here .....
if(sms_InitAppData((CSmsApp *)*ppObj))
{
//Data initialized successfully
return(AEE_SUCCESS);
}
else
{
//Release the applet. This will free the memory allocated for the applet when
// AEEApplet_New was called.
IAPPLET_Release((IApplet*)*ppObj);
return EFAILED;
}
}
}
return (EFAILED);
}
static boolean sms_InitAppData(CSmsApp * pApp)
{
AEEDeviceInfo di;
int fontAscent, fontDscent;
//get screen size
ISHELL_GetDeviceInfo(pApp->a.m_pIShell, &di);
SETAEERECT(&pApp->m_rc, 0, 0, di.cxScreen, di.cyScreen);
//GetFontHeight
if(IDISPLAY_GetFontMetrics(pApp->a.m_pIDisplay, AEE_FONT_NORMAL, &fontAscent, &fontDscent)!=EFAILED)
{
pApp->m_fontHeight = fontAscent + fontDscent + 2;
}
pApp->m_pSoftKey = NULL;
pApp->m_pText = NULL;
return TRUE;
}
static void sms_FreeAppData(CSmsApp * pApp)
{
if(pApp->m_pText)
ITEXTCTL_Release(pApp->m_pText);
if(pApp->m_pSoftKey)
IMENUCTL_Release(pApp->m_pSoftKey);
if(pApp->m_pMessageText)
ITEXTCTL_Release(pApp->m_pMessageText);
if(pApp->m_pMessageSoftKey)
IMENUCTL_Release(pApp->m_pMessageSoftKey);
if(pApp->m_pResultSoftKey)
{
IMENUCTL_Release(pApp->m_pResultSoftKey);
pApp->m_pResultSoftKey = NULL;
}
if(pApp->m_pITAPI)
{
ITAPI_Release(pApp->m_pITAPI);
pApp->m_pITAPI = NULL;
}
if(pApp->m_pStatic)
{
ISTATIC_Release(pApp->m_pStatic);
pApp->m_pStatic = NULL;
}
pApp->m_pText = NULL;
pApp->m_pSoftKey = NULL;
pApp->m_pMessageText = NULL;
pApp->m_pMessageSoftKey = NULL;
}
static void sms_release(CSmsApp * pApp)
{
if(pApp->m_pText!=NULL)
{
ITEXTCTL_GetText(pApp->m_pText, pApp->wStrNum, PHONE_NUM);
ITEXTCTL_Release(pApp->m_pText);
pApp->m_pText = NULL;
}
if(pApp->m_pSoftKey)
{
IMENUCTL_Release(pApp->m_pSoftKey);
pApp->m_pSoftKey = NULL;
}
if(pApp->m_pMessageText!=NULL)
{
ITEXTCTL_GetText(pApp->m_pMessageText, pApp->wStrMessage, MESSAGE_LENGTH);
ITEXTCTL_Release(pApp->m_pMessageText);
pApp->m_pMessageText = NULL;
}
if(pApp->m_pMessageSoftKey)
{
IMENUCTL_Release(pApp->m_pMessageSoftKey);
pApp->m_pMessageSoftKey = NULL;
}
if(pApp->m_pITAPI)
{
ITAPI_Release(pApp->m_pITAPI);
pApp->m_pITAPI = NULL;
}
if(pApp->m_pStatic)
{
ISTATIC_Release(pApp->m_pStatic);
pApp->m_pStatic = NULL;
}
if(pApp->m_pResultSoftKey)
{
IMENUCTL_Release(pApp->m_pResultSoftKey);
pApp->m_pResultSoftKey = NULL;
}
}
/*===========================================================================
FUNCTION sms_HandleEvent
DESCRIPTION
This is the EventHandler for this app. All events to this app are handled in this
function. All APPs must supply an Event Handler.
PROTOTYPE:
boolean sms_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
to this applet. It was initialized during the AEEClsCreateInstance() function.
ecode: Specifies the Event sent to this applet
wParam, dwParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event
SIDE EFFECTS
none
===========================================================================*/
static boolean sms_HandleEvent(CSmsApp * pApp, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
uint16 CurSel;
AECHAR szTitle[20];
AECHAR szText[20];
if((pApp->m_pText!=NULL) &&
(pApp->m_focus== PHONE_NUMBER_TEXT_CTL)&&
ITEXTCTL_HandleEvent(pApp->m_pText, eCode, wParam, dwParam))
return TRUE;
if((pApp->m_pSoftKey!=NULL) &&
(pApp->m_focus==SOFTKEY_OK_CTL)&&
IMENUCTL_HandleEvent(pApp->m_pSoftKey, eCode, wParam, dwParam))
return TRUE;
if((pApp->m_pMessageText!=NULL) &&
(pApp->m_focus== MESSAGE_TEXT_CTL)&&
ITEXTCTL_HandleEvent(pApp->m_pMessageText, eCode, wParam, dwParam))
return TRUE;
if((pApp->m_pMessageSoftKey!=NULL) &&
IMENUCTL_HandleEvent(pApp->m_pMessageSoftKey, eCode, wParam, dwParam))
return TRUE;
if((pApp->m_pResultSoftKey!=NULL) &&
IMENUCTL_HandleEvent(pApp->m_pResultSoftKey, eCode, wParam, dwParam))
return TRUE;
switch (eCode)
{
case EVT_APP_START:
// Add your code here .....
sms_init(pApp);
IMENUCTL_SetActive(pApp->m_pSoftKey, FALSE);
ITEXTCTL_SetActive(pApp->m_pText, TRUE);
return(TRUE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -