⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ringertest.c

📁 复件 使用IRINGERMGR接口设置手机铃声的例子
💻 C
📖 第 1 页 / 共 2 页
字号:
/*===========================================================================

FILE: RingerTest.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEEFile.h"			// File interface definitions
#include "AEEStdLib.h"
#include "AEERinger.h"
#include "AEEMenu.h"
#include "ringertest.bid"


typedef struct _CRingerTest
{
	AEEApplet		a;				// AEE Applet
	IFileMgr	*	m_pIFileMgr;	// File Manager
	IFile		*	m_pIFile;		// File Object
	IMenuCtl	*	m_pIMainMenu;	// Main Menu
	IMenuCtl	*	m_pISoftMenu;	// Soft-Key Menu
	IRingerMgr  *	m_pIRingerMgr;
	IMemAStream *	m_pMemStream;
	IStatic		*	m_pIStatic;
	AECHAR		*   m_pszText;
	byte		*	m_pBuff;
	AECHAR			m_szTitle[20];
} CRingerTest;

const char * FormatList[] = { "UNKNOWN\n", "MIDI\n", "MP3\n", "LAST\n" };

#define RT_CREATE			100
#define RT_ENUMCATEGORY		101
#define RT_ENUMRINGER		102
#define RT_RINGERFORMAT		103
#define RT_PLAY				104
#define RT_SETRINGER		105
#define RT_REMOVE			106

#define SOFTMENU_BACK		400

#define TEXT_BUFFER_SIZE (1024 * sizeof(AECHAR))
#define BOTTOM_TEXT_HEIGHT			15

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean RingerTest_HandleEvent(IApplet * pi, AEEEvent eCode, 
                                      uint16 wParam, uint32 dwParam);

static boolean RingerTest_InitAppData(CRingerTest * pMe);
static void RingerTest_FreeAppData(CRingerTest * pMe);
static void DisplayText(CRingerTest * pMe);
static void BuildMainMenu(CRingerTest * pMe);
static boolean CreateRinger(CRingerTest * pMe, const char * ringername, 
						const char * inputfile, AEESoundPlayerFile format);
static void CleanUp(CRingerTest * pMe);

static AEERingerID GetFirstRingerID(CRingerTest * pMe);

/*===============================================================================
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_RINGERTEST)
	{
		if(AEEApplet_New(sizeof(CRingerTest), ClsId, pIShell,po, (IApplet**)ppObj,
			(AEEHANDLER)RingerTest_HandleEvent,NULL) == TRUE)
		{
			return (AEE_SUCCESS);
		}
	}
	
	return (EFAILED);
}

/*===========================================================================

FUNCTION RingerTest_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 RingerTest_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 RingerTest_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  
	CRingerTest * pMe = (CRingerTest *) pi;
	char szBuf[100];

	switch (eCode) 
	{
		case EVT_APP_START:
			if (!RingerTest_InitAppData(pMe))
				return FALSE;
			BuildMainMenu(pMe);
			IDISPLAY_Update(pMe->a.m_pIDisplay);
			return(TRUE);

		case EVT_APP_STOP:
			RingerTest_FreeAppData(pMe);
			return TRUE;

		case EVT_APP_SUSPEND:
			return TRUE;
	  
		case EVT_APP_RESUME:
			return TRUE;
	
		case EVT_KEY:
			//If Main Menu is Active let it handle the event
			if(pMe->m_pIMainMenu && IMENUCTL_IsActive(pMe->m_pIMainMenu))
			{
				CleanUp(pMe);
				return IMENUCTL_HandleEvent(pMe->m_pIMainMenu, EVT_KEY, wParam, 0);
			}
		
			//If Soft Menu is Active let it handle the event		
			if(pMe->m_pISoftMenu && IMENUCTL_IsActive(pMe->m_pISoftMenu))
			{
		
				switch(wParam)
				{
				case AVK_CLR:
					// Go back to the mainmenu
					ISTATIC_Release (pMe->m_pIStatic);
					pMe->m_pIStatic = NULL;

					IMENUCTL_SetActive(pMe->m_pISoftMenu, FALSE);
					IMENUCTL_SetActive(pMe->m_pIMainMenu, TRUE);
					IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
					IMENUCTL_Redraw(pMe->m_pIMainMenu);
					return TRUE;
			
				default:
					return IMENUCTL_HandleEvent(pMe->m_pISoftMenu, EVT_KEY, wParam, 0);
				}
			}

			return FALSE;

		case EVT_COMMAND:
			switch (wParam)
			{
			case RT_CREATE:
				STRTOWSTR("Create", pMe->m_szTitle, sizeof(pMe->m_szTitle));

				if (TRUE != CreateRinger(pMe, "ring0", "ringer0.mid", AEE_SOUNDPLAYER_FILE_MIDI))
				{
					DBGPRINTF("Create ring0 failed!");
					STRCPY(szBuf, "Create ring0 failed!\n");
				}
				else
				{
					DBGPRINTF("Create ring0 successfully!");
					STRCPY(szBuf, "Create ring0 successfully!\n");
				}
				
				if (TRUE != CreateRinger(pMe, "ring1", "ringer1.mid", AEE_SOUNDPLAYER_FILE_MIDI))
				{
					DBGPRINTF("Create ring1 failed!");
					STRCAT(szBuf, "Create ring1 failed!");
				}
				else
				{
					DBGPRINTF("Create ring1 successfully!");
					STRCAT(szBuf, "Create ring1 successfully!");
				}
				STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
				IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
				DisplayText(pMe);

				return TRUE;
				
			case RT_ENUMCATEGORY:
				{
					AEERingerCat catinfo;
					AECHAR szFormat[30], szText[70];

					STRTOWSTR("EnumCategory", pMe->m_szTitle, sizeof(pMe->m_szTitle));

					ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_RINGERMGR, (void **)&pMe->m_pIRingerMgr); 
					if(pMe->m_pIRingerMgr == NULL)
					{
						DBGPRINTF("Create RingerMgr failed!");
						STRCPY(szBuf, "Create RingerMgr failed!");
						STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
						IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
						DisplayText(pMe);
						return TRUE;
					}

					if(SUCCESS != IRINGERMGR_EnumCategoryInit(pMe->m_pIRingerMgr))
					{
						DBGPRINTF("EnumCTG failed!");
						CleanUp(pMe);
						STRCPY(szBuf, "EnumCateInit failed!");
						STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
						IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
						DisplayText(pMe);

						return TRUE;
					}
				 
					DBGPRINTF("EnumCTG Begin:");
					MEMSET(pMe->m_pszText, 0, TEXT_BUFFER_SIZE);

					while(IRINGERMGR_EnumNextCategory(pMe->m_pIRingerMgr,&catinfo))
					{
						DBGPRINTF("CATEGORY ID: %u", catinfo.id);
						DBGPRINTF("RINGER ID: %u", catinfo.idRinger);
						DBGPRINTF("NAME: %S", catinfo.szName);
//						STRTOWSTR("CATEGORY ID: %u\nRINGER ID: %u\nNAME: %s\n", szFormat, sizeof(szFormat));
//						WSPRINTF(szText, sizeof(szText), szFormat, catinfo.id, catinfo.idRinger, catinfo.szName);
						STRTOWSTR("CATEGORY NAME: %s \n", szFormat, sizeof(szFormat));
						WSPRINTF(szText, sizeof(szText), szFormat, catinfo.szName);
						WSTRCAT(pMe->m_pszText, szText);
					}
				}
				
				CleanUp(pMe);
				IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
				DisplayText(pMe);
				
				return TRUE;
				
			case RT_ENUMRINGER:
				{
				  
					AEERingerInfo ringerinfo;
					AECHAR szFormat[30], szText[70];

					STRTOWSTR("EnumRinger", pMe->m_szTitle, sizeof(pMe->m_szTitle));
					ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_RINGERMGR, (void **)&pMe->m_pIRingerMgr); 
					if(pMe->m_pIRingerMgr == NULL)
					{
						DBGPRINTF("Create RingerMgr failed!");
						STRCPY(szBuf, "Create RingerMgr failed!");
						STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
						IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
						DisplayText(pMe);
						return TRUE;
					}

					if (SUCCESS != IRINGERMGR_EnumRingerInit(pMe->m_pIRingerMgr))
					{
						DBGPRINTF("EnumRing failed!");
						CleanUp(pMe);
						STRCPY(szBuf, "EnumRinger failed!");
						STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
						IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
						DisplayText(pMe);
						return TRUE;
					}
					MEMSET(pMe->m_pszText, 0, TEXT_BUFFER_SIZE);

					while(IRINGERMGR_EnumNextRinger(pMe->m_pIRingerMgr, &ringerinfo))
					{
						DBGPRINTF("RINGER ID: %u", ringerinfo.id);
						DBGPRINTF("FORMAT: %u", ringerinfo.format);
						DBGPRINTF("NAME: %s", ringerinfo.szName);
						if (ringerinfo.szFile) // can be NULL if read only
						{
							DBGPRINTF("FILE: %s", ringerinfo.szFile);
						}
//						STRTOWSTR("RINGER ID: %u\nFormat: %u\nNAME: %s\n", szFormat, sizeof(szFormat));
//						WSPRINTF(szText, sizeof(szText), szFormat, ringerinfo.id, ringerinfo.format, ringerinfo.szName);
						STRTOWSTR("NAME: %s \n", szFormat, sizeof(szFormat));
						WSPRINTF(szText, sizeof(szText), szFormat, ringerinfo.szName);
						WSTRCAT(pMe->m_pszText, szText);
					}
				}
				CleanUp(pMe);

				IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
				DisplayText(pMe);
				return TRUE;

			case RT_RINGERFORMAT:
				{
					AEESoundPlayerFile pwFormats[4];
					int NumberOfFormats = -1, i;
					
					STRTOWSTR("RingerFormat", pMe->m_szTitle, sizeof(pMe->m_szTitle));
					ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_RINGERMGR, (void **)&pMe->m_pIRingerMgr); 
					if(pMe->m_pIRingerMgr == NULL)
					{
						DBGPRINTF("Create RingerMgr failed!");
						STRCPY(szBuf, "Create RingerMgr failed!");
						STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
						IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
						DisplayText(pMe);
						return TRUE;
					}

					NumberOfFormats = IRINGERMGR_GetNumberFormats(pMe->m_pIRingerMgr);
					IRINGERMGR_GetFormats(pMe->m_pIRingerMgr, pwFormats, NumberOfFormats);
					
					STRCPY(szBuf, "Support Format: \n");

					for (i = 0; i<NumberOfFormats; i++)
					{
						DBGPRINTF("Support Format: %d", (int)pwFormats[i]);
						STRCAT(szBuf, FormatList[(int)pwFormats[i]]);						
					}

  					CleanUp(pMe);
				}

				STRTOWSTR(szBuf, pMe->m_pszText, TEXT_BUFFER_SIZE);
				IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
				DisplayText(pMe);
				return TRUE;
				
			case RT_PLAY:
				{
					AEERingerID ringId = GetFirstRingerID(pMe);
					STRTOWSTR("Play", pMe->m_szTitle, sizeof(pMe->m_szTitle));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -