Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

IFlip sample code, part 3

Definition and implementation of the SampleAppWizard_HandleEvent() function

/*===========================================================================
FUNCTION SampleAppWizard_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 SampleAppWizard_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 c_iflipapp_HandleEvent(c_iflipapp* pMe, 
                                      AEEEvent eCode, 
                                      uint16 wParam, 
                                      uint32 dwParam)
{  
   DBGPRINTF("eCode=%d wParam=%d",eCode,wParam);

   if (pMe->pIStatic && ISTATIC_HandleEvent(pMe->pIStatic, eCode, wParam, dwParam))
      return TRUE;

   switch (eCode) 
   {
        // App is told it is starting up
      case EVT_APP_START:                        
	     c_iflipapp_DrawScreen(pMe, pMe->currentAppState);    
      return(TRUE);
      // App is told it is exiting
      case EVT_APP_STOP:
	  // Send event to Background application to stop it
         ISHELL_PostEvent(pMe->pIShell, AEECLSID_C_BGAPP, EVT_BGAPP_STOP, NULL, NULL);
      return(TRUE);
	  case BGAPP_FLIP_EVENT_RECEIVED:
	  // Notified from Background application for flip event
		c_iflipapp_ackBGapp(pMe, BGAPP_FLIP_EVENT_RECEIVED);
	  return TRUE;
	  case EVT_BGAPP_KEYGAURD_EVENT_RECEIVED:
      // Notified from Background application for keyguard event
        c_iflipapp_ackBGapp(pMe, EVT_BGAPP_KEYGAURD_EVENT_RECEIVED);
      return TRUE;
	  case EVT_BGAPP_SCREENROTATE_RECEIVED:
      // Notified from Background application for screen rotate event
        c_iflipapp_ackBGapp(pMe, EVT_BGAPP_SCREENROTATE_RECEIVED);
      return TRUE;
      // Handling EVT_FlIP event
	  case EVT_FLIP:
         {
            int i=0,x=-1,y=-1,z=-1,id;
			pMe->bIsFlip = TRUE;
			// Reset buffer
			MEMSET(pMe->pAckFromBGapp, 0, TEXT_BUFFER_SIZE);

			// let's find out current position when flip open/closed and do action accordingly.
			for (i=0; i < pMe->nNumberOfFlip; ++i)
			{
            if( SUCCESS == IFLIP_GetFlipPosition(pMe->pIFlip,
                                                ((pMe->pFlipInfoListOnFlipEvents)+i)))
			   {	
						id=DEVNOTIFY_GET_ID(*((pMe->pFlipInfoListOnFlipEvents)+i));
						x= DEVNOTIFY_GET_X(*((pMe->pFlipInfoListOnFlipEvents)+i));
						y= DEVNOTIFY_GET_Y(*((pMe->pFlipInfoListOnFlipEvents)+i));
						z= DEVNOTIFY_GET_Z(*((pMe->pFlipInfoListOnFlipEvents)+i));
						DBGPRINTF("Flip id=%d,X =%d,Y=%d,Z=%d",id,x,y,z);
					}
				}

            if(wParam)
			{
			   DBGPRINTF("Flip Opened"); 

			   // Display the accessed keylist(when flip was closed) on primary display   
               if(SECONDARY_SCR == pMe->currentAppState)
			   {

			      IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
				  ISTATIC_SetText(pMe->pIStatic, L"KeyList(Flip close)", NULL, AEE_FONT_BOLD, NULL);
                  ISTATIC_SetTextEx(pMe->pIStatic, (byte*)pMe->pCloseKeyList, NULL, FALSE);
                  IDISPLAY_DrawText(pMe->a.m_pIDisplay, 
                                    AEE_FONT_NORMAL, 
                                    L"NEXT", -1, 0, 0, NULL , 
                                    IDF_ALIGN_RIGHT|IDF_ALIGN_BOTTOM);
				  ISTATIC_Redraw(pMe->pIStatic);
                  IDISPLAY_Update(pMe->a.m_pIDisplay);
				  pMe->currentAppState = SEC_KEYLIST_OUTPUT_SCR;
			   }
			   else
			   {
				  c_iflipapp_DrawScreen(pMe, pMe->currentAppState);
			   }

			   // Play the audio if flip opens
			   if (x==180 || y==180 || z==180)
			   {
			      c_iflipapp_PlayAudio(pMe, "media/flip180.qcp");
			   }
			   else if (x==90 || y==90 || z==90)
			   {
			      c_iflipapp_PlayAudio(pMe, "media/flip90.qcp");
			   }

			}
			else
			{
				  DBGPRINTF("Flip Closed"); 
				
				  /* Gets the keylist when flip is closed but don't show it here
				   it will be shown when primary display gets available again.
				  */
				  c_iflipapp_DrawScreen(pMe, SEC_KEYLIST_OUTPUT_SCR);

				  // Display message on secondary display
				  c_iflipapp_DrawScreen(pMe, SECONDARY_SCR);
				
				  if(x==0 || y==0 || z==0)
				  {
					
				     // Flip closed at 0 degree
					 c_iflipapp_PlayAudio(pMe, "media/flip0.qcp");
				  }
			}
		 }
		 return TRUE;
			
      case EVT_KEYGUARD:
         DBGPRINTF("EVT_KEYGUARD");

		    // No need to call this block for flip phones
		    if (pMe->bIsFlip) 
			{
			   DBGPRINTF("Break for flip phones");
			   return TRUE;
			}
			else if (!pMe->DeviceInfo.bFlip) // Call only for slider phones
			{
			   int i = 0, x = -1, y = -1, z = -1, id;
			   // Clean the buffer
			   MEMSET(pMe->pAckFromBGapp, 0, TEXT_BUFFER_SIZE);

			   // let's find out current position when flip open/closed and do action accordingly.

			   DBGPRINTF("bFlip EVT_KEYGUARD");
			   for (i=0; i < pMe->nNumberOfFlip;++i)
			   {
			      if (SUCCESS == IFLIP_GetFlipPosition(pMe->pIFlip,
                                             ((pMe->pFlipInfoListOnFlipEvents)+i)))
				  {
                     id=DEVNOTIFY_GET_ID(*((pMe->pFlipInfoListOnFlipEvents)+i));
					 x= DEVNOTIFY_GET_X(*((pMe->pFlipInfoListOnFlipEvents)+i));
					 y= DEVNOTIFY_GET_Y(*((pMe->pFlipInfoListOnFlipEvents)+i));
					 z= DEVNOTIFY_GET_Z(*((pMe->pFlipInfoListOnFlipEvents)+i));
					
					 DBGPRINTF("flip id=%d,id=%d,X =%d,Y=%d,Z=%d",pMe->nCurrentFlip,id,x,y,z);
				  }
			   }
				
			   if(wParam)
			   {
                  DBGPRINTF("Slider Closed");
				  // Display the accesed keylist when slider is closed
				  c_iflipapp_DrawScreen(pMe, SLIDER_KEYLIST_CLOSED_SCR);
				  // play the audio when slider is closed
				  c_iflipapp_PlayAudio(pMe, "media/slider0.qcp");
			   }
			   else
			   {
                  DBGPRINTF("Slider Open");
    			  // Disoplay the accesed keylist when slider is opened
				  c_iflipapp_DrawScreen(pMe, SLIDER_KEYLIST_OPENED_SCR);
                  if (x==180 || y==180 || z==180)
				  {
                     if(x==180) DBGPRINTF("X 180");
				     if(y==180) DBGPRINTF("Y 180");
					 if(z==180) DBGPRINTF("Z 180");
                     c_iflipapp_PlayAudio(pMe, "media/slider180.qcp");
				  }
			   }
			}

			return TRUE;
      case EVT_SCR_ROTATE:
	     DBGPRINTF("EVT_SCR_ROTATE");
	  return TRUE;
	  case EVT_NOTIFY:
         if (dwParam)
			{
			   AEENotify * pNotify = (AEENotify *) dwParam;
               AEEDeviceNotify * pDevNotify = NULL;
			      if (AEECLSID_DEVICENOTIFIER == pNotify->cls)
				  {
                     // Check for Flip Notification
                     if (NMASK_DEVICENOTIFIER_FLIP == pNotify->dwMask)
					 {
					    pDevNotify = (AEEDeviceNotify *) pNotify->pData;
                           if (pDevNotify->wParam)
						   {
						      DBGPRINTF("Flip open notification");
						   }
						   else
						   {
						      DBGPRINTF("Flip close notification");
						   }
					 } 
                     // Check for Keyguard notification
					 else if (NMASK_DEVICENOTIFIER_KEYGUARD == pNotify->dwMask)
					 {
                        pDevNotify = (AEEDeviceNotify *) pNotify->pData;
                           if (pDevNotify->wParam)
						   {
						      DBGPRINTF("keyguard on notification");
						   }
						   else
						   {
						      DBGPRINTF("keyguard off notification");
						   }
					 } 
					 // Check for Screen Rotate notification
                     else if (NMASK_DEVICENOTIFIER_SCR_ROTATE == pNotify->dwMask)
					 {
						pDevNotify = (AEEDeviceNotify *) pNotify->pData;
    					   if (AEE_SO_PORTRAIT == (AEEScrOrientation)pDevNotify->wParam)
						   {
						      DBGPRINTF("Screen rotate portrait notification");
						   }
						   else if (AEE_SO_LANDSCAPE == (AEEScrOrientation)pDevNotify->wParam)
						   {
						      DBGPRINTF("Screen rotate landscape notification");
						   }
					 }
				  }
		    }
			return TRUE;
      // App is being suspended 
      case EVT_APP_SUSPEND:
	     DBGPRINTF("EVT_APP_SUSPEND");
	  // Deactivate istatic control
	     if( pMe->pIStatic)
		 {
		    ISTATIC_SetActive( pMe->pIStatic, FALSE );
		 }
      return(TRUE);
      // App is being resumed
      case EVT_APP_RESUME:
	     DBGPRINTF("EVT_APP_RESUME");
		    if( pMe->pIStatic)
			{
				ISTATIC_SetActive( pMe->pIStatic, TRUE );
			}
     		// Draw that screen before application was suspended
			c_iflipapp_DrawScreen(pMe, pMe->currentAppState);

      return(TRUE);
	  case EVT_POINTER_UP:
		 {
            int x0, y0;

            // Getting X and Y coordinates of pointer
            AEE_POINTER_GET_XY((char *)dwParam, &x0, &y0);
			
			// Process only when touched under the 'Next' button
			if ((x0 < pMe->DeviceInfo.cxScreen) && 
      (x0 > pMe->DeviceInfo.cxScreen - SOFT_KEY_WIDTH) &&
			   (y0 < pMe->DeviceInfo.cyScreen) && 
      (y0 > pMe->DeviceInfo.cyScreen - SOFT_KEY_HEIGHT))
			{
			   DBGPRINTF("Pressed under scope");
			   switch (pMe->currentAppState)
			   {
			      case PRIMARY_OUTPUT_SCR:
				     if (pMe->DeviceInfo.bFlip || pMe->bIsFlip)
					 {
					    c_iflipapp_DrawScreen(pMe, PRI_KEYLIST_OUTPUT_SCR);
					 }
					 else
					 {
					    int pnSize = 1;
						boolean pBuf = TRUE;
						// Check the current state of slider
						ISHELL_GetDeviceInfoEx(pMe->pIShell, 
                             AEE_DEVICESTATE_KEYGUARD_ON, 
                             (void*)&pBuf, &pnSize);
						if(pBuf)    // Keyguard is on If true
						{
						   DBGPRINTF("Slider is closed");
						   c_iflipapp_DrawScreen(pMe, SLIDER_KEYLIST_CLOSED_SCR);
						}
						else        // Keyguard is off if pBuf is false
						{
						   DBGPRINTF("Slider is opened");
						   c_iflipapp_DrawScreen(pMe, SLIDER_KEYLIST_OPENED_SCR);
						}
					 }

					break;
				  case PRI_KEYLIST_OUTPUT_SCR:
				  case SLIDER_KEYLIST_OPENED_SCR:
				  case SLIDER_KEYLIST_CLOSED_SCR:
				  case SEC_KEYLIST_OUTPUT_SCR:
				     c_iflipapp_DrawScreen(pMe, PRIMARY_OUTPUT_SCR);
				  break;
			   }
			}
			else
			{
			   DBGPRINTF("Pressed outside scope");
			}
		 }
      return TRUE;
      case EVT_KEY:
		 DBGPRINTF("EVT_KEY");
         if( NOTICE_SCR == pMe->currentAppState)
		 {
		    c_iflipapp_DrawScreen(pMe, PRIMARY_OUTPUT_SCR);
		 }
         switch(wParam)
		 {
		    case AVK_SOFT2:
			   switch (pMe->currentAppState)
			   {
			      case PRIMARY_OUTPUT_SCR:
					 {
					    if(pMe->DeviceInfo.bFlip || pMe->bIsFlip)
						{
						   c_iflipapp_DrawScreen(pMe, PRI_KEYLIST_OUTPUT_SCR);
						}
						else
						{
						   int pnSize = 1;
						   boolean pBuf = TRUE;
						   // Check for the current state of slider
						   ISHELL_GetDeviceInfoEx(pMe->pIShell, 
                                AEE_DEVICESTATE_KEYGUARD_ON, 
                                (void*)&pBuf, &pnSize);
						   if(pBuf)  // Keyguard is on If true
						   {
						      DBGPRINTF("Slider is closed");
							  c_iflipapp_DrawScreen(pMe, SLIDER_KEYLIST_CLOSED_SCR);
						   }
						   else    // Keyguard is off if pBuf is false
						   {
						      DBGPRINTF("Slider is opened");
							  c_iflipapp_DrawScreen(pMe, SLIDER_KEYLIST_OPENED_SCR);
						   }
						}
					 }
					break;
				  case PRI_KEYLIST_OUTPUT_SCR:
				  case SLIDER_KEYLIST_OPENED_SCR:
				  case SLIDER_KEYLIST_CLOSED_SCR:
				  case SEC_KEYLIST_OUTPUT_SCR:
				     c_iflipapp_DrawScreen(pMe, PRIMARY_OUTPUT_SCR);
				  break;
			   }
			break;
		 }
      return(TRUE);

	  case EVT_KEY_PRESS:
         DBGPRINTF("EVT_KEY_PRESS");
         switch(wParam)
		 {
		    case AVK_CLR:
				ISHELL_CloseApplet(pMe->pIShell, FALSE);
        	return TRUE;
		 }
	  return TRUE;

	  case EVT_KEY_RELEASE:
         DBGPRINTF("EVT_KEY_RELEASE");
	  return TRUE;
        // If nothing fits up to this point then we'll just break out
        default:
            break;
   }

   return FALSE;
}