📄 qiqiweatherappui.cpp
字号:
/*
============================================================================
Name : QiQiWeatherAppUi.cpp
Author : Richie Chyi
Copyright : Copyright?2008
Description : CQiQiWeatherAppUi implementation
============================================================================
*/
// INCLUDE FILES
#include <avkon.hrh>
#include <aknmessagequerydialog.h>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <f32file.h>
#include <s32file.h>
#include <hlplch.h>
#include <aknnavide.h> // For CAknNavigationDecorator
#include <BARSREAD.H> // For TResourceReader
#include <eikspane.h> // For CEikStatusPane
#include <aknnavi.h> // For CAknNavigationControlContainer
#include <akntabgrp.h> // For CAknTabGroup
#include <APGTASK.H> // For TApaTaskList
#include <QiQiWeather_0xE6E51F33.rsg>
#include "QiQiWeather_0xE6E51F33.hlp.hrh"
#include "QiQiWeather.hrh"
#include "QiQiWeather.pan"
#include "QiQiWeatherApplication.h"
#include "QiQiWeatherAppUi.h"
#include "QiQiWeatherAppView.h"
#include "WeatherShow.h"
#include "SettingDlg.h"
#include "Setting.h"
_LIT(KFileName, "C:\\private\\E6E51F33\\QiQiWeather.txt");
_LIT(KText, "Hello World!");
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CQiQiWeatherAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CQiQiWeatherAppUi::ConstructL()
{
// Initialise app UI with standard value.
BaseConstructL(CAknAppUi::EAknEnableSkin);
//SetHidden(ETrue);
//CEikonEnv::Static()->RootWin().SetOrdinalPosition(0, ECoeWinPriorityNeverAtFront);
// Create view object
iAppView = CQiQiWeatherAppView::NewL(this, ClientRect() );
iPeriodic = CPeriodic::NewL(CActive::EPriorityStandard);
iPeriodic->Start(TTimeIntervalMicroSeconds32(KDelay),
TTimeIntervalMicroSeconds32(KInterval),
TCallBack(CQiQiWeatherAppUi::ShowWeatherInfoL, this));
// Create Setting file
CSetting* setting = CSetting::NewLC();
// 设置默认值
if (!setting->IsSaved())
{
// 根据当前时间设定特定值,保证第一次运行程序时,立马预报天气
TTime currentTime;
currentTime.HomeTime();
TDateTime dateTime = currentTime.DateTime();
setting->SetCityIndex(0);
setting->SetHour(dateTime.Hour());
setting->SetMinute(dateTime.Minute() - 10); // 设定当前时间前十秒
setting->SaveToFileL();
}
CleanupStack::PopAndDestroy(setting);
// Create Pane Tabs
TUid naviPaneUid;
naviPaneUid.iUid = EEikStatusPaneUidNavi;
CEikStatusPane* statusPane = StatusPane();
CEikStatusPaneBase::TPaneCapabilities subPane =
statusPane->PaneCapabilities(naviPaneUid);
// if we can access the navigation pane
if (subPane.IsPresent() && subPane.IsAppOwned())
{
CAknNavigationControlContainer* naviPane =
(CAknNavigationControlContainer *) statusPane->ControlL(naviPaneUid);
// read the tab group resource
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_NAVIGATIONPANE_TABGROUP);
if (iNaviDecorator)
{
delete iNaviDecorator;
iNaviDecorator = NULL;
}
// set the navigation pane tab group
iNaviDecorator = naviPane->CreateTabGroupL(reader);
CleanupStack::PopAndDestroy(); // pushed by CreateResourceReaderLC
naviPane->PushL(*iNaviDecorator);
}
// Create a file to write the text to
TInt err = CCoeEnv::Static()->FsSession().MkDirAll(KFileName);
if ( (KErrNone != err) && (KErrAlreadyExists != err))
{
return;
}
RFile file;
err = file.Replace(CCoeEnv::Static()->FsSession(), KFileName, EFileWrite);
CleanupClosePushL(file);
if (KErrNone != err)
{
CleanupStack::PopAndDestroy(1); // file
return;
}
RFileWriteStream outputFileStream(file);
CleanupClosePushL(outputFileStream);
outputFileStream << KText;
CleanupStack::PopAndDestroy(2); // outputFileStream, file
}
// -----------------------------------------------------------------------------
// CQiQiWeatherAppUi::CQiQiWeatherAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CQiQiWeatherAppUi::CQiQiWeatherAppUi()
:iNaviDecorator(NULL), iCurrentTabIndex(0)
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CQiQiWeatherAppUi::~CQiQiWeatherAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CQiQiWeatherAppUi::~CQiQiWeatherAppUi()
{
if (iAppView)
{
delete iAppView;
iAppView = NULL;
}
if(iPeriodic->IsActive())
{
iPeriodic->Cancel();
}
delete iPeriodic;
iPeriodic = NULL;
if (iNaviDecorator)
{
delete iNaviDecorator;
iNaviDecorator = NULL;
}
iWeatherDetails.Reset();
}
// -----------------------------------------------------------------------------
// CQiQiWeatherAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CQiQiWeatherAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
case ESetting:
{
if (CSettingDlg::RunDlgLD())
{
// TODO:...
}
}
break;
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
SetHidden(ETrue);
//CEikonEnv::Static()->RootWin().SetOrdinalPosition(0, ECoeWinPriorityNeverAtFront);
break;
case EHelp:
{
CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
}
break;
case EAbout:
{
CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog();
dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
dlg->QueryHeading()->SetTextL(*title);
CleanupStack::PopAndDestroy(); //title
HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
dlg->SetMessageTextL(*msg);
CleanupStack::PopAndDestroy(); //msg
dlg->RunLD();
}
break;
case EHidden:
{
//SetHidden(ETrue);
//CEikonEnv::Static()->RootWin().SetOrdinalPosition(0, ECoeWinPriorityNeverAtFront);
// 使用上面的隐藏,再点击图标后,会创建一个新进程实例,而不是将已存在进程调至前台
TApaTask task(CEikonEnv::Static()->WsSession());
task.SetWgId(CEikonEnv::Static()->RootWin().Identifier());
task.SendToBackground();
}
break;
case ERefresh:
{
CWeatherShow* weatherShow = CWeatherShow::NewLC();
weatherShow->ShowWeatherL();
CleanupStack::PopAndDestroy(weatherShow);
}
break;
default:
Panic(EQiQiWeatherUi);
break;
}
}
// -----------------------------------------------------------------------------
// Called by the framework when the application status pane
// size is changed. Passes the new client rectangle to the
// AppView
// -----------------------------------------------------------------------------
//
void CQiQiWeatherAppUi::HandleStatusPaneSizeChange()
{
iAppView->SetRect(ClientRect() );
}
CArrayFix<TCoeHelpContext>* CQiQiWeatherAppUi::HelpContextL() const
{
#warning "Please see comment about help and UID3..."
// Note: Help will not work if the application uid3 is not in the
// protected range. The default uid3 range for projects created
// from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so that they
// can be self signed and installed on the device during testing.
// Once you get your official uid3 from Symbian Ltd. and find/replace
// all occurrences of uid3 in your project, the context help will
// work.
CArrayFixFlat<TCoeHelpContext>* array = new(ELeave)CArrayFixFlat<TCoeHelpContext>(1);
CleanupStack::PushL(array);
array->AppendL(TCoeHelpContext(KUidQiQiWeatherApp, KGeneral_Information));
CleanupStack::Pop(array);
return array;
}
TKeyResponse CQiQiWeatherAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
CAknNavigationDecorator* navi = iNaviDecorator;
// if we haven't already got a navigation decorator, then try to get current one
if (navi == NULL)
{
TUid naviPaneUid;
naviPaneUid.iUid = EEikStatusPaneUidNavi;
CEikStatusPane* statusPane = StatusPane();
CAknNavigationControlContainer* naviPane =
(CAknNavigationControlContainer *) statusPane->ControlL(naviPaneUid);
navi = naviPane->Top();
}
if (navi == NULL)
{
return EKeyWasNotConsumed;
}
CAknTabGroup* tabGroup = (CAknTabGroup*) navi->DecoratedControl();
if (tabGroup == NULL)
{
return EKeyWasNotConsumed;
}
// 更新TabIndex
switch (aKeyEvent.iCode)
{
case EKeyLeftArrow:
{
if (0 < iCurrentTabIndex)
{
--iCurrentTabIndex;
}
}
break;
case EKeyRightArrow:
{
if (KTabCount - 1 > iCurrentTabIndex)
{
++iCurrentTabIndex;
}
}
break;
default:
break;
}
// 更新天气详情
if (aType == EEventKeyUp) // 只需更新一次
{
iAppView->UpdateWeather(iCurrentTabIndex);
}
// if we've got a tab group, then offer the key event to it.
return tabGroup->OfferKeyEventL(aKeyEvent, aType);
}
TInt CQiQiWeatherAppUi::ShowWeatherInfoL(TAny* /*aArgument*/)
{
TTime currentTime;
currentTime.HomeTime();
TDateTime dateTime = currentTime.DateTime();
CSetting* setting = CSetting::NewLC();
setting->ReadFromFileL();
// 以分钟数为参照进行对比
TInt minutes = setting->Hour()*60 + setting->Minute();
TInt currentMinutes = dateTime.Hour()*60 + dateTime.Minute();
// 当前时间超过设定时间,且两者时间差不超过Interval
if (minutes < currentMinutes
&& KInterval/(60*1000000) > (currentMinutes - minutes))
{
CQiQiWeatherAppUi* appui =
static_cast<CQiQiWeatherAppUi*>(CEikonEnv::Static()->AppUi());
if (appui)
{
CEikonEnv::Static()->RootWin().SetOrdinalPosition(0, ECoeWinPriorityNormal);
appui->SetHidden(EFalse);
}
CWeatherShow* weatherShow = CWeatherShow::NewLC();
weatherShow->ShowWeatherL();
CleanupStack::PopAndDestroy(weatherShow);
}
return 0;
}
void CQiQiWeatherAppUi::UpdataWeather()
{
// 更新天气详情
iAppView->UpdateWeather(iCurrentTabIndex);
// 更新Tab显示文本
UpdateTabText();
}
void CQiQiWeatherAppUi::UpdateTabText()
{
CAknTabGroup* tabgroup =
static_cast<CAknTabGroup*>(iNaviDecorator->DecoratedControl());
if (tabgroup)
{
for (TInt i = 0; i < tabgroup->TabCount(); ++i)
{
tabgroup->ReplaceTabTextL(tabgroup->TabIdFromIndex(i),
iWeatherDetails[i].iDayOfWeek);
}
}
}
/*
* 隐藏界面
*/
void CQiQiWeatherAppUi::SetHidden(TBool aHide)
{
HideApplicationFromFSW(aHide);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -