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

📄 eggclockappview.cpp

📁 symbian s60环境一个鸡蛋型图像钟表源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      else
      {
        TInt iTotalWidth = pVolume->SizeInPixels().iWidth + CLOCK_SIDE_PADDING;
        TPoint iPoint(Size().iWidth - iTotalWidth, CLOCK_SIDE_PADDING);
        gc.DrawBitmapMasked(TRect(iPoint, pVolume->SizeInPixels()), pVolume, TRect(pVolume->SizeInPixels()), pVolume, ETrue);
      }
    }
  }
}

void CEggClockAppView::SizeChanged()
{
  DrawNow();
}

TBool CEggClockAppView::StartTimer()
{
  if (m_pFlashTimer && m_pFlashTimer->IsActive())
  {
    m_pFlashTimer->Cancel();
  }
  if (m_pTimer && !m_pTimer->IsActive())
  {
    m_pTimer->Start(ONE_SECOND, ONE_SECOND, TCallBack(CEggClockAppView::TimerFired, this));
    DrawNow();
    return ETrue;
  }
  return EFalse;
}

TBool CEggClockAppView::StopTimer()
{
  if (m_pFlashTimer && m_pFlashTimer->IsActive())
  {
    m_pFlashTimer->Cancel();
  }
  if (m_pTimer && m_pTimer->IsActive())
  {
    m_pTimer->Cancel();
  }
  if (m_pFilePlayer && m_iAudioState == eAudioPlaying)
  {
    m_pFilePlayer->Stop();
    m_iAudioState = eAudioReady;
  }
  DrawNow();
  return ETrue;
}

TBool CEggClockAppView::ResetTimer()
{
  if (m_pFlashTimer && m_pFlashTimer->IsActive())
  {
    m_pFlashTimer->Cancel();
  }
  if (m_pTimer && m_pTimer->IsActive())
  {
    m_pTimer->Cancel();
  }
  if (m_pFilePlayer && m_iAudioState == eAudioPlaying)
  {
    m_pFilePlayer->Stop();
    m_iAudioState = eAudioReady;
  }

  m_iRemainingDuration = m_iTotalDuration;

  DrawNow();
  return ETrue;
}

TInt CEggClockAppView::GetDuration()
{
  return m_iTotalDuration;
}

void CEggClockAppView::SetDuration(TInt n_iDuration)
{
  m_iTotalDuration = n_iDuration;
  if (!IsRunning())
  {
    m_iRemainingDuration = m_iTotalDuration;
    DrawNow();
  }
  
  // Save settings for future
  TRAPD(r, SaveSettingsL(); );
}

TBool CEggClockAppView::IsRunning()
{
  if (m_pTimer && m_pTimer->IsActive())
  {
    return ETrue;
  }
  return EFalse;
}

TBool CEggClockAppView::IsReset()
{
  if (m_pTimer && !m_pTimer->IsActive() && m_iTotalDuration == m_iRemainingDuration)
  {
    return ETrue;
  }
  return EFalse;
}

TInt CEggClockAppView::TimerFired(TAny* aPtr)
{
  CEggClockAppView* pThis = (CEggClockAppView*)aPtr;
  if (pThis)
  {
    pThis->DoTimerFired();
  }
  return TRUE;
}

void CEggClockAppView::DoTimerFired()
{
  m_iRemainingDuration--;
  if (m_iRemainingDuration == 0)
  {
    PlayNotificationL();
  }
  if (m_iRemainingDuration < 0 && m_iRepeatMinutes > 0 && m_iRepeatMinutes < INFINITE_MINUTES &&
      ((-m_iRemainingDuration) % (60 * m_iRepeatMinutes)) == 0)
  {
    if (m_iAudioState == eAudioReady)
    {
      m_pFilePlayer->Play();
      m_iAudioState = eAudioPlaying;
    }
  }
  
  DrawNow();
}

void CEggClockAppView::PlayNotificationL()
{
  // Start flashing
  if (m_pFlashTimer && !m_pFlashTimer->IsActive())
  {
    m_bFlash = ETrue;
    m_pFlashTimer->Start(FLASH_TIME, FLASH_TIME, TCallBack(CEggClockAppView::FlashTimerFired, this));
  }
  // Start notification
  if (m_pFilePlayer && m_iAudioState == eAudioReady)
  {
    m_pFilePlayer->SetVolume((m_pFilePlayer->MaxVolume() * m_iVolume) / MAX_VOLUME);
    m_pFilePlayer->Play();
    m_iAudioState = eAudioPlaying;
  }
  
  // Bring application to foreground
  CEikonEnv::Static()->RootWin().SetOrdinalPosition(0);
}

TInt CEggClockAppView::FlashTimerFired(TAny* aPtr)
{
  CEggClockAppView* pThis = (CEggClockAppView*)aPtr;
  if (pThis)
  {
    pThis->DoFlashTimerFired();
  }
  return TRUE;
}

void CEggClockAppView::DoFlashTimerFired()
{
  m_bFlash = !m_bFlash;
  DrawNow();
}

void CEggClockAppView::SetNotificationL(const TDesC& aFileName)
{
  m_iNotificationFile.Copy(aFileName);
  
  // Delete old player
  if (m_pFilePlayer)
  {
    if (m_iAudioState == eAudioPlaying)
    {
      m_pFilePlayer->Stop();
      m_pFilePlayer->Close();
    }
    delete m_pFilePlayer;
    m_pFilePlayer = NULL;
  }

  // Create new file player
  m_iAudioState = eAudioIdle;
  if (m_iNotificationFile.Length() > 0)
  {
#ifndef DRM_PLAYER
    m_pFilePlayer = CMdaAudioPlayerUtility::NewFilePlayerL(m_iNotificationFile, *this, EMdaPriorityNormal, EMdaPriorityPreferenceTime);
#else
    m_pFilePlayer = CDrmPlayerUtility::NewFilePlayerL(m_iNotificationFile, *this, EMdaPriorityNormal, EMdaPriorityPreferenceTime);
#endif
    if (m_pFilePlayer)
    {
      m_iAudioState = eAudioIniting;
    }
  }

  // Save settings for future
  SaveSettingsL();
}

void CEggClockAppView::SetRepeatMinutesL(const TInt iMinutes)
{
  m_iRepeatMinutes = iMinutes;
  
  DrawNow();
  
  // Save settings for future
  SaveSettingsL();
}

TInt CEggClockAppView::GetRepeatMinutes()
{
  return m_iRepeatMinutes;
}

void CEggClockAppView::ChangeVolume(TInt iStep)
{
  if (iStep > 0 && m_iVolume < MAX_VOLUME)
  {
    m_iVolume++;
  }
  if (iStep < 0 && m_iVolume > 0)
  {
    m_iVolume--;
  }
  
  if (m_pFilePlayer && m_iAudioState == eAudioPlaying)
  {
    m_pFilePlayer->SetVolume((m_pFilePlayer->MaxVolume() * m_iVolume) / MAX_VOLUME);
  }
  
  DrawNow();

  TRAPD(r, SaveSettingsL(); );
}

void CEggClockAppView::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
{
  if (KErrNone == aError)
  {
    m_iAudioState = eAudioReady;
  }
  else
  {
    m_iAudioState = eAudioIdle;
    if (m_pFilePlayer)
    {
      delete m_pFilePlayer;
      m_pFilePlayer = NULL;
    }

    TRAPD(r,
      HBufC* pAudioErrorString = CCoeEnv::Static()->AllocReadResourceLC(R_STRING_AUDIO_ERROR);
      CAknErrorNote* pAudioErrorNote = new (ELeave) CAknErrorNote;
      pAudioErrorNote->ExecuteLD(*pAudioErrorString);
      CleanupStack::PopAndDestroy(pAudioErrorString);
    )    
  }
}

void CEggClockAppView::MapcPlayComplete(TInt aError)
{
  if (m_iRepeatMinutes == 0 && m_iAudioState == eAudioPlaying && aError == KErrNone)
  {
    m_pFilePlayer->Play();
  }
  else
  {
    m_iAudioState = eAudioReady;
  }
}

void CEggClockAppView::MdapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration)
{
  MapcInitComplete(aError, aDuration);
}

void CEggClockAppView::MdapcPlayComplete(TInt aError)
{
  MapcPlayComplete(aError);
}

void CEggClockAppView::SaveSettingsL()
{
  RFs iFileSession;
  if (KErrNone == iFileSession.Connect())
  {
    if (KErrNone == iFileSession.CreatePrivatePath(EDriveC))
    {
      if (KErrNone == iFileSession.SetSessionToPrivate(EDriveC))
      {        
        TFileName iFileName;
        iFileSession.PrivatePath(iFileName);
        iFileName.Append(KSettingsFileName);
        
        RFile iFile;
        if (KErrNone == iFile.Replace(iFileSession, iFileName, EFileWrite))
        {
          SETTINGS_BUF* pSettingsBuf = new SETTINGS_BUF();
          if (pSettingsBuf)
          {
            (*pSettingsBuf)().iNotificationFile.Copy(m_iNotificationFile);
            (*pSettingsBuf)().iTotalTime = m_iTotalDuration;
            (*pSettingsBuf)().iVolume = m_iVolume;
            (*pSettingsBuf)().iRepeatMinutes = m_iRepeatMinutes;
          
            iFile.Write((*pSettingsBuf));
            iFile.Flush();
            
            delete pSettingsBuf;
          }
          iFile.Close();
        }
      }
    }
    iFileSession.Close();
  }
}

void CEggClockAppView::LoadSettingsL()
{
  RFs iFileSession;
  if (KErrNone == iFileSession.Connect())
  {
    if (KErrNone == iFileSession.SetSessionToPrivate(EDriveC))
    {
      TFileName iFileName;
      iFileSession.PrivatePath(iFileName);
      iFileName.Append(KSettingsFileName);
      
      RFile iFile;
      if (KErrNone == iFile.Open(iFileSession, iFileName, EFileRead))
      {
        SETTINGS_BUF* pSettingsBuf = new SETTINGS_BUF();
        if (pSettingsBuf)
        {
          iFile.Read(*pSettingsBuf);

          if ((*pSettingsBuf)().iTotalTime < 0) (*pSettingsBuf)().iTotalTime = 0;
          if ((*pSettingsBuf)().iTotalTime > 5999) (*pSettingsBuf)().iTotalTime = 5999;
          if ((*pSettingsBuf)().iVolume < 0) (*pSettingsBuf)().iVolume = 0;
          if ((*pSettingsBuf)().iVolume > MAX_VOLUME) (*pSettingsBuf)().iVolume = MAX_VOLUME;
          if ((*pSettingsBuf)().iRepeatMinutes < 0) (*pSettingsBuf)().iRepeatMinutes = 0;

          m_iTotalDuration = (*pSettingsBuf)().iTotalTime;
          m_iRemainingDuration = (*pSettingsBuf)().iTotalTime;
          m_iNotificationFile.Copy((*pSettingsBuf)().iNotificationFile);
          m_iVolume = (*pSettingsBuf)().iVolume;
          m_iRepeatMinutes = (*pSettingsBuf)().iRepeatMinutes;
          
          delete pSettingsBuf;

          //iEikonEnv->InfoMsg(m_iNotificationFile);
        }
        iFile.Close();        
      }
    }
    iFileSession.Close();
  }
}

⌨️ 快捷键说明

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