显示小图标

今天做了个短信拦截的后台,想在有短信被拦截后,会在屏幕的最上方出现一个小图标(跟手机自带的有未读短信时屏幕上方显示一个信封的一样)。

我今天弄了一个,发现在3rd可以,但是在5版上就不可以,在5版上只显示了一次,只要一操作手机,图标就没了,不知道是不是被覆盖了???

请高手帮帮忙~~~谢谢!

注:调用的时候 iMyDrawScreen = CMyDrawScreen::NewL(); iMyDrawScreen->Enable();

 

以下是代码:

-------------------------------------------------------------------------------------------

#include "MyDrawScreen.h"
extern void WriteLogfile(const TDesC& aDes);
#define __EVENTREADY__
CMyDrawScreen::CMyDrawScreen() :
CActive(CActive::EPriorityStandard)
{
// No implementation required
}
CMyDrawScreen::~CMyDrawScreen()
{
Cancel();
delete iBitmap;
delete iBitmapMask;
if (iWindow)
{
  iWindow->Close();
  delete iWindow;
}
if (iGc)
  delete iGc;
if (iWg)
{
  iWg->Close();
  delete iWg;
}
delete iWsScreen;
if (iWsSession)
{
  iWsSession->Close();
  delete iWsSession;
}
}
CMyDrawScreen* CMyDrawScreen::NewLC()
{
CMyDrawScreen* self = new (ELeave)CMyDrawScreen();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CMyDrawScreen* CMyDrawScreen::NewL()
{
CMyDrawScreen* self=CMyDrawScreen::NewLC();
CleanupStack::Pop(); // self;
return self;
}
void CMyDrawScreen::ConstructL()
{
CActiveScheduler::Add(this);
InitReady = isEnabled = EFalse;
iWsSession = new RWsSession;
if ( iWsSession && iWsSession->Connect()!= KErrNone)
  return;
iWg = new RWindowGroup(*iWsSession);
if ( iWg && iWg->Construct(reinterpret_cast<TUint32>(&iWg), EFalse)!= KErrNone)
  return;
iWg->SetOrdinalPosition(10, ECoeWinPriorityAlwaysAtFront);
iWindow = new RWindow((*iWsSession));
if (iWindow->Construct(*iWg, reinterpret_cast<TUint32>(iWg) + 1)!= KErrNone)
  return;

InitReady = ETrue;
iWsScreen = new(ELeave) CWsScreenDevice(*iWsSession);
if (iWsScreen == NULL)
  return;
iWsScreen->Construct();
if (iWsScreen->CreateContext(iGc)!= KErrNone)
  return;
TInt aMode = iWsScreen->CurrentScreenMode();
TPixelsAndRotation aType;
iWsScreen->GetScreenModeSizeAndRotation(aMode, aType);
iRect.iTl = TPoint(aType.iPixelSize.iWidth-28, 0);
iRect.SetSize(TSize(12, 8));
iMode = iWsScreen->DisplayMode();


iWindow->SetVisible(ETrue);
iWindow->SetExtent(iRect.iTl, TSize(12, 8));
iWindow->Activate();
iWinRect = TRect(iWindow->Size());

iBitmap = new CWsBitmap(*iWsSession);
if ( iBitmap->Load(KBitmapFile, EMbmAm321server8x8)!= KErrNone)
{
  delete iBitmap;
  iBitmap = NULL;
  return;
}
/*iBitmapMask = new CWsBitmap(*iWsSession);
if ( iBitmapMask->Load(KBitmapFile, EMbmAm321server8x8mask)!= KErrNone)
{
  delete iBitmap;
  iBitmap = NULL;
  delete iBitmapMask;
  iBitmapMask = NULL;
  return;;
}*/
DrawAWindow();
Disable();
#if defined(__EVENTREADY__)
iWg->EnableFocusChangeEvents();
iWsSession->EventReady(&iStatus);
#else
iWsSession->RedrawReady(&iStatus); // request redraw
#endif
SetActive(); // so we're now active
}
void CMyDrawScreen::Enable()
{
if (!InitReady)
  return;
iWg->SetOrdinalPosition(10, ECoeWinPriorityAlwaysAtFront);
if(IsIdleState())
  DrawAWindow();
iWsSession->Flush();
isEnabled = ETrue;
}
void CMyDrawScreen::Disable()
{
if (!InitReady )
  return;
iWg->SetOrdinalPosition(10, ECoeWinPriorityNeverAtFront);
iWsSession->Flush();
isEnabled = EFalse;
}
void CMyDrawScreen::RunL()
{
#if defined(__EVENTREADY__)
TWsEvent aEvent;
iWsSession->GetEvent(aEvent);
if(aEvent.Type() == EEventFocusGroupChanged)
{
  if(isEnabled&&IsIdleState())
  {
   iWg->SetOrdinalPosition(10, ECoeWinPriorityAlwaysAtFront);
   DrawAWindow();
  }
  else
  {
   iWg->SetOrdinalPosition(10, ECoeWinPriorityNeverAtFront);
   iWindow->Invalidate(iWinRect);
   iWindow->BeginRedraw(iWinRect);
   iWindow->EndRedraw();
  }
}
iWsSession->Flush();
iWg->EnableFocusChangeEvents();
iWsSession->EventReady(&iStatus);
#else
TWsRedrawEvent redrawEvent;
iWsSession->GetRedraw(redrawEvent); // get event
if ( redrawEvent.Handle())
{
  if(isEnabled)
   DrawAWindow();
  else
  {
   iWindow->Invalidate(iWinRect);
   iWindow->BeginRedraw(iWinRect);
   iWindow->EndRedraw();
  }
}
iWsSession->Flush();
iWsSession->RedrawReady(&iStatus); // request redraw
#endif
SetActive(); // so we're now active
}
void CMyDrawScreen::DoCancel()
{
#if defined(__EVENTREADY__)
iWsSession->EventReadyCancel();
#else
iWsSession->RedrawReadyCancel(); // cancel redraw request
#endif
}
void CMyDrawScreen::DrawAWindow()
{
iGc->Activate(*iWindow);
iWindow->Invalidate(iWinRect);
iWindow->BeginRedraw(iWinRect);
if (iBitmap)
  iGc->BitBlt(TPoint(0,0), iBitmap);
else
{
  iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  iGc->Clear();
}
iWindow->EndRedraw();
iGc->Deactivate();
}
#include <APGCLI.H>
#include <APAID.h>
#include <APGWGNAM.H>
TBool CMyDrawScreen::IsIdleState()
{
TBool find(EFalse);
RApaLsSession ls;
TInt result = ls.Connect();
if (result == KErrNone)
{
  result = ls.GetAllApps(); // Or use other methods
  if (result == KErrNone)
  {

   const TUid KUidPhone = { 0x100058b3 };
   const TUid KUidIdle  = { 0x101fd64c };
   TInt wgid = iWsSession->GetFocusWindowGroup();
      CApaWindowGroupName* gn = CApaWindowGroupName::NewLC(*iWsSession, wgid);
      TUid uid = gn->AppUid();
   if( uid == KUidPhone || uid == KUidIdle)
    find = ETrue;
   CleanupStack::PopAndDestroy(gn);
  }
  ls.Close();
}
return find;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值